From 6cc9a11a09a9b650442bf301eb8fd1aa6cad66bc Mon Sep 17 00:00:00 2001 From: Idan Amit Date: Wed, 13 Sep 2017 17:21:33 +0300 Subject: ComponentBaseTest.java enhancement and new onboarding class that test onboarding only And merge release/1710 branch into master Change-Id: I300d897b151010aa26f8732518fa2e3b7ed4291b Issue-Id: SDC-331 Signed-off-by: Idan Amit --- .../be/components/impl/ArtifactsBusinessLogic.java | 12 +- .../be/components/impl/CsarValidationUtils.java | 2 +- .../be/components/impl/ResourceBusinessLogic.java | 155 +++++++++++++-------- .../be/components/impl/ServiceBusinessLogic.java | 2 +- .../servlet/ArtifactExternalServlet.java | 16 +-- .../be/externalapi/servlet/AssetsDataServlet.java | 2 +- .../be/servlets/AbstractValidationsServlet.java | 2 +- .../be/tosca/CapabiltyRequirementConvertor.java | 11 +- .../java/org/openecomp/sdc/be/tosca/CsarUtils.java | 6 +- 9 files changed, 123 insertions(+), 85 deletions(-) (limited to 'catalog-be/src/main/java') diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java index 61f0c02d10..74bb55b63d 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java @@ -355,7 +355,7 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic { } byte[] decodedPayload = artifactDefinition.getPayloadData(); artifactDefinition.setEsId(artifactDefinition.getUniqueId()); - artifactDefinition.setArtifactChecksum(GeneralUtility.calculateMD5ByByteArray(decodedPayload)); + artifactDefinition.setArtifactChecksum(GeneralUtility.calculateMD5Base64EncodedByByteArray(decodedPayload)); return lockComponentAndUpdateArtifact(component.getUniqueId(), artifactDefinition, AuditingActionEnum.ARTIFACT_PAYLOAD_UPDATE, artifactDefinition.getUniqueId(), user, component.getComponentType(), component, decodedPayload, null, null, shouldLock, inTransaction); @@ -1007,7 +1007,7 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic { private Either validateMd5(String origMd5, String originData, byte[] payload, ArtifactOperationInfo operation) { if (origMd5 != null) { - String encodeBase64Str = GeneralUtility.calculateMD5ByString(originData); + String encodeBase64Str = GeneralUtility.calculateMD5Base64EncodedByString(originData); if (false == encodeBase64Str.equals(origMd5)) { log.debug("The calculated md5 is different then the received one"); @@ -2754,7 +2754,7 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic { return Either.right(responseFormat); } - String checkSum = GeneralUtility.calculateMD5ByByteArray(decodedPayload); + String checkSum = GeneralUtility.calculateMD5Base64EncodedByByteArray(decodedPayload); artifactInfo.setArtifactChecksum(checkSum); log.trace("Calculated checksum, base64 payload: {}, checksum: {}", payload, checkSum); @@ -3642,7 +3642,7 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic { return Either.right(artifactDataRes.right().value()); } - String newCheckSum = GeneralUtility.calculateMD5ByByteArray(artifactData.getDataAsArray()); + String newCheckSum = GeneralUtility.calculateMD5Base64EncodedByByteArray(artifactData.getDataAsArray()); String oldCheckSum; String esArtifactId = artifactDefinition.getEsId(); Either artifactfromES; @@ -3657,7 +3657,7 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic { return Either.right(componentsUtils.getResponseFormatByArtifactId(actionStatus, artifactDefinition.getArtifactDisplayName())); } esArtifactData = artifactfromES.left().value(); - oldCheckSum = GeneralUtility.calculateMD5ByByteArray(esArtifactData.getDataAsArray()); + oldCheckSum = GeneralUtility.calculateMD5Base64EncodedByByteArray(esArtifactData.getDataAsArray()); } else { oldCheckSum = artifactDefinition.getArtifactChecksum(); @@ -4696,7 +4696,7 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic { try { for (ArtifactDefinition artifact : artifactsToHandle) { originData = buildJsonStringForCsarVfcArtifact(artifact); - origMd5 = GeneralUtility.calculateMD5ByString(originData); + origMd5 = GeneralUtility.calculateMD5Base64EncodedByString(originData); actionResult = handleArtifactRequest(component.getUniqueId(), user.getUserId(), componentType, operation, artifact.getUniqueId(), artifact, origMd5, originData, null, null, null, null, shouldLock, inTransaction); if (actionResult.isRight()) { log.debug("Failed to upload artifact to component with type {} and name {}. Status is {}. ", componentType, component.getName(), actionResult.right().value()); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CsarValidationUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CsarValidationUtils.java index 3d280ab7ca..8198ef3d85 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CsarValidationUtils.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CsarValidationUtils.java @@ -307,7 +307,7 @@ public class CsarValidationUtils { return Either.right(toscaYamlRes.right().value()); } - String newCheckSum = GeneralUtility.calculateMD5ByByteArray(toscaYamlRes.left().value().getRight().getBytes()); + String newCheckSum = GeneralUtility.calculateMD5Base64EncodedByByteArray(toscaYamlRes.left().value().getRight().getBytes()); return Either.left(newCheckSum); } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java index 8fd28e1224..ba26576648 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java @@ -82,12 +82,12 @@ import org.openecomp.sdc.be.model.ComponentInstance; import org.openecomp.sdc.be.model.ComponentInstanceInput; import org.openecomp.sdc.be.model.ComponentInstanceProperty; import org.openecomp.sdc.be.model.ComponentParametersView; +import org.openecomp.sdc.be.model.CsarInfo; import org.openecomp.sdc.be.model.DataTypeDefinition; import org.openecomp.sdc.be.model.GroupDefinition; import org.openecomp.sdc.be.model.GroupProperty; import org.openecomp.sdc.be.model.GroupTypeDefinition; import org.openecomp.sdc.be.model.HeatParameterDefinition; -import org.openecomp.sdc.be.model.CsarInfo; import org.openecomp.sdc.be.model.InputDefinition; import org.openecomp.sdc.be.model.InterfaceDefinition; import org.openecomp.sdc.be.model.LifeCycleTransitionEnum; @@ -148,13 +148,13 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.context.WebApplicationContext; import org.yaml.snakeyaml.DumperOptions; import org.yaml.snakeyaml.Yaml; +import org.yaml.snakeyaml.parser.ParserException; import com.google.gson.Gson; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import fj.data.Either; -import org.yaml.snakeyaml.parser.ParserException; @org.springframework.stereotype.Component("resourceBusinessLogic") public class ResourceBusinessLogic extends ComponentBusinessLogic { @@ -624,7 +624,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { } preparedResource = createResourcesInstancesEither.left().value(); - createResourcesInstancesEither = createResourceInstancesRelations(csarInfo.getModifier(), yamlFileName, preparedResource, instances, inTransaction, shouldLock); + createResourcesInstancesEither = createResourceInstancesRelations(csarInfo.getModifier(), yamlFileName, preparedResource, instances); if (createResourcesInstancesEither.isRight()) { log.debug("failed to create relation between resource instances status is {}", createResourcesInstancesEither.right().value()); result = Either.right(createResourcesInstancesEither.right().value()); @@ -779,7 +779,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { if (!foundArtifact.getArtifactChecksum().equals(currNewArtifact.getArtifactChecksum())) { foundArtifact.setPayload(currNewArtifact.getPayloadData()); foundArtifact.setPayloadData(Base64.encodeBase64String(currNewArtifact.getPayloadData())); - foundArtifact.setArtifactChecksum(GeneralUtility.calculateMD5ByByteArray(currNewArtifact.getPayloadData())); + foundArtifact.setArtifactChecksum(GeneralUtility.calculateMD5Base64EncodedByByteArray(currNewArtifact.getPayloadData())); artifactsToUpdate.add(foundArtifact); } existingArtifacts.remove(foundArtifact.getArtifactLabel()); @@ -1461,7 +1461,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { String nameWithouNamespacePrefix = nodeName.substring(Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX.length()); String[] findTypes = nameWithouNamespacePrefix.split("\\."); String resourceType = findTypes[0]; - return resourceVfName + "-" + nameWithouNamespacePrefix.substring(resourceType.length() + 1); + return resourceVfName + "-" + nameWithouNamespacePrefix.substring(resourceType.length() + 1) + "Cvfc"; } private Either createResourceAndRIsFromYaml(String yamlName, Resource resource, ParsedToscaYamlInfo parsedToscaYamlInfo, AuditingActionEnum actionEnum, boolean isNormative, @@ -1633,7 +1633,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { List groupsToCreate = new ArrayList(); if (groupsFromResource != null && !groupsFromResource.isEmpty()) { for (GroupDefinition group : groupsAsList) { - Optional op = groupsFromResource.stream().filter(p -> p.getName().equals(group.getName())).findAny(); + Optional op = groupsFromResource.stream().filter(p -> p.getName().equalsIgnoreCase(group.getName())).findAny(); if (op.isPresent()) { GroupDefinition groupToUpdate = op.get(); groupToUpdate.setMembers(group.getMembers()); @@ -1643,7 +1643,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { } } for (GroupDefinition group : groupsFromResource) { - Optional op = groupsAsList.stream().filter(p -> p.getName().equals(group.getName())).findAny(); + Optional op = groupsAsList.stream().filter(p -> p.getName().equalsIgnoreCase(group.getName())).findAny(); if (!op.isPresent() && (group.getArtifacts() == null || group.getArtifacts().isEmpty())) { groupsToDelete.add(group); @@ -1651,7 +1651,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { } } else - groupsToCreate.addAll(groupsAsList); + groupsToCreate.addAll(groupsAsList); Either, ResponseFormat> prepareGroups = null; if (!groupsToCreate.isEmpty()) { @@ -1886,7 +1886,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { } resource = createResourcesInstancesEither.left().value(); log.debug("************* Going to create all relations {}", yamlName); - createResourcesInstancesEither = createResourceInstancesRelations(csarInfo.getModifier(), yamlName, resource, uploadComponentInstanceInfoMap, true, false); + createResourcesInstancesEither = createResourceInstancesRelations(csarInfo.getModifier(), yamlName, resource, uploadComponentInstanceInfoMap); log.debug("************* Finished to create all relations {}", yamlName); @@ -2087,7 +2087,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { String jsonStr = gson.toJson(json); - String origMd5 = GeneralUtility.calculateMD5ByString(jsonStr); + String origMd5 = GeneralUtility.calculateMD5Base64EncodedByString(jsonStr); ArtifactDefinition artifactDefinitionFromJson = RepresentationUtils.convertJsonToArtifactDefinition(jsonStr, ArtifactDefinition.class); String artifactUniqueId = artifactDefinitionFromJson == null ? null : artifactDefinitionFromJson.getUniqueId(); Either, ResponseFormat> uploadArtifactToService = artifactsBusinessLogic.validateAndHandleArtifact(resource.getUniqueId(), ComponentTypeEnum.RESOURCE, operation, artifactUniqueId, @@ -2416,7 +2416,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { for (ArtifactDefinition createdArtifact : createdDeplymentArtifactsAfterDelete) { if (artifactTemplate.getFileName().equalsIgnoreCase(createdArtifact.getArtifactName())) { arifactsUids.add(createdArtifact.getUniqueId()); - arifactsUuids.add(createdArtifact.getUniqueId()); + arifactsUuids.add(createdArtifact.getArtifactUUID()); isCreate = false; String heatEnvId = checkAndGetHeatEnvId(createdArtifact); if (!heatEnvId.isEmpty()) { @@ -2436,7 +2436,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { for (ArtifactDefinition createdNewArtifact : createdNewArtifacts) { if (artifactTemplate.getFileName().equalsIgnoreCase(createdNewArtifact.getArtifactName())) { arifactsUids.add(createdNewArtifact.getUniqueId()); - arifactsUuids.add(createdNewArtifact.getUniqueId()); + arifactsUuids.add(createdNewArtifact.getArtifactUUID()); isCreate = false; String heatEnvId = checkAndGetHeatEnvId(createdNewArtifact); if (!heatEnvId.isEmpty()) { @@ -2455,7 +2455,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { } ArtifactDefinition createdArtifact = createArtifactEither.left().value(); arifactsUids.add(createdArtifact.getUniqueId()); - arifactsUuids.add(createdArtifact.getUniqueId()); + arifactsUuids.add(createdArtifact.getArtifactUUID()); ArtifactTypeEnum artifactType = ArtifactTypeEnum.findType(createdArtifact.getArtifactType()); if (artifactType == ArtifactTypeEnum.HEAT || artifactType == ArtifactTypeEnum.HEAT_NET || artifactType == ArtifactTypeEnum.HEAT_VOL) { Either createHeatEnvPlaceHolder = artifactsBusinessLogic.createHeatEnvPlaceHolder(createdArtifact, ArtifactsBusinessLogic.HEAT_VF_ENV_NAME, resource.getUniqueId(), NodeTypeEnum.Resource, @@ -3532,7 +3532,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { return Either.left(artifactTemplateInfoList); } - private Either createResourceInstancesRelations(User user, String yamlName, Resource resource, Map uploadResInstancesMap, boolean inTransaction, boolean needLock) { + private Either createResourceInstancesRelations(User user, String yamlName, Resource resource, Map uploadResInstancesMap) { log.debug("createResourceInstancesRelations try to create relations "); List componentInstancesList = resource.getComponentInstances(); if (uploadResInstancesMap == null) { @@ -3590,7 +3590,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { return Either.right(responseFormat); } String resourceInstanceId = currentCompInstance.getUniqueId(); - Resource originResource = null; + Resource originResource; if (!originCompMap.containsKey(currentCompInstance.getComponentUid())) { Either getOriginResourceRes = toscaOperationFacade.getToscaFullElement(currentCompInstance.getComponentUid()); if (getOriginResourceRes.isRight()) { @@ -3603,38 +3603,10 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { } else { originResource = originCompMap.get(currentCompInstance.getComponentUid()); } - if (originResource.getCapabilities() != null && !originResource.getCapabilities().isEmpty()) { - Map> originCapabilities ; - if (MapUtils.isNotEmpty(uploadComponentInstanceInfo.getCapabilitiesNamesToUpdate()) && resource.getResourceType() == ResourceTypeEnum.CVFC) { - originCapabilities = new HashMap<>(); - originResource.getCapabilities().entrySet().stream().forEach(e ->{ - List list = e.getValue().stream().map(l -> new CapabilityDefinition(l)).collect(Collectors.toList()); - originCapabilities.put(e.getKey(), list); - }); - for (List capabilities : originCapabilities.values()) { - capabilities.stream().filter(c -> uploadComponentInstanceInfo.getCapabilitiesNamesToUpdate().containsKey(c.getName())).forEach(c -> c.setName(uploadComponentInstanceInfo.getCapabilitiesNamesToUpdate().get(c.getName()))); - } - }else{ - originCapabilities = originResource.getCapabilities(); - } - instCapabilties.put(currentCompInstance, originCapabilities); - } - if (originResource.getRequirements() != null && !originResource.getRequirements().isEmpty()) { - Map> originRequirements; - if (MapUtils.isNotEmpty(uploadComponentInstanceInfo.getRequirementsNamesToUpdate()) && resource.getResourceType() == ResourceTypeEnum.CVFC) { - originRequirements = new HashMap<>(); - originResource.getRequirements().entrySet().stream().forEach(e ->{ - List list = e.getValue().stream().map(l -> new RequirementDefinition(l)).collect(Collectors.toList()); - originRequirements.put(e.getKey(), list); - }); - for (List requirements : originRequirements.values()) { - requirements.stream().filter(r -> uploadComponentInstanceInfo.getRequirementsNamesToUpdate().containsKey(r.getName())).forEach(r -> r.setName(uploadComponentInstanceInfo.getRequirementsNamesToUpdate().get(r.getName()))); - } - }else{ - originRequirements = originResource.getRequirements(); - } - instRequirements.put(currentCompInstance, originRequirements); - } + if (originResource.getCapabilities() != null && !originResource.getCapabilities().isEmpty()) + instCapabilties.put(currentCompInstance, originResource.getCapabilities()); + if (originResource.getRequirements() != null && !originResource.getRequirements().isEmpty()) + instRequirements.put(currentCompInstance, originResource.getRequirements()); if (originResource.getDeploymentArtifacts() != null && !originResource.getDeploymentArtifacts().isEmpty()) instDeploymentArtifacts.put(resourceInstanceId, originResource.getDeploymentArtifacts()); if (originResource.getArtifacts() != null && !originResource.getArtifacts().isEmpty()) @@ -3711,16 +3683,16 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { parametersView.setIgnoreCapabilities(false); parametersView.setIgnoreRequirements(false); - Either eitherGerResource = toscaOperationFacade.getToscaElement(resource.getUniqueId(), parametersView); + Either eitherGetResource = toscaOperationFacade.getToscaElement(resource.getUniqueId(), parametersView); - if (eitherGerResource.isRight()) { - ResponseFormat responseFormat = componentsUtils.getResponseFormatByResource(componentsUtils.convertFromStorageResponse(eitherGerResource.right().value()), resource); + if (eitherGetResource.isRight()) { + ResponseFormat responseFormat = componentsUtils.getResponseFormatByResource(componentsUtils.convertFromStorageResponse(eitherGetResource.right().value()), resource); return Either.right(responseFormat); } - resource = eitherGerResource.left().value(); + resource = eitherGetResource.left().value(); for (Entry entry : uploadResInstancesMap.entrySet()) { UploadComponentInstanceInfo uploadComponentInstanceInfo = entry.getValue(); @@ -3755,15 +3727,88 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { log.debug("************* in create relations, getResource start"); - eitherGerResource = toscaOperationFacade.getToscaElement(resource.getUniqueId()); + eitherGetResource = toscaOperationFacade.getToscaElement(resource.getUniqueId()); log.debug("************* in create relations, getResource end"); - if (eitherGerResource.isRight()) { - ResponseFormat responseFormat = componentsUtils.getResponseFormatByResource(componentsUtils.convertFromStorageResponse(eitherGerResource.right().value()), resource); + if (eitherGetResource.isRight()) { + ResponseFormat responseFormat = componentsUtils.getResponseFormatByResource(componentsUtils.convertFromStorageResponse(eitherGetResource.right().value()), resource); return Either.right(responseFormat); } - return Either.left(eitherGerResource.left().value()); + resource = eitherGetResource.left().value(); + if(resource.getResourceType() == ResourceTypeEnum.CVFC){ + eitherGetResource = updateCalculatedCapReqWithSubstitutionMappings(resource, uploadResInstancesMap); + if (eitherGetResource.isRight()) { + ResponseFormat responseFormat = componentsUtils.getResponseFormatByResource(componentsUtils.convertFromStorageResponse(eitherGetResource.right().value()), resource); + return Either.right(responseFormat); + } + } + return Either.left(eitherGetResource.left().value()); + } + + private Either updateCalculatedCapReqWithSubstitutionMappings(Resource resource, Map uploadResInstancesMap) { + Either updateRes = null; + Map>> updatedInstCapabilities = new HashMap<>(); + Map>> updatedInstRequirements = new HashMap<>(); + StorageOperationStatus status = toscaOperationFacade.deleteAllCalculatedCapabilitiesRequirements( resource.getUniqueId()); + if(status != StorageOperationStatus.OK && status != StorageOperationStatus.NOT_FOUND){ + log.debug("Failed to delete all calculated capabilities and requirements of resource {} upon update. Status is {}", resource.getUniqueId(), status); + updateRes = Either.right(status); + } + if(updateRes == null){ + fillUpdatedInstCapabilitiesRequirements(resource.getComponentInstances(), uploadResInstancesMap, updatedInstCapabilities, updatedInstRequirements); + status = toscaOperationFacade.associateCalculatedCapReq(updatedInstCapabilities, updatedInstRequirements, resource.getUniqueId()); + if (status != StorageOperationStatus.OK && status != StorageOperationStatus.NOT_FOUND) { + log.debug("Failed to associate capabilities and requirementss of resource {}, updated according to a substitution mapping. Status is {}", resource.getUniqueId(), status); + updateRes = Either.right(status); + } + } + if(updateRes == null){ + updateRes = toscaOperationFacade.getToscaElement( resource.getUniqueId()); + } + return updateRes; + } + + + private void fillUpdatedInstCapabilitiesRequirements(List componentInstances, Map uploadResInstancesMap, + Map>> updatedInstCapabilities, Map>> updatedInstRequirements) { + + componentInstances.stream().forEach( i -> { + fillUpdatedInstCapabilities(updatedInstCapabilities, i, uploadResInstancesMap.get(i.getName()).getCapabilitiesNamesToUpdate()); + fillUpdatedInstRequirements(updatedInstRequirements, i, uploadResInstancesMap.get(i.getName()).getRequirementsNamesToUpdate()); + }); + } + + private void fillUpdatedInstRequirements(Map>> updatedInstRequirements, ComponentInstance instance, Map requirementsNamesToUpdate) { + Map> updatedRequirements = new HashMap<>(); + Set updatedReqNames = new HashSet<>(); + if(MapUtils.isNotEmpty(requirementsNamesToUpdate)){ + for (Map.Entry> requirements : instance.getRequirements().entrySet()) { + updatedRequirements.put(requirements.getKey(), requirements.getValue().stream() + .filter(r -> requirementsNamesToUpdate.containsKey(r.getName()) && !updatedReqNames.contains(requirementsNamesToUpdate.get(r.getName()))) + .map(r ->{r.setParentName(r.getName()); r.setName(requirementsNamesToUpdate.get(r.getName())); updatedReqNames.add(r.getName()); return r;}) + .collect(Collectors.toList())); + } + } + if(MapUtils.isNotEmpty(updatedRequirements)){ + updatedInstRequirements.put(instance, updatedRequirements); + } + } + + private void fillUpdatedInstCapabilities(Map>> updatedInstCapabilties, ComponentInstance instance, Map capabilitiesNamesToUpdate) { + Map> updatedCapabilities = new HashMap<>(); + Set updatedCapNames = new HashSet<>(); + if(MapUtils.isNotEmpty(capabilitiesNamesToUpdate)){ + for (Map.Entry> requirements : instance.getCapabilities().entrySet()) { + updatedCapabilities.put(requirements.getKey(), requirements.getValue().stream() + .filter(c -> capabilitiesNamesToUpdate.containsKey(c.getName()) && !updatedCapNames.contains(capabilitiesNamesToUpdate.get(c.getName()))) + .map(c -> {c.setParentName(c.getName()); c.setName(capabilitiesNamesToUpdate.get(c.getName())); updatedCapNames.add(c.getName()); return c;}) + .collect(Collectors.toList())); + } + } + if(MapUtils.isNotEmpty(updatedCapabilities)){ + updatedInstCapabilties.put(instance, updatedCapabilities); + } } private ResponseFormat addRelationToRI(String yamlName, Resource resource, UploadComponentInstanceInfo nodesInfoValue, List relations) { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java index 85db9a2c0f..89c444b6d9 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java @@ -1616,7 +1616,7 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic { vfModuleArtifactDefinition.setArtifactName(currVF.getNormalizedName() + "_modules.json"); vfModuleArtifactDefinition.setPayloadData(vfModulePayloadString); if (vfModulePayloadString != null) { - newCheckSum = GeneralUtility.calculateMD5ByByteArray(vfModulePayloadString.getBytes()); + newCheckSum = GeneralUtility.calculateMD5Base64EncodedByByteArray(vfModulePayloadString.getBytes()); } vfModuleArtifactDefinition.setArtifactChecksum(newCheckSum); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/ArtifactExternalServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/ArtifactExternalServlet.java index 32293ca9b7..1c2f175cfb 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/ArtifactExternalServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/ArtifactExternalServlet.java @@ -166,7 +166,7 @@ public class ArtifactExternalServlet extends AbstractValidationsServlet { } else { Object representation = RepresentationUtils.toRepresentation(uploadArtifactEither.left().value()); Map headers = new HashMap<>(); - headers.put(Constants.MD5_HEADER, GeneralUtility.calculateMD5ByString((String) representation)); + headers.put(Constants.MD5_HEADER, GeneralUtility.calculateMD5Base64EncodedByString((String) representation)); responseWrapper.setInnerElement(getComponentsUtils().getResponseFormat(ActionStatus.OK)); response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), representation, headers); } @@ -263,7 +263,7 @@ public class ArtifactExternalServlet extends AbstractValidationsServlet { } else { Object representation = RepresentationUtils.toRepresentation(uploadArtifactEither.left().value()); Map headers = new HashMap<>(); - headers.put(Constants.MD5_HEADER, GeneralUtility.calculateMD5ByString((String) representation)); + headers.put(Constants.MD5_HEADER, GeneralUtility.calculateMD5Base64EncodedByString((String) representation)); responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK); responseWrapper.setInnerElement(buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), representation, headers)); } @@ -363,7 +363,7 @@ public class ArtifactExternalServlet extends AbstractValidationsServlet { } else { Object representation = RepresentationUtils.toRepresentation(uploadArtifactEither.left().value()); Map headers = new HashMap<>(); - headers.put(Constants.MD5_HEADER, GeneralUtility.calculateMD5ByString((String) representation)); + headers.put(Constants.MD5_HEADER, GeneralUtility.calculateMD5Base64EncodedByString((String) representation)); responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK); responseWrapper.setInnerElement(buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), representation, headers)); } @@ -459,7 +459,7 @@ public class ArtifactExternalServlet extends AbstractValidationsServlet { } else { Object representation = RepresentationUtils.toRepresentation(uploadArtifactEither.left().value()); Map headers = new HashMap<>(); - headers.put(Constants.MD5_HEADER, GeneralUtility.calculateMD5ByString((String) representation)); + headers.put(Constants.MD5_HEADER, GeneralUtility.calculateMD5Base64EncodedByString((String) representation)); responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK); responseWrapper.setInnerElement(buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), representation, headers)); } @@ -550,7 +550,7 @@ public class ArtifactExternalServlet extends AbstractValidationsServlet { } else { Object representation = RepresentationUtils.toRepresentation(uploadArtifactEither.left().value()); Map headers = new HashMap<>(); - headers.put(Constants.MD5_HEADER, GeneralUtility.calculateMD5ByString((String) representation)); + headers.put(Constants.MD5_HEADER, GeneralUtility.calculateMD5Base64EncodedByString((String) representation)); responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK); responseWrapper.setInnerElement(buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), representation, headers)); } @@ -641,7 +641,7 @@ public class ArtifactExternalServlet extends AbstractValidationsServlet { } else { Object representation = RepresentationUtils.toRepresentation(uploadArtifactEither.left().value()); Map headers = new HashMap<>(); - headers.put(Constants.MD5_HEADER, GeneralUtility.calculateMD5ByString((String) representation)); + headers.put(Constants.MD5_HEADER, GeneralUtility.calculateMD5Base64EncodedByString((String) representation)); responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK); responseWrapper.setInnerElement(buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), representation, headers)); } @@ -719,7 +719,7 @@ public class ArtifactExternalServlet extends AbstractValidationsServlet { byte[] value = downloadComponentArtifactEither.left().value(); InputStream is = new ByteArrayInputStream(value); Map headers = new HashMap<>(); - headers.put(Constants.MD5_HEADER, GeneralUtility.calculateMD5ByByteArray(value)); + headers.put(Constants.MD5_HEADER, GeneralUtility.calculateMD5Base64EncodedByByteArray(value)); responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK); responseWrapper.setInnerElement(buildOkResponse(responseFormat, is, headers)); } @@ -800,7 +800,7 @@ public class ArtifactExternalServlet extends AbstractValidationsServlet { byte[] value = downloadResourceArtifactEither.left().value(); InputStream is = new ByteArrayInputStream(value); Map headers = new HashMap<>(); - headers.put(Constants.MD5_HEADER, GeneralUtility.calculateMD5ByByteArray(value)); + headers.put(Constants.MD5_HEADER, GeneralUtility.calculateMD5Base64EncodedByByteArray(value)); responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK); responseWrapper.setInnerElement(buildOkResponse(responseFormat, is, headers)); } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/AssetsDataServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/AssetsDataServlet.java index f96e226d26..6e971f215d 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/AssetsDataServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/AssetsDataServlet.java @@ -352,7 +352,7 @@ public class AssetsDataServlet extends AbstractValidationsServlet { } else { byte[] value = csarArtifact.left().value().getRight(); InputStream is = new ByteArrayInputStream(value); - String contenetMD5 = GeneralUtility.calculateMD5ByByteArray(value); + String contenetMD5 = GeneralUtility.calculateMD5Base64EncodedByByteArray(value); Map headers = new HashMap<>(); headers.put(Constants.CONTENT_DISPOSITION_HEADER, getContentDispositionValue(csarArtifact.left().value().getLeft())); headers.put(Constants.MD5_HEADER, contenetMD5); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AbstractValidationsServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AbstractValidationsServlet.java index 55ad44db0c..f1dd1539b4 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AbstractValidationsServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AbstractValidationsServlet.java @@ -458,7 +458,7 @@ public abstract class AbstractValidationsServlet extends BeGenericServlet { if (recievedMD5 == null) { isValid = false; } else { - String calculateMD5 = GeneralUtility.calculateMD5ByString(resourceInfoJsonString); + String calculateMD5 = GeneralUtility.calculateMD5Base64EncodedByString(resourceInfoJsonString); isValid = calculateMD5.equals(recievedMD5); } if (!isValid) { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CapabiltyRequirementConvertor.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CapabiltyRequirementConvertor.java index 6c4c5fafe1..006c5c22d3 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CapabiltyRequirementConvertor.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CapabiltyRequirementConvertor.java @@ -187,7 +187,7 @@ public class CapabiltyRequirementConvertor { String sourceCapName; if(ToscaUtils.isComplexVfc(component)){ fullReqName = r.getName(); - sourceCapName = getSourceCvfcDataTypeName(r.getName(), r.getOwnerName()); + sourceCapName = r.getParentName(); } else { fullReqName = getRequirementPath(r); sourceCapName = getSubPathByFirstDelimiterAppearance(fullReqName); @@ -205,13 +205,6 @@ public class CapabiltyRequirementConvertor { return toscaRequirements; } - private String getSourceCvfcDataTypeName(String name, String ownerName) { - if(name.contains(ownerName)){ - return name.substring(0, name.length() - ownerName.length() - 1); - } - return null; - } - private String getRequirementPath(RequirementDefinition r) { List pathArray = Lists.reverse(r.getPath().stream() .map(path -> ValidationUtils.normalizeComponentInstanceName(getSubPathByLastDelimiterAppearance(path))) @@ -275,7 +268,7 @@ public class CapabiltyRequirementConvertor { String sourceReqName; if(ToscaUtils.isComplexVfc(component)){ fullCapName = c.getName(); - sourceReqName = getSourceCvfcDataTypeName(c.getName(), c.getOwnerName()); + sourceReqName = c.getParentName(); } else { fullCapName = getCapabilityPath(c); sourceReqName = getSubPathByFirstDelimiterAppearance(fullCapName); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java index 85b1927548..66627086f6 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java @@ -633,7 +633,7 @@ public class CsarUtils { for (ArtifactDefinition artDef : generatedArtifactsDefinitions) { String data = gson.toJson(artDef); - String dataMD5 = GeneralUtility.calculateMD5ByString(data); + String dataMD5 = GeneralUtility.calculateMD5Base64EncodedByString(data); String artifactUniqueId = null; if ((operationType.getArtifactOperationEnum() == ArtifactOperationEnum.Update) || (operationType.getArtifactOperationEnum() == ArtifactOperationEnum.Delete)) { @@ -941,7 +941,7 @@ public class CsarUtils { artifact.setArtifactDisplayName(artifact.getArtifactName().lastIndexOf('.') > 0 ? artifact.getArtifactName().substring(0, artifact.getArtifactName().lastIndexOf('.')) : artifact.getArtifactName()); artifact.setArtifactLabel(ValidationUtils.normalizeArtifactLabel(artifact.getArtifactName())); artifact.setDescription(ARTIFACT_CREATED_FROM_CSAR); - artifact.setArtifactChecksum(GeneralUtility.calculateMD5ByByteArray(entry.getValue())); + artifact.setArtifactChecksum(GeneralUtility.calculateMD5Base64EncodedByByteArray(entry.getValue())); return artifact; } @@ -971,7 +971,7 @@ public class CsarUtils { this.artifactLabel = ValidationUtils.normalizeArtifactLabel(artifactName); if (payloadData != null) { this.payloadData = Base64.encodeBase64String(payloadData); - this.artifactChecksum = GeneralUtility.calculateMD5ByByteArray(payloadData); + this.artifactChecksum = GeneralUtility.calculateMD5Base64EncodedByByteArray(payloadData); } this.artifactUniqueId = artifactUniqueId; } -- cgit 1.2.3-korg