aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be
diff options
context:
space:
mode:
authorIdan Amit <ia096e@intl.att.com>2017-09-13 17:21:33 +0300
committerIdan Amit <ia096e@intl.att.com>2017-09-13 17:21:33 +0300
commit6cc9a11a09a9b650442bf301eb8fd1aa6cad66bc (patch)
treed7a891f71608fd32b1a5a61054530ce0244fe149 /catalog-be
parent45e38d57442499a535f2915aab95a057e106d79f (diff)
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 <ia096e@intl.att.com>
Diffstat (limited to 'catalog-be')
-rw-r--r--catalog-be/pom.xml5
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java12
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CsarValidationUtils.java2
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java155
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java2
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/ArtifactExternalServlet.java16
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/AssetsDataServlet.java2
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AbstractValidationsServlet.java2
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CapabiltyRequirementConvertor.java11
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java6
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java8
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ResourceServletTest.java2
12 files changed, 130 insertions, 93 deletions
diff --git a/catalog-be/pom.xml b/catalog-be/pom.xml
index 6d34402ac5..8b638e84d7 100644
--- a/catalog-be/pom.xml
+++ b/catalog-be/pom.xml
@@ -320,9 +320,8 @@
</dependency>
<dependency>
- <groupId>com.thinkaurelius.titan</groupId>
- <artifactId>titan-cassandra</artifactId>
- <!--<artifactId>asdc-titan-cassandra</artifactId>-->
+ <groupId>org.openecomp.sdc.sdc-titan-cassandra</groupId>
+ <artifactId>sdc-titan-cassandra</artifactId>
<version>${titan.version}</version>
<scope>compile</scope>
<exclusions>
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<Boolean, ResponseFormat> 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<ESArtifactData, CassandraOperationStatus> 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<Resource, ResponseFormat> createResourceAndRIsFromYaml(String yamlName, Resource resource, ParsedToscaYamlInfo parsedToscaYamlInfo, AuditingActionEnum actionEnum, boolean isNormative,
@@ -1633,7 +1633,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic {
List<GroupDefinition> groupsToCreate = new ArrayList<GroupDefinition>();
if (groupsFromResource != null && !groupsFromResource.isEmpty()) {
for (GroupDefinition group : groupsAsList) {
- Optional<GroupDefinition> op = groupsFromResource.stream().filter(p -> p.getName().equals(group.getName())).findAny();
+ Optional<GroupDefinition> 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<GroupDefinition> op = groupsAsList.stream().filter(p -> p.getName().equals(group.getName())).findAny();
+ Optional<GroupDefinition> 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<List<GroupDefinition>, 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<Either<ArtifactDefinition, Operation>, 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<ArtifactDefinition, ResponseFormat> 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<Resource, ResponseFormat> createResourceInstancesRelations(User user, String yamlName, Resource resource, Map<String, UploadComponentInstanceInfo> uploadResInstancesMap, boolean inTransaction, boolean needLock) {
+ private Either<Resource, ResponseFormat> createResourceInstancesRelations(User user, String yamlName, Resource resource, Map<String, UploadComponentInstanceInfo> uploadResInstancesMap) {
log.debug("createResourceInstancesRelations try to create relations ");
List<ComponentInstance> 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<Resource, StorageOperationStatus> 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<String, List<CapabilityDefinition>> originCapabilities ;
- if (MapUtils.isNotEmpty(uploadComponentInstanceInfo.getCapabilitiesNamesToUpdate()) && resource.getResourceType() == ResourceTypeEnum.CVFC) {
- originCapabilities = new HashMap<>();
- originResource.getCapabilities().entrySet().stream().forEach(e ->{
- List<CapabilityDefinition> list = e.getValue().stream().map(l -> new CapabilityDefinition(l)).collect(Collectors.toList());
- originCapabilities.put(e.getKey(), list);
- });
- for (List<CapabilityDefinition> 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<String, List<RequirementDefinition>> originRequirements;
- if (MapUtils.isNotEmpty(uploadComponentInstanceInfo.getRequirementsNamesToUpdate()) && resource.getResourceType() == ResourceTypeEnum.CVFC) {
- originRequirements = new HashMap<>();
- originResource.getRequirements().entrySet().stream().forEach(e ->{
- List<RequirementDefinition> list = e.getValue().stream().map(l -> new RequirementDefinition(l)).collect(Collectors.toList());
- originRequirements.put(e.getKey(), list);
- });
- for (List<RequirementDefinition> 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<Resource, StorageOperationStatus> eitherGerResource = toscaOperationFacade.getToscaElement(resource.getUniqueId(), parametersView);
+ Either<Resource, StorageOperationStatus> 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<String, UploadComponentInstanceInfo> 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<Resource, StorageOperationStatus> updateCalculatedCapReqWithSubstitutionMappings(Resource resource, Map<String, UploadComponentInstanceInfo> uploadResInstancesMap) {
+ Either<Resource, StorageOperationStatus> updateRes = null;
+ Map<ComponentInstance, Map<String, List<CapabilityDefinition>>> updatedInstCapabilities = new HashMap<>();
+ Map<ComponentInstance, Map<String, List<RequirementDefinition>>> 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<ComponentInstance> componentInstances, Map<String, UploadComponentInstanceInfo> uploadResInstancesMap,
+ Map<ComponentInstance, Map<String, List<CapabilityDefinition>>> updatedInstCapabilities, Map<ComponentInstance, Map<String, List<RequirementDefinition>>> 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<ComponentInstance, Map<String, List<RequirementDefinition>>> updatedInstRequirements, ComponentInstance instance, Map<String, String> requirementsNamesToUpdate) {
+ Map<String, List<RequirementDefinition>> updatedRequirements = new HashMap<>();
+ Set<String> updatedReqNames = new HashSet<>();
+ if(MapUtils.isNotEmpty(requirementsNamesToUpdate)){
+ for (Map.Entry<String, List<RequirementDefinition>> 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<ComponentInstance, Map<String, List<CapabilityDefinition>>> updatedInstCapabilties, ComponentInstance instance, Map<String, String> capabilitiesNamesToUpdate) {
+ Map<String, List<CapabilityDefinition>> updatedCapabilities = new HashMap<>();
+ Set<String> updatedCapNames = new HashSet<>();
+ if(MapUtils.isNotEmpty(capabilitiesNamesToUpdate)){
+ for (Map.Entry<String, List<CapabilityDefinition>> 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<RequirementCapabilityRelDef> 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<String, String> 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<String, String> 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<String, String> 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<String, String> 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<String, String> 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<String, String> 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<String, String> 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<String, String> 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<String, String> 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<String> 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;
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java
index f3c7a7d24c..c47400bcdb 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java
@@ -1498,14 +1498,14 @@ public class ResourceBusinessLogicTest {
deploymentArtifactToUpdate.setArtifactName(deploymentArtifactToUpdateFileName);
deploymentArtifactToUpdate.setArtifactType("SNMP_POLL");
deploymentArtifactToUpdate.setPayload(oldPayloadData);
- deploymentArtifactToUpdate.setArtifactChecksum(GeneralUtility.calculateMD5ByByteArray(oldPayloadData));
+ deploymentArtifactToUpdate.setArtifactChecksum(GeneralUtility.calculateMD5Base64EncodedByByteArray(oldPayloadData));
ArtifactDefinition deploymentArtifactToDelete = new ArtifactDefinition();
deploymentArtifactToDelete.setMandatory(false);
deploymentArtifactToDelete.setArtifactName(deploymentArtifactToDeleteFileName);
deploymentArtifactToDelete.setArtifactType("SNMP_TRAP");
deploymentArtifactToDelete.setPayload(oldPayloadData);
- deploymentArtifactToDelete.setArtifactChecksum(GeneralUtility.calculateMD5ByByteArray(oldPayloadData));
+ deploymentArtifactToDelete.setArtifactChecksum(GeneralUtility.calculateMD5Base64EncodedByByteArray(oldPayloadData));
ArtifactDefinition deploymentArtifactToIgnore = new ArtifactDefinition();
@@ -1520,14 +1520,14 @@ public class ResourceBusinessLogicTest {
artifactToUpdate.setArtifactName(artifactInfoToUpdateFileName);
artifactToUpdate.setArtifactType("SNMP_POLL");
artifactToUpdate.setPayload(oldPayloadData);
- artifactToUpdate.setArtifactChecksum(GeneralUtility.calculateMD5ByByteArray(oldPayloadData));
+ artifactToUpdate.setArtifactChecksum(GeneralUtility.calculateMD5Base64EncodedByByteArray(oldPayloadData));
ArtifactDefinition artifactToDelete = new ArtifactDefinition();
artifactToDelete.setMandatory(false);
artifactToDelete.setArtifactName(artifactInfoToDeleteFileName);
artifactToDelete.setArtifactType("SNMP_TRAP");
artifactToDelete.setPayload(oldPayloadData);
- artifactToDelete.setArtifactChecksum(GeneralUtility.calculateMD5ByByteArray(oldPayloadData));
+ artifactToDelete.setArtifactChecksum(GeneralUtility.calculateMD5Base64EncodedByByteArray(oldPayloadData));
ArtifactDefinition artifactToIgnore = new ArtifactDefinition();
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ResourceServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ResourceServletTest.java
index 3afb5d6bdc..107163c520 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ResourceServletTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ResourceServletTest.java
@@ -229,7 +229,7 @@ public class ResourceServletTest extends JerseyTest {
}
private void setMD5OnRequest(boolean isValid, UploadResourceInfo json) {
- String md5 = (isValid) ? GeneralUtility.calculateMD5ByString(gson.toJson(json)) : "stam=";
+ String md5 = (isValid) ? GeneralUtility.calculateMD5Base64EncodedByString(gson.toJson(json)) : "stam=";
when(request.getHeader(Constants.MD5_HEADER)).thenReturn(md5);
}