summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib
diff options
context:
space:
mode:
authorvempo <vitaliy.emporopulo@amdocs.com>2017-10-23 13:28:46 +0300
committervempo <vitaliy.emporopulo@amdocs.com>2017-10-23 13:39:10 +0300
commit5f3a0ea3230fc09bb66a5b6fbd65868fe2a46e6c (patch)
tree6d5928c7947746eab1c38cf7d6ebbed060ca6390 /openecomp-be/lib/openecomp-sdc-vendor-software-product-lib
parentb8aabbe3590c90be5c6f3e2c63b57c0e396baed6 (diff)
Fixed resources not being released, code cleanup
Properly close input streams; code cleanup; fixed static analysis violations and coding convetions. Change-Id: I53dabcc9f8898a0ab25636735cb0b5f84b57c427 Issue-ID: SDC-291 Signed-off-by: vempo <vitaliy.emporopulo@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-vendor-software-product-lib')
-rw-r--r--openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/HeatFileAnalyzerRowDataImpl.java13
-rw-r--r--openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/utils/CandidateEntityBuilder.java76
2 files changed, 43 insertions, 46 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/HeatFileAnalyzerRowDataImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/HeatFileAnalyzerRowDataImpl.java
index f7ca6463cb..dd303c7bb9 100644
--- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/HeatFileAnalyzerRowDataImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/HeatFileAnalyzerRowDataImpl.java
@@ -53,7 +53,7 @@ public class HeatFileAnalyzerRowDataImpl implements HeatFileAnalyzer {
private static final String DESCRIPTION = "DESCRIPTION";
private static final String NESTED_PATTERN = "NESTED_PATTERN";
- private Map<String, Pattern> patterns;
+ private final Map<String, Pattern> patterns;
public HeatFileAnalyzerRowDataImpl() {
patterns = new HashMap<>();
@@ -72,16 +72,17 @@ public class HeatFileAnalyzerRowDataImpl implements HeatFileAnalyzer {
throws IOException {
AnalyzedZipHeatFiles analyzedZipHeatFiles = new AnalyzedZipHeatFiles();
- BufferedReader bfReader;
for (Map.Entry<String, byte[]> fileData : files.entrySet()) {
String fileName = fileData.getKey();
if (!HeatFileAnalyzer.isYamlFile(fileName)) {
analyzedZipHeatFiles.addOtherNonModuleFile(fileName);
continue;
}
+
boolean foundHeatIdentifier = false;
- try (InputStream is = new ByteArrayInputStream(fileData.getValue())) {
- bfReader = new BufferedReader(new InputStreamReader(is));
+ try (InputStream is = new ByteArrayInputStream(fileData.getValue());
+ BufferedReader bfReader = new BufferedReader(new InputStreamReader(is))) {
+
String line;
boolean isResourcesSection = false;
Set<String> nestedFilesNames = new HashSet<>();
@@ -108,11 +109,9 @@ public class HeatFileAnalyzerRowDataImpl implements HeatFileAnalyzer {
}
analyzedZipHeatFiles.addNestedFiles(fetchFileNamesToReturn(nestedFilesNames,
foundHeatIdentifier));
- if (Objects.nonNull(bfReader)) {
- bfReader.close();
- }
}
}
+
return analyzedZipHeatFiles;
}
diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/utils/CandidateEntityBuilder.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/utils/CandidateEntityBuilder.java
index ca5329344b..41510ecc13 100644
--- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/utils/CandidateEntityBuilder.java
+++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/utils/CandidateEntityBuilder.java
@@ -38,6 +38,7 @@ import org.openecomp.sdc.vendorsoftwareproduct.services.impl.HeatFileAnalyzerRow
import org.openecomp.sdc.vendorsoftwareproduct.types.CandidateDataEntityTo;
import org.openecomp.sdc.vendorsoftwareproduct.types.candidateheat.AnalyzedZipHeatFiles;
+import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Map;
@@ -45,8 +46,10 @@ import java.util.Objects;
import java.util.Optional;
public class CandidateEntityBuilder {
- private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
- private CandidateService candidateService;
+
+ private static final MdcDataDebugMessage MDC_DATA_DEBUG_MESSAGE = new MdcDataDebugMessage();
+
+ private final CandidateService candidateService;
public CandidateEntityBuilder(CandidateService candidateService) {
this.candidateService = candidateService;
@@ -57,35 +60,28 @@ public class CandidateEntityBuilder {
Map<String, List<ErrorMessage>> uploadErrors, String user) throws Exception {
//mdcDataDebugMessage.debugEntryMessage("VSP Id", vspDetails.getId());
- InputStream zipFileManifest = contentMap.getFileContent(SdcCommon.MANIFEST_NAME);
- HeatFileAnalyzer heatFileAnalyzer = new HeatFileAnalyzerRowDataImpl();
- AnalyzedZipHeatFiles analyzedZipHeatFiles =
- heatFileAnalyzer.analyzeFilesNotEligibleForModulesFromFileAnalyzer(contentMap.getFiles());
- HeatStructureTree tree = getHeatStructureTree(vspDetails, contentMap, analyzedZipHeatFiles);
+ try (InputStream zipFileManifest = contentMap.getFileContent(SdcCommon.MANIFEST_NAME)) {
+ HeatFileAnalyzer heatFileAnalyzer = new HeatFileAnalyzerRowDataImpl();
+ AnalyzedZipHeatFiles analyzedZipHeatFiles =
+ heatFileAnalyzer.analyzeFilesNotEligibleForModulesFromFileAnalyzer(contentMap.getFiles());
+ HeatStructureTree tree = getHeatStructureTree(vspDetails, contentMap, analyzedZipHeatFiles);
- CandidateDataEntityTo candidateDataEntityTo =
- new CandidateDataEntityTo(vspDetails.getId(), user, uploadedFileData, tree, contentMap,
- vspDetails.getVersion());
- candidateDataEntityTo.setErrors(uploadErrors);
- OrchestrationTemplateCandidateData candidateDataEntity =
- candidateService.createCandidateDataEntity(candidateDataEntityTo, zipFileManifest,
- analyzedZipHeatFiles);
+ CandidateDataEntityTo candidateDataEntityTo =
+ new CandidateDataEntityTo(vspDetails.getId(), user, uploadedFileData, tree, contentMap,
+ vspDetails.getVersion());
+ candidateDataEntityTo.setErrors(uploadErrors);
+ OrchestrationTemplateCandidateData candidateDataEntity =
+ candidateService.createCandidateDataEntity(candidateDataEntityTo, zipFileManifest,
+ analyzedZipHeatFiles);
- mdcDataDebugMessage.debugExitMessage("VSP Id", vspDetails.getId());
- return candidateDataEntity;
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage("VSP Id", vspDetails.getId());
+ return candidateDataEntity;
+ }
}
-// public OrchestrationTemplateCandidateData buildOrchestrationTemplateFromCsar(VspDetails vspDetails,
-// byte[] uploadedFileData,
-// FileContentHandler contentMap,
-// Map<String, List<ErrorMessage>> uploadErrors,
-// String user){
-//
-// }
-
private HeatStructureTree getHeatStructureTree(VspDetails vspDetails,
FileContentHandler contentMap,
- AnalyzedZipHeatFiles analyzedZipHeatFiles) {
+ AnalyzedZipHeatFiles analyzedZipHeatFiles) throws IOException {
addManifestToFileContentMapIfNotExist(vspDetails, contentMap, analyzedZipHeatFiles);
HeatTreeManager heatTreeManager = HeatTreeManagerUtil.initHeatTreeManager(contentMap);
heatTreeManager.createTree();
@@ -94,22 +90,24 @@ public class CandidateEntityBuilder {
private void addManifestToFileContentMapIfNotExist(VspDetails vspDetails,
FileContentHandler fileContentHandler,
- AnalyzedZipHeatFiles analyzedZipHeatFiles) {
- mdcDataDebugMessage.debugEntryMessage("VSP Id", vspDetails.getId());
+ AnalyzedZipHeatFiles analyzedZipHeatFiles) throws IOException {
+ MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("VSP Id", vspDetails.getId());
+
+ try (InputStream manifest = fileContentHandler.getFileContent(SdcCommon.MANIFEST_NAME)) {
- InputStream manifest = fileContentHandler.getFileContent(SdcCommon.MANIFEST_NAME);
- if (Objects.isNull(manifest)) {
- Optional<ManifestContent> manifestContentOptional =
- candidateService.createManifest(vspDetails, fileContentHandler, analyzedZipHeatFiles);
- if (!manifestContentOptional.isPresent()) {
- throw new RuntimeException(Messages.CREATE_MANIFEST_FROM_ZIP.getErrorMessage());
+ if (Objects.isNull(manifest)) {
+ Optional<ManifestContent> manifestContentOptional =
+ candidateService.createManifest(vspDetails, fileContentHandler, analyzedZipHeatFiles);
+ if (!manifestContentOptional.isPresent()) {
+ throw new RuntimeException(Messages.CREATE_MANIFEST_FROM_ZIP.getErrorMessage());
+ }
+ ManifestContent manifestContent = manifestContentOptional.get();
+ fileContentHandler.addFile(
+ SdcCommon.MANIFEST_NAME,
+ String.valueOf(JsonUtil.sbObject2Json(manifestContent)).getBytes());
}
- ManifestContent manifestContent = manifestContentOptional.get();
- fileContentHandler.addFile(
- SdcCommon.MANIFEST_NAME,
- String.valueOf(JsonUtil.sbObject2Json(manifestContent)).getBytes());
+ } finally {
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage("VSP Id", vspDetails.getId());
}
-
- mdcDataDebugMessage.debugExitMessage("VSP Id", vspDetails.getId());
}
}