Skip to content
This repository has been archived by the owner on Oct 2, 2023. It is now read-only.

Commit

Permalink
Merge pull request #262 from hygieia/fix-memory-leaks
Browse files Browse the repository at this point in the history
Performance boost for api/v3/build
  • Loading branch information
aswink19 authored Mar 29, 2022
2 parents d5ba71e + bcfc4ff commit 3eab2a1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<artifactId>api</artifactId>
<packaging>jar</packaging>
<name>${project.groupId}:${project.artifactId}</name>
<version>3.4.30</version>
<version>3.4.31</version>
<description>Hygieia Rest API Layer</description>
<url>https://github.com/Hygieia/api</url>

Expand Down Expand Up @@ -59,7 +59,7 @@

<properties>
<!-- Dependencies -->
<com.capitalone.dashboard.core.version>3.15.21</com.capitalone.dashboard.core.version>
<com.capitalone.dashboard.core.version>3.15.26</com.capitalone.dashboard.core.version>
<spring-security.version>4.2.18.RELEASE</spring-security.version>
<tomcat.version>8.5.70</tomcat.version>
<commons-beanutils.version>1.9.4</commons-beanutils.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.springframework.stereotype.Service;

import javax.validation.constraints.NotNull;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -128,7 +127,6 @@ public DataResponse<Iterable<Build>> search(BuildSearchRequest request) {

return new DataResponse<>(result, collector.getLastExecuted());
}

protected Build createBuild(BuildDataCreateRequest request) throws HygieiaException {
/**
* Step 1: create Collector if not there
Expand Down Expand Up @@ -173,16 +171,12 @@ public String createV2(BuildDataCreateRequest request) throws HygieiaException {
public BuildDataCreateResponse createV3(BuildDataCreateRequest request) throws HygieiaException {
BuildDataCreateResponse response = new BuildDataCreateResponse();
Build build = createBuild(request);
try {
org.apache.commons.beanutils.BeanUtils.copyProperties(response, build);
} catch (IllegalAccessException | InvocationTargetException e) {
throw new HygieiaException(e);
} finally {
if (settings.isLookupDashboardForBuildDataCreate()) {
populateDashboardId(response);
}
}
String clientReference = StringUtils.isNotEmpty(build.getClientReference()) ? build.getClientReference() : request.getClientReference();
if(build == null) throw new HygieiaException("Unable to create build for request.", HygieiaException.ERROR_INSERTING_DATA);
populateBuildDateResponse(response, build);
if(settings.isLookupDashboardForBuildDataCreate()) {
populateDashboardId(response);
}
response.setClientReference(clientReference);
// Will be refactored soon
CollectorItem buildCollectorItem = collectorItemRepository.findOne(build.getCollectorItemId());
Expand Down Expand Up @@ -221,6 +215,19 @@ public BuildDataCreateResponse createV3(BuildDataCreateRequest request) throws H
return response;
}

private void populateBuildDateResponse(BuildDataCreateResponse response, Build build) {
if (response == null || build == null) return;
response.setCollectorItemId(build.getCollectorItemId());
response.setTimestamp(build.getTimestamp());
response.setNumber(build.getNumber());
response.setBuildUrl(build.getBuildUrl());
response.setStartTime(build.getStartTime());
response.setEndTime(build.getEndTime());
response.setDuration(build.getDuration());
response.setBuildStatus(build.getBuildStatus());
response.setStartedBy(build.getStartedBy());
}

private String buildStageErrorLog (BuildStage buildStage) {
if(Objects.isNull(buildStage) || Objects.isNull(buildStage.getError())) return "";
return " build_stage_error="+buildStage.getError().getType()+":"+buildStage.getError().getMessage();
Expand Down

0 comments on commit 3eab2a1

Please sign in to comment.