diff options
Diffstat (limited to 'asdc-controller/src/main')
8 files changed, 383 insertions, 82 deletions
diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/client/ASDCController.java b/asdc-controller/src/main/java/org/onap/so/asdc/client/ASDCController.java index 9a1392bdca..7a02f47d3f 100644 --- a/asdc-controller/src/main/java/org/onap/so/asdc/client/ASDCController.java +++ b/asdc-controller/src/main/java/org/onap/so/asdc/client/ASDCController.java @@ -28,6 +28,7 @@ import java.io.IOException; import java.io.UnsupportedEncodingException; import java.nio.file.Paths; import java.util.List; +import java.util.Optional; import org.onap.sdc.api.IDistributionClient; import org.onap.sdc.api.consumer.IDistributionStatusMessage; @@ -55,11 +56,16 @@ import org.onap.so.asdc.util.ASDCNotificationLogging; import org.onap.so.db.request.beans.WatchdogDistributionStatus; import org.onap.so.db.request.data.repository.WatchdogDistributionStatusRepository; import org.onap.so.logger.MessageEnum; - import org.onap.so.logger.MsoLogger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.MapperFeature; +import com.fasterxml.jackson.databind.ObjectMapper; + @Component public class ASDCController { @@ -555,6 +561,22 @@ public class ASDCController { LOGGER.recordMetricEvent (subStarttime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully sent Final notification to ASDC", "ASDC", null, null); } + private Optional<String> getNotificationJson(INotificationData iNotif) { + ObjectMapper mapper = new ObjectMapper(); + mapper.setSerializationInclusion(Include.NON_NULL); + mapper.setSerializationInclusion(Include.NON_EMPTY); + mapper.setSerializationInclusion(Include.NON_ABSENT); + mapper.enable(MapperFeature.USE_ANNOTATIONS); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + Optional<String> returnValue = Optional.empty(); + try { + returnValue = Optional.of(mapper.writeValueAsString(iNotif)); + } catch (JsonProcessingException e) { + LOGGER.error("Error converting incoming ASDC notification to JSON" , e); + } + return returnValue; + } + public void treatNotification (INotificationData iNotif) { int noOfArtifacts = 0; @@ -571,7 +593,9 @@ public class ASDCController { LOGGER.debug(ASDCNotificationLogging.dumpASDCNotification(iNotif)); LOGGER.info(MessageEnum.ASDC_RECEIVE_SERVICE_NOTIF, iNotif.getServiceUUID(), "ASDC", "treatNotification"); this.changeControllerStatus(ASDCControllerStatus.BUSY); - toscaInstaller.processWatchdog(iNotif.getDistributionID(),iNotif.getServiceUUID()); + Optional<String> notificationMessage = getNotificationJson(iNotif); + toscaInstaller.processWatchdog(iNotif.getDistributionID(), iNotif.getServiceUUID(), notificationMessage, + asdcConfig.getConsumerID()); // Process only the Resource artifacts in MSO this.processResourceNotification(iNotif); @@ -687,6 +711,13 @@ public class ASDCController { try { this.processCsarServiceArtifacts(iNotif, toscaResourceStructure); + IArtifactInfo iArtifact = toscaResourceStructure.getToscaArtifact(); + String filePath = System.getProperty("mso.config.path") + "/ASDC/" + iArtifact.getArtifactVersion() + "/" + iArtifact.getArtifactName(); + File csarFile = new File(filePath); + String csarFilePath = csarFile.getAbsolutePath(); + if (bpmnInstaller.containsWorkflows(csarFilePath)) { + bpmnInstaller.installBpmn(csarFilePath); + } for (IResourceInstance resource : iNotif.getResources()){ diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/client/test/emulators/ArtifactInfoImpl.java b/asdc-controller/src/main/java/org/onap/so/asdc/client/test/emulators/ArtifactInfoImpl.java index 7dab49f82a..ed97f5bdea 100644 --- a/asdc-controller/src/main/java/org/onap/so/asdc/client/test/emulators/ArtifactInfoImpl.java +++ b/asdc-controller/src/main/java/org/onap/so/asdc/client/test/emulators/ArtifactInfoImpl.java @@ -24,6 +24,8 @@ import java.util.ArrayList; import java.util.List; import org.onap.sdc.api.notification.IArtifactInfo; +import org.apache.commons.lang3.builder.HashCodeBuilder; +import org.apache.commons.lang3.builder.EqualsBuilder; public class ArtifactInfoImpl implements IArtifactInfo { @@ -168,4 +170,23 @@ public class ArtifactInfoImpl implements IArtifactInfo { public void setRelatedArtifacts(List<ArtifactInfoImpl> relatedArtifacts) { this.relatedArtifactsImpl = relatedArtifacts; } + + @Override + public boolean equals(final Object other) { + if (!(other instanceof ArtifactInfoImpl)) { + return false; + } + ArtifactInfoImpl castOther = (ArtifactInfoImpl) other; + return new EqualsBuilder().append(artifactUUID, castOther.artifactUUID) + .append(artifactVersion, castOther.artifactVersion).isEquals(); + } + + @Override + public int hashCode() { + return new HashCodeBuilder().append(artifactName).append(artifactType).append(artifactURL) + .append(artifactChecksum).append(artifactDescription).append(artifactTimeout).append(artifactVersion) + .append(artifactUUID).append(generatedFromUUID).append(generatedArtifact).append(relatedArtifactsInfo) + .append(relatedArtifactsImpl).toHashCode(); + } + } diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/client/test/emulators/NotificationDataImpl.java b/asdc-controller/src/main/java/org/onap/so/asdc/client/test/emulators/NotificationDataImpl.java index 294221352c..a1c660f75f 100644 --- a/asdc-controller/src/main/java/org/onap/so/asdc/client/test/emulators/NotificationDataImpl.java +++ b/asdc-controller/src/main/java/org/onap/so/asdc/client/test/emulators/NotificationDataImpl.java @@ -23,11 +23,15 @@ package org.onap.so.asdc.client.test.emulators; import java.util.ArrayList; import java.util.List; +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; import org.onap.sdc.api.notification.IArtifactInfo; import org.onap.sdc.api.notification.INotificationData; import org.onap.sdc.api.notification.IResourceInstance; import org.springframework.stereotype.Component; +import com.fasterxml.jackson.annotation.JsonIgnore; + @Component public class NotificationDataImpl implements INotificationData { @@ -114,6 +118,7 @@ public class NotificationDataImpl implements INotificationData { return ret; } + @JsonIgnore public List<ResourceInfoImpl> getResourcesImpl(){ return resources; } @@ -172,4 +177,22 @@ public class NotificationDataImpl implements INotificationData { } return ret; } + + @Override + public boolean equals(final Object other) { + if (!(other instanceof NotificationDataImpl)) { + return false; + } + NotificationDataImpl castOther = (NotificationDataImpl) other; + return new EqualsBuilder().append(serviceUUID, castOther.serviceUUID) + .append(serviceVersion, castOther.serviceVersion).isEquals(); + } + + @Override + public int hashCode() { + return new HashCodeBuilder().append(distributionID).append(serviceName).append(serviceVersion) + .append(serviceUUID).append(serviceDescription).append(serviceInvariantUUID).append(resources) + .append(serviceArtifacts).append(workloadContext).toHashCode(); + } + } diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/client/test/emulators/ResourceInfoImpl.java b/asdc-controller/src/main/java/org/onap/so/asdc/client/test/emulators/ResourceInfoImpl.java index eb4764dec1..dad7e64931 100644 --- a/asdc-controller/src/main/java/org/onap/so/asdc/client/test/emulators/ResourceInfoImpl.java +++ b/asdc-controller/src/main/java/org/onap/so/asdc/client/test/emulators/ResourceInfoImpl.java @@ -23,9 +23,13 @@ package org.onap.so.asdc.client.test.emulators; import java.util.ArrayList; import java.util.List; +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; import org.onap.sdc.api.notification.IArtifactInfo; import org.onap.sdc.api.notification.IResourceInstance; +import com.fasterxml.jackson.annotation.JsonIgnore; + public class ResourceInfoImpl implements IResourceInstance{ ResourceInfoImpl (){} private String resourceInstanceName; @@ -120,7 +124,8 @@ public class ResourceInfoImpl implements IResourceInstance{ this.artifacts = artifacts; } - public List<ArtifactInfoImpl> getArtifactsImpl(){ + @JsonIgnore + public List<ArtifactInfoImpl> getArtifactsImpl() { return artifacts; } @@ -155,4 +160,21 @@ public class ResourceInfoImpl implements IResourceInstance{ public void setSubcategory(String subcategory) { this.subcategory = subcategory; } + + @Override + public boolean equals(final Object other) { + if (!(other instanceof ResourceInfoImpl)) { + return false; + } + ResourceInfoImpl castOther = (ResourceInfoImpl) other; + return new EqualsBuilder().append(resourceUUID, castOther.resourceUUID) + .append(resourceVersion, castOther.resourceVersion).isEquals(); + } + + @Override + public int hashCode() { + return new HashCodeBuilder().append(resourceInstanceName).append(resourceCustomizationUUID).append(resourceName) + .append(resourceVersion).append(resourceType).append(resourceUUID).append(resourceInvariantUUID) + .append(category).append(subcategory).append(artifacts).toHashCode(); + } } diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/installer/ToscaResourceStructure.java b/asdc-controller/src/main/java/org/onap/so/asdc/installer/ToscaResourceStructure.java index 179dac3c35..6ddc2a8bdd 100644 --- a/asdc-controller/src/main/java/org/onap/so/asdc/installer/ToscaResourceStructure.java +++ b/asdc-controller/src/main/java/org/onap/so/asdc/installer/ToscaResourceStructure.java @@ -132,7 +132,7 @@ public class ToscaResourceStructure { LOGGER.info(MessageEnum.ASDC_RECEIVE_SERVICE_NOTIF, "***PATH", "ASDC", spoolFile.getAbsolutePath()); - sdcCsarHelper = factory.getSdcCsarHelper(spoolFile.getAbsolutePath()); + sdcCsarHelper = factory.getSdcCsarHelper(spoolFile.getAbsolutePath(),false); }catch(Exception e){ System.out.println("System out " + e.getMessage()); diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/installer/bpmn/BpmnInstaller.java b/asdc-controller/src/main/java/org/onap/so/asdc/installer/bpmn/BpmnInstaller.java index 486844ae02..cd9a121ddb 100644 --- a/asdc-controller/src/main/java/org/onap/so/asdc/installer/bpmn/BpmnInstaller.java +++ b/asdc-controller/src/main/java/org/onap/so/asdc/installer/bpmn/BpmnInstaller.java @@ -27,7 +27,9 @@ import java.io.IOException; import java.net.URI; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.Enumeration; import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; import java.util.zip.ZipInputStream; import org.apache.commons.io.IOUtils; @@ -109,6 +111,30 @@ public class BpmnInstaller { } return; } + + public boolean containsWorkflows(String csarFilePath) { + boolean workflowsInCsar = false; + try { + ZipFile zipFile = new ZipFile(csarFilePath); + Enumeration<? extends ZipEntry> zipEntries = zipFile.entries(); + while (zipEntries.hasMoreElements()) { + String fileName = ((ZipEntry) zipEntries.nextElement()).getName(); + if (fileName.endsWith(BPMN_SUFFIX)) { + workflowsInCsar = true; + break; + } + } + } + catch (Exception e) { + LOGGER.debug("Exception :",e); + LOGGER.error(MessageEnum.ASDC_ARTIFACT_CHECK_EXC, + csarFilePath, + "", + "", + e.getMessage(), "", "", MsoLogger.ErrorCode.DataError, "ASDC Unable to check CSAR entries"); + } + return workflowsInCsar; + } protected HttpResponse sendDeploymentRequest(String bpmnFileName) throws Exception { HttpClient client = HttpClientBuilder.create().build(); diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java b/asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java index 722e1599b6..90b705c019 100644 --- a/asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java +++ b/asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java @@ -25,25 +25,34 @@ package org.onap.so.asdc.installer.heat; import java.sql.Timestamp; import java.util.ArrayList; import java.util.Date; +import java.util.HashMap; import java.util.HashSet; +import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; import java.util.Optional; import java.util.Set; +import java.util.stream.Collectors; import org.hibernate.exception.ConstraintViolationException; import org.hibernate.exception.LockAcquisitionException; import org.onap.sdc.api.notification.IArtifactInfo; import org.onap.sdc.api.notification.IResourceInstance; import org.onap.sdc.api.notification.IStatusData; +import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; +import org.onap.sdc.tosca.parser.enums.SdcTypes; import org.onap.sdc.tosca.parser.impl.SdcPropertyNames; -import org.onap.sdc.tosca.parser.impl.SdcTypes; import org.onap.sdc.toscaparser.api.CapabilityAssignment; import org.onap.sdc.toscaparser.api.CapabilityAssignments; import org.onap.sdc.toscaparser.api.Group; import org.onap.sdc.toscaparser.api.NodeTemplate; import org.onap.sdc.toscaparser.api.Policy; +import org.onap.sdc.toscaparser.api.Property; import org.onap.sdc.toscaparser.api.RequirementAssignment; +import org.onap.sdc.toscaparser.api.RequirementAssignments; import org.onap.sdc.toscaparser.api.elements.Metadata; +import org.onap.sdc.toscaparser.api.functions.GetInput; +import org.onap.sdc.toscaparser.api.parameters.Input; import org.onap.sdc.utils.DistributionStatusEnum; import org.onap.so.asdc.client.ASDCConfiguration; import org.onap.so.asdc.client.exceptions.ArtifactInstallerException; @@ -118,6 +127,9 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; + @Component public class ToscaResourceInstaller { @@ -137,6 +149,7 @@ public class ToscaResourceInstaller { protected static final String MSO = "SO"; + @Autowired protected ServiceRepository serviceRepo; @@ -145,7 +158,7 @@ public class ToscaResourceInstaller { @Autowired protected ServiceProxyResourceCustomizationRepository serviceProxyCustomizationRepo; - + @Autowired protected CollectionResourceRepository collectionRepo; @@ -267,9 +280,9 @@ public class ToscaResourceInstaller { @Transactional(rollbackFor = { ArtifactInstallerException.class }) public void installTheResource(ToscaResourceStructure toscaResourceStruct, VfResourceStructure vfResourceStruct) - throws ArtifactInstallerException { + throws ArtifactInstallerException { VfResourceStructure vfResourceStructure = vfResourceStruct; - extractHeatInformation(toscaResourceStruct, vfResourceStructure); + extractHeatInformation(toscaResourceStruct, vfResourceStructure); // PCLO: in case of deployment failure, use a string that will represent // the type of artifact that failed... @@ -278,9 +291,23 @@ public class ToscaResourceInstaller { createToscaCsar(toscaResourceStruct); createService(toscaResourceStruct, vfResourceStruct); Service service = toscaResourceStruct.getCatalogService(); - + List<NodeTemplate> vfNodeTemplatesList = toscaResourceStruct.getSdcCsarHelper().getServiceVfList(); + + + for (NodeTemplate nodeTemplate : vfNodeTemplatesList) { + + Metadata metadata = nodeTemplate.getMetaData(); + String serviceType = toscaResourceStruct.getCatalogService().getServiceType(); + String vfCustomizationCategory = toscaResourceStruct.getSdcCsarHelper() + .getMetadataPropertyValue(metadata, SdcPropertyNames.PROPERTY_NAME_CATEGORY); + processVfModules(toscaResourceStruct, vfResourceStructure, service, nodeTemplate, metadata, + vfCustomizationCategory); + } + + processResourceSequence(toscaResourceStruct, service); processVFResources(toscaResourceStruct, service, vfResourceStructure); - processAllottedResources(toscaResourceStruct, service); + List<NodeTemplate> allottedResourceList = toscaResourceStruct.getSdcCsarHelper().getAllottedResources(); + processAllottedResources(toscaResourceStruct, service, allottedResourceList); processNetworks(toscaResourceStruct, service); // process Network Collections processNetworkCollections(toscaResourceStruct, service); @@ -327,12 +354,136 @@ public class ToscaResourceInstaller { } } + + List<NodeTemplate> getRequirementList(List<NodeTemplate> resultList, List<NodeTemplate> nodeTemplates, + ISdcCsarHelper iSdcCsarHelper) { + + List<NodeTemplate> nodes = new ArrayList<NodeTemplate>(); + nodes.addAll(nodeTemplates); + + for (NodeTemplate nodeTemplate : nodeTemplates) { + RequirementAssignments requirement = iSdcCsarHelper.getRequirementsOf(nodeTemplate); + List<RequirementAssignment> reqAs = requirement.getAll(); + for (RequirementAssignment ra : reqAs) { + String reqNode = ra.getNodeTemplateName(); + for (NodeTemplate rNode : resultList) { + if (rNode.getName().equals(reqNode)) { + if(!resultList.contains(nodeTemplate)) { + resultList.add(nodeTemplate); + } + if(nodes.contains(nodeTemplate)) { + nodes.remove(nodeTemplate); + } + break; + } + } + } + } + + if (!nodes.isEmpty()) { + getRequirementList(resultList, nodes, iSdcCsarHelper); + } + + return resultList; + } + + // This method retrieve resource sequence from csar file + void processResourceSequence(ToscaResourceStructure toscaResourceStructure, Service service) { + List<String> resouceSequence = new ArrayList<String>(); + List<NodeTemplate> resultList = new ArrayList<NodeTemplate>(); + + ISdcCsarHelper iSdcCsarHelper = toscaResourceStructure.getSdcCsarHelper(); + List<NodeTemplate> nodeTemplates = iSdcCsarHelper.getServiceNodeTemplates(); + List<NodeTemplate> nodes = new ArrayList<NodeTemplate>(); + nodes.addAll(nodeTemplates); + + for (NodeTemplate nodeTemplate : nodeTemplates) { + RequirementAssignments requirement = iSdcCsarHelper.getRequirementsOf(nodeTemplate); + + if (requirement == null || requirement.getAll() == null || requirement.getAll().isEmpty()) { + resultList.add(nodeTemplate); + nodes.remove(nodeTemplate); + } + } + + resultList = getRequirementList(resultList, nodes, iSdcCsarHelper); + + for (NodeTemplate node : resultList) { + String templateName = node.getMetaData().getValue("name"); + if (!resouceSequence.contains(templateName)) { + resouceSequence.add(templateName); + } + } + + String resourceSeqStr = resouceSequence.stream().collect(Collectors.joining(",")); + service.setResourceOrder(resourceSeqStr); + logger.debug(" resourceSeq for service uuid(" + service.getModelUUID() + ") : " + resourceSeqStr); + } + + private static String CUSTOMIZATION_UUID = "customizationUUID"; + + private static String getValue(Object value, List<Input> servInputs) { + String output = null; + if(value instanceof Map) { + // currently this logic handles only one level of nesting. + return ((LinkedHashMap) value).values().toArray()[0].toString(); + } else if(value instanceof GetInput) { + String inputName = ((GetInput)value).getInputName(); + + for(Input input : servInputs) { + if(input.getName().equals(inputName)) { + // keep both input name and default value + // if service input does not supplies value the use default value + String defaultValue = input.getDefault() != null ? (String) input.getDefault().toString() : ""; + output = inputName + "|" + defaultValue;// return default value + } + } + + } else { + output = value != null ? value.toString() : ""; + } + return output; // return property value + } + + String getResourceInput(ToscaResourceStructure toscaResourceStructure, String resourceCustomizationUuid) throws ArtifactInstallerException { + Map<String, String> resouceRequest = new HashMap<>(); + ISdcCsarHelper iSdcCsarHelper = toscaResourceStructure.getSdcCsarHelper(); + + List<Input> serInput = iSdcCsarHelper.getServiceInputs(); + Optional<NodeTemplate> nodeTemplateOpt = iSdcCsarHelper.getServiceNodeTemplates().stream() + .filter(e -> e.getMetaData().getValue(CUSTOMIZATION_UUID).equals(resourceCustomizationUuid)).findFirst(); + if(nodeTemplateOpt.isPresent()) { + NodeTemplate nodeTemplate = nodeTemplateOpt.get(); + LinkedHashMap<String, Property> resourceProperties = nodeTemplate.getProperties(); + + for(String key : resourceProperties.keySet()) { + Property property = resourceProperties.get(key); + + String value = getValue(property.getValue(), serInput); + resouceRequest.put(key, value); + } + } + + try { + ObjectMapper objectMapper = new ObjectMapper(); + String jsonStr = objectMapper.writeValueAsString(resouceRequest); + + jsonStr = jsonStr.replace("\"", "\\\""); + logger.debug("resource request for resource customization id (" + resourceCustomizationUuid + ") : " + jsonStr); + return jsonStr; + } catch (JsonProcessingException e) { + logger.error("resource input could not be deserialized for resource customization id (" + + resourceCustomizationUuid + ")"); + throw new ArtifactInstallerException("resource input could not be parsed", e); + } + } + protected void processNetworks (ToscaResourceStructure toscaResourceStruct, Service service) throws ArtifactInstallerException { List <NodeTemplate> nodeTemplatesVLList = toscaResourceStruct.getSdcCsarHelper ().getServiceVlList (); - if (nodeTemplatesVLList != null) { - for (NodeTemplate vlNode : nodeTemplatesVLList) { + if (nodeTemplatesVLList != null) { + for (NodeTemplate vlNode : nodeTemplatesVLList) { String networkResourceModelName = vlNode.getMetaData ().getValue (SdcPropertyNames.PROPERTY_NAME_NAME); TempNetworkHeatTemplateLookup tempNetworkLookUp = @@ -353,8 +504,8 @@ public class ToscaResourceInstaller { } else { throw new ArtifactInstallerException ("No HeatTemplate found for artifactUUID: " + tempNetworkLookUp.getHeatTemplateArtifactUuid ()); - } - } else { + } + } else { NetworkResourceCustomization networkCustomization = createNetwork (vlNode, toscaResourceStruct, null, @@ -363,16 +514,15 @@ public class ToscaResourceInstaller { service); service.getNetworkCustomizations().add (networkCustomization); logger.debug ("No NetworkResourceName found in TempNetworkHeatTemplateLookup for " - + networkResourceModelName); - } - - } - } + + networkResourceModelName); + } + + } + } } - protected void processAllottedResources(ToscaResourceStructure toscaResourceStruct, Service service) { - List<NodeTemplate> allottedResourceList = toscaResourceStruct.getSdcCsarHelper().getAllottedResources(); - + protected void processAllottedResources(ToscaResourceStructure toscaResourceStruct, Service service, + List<NodeTemplate> allottedResourceList) { if (allottedResourceList != null) { for (NodeTemplate allottedNode : allottedResourceList) { service.getAllottedCustomizations() @@ -395,11 +545,7 @@ public class ToscaResourceInstaller { if (serviceProxyResourceList != null) { for (NodeTemplate spNode : serviceProxyResourceList) { serviceProxy = createServiceProxy(spNode, service, toscaResourceStruct); - - ServiceProxyResourceCustomization serviceProxyResource = findExistingServiceProxyResource(serviceProxyList, serviceProxy.getModelCustomizationUUID()); - - if(serviceProxyResource == null){ - + serviceProxyList.add(serviceProxy); for (NodeTemplate configNode : configurationNodeTemplatesList) { @@ -408,14 +554,18 @@ public class ToscaResourceInstaller { for (RequirementAssignment requirement : requirementsList) { if (requirement.getNodeTemplateName().equals(spNode.getName())) { ConfigurationResourceCustomization configurationResource = createConfiguration(configNode, toscaResourceStruct, serviceProxy); - - configurationResourceList.add(configurationResource); + + Optional<ConfigurationResourceCustomization> matchingObject = configurationResourceList.stream() + .filter(configurationResourceCustomization -> configNode.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID).equals(configurationResource.getModelCustomizationUUID())) + .findFirst(); + if(!matchingObject.isPresent()){ + configurationResourceList.add(configurationResource); + } + break; } } } - - } } } @@ -478,9 +628,9 @@ public class ToscaResourceInstaller { logger.debug("vfCustomizationUUID: " + vfCustomizationUUID + " matches vfNotificationResource CustomizationUUID"); - processVfModules(toscaResourceStruct, vfResourceStructure, service, nodeTemplate, vfCustomizationUUID); - } - else { + processVfModules(toscaResourceStruct, vfResourceStructure, service, nodeTemplate, metadata, + vfCustomizationCategory); + } else { logger.debug("Notification VF ResourceCustomizationUUID: " + vfNotificationResource.getResourceCustomizationUUID() + " doesn't match " + "Tosca VF Customization UUID: " + vfCustomizationUUID); @@ -490,44 +640,65 @@ public class ToscaResourceInstaller { protected void processVfModules(ToscaResourceStructure toscaResourceStruct, VfResourceStructure vfResourceStructure, - Service service, NodeTemplate nodeTemplate, String vfCustomizationUUID) - throws Exception { - logger.debug("processVfModules for vfCustomizationUUID: " + vfCustomizationUUID); + Service service, NodeTemplate nodeTemplate, Metadata metadata, String vfCustomizationCategory) throws Exception { - VnfResourceCustomization vnfResource = createVnfResource(nodeTemplate, toscaResourceStruct, service); + logger.debug("VF Category is : " + vfCustomizationCategory); - if (vfResourceStructure.getVfModuleStructure() != null && !vfResourceStructure.getVfModuleStructure().isEmpty()) { - Set<CvnfcCustomization> existingCvnfcSet = new HashSet<CvnfcCustomization>(); - Set<VnfcCustomization> existingVnfcSet = new HashSet<VnfcCustomization>(); - - for (VfModuleStructure vfModuleStructure : vfResourceStructure.getVfModuleStructure()) { - - logger.debug("vfModuleStructure:" + vfModuleStructure.toString()); - List<org.onap.sdc.toscaparser.api.Group> vfGroups = toscaResourceStruct.getSdcCsarHelper() - .getVfModulesByVf(vfCustomizationUUID); - IVfModuleData vfMetadata = vfModuleStructure.getVfModuleMetadata(); + if(vfResourceStructure.getVfModuleStructure() != null && !vfResourceStructure.getVfModuleStructure().isEmpty()) + { - logger.debug("Comparing Vf_Modules_Metadata CustomizationUUID : " + vfMetadata.getVfModuleModelCustomizationUUID()); - - Optional<org.onap.sdc.toscaparser.api.Group> matchingObject = vfGroups.stream() - .peek(group -> logger.debug("To Csar Group VFModuleModelCustomizationUUID " + group.getMetadata().getValue("vfModuleModelCustomizationUUID"))) - .filter(group -> group.getMetadata().getValue("vfModuleModelCustomizationUUID").equals(vfMetadata.getVfModuleModelCustomizationUUID())) - .findFirst(); - if (matchingObject.isPresent()) { - VfModuleCustomization vfModuleCustomization = createVFModuleResource(matchingObject.get(), nodeTemplate, toscaResourceStruct, - vfResourceStructure, vfMetadata, vnfResource,service, existingCvnfcSet, existingVnfcSet); - vfModuleCustomization.getVfModule().setVnfResources(vnfResource.getVnfResources()); - } else { - throw new Exception("Cannot find matching VFModule Customization in Csar for Vf_Modules_Metadata: " + vfMetadata.getVfModuleModelCustomizationUUID()); + String vfCustomizationUUID = toscaResourceStruct.getSdcCsarHelper() + .getMetadataPropertyValue(metadata, SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID); + logger.debug("VFCustomizationUUID=" + vfCustomizationUUID); + + IResourceInstance vfNotificationResource = vfResourceStructure.getResourceInstance(); + + // Make sure the VF ResourceCustomizationUUID from the notification and tosca customizations match before comparing their VF Modules UUID's + logger.debug("Checking if Notification VF ResourceCustomizationUUID: " + vfNotificationResource.getResourceCustomizationUUID() + + " matches Tosca VF Customization UUID: " + vfCustomizationUUID); + + if(vfCustomizationUUID.equals(vfNotificationResource.getResourceCustomizationUUID())){ + + logger.debug("vfCustomizationUUID: " + vfCustomizationUUID + " matches vfNotificationResource CustomizationUUID"); + + VnfResourceCustomization vnfResource = createVnfResource(nodeTemplate, toscaResourceStruct, service); + + Set<CvnfcCustomization> existingCvnfcSet = new HashSet<CvnfcCustomization>(); + Set<VnfcCustomization> existingVnfcSet = new HashSet<VnfcCustomization>(); + + for (VfModuleStructure vfModuleStructure : vfResourceStructure.getVfModuleStructure()) { + + logger.debug("vfModuleStructure:" + vfModuleStructure.toString()); + List<org.onap.sdc.toscaparser.api.Group> vfGroups = toscaResourceStruct + .getSdcCsarHelper().getVfModulesByVf(vfCustomizationUUID); + IVfModuleData vfMetadata = vfModuleStructure.getVfModuleMetadata(); + + logger.debug("Comparing Vf_Modules_Metadata CustomizationUUID : " + vfMetadata.getVfModuleModelCustomizationUUID()); + + Optional<org.onap.sdc.toscaparser.api.Group> matchingObject = vfGroups.stream() + .peek(group -> logger.debug("To Csar Group VFModuleModelCustomizationUUID " + group.getMetadata().getValue("vfModuleModelCustomizationUUID"))) + .filter(group -> group.getMetadata().getValue("vfModuleModelCustomizationUUID").equals(vfMetadata.getVfModuleModelCustomizationUUID())) + .findFirst(); + if(matchingObject.isPresent()){ + VfModuleCustomization vfModuleCustomization = createVFModuleResource(matchingObject.get(), nodeTemplate, toscaResourceStruct, + vfResourceStructure,vfMetadata, vnfResource, service, existingCvnfcSet, existingVnfcSet); + vfModuleCustomization.getVfModule().setVnfResources(vnfResource.getVnfResources()); + }else + throw new Exception("Cannot find matching VFModule Customization in Csar for Vf_Modules_Metadata: " + vfMetadata.getVfModuleModelCustomizationUUID()); + } + service.getVnfCustomizations().add(vnfResource); + } else{ + logger.debug("Notification VF ResourceCustomizationUUID: " + vfNotificationResource.getResourceCustomizationUUID() + " doesn't match " + + "Tosca VF Customization UUID: " + vfCustomizationUUID); } } - - service.getVnfCustomizations().add(vnfResource); } - public void processWatchdog(String distributionId, String servideUUID) { - WatchdogServiceModVerIdLookup modVerIdLookup = new WatchdogServiceModVerIdLookup(distributionId,servideUUID); + public void processWatchdog(String distributionId, String servideUUID, Optional<String> distributionNotification, + String consumerId) { + WatchdogServiceModVerIdLookup modVerIdLookup = new WatchdogServiceModVerIdLookup(distributionId, servideUUID, + distributionNotification, consumerId); watchdogModVerIdLookupRepository.saveAndFlush(modVerIdLookup); WatchdogDistributionStatus distributionStatus = new WatchdogDistributionStatus(distributionId); @@ -759,9 +930,15 @@ public class ToscaResourceInstaller { spCustomizationResource.setModelCustomizationUUID(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)); spCustomizationResource.setModelInstanceName(nodeTemplate.getName()); spCustomizationResource.setToscaNodeType(nodeTemplate.getType()); - spCustomizationResource.setSourceService(service); + + String sourceServiceUUID = spMetadata.getValue("sourceModelUuid"); + + Service sourceService = serviceRepo.findOneByModelUUID(sourceServiceUUID); + + spCustomizationResource.setSourceService(sourceService); spCustomizationResource.setToscaNodeType(nodeTemplate.getType()); serviceProxyCustomizationSet.add(spCustomizationResource); + toscaResourceStructure.setCatalogServiceProxyResourceCustomization(spCustomizationResource); @@ -885,7 +1062,21 @@ public class ToscaResourceInstaller { ToscaResourceStructure toscaResourceStructure, HeatTemplate heatTemplate, String aicMax, String aicMin,Service service) { NetworkResourceCustomization networkResourceCustomization=networkCustomizationRepo.findOneByModelCustomizationUUID(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)); - if(networkResourceCustomization==null){ + + boolean networkUUIDsMatch = true; + // Check to make sure the NetworkResourceUUID on the Customization record matches the NetworkResourceUUID from the distribution. + // If not we'll update the Customization record with latest from the distribution + if(networkResourceCustomization != null){ + String existingNetworkModelUUID = networkResourceCustomization.getNetworkResource().getModelUUID(); + String latestNetworkModelUUID = networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID); + + if(!existingNetworkModelUUID.equals(latestNetworkModelUUID)){ + networkUUIDsMatch = false; + } + + } + + if(networkResourceCustomization==null || !networkUUIDsMatch){ networkResourceCustomization = createNetworkResourceCustomization(networkNodeTemplate, toscaResourceStructure); @@ -897,7 +1088,8 @@ public class ToscaResourceInstaller { networkResource.addNetworkResourceCustomization(networkResourceCustomization); networkResourceCustomization.setNetworkResource(networkResource); - } + } + return networkResourceCustomization; } @@ -1376,21 +1568,7 @@ public class ToscaResourceInstaller { return configResource; } - - protected ServiceProxyResourceCustomization findExistingServiceProxyResource(List<ServiceProxyResourceCustomization> serviceProxyList, String modelCustomizationUUID) { - ServiceProxyResourceCustomization serviceProxyResourceCustomization = null; - for(ServiceProxyResourceCustomization serviceProxyResourceCustom : serviceProxyList){ - if (serviceProxyResourceCustom != null - && serviceProxyResourceCustom.getModelCustomizationUUID().equals(modelCustomizationUUID)) { - serviceProxyResourceCustomization = serviceProxyResourceCustom; - } - } - if(serviceProxyResourceCustomization==null) - serviceProxyResourceCustomization = serviceProxyCustomizationRepo.findResourceByModelCustomizationUUID(modelCustomizationUUID); - return serviceProxyResourceCustomization; - } - protected VfModuleCustomization findExistingVfModuleCustomization(VnfResourceCustomization vnfResource, String vfModuleModelCustomizationUUID) { VfModuleCustomization vfModuleCustomization = null; diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/util/ASDCNotificationLogging.java b/asdc-controller/src/main/java/org/onap/so/asdc/util/ASDCNotificationLogging.java index f7c761f017..24304ba28c 100644 --- a/asdc-controller/src/main/java/org/onap/so/asdc/util/ASDCNotificationLogging.java +++ b/asdc-controller/src/main/java/org/onap/so/asdc/util/ASDCNotificationLogging.java @@ -28,8 +28,8 @@ import org.onap.sdc.api.notification.IArtifactInfo; import org.onap.sdc.api.notification.INotificationData; import org.onap.sdc.api.notification.IResourceInstance; import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; +import org.onap.sdc.tosca.parser.enums.SdcTypes; import org.onap.sdc.tosca.parser.impl.SdcPropertyNames; -import org.onap.sdc.tosca.parser.impl.SdcTypes; import org.onap.sdc.toscaparser.api.Group; import org.onap.sdc.toscaparser.api.NodeTemplate; import org.onap.sdc.toscaparser.api.elements.Metadata; |