summaryrefslogtreecommitdiffstats
path: root/openecomp-be
diff options
context:
space:
mode:
authorVitaly Emporopulo <Vitaliy.Emporopulo@amdocs.com>2017-10-23 11:22:15 +0000
committerGerrit Code Review <gerrit@onap.org>2017-10-23 11:22:15 +0000
commitb75aaccf629eecac3a68d3d30edec6312fd5ec38 (patch)
tree168a028a87efbd8464735d879db7a3cff28c3ce3 /openecomp-be
parent8e5fc51917be4fc78d55197ca43b2b11fa357856 (diff)
parent5f3a0ea3230fc09bb66a5b6fbd65868fe2a46e6c (diff)
Merge "Fixed resources not being released, code cleanup"
Diffstat (limited to 'openecomp-be')
-rw-r--r--openecomp-be/backend/openecomp-sdc-validation-manager/src/main/java/org/openecomp/sdc/validation/impl/UploadValidationManagerImpl.java21
-rw-r--r--openecomp-be/backend/openecomp-sdc-validation-manager/src/main/java/org/openecomp/sdc/validation/util/ValidationManagerUtil.java12
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ProcessManagerImpl.java60
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java161
-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
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/ToscaConverterImplTest.java21
7 files changed, 172 insertions, 192 deletions
diff --git a/openecomp-be/backend/openecomp-sdc-validation-manager/src/main/java/org/openecomp/sdc/validation/impl/UploadValidationManagerImpl.java b/openecomp-be/backend/openecomp-sdc-validation-manager/src/main/java/org/openecomp/sdc/validation/impl/UploadValidationManagerImpl.java
index ddb56ddbfc..1d1ce4f03c 100644
--- a/openecomp-be/backend/openecomp-sdc-validation-manager/src/main/java/org/openecomp/sdc/validation/impl/UploadValidationManagerImpl.java
+++ b/openecomp-be/backend/openecomp-sdc-validation-manager/src/main/java/org/openecomp/sdc/validation/impl/UploadValidationManagerImpl.java
@@ -62,20 +62,19 @@ import java.util.zip.ZipInputStream;
*/
public class UploadValidationManagerImpl implements UploadValidationManager {
- private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
+ private static final MdcDataDebugMessage MDC_DATA_DEBUG_MESSAGE = new MdcDataDebugMessage();
private static FileContentHandler getFileContentMapFromZip(byte[] uploadFileData)
throws IOException, CoreException {
+
ZipEntry zipEntry;
List<String> folderList = new ArrayList<>();
FileContentHandler mapFileContent = new FileContentHandler();
- try {
- ZipInputStream inputZipStream;
+ try (ZipInputStream inputZipStream = new ZipInputStream(new ByteArrayInputStream(uploadFileData))) {
byte[] fileByteContent;
String currentEntryName;
- inputZipStream = new ZipInputStream(new ByteArrayInputStream(uploadFileData));
while ((zipEntry = inputZipStream.getNextEntry()) != null) {
currentEntryName = zipEntry.getName();
@@ -130,7 +129,7 @@ public class UploadValidationManagerImpl implements UploadValidationManager {
throws IOException {
- mdcDataDebugMessage.debugEntryMessage(null, null);
+ MDC_DATA_DEBUG_MESSAGE.debugEntryMessage(null, (String[]) null);
ValidationFileResponse validationFileResponse = new ValidationFileResponse();
@@ -150,15 +149,12 @@ public class UploadValidationManagerImpl implements UploadValidationManager {
Map<String, List<ErrorMessage>> errors = validateHeatUploadData(content);
tree = HeatTreeManagerUtil.initHeatTreeManager(content);
tree.createTree();
- if (MapUtils.isNotEmpty(errors)) {
-
+ if (MapUtils.isNotEmpty(errors)) {
tree.addErrors(errors);
validationStructureList.setImportStructure(tree.getTree());
- //validationFileResponse.setStatus(ValidationFileStatus.Failure);
- } else {
- //validationFileResponse.setStatus(ValidationFileStatus.Success);
}
+
} else {
MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_API,
LoggerTragetServiceName.VALIDATE_FILE_TYPE, ErrorLevel.ERROR.name(),
@@ -167,12 +163,11 @@ public class UploadValidationManagerImpl implements UploadValidationManager {
}
validationFileResponse.setValidationData(validationStructureList);
- mdcDataDebugMessage.debugExitMessage(null, null);
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage(null, (String[]) null);
return validationFileResponse;
}
- private Map<String, List<ErrorMessage>> validateHeatUploadData(FileContentHandler fileContentMap)
- throws IOException {
+ private Map<String, List<ErrorMessage>> validateHeatUploadData(FileContentHandler fileContentMap) {
ValidationManager validationManager =
ValidationManagerUtil.initValidationManager(fileContentMap);
return validationManager.validate();
diff --git a/openecomp-be/backend/openecomp-sdc-validation-manager/src/main/java/org/openecomp/sdc/validation/util/ValidationManagerUtil.java b/openecomp-be/backend/openecomp-sdc-validation-manager/src/main/java/org/openecomp/sdc/validation/util/ValidationManagerUtil.java
index 924a956628..53b05eb953 100644
--- a/openecomp-be/backend/openecomp-sdc-validation-manager/src/main/java/org/openecomp/sdc/validation/util/ValidationManagerUtil.java
+++ b/openecomp-be/backend/openecomp-sdc-validation-manager/src/main/java/org/openecomp/sdc/validation/util/ValidationManagerUtil.java
@@ -29,6 +29,7 @@ import org.openecomp.sdc.common.utils.SdcCommon;
import org.openecomp.sdc.datatypes.error.ErrorLevel;
import org.openecomp.sdc.datatypes.error.ErrorMessage;
+import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Map;
@@ -43,11 +44,12 @@ public class ValidationManagerUtil {
* @param errors the errors
*/
public static void handleMissingManifest(FileContentHandler fileContentMap,
- Map<String, List<ErrorMessage>> errors) {
- InputStream manifest = fileContentMap.getFileContent(SdcCommon.MANIFEST_NAME);
- if (manifest == null) {
- ErrorMessage.ErrorMessageUtil.addMessage(SdcCommon.MANIFEST_NAME, errors)
- .add(new ErrorMessage(ErrorLevel.ERROR, Messages.MANIFEST_NOT_EXIST.getErrorMessage()));
+ Map<String, List<ErrorMessage>> errors) throws IOException {
+ try (InputStream manifest = fileContentMap.getFileContent(SdcCommon.MANIFEST_NAME)) {
+ if (manifest == null) {
+ ErrorMessage.ErrorMessageUtil.addMessage(SdcCommon.MANIFEST_NAME, errors)
+ .add(new ErrorMessage(ErrorLevel.ERROR, Messages.MANIFEST_NOT_EXIST.getErrorMessage()));
+ }
}
}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ProcessManagerImpl.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ProcessManagerImpl.java
index 4df00fd74a..a3d0286019 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ProcessManagerImpl.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ProcessManagerImpl.java
@@ -50,10 +50,10 @@ import java.io.InputStream;
import java.util.Collection;
public class ProcessManagerImpl implements ProcessManager {
- private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
- private ActivityLogManager activityLogManager;
+ private static final MdcDataDebugMessage MDC_DATA_DEBUG_MESSAGE = new MdcDataDebugMessage();
+ private final ActivityLogManager activityLogManager;
- private VendorSoftwareProductDao vendorSoftwareProductDao;
+ private final VendorSoftwareProductDao vendorSoftwareProductDao;
private final Logger log = (Logger) LoggerFactory.getLogger(this.getClass().getName());
@@ -66,15 +66,15 @@ public class ProcessManagerImpl implements ProcessManager {
public Collection<ProcessEntity> listProcesses(String vspId, Version version,
String componentId,
String user) {
- mdcDataDebugMessage.debugEntryMessage("VSP id, component id", vspId, componentId);
- mdcDataDebugMessage.debugExitMessage("VSP id, component id", vspId, componentId);
+ MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("VSP id, component id", vspId, componentId);
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage("VSP id, component id", vspId, componentId);
return vendorSoftwareProductDao.listProcesses(vspId, version, componentId);
}
@Override
public void deleteProcesses(String vspId, Version version, String componentId, String user) {
- mdcDataDebugMessage.debugEntryMessage("VSP id, component id", vspId, componentId);
+ MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("VSP id, component id", vspId, componentId);
Collection<ProcessEntity> processes =
vendorSoftwareProductDao.listProcesses(vspId, version, componentId);
@@ -87,12 +87,12 @@ public class ProcessManagerImpl implements ProcessManager {
vendorSoftwareProductDao.deleteProcesses(vspId, version, componentId);
}
- mdcDataDebugMessage.debugExitMessage("VSP id, component id", vspId, componentId);
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage("VSP id, component id", vspId, componentId);
}
@Override
public ProcessEntity createProcess(ProcessEntity process, String user) {
- mdcDataDebugMessage.debugEntryMessage("VSP id, component id", process.getId(),
+ MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("VSP id, component id", process.getId(),
process.getComponentId());
validateUniqueName(process.getVspId(), process.getVersion(), process.getComponentId(),
process.getName());
@@ -102,7 +102,7 @@ public class ProcessManagerImpl implements ProcessManager {
createUniqueName(process.getVspId(), process.getVersion(), process.getComponentId(),
process.getName());
- mdcDataDebugMessage.debugExitMessage("VSP id, component id", process.getId(),
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage("VSP id, component id", process.getId(),
process.getComponentId());
return process;
@@ -112,20 +112,20 @@ public class ProcessManagerImpl implements ProcessManager {
@Override
public ProcessEntity getProcess(String vspId, Version version, String componentId,
String processId, String user) {
- mdcDataDebugMessage.debugEntryMessage("VSP id, component id", vspId, componentId);
+ MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("VSP id, component id", vspId, componentId);
ProcessEntity retrieved =
vendorSoftwareProductDao.getProcess(vspId, version, componentId, processId);
validateProcessExistence(vspId, version, componentId, processId, retrieved);
- mdcDataDebugMessage.debugExitMessage("VSP id, component id", vspId, componentId);
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage("VSP id, component id", vspId, componentId);
return retrieved;
}
@Override
public void updateProcess(ProcessEntity process, String user) {
- mdcDataDebugMessage.debugEntryMessage("VSP id, component id", process.getId(),
+ MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("VSP id, component id", process.getId(),
process.getComponentId());
ProcessEntity retrieved = vendorSoftwareProductDao
@@ -138,14 +138,14 @@ public class ProcessManagerImpl implements ProcessManager {
retrieved.getName(), process.getName());
vendorSoftwareProductDao.updateProcess(process);
- mdcDataDebugMessage.debugExitMessage("VSP id, component id", process.getId(),
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage("VSP id, component id", process.getId(),
process.getComponentId());
}
@Override
public void deleteProcess(String vspId, Version version, String componentId, String processId,
String user) {
- mdcDataDebugMessage.debugEntryMessage("VSP id, component id", vspId, componentId);
+ MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("VSP id, component id", vspId, componentId);
ProcessEntity retrieved =
vendorSoftwareProductDao.getProcess(vspId, version, componentId, processId);
@@ -155,33 +155,30 @@ public class ProcessManagerImpl implements ProcessManager {
deleteUniqueValue(retrieved.getVspId(), retrieved.getVersion(), retrieved.getComponentId(),
retrieved.getName());
- mdcDataDebugMessage.debugExitMessage("VSP id, component id", vspId, componentId);
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage("VSP id, component id", vspId, componentId);
}
@Override
public File getProcessArtifact(String vspId, Version version, String componentId,
String processId, String user) {
- mdcDataDebugMessage.debugEntryMessage("VSP id, component id", vspId, componentId);
+ MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("VSP id, component id", vspId, componentId);
ProcessEntity retrieved =
vendorSoftwareProductDao.getProcessArtifact(vspId, version, componentId, processId);
validateProcessArtifactExistence(vspId, version, componentId, processId, retrieved);
File file = new File(String.format("%s_%s_%s", vspId, componentId, processId));
- try {
- FileOutputStream fos = new FileOutputStream(file);
+ try (FileOutputStream fos = new FileOutputStream(file)) {
fos.write(retrieved.getArtifact().array());
- fos.close();
} catch (IOException exception) {
- log.debug("", exception);
MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
LoggerTragetServiceName.GET_PROCESS_ARTIFACT, ErrorLevel.ERROR.name(),
LoggerErrorCode.DATA_ERROR.getErrorCode(), "Can't get process artifact");
- throw new CoreException(new UploadInvalidErrorBuilder().build());
+ throw new CoreException(new UploadInvalidErrorBuilder().build(), exception);
}
- mdcDataDebugMessage.debugExitMessage("VSP id, component id", vspId, componentId);
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage("VSP id, component id", vspId, componentId);
return file;
}
@@ -189,7 +186,7 @@ public class ProcessManagerImpl implements ProcessManager {
@Override
public void deleteProcessArtifact(String vspId, Version version, String componentId,
String processId, String user) {
- mdcDataDebugMessage.debugEntryMessage("VSP id, component id", vspId, componentId);
+ MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("VSP id, component id", vspId, componentId);
ProcessEntity retrieved =
vendorSoftwareProductDao.getProcessArtifact(vspId, version, componentId, processId);
@@ -197,14 +194,14 @@ public class ProcessManagerImpl implements ProcessManager {
vendorSoftwareProductDao.deleteProcessArtifact(vspId, version, componentId, processId);
- mdcDataDebugMessage.debugExitMessage("VSP id, component id", vspId, componentId);
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage("VSP id, component id", vspId, componentId);
}
@Override
public void uploadProcessArtifact(InputStream artifactFile, String artifactFileName, String vspId,
Version version, String componentId, String processId,
String user) {
- mdcDataDebugMessage.debugEntryMessage("VSP id, component id", vspId, componentId);
+ MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("VSP id, component id", vspId, componentId);
ProcessEntity retrieved =
vendorSoftwareProductDao.getProcess(vspId, version, componentId, processId);
@@ -221,11 +218,10 @@ public class ProcessManagerImpl implements ProcessManager {
try {
artifact = FileUtils.toByteArray(artifactFile);
} catch (RuntimeException exception) {
- log.debug("", exception);
MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
LoggerTragetServiceName.UPLOAD_PROCESS_ARTIFACT, ErrorLevel.ERROR.name(),
LoggerErrorCode.DATA_ERROR.getErrorCode(), "Can't upload process artifact");
- throw new CoreException(new UploadInvalidErrorBuilder().build());
+ throw new CoreException(new UploadInvalidErrorBuilder().build(), exception);
}
vendorSoftwareProductDao.uploadProcessArtifact(vspId, version, componentId, processId, artifact,
@@ -234,13 +230,13 @@ public class ProcessManagerImpl implements ProcessManager {
ActivityType.UPLOAD_MONITORING_FILE.toString(), user, true, "", "");
activityLogManager.addActionLog(activityLogEntity, user);
- mdcDataDebugMessage.debugExitMessage("VSP id, component id", vspId, componentId);
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage("VSP id, component id", vspId, componentId);
}
private void validateProcessExistence(String vspId, Version version, String componentId,
String processId, ProcessEntity retrieved) {
- mdcDataDebugMessage.debugEntryMessage("VSP id, component id, process id", vspId, componentId,
+ MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("VSP id, component id, process id", vspId, componentId,
processId);
if (retrieved != null) {
@@ -250,13 +246,13 @@ public class ProcessManagerImpl implements ProcessManager {
new ProcessEntity(vspId, version, componentId, processId),
VspDetails.ENTITY_TYPE);//todo retrieved is always null ??
- mdcDataDebugMessage.debugExitMessage("VSP id, component id, process id", vspId, componentId,
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage("VSP id, component id, process id", vspId, componentId,
processId);
}
private void validateProcessArtifactExistence(String vspId, Version version, String componentId,
String processId, ProcessEntity retrieved) {
- mdcDataDebugMessage.debugEntryMessage("VSP id, component id, process id", vspId, componentId,
+ MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("VSP id, component id, process id", vspId, componentId,
processId);
if (retrieved != null) {
@@ -269,7 +265,7 @@ public class ProcessManagerImpl implements ProcessManager {
VspDetails.ENTITY_TYPE); //todo retrieved is always null ??
}
- mdcDataDebugMessage.debugExitMessage("VSP id, component id, process id", vspId, componentId,
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage("VSP id, component id, process id", vspId, componentId,
processId);
}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java
index be1aaf08e5..dde5d61663 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java
@@ -146,25 +146,25 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa
private static final String VALIDATION_VSP_NAME = "validationOnlyVspName";
//private static final String VALIDATION_VSP_USER = "validationOnlyVspUser";
- private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
- private static final Logger logger =
+ private static final MdcDataDebugMessage MDC_DATA_DEBUG_MESSAGE = new MdcDataDebugMessage();
+ private static final Logger LOGGER =
LoggerFactory.getLogger(VendorSoftwareProductManagerImpl.class);
- private OrchestrationTemplateDao orchestrationTemplateDao;
- private VendorSoftwareProductInfoDao vspInfoDao;
- private VersioningManager versioningManager;
- private VendorSoftwareProductDao vendorSoftwareProductDao;
- private VendorLicenseFacade vendorLicenseFacade;
- private ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDao;
- private EnrichedServiceModelDao<ToscaServiceModel, ServiceElement> enrichedServiceModelDao;
- private HealingManager healingManager;
- private VendorLicenseArtifactsService licenseArtifactsService;
- private InformationArtifactGenerator informationArtifactGenerator;
- private PackageInfoDao packageInfoDao;
- private ActivityLogManager activityLogManager;
- private DeploymentFlavorDao deploymentFlavorDao;
- private NicDao nicDao;
- private ManualVspToscaManager manualVspToscaManager;
+ private final OrchestrationTemplateDao orchestrationTemplateDao;
+ private final VendorSoftwareProductInfoDao vspInfoDao;
+ private final VersioningManager versioningManager;
+ private final VendorSoftwareProductDao vendorSoftwareProductDao;
+ private final VendorLicenseFacade vendorLicenseFacade;
+ private final ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDao;
+ private final EnrichedServiceModelDao<ToscaServiceModel, ServiceElement> enrichedServiceModelDao;
+ private final HealingManager healingManager;
+ private final VendorLicenseArtifactsService licenseArtifactsService;
+ private final InformationArtifactGenerator informationArtifactGenerator;
+ private final PackageInfoDao packageInfoDao;
+ private final ActivityLogManager activityLogManager;
+ private final DeploymentFlavorDao deploymentFlavorDao;
+ private final NicDao nicDao;
+ private final ManualVspToscaManager manualVspToscaManager;
/**
* Instantiates a new Vendor software product manager.
@@ -230,7 +230,7 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa
@Override
public Version checkout(String vendorSoftwareProductId, String user) {
- mdcDataDebugMessage.debugEntryMessage("VSP id", vendorSoftwareProductId);
+ MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("VSP id", vendorSoftwareProductId);
MDC.put(LoggerConstants.SERVICE_NAME, LoggerServiceName.Checkout_Entity.toString());
Version newVersion = versioningManager
@@ -244,14 +244,14 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa
activityLogManager.addActionLog(activityLogEntity, user);
}
- mdcDataDebugMessage.debugExitMessage("VSP id", vendorSoftwareProductId);
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage("VSP id", vendorSoftwareProductId);
return newVersion;
}
@Override
public Version undoCheckout(String vendorSoftwareProductId, String user) {
- mdcDataDebugMessage.debugEntryMessage("VSP id", vendorSoftwareProductId);
+ MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("VSP id", vendorSoftwareProductId);
Version version =
getVersionInfo(vendorSoftwareProductId, VersionableEntityAction.Read, user)
@@ -275,14 +275,14 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa
updateUniqueName(preVspName, postVspName);
- mdcDataDebugMessage.debugExitMessage("VSP id", vendorSoftwareProductId);
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage("VSP id", vendorSoftwareProductId);
return newVersion;
}
@Override
public Version checkin(String vendorSoftwareProductId, String user) {
- mdcDataDebugMessage.debugEntryMessage("VSP id", vendorSoftwareProductId);
+ MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("VSP id", vendorSoftwareProductId);
Version newVersion = versioningManager.checkin(
VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE,
@@ -295,14 +295,14 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa
activityLogManager.addActionLog(activityLogEntity, user);
}
- mdcDataDebugMessage.debugExitMessage("VSP id", vendorSoftwareProductId);
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage("VSP id", vendorSoftwareProductId);
return newVersion;
}
@Override
public ValidationResponse submit(String vspId, String user) throws IOException {
- mdcDataDebugMessage.debugEntryMessage("VSP id", vspId);
+ MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("VSP id", vspId);
Version version = getVersionInfo(vspId, VersionableEntityAction.Read, user).getActiveVersion();
VspDetails vspDetails = getVsp(vspId, version, user);
@@ -379,7 +379,7 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa
activityLogManager.addActionLog(activityLogEntity, user);
}
- mdcDataDebugMessage.debugExitMessage("VSP id", vspId);
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage("VSP id", vspId);
return validationResponse;
}
@@ -397,7 +397,7 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa
private Collection<ErrorCode> deploymentFlavorValidation(String vspId,
Version version) {
- mdcDataDebugMessage.debugEntryMessage("VSP id", vspId);
+ MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("VSP id", vspId);
Set<CompositionEntityValidationData> validationData = new HashSet<>();
Collection<ErrorCode> errorCodeList = new ArrayList<>();
Collection<DeploymentFlavorEntity> deploymentFlavors =
@@ -451,7 +451,7 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa
}
private Set<CompositionEntityValidationData> componentValidation(String vspId, Version version) {
- mdcDataDebugMessage.debugEntryMessage("VSP id", vspId);
+ MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("VSP id", vspId);
Set<CompositionEntityValidationData> validationData = new HashSet<>();
Collection<ComponentEntity> components =
@@ -578,8 +578,8 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa
}
String getVspQuestionnaireSchema(SchemaTemplateInput schemaInput) {
- mdcDataDebugMessage.debugEntryMessage(null);
- mdcDataDebugMessage.debugExitMessage(null);
+ MDC_DATA_DEBUG_MESSAGE.debugEntryMessage(null);
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage(null);
return SchemaGenerator
.generate(SchemaTemplateContext.questionnaire, CompositionEntityType.vsp, schemaInput);
}
@@ -606,7 +606,7 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa
Map<String, List<ErrorMessage>> enrichErrors = enrichmentManager.enrich();
if (MapUtils.isEmpty(MessageContainerUtil.getMessageByLevel(ErrorLevel.ERROR, enrichErrors))) {
- logger.audit(AuditMessages.AUDIT_MSG + AuditMessages.ENRICHMENT_COMPLETED
+ LOGGER.audit(AuditMessages.AUDIT_MSG + AuditMessages.ENRICHMENT_COMPLETED
+ vendorSoftwareProductId);
} else {
enrichErrors.values().forEach(errorList ->
@@ -621,7 +621,7 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa
}
private Collection<ErrorCode> validateLicensingData(VspDetails vspDetails) {
- mdcDataDebugMessage.debugEntryMessage("VSP id", vspDetails.getId());
+ MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("VSP id", vspDetails.getId());
if (vspDetails.getVendorId() == null || vspDetails.getVlmVersion() == null
|| vspDetails.getLicenseAgreement() == null
@@ -629,7 +629,7 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa
return null;
}
- mdcDataDebugMessage.debugExitMessage("VSP id", vspDetails.getId());
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage("VSP id", vspDetails.getId());
return vendorLicenseFacade
.validateLicensingData(vspDetails.getVendorId(), vspDetails.getVlmVersion(),
vspDetails.getLicenseAgreement(), vspDetails.getFeatureGroups());
@@ -640,7 +640,7 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa
try {
validateUniqueName(VALIDATION_VSP_NAME);
} catch (Exception ignored) {
- logger.debug("", ignored);
+ LOGGER.debug("Ignored exception when validating unique VSP name", ignored);
return VALIDATION_VSP_ID;
}
VspDetails validationVsp = new VspDetails();
@@ -659,7 +659,7 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa
@Override
public VspDetails createVsp(VspDetails vspDetails, String user) {
- mdcDataDebugMessage.debugEntryMessage(null);
+ MDC_DATA_DEBUG_MESSAGE.debugEntryMessage(null);
validateUniqueName(vspDetails.getName());
@@ -679,13 +679,13 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa
activityLogManager.addActionLog(activityLogEntity, user);
String vspName = vspDetails.getName();
createUniqueName(vspName);
- mdcDataDebugMessage.debugExitMessage(null);
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage(null);
return vspDetails;
}
@Override
public List<VersionedVendorSoftwareProductInfo> listVsps(String versionFilter, String user) {
- mdcDataDebugMessage.debugEntryMessage(null);
+ MDC_DATA_DEBUG_MESSAGE.debugEntryMessage(null);
Map<String, VersionInfo> idToVersionsInfo = versioningManager.listEntitiesVersionInfo(
VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, user,
@@ -714,25 +714,23 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa
vsps.add(new VersionedVendorSoftwareProductInfo(vsp, versionInfo));
}
} catch (RuntimeException rte) {
- logger.debug("", rte);
- logger.error(
+ LOGGER.error(
"Error trying to retrieve vsp[" + entry.getKey() + "] version[" + version.toString
() + "] " +
- "message:" + rte
- .getMessage());
+ "message:" + rte.getMessage(), rte);
}
}
sortVspListByModificationTimeDescOrder(vsps);
- mdcDataDebugMessage.debugExitMessage(null);
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage(null);
return vsps;
}
@Override
public void updateVsp(VspDetails vspDetails, String user) {
- mdcDataDebugMessage.debugEntryMessage("VSP id", vspDetails.getId());
+ MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("VSP id", vspDetails.getId());
VspDetails retrieved = vspInfoDao.get(vspDetails);
if (!Objects.equals(retrieved.getOnboardingMethod(), vspDetails.getOnboardingMethod())) {
@@ -756,7 +754,7 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa
vspInfoDao.update(vspDetails);
//vendorSoftwareProductDao.updateVspLatestModificationTime(vspDetails.getId(), activeVersion);
- mdcDataDebugMessage.debugExitMessage("VSP id", vspDetails.getId());
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage("VSP id", vspDetails.getId());
}
private void updateDeploymentFlavor(VspDetails vspDetails, String user) {
@@ -785,7 +783,7 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa
@Override
public VspDetails getVsp(String vspId, Version version, String user) {
- mdcDataDebugMessage.debugEntryMessage("VSP id", vspId);
+ MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("VSP id", vspId);
VspDetails vsp = vspInfoDao.get(new VspDetails(vspId, version));
if (vsp == null) {
@@ -803,7 +801,7 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa
vsp.setNetworkPackageName("Upload File");
}
- mdcDataDebugMessage.debugExitMessage("VSP id", vspId);
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage("VSP id", vspId);
return vsp;
}
@@ -853,12 +851,12 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa
@Override
public void deleteVsp(String vspId, String user) {
- mdcDataDebugMessage.debugEntryMessage("VSP id", vspId);
+ MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("VSP id", vspId);
MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
LoggerTragetServiceName.DELETE_VSP, ErrorLevel.ERROR.name(),
LoggerErrorCode.PERMISSION_ERROR.getErrorCode(), "Unsupported operation");
- mdcDataDebugMessage.debugExitMessage("VSP id", vspId);
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage("VSP id", vspId);
throw new UnsupportedOperationException(
VendorSoftwareProductConstants.UNSUPPORTED_OPERATION_ERROR);
@@ -866,7 +864,7 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa
@Override
public void heal(String vspId, Version version, String user) {
- mdcDataDebugMessage.debugEntryMessage("VSP id", vspId);
+ MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("VSP id", vspId);
VersionInfo versionInfo = getVersionInfo(vspId, VersionableEntityAction.Read, user);
@@ -882,17 +880,17 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa
vspDetails.setOldVersion(null);
vspInfoDao.updateOldVersionIndication(vspDetails);
- logger.audit("Healed VSP " + vspDetails.getId());
- mdcDataDebugMessage.debugExitMessage("VSP id", vspId);
+ LOGGER.audit("Healed VSP " + vspDetails.getId());
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage("VSP id", vspId);
- if (errorMessages.isPresent()) {
+ errorMessages.ifPresent(s -> {
throw new CoreException(new ErrorCode.ErrorCodeBuilder().withId("HEALING_ERROR")
- .withCategory(ErrorCategory.APPLICATION).withMessage(errorMessages.get()).build());
- }
+ .withCategory(ErrorCategory.APPLICATION).withMessage(s).build());
+ });
}
private void autoHeal(String vspId, Version checkoutVersion, VspDetails vspDetails, String user) {
- mdcDataDebugMessage.debugEntryMessage("VSP id", vspId);
+ MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("VSP id", vspId);
checkoutVersion.setStatus(VersionStatus.Locked);
Map<String, Object> healingParams = getHealingParamsAsMap(vspId, checkoutVersion, user);
@@ -903,13 +901,13 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa
vspDetails.setOldVersion(null);
vspInfoDao.updateOldVersionIndication(vspDetails);
- logger.audit("Healed VSP " + vspDetails.getName());
- mdcDataDebugMessage.debugExitMessage("VSP id", vspId);
+ LOGGER.audit("Healed VSP " + vspDetails.getName());
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage("VSP id", vspId);
- if (errorMessages.isPresent()) {
+ errorMessages.ifPresent(s -> {
throw new CoreException(new ErrorCode.ErrorCodeBuilder().withId("HEALING_ERROR")
- .withCategory(ErrorCategory.APPLICATION).withMessage(errorMessages.get()).build());
- }
+ .withCategory(ErrorCategory.APPLICATION).withMessage(s).build());
+ });
}
private Map<String, Object> getHealingParamsAsMap(String vspId, Version version, String user) {
@@ -929,7 +927,7 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa
@Override
public File getTranslatedFile(String vspId, Version version, String user) {
- mdcDataDebugMessage.debugEntryMessage("VSP id", vspId);
+ MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("VSP id", vspId);
String errorMessage;
if (version == null) {
errorMessage = "Package not found";
@@ -966,10 +964,8 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa
File translatedFile = new File(VendorSoftwareProductConstants.VSP_PACKAGE_ZIP);
- try {
- FileOutputStream fos = new FileOutputStream(translatedFile);
+ try (FileOutputStream fos = new FileOutputStream(translatedFile)) {
fos.write(translatedFileBuffer.array());
- fos.close();
} catch (IOException exception) {
errorMessage = "Can't create package";
MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
@@ -979,7 +975,7 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa
exception);
}
- mdcDataDebugMessage.debugExitMessage("VSP id", vspId);
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage("VSP id", vspId);
return translatedFile;
}
@@ -987,7 +983,7 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa
@Override
public byte[] getOrchestrationTemplateFile(String vspId, Version version, String user) {
- mdcDataDebugMessage.debugEntryMessage("VSP id", vspId);
+ MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("VSP id", vspId);
UploadDataEntity uploadData = orchestrationTemplateDao.getOrchestrationTemplate(vspId, version);
ByteBuffer contentData = uploadData.getContentData();
@@ -1008,13 +1004,13 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa
throw new CoreException(new FileCreationErrorBuilder(vspId).build(), exception);
}
- mdcDataDebugMessage.debugExitMessage("VSP id", vspId);
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage("VSP id", vspId);
return baos.toByteArray();
}
@Override
public PackageInfo createPackage(String vspId, Version version, String user) throws IOException {
- mdcDataDebugMessage.debugEntryMessage("VSP id", vspId);
+ MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("VSP id", vspId);
if (!version.isFinal()) {
MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
@@ -1042,9 +1038,9 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa
packageInfoDao.create(packageInfo);
- logger.audit(AuditMessages.AUDIT_MSG + AuditMessages.CREATE_PACKAGE + vspId);
+ LOGGER.audit(AuditMessages.AUDIT_MSG + AuditMessages.CREATE_PACKAGE + vspId);
- mdcDataDebugMessage.debugExitMessage("VSP id", vspId);
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage("VSP id", vspId);
return packageInfo;
}
@@ -1065,7 +1061,7 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa
@Override
public QuestionnaireResponse getVspQuestionnaire(String vspId, Version version, String user) {
- mdcDataDebugMessage.debugEntryMessage("VSP id", vspId);
+ MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("VSP id", vspId);
VspQuestionnaireEntity retrieved = vspInfoDao.getQuestionnaire(vspId, version);
VersioningUtil.validateEntityExistence(retrieved, new VspQuestionnaireEntity(vspId, version),
@@ -1077,7 +1073,7 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa
questionnaireResponse.setData(questionnaireData);
questionnaireResponse.setSchema(getVspQuestionnaireSchema(null));
- mdcDataDebugMessage.debugExitMessage("VSP id", vspId);
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage("VSP id", vspId);
return questionnaireResponse;
}
@@ -1085,11 +1081,11 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa
@Override
public void updateVspQuestionnaire(String vspId, Version version, String questionnaireData,
String user) {
- mdcDataDebugMessage.debugEntryMessage("VSP id", vspId);
+ MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("VSP id", vspId);
vspInfoDao.updateQuestionnaireData(vspId, version, questionnaireData);
- mdcDataDebugMessage.debugExitMessage("VSP id", vspId);
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage("VSP id", vspId);
}
@@ -1128,7 +1124,7 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa
private QuestionnaireValidationResult validateQuestionnaire(String vspId, Version version,
String onboardingMethod) {
- mdcDataDebugMessage.debugEntryMessage("VSP id", vspId);
+ MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("VSP id", vspId);
// The apis of CompositionEntityDataManager used here are stateful!
// so, it must be re-created from scratch when it is used!
@@ -1174,18 +1170,18 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa
compositionEntityDataManager.getEntityListWithErrors();*/
//Collection<CompositionEntityValidationData> roots = compositionEntityDataManager.getTrees();
- mdcDataDebugMessage.debugExitMessage("VSP id", vspId);
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage("VSP id", vspId);
return new QuestionnaireValidationResult(
compositionEntityDataManager.getAllErrorsByVsp(vspId));
}
- mdcDataDebugMessage.debugExitMessage("VSP id", vspId);
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage("VSP id", vspId);
return null;
}
@Override
public File getInformationArtifact(String vspId, Version version, String user) {
- mdcDataDebugMessage.debugEntryMessage("VSP id", vspId);
+ MDC_DATA_DEBUG_MESSAGE.debugEntryMessage("VSP id", vspId);
VspDetails vspDetails = vspInfoDao.get(new VspDetails(vspId, version));
if (vspDetails == null) {
@@ -1202,14 +1198,15 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa
infoArtifactFile =
new File(
String.format(VendorSoftwareProductConstants.INFORMATION_ARTIFACT_NAME, vspName));
- OutputStream out = new BufferedOutputStream(new FileOutputStream(infoArtifactFile));
- out.write(infoArtifactAsByteBuffer.array());
- out.close();
+ try (OutputStream out = new BufferedOutputStream(new FileOutputStream(infoArtifactFile))) {
+ out.write(infoArtifactAsByteBuffer.array());
+ }
+
} catch (IOException ex) {
throw new CoreException(new InformationArtifactCreationErrorBuilder(vspId).build(), ex);
}
- mdcDataDebugMessage.debugExitMessage("VSP id", vspId);
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage("VSP id", vspId);
return infoArtifactFile;
}
@@ -1239,7 +1236,7 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa
errorList.forEach(errorMessage -> {
if (errorMessage.getLevel().equals(ErrorLevel.ERROR)) {
- logger.audit(AuditMessages.AUDIT_MSG + String.format(auditType, errorMessage.getMessage(),
+ LOGGER.audit(AuditMessages.AUDIT_MSG + String.format(auditType, errorMessage.getMessage(),
vspId));
}
});
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());
}
}
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/ToscaConverterImplTest.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/ToscaConverterImplTest.java
index f29ca4a427..471e3891c7 100644
--- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/ToscaConverterImplTest.java
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/ToscaConverterImplTest.java
@@ -41,22 +41,18 @@ public class ToscaConverterImplTest {
private static final String VIRTUAL_LINK = "virtualLink";
private static final String UNBOUNDED = "UNBOUNDED";
- private static String inputFilesPath;
- private static String outputFilesPath;
- private static Map<String, ServiceTemplate> expectedOutserviceTemplates;
-
@Test
public void testConvertMainSt() throws IOException {
- inputFilesPath = "/mock/toscaConverter/convertMainSt/in";
- outputFilesPath = "/mock/toscaConverter/convertMainSt/out";
+ String inputFilesPath = "/mock/toscaConverter/convertMainSt/in";
+ String outputFilesPath = "/mock/toscaConverter/convertMainSt/out";
FileContentHandler fileContentHandler =
createFileContentHandlerFromInput(inputFilesPath);
- expectedOutserviceTemplates = new HashMap<>();
+ Map<String, ServiceTemplate> expectedOutserviceTemplates = new HashMap<>();
loadServiceTemplates(outputFilesPath, new ToscaExtensionYamlUtil(),
- expectedOutserviceTemplates);
+ expectedOutserviceTemplates);
ToscaServiceModel toscaServiceModel = toscaConverter.convert(fileContentHandler);
ServiceTemplate mainSt = toscaServiceModel.getServiceTemplates().get(mainStName);
@@ -201,18 +197,15 @@ public class ToscaConverterImplTest {
private static void addServiceTemplateFiles(Map<String, ServiceTemplate> serviceTemplates,
File[] files,
- ToscaExtensionYamlUtil toscaExtensionYamlUtil)
- throws IOException {
+ ToscaExtensionYamlUtil toscaExtensionYamlUtil) throws IOException {
+
for (File file : files) {
+
try (InputStream yamlFile = new FileInputStream(file)) {
ServiceTemplate serviceTemplateFromYaml =
toscaExtensionYamlUtil.yamlToObject(yamlFile, ServiceTemplate.class);
createConcreteRequirementObjectsInServiceTemplate(serviceTemplateFromYaml, toscaExtensionYamlUtil);
serviceTemplates.put(file.getName(), serviceTemplateFromYaml);
- try {
- yamlFile.close();
- } catch (IOException ignore) {
- }
}
}
}