diff options
Diffstat (limited to 'asdc-controller/src/main/java')
11 files changed, 3287 insertions, 2727 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 fd810e1e67..c9332e8f84 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 @@ -24,6 +24,11 @@ d * ============LICENSE_START=================================================== package org.onap.so.asdc.client; +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; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -31,7 +36,6 @@ 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; import org.onap.sdc.api.consumer.IFinalDistrStatusMessage; @@ -48,6 +52,9 @@ import org.onap.so.asdc.client.exceptions.ASDCDownloadException; import org.onap.so.asdc.client.exceptions.ASDCParametersException; import org.onap.so.asdc.client.exceptions.ArtifactInstallerException; import org.onap.so.asdc.installer.IVfResourceInstaller; +import org.onap.so.asdc.installer.PnfResourceStructure; +import org.onap.so.asdc.installer.ResourceStructure; +import org.onap.so.asdc.installer.ResourceType; import org.onap.so.asdc.installer.ToscaResourceStructure; import org.onap.so.asdc.installer.VfResourceStructure; import org.onap.so.asdc.installer.bpmn.BpmnInstaller; @@ -65,12 +72,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.orm.ObjectOptimisticLockingFailureException; 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 { @@ -79,54 +80,49 @@ public class ASDCController { protected boolean isAsdcClientAutoManaged = false; protected String controllerName; - + private ASDCControllerStatus controllerStatus = ASDCControllerStatus.STOPPED; - + protected int nbOfNotificationsOngoing = 0; @Autowired private ToscaResourceInstaller toscaInstaller; - + @Autowired private BpmnInstaller bpmnInstaller; - + @Autowired private WatchdogDistributionStatusRepository wdsRepo; - + @Autowired private ASDCConfiguration asdcConfig; - + @Autowired private ASDCStatusCallBack asdcStatusCallBack; - + @Autowired private ASDCNotificationCallBack asdcNotificationCallBack; - + private IDistributionClient distributionClient; - + private static final String UUID_PARAM = "(UUID:"; - + @Autowired private WatchdogDistribution wd; - - public int getNbOfNotificationsOngoing () { + public int getNbOfNotificationsOngoing() { return nbOfNotificationsOngoing; - } + } public IDistributionClient getDistributionClient() { - return distributionClient; - } - - - - public void setDistributionClient(IDistributionClient distributionClient) { - this.distributionClient = distributionClient; - } - + return distributionClient; + } + public void setDistributionClient(IDistributionClient distributionClient) { + this.distributionClient = distributionClient; + } - protected void changeControllerStatus (ASDCControllerStatus newControllerStatus) { + protected void changeControllerStatus(ASDCControllerStatus newControllerStatus) { switch (newControllerStatus) { case BUSY: @@ -150,97 +146,99 @@ public class ASDCController { } } - public ASDCControllerStatus getControllerStatus () { + public ASDCControllerStatus getControllerStatus() { return this.controllerStatus; } - - public ASDCController () { - isAsdcClientAutoManaged = true; + + public ASDCController() { + this(""); } - public ASDCController (String controllerConfigName) { + public ASDCController(String controllerConfigName) { isAsdcClientAutoManaged = true; this.controllerName = controllerConfigName; } - public ASDCController (String controllerConfigName, IDistributionClient asdcClient, IVfResourceInstaller resourceinstaller) { - distributionClient = asdcClient; + public ASDCController(String controllerConfigName, IDistributionClient asdcClient, + IVfResourceInstaller resourceinstaller) { + distributionClient = asdcClient; } - public ASDCController (String controllerConfigName,IDistributionClient asdcClient) { + public ASDCController(String controllerConfigName, IDistributionClient asdcClient) { distributionClient = asdcClient; - this.controllerName = controllerConfigName; + this.controllerName = controllerConfigName; } + public String getControllerName() { - return controllerName; - } + return controllerName; + } - public void setControllerName(String controllerName) { - this.controllerName = controllerName; - } + public void setControllerName(String controllerName) { + this.controllerName = controllerName; + } - /** + /** * This method initializes the ASDC Controller and the ASDC Client. * * @throws ASDCControllerException It throws an exception if the ASDC Client cannot be instantiated or if an init - * attempt is done when already initialized + * attempt is done when already initialized * @throws ASDCParametersException If there is an issue with the parameters provided * @throws IOException In case of issues when trying to load the key file */ - public void initASDC () throws ASDCControllerException { + public void initASDC() throws ASDCControllerException { String event = "Initialize the ASDC Controller"; logger.debug(event); - if (this.getControllerStatus () != ASDCControllerStatus.STOPPED) { + if (this.getControllerStatus() != ASDCControllerStatus.STOPPED) { String endEvent = "The controller is already initialized, call the closeASDC method first"; - throw new ASDCControllerException (endEvent); + throw new ASDCControllerException(endEvent); } - if (asdcConfig != null) { + if (asdcConfig != null) { asdcConfig.setAsdcControllerName(controllerName); - } + } if (this.distributionClient == null) { - distributionClient = DistributionClientFactory.createDistributionClient (); + distributionClient = DistributionClientFactory.createDistributionClient(); } - - IDistributionClientResult result = this.distributionClient.init (asdcConfig, - asdcNotificationCallBack, asdcStatusCallBack); - if (!result.getDistributionActionResult ().equals (DistributionActionResultEnum.SUCCESS)) { + + IDistributionClientResult result = this.distributionClient.init(asdcConfig, + asdcNotificationCallBack, asdcStatusCallBack); + if (!result.getDistributionActionResult().equals(DistributionActionResultEnum.SUCCESS)) { String endEvent = "ASDC distribution client init failed with reason:" - + result.getDistributionMessageResult (); - logger.debug (endEvent); - this.changeControllerStatus (ASDCControllerStatus.STOPPED); - throw new ASDCControllerException ("Initialization of the ASDC Controller failed with reason: " - + result.getDistributionMessageResult ()); + + result.getDistributionMessageResult(); + logger.debug(endEvent); + this.changeControllerStatus(ASDCControllerStatus.STOPPED); + throw new ASDCControllerException("Initialization of the ASDC Controller failed with reason: " + + result.getDistributionMessageResult()); } - result = this.distributionClient.start (); - if (!result.getDistributionActionResult ().equals (DistributionActionResultEnum.SUCCESS)) { + result = this.distributionClient.start(); + if (!result.getDistributionActionResult().equals(DistributionActionResultEnum.SUCCESS)) { String endEvent = "ASDC distribution client start failed with reason:" - + result.getDistributionMessageResult (); - logger.debug (endEvent); - this.changeControllerStatus (ASDCControllerStatus.STOPPED); - throw new ASDCControllerException ("Startup of the ASDC Controller failed with reason: " - + result.getDistributionMessageResult ()); + + result.getDistributionMessageResult(); + logger.debug(endEvent); + this.changeControllerStatus(ASDCControllerStatus.STOPPED); + throw new ASDCControllerException("Startup of the ASDC Controller failed with reason: " + + result.getDistributionMessageResult()); } - this.changeControllerStatus (ASDCControllerStatus.IDLE); + this.changeControllerStatus(ASDCControllerStatus.IDLE); logger.info("{} {} {}", MessageEnum.ASDC_INIT_ASDC_CLIENT_SUC.toString(), "ASDC", "changeControllerStatus"); } /** * This method closes the ASDC Controller and the ASDC Client. * - * @throws ASDCControllerException It throws an exception if the ASDC Client cannot be closed because - * it's currently BUSY in processing notifications. + * @throws ASDCControllerException It throws an exception if the ASDC Client cannot be closed because it's currently + * BUSY in processing notifications. */ - public void closeASDC () throws ASDCControllerException { + public void closeASDC() throws ASDCControllerException { - if (this.getControllerStatus () == ASDCControllerStatus.BUSY) { - throw new ASDCControllerException ("Cannot close the ASDC controller as it's currently in BUSY state"); + if (this.getControllerStatus() == ASDCControllerStatus.BUSY) { + throw new ASDCControllerException("Cannot close the ASDC controller as it's currently in BUSY state"); } if (this.distributionClient != null) { - this.distributionClient.stop (); + this.distributionClient.stop(); // If auto managed we can set it to Null, ASDCController controls it. // In the other case the client of this class has specified it, so we can't reset it if (isAsdcClientAutoManaged) { @@ -249,59 +247,54 @@ public class ASDCController { } } - this.changeControllerStatus (ASDCControllerStatus.STOPPED); + this.changeControllerStatus(ASDCControllerStatus.STOPPED); } - private boolean checkResourceAlreadyDeployed (VfResourceStructure resource) throws ArtifactInstallerException { + private boolean checkResourceAlreadyDeployed(VfResourceStructure resource) throws ArtifactInstallerException { - - if (toscaInstaller.isResourceAlreadyDeployed (resource)) { - logger.info("{} {} {} {}", MessageEnum.ASDC_ARTIFACT_ALREADY_EXIST.toString(), - resource.getResourceInstance().getResourceInstanceName(), - resource.getResourceInstance().getResourceUUID(), - resource.getResourceInstance().getResourceName()); + if (toscaInstaller.isResourceAlreadyDeployed(resource)) { + logger.info("{} {} {} {}", MessageEnum.ASDC_ARTIFACT_ALREADY_EXIST.toString(), + resource.getResourceInstance().getResourceInstanceName(), + resource.getResourceInstance().getResourceUUID(), + resource.getResourceInstance().getResourceName()); - this.sendDeployNotificationsForResource(resource,DistributionStatusEnum.ALREADY_DOWNLOADED,null); - this.sendDeployNotificationsForResource(resource,DistributionStatusEnum.ALREADY_DEPLOYED,null); + this.sendDeployNotificationsForResource(resource, DistributionStatusEnum.ALREADY_DOWNLOADED, null); + this.sendDeployNotificationsForResource(resource, DistributionStatusEnum.ALREADY_DEPLOYED, null); - return true; - } else { - return false; - } + return true; + } else { + return false; + } } - - protected IDistributionClientDownloadResult downloadTheArtifact (IArtifactInfo artifact, - String distributionId) throws ASDCDownloadException { + protected IDistributionClientDownloadResult downloadTheArtifact(IArtifactInfo artifact, + String distributionId) throws ASDCDownloadException { - logger.debug("Trying to download the artifact : " + artifact.getArtifactURL () - + UUID_PARAM - + artifact.getArtifactUUID () - + ")"); + logger.info("Trying to download the artifact UUID: {} from URL: {}", artifact.getArtifactUUID(), + artifact.getArtifactURL()); IDistributionClientDownloadResult downloadResult; - try { - downloadResult = distributionClient.download (artifact); + downloadResult = distributionClient.download(artifact); if (null == downloadResult) { - logger.info ("{} {}", MessageEnum.ASDC_ARTIFACT_NULL.toString(), artifact.getArtifactUUID()); - return downloadResult; + logger.info("{} {}", MessageEnum.ASDC_ARTIFACT_NULL.toString(), artifact.getArtifactUUID()); + return downloadResult; } } catch (RuntimeException e) { - logger.debug ("Not able to download the artifact due to an exception: " + artifact.getArtifactURL ()); - this.sendASDCNotification (NotificationType.DOWNLOAD, - artifact.getArtifactURL (), - asdcConfig.getConsumerID (), - distributionId, - DistributionStatusEnum.DOWNLOAD_ERROR, - e.getMessage (), - System.currentTimeMillis ()); - - throw new ASDCDownloadException ("Exception caught when downloading the artifact", e); + logger.debug("Not able to download the artifact due to an exception: " + artifact.getArtifactURL()); + this.sendASDCNotification(NotificationType.DOWNLOAD, + artifact.getArtifactURL(), + asdcConfig.getConsumerID(), + distributionId, + DistributionStatusEnum.DOWNLOAD_ERROR, + e.getMessage(), + System.currentTimeMillis()); + + throw new ASDCDownloadException("Exception caught when downloading the artifact", e); } - if (DistributionActionResultEnum.SUCCESS.equals(downloadResult.getDistributionActionResult ())) { + if (DistributionActionResultEnum.SUCCESS.equals(downloadResult.getDistributionActionResult())) { logger.info("{} {} {} {}", MessageEnum.ASDC_ARTIFACT_DOWNLOAD_SUC.toString(), artifact.getArtifactURL(), artifact.getArtifactUUID(), String.valueOf(downloadResult.getArtifactPayload().length)); @@ -311,143 +304,144 @@ public class ASDCController { downloadResult.getDistributionMessageResult(), ErrorCode.DataError.getValue(), "ASDC artifact download fail"); - this.sendASDCNotification (NotificationType.DOWNLOAD, - artifact.getArtifactURL (), - asdcConfig.getConsumerID (), - distributionId, - DistributionStatusEnum.DOWNLOAD_ERROR, - downloadResult.getDistributionMessageResult (), - System.currentTimeMillis ()); - - throw new ASDCDownloadException ("Artifact " + artifact.getArtifactName () - + " could not be downloaded from ASDC URL " - + artifact.getArtifactURL () - + UUID_PARAM - + artifact.getArtifactUUID () - + ")" - + System.lineSeparator () - + "Error message is " - + downloadResult.getDistributionMessageResult () - + System.lineSeparator ()); + this.sendASDCNotification(NotificationType.DOWNLOAD, + artifact.getArtifactURL(), + asdcConfig.getConsumerID(), + distributionId, + DistributionStatusEnum.DOWNLOAD_ERROR, + downloadResult.getDistributionMessageResult(), + System.currentTimeMillis()); + + throw new ASDCDownloadException("Artifact " + artifact.getArtifactName() + + " could not be downloaded from ASDC URL " + + artifact.getArtifactURL() + + UUID_PARAM + + artifact.getArtifactUUID() + + ")" + + System.lineSeparator() + + "Error message is " + + downloadResult.getDistributionMessageResult() + + System.lineSeparator()); } - this.sendASDCNotification (NotificationType.DOWNLOAD, - artifact.getArtifactURL (), - asdcConfig.getConsumerID (), - distributionId, - DistributionStatusEnum.DOWNLOAD_OK, - null, - System.currentTimeMillis ()); + this.sendASDCNotification(NotificationType.DOWNLOAD, + artifact.getArtifactURL(), + asdcConfig.getConsumerID(), + distributionId, + DistributionStatusEnum.DOWNLOAD_OK, + null, + System.currentTimeMillis()); return downloadResult; } - private void writeArtifactToFile (IArtifactInfo artifact, - IDistributionClientDownloadResult resultArtifact) { + private void writeArtifactToFile(IArtifactInfo artifact, IDistributionClientDownloadResult resultArtifact) { - logger.debug( - "Trying to write artifact to file : " + artifact.getArtifactURL() + UUID_PARAM + artifact.getArtifactUUID() - + ")"); - - String filePath = Paths.get(System.getProperty("mso.config.path"), "ASDC", artifact.getArtifactVersion(), artifact.getArtifactName()).normalize().toString(); - // make parent directory - File file = new File(filePath); - File fileParent = file.getParentFile(); - if (!fileParent.exists()) { - fileParent.mkdirs(); - } - - byte[] payloadBytes = resultArtifact.getArtifactPayload(); - - try (FileOutputStream outFile = new FileOutputStream(filePath)) { - logger.info("{} {} {} {}", MessageEnum.ASDC_RECEIVE_SERVICE_NOTIF.toString(), "***WRITE FILE ARTIFACT NAME", - "ASDC", artifact.getArtifactName()); - outFile.write(payloadBytes, 0, payloadBytes.length); - outFile.close(); - } catch (Exception e) { - logger.debug("Exception :", e); - logger.error("{} {} {} {} {} {} {}", MessageEnum.ASDC_ARTIFACT_DOWNLOAD_FAIL.toString(), - artifact.getArtifactName(), artifact.getArtifactURL(), artifact.getArtifactUUID(), - resultArtifact.getDistributionMessageResult(), ErrorCode.DataError.getValue(), - "ASDC write to file failed"); + String filePath = Paths + .get(getMsoConfigPath(), "ASDC", artifact.getArtifactVersion(), artifact.getArtifactName()).normalize() + .toString(); + + logger.info("Trying to write artifact UUID: {}, URL: {} to file: {}", artifact.getArtifactUUID(), + artifact.getArtifactURL(), filePath); + + // make parent directory + File file = new File(filePath); + File fileParent = file.getParentFile(); + if (!fileParent.exists()) { + fileParent.mkdirs(); + } + + byte[] payloadBytes = resultArtifact.getArtifactPayload(); + + try (FileOutputStream outFile = new FileOutputStream(filePath)) { + logger.info("{} {} {} {}", MessageEnum.ASDC_RECEIVE_SERVICE_NOTIF.toString(), "***WRITE FILE ARTIFACT NAME", + "ASDC", artifact.getArtifactName()); + outFile.write(payloadBytes, 0, payloadBytes.length); + } catch (Exception e) { + logger.debug("Exception :", e); + logger.error("{} {} {} {} {} {} {}", MessageEnum.ASDC_ARTIFACT_DOWNLOAD_FAIL.toString(), + artifact.getArtifactName(), artifact.getArtifactURL(), artifact.getArtifactUUID(), + resultArtifact.getDistributionMessageResult(), ErrorCode.DataError.getValue(), + "ASDC write to file failed"); } } - protected void sendDeployNotificationsForResource(VfResourceStructure vfResourceStructure,DistributionStatusEnum distribStatus, String errorReason) { - - for (IArtifactInfo artifactInfo : vfResourceStructure.getResourceInstance().getArtifacts()) { - - if ((DistributionStatusEnum.DEPLOY_OK.equals(distribStatus) && !artifactInfo.getArtifactType().equalsIgnoreCase("OTHER") && !vfResourceStructure.isAlreadyDeployed()) - // This could be NULL if the artifact is a VF module artifact, this won't be present in the MAP - && vfResourceStructure.getArtifactsMapByUUID().get(artifactInfo.getArtifactUUID()) != null - && vfResourceStructure.getArtifactsMapByUUID().get(artifactInfo.getArtifactUUID()).getDeployedInDb() == 0) { - this.sendASDCNotification (NotificationType.DEPLOY, - artifactInfo.getArtifactURL (), - asdcConfig.getConsumerID (), - vfResourceStructure.getNotification().getDistributionID(), - DistributionStatusEnum.DEPLOY_ERROR, - "The artifact has not been used by the modules defined in the resource", - System.currentTimeMillis ()); - } else { - this.sendASDCNotification (NotificationType.DEPLOY, - artifactInfo.getArtifactURL (), - asdcConfig.getConsumerID (), - vfResourceStructure.getNotification().getDistributionID(), - distribStatus, - errorReason, - System.currentTimeMillis ()); - } - } + protected void sendDeployNotificationsForResource(ResourceStructure resourceStructure, + DistributionStatusEnum distribStatus, String errorReason) { + + for (IArtifactInfo artifactInfo : resourceStructure.getResourceInstance().getArtifacts()) { + + if ((DistributionStatusEnum.DEPLOY_OK.equals(distribStatus) && !artifactInfo.getArtifactType() + .equalsIgnoreCase("OTHER") && !resourceStructure.isAlreadyDeployed()) + // This could be NULL if the artifact is a VF module artifact, this won't be present in the MAP + && resourceStructure.getArtifactsMapByUUID().get(artifactInfo.getArtifactUUID()) != null + && resourceStructure.getArtifactsMapByUUID().get(artifactInfo.getArtifactUUID()).getDeployedInDb() + == 0) { + this.sendASDCNotification(NotificationType.DEPLOY, + artifactInfo.getArtifactURL(), + asdcConfig.getConsumerID(), + resourceStructure.getNotification().getDistributionID(), + DistributionStatusEnum.DEPLOY_ERROR, + "The artifact has not been used by the modules defined in the resource", + System.currentTimeMillis()); + } else { + this.sendASDCNotification(NotificationType.DEPLOY, + artifactInfo.getArtifactURL(), + asdcConfig.getConsumerID(), + resourceStructure.getNotification().getDistributionID(), + distribStatus, + errorReason, + System.currentTimeMillis()); + } + } } - - protected void sendCsarDeployNotification(INotificationData iNotif, VfResourceStructure resourceStructure, ToscaResourceStructure toscaResourceStructure, boolean deploySuccessful, String errorReason) { - - IArtifactInfo csarArtifact = toscaResourceStructure.getToscaArtifact(); - - if(deploySuccessful){ - - this.sendASDCNotification (NotificationType.DEPLOY, - csarArtifact.getArtifactURL (), - asdcConfig.getConsumerID (), - resourceStructure.getNotification().getDistributionID(), - DistributionStatusEnum.DEPLOY_OK, - errorReason, - System.currentTimeMillis ()); - - } else { - - this.sendASDCNotification (NotificationType.DEPLOY, - csarArtifact.getArtifactURL (), - asdcConfig.getConsumerID (), - resourceStructure.getNotification().getDistributionID(), - DistributionStatusEnum.DEPLOY_ERROR, - errorReason, - System.currentTimeMillis ()); - - } + + protected void sendCsarDeployNotification(INotificationData iNotif, ResourceStructure resourceStructure, + ToscaResourceStructure toscaResourceStructure, boolean deploySuccessful, String errorReason) { + + IArtifactInfo csarArtifact = toscaResourceStructure.getToscaArtifact(); + + if (deploySuccessful) { + + this.sendASDCNotification(NotificationType.DEPLOY, + csarArtifact.getArtifactURL(), + asdcConfig.getConsumerID(), + resourceStructure.getNotification().getDistributionID(), + DistributionStatusEnum.DEPLOY_OK, + errorReason, + System.currentTimeMillis()); + + } else { + + this.sendASDCNotification(NotificationType.DEPLOY, + csarArtifact.getArtifactURL(), + asdcConfig.getConsumerID(), + resourceStructure.getNotification().getDistributionID(), + DistributionStatusEnum.DEPLOY_ERROR, + errorReason, + System.currentTimeMillis()); + + } } - - protected void deployResourceStructure (VfResourceStructure resourceStructure, ToscaResourceStructure toscaResourceStructure) throws ArtifactInstallerException { + + protected void deployResourceStructure(ResourceStructure resourceStructure, + ToscaResourceStructure toscaResourceStructure) throws ArtifactInstallerException { logger.info("{} {} {} {}", MessageEnum.ASDC_START_DEPLOY_ARTIFACT.toString(), resourceStructure.getResourceInstance().getResourceInstanceName(), resourceStructure.getResourceInstance().getResourceUUID(), "ASDC"); try { - String resourceType = resourceStructure.getResourceInstance().getResourceType(); - String category = resourceStructure.getResourceInstance().getCategory(); - if("VF".equals(resourceType) && !"Allotted Resource".equalsIgnoreCase(category)){ - resourceStructure.createVfModuleStructures(); - } - toscaInstaller.installTheResource(toscaResourceStructure, resourceStructure); + resourceStructure.prepareInstall(); + toscaInstaller.installTheResource(toscaResourceStructure, resourceStructure); } catch (ArtifactInstallerException e) { logger.info("{} {} {} {} {} {}", MessageEnum.ASDC_ARTIFACT_DOWNLOAD_FAIL.toString(), resourceStructure.getResourceInstance().getResourceName(), resourceStructure.getResourceInstance().getResourceUUID(), - String.valueOf(resourceStructure.getVfModuleStructure().size()), "ASDC", "deployResourceStructure"); + String.valueOf(resourceStructure.getNumberOfResources()), "ASDC", "deployResourceStructure"); sendDeployNotificationsForResource(resourceStructure, DistributionStatusEnum.DEPLOY_ERROR, e.getMessage()); throw e; } @@ -456,66 +450,66 @@ public class ASDCController { logger.info("{} {} {} {} {} {}", MessageEnum.ASDC_ARTIFACT_DEPLOY_SUC.toString(), resourceStructure.getResourceInstance().getResourceName(), resourceStructure.getResourceInstance().getResourceUUID(), - String.valueOf(resourceStructure.getVfModuleStructure().size()), "ASDC", "deployResourceStructure"); + String.valueOf(resourceStructure.getNumberOfResources()), "ASDC", "deployResourceStructure"); sendDeployNotificationsForResource(resourceStructure, DistributionStatusEnum.DEPLOY_OK, null); } } - + private enum NotificationType { - DOWNLOAD, DEPLOY + DOWNLOAD, DEPLOY } - protected void sendASDCNotification (NotificationType notificationType, - String artifactURL, - String consumerID, - String distributionID, - DistributionStatusEnum status, - String errorReason, - long timestamp) { - - String event = "Sending " + notificationType.name () - + "(" - + status.name () - + ")" - + " notification to ASDC for artifact:" - + artifactURL; + protected void sendASDCNotification(NotificationType notificationType, + String artifactURL, + String consumerID, + String distributionID, + DistributionStatusEnum status, + String errorReason, + long timestamp) { + + String event = "Sending " + notificationType.name() + + "(" + + status.name() + + ")" + + " notification to ASDC for artifact:" + + artifactURL; if (errorReason != null) { - event=event+"("+errorReason+")"; + event = event + "(" + errorReason + ")"; } logger.info("{} {} {} {} {} {}", MessageEnum.ASDC_SEND_NOTIF_ASDC.toString(), notificationType.name(), status.name(), artifactURL, "ASDC", "sendASDCNotification"); - logger.debug (event); + logger.debug(event); String action = ""; try { - IDistributionStatusMessage message = new DistributionStatusMessage (artifactURL, - consumerID, - distributionID, - status, - timestamp); + IDistributionStatusMessage message = new DistributionStatusMessage(artifactURL, + consumerID, + distributionID, + status, + timestamp); switch (notificationType) { case DOWNLOAD: if (errorReason != null) { - this.distributionClient.sendDownloadStatus (message, errorReason); + this.distributionClient.sendDownloadStatus(message, errorReason); } else { - this.distributionClient.sendDownloadStatus (message); + this.distributionClient.sendDownloadStatus(message); } action = "sendDownloadStatus"; break; case DEPLOY: if (errorReason != null) { - this.distributionClient.sendDeploymentStatus (message, errorReason); + this.distributionClient.sendDeploymentStatus(message, errorReason); } else { - this.distributionClient.sendDeploymentStatus (message); + this.distributionClient.sendDeploymentStatus(message); } action = "sendDeploymentdStatus"; break; default: - break; + break; } } catch (RuntimeException e) { logger.warn("{} {} {} {} {}", MessageEnum.ASDC_SEND_NOTIF_ASDC_EXEC.toString(), "ASDC", @@ -523,148 +517,150 @@ public class ASDCController { "RuntimeException - sendASDCNotification", e); } } - - protected void sendFinalDistributionStatus ( - String distributionID, - DistributionStatusEnum status, - String errorReason) { + protected void sendFinalDistributionStatus( + String distributionID, + DistributionStatusEnum status, + String errorReason) { - logger.debug("Enter sendFinalDistributionStatus with DistributionID " + distributionID + " and Status of " + status + logger.debug( + "Enter sendFinalDistributionStatus with DistributionID " + distributionID + " and Status of " + status .name() + " and ErrorReason " + errorReason); - long subStarttime = System.currentTimeMillis (); - try { - - - IFinalDistrStatusMessage finalDistribution = new FinalDistributionStatusMessage(distributionID,status,subStarttime, asdcConfig.getConsumerID()); - - if(errorReason == null){ - this.distributionClient.sendFinalDistrStatus(finalDistribution); - }else{ - this.distributionClient.sendFinalDistrStatus(finalDistribution, errorReason); - } - - - } catch (RuntimeException e) { - logger.debug("Exception caught in sendFinalDistributionStatus {}", e.getMessage()); - logger.warn("{} {} {} {} {}", MessageEnum.ASDC_SEND_NOTIF_ASDC_EXEC.toString(), "ASDC", "sendASDCNotification", - ErrorCode.SchemaError.getValue(), "RuntimeException - sendASDCNotification", e); - } + long subStarttime = System.currentTimeMillis(); + try { + + IFinalDistrStatusMessage finalDistribution = new FinalDistributionStatusMessage(distributionID, status, + subStarttime, asdcConfig.getConsumerID()); + + if (errorReason == null) { + this.distributionClient.sendFinalDistrStatus(finalDistribution); + } else { + this.distributionClient.sendFinalDistrStatus(finalDistribution, errorReason); + } + + + } catch (RuntimeException e) { + logger.debug("Exception caught in sendFinalDistributionStatus {}", e.getMessage()); + logger.warn("{} {} {} {} {}", MessageEnum.ASDC_SEND_NOTIF_ASDC_EXEC.toString(), "ASDC", + "sendASDCNotification", + ErrorCode.SchemaError.getValue(), "RuntimeException - sendASDCNotification", e); + } } - 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); + 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; - - - for (IResourceInstance resource : iNotif.getResources ()) { - noOfArtifacts += resource.getArtifacts ().size (); - } + 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; + + for (IResourceInstance resource : iNotif.getResources()) { + noOfArtifacts += resource.getArtifacts().size(); + } logger.info("{} {} {} {}", MessageEnum.ASDC_RECEIVE_CALLBACK_NOTIF.toString(), String.valueOf(noOfArtifacts), iNotif.getServiceUUID(), "ASDC"); try { - logger.debug(ASDCNotificationLogging.dumpASDCNotification(iNotif)); - logger.info("{} {} {} {}", MessageEnum.ASDC_RECEIVE_SERVICE_NOTIF.toString(), iNotif.getServiceUUID(), "ASDC", + logger.debug(ASDCNotificationLogging.dumpASDCNotification(iNotif)); + logger + .info("{} {} {} {}", MessageEnum.ASDC_RECEIVE_SERVICE_NOTIF.toString(), iNotif.getServiceUUID(), "ASDC", "treatNotification"); this.changeControllerStatus(ASDCControllerStatus.BUSY); - Optional<String> notificationMessage = getNotificationJson(iNotif); - toscaInstaller.processWatchdog(iNotif.getDistributionID(), iNotif.getServiceUUID(), notificationMessage, - asdcConfig.getConsumerID()); - - // Process only the Resource artifacts in MSO - this.processResourceNotification(iNotif); - - //******************************************************************************************************** - //Start Watchdog loop and wait for all components to complete before reporting final status back. - // **If timer expires first then we will report a Distribution Error back to ASDC - //******************************************************************************************************** - long initialStartTime = System.currentTimeMillis(); - boolean componentsComplete = false; - String distributionStatus = null; - String watchdogError = null; - String overallStatus = null; - int watchDogTimeout = asdcConfig.getWatchDogTimeout() * 1000; - boolean isDeploySuccess = false; - - while(!componentsComplete && (System.currentTimeMillis() - initialStartTime) < watchDogTimeout) - { - - try{ - distributionStatus = wd.getOverallDistributionStatus(iNotif.getDistributionID()); - Thread.sleep(watchDogTimeout / 10); - }catch(Exception e){ - logger.debug ("Exception in Watchdog Loop {}", e.getMessage()); - Thread.sleep(watchDogTimeout / 10); - } - - if(distributionStatus != null && !distributionStatus.equalsIgnoreCase(DistributionStatus.INCOMPLETE.name())){ - - if(distributionStatus.equalsIgnoreCase(DistributionStatus.SUCCESS.name())){ - isDeploySuccess = true; - overallStatus = DistributionStatusEnum.DISTRIBUTION_COMPLETE_OK.name(); - }else{ - overallStatus = DistributionStatusEnum.DISTRIBUTION_COMPLETE_ERROR.name(); - } - componentsComplete = true; - } - } - - if(!componentsComplete){ - logger.debug("Timeout of {} seconds was reached before all components reported status", watchDogTimeout); - watchdogError = "Timeout occurred while waiting for all components to report status"; - overallStatus = DistributionStatusEnum.DISTRIBUTION_COMPLETE_ERROR.name(); - } - - if(distributionStatus == null){ - overallStatus = DistributionStatusEnum.DISTRIBUTION_COMPLETE_ERROR.name(); - logger.debug("DistributionStatus is null for DistributionId: {}", iNotif.getDistributionID()); - } - - try { - wd.executePatchAAI(iNotif.getDistributionID(), iNotif.getServiceInvariantUUID(), overallStatus); - logger.debug("A&AI Updated succefully with Distribution Status!"); - } - catch(Exception e) { - logger.debug("Exception in Watchdog executePatchAAI(): {}", e.getMessage()); - watchdogError = "Error calling A&AI " + e.getMessage(); - if(e.getCause() != null) { - logger.debug("Exception caused by: {}", e.getCause().getMessage()); - } - } - - - if(isDeploySuccess && watchdogError == null){ - sendFinalDistributionStatus(iNotif.getDistributionID(), DistributionStatusEnum.DISTRIBUTION_COMPLETE_OK, null); - WatchdogDistributionStatus wds = new WatchdogDistributionStatus(iNotif.getDistributionID()); - wds.setDistributionIdStatus(DistributionStatusEnum.DISTRIBUTION_COMPLETE_OK.toString()); - wdsRepo.save(wds); - } else { - sendFinalDistributionStatus(iNotif.getDistributionID(), DistributionStatusEnum.DISTRIBUTION_COMPLETE_ERROR, watchdogError); - WatchdogDistributionStatus wds = new WatchdogDistributionStatus(iNotif.getDistributionID()); - wds.setDistributionIdStatus(DistributionStatusEnum.DISTRIBUTION_COMPLETE_ERROR.toString()); - wdsRepo.save(wds); - } - - - } catch(ObjectOptimisticLockingFailureException e) { + Optional<String> notificationMessage = getNotificationJson(iNotif); + toscaInstaller.processWatchdog(iNotif.getDistributionID(), iNotif.getServiceUUID(), notificationMessage, + asdcConfig.getConsumerID()); + + // Process only the Resource artifacts in MSO + this.processResourceNotification(iNotif); + + //******************************************************************************************************** + //Start Watchdog loop and wait for all components to complete before reporting final status back. + // **If timer expires first then we will report a Distribution Error back to ASDC + //******************************************************************************************************** + long initialStartTime = System.currentTimeMillis(); + boolean componentsComplete = false; + String distributionStatus = null; + String watchdogError = null; + String overallStatus = null; + int watchDogTimeout = asdcConfig.getWatchDogTimeout() * 1000; + boolean isDeploySuccess = false; + + while (!componentsComplete && (System.currentTimeMillis() - initialStartTime) < watchDogTimeout) { + + try { + distributionStatus = wd.getOverallDistributionStatus(iNotif.getDistributionID()); + Thread.sleep(watchDogTimeout / 10); + } catch (Exception e) { + logger.debug("Exception in Watchdog Loop {}", e.getMessage()); + Thread.sleep(watchDogTimeout / 10); + } + + if (distributionStatus != null && !distributionStatus + .equalsIgnoreCase(DistributionStatus.INCOMPLETE.name())) { + + if (distributionStatus.equalsIgnoreCase(DistributionStatus.SUCCESS.name())) { + isDeploySuccess = true; + overallStatus = DistributionStatusEnum.DISTRIBUTION_COMPLETE_OK.name(); + } else { + overallStatus = DistributionStatusEnum.DISTRIBUTION_COMPLETE_ERROR.name(); + } + componentsComplete = true; + } + } + + if (!componentsComplete) { + logger + .debug("Timeout of {} seconds was reached before all components reported status", watchDogTimeout); + watchdogError = "Timeout occurred while waiting for all components to report status"; + overallStatus = DistributionStatusEnum.DISTRIBUTION_COMPLETE_ERROR.name(); + } + + if (distributionStatus == null) { + overallStatus = DistributionStatusEnum.DISTRIBUTION_COMPLETE_ERROR.name(); + logger.debug("DistributionStatus is null for DistributionId: {}", iNotif.getDistributionID()); + } + + try { + wd.executePatchAAI(iNotif.getDistributionID(), iNotif.getServiceInvariantUUID(), overallStatus); + logger.debug("A&AI Updated succefully with Distribution Status!"); + } catch (Exception e) { + logger.debug("Exception in Watchdog executePatchAAI(): {}", e.getMessage()); + watchdogError = "Error calling A&AI " + e.getMessage(); + if (e.getCause() != null) { + logger.debug("Exception caused by: {}", e.getCause().getMessage()); + } + } + + if (isDeploySuccess && watchdogError == null) { + sendFinalDistributionStatus(iNotif.getDistributionID(), DistributionStatusEnum.DISTRIBUTION_COMPLETE_OK, + null); + WatchdogDistributionStatus wds = new WatchdogDistributionStatus(iNotif.getDistributionID()); + wds.setDistributionIdStatus(DistributionStatusEnum.DISTRIBUTION_COMPLETE_OK.toString()); + wdsRepo.save(wds); + } else { + sendFinalDistributionStatus(iNotif.getDistributionID(), + DistributionStatusEnum.DISTRIBUTION_COMPLETE_ERROR, watchdogError); + WatchdogDistributionStatus wds = new WatchdogDistributionStatus(iNotif.getDistributionID()); + wds.setDistributionIdStatus(DistributionStatusEnum.DISTRIBUTION_COMPLETE_ERROR.toString()); + wdsRepo.save(wds); + } + + + } catch (ObjectOptimisticLockingFailureException e) { logger.debug("OptimisticLockingFailure for DistributionId: {} Another process " + "has already altered this distribution, so not going to process it on this site.", @@ -675,9 +671,10 @@ public class ASDCController { } catch (Exception e) { logger.error("", MessageEnum.ASDC_GENERAL_EXCEPTION_ARG.toString(), - "Unexpected exception caught during the notification processing", "ASDC", - "treatNotification", ErrorCode.SchemaError.getValue(), "RuntimeException in treatNotification", - e); + "Unexpected exception caught during the notification processing", "ASDC", + "treatNotification", ErrorCode.SchemaError.getValue(), + "RuntimeException in treatNotification", + e); try { wd.executePatchAAI(iNotif.getDistributionID(), iNotif.getServiceInvariantUUID(), @@ -690,167 +687,168 @@ public class ASDCController { logger.debug("Exception caused by: {}", aaiException.getCause().getMessage()); } } - - sendFinalDistributionStatus(iNotif.getDistributionID(), DistributionStatusEnum.DISTRIBUTION_COMPLETE_ERROR, e.getMessage()); - - WatchdogDistributionStatus wds = new WatchdogDistributionStatus(iNotif.getDistributionID()); - wds.setDistributionIdStatus(DistributionStatusEnum.DISTRIBUTION_COMPLETE_ERROR.toString()); - wdsRepo.save(wds); - + + sendFinalDistributionStatus(iNotif.getDistributionID(), DistributionStatusEnum.DISTRIBUTION_COMPLETE_ERROR, + e.getMessage()); + + WatchdogDistributionStatus wds = new WatchdogDistributionStatus(iNotif.getDistributionID()); + wds.setDistributionIdStatus(DistributionStatusEnum.DISTRIBUTION_COMPLETE_ERROR.toString()); + wdsRepo.save(wds); + } finally { - this.changeControllerStatus (ASDCControllerStatus.IDLE); + this.changeControllerStatus(ASDCControllerStatus.IDLE); } } - protected void processResourceNotification (INotificationData iNotif) { - // For each artifact, create a structure describing the VFModule in a ordered flat level - VfResourceStructure resourceStructure = null; - ToscaResourceStructure toscaResourceStructure = new ToscaResourceStructure(); - boolean deploySuccessful = true; - boolean hasVFResource = false; - String errorMessage = null; - - 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()){ - - resourceStructure = new VfResourceStructure(iNotif,resource); - - String resourceType = resourceStructure.getResourceInstance().getResourceType(); - String category = resourceStructure.getResourceInstance().getCategory(); - - logger.debug("Processing Resource Type: " + resourceType + " and Model UUID: " + resourceStructure - .getResourceInstance().getResourceUUID()); - - if("VF".equals(resourceType) && !"Allotted Resource".equalsIgnoreCase(category)){ - - hasVFResource = true; - - for (IArtifactInfo artifact : resource.getArtifacts()) { - IDistributionClientDownloadResult resultArtifact = this.downloadTheArtifact(artifact, - iNotif.getDistributionID()); - if (resultArtifact != null) { - - if (ASDCConfiguration.VF_MODULES_METADATA.equals(artifact.getArtifactType())) { - logger.debug("VF_MODULE_ARTIFACT: "+ new String(resultArtifact.getArtifactPayload(),"UTF-8")); - logger.debug(ASDCNotificationLogging.dumpVfModuleMetaDataList(resourceStructure.decodeVfModuleArtifact - (resultArtifact.getArtifactPayload()))); - } - resourceStructure.addArtifactToStructure(distributionClient,artifact, resultArtifact); - } - } - - //Deploy VF resource and artifacts - logger.debug("Preparing to deploy Service: {}", iNotif.getServiceUUID()); - try{ - - this.deployResourceStructure(resourceStructure, toscaResourceStructure); - - } catch(ArtifactInstallerException e){ - deploySuccessful = false; - errorMessage = e.getMessage(); - logger.error("Exception occurred", e); - } - } - - } - - // There are cases where the Service has no VF resources, those are handled here - if (!hasVFResource) { - - logger.debug("No resources found for Service: {}", iNotif.getServiceUUID()); - - try{ - resourceStructure = new VfResourceStructure(iNotif,new ResourceInstance()); - - this.deployResourceStructure(resourceStructure, toscaResourceStructure); - - } catch(ArtifactInstallerException e){ - deploySuccessful = false; - errorMessage = e.getMessage(); - logger.error("Exception occurred", e); - } - } - this.sendCsarDeployNotification(iNotif, resourceStructure, toscaResourceStructure, deploySuccessful, errorMessage); - - } catch (ASDCDownloadException | UnsupportedEncodingException e) { - logger.error("{} {} {} {} {} {}", MessageEnum.ASDC_GENERAL_EXCEPTION_ARG.toString(), - "Exception caught during Installation of artifact", "ASDC", "processResourceNotification", - ErrorCode.BusinessProcesssError.getValue(), "Exception in processResourceNotification", e); - } + protected void processResourceNotification(INotificationData iNotif) { + // For each artifact, create a structure describing the VFModule in a ordered flat level + ResourceStructure resourceStructure = null; + String msoConfigPath = getMsoConfigPath(); + ToscaResourceStructure toscaResourceStructure = new ToscaResourceStructure(msoConfigPath); + boolean deploySuccessful = true; + String errorMessage = null; + + try { + this.processCsarServiceArtifacts(iNotif, toscaResourceStructure); + IArtifactInfo iArtifact = toscaResourceStructure.getToscaArtifact(); + String filePath = + msoConfigPath + "/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()) { + + String resourceType = resource.getResourceType(); + String category = resource.getCategory(); + + logger.info("Processing Resource Type: {}, Model UUID: {}", resourceType, resource.getResourceUUID()); + + if ("VF".equals(resourceType) && !"Allotted Resource".equalsIgnoreCase(category)) { + resourceStructure = new VfResourceStructure(iNotif, resource); + } else if ("PNF".equals(resourceType)) { + resourceStructure = new PnfResourceStructure(iNotif, resource); + } else { + // There are cases where the Service has no VF resources, those are handled here + logger.info("No resources found for Service: {}", iNotif.getServiceUUID()); + resourceStructure = new VfResourceStructure(iNotif, new ResourceInstance()); + resourceStructure.setResourceType(ResourceType.OTHER); + } + + for (IArtifactInfo artifact : resource.getArtifacts()) { + IDistributionClientDownloadResult resultArtifact = this.downloadTheArtifact(artifact, + iNotif.getDistributionID()); + if (resultArtifact != null) { + resourceStructure.addArtifactToStructure(distributionClient, artifact, resultArtifact); + } + } + + //Deploy VF resource and artifacts + logger.debug("Preparing to deploy Service: {}", iNotif.getServiceUUID()); + try { + this.deployResourceStructure(resourceStructure, toscaResourceStructure); + } catch (ArtifactInstallerException e) { + deploySuccessful = false; + errorMessage = e.getMessage(); + logger.error("Exception occurred", e); + } + + this.sendCsarDeployNotification(iNotif, resourceStructure, toscaResourceStructure, deploySuccessful, + errorMessage); + } + + + } catch (ASDCDownloadException | UnsupportedEncodingException e) { + logger.error("{} {} {} {} {} {}", MessageEnum.ASDC_GENERAL_EXCEPTION_ARG.toString(), + "Exception caught during Installation of artifact", "ASDC", "processResourceNotification", + ErrorCode.BusinessProcesssError.getValue(), "Exception in processResourceNotification", e); + } } - protected void processCsarServiceArtifacts (INotificationData iNotif, ToscaResourceStructure toscaResourceStructure) { - - List<IArtifactInfo> serviceArtifacts = iNotif.getServiceArtifacts(); - - for(IArtifactInfo artifact : serviceArtifacts){ - - if(artifact.getArtifactType().equals(ASDCConfiguration.TOSCA_CSAR)){ - - try{ - - toscaResourceStructure.setToscaArtifact(artifact); - - IDistributionClientDownloadResult resultArtifact = this.downloadTheArtifact(artifact,iNotif.getDistributionID()); - - writeArtifactToFile(artifact, resultArtifact); - - toscaResourceStructure.updateResourceStructure(artifact); - - toscaResourceStructure.setServiceVersion(iNotif.getServiceVersion()); - - logger.debug(ASDCNotificationLogging.dumpCSARNotification(iNotif, toscaResourceStructure)); - - - } catch(Exception e){ - logger.error("{} {} {} {} {} {}", MessageEnum.ASDC_GENERAL_EXCEPTION_ARG.toString(), - "Exception caught during processCsarServiceArtifacts", "ASDC", "processCsarServiceArtifacts", - ErrorCode.BusinessProcesssError.getValue(), "Exception in processCsarServiceArtifacts", e); - } - } - else if(artifact.getArtifactType().equals(ASDCConfiguration.WORKFLOWS)){ - - try{ - - IDistributionClientDownloadResult resultArtifact = this.downloadTheArtifact(artifact,iNotif.getDistributionID()); - - writeArtifactToFile(artifact, resultArtifact); - - toscaResourceStructure.setToscaArtifact(artifact); - - logger.debug(ASDCNotificationLogging.dumpASDCNotification(iNotif)); - - - } catch(Exception e){ - logger.info("Whats the error {}", e.getMessage()); - logger.error("{} {} {} {} {} {}", MessageEnum.ASDC_GENERAL_EXCEPTION_ARG.toString(), - "Exception caught during processCsarServiceArtifacts", "ASDC", "processCsarServiceArtifacts", - ErrorCode.BusinessProcesssError.getValue(), "Exception in processCsarServiceArtifacts", - e); + + private String getMsoConfigPath() { + String msoConfigPath = System.getProperty("mso.config.path"); + if (msoConfigPath == null) { + logger.info("Unable to find the system property mso.config.path, use the default configuration"); + msoConfigPath = asdcConfig.getPropertyOrNull("mso.config.defaultpath"); + } + if (msoConfigPath == null) { + logger.info("Unable to find the property: {} from configuration.", "mso.config.defaultpath"); + msoConfigPath = ""; + } + logger.info("MSO config path is: {}", msoConfigPath); + return msoConfigPath; + } + + protected void processCsarServiceArtifacts(INotificationData iNotif, + ToscaResourceStructure toscaResourceStructure) { + + List<IArtifactInfo> serviceArtifacts = iNotif.getServiceArtifacts(); + + for (IArtifactInfo artifact : serviceArtifacts) { + + if (artifact.getArtifactType().equals(ASDCConfiguration.TOSCA_CSAR)) { + + try { + + toscaResourceStructure.setToscaArtifact(artifact); + + IDistributionClientDownloadResult resultArtifact = this + .downloadTheArtifact(artifact, iNotif.getDistributionID()); + + writeArtifactToFile(artifact, resultArtifact); + + toscaResourceStructure.updateResourceStructure(artifact); + + toscaResourceStructure.setServiceVersion(iNotif.getServiceVersion()); + + logger.debug(ASDCNotificationLogging.dumpCSARNotification(iNotif, toscaResourceStructure)); + + + } catch (Exception e) { + logger.error("{} {} {} {} {} {}", MessageEnum.ASDC_GENERAL_EXCEPTION_ARG.toString(), + "Exception caught during processCsarServiceArtifacts", "ASDC", "processCsarServiceArtifacts", + ErrorCode.BusinessProcesssError.getValue(), + "Exception in processCsarServiceArtifacts", e); + } + } else if (artifact.getArtifactType().equals(ASDCConfiguration.WORKFLOWS)) { + + try { + + IDistributionClientDownloadResult resultArtifact = this + .downloadTheArtifact(artifact, iNotif.getDistributionID()); + + writeArtifactToFile(artifact, resultArtifact); + + toscaResourceStructure.setToscaArtifact(artifact); + + logger.debug(ASDCNotificationLogging.dumpASDCNotification(iNotif)); + + + } catch (Exception e) { + logger.info("Whats the error {}", e.getMessage()); + logger.error("{} {} {} {} {} {}", MessageEnum.ASDC_GENERAL_EXCEPTION_ARG.toString(), + "Exception caught during processCsarServiceArtifacts", "ASDC", "processCsarServiceArtifacts", + ErrorCode.BusinessProcesssError.getValue(), + "Exception in processCsarServiceArtifacts", + e); + } } - } - - } + + } } - - private static final String UNKNOWN="Unknown"; - + + private static final String UNKNOWN = "Unknown"; + /** * @return the address of the ASDC we are connected to. */ - public String getAddress () { + public String getAddress() { if (asdcConfig != null) { - return asdcConfig.getAsdcAddress (); + return asdcConfig.getAsdcAddress(); } return UNKNOWN; } @@ -858,9 +856,9 @@ public class ASDCController { /** * @return the environment name of the ASDC we are connected to. */ - public String getEnvironment () { + public String getEnvironment() { if (asdcConfig != null) { - return asdcConfig.getEnvironmentName (); + return asdcConfig.getEnvironmentName(); } return UNKNOWN; } 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 ed97f5bdea..759d88f196 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 @@ -41,7 +41,7 @@ public class ArtifactInfoImpl implements IArtifactInfo { private ArtifactInfoImpl generatedArtifact; private List<IArtifactInfo> relatedArtifactsInfo; private List<ArtifactInfoImpl> relatedArtifactsImpl; - ArtifactInfoImpl(){} + public ArtifactInfoImpl(){} private ArtifactInfoImpl(IArtifactInfo iArtifactInfo){ artifactName = iArtifactInfo.getArtifactName(); 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 cbe16d864a..9462cc85d8 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 @@ -129,6 +129,10 @@ public class NotificationDataImpl implements INotificationData { } return ret; } + + public void setResources(List<ResourceInfoImpl> resources){ + this.resources = resources; + } public List<ResourceInfoImpl> getResourcesImpl(){ return resources; 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 dad7e64931..9103ae132e 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 @@ -31,7 +31,7 @@ import org.onap.sdc.api.notification.IResourceInstance; import com.fasterxml.jackson.annotation.JsonIgnore; public class ResourceInfoImpl implements IResourceInstance{ - ResourceInfoImpl (){} + public ResourceInfoImpl (){} private String resourceInstanceName; private String resourceCustomizationUUID; private String resourceName; diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/installer/PnfResourceStructure.java b/asdc-controller/src/main/java/org/onap/so/asdc/installer/PnfResourceStructure.java new file mode 100644 index 0000000000..1c1351b272 --- /dev/null +++ b/asdc-controller/src/main/java/org/onap/so/asdc/installer/PnfResourceStructure.java @@ -0,0 +1,50 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.so.asdc.installer; + +import java.io.UnsupportedEncodingException; +import org.onap.sdc.api.IDistributionClient; +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.api.results.IDistributionClientDownloadResult; +import org.onap.so.asdc.client.exceptions.ArtifactInstallerException; + +/** + * This class represents the PNF resource structure. + */ +public class PnfResourceStructure extends ResourceStructure { + + public PnfResourceStructure(INotificationData notificationData, IResourceInstance resourceInstance) { + super(notificationData, resourceInstance); + this.resourceType = ResourceType.PNF_RESOURCE; + } + + @Override + public void addArtifactToStructure(IDistributionClient distributionClient, IArtifactInfo artifactinfo, + IDistributionClientDownloadResult clientResult) throws UnsupportedEncodingException { + + } + + @Override + public void prepareInstall() throws ArtifactInstallerException { + + } +} diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/installer/ResourceStructure.java b/asdc-controller/src/main/java/org/onap/so/asdc/installer/ResourceStructure.java new file mode 100644 index 0000000000..53cc74f7e4 --- /dev/null +++ b/asdc-controller/src/main/java/org/onap/so/asdc/installer/ResourceStructure.java @@ -0,0 +1,152 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.so.asdc.installer; + +import java.io.UnsupportedEncodingException; +import java.util.HashMap; +import java.util.Map; +import org.onap.sdc.api.IDistributionClient; +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.api.results.IDistributionClientDownloadResult; +import org.onap.so.asdc.client.exceptions.ArtifactInstallerException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Abstract class to represent the resource structure. + * + * This structure exists to avoid having issues if the order of the resource artifact of tree structure is not good. + */ +public abstract class ResourceStructure { + + /** + * Flag to indicate whether the resource is deployed successfully. + */ + protected boolean isDeployedSuccessfully = false; + + /** + * Flag to indicate whether the resource is already deployed. + */ + protected boolean isAlreadyDeployed = false; + + /** + * The resource type. + */ + protected ResourceType resourceType; + + /** + * The Raw notification data. + */ + protected INotificationData notificationData; + + /** + * The resource we will try to deploy. + */ + protected IResourceInstance resourceInstance; + + /** + * Number of resources provided by the resource structure. + */ + protected int NumberOfResources; + + /** + * The list of artifacts existing in this resource hashed by UUID. + */ + protected final Map<String, VfModuleArtifact> artifactsMapByUUID; + + public ResourceStructure(INotificationData notificationData, IResourceInstance resourceInstance) { + this.notificationData = notificationData; + this.resourceInstance = resourceInstance; + artifactsMapByUUID = new HashMap<>(); + } + + /** + * Add artifact to the resource structure. + * + * @param distributionClient + * @param artifactinfo + * @param clientResult + * @throws UnsupportedEncodingException + */ + public abstract void addArtifactToStructure(IDistributionClient distributionClient, IArtifactInfo artifactinfo, + IDistributionClientDownloadResult clientResult) throws UnsupportedEncodingException; + + /** + * Prepare the resource for installation. + * + * @throws ArtifactInstallerException + */ + public abstract void prepareInstall() throws ArtifactInstallerException; + + public boolean isDeployedSuccessfully() { + return isDeployedSuccessfully; + } + + public void setDeployedSuccessfully(boolean deployedSuccessfully) { + isDeployedSuccessfully = deployedSuccessfully; + } + + public boolean isAlreadyDeployed() { + return isAlreadyDeployed; + } + + public void setAlreadyDeployed(boolean alreadyDeployed) { + isAlreadyDeployed = alreadyDeployed; + } + + public ResourceType getResourceType() { + return resourceType; + } + + public void setResourceType(ResourceType resourceType) { + this.resourceType = resourceType; + } + + public INotificationData getNotification() { + return notificationData; + } + + public void setNotification(INotificationData notificationData) { + this.notificationData = notificationData; + } + + public IResourceInstance getResourceInstance() { + return resourceInstance; + } + + public void setResourceInstance(IResourceInstance resourceInstance) { + this.resourceInstance = resourceInstance; + } + + public int getNumberOfResources() { + return NumberOfResources; + } + + public void setNumberOfResources(int numberOfResources) { + NumberOfResources = numberOfResources; + } + + public Map<String, VfModuleArtifact> getArtifactsMapByUUID() { + return artifactsMapByUUID; + } + +} diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/installer/ResourceType.java b/asdc-controller/src/main/java/org/onap/so/asdc/installer/ResourceType.java new file mode 100644 index 0000000000..8d55f57dfa --- /dev/null +++ b/asdc-controller/src/main/java/org/onap/so/asdc/installer/ResourceType.java @@ -0,0 +1,41 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.so.asdc.installer; + +/** + * This enum defines the resource type, it's used for tosca parsing, extraction and ingestion in SO. + */ +public enum ResourceType { + + /** + * VF resource and the category is not allotted_resource. + */ + VF_RESOURCE, + + /** + * PNF resource. + */ + PNF_RESOURCE, + + /** + * Other resource type, including VF resource of allotted_resource category. + */ + OTHER +} 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 6616bf4b54..3efc503fcb 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 @@ -43,6 +43,7 @@ import org.onap.so.db.catalog.beans.NetworkCollectionResourceCustomization; import org.onap.so.db.catalog.beans.NetworkInstanceGroup; import org.onap.so.db.catalog.beans.NetworkResource; import org.onap.so.db.catalog.beans.NetworkResourceCustomization; +import org.onap.so.db.catalog.beans.PnfResourceCustomization; import org.onap.so.db.catalog.beans.Service; import org.onap.so.db.catalog.beans.ServiceProxyResourceCustomization; import org.onap.so.db.catalog.beans.TempNetworkHeatTemplateLookup; @@ -54,8 +55,16 @@ import org.onap.so.logger.ErrorCode; import org.onap.so.logger.MessageEnum; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; public class ToscaResourceStructure { + + protected static final Logger logger = LoggerFactory.getLogger(ToscaResourceStructure.class); + + /** + * mso config path, used for the config files, like download csar files. + */ + private String msoConfigPath; Metadata serviceMetadata; private Service catalogService; @@ -100,6 +109,8 @@ public class ToscaResourceStructure { private VfModuleCustomization vfModuleCustomization; private VnfResourceCustomization vnfResourceCustomization; + + private PnfResourceCustomization pnfResourceCustomization; private AllottedResource allottedResource; @@ -111,22 +122,21 @@ public class ToscaResourceStructure { private ToscaCsar toscaCsar; - protected static final Logger logger = LoggerFactory.getLogger(ToscaResourceStructure.class); - - public ToscaResourceStructure(){ + this(System.getProperty("mso.config.path")); } - + + public ToscaResourceStructure(final String msoConfigPath){ + this.msoConfigPath = msoConfigPath; + logger.info("MSO config path is: {}", msoConfigPath); + } + public void updateResourceStructure(IArtifactInfo artifact) throws ASDCDownloadException { - - + try { - SdcToscaParserFactory factory = SdcToscaParserFactory.getInstance();//Autoclosable - - logger.debug("MSO config path is: " + System.getProperty("mso.config.path")); - - String filePath = Paths.get(System.getProperty("mso.config.path"), "ASDC", artifact.getArtifactVersion(), artifact.getArtifactName()).normalize().toString(); + + String filePath = Paths.get(msoConfigPath, "ASDC", artifact.getArtifactVersion(), artifact.getArtifactName()).normalize().toString(); File spoolFile = new File(filePath); @@ -137,7 +147,7 @@ public class ToscaResourceStructure { sdcCsarHelper = factory.getSdcCsarHelper(spoolFile.getAbsolutePath(),false); }catch(Exception e){ - logger.info("System out {}", e.getMessage()); + logger.debug(e.getMessage(), e); logger.error("{} {} {} {} {} {}", MessageEnum.ASDC_GENERAL_EXCEPTION_ARG.toString(), "Exception caught during parser *****LOOK********* " + artifact.getArtifactName(), "ASDC", "processResourceNotification", ErrorCode.BusinessProcesssError.getValue(), @@ -259,6 +269,15 @@ public class ToscaResourceStructure { this.vnfResourceCustomization = vnfResourceCustomization; } + public PnfResourceCustomization getPnfResourceCustomization() { + return pnfResourceCustomization; + } + + public void setPnfResourceCustomization(PnfResourceCustomization pnfResourceCustomization) { + this.pnfResourceCustomization = pnfResourceCustomization; + } + + public VfModuleCustomization getCatalogVfModuleCustomization() { return vfModuleCustomization; } diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/installer/VfModuleArtifact.java b/asdc-controller/src/main/java/org/onap/so/asdc/installer/VfModuleArtifact.java index 92fc598e7d..cb4761c557 100644 --- a/asdc-controller/src/main/java/org/onap/so/asdc/installer/VfModuleArtifact.java +++ b/asdc-controller/src/main/java/org/onap/so/asdc/installer/VfModuleArtifact.java @@ -42,8 +42,7 @@ public final class VfModuleArtifact { private HeatEnvironment heatEnvironment; public VfModuleArtifact(IArtifactInfo artifactinfo,IDistributionClientDownloadResult clientResult) throws UnsupportedEncodingException { - artifactInfo=artifactinfo; - result = new String(clientResult.getArtifactPayload(), "UTF-8"); + this(artifactinfo, clientResult, null); } public VfModuleArtifact(IArtifactInfo artifactinfo,IDistributionClientDownloadResult clientResult, String modifiedHeatTemplate) throws UnsupportedEncodingException { diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/installer/VfResourceStructure.java b/asdc-controller/src/main/java/org/onap/so/asdc/installer/VfResourceStructure.java index 5b24dc56a1..402af160c1 100644 --- a/asdc-controller/src/main/java/org/onap/so/asdc/installer/VfResourceStructure.java +++ b/asdc-controller/src/main/java/org/onap/so/asdc/installer/VfResourceStructure.java @@ -10,9 +10,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -31,6 +31,7 @@ import java.util.List; import java.util.Map; import org.onap.so.asdc.client.ASDCConfiguration; import org.onap.so.asdc.client.exceptions.ArtifactInstallerException; +import org.onap.so.asdc.util.ASDCNotificationLogging; import org.onap.so.db.catalog.beans.AllottedResourceCustomization; import org.onap.so.db.catalog.beans.NetworkResourceCustomization; import org.onap.so.db.catalog.beans.Service; @@ -49,186 +50,156 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * This structure exists to avoid having issues if the order of the vfResource/vfmodule artifact is not good (tree structure). - * + * This structure exists to avoid having issues if the order of the vfResource/vfmodule artifact is not good (tree + * structure). */ - - -public class VfResourceStructure { - - protected static final Logger logger = LoggerFactory.getLogger(VfResourceStructure.class); - - private boolean isDeployedSuccessfully=false; - /** - * The Raw notification data. - */ - private final INotificationData notification; - /** - * The Raw notification data. - */ - private boolean isAlreadyDeployed=false; - - /** - * The resource we will try to deploy. - */ - private final IResourceInstance resourceInstance; - - /** - * The list of VfModules defined for this resource. - */ - private final List<VfModuleStructure> vfModulesStructureList; - - /** - * The list of VfModulesMetadata defined for this resource. - */ - private List<IVfModuleData> vfModulesMetadataList; - - private VnfResource catalogVnfResource; - - private NetworkResourceCustomization catalogNetworkResourceCustomization; - - private AllottedResourceCustomization catalogResourceCustomization; - - private Service catalogService; - - /** - * The list of artifacts existing in this resource hashed by UUID. - */ - private final Map<String, VfModuleArtifact> artifactsMapByUUID; - - - public VfResourceStructure(INotificationData notificationdata, IResourceInstance resourceinstance) { - notification=notificationdata; - resourceInstance=resourceinstance; - vfModulesStructureList = new LinkedList<>(); - artifactsMapByUUID = new HashMap<>(); - } - - public void addArtifactToStructure(IDistributionClient distributionClient,IArtifactInfo artifactinfo,IDistributionClientDownloadResult clientResult) throws UnsupportedEncodingException { - VfModuleArtifact vfModuleArtifact = new VfModuleArtifact(artifactinfo,clientResult); - addArtifactByType(artifactinfo,clientResult,vfModuleArtifact); - } - - public void addArtifactToStructure(IDistributionClient distributionClient,IArtifactInfo artifactinfo,IDistributionClientDownloadResult clientResult, String modifiedHeatTemplate) throws UnsupportedEncodingException { - VfModuleArtifact vfModuleArtifact = new VfModuleArtifact(artifactinfo,clientResult,modifiedHeatTemplate); - addArtifactByType(artifactinfo,clientResult,vfModuleArtifact); - } - - protected void addArtifactByType(IArtifactInfo artifactinfo,IDistributionClientDownloadResult clientResult, VfModuleArtifact vfModuleArtifact) throws UnsupportedEncodingException { - - switch(artifactinfo.getArtifactType()) { - case ASDCConfiguration.HEAT: - case ASDCConfiguration.HEAT_ENV: - case ASDCConfiguration.HEAT_VOL: - case ASDCConfiguration.HEAT_NESTED: // For 1607 only 1 level tree is supported - case ASDCConfiguration.HEAT_ARTIFACT: - case ASDCConfiguration.HEAT_NET: - case ASDCConfiguration.OTHER: - artifactsMapByUUID.put(artifactinfo.getArtifactUUID(), vfModuleArtifact); - break; - case ASDCConfiguration.VF_MODULES_METADATA: - vfModulesMetadataList = this.decodeVfModuleArtifact(clientResult.getArtifactPayload()); - break; - default: - break; - } - } - - public void createVfModuleStructures() throws ArtifactInstallerException { - - //for vender tosca VNF there is no VFModule in VF - if (vfModulesMetadataList == null) { - logger.info("{} {} {} {}", MessageEnum.ASDC_GENERAL_INFO.toString(), "There is no VF mudules in the VF.", "ASDC", - "createVfModuleStructures"); - return; - } - for (IVfModuleData vfModuleMeta:vfModulesMetadataList) { - vfModulesStructureList.add(new VfModuleStructure(this,vfModuleMeta)); - } - } - - public INotificationData getNotification() { - return notification; - } - - public IResourceInstance getResourceInstance() { - return resourceInstance; - } - - public List<VfModuleStructure> getVfModuleStructure() { - return vfModulesStructureList; - } - - public boolean isDeployedSuccessfully() { - return isDeployedSuccessfully; - } - - public void setSuccessfulDeployment() { - isDeployedSuccessfully = true; - } - - public boolean isAlreadyDeployed() { - return isAlreadyDeployed; - } - - public void setAlreadyDeployed(boolean isAlreadyDeployed) { - this.isAlreadyDeployed = isAlreadyDeployed; - } - - public Map<String, VfModuleArtifact> getArtifactsMapByUUID() { - return artifactsMapByUUID; - } - - public List<VfModuleStructure> getVfModulesStructureList() { - return vfModulesStructureList; - } - - public VnfResource getCatalogVnfResource() { - return catalogVnfResource; - } - - public void setCatalogVnfResource(VnfResource catalogVnfResource) { - this.catalogVnfResource = catalogVnfResource; - } - - // Network Only - public NetworkResourceCustomization getCatalogNetworkResourceCustomization() { - return catalogNetworkResourceCustomization; - } - // Network Only - public void setCatalogNetworkResourceCustomization(NetworkResourceCustomization catalogNetworkResourceCustomization) { - this.catalogNetworkResourceCustomization = catalogNetworkResourceCustomization; - } - - public AllottedResourceCustomization getCatalogResourceCustomization() { - return catalogResourceCustomization; - } - - public void setCatalogResourceCustomization( - AllottedResourceCustomization catalogResourceCustomization) { - this.catalogResourceCustomization = catalogResourceCustomization; - } - - public Service getCatalogService() { - return catalogService; - } - - public void setCatalogService(Service catalogService) { - this.catalogService = catalogService; - } - - public List<IVfModuleData> decodeVfModuleArtifact(byte[] arg0) { - try { - List<IVfModuleData> listVFModuleMetaData = new ObjectMapper().readValue(arg0, new TypeReference<List<VfModuleMetaData>>(){}); - return listVFModuleMetaData; - - } catch (JsonParseException e) { - logger.debug("JsonParseException : ",e); - } catch (JsonMappingException e) { - logger.debug("JsonMappingException : ",e); - } catch (IOException e) { - logger.debug("IOException : ",e); - } - return null; - } +public class VfResourceStructure extends ResourceStructure { + + protected static final Logger logger = LoggerFactory.getLogger(VfResourceStructure.class); + + /** + * The list of VfModules defined for this resource. + */ + private final List<VfModuleStructure> vfModulesStructureList; + + /** + * The list of VfModulesMetadata defined for this resource. + */ + private List<IVfModuleData> vfModulesMetadataList; + + private VnfResource catalogVnfResource; + + private NetworkResourceCustomization catalogNetworkResourceCustomization; + + private AllottedResourceCustomization catalogResourceCustomization; + + private Service catalogService; + + + public VfResourceStructure(INotificationData notificationdata, IResourceInstance resourceinstance) { + super(notificationdata, resourceinstance); + this.resourceType = ResourceType.VF_RESOURCE; + vfModulesStructureList = new LinkedList<>(); + } + + public void addArtifactToStructure(IDistributionClient distributionClient, IArtifactInfo artifactinfo, + IDistributionClientDownloadResult clientResult) throws UnsupportedEncodingException { + this.addArtifactToStructure(distributionClient, artifactinfo, clientResult, null); + } + + public void addArtifactToStructure(IDistributionClient distributionClient, IArtifactInfo artifactinfo, + IDistributionClientDownloadResult clientResult, String modifiedHeatTemplate) + throws UnsupportedEncodingException { + VfModuleArtifact vfModuleArtifact = new VfModuleArtifact(artifactinfo, clientResult, modifiedHeatTemplate); + addArtifactByType(artifactinfo, clientResult, vfModuleArtifact); + if (ASDCConfiguration.VF_MODULES_METADATA.equals(artifactinfo.getArtifactType())) { + logger.debug("VF_MODULE_ARTIFACT: " + new String(clientResult.getArtifactPayload(), "UTF-8")); + logger.debug(ASDCNotificationLogging.dumpVfModuleMetaDataList(vfModulesMetadataList)); + } + } + + protected void addArtifactByType(IArtifactInfo artifactinfo, IDistributionClientDownloadResult clientResult, + VfModuleArtifact vfModuleArtifact) throws UnsupportedEncodingException { + + switch (artifactinfo.getArtifactType()) { + case ASDCConfiguration.HEAT: + case ASDCConfiguration.HEAT_ENV: + case ASDCConfiguration.HEAT_VOL: + case ASDCConfiguration.HEAT_NESTED: // For 1607 only 1 level tree is supported + case ASDCConfiguration.HEAT_ARTIFACT: + case ASDCConfiguration.HEAT_NET: + case ASDCConfiguration.OTHER: + artifactsMapByUUID.put(artifactinfo.getArtifactUUID(), vfModuleArtifact); + break; + case ASDCConfiguration.VF_MODULES_METADATA: + vfModulesMetadataList = this.decodeVfModuleArtifact(clientResult.getArtifactPayload()); + break; + default: + break; + } + } + + public void prepareInstall() throws ArtifactInstallerException{ + createVfModuleStructures(); + } + + public void createVfModuleStructures() throws ArtifactInstallerException { + + //for vender tosca VNF there is no VFModule in VF + if (vfModulesMetadataList == null) { + logger.info("{} {} {} {}", MessageEnum.ASDC_GENERAL_INFO.toString(), "There is no VF mudules in the VF.", + "ASDC", + "createVfModuleStructures"); + return; + } + for (IVfModuleData vfModuleMeta : vfModulesMetadataList) { + vfModulesStructureList.add(new VfModuleStructure(this, vfModuleMeta)); + } + setNumberOfResources(vfModulesMetadataList.size()); + } + + public List<VfModuleStructure> getVfModuleStructure() { + return vfModulesStructureList; + } + + public Map<String, VfModuleArtifact> getArtifactsMapByUUID() { + return artifactsMapByUUID; + } + + public List<VfModuleStructure> getVfModulesStructureList() { + return vfModulesStructureList; + } + + public VnfResource getCatalogVnfResource() { + return catalogVnfResource; + } + + public void setCatalogVnfResource(VnfResource catalogVnfResource) { + this.catalogVnfResource = catalogVnfResource; + } + + // Network Only + public NetworkResourceCustomization getCatalogNetworkResourceCustomization() { + return catalogNetworkResourceCustomization; + } + + // Network Only + public void setCatalogNetworkResourceCustomization( + NetworkResourceCustomization catalogNetworkResourceCustomization) { + this.catalogNetworkResourceCustomization = catalogNetworkResourceCustomization; + } + + public AllottedResourceCustomization getCatalogResourceCustomization() { + return catalogResourceCustomization; + } + + public void setCatalogResourceCustomization( + AllottedResourceCustomization catalogResourceCustomization) { + this.catalogResourceCustomization = catalogResourceCustomization; + } + + public Service getCatalogService() { + return catalogService; + } + + public void setCatalogService(Service catalogService) { + this.catalogService = catalogService; + } + + public List<IVfModuleData> decodeVfModuleArtifact(byte[] arg0) { + try { + List<IVfModuleData> listVFModuleMetaData = new ObjectMapper() + .readValue(arg0, new TypeReference<List<VfModuleMetaData>>() { + }); + return listVFModuleMetaData; + + } catch (JsonParseException e) { + logger.debug("JsonParseException : ", e); + } catch (JsonMappingException e) { + logger.debug("JsonMappingException : ", e); + } catch (IOException e) { + logger.debug("IOException : ", e); + } + return null; + } } 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 5af427a81a..db639dad0a 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 @@ -10,9 +10,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -24,6 +24,8 @@ package org.onap.so.asdc.installer.heat; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; import java.sql.Timestamp; import java.util.ArrayList; import java.util.Date; @@ -35,13 +37,15 @@ 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.IEntityDetails; import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; +import org.onap.sdc.tosca.parser.elements.queries.EntityQuery; +import org.onap.sdc.tosca.parser.elements.queries.TopologyTemplateQuery; import org.onap.sdc.tosca.parser.enums.SdcTypes; import org.onap.sdc.tosca.parser.impl.SdcPropertyNames; import org.onap.sdc.toscaparser.api.CapabilityAssignment; @@ -62,6 +66,8 @@ import org.onap.so.asdc.client.exceptions.ArtifactInstallerException; import org.onap.so.asdc.installer.ASDCElementInfo; import org.onap.so.asdc.installer.BigDecimalVersion; import org.onap.so.asdc.installer.IVfModuleData; +import org.onap.so.asdc.installer.PnfResourceStructure; +import org.onap.so.asdc.installer.ResourceStructure; import org.onap.so.asdc.installer.ToscaResourceStructure; import org.onap.so.asdc.installer.VfModuleArtifact; import org.onap.so.asdc.installer.VfModuleStructure; @@ -84,6 +90,8 @@ import org.onap.so.db.catalog.beans.NetworkCollectionResourceCustomization; import org.onap.so.db.catalog.beans.NetworkInstanceGroup; import org.onap.so.db.catalog.beans.NetworkResource; import org.onap.so.db.catalog.beans.NetworkResourceCustomization; +import org.onap.so.db.catalog.beans.PnfResource; +import org.onap.so.db.catalog.beans.PnfResourceCustomization; import org.onap.so.db.catalog.beans.Service; import org.onap.so.db.catalog.beans.ServiceProxyResourceCustomization; import org.onap.so.db.catalog.beans.SubType; @@ -109,6 +117,8 @@ import org.onap.so.db.catalog.data.repository.HeatTemplateRepository; import org.onap.so.db.catalog.data.repository.InstanceGroupRepository; import org.onap.so.db.catalog.data.repository.NetworkResourceCustomizationRepository; import org.onap.so.db.catalog.data.repository.NetworkResourceRepository; +import org.onap.so.db.catalog.data.repository.PnfCustomizationRepository; +import org.onap.so.db.catalog.data.repository.PnfResourceRepository; import org.onap.so.db.catalog.data.repository.ServiceProxyResourceCustomizationRepository; import org.onap.so.db.catalog.data.repository.ServiceRepository; import org.onap.so.db.catalog.data.repository.TempNetworkHeatTemplateRepository; @@ -133,2007 +143,2323 @@ import org.springframework.orm.ObjectOptimisticLockingFailureException; 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 { - protected static final String NODES_VRF_ENTRY = "org.openecomp.nodes.VRFEntry"; - - protected static final String VLAN_NETWORK_RECEPTOR = "org.openecomp.nodes.VLANNetworkReceptor"; - - protected static final String ALLOTTED_RESOURCE = "Allotted Resource"; - - protected static final String MULTI_STAGE_DESIGN = "multi_stage_design"; - - protected static final String SCALABLE = "scalable"; - - protected static final String BASIC = "BASIC"; - - protected static final String PROVIDER = "PROVIDER"; - - protected static final String HEAT = "HEAT"; - - protected static final String MANUAL_RECORD = "MANUAL_RECORD"; - - protected static final String MSO = "SO"; - - - @Autowired - protected ServiceRepository serviceRepo; - - @Autowired - protected InstanceGroupRepository instanceGroupRepo; - - @Autowired - protected ServiceProxyResourceCustomizationRepository serviceProxyCustomizationRepo; - - @Autowired - protected CollectionResourceRepository collectionRepo; - - @Autowired - protected CollectionResourceCustomizationRepository collectionCustomizationRepo; - - @Autowired - protected ConfigurationResourceCustomizationRepository configCustomizationRepo; - - @Autowired - protected ConfigurationResourceRepository configRepo; - - @Autowired - protected VnfResourceRepository vnfRepo; - - @Autowired - protected VnfCustomizationRepository vnfCustomizationRepo; - - @Autowired - protected VFModuleRepository vfModuleRepo; - - @Autowired - protected VFModuleCustomizationRepository vfModuleCustomizationRepo; - - @Autowired - protected VnfcInstanceGroupCustomizationRepository vnfcInstanceGroupCustomizationRepo; - - @Autowired - protected VnfcCustomizationRepository vnfcCustomizationRepo; - - @Autowired - protected CvnfcCustomizationRepository cvnfcCustomizationRepo; - - @Autowired - protected AllottedResourceRepository allottedRepo; - - @Autowired - protected AllottedResourceCustomizationRepository allottedCustomizationRepo; - - @Autowired - protected NetworkResourceRepository networkRepo; - - @Autowired - protected HeatTemplateRepository heatRepo; - - @Autowired - protected NetworkResourceCustomizationRepository networkCustomizationRepo; - - @Autowired - protected WatchdogComponentDistributionStatusRepository watchdogCDStatusRepository; - @Autowired - protected WatchdogDistributionStatusRepository watchdogDistributionStatusRepository; - @Autowired - protected WatchdogServiceModVerIdLookupRepository watchdogModVerIdLookupRepository; - - @Autowired - protected TempNetworkHeatTemplateRepository tempNetworkLookupRepo; - - @Autowired - protected ExternalServiceToInternalServiceRepository externalServiceToInternalServiceRepository; - - protected static final Logger logger = LoggerFactory.getLogger(ToscaResourceInstaller.class); - - public boolean isResourceAlreadyDeployed(VfResourceStructure vfResourceStruct) throws ArtifactInstallerException { - boolean status = false; - VfResourceStructure vfResourceStructure = vfResourceStruct; - try { - status = vfResourceStructure.isDeployedSuccessfully(); - } catch (RuntimeException e) { - status = false; - } - try { - Service existingService = serviceRepo.findOneByModelUUID(vfResourceStructure.getNotification().getServiceUUID()); - if(existingService != null) - status = true; - if (status) { - logger.info(vfResourceStructure.getResourceInstance().getResourceInstanceName(), - vfResourceStructure.getResourceInstance().getResourceCustomizationUUID(), - vfResourceStructure.getNotification().getServiceName(), - BigDecimalVersion.castAndCheckNotificationVersionToString( - vfResourceStructure.getNotification().getServiceVersion()), - vfResourceStructure.getNotification().getServiceUUID(), - vfResourceStructure.getResourceInstance().getResourceName(), "", ""); - WatchdogComponentDistributionStatus wdStatus = new WatchdogComponentDistributionStatus(vfResourceStruct.getNotification().getDistributionID(), MSO); - wdStatus.setComponentDistributionStatus(DistributionStatusEnum.COMPONENT_DONE_OK.name()); - watchdogCDStatusRepository.saveAndFlush(wdStatus); - } else { - logger.info(vfResourceStructure.getResourceInstance().getResourceInstanceName(), - vfResourceStructure.getResourceInstance().getResourceCustomizationUUID(), - vfResourceStructure.getNotification().getServiceName(), - BigDecimalVersion.castAndCheckNotificationVersionToString( - vfResourceStructure.getNotification().getServiceVersion()), - vfResourceStructure.getNotification().getServiceUUID(), - vfResourceStructure.getResourceInstance().getResourceName(), "", ""); - } - return status; - } catch (Exception e) { - logger - .error("{} {} {}", MessageEnum.ASDC_ARTIFACT_CHECK_EXC.toString(), ErrorCode.SchemaError.getValue(), - "Exception - isResourceAlreadyDeployed"); - throw new ArtifactInstallerException("Exception caught during checking existence of the VNF Resource.", e); - } - } - - public void installTheComponentStatus(IStatusData iStatus) throws ArtifactInstallerException { - logger.debug("Entering installTheComponentStatus for distributionId {} and ComponentName {}", - iStatus.getDistributionID(), iStatus.getComponentName()); - - try { - WatchdogComponentDistributionStatus cdStatus = new WatchdogComponentDistributionStatus(iStatus.getDistributionID(), - iStatus.getComponentName()); - cdStatus.setComponentDistributionStatus(iStatus.getStatus().toString()); - watchdogCDStatusRepository.save(cdStatus); - - } catch (Exception e) { - logger.debug("Exception caught in installTheComponentStatus {}", e.getMessage()); - throw new ArtifactInstallerException("Exception caught in installTheComponentStatus " + e.getMessage()); - } - } - - @Transactional(rollbackFor = { ArtifactInstallerException.class }) - public void installTheResource(ToscaResourceStructure toscaResourceStruct, VfResourceStructure vfResourceStruct) - throws ArtifactInstallerException { - VfResourceStructure vfResourceStructure = vfResourceStruct; - extractHeatInformation(toscaResourceStruct, vfResourceStructure); - - // PCLO: in case of deployment failure, use a string that will represent - // the type of artifact that failed... - List<ASDCElementInfo> artifactListForLogging = new ArrayList<>(); - try { - createToscaCsar(toscaResourceStruct); - Service service = createService(toscaResourceStruct, vfResourceStruct); - - processResourceSequence(toscaResourceStruct, service); - processVFResources(toscaResourceStruct, service, vfResourceStructure); - List<NodeTemplate> allottedResourceList = toscaResourceStruct.getSdcCsarHelper().getAllottedResources(); - processAllottedResources(toscaResourceStruct, service, allottedResourceList); - processNetworks(toscaResourceStruct, service); - // process Network Collections - processNetworkCollections(toscaResourceStruct, service); - // Process Service Proxy & Configuration - processServiceProxyAndConfiguration(toscaResourceStruct, service); - - serviceRepo.save(service); - - WatchdogComponentDistributionStatus status = new WatchdogComponentDistributionStatus(vfResourceStruct.getNotification().getDistributionID(), MSO); - status.setComponentDistributionStatus(DistributionStatusEnum.COMPONENT_DONE_OK.name()); - watchdogCDStatusRepository.save(status); - - toscaResourceStruct.setSuccessfulDeployment(); - - } catch (Exception e) { - logger.debug("Exception :", e); - WatchdogComponentDistributionStatus status = new WatchdogComponentDistributionStatus(vfResourceStruct.getNotification().getDistributionID(), MSO); - status.setComponentDistributionStatus(DistributionStatusEnum.COMPONENT_DONE_ERROR.name()); - watchdogCDStatusRepository.save(status); - Throwable dbExceptionToCapture = e; - while (!(dbExceptionToCapture instanceof ConstraintViolationException - || dbExceptionToCapture instanceof LockAcquisitionException) - && (dbExceptionToCapture.getCause() != null)) { - dbExceptionToCapture = dbExceptionToCapture.getCause(); - } - - if (dbExceptionToCapture instanceof ConstraintViolationException - || dbExceptionToCapture instanceof LockAcquisitionException) { - logger.warn("{} {} {} {} {}", MessageEnum.ASDC_ARTIFACT_ALREADY_DEPLOYED.toString(), - vfResourceStructure.getResourceInstance().getResourceName(), - vfResourceStructure.getNotification().getServiceVersion(), ErrorCode.DataError.getValue(), - "Exception - ASCDC Artifact already deployed", e); - } else { - String elementToLog = (!artifactListForLogging.isEmpty() - ? artifactListForLogging.get(artifactListForLogging.size() - 1).toString() - : "No element listed"); - logger.error("{} {} {} {}", MessageEnum.ASDC_ARTIFACT_INSTALL_EXC.toString(), elementToLog, - ErrorCode.DataError.getValue(), - "Exception caught during installation of " + vfResourceStructure.getResourceInstance().getResourceName() - + ". Transaction rollback", e); - throw new ArtifactInstallerException("Exception caught during installation of " - + vfResourceStructure.getResourceInstance().getResourceName() + ". Transaction rollback.", e); - } - } - } - - - 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) { - String networkResourceModelName = vlNode.getMetaData ().getValue (SdcPropertyNames.PROPERTY_NAME_NAME); + protected static final String NODES_VRF_ENTRY = "org.openecomp.nodes.VRFEntry"; + + protected static final String VLAN_NETWORK_RECEPTOR = "org.openecomp.nodes.VLANNetworkReceptor"; + + protected static final String ALLOTTED_RESOURCE = "Allotted Resource"; + + protected static final String MULTI_STAGE_DESIGN = "multi_stage_design"; + + protected static final String SCALABLE = "scalable"; + + protected static final String BASIC = "BASIC"; + + protected static final String PROVIDER = "PROVIDER"; + + protected static final String HEAT = "HEAT"; + + protected static final String MANUAL_RECORD = "MANUAL_RECORD"; + + protected static final String MSO = "SO"; + + protected static final String SDNC_MODEL_NAME = "sdnc_model_name"; + + protected static final String SDNC_MODEL_VERSION = "sdnc_model_version"; + + private static String CUSTOMIZATION_UUID = "customizationUUID"; + + + @Autowired + protected ServiceRepository serviceRepo; + + @Autowired + protected InstanceGroupRepository instanceGroupRepo; + + @Autowired + protected ServiceProxyResourceCustomizationRepository serviceProxyCustomizationRepo; + + @Autowired + protected CollectionResourceRepository collectionRepo; + + @Autowired + protected CollectionResourceCustomizationRepository collectionCustomizationRepo; + + @Autowired + protected ConfigurationResourceCustomizationRepository configCustomizationRepo; + + @Autowired + protected ConfigurationResourceRepository configRepo; + + @Autowired + protected VnfResourceRepository vnfRepo; + + @Autowired + protected VnfCustomizationRepository vnfCustomizationRepo; + + @Autowired + protected VFModuleRepository vfModuleRepo; + + @Autowired + protected VFModuleCustomizationRepository vfModuleCustomizationRepo; + + @Autowired + protected VnfcInstanceGroupCustomizationRepository vnfcInstanceGroupCustomizationRepo; + + @Autowired + protected VnfcCustomizationRepository vnfcCustomizationRepo; + + @Autowired + protected CvnfcCustomizationRepository cvnfcCustomizationRepo; + + @Autowired + protected AllottedResourceRepository allottedRepo; + + @Autowired + protected AllottedResourceCustomizationRepository allottedCustomizationRepo; + + @Autowired + protected NetworkResourceRepository networkRepo; + + @Autowired + protected HeatTemplateRepository heatRepo; + + @Autowired + protected NetworkResourceCustomizationRepository networkCustomizationRepo; + + @Autowired + protected WatchdogComponentDistributionStatusRepository watchdogCDStatusRepository; + @Autowired + protected WatchdogDistributionStatusRepository watchdogDistributionStatusRepository; + @Autowired + protected WatchdogServiceModVerIdLookupRepository watchdogModVerIdLookupRepository; + + @Autowired + protected TempNetworkHeatTemplateRepository tempNetworkLookupRepo; + + @Autowired + protected ExternalServiceToInternalServiceRepository externalServiceToInternalServiceRepository; + + @Autowired + protected PnfResourceRepository pnfResourceRepository; + + @Autowired + protected PnfCustomizationRepository pnfCustomizationRepository; + + protected static final Logger logger = LoggerFactory.getLogger(ToscaResourceInstaller.class); + + public boolean isResourceAlreadyDeployed(VfResourceStructure vfResourceStruct) throws ArtifactInstallerException { + boolean status = false; + VfResourceStructure vfResourceStructure = vfResourceStruct; + try { + status = vfResourceStructure.isDeployedSuccessfully(); + } catch (RuntimeException e) { + status = false; + } + try { + Service existingService = serviceRepo + .findOneByModelUUID(vfResourceStructure.getNotification().getServiceUUID()); + if (existingService != null) { + status = true; + } + if (status) { + logger.info(vfResourceStructure.getResourceInstance().getResourceInstanceName(), + vfResourceStructure.getResourceInstance().getResourceCustomizationUUID(), + vfResourceStructure.getNotification().getServiceName(), + BigDecimalVersion.castAndCheckNotificationVersionToString( + vfResourceStructure.getNotification().getServiceVersion()), + vfResourceStructure.getNotification().getServiceUUID(), + vfResourceStructure.getResourceInstance().getResourceName(), "", ""); + WatchdogComponentDistributionStatus wdStatus = new WatchdogComponentDistributionStatus( + vfResourceStruct.getNotification().getDistributionID(), MSO); + wdStatus.setComponentDistributionStatus(DistributionStatusEnum.COMPONENT_DONE_OK.name()); + watchdogCDStatusRepository.saveAndFlush(wdStatus); + } else { + logger.info(vfResourceStructure.getResourceInstance().getResourceInstanceName(), + vfResourceStructure.getResourceInstance().getResourceCustomizationUUID(), + vfResourceStructure.getNotification().getServiceName(), + BigDecimalVersion.castAndCheckNotificationVersionToString( + vfResourceStructure.getNotification().getServiceVersion()), + vfResourceStructure.getNotification().getServiceUUID(), + vfResourceStructure.getResourceInstance().getResourceName(), "", ""); + } + return status; + } catch (Exception e) { + logger + .error("{} {} {}", MessageEnum.ASDC_ARTIFACT_CHECK_EXC.toString(), + ErrorCode.SchemaError.getValue(), + "Exception - isResourceAlreadyDeployed"); + throw new ArtifactInstallerException("Exception caught during checking existence of the VNF Resource.", e); + } + } + + public void installTheComponentStatus(IStatusData iStatus) throws ArtifactInstallerException { + logger.debug("Entering installTheComponentStatus for distributionId {} and ComponentName {}", + iStatus.getDistributionID(), iStatus.getComponentName()); + + try { + WatchdogComponentDistributionStatus cdStatus = new WatchdogComponentDistributionStatus( + iStatus.getDistributionID(), + iStatus.getComponentName()); + cdStatus.setComponentDistributionStatus(iStatus.getStatus().toString()); + watchdogCDStatusRepository.save(cdStatus); + + } catch (Exception e) { + logger.debug("Exception caught in installTheComponentStatus {}", e.getMessage()); + throw new ArtifactInstallerException("Exception caught in installTheComponentStatus " + e.getMessage()); + } + } + + @Transactional(rollbackFor = {ArtifactInstallerException.class}) + public void installTheResource(ToscaResourceStructure toscaResourceStruct, ResourceStructure resourceStruct) + throws ArtifactInstallerException { + if (resourceStruct instanceof VfResourceStructure) { + installTheVfResouce(toscaResourceStruct, (VfResourceStructure) resourceStruct); + } else if (resourceStruct instanceof PnfResourceStructure) { + installPnfResource(toscaResourceStruct, (PnfResourceStructure) resourceStruct); + } else { + logger.warn("Unrecognized resource type"); + } + } + + private void installPnfResource(ToscaResourceStructure toscaResourceStruct, PnfResourceStructure resourceStruct) + throws ArtifactInstallerException { + + // PCLO: in case of deployment failure, use a string that will represent + // the type of artifact that failed... + List<ASDCElementInfo> artifactListForLogging = new ArrayList<>(); + try { + createToscaCsar(toscaResourceStruct); + Service service = createService(toscaResourceStruct, resourceStruct); + + processResourceSequence(toscaResourceStruct, service); + processPnfResources(toscaResourceStruct, service, resourceStruct); + serviceRepo.save(service); + + WatchdogComponentDistributionStatus status = new WatchdogComponentDistributionStatus( + resourceStruct.getNotification().getDistributionID(), MSO); + status.setComponentDistributionStatus(DistributionStatusEnum.COMPONENT_DONE_OK.name()); + watchdogCDStatusRepository.save(status); + + toscaResourceStruct.setSuccessfulDeployment(); + + } catch (Exception e) { + logger.debug("Exception :", e); + WatchdogComponentDistributionStatus status = new WatchdogComponentDistributionStatus( + resourceStruct.getNotification().getDistributionID(), MSO); + status.setComponentDistributionStatus(DistributionStatusEnum.COMPONENT_DONE_ERROR.name()); + watchdogCDStatusRepository.save(status); + Throwable dbExceptionToCapture = e; + while (!(dbExceptionToCapture instanceof ConstraintViolationException + || dbExceptionToCapture instanceof LockAcquisitionException) + && (dbExceptionToCapture.getCause() != null)) { + dbExceptionToCapture = dbExceptionToCapture.getCause(); + } + + if (dbExceptionToCapture instanceof ConstraintViolationException + || dbExceptionToCapture instanceof LockAcquisitionException) { + logger.warn("{} {} {} {} {}", MessageEnum.ASDC_ARTIFACT_ALREADY_DEPLOYED.toString(), + resourceStruct.getResourceInstance().getResourceName(), + resourceStruct.getNotification().getServiceVersion(), ErrorCode.DataError.getValue(), + "Exception - ASCDC Artifact already deployed", e); + } else { + String elementToLog = (!artifactListForLogging.isEmpty() + ? artifactListForLogging.get(artifactListForLogging.size() - 1).toString() + : "No element listed"); + logger.error("{} {} {} {}", MessageEnum.ASDC_ARTIFACT_INSTALL_EXC.toString(), elementToLog, + ErrorCode.DataError.getValue(), + "Exception caught during installation of " + resourceStruct.getResourceInstance() + .getResourceName() + + ". Transaction rollback", e); + throw new ArtifactInstallerException("Exception caught during installation of " + + resourceStruct.getResourceInstance().getResourceName() + ". Transaction rollback.", e); + } + } + } + + private void installTheVfResouce(ToscaResourceStructure toscaResourceStruct, VfResourceStructure resourceStruct) + throws ArtifactInstallerException { + VfResourceStructure vfResourceStructure = resourceStruct; + extractHeatInformation(toscaResourceStruct, vfResourceStructure); + + // PCLO: in case of deployment failure, use a string that will represent + // the type of artifact that failed... + List<ASDCElementInfo> artifactListForLogging = new ArrayList<>(); + try { + createToscaCsar(toscaResourceStruct); + Service service = createService(toscaResourceStruct, resourceStruct); + + processResourceSequence(toscaResourceStruct, service); + processVFResources(toscaResourceStruct, service, vfResourceStructure); + List<NodeTemplate> allottedResourceList = toscaResourceStruct.getSdcCsarHelper().getAllottedResources(); + processAllottedResources(toscaResourceStruct, service, allottedResourceList); + processNetworks(toscaResourceStruct, service); + // process Network Collections + processNetworkCollections(toscaResourceStruct, service); + // Process Service Proxy & Configuration + processServiceProxyAndConfiguration(toscaResourceStruct, service); + + serviceRepo.save(service); + + WatchdogComponentDistributionStatus status = new WatchdogComponentDistributionStatus( + resourceStruct.getNotification().getDistributionID(), MSO); + status.setComponentDistributionStatus(DistributionStatusEnum.COMPONENT_DONE_OK.name()); + watchdogCDStatusRepository.save(status); + + toscaResourceStruct.setSuccessfulDeployment(); + + } catch (Exception e) { + logger.debug("Exception :", e); + WatchdogComponentDistributionStatus status = new WatchdogComponentDistributionStatus( + resourceStruct.getNotification().getDistributionID(), MSO); + status.setComponentDistributionStatus(DistributionStatusEnum.COMPONENT_DONE_ERROR.name()); + watchdogCDStatusRepository.save(status); + Throwable dbExceptionToCapture = e; + while (!(dbExceptionToCapture instanceof ConstraintViolationException + || dbExceptionToCapture instanceof LockAcquisitionException) + && (dbExceptionToCapture.getCause() != null)) { + dbExceptionToCapture = dbExceptionToCapture.getCause(); + } + + if (dbExceptionToCapture instanceof ConstraintViolationException + || dbExceptionToCapture instanceof LockAcquisitionException) { + logger.warn("{} {} {} {} {}", MessageEnum.ASDC_ARTIFACT_ALREADY_DEPLOYED.toString(), + vfResourceStructure.getResourceInstance().getResourceName(), + vfResourceStructure.getNotification().getServiceVersion(), ErrorCode.DataError.getValue(), + "Exception - ASCDC Artifact already deployed", e); + } else { + String elementToLog = (!artifactListForLogging.isEmpty() + ? artifactListForLogging.get(artifactListForLogging.size() - 1).toString() + : "No element listed"); + logger.error("{} {} {} {}", MessageEnum.ASDC_ARTIFACT_INSTALL_EXC.toString(), elementToLog, + ErrorCode.DataError.getValue(), + "Exception caught during installation of " + vfResourceStructure.getResourceInstance() + .getResourceName() + + ". Transaction rollback", e); + throw new ArtifactInstallerException("Exception caught during installation of " + + vfResourceStructure.getResourceInstance().getResourceName() + ". Transaction rollback.", e); + } + } + } + + + 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 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) { + String networkResourceModelName = vlNode.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME); TempNetworkHeatTemplateLookup tempNetworkLookUp = - tempNetworkLookupRepo.findFirstBynetworkResourceModelName (networkResourceModelName); + tempNetworkLookupRepo.findFirstBynetworkResourceModelName(networkResourceModelName); if (tempNetworkLookUp != null) { HeatTemplate heatTemplate = - heatRepo.findByArtifactUuid (tempNetworkLookUp.getHeatTemplateArtifactUuid ()); + heatRepo.findByArtifactUuid(tempNetworkLookUp.getHeatTemplateArtifactUuid()); if (heatTemplate != null) { NetworkResourceCustomization networkCustomization = - createNetwork (vlNode, - toscaResourceStruct, - heatTemplate, - tempNetworkLookUp.getAicVersionMax (), - tempNetworkLookUp.getAicVersionMin (), - service); - service.getNetworkCustomizations ().add (networkCustomization); + createNetwork(vlNode, + toscaResourceStruct, + heatTemplate, + tempNetworkLookUp.getAicVersionMax(), + tempNetworkLookUp.getAicVersionMin(), + service); + service.getNetworkCustomizations().add(networkCustomization); + } else { + throw new ArtifactInstallerException("No HeatTemplate found for artifactUUID: " + + tempNetworkLookUp.getHeatTemplateArtifactUuid()); + } + } else { + NetworkResourceCustomization networkCustomization = createNetwork(vlNode, + toscaResourceStruct, + null, + null, + null, + service); + service.getNetworkCustomizations().add(networkCustomization); + logger.debug("No NetworkResourceName found in TempNetworkHeatTemplateLookup for " + + networkResourceModelName); + } + + } + } + } + + protected void processAllottedResources(ToscaResourceStructure toscaResourceStruct, Service service, + List<NodeTemplate> allottedResourceList) { + if (allottedResourceList != null) { + for (NodeTemplate allottedNode : allottedResourceList) { + service.getAllottedCustomizations() + .add(createAllottedResource(allottedNode, toscaResourceStruct, service)); + } + } + } + + + protected ConfigurationResource getConfigurationResource(NodeTemplate nodeTemplate) { + Metadata metadata = nodeTemplate.getMetaData(); + ConfigurationResource configResource = new ConfigurationResource(); + configResource.setModelName(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME)); + configResource.setModelInvariantUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)); + configResource.setModelUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID)); + configResource.setModelVersion(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)); + configResource.setDescription(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)); + configResource.setToscaNodeType(nodeTemplate.getType()); + return configResource; + } + + protected ConfigurationResourceCustomization getConfigurationResourceCustomization(NodeTemplate nodeTemplate, + ToscaResourceStructure toscaResourceStructure, + ServiceProxyResourceCustomization spResourceCustomization) { + Metadata metadata = nodeTemplate.getMetaData(); + + ConfigurationResource configResource = getConfigurationResource(nodeTemplate); + + ConfigurationResourceCustomization configCustomizationResource = new ConfigurationResourceCustomization(); + + Set<ConfigurationResourceCustomization> configResourceCustomizationSet = new HashSet<>(); + + configCustomizationResource + .setModelCustomizationUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)); + configCustomizationResource.setModelInstanceName(nodeTemplate.getName()); + + configCustomizationResource.setNfFunction(toscaResourceStructure.getSdcCsarHelper() + .getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFFUNCTION)); + configCustomizationResource.setNfRole(toscaResourceStructure.getSdcCsarHelper() + .getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFROLE)); + configCustomizationResource.setNfType(toscaResourceStructure.getSdcCsarHelper() + .getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFTYPE)); + configCustomizationResource + .setServiceProxyResourceCustomizationUUID(spResourceCustomization.getModelCustomizationUUID()); + + configCustomizationResource.setConfigurationResource(configResource); + configResourceCustomizationSet.add(configCustomizationResource); + + configResource.setConfigurationResourceCustomization(configResourceCustomizationSet); + return configCustomizationResource; + } + + + protected Optional<ConfigurationResourceCustomization> getVnrNodeTemplate( + List<NodeTemplate> configurationNodeTemplatesList, + ToscaResourceStructure toscaResourceStructure, ServiceProxyResourceCustomization spResourceCustomization) { + Optional<ConfigurationResourceCustomization> configurationResourceCust = Optional.empty(); + for (NodeTemplate nodeTemplate : configurationNodeTemplatesList) { + StatefulEntityType entityType = nodeTemplate.getTypeDefinition(); + String type = entityType.getType(); + + if (VLAN_NETWORK_RECEPTOR.equals(type)) { + configurationResourceCust = Optional.of(getConfigurationResourceCustomization(nodeTemplate, + toscaResourceStructure, spResourceCustomization)); + break; + } + } + + return configurationResourceCust; + } + + protected void processServiceProxyAndConfiguration(ToscaResourceStructure toscaResourceStruct, Service service) { + + List<NodeTemplate> serviceProxyResourceList = toscaResourceStruct.getSdcCsarHelper() + .getServiceNodeTemplateBySdcType(SdcTypes.SERVICE_PROXY); + + List<NodeTemplate> configurationNodeTemplatesList = toscaResourceStruct.getSdcCsarHelper() + .getServiceNodeTemplateBySdcType(SdcTypes.CONFIGURATION); + + List<ServiceProxyResourceCustomization> serviceProxyList = new ArrayList<ServiceProxyResourceCustomization>(); + List<ConfigurationResourceCustomization> configurationResourceList = new ArrayList<ConfigurationResourceCustomization>(); + + ServiceProxyResourceCustomization serviceProxy = null; + + if (serviceProxyResourceList != null) { + for (NodeTemplate spNode : serviceProxyResourceList) { + serviceProxy = createServiceProxy(spNode, service, toscaResourceStruct); + serviceProxyList.add(serviceProxy); + Optional<ConfigurationResourceCustomization> vnrResourceCustomization = getVnrNodeTemplate( + configurationNodeTemplatesList, toscaResourceStruct, serviceProxy); + + for (NodeTemplate configNode : configurationNodeTemplatesList) { + + List<RequirementAssignment> requirementsList = toscaResourceStruct.getSdcCsarHelper() + .getRequirementsOf(configNode).getAll(); + for (RequirementAssignment requirement : requirementsList) { + if (requirement.getNodeTemplateName().equals(spNode.getName())) { + ConfigurationResourceCustomization configurationResource = createConfiguration(configNode, + toscaResourceStruct, serviceProxy, vnrResourceCustomization); + + 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; + } + } + } + + } + } + + service.setConfigurationCustomizations(configurationResourceList); + service.setServiceProxyCustomizations(serviceProxyList); + } + + protected void processNetworkCollections(ToscaResourceStructure toscaResourceStruct, Service service) { + + List<NodeTemplate> networkCollectionList = toscaResourceStruct.getSdcCsarHelper() + .getServiceNodeTemplateBySdcType(SdcTypes.CR); + + if (networkCollectionList != null) { + for (NodeTemplate crNode : networkCollectionList) { + + createNetworkCollection(crNode, toscaResourceStruct, service); + collectionRepo.saveAndFlush(toscaResourceStruct.getCatalogCollectionResource()); + + List<NetworkInstanceGroup> networkInstanceGroupList = toscaResourceStruct + .getCatalogNetworkInstanceGroup(); + for (NetworkInstanceGroup networkInstanceGroup : networkInstanceGroupList) { + instanceGroupRepo.saveAndFlush(networkInstanceGroup); + } + + } + } + service.getCollectionResourceCustomizations() + .add(toscaResourceStruct.getCatalogCollectionResourceCustomization()); + } + + + protected void processVFResources(ToscaResourceStructure toscaResourceStruct, Service service, + VfResourceStructure vfResourceStructure) + throws Exception { + logger.debug("processVFResources"); + + List<NodeTemplate> vfNodeTemplatesList = toscaResourceStruct.getSdcCsarHelper().getServiceVfList(); + + for (NodeTemplate nodeTemplate : vfNodeTemplatesList) { + Metadata metadata = nodeTemplate.getMetaData(); + String vfCustomizationCategory = metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CATEGORY); + logger.debug("VF Category is : " + vfCustomizationCategory); + + // Do not treat Allotted Resources as VNF resources + if (ALLOTTED_RESOURCE.equalsIgnoreCase(vfCustomizationCategory)) { + continue; + } + + String vfCustomizationUUID = metadata.getValue(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"); + + processVfModules(toscaResourceStruct, vfResourceStructure, service, nodeTemplate, metadata, + vfCustomizationCategory); + } else { + logger.debug("Notification VF ResourceCustomizationUUID: " + + vfNotificationResource.getResourceCustomizationUUID() + " doesn't match " + + "Tosca VF Customization UUID: " + vfCustomizationUUID); + } + } + } + + /** + * This is used to process the PNF specific resource, including resource and resource_customization. {@link + * IEntityDetails} based API is used to retrieve information. Please check {@link ISdcCsarHelper} for details. + */ + protected void processPnfResources(ToscaResourceStructure toscaResourceStruct, Service service, + PnfResourceStructure resourceStructure) throws Exception { + logger.info("Processing PNF resource: {}", resourceStructure.getResourceInstance().getResourceUUID()); + + ISdcCsarHelper sdcCsarHelper = toscaResourceStruct.getSdcCsarHelper(); + EntityQuery entityQuery = EntityQuery.newBuilder(SdcTypes.PNF).build(); + TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.SERVICE).build(); + + List<IEntityDetails> entityDetailsList = sdcCsarHelper.getEntity(entityQuery, topologyTemplateQuery, false); + for (IEntityDetails entityDetails : entityDetailsList) { + Metadata metadata = entityDetails.getMetadata(); + String customizationUUID = metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID); + String modelUuid = metadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID); + String notifCustomizationUUID = resourceStructure.getResourceInstance().getResourceCustomizationUUID(); + if (customizationUUID != null && customizationUUID.equals(notifCustomizationUUID)) { + logger.info("Resource customization UUID: {} is the same as notified resource customizationUUID: {}", + customizationUUID, notifCustomizationUUID); + + if (checkExistingPnfResourceCutomization(customizationUUID)) { + logger.info("Resource customization UUID: {} already deployed", customizationUUID); + } else { + PnfResource pnfResource = findExistingPnfResource(service, modelUuid); + if (pnfResource == null) { + pnfResource = createPnfResource(entityDetails); + } + PnfResourceCustomization pnfResourceCustomization = createPnfResourceCustomization(entityDetails, + pnfResource); + pnfResource.getPnfResourceCustomizations().add(pnfResourceCustomization); + toscaResourceStruct.setPnfResourceCustomization(pnfResourceCustomization); + service.getPnfCustomizations().add(pnfResourceCustomization); + } + } else { + logger + .warn("Resource customization UUID: {} is NOT the same as notified resource customizationUUID: {}", + customizationUUID, notifCustomizationUUID); + } + } + } + + private PnfResource findExistingPnfResource(Service service, String modelUuid) { + PnfResource pnfResource = null; + for (PnfResourceCustomization pnfResourceCustomization : service.getPnfCustomizations()) { + if (pnfResourceCustomization.getPnfResources() != null && pnfResourceCustomization.getPnfResources() + .getModelUUID().equals(modelUuid)) { + pnfResource = pnfResourceCustomization.getPnfResources(); + } + } + if (pnfResource == null) { + pnfResource = pnfResourceRepository.findById(modelUuid).orElse(pnfResource); + } + return pnfResource; + } + + private boolean checkExistingPnfResourceCutomization(String customizationUUID) { + return pnfCustomizationRepository.findById(customizationUUID).isPresent(); + } + + /** + * Construct the {@link PnfResource} from {@link IEntityDetails} object. + */ + private PnfResource createPnfResource(IEntityDetails entity) { + PnfResource pnfResource = new PnfResource(); + Metadata metadata = entity.getMetadata(); + pnfResource.setModelInvariantUUID( + testNull(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID))); + pnfResource.setModelName(testNull(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME))); + pnfResource.setModelUUID(testNull(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID))); + pnfResource.setModelVersion( + testNull(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION))); + pnfResource.setDescription( + testNull(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION))); + pnfResource.setCategory(testNull(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CATEGORY))); + pnfResource.setSubCategory(testNull(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_SUBCATEGORY))); + pnfResource.setToscaNodeType(entity.getToscaType()); + return pnfResource; + } + + /** + * Construct the {@link PnfResourceCustomization} from {@link IEntityDetails} object. + */ + private PnfResourceCustomization createPnfResourceCustomization(IEntityDetails entityDetails, + PnfResource pnfResource) { + + PnfResourceCustomization pnfResourceCustomization = new PnfResourceCustomization(); + Metadata metadata = entityDetails.getMetadata(); + Map<String, Property> properties = entityDetails.getProperties(); + pnfResourceCustomization + .setModelCustomizationUUID(testNull(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID))); + pnfResourceCustomization.setModelInstanceName(entityDetails.getName()); + pnfResourceCustomization + .setNfFunction(getStringValue(properties.get(SdcPropertyNames.PROPERTY_NAME_NFFUNCTION))); + pnfResourceCustomization.setNfNamingCode(getStringValue(properties.get(SdcPropertyNames.PROPERTY_NAME_NFCODE))); + pnfResourceCustomization.setNfRole(getStringValue(properties.get(SdcPropertyNames.PROPERTY_NAME_NFROLE))); + pnfResourceCustomization.setNfType(getStringValue(properties.get(SdcPropertyNames.PROPERTY_NAME_NFTYPE))); + pnfResourceCustomization.setMultiStageDesign(getStringValue(properties.get(MULTI_STAGE_DESIGN))); + pnfResourceCustomization.setBlueprintName(getStringValue(properties.get(SDNC_MODEL_NAME))); + pnfResourceCustomization.setBlueprintVersion(getStringValue(properties.get(SDNC_MODEL_VERSION))); + + pnfResourceCustomization.setPnfResources(pnfResource); + + return pnfResourceCustomization; + } + + /** + * Get value from {@link Property} and cast to String value. Return empty String if property is null value. + */ + private String getStringValue(Property property) { + if (null == property) { + return ""; + } + Object value = property.getValue(); + return String.valueOf(value); + } + + protected void processVfModules(ToscaResourceStructure toscaResourceStruct, VfResourceStructure vfResourceStructure, + Service service, NodeTemplate nodeTemplate, Metadata metadata, String vfCustomizationCategory) + throws Exception { + + logger.debug("VF Category is : " + vfCustomizationCategory); + + VnfResourceCustomization vnfResource = createVnfResource(nodeTemplate, toscaResourceStruct, service); + + if (vfResourceStructure.getVfModuleStructure() != null && !vfResourceStructure.getVfModuleStructure() + .isEmpty()) { + + 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"); + + 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()); + } + + } + + } 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, Optional<String> distributionNotification, + String consumerId) { + WatchdogServiceModVerIdLookup modVerIdLookup = new WatchdogServiceModVerIdLookup(distributionId, servideUUID, + distributionNotification, consumerId); + watchdogModVerIdLookupRepository.saveAndFlush(modVerIdLookup); + + try { + + WatchdogDistributionStatus distributionStatus = new WatchdogDistributionStatus(distributionId); + watchdogDistributionStatusRepository.saveAndFlush(distributionStatus); + + } catch (ObjectOptimisticLockingFailureException e) { + logger.debug("ObjectOptimisticLockingFailureException in processWatchdog : " + e.toString()); + throw e; + } + } + + protected void extractHeatInformation(ToscaResourceStructure toscaResourceStruct, + VfResourceStructure vfResourceStructure) { + for (VfModuleArtifact vfModuleArtifact : vfResourceStructure.getArtifactsMapByUUID().values()) { + + switch (vfModuleArtifact.getArtifactInfo().getArtifactType()) { + case ASDCConfiguration.HEAT: + case ASDCConfiguration.HEAT_NESTED: + createHeatTemplateFromArtifact(vfResourceStructure, toscaResourceStruct, + vfModuleArtifact); + break; + case ASDCConfiguration.HEAT_VOL: + createHeatTemplateFromArtifact(vfResourceStructure, toscaResourceStruct, + vfModuleArtifact); + VfModuleArtifact envModuleArtifact = getHeatEnvArtifactFromGeneratedArtifact(vfResourceStructure, + vfModuleArtifact); + createHeatEnvFromArtifact(vfResourceStructure, envModuleArtifact); + break; + case ASDCConfiguration.HEAT_ENV: + createHeatEnvFromArtifact(vfResourceStructure, vfModuleArtifact); + break; + case ASDCConfiguration.HEAT_ARTIFACT: + createHeatFileFromArtifact(vfResourceStructure, vfModuleArtifact, + toscaResourceStruct); + break; + case ASDCConfiguration.HEAT_NET: + case ASDCConfiguration.OTHER: + logger.warn("{} {} {} {}", MessageEnum.ASDC_ARTIFACT_TYPE_NOT_SUPPORT.toString(), + vfModuleArtifact.getArtifactInfo().getArtifactType() + "(Artifact Name:" + vfModuleArtifact + .getArtifactInfo() + .getArtifactName() + ")", ErrorCode.DataError.getValue(), + "Artifact type not supported"); + break; + default: + break; + + } + } + } + + protected VfModuleArtifact getHeatEnvArtifactFromGeneratedArtifact(VfResourceStructure vfResourceStructure, + VfModuleArtifact vfModuleArtifact) { + String artifactName = vfModuleArtifact.getArtifactInfo().getArtifactName(); + artifactName = artifactName.substring(0, artifactName.indexOf('.')); + for (VfModuleArtifact moduleArtifact : vfResourceStructure.getArtifactsMapByUUID().values()) { + if (moduleArtifact.getArtifactInfo().getArtifactName().contains(artifactName) + && moduleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_ENV)) { + return moduleArtifact; + } + } + return null; + } + + public String verifyTheFilePrefixInArtifacts(String filebody, VfResourceStructure vfResourceStructure, + List<String> listTypes) { + String newFileBody = filebody; + for (VfModuleArtifact moduleArtifact : vfResourceStructure.getArtifactsMapByUUID().values()) { + + if (listTypes.contains(moduleArtifact.getArtifactInfo().getArtifactType())) { + + newFileBody = verifyTheFilePrefixInString(newFileBody, + moduleArtifact.getArtifactInfo().getArtifactName()); + } + } + return newFileBody; + } + + public String verifyTheFilePrefixInString(final String body, final String filenameToVerify) { + + String needlePrefix = "file:///"; + String prefixedFilenameToVerify = needlePrefix + filenameToVerify; + + if ((body == null) || (body.length() == 0) || (filenameToVerify == null) || (filenameToVerify.length() == 0)) { + return body; + } + + StringBuilder sb = new StringBuilder(body.length()); + + int currentIndex = 0; + int startIndex = 0; + + while (currentIndex != -1) { + startIndex = currentIndex; + currentIndex = body.indexOf(prefixedFilenameToVerify, startIndex); + + if (currentIndex == -1) { + break; + } + // We append from the startIndex up to currentIndex (start of File + // Name) + sb.append(body.substring(startIndex, currentIndex)); + sb.append(filenameToVerify); + + currentIndex += prefixedFilenameToVerify.length(); + } + + sb.append(body.substring(startIndex)); + + return sb.toString(); + } + + protected void createHeatTemplateFromArtifact(VfResourceStructure vfResourceStructure, + ToscaResourceStructure toscaResourceStruct, VfModuleArtifact vfModuleArtifact) { + HeatTemplate heatTemplate = new HeatTemplate(); + List<String> typeList = new ArrayList<>(); + typeList.add(ASDCConfiguration.HEAT_NESTED); + typeList.add(ASDCConfiguration.HEAT_ARTIFACT); + + heatTemplate.setTemplateBody( + verifyTheFilePrefixInArtifacts(vfModuleArtifact.getResult(), vfResourceStructure, typeList)); + heatTemplate.setTemplateName(vfModuleArtifact.getArtifactInfo().getArtifactName()); + + if (vfModuleArtifact.getArtifactInfo().getArtifactTimeout() != null) { + heatTemplate.setTimeoutMinutes(vfModuleArtifact.getArtifactInfo().getArtifactTimeout()); + } else { + heatTemplate.setTimeoutMinutes(240); + } + + heatTemplate.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription()); + heatTemplate.setVersion(BigDecimalVersion + .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion())); + heatTemplate.setArtifactUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID()); + + if (vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null) { + heatTemplate.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum()); + } else { + heatTemplate.setArtifactChecksum(MANUAL_RECORD); + } + + Set<HeatTemplateParam> heatParam = extractHeatTemplateParameters( + vfModuleArtifact.getResult(), vfModuleArtifact.getArtifactInfo().getArtifactUUID()); + heatTemplate.setParameters(heatParam); + vfModuleArtifact.setHeatTemplate(heatTemplate); + } + + protected void createHeatEnvFromArtifact(VfResourceStructure vfResourceStructure, + VfModuleArtifact vfModuleArtifact) { + HeatEnvironment heatEnvironment = new HeatEnvironment(); + heatEnvironment.setName(vfModuleArtifact.getArtifactInfo().getArtifactName()); + List<String> typeList = new ArrayList<>(); + typeList.add(ASDCConfiguration.HEAT); + typeList.add(ASDCConfiguration.HEAT_VOL); + heatEnvironment.setEnvironment( + verifyTheFilePrefixInArtifacts(vfModuleArtifact.getResult(), vfResourceStructure, typeList)); + heatEnvironment.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription()); + heatEnvironment.setVersion(BigDecimalVersion + .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion())); + heatEnvironment.setArtifactUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID()); + + if (vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null) { + heatEnvironment.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum()); + } else { + heatEnvironment.setArtifactChecksum(MANUAL_RECORD); + } + vfModuleArtifact.setHeatEnvironment(heatEnvironment); + } + + protected void createHeatFileFromArtifact(VfResourceStructure vfResourceStructure, + VfModuleArtifact vfModuleArtifact, ToscaResourceStructure toscaResourceStruct) { + + HeatFiles heatFile = new HeatFiles(); + heatFile.setAsdcUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID()); + heatFile.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription()); + heatFile.setFileBody(vfModuleArtifact.getResult()); + heatFile.setFileName(vfModuleArtifact.getArtifactInfo().getArtifactName()); + heatFile.setVersion(BigDecimalVersion + .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion())); + toscaResourceStruct.setHeatFilesUUID(vfModuleArtifact.getArtifactInfo().getArtifactUUID()); + if (vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null) { + heatFile.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum()); + } else { + heatFile.setArtifactChecksum(MANUAL_RECORD); + } + vfModuleArtifact.setHeatFiles(heatFile); + } + + protected Service createService(ToscaResourceStructure toscaResourceStructure, + ResourceStructure resourceStructure) { + + Metadata serviceMetadata = toscaResourceStructure.getServiceMetadata(); + + Service service = new Service(); + + if (serviceMetadata != null) { + + if (toscaResourceStructure.getServiceVersion() != null) { + service.setModelVersion(toscaResourceStructure.getServiceVersion()); + } + + service.setServiceType(serviceMetadata.getValue("serviceType")); + service.setServiceRole(serviceMetadata.getValue("serviceRole")); + service.setCategory(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_CATEGORY)); + service.setDescription(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)); + service.setModelName(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME)); + service.setModelUUID(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID)); + service.setEnvironmentContext(serviceMetadata.getValue("environmentContext")); + + if (resourceStructure != null) { + service.setWorkloadContext(resourceStructure.getNotification().getWorkloadContext()); + } + + service.setModelInvariantUUID(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)); + service.setCsar(toscaResourceStructure.getCatalogToscaCsar()); + } + + toscaResourceStructure.setCatalogService(service); + return service; + } + + protected ServiceProxyResourceCustomization createServiceProxy(NodeTemplate nodeTemplate, Service service, + ToscaResourceStructure toscaResourceStructure) { + + Metadata spMetadata = nodeTemplate.getMetaData(); + + ServiceProxyResourceCustomization spCustomizationResource = new ServiceProxyResourceCustomization(); + + Set<ServiceProxyResourceCustomization> serviceProxyCustomizationSet = new HashSet<>(); + + spCustomizationResource.setModelName(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME)); + spCustomizationResource + .setModelInvariantUUID(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)); + spCustomizationResource.setModelUUID(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID)); + spCustomizationResource.setModelVersion(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)); + spCustomizationResource.setDescription(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)); + + spCustomizationResource + .setModelCustomizationUUID(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)); + spCustomizationResource.setModelInstanceName(nodeTemplate.getName()); + spCustomizationResource.setToscaNodeType(nodeTemplate.getType()); + + String sourceServiceUUID = spMetadata.getValue("sourceModelUuid"); + + Service sourceService = serviceRepo.findOneByModelUUID(sourceServiceUUID); + + spCustomizationResource.setSourceService(sourceService); + spCustomizationResource.setToscaNodeType(nodeTemplate.getType()); + serviceProxyCustomizationSet.add(spCustomizationResource); + + toscaResourceStructure.setCatalogServiceProxyResourceCustomization(spCustomizationResource); + + return spCustomizationResource; + } + + protected ConfigurationResourceCustomization createConfiguration(NodeTemplate nodeTemplate, + ToscaResourceStructure toscaResourceStructure, ServiceProxyResourceCustomization spResourceCustomization, + Optional<ConfigurationResourceCustomization> vnrResourceCustomization) { + + ConfigurationResourceCustomization configCustomizationResource = getConfigurationResourceCustomization( + nodeTemplate, + toscaResourceStructure, spResourceCustomization); + + ConfigurationResource configResource = getConfigurationResource(nodeTemplate); + + Set<ConfigurationResourceCustomization> configResourceCustomizationSet = new HashSet<>(); + + StatefulEntityType entityType = nodeTemplate.getTypeDefinition(); + String type = entityType.getType(); + + if (NODES_VRF_ENTRY.equals(type)) { + configCustomizationResource.setConfigResourceCustomization(vnrResourceCustomization.orElse(null)); + } + + configCustomizationResource.setConfigurationResource(configResource); + + configResourceCustomizationSet.add(configCustomizationResource); + + configResource.setConfigurationResourceCustomization(configResourceCustomizationSet); + + toscaResourceStructure.setCatalogConfigurationResource(configResource); + + toscaResourceStructure.setCatalogConfigurationResourceCustomization(configCustomizationResource); + + return configCustomizationResource; + } + + protected ConfigurationResource createFabricConfiguration(NodeTemplate nodeTemplate, + ToscaResourceStructure toscaResourceStructure) { + + Metadata fabricMetadata = nodeTemplate.getMetaData(); + + ConfigurationResource configResource = new ConfigurationResource(); + + configResource.setModelName(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME)); + configResource.setModelInvariantUUID(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)); + configResource.setModelUUID(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID)); + configResource.setModelVersion(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)); + configResource.setDescription(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)); + configResource.setToscaNodeType(nodeTemplate.getType()); + + return configResource; + } + + protected void createToscaCsar(ToscaResourceStructure toscaResourceStructure) { + ToscaCsar toscaCsar = new ToscaCsar(); + if (toscaResourceStructure.getToscaArtifact().getArtifactChecksum() != null) { + toscaCsar.setArtifactChecksum(toscaResourceStructure.getToscaArtifact().getArtifactChecksum()); + } else { + toscaCsar.setArtifactChecksum(MANUAL_RECORD); + } + toscaCsar.setArtifactUUID(toscaResourceStructure.getToscaArtifact().getArtifactUUID()); + toscaCsar.setName(toscaResourceStructure.getToscaArtifact().getArtifactName()); + toscaCsar.setVersion(toscaResourceStructure.getToscaArtifact().getArtifactVersion()); + toscaCsar.setDescription(toscaResourceStructure.getToscaArtifact().getArtifactDescription()); + toscaCsar.setUrl(toscaResourceStructure.getToscaArtifact().getArtifactURL()); + + toscaResourceStructure.setCatalogToscaCsar(toscaCsar); + } + + protected VnfcCustomization findExistingVfc(Set<VnfcCustomization> vnfcCustomizations, String customizationUUID) { + VnfcCustomization vnfcCustomization = null; + for (VnfcCustomization vnfcCustom : vnfcCustomizations) { + if (vnfcCustom != null && vnfcCustom.getModelCustomizationUUID().equals(customizationUUID)) { + vnfcCustomization = vnfcCustom; + } + } + + if (vnfcCustomization == null) { + vnfcCustomization = vnfcCustomizationRepo.findOneByModelCustomizationUUID(customizationUUID); + } + + return vnfcCustomization; + } + + protected CvnfcCustomization findExistingCvfc(Set<CvnfcCustomization> cvnfcCustomizations, + String customizationUUID) { + CvnfcCustomization cvnfcCustomization = null; + for (CvnfcCustomization cvnfcCustom : cvnfcCustomizations) { + if (cvnfcCustom != null && cvnfcCustom.getModelCustomizationUUID().equals(customizationUUID)) { + cvnfcCustomization = cvnfcCustom; + } + } + + if (cvnfcCustomization == null) { + cvnfcCustomization = cvnfcCustomizationRepo.findOneByModelCustomizationUUID(customizationUUID); + } + + return cvnfcCustomization; + } + + protected NetworkResourceCustomization createNetwork(NodeTemplate networkNodeTemplate, + ToscaResourceStructure toscaResourceStructure, HeatTemplate heatTemplate, String aicMax, String aicMin, + Service service) { + + NetworkResourceCustomization networkResourceCustomization = networkCustomizationRepo + .findOneByModelCustomizationUUID( + networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)); + + 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) { + + NetworkResource networkResource = createNetworkResource(networkNodeTemplate, toscaResourceStructure, + heatTemplate, + aicMax, aicMin); + + networkResourceCustomization.setNetworkResource(networkResource); + + networkCustomizationRepo.saveAndFlush(networkResourceCustomization); + + } else if (networkResourceCustomization == null) { + networkResourceCustomization = createNetworkResourceCustomization(networkNodeTemplate, + toscaResourceStructure); + + NetworkResource networkResource = findExistingNetworkResource(service, + networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)); + if (networkResource == null) { + networkResource = createNetworkResource(networkNodeTemplate, toscaResourceStructure, heatTemplate, + aicMax, aicMin); + } + + networkResource.addNetworkResourceCustomization(networkResourceCustomization); + networkResourceCustomization.setNetworkResource(networkResource); + } + + return networkResourceCustomization; + } + + protected NetworkResource findExistingNetworkResource(Service service, String modelUUID) { + NetworkResource networkResource = null; + for (NetworkResourceCustomization networkCustom : service.getNetworkCustomizations()) { + if (networkCustom.getNetworkResource() != null + && networkCustom.getNetworkResource().getModelUUID().equals(modelUUID)) { + networkResource = networkCustom.getNetworkResource(); + } + } + if (networkResource == null) { + networkResource = networkRepo.findResourceByModelUUID(modelUUID); + } + + return networkResource; + } + + protected NetworkResourceCustomization createNetworkResourceCustomization(NodeTemplate networkNodeTemplate, + ToscaResourceStructure toscaResourceStructure) { + NetworkResourceCustomization networkResourceCustomization = new NetworkResourceCustomization(); + networkResourceCustomization.setModelInstanceName( + testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME))); + networkResourceCustomization.setModelCustomizationUUID( + testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID))); + + networkResourceCustomization.setNetworkTechnology( + testNull(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate, + SdcPropertyNames.PROPERTY_NAME_NETWORKTECHNOLOGY))); + networkResourceCustomization.setNetworkType(testNull(toscaResourceStructure.getSdcCsarHelper() + .getNodeTemplatePropertyLeafValue(networkNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKTYPE))); + networkResourceCustomization.setNetworkRole(testNull(toscaResourceStructure.getSdcCsarHelper() + .getNodeTemplatePropertyLeafValue(networkNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKROLE))); + networkResourceCustomization.setNetworkScope(testNull(toscaResourceStructure.getSdcCsarHelper() + .getNodeTemplatePropertyLeafValue(networkNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKSCOPE))); + return networkResourceCustomization; + } + + protected NetworkResource createNetworkResource(NodeTemplate networkNodeTemplate, + ToscaResourceStructure toscaResourceStructure, HeatTemplate heatTemplate, String aicMax, String aicMin) { + NetworkResource networkResource = new NetworkResource(); + String providerNetwork = toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue( + networkNodeTemplate, SdcPropertyNames.PROPERTY_NAME_PROVIDERNETWORK_ISPROVIDERNETWORK); + + if ("true".equalsIgnoreCase(providerNetwork)) { + networkResource.setNeutronNetworkType(PROVIDER); + } else { + networkResource.setNeutronNetworkType(BASIC); + } + + networkResource.setModelName( + testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME))); + + networkResource.setModelInvariantUUID( + testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID))); + networkResource.setModelUUID( + testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID))); + networkResource.setModelVersion( + testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION))); + + networkResource.setAicVersionMax(aicMax); + networkResource.setAicVersionMin(aicMin); + networkResource.setToscaNodeType(networkNodeTemplate.getType()); + networkResource.setDescription( + testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION))); + networkResource.setOrchestrationMode(HEAT); + networkResource.setHeatTemplate(heatTemplate); + return networkResource; + } + + protected CollectionNetworkResourceCustomization createNetworkCollection(NodeTemplate networkNodeTemplate, + ToscaResourceStructure toscaResourceStructure, Service service) { + + CollectionNetworkResourceCustomization collectionNetworkResourceCustomization = new CollectionNetworkResourceCustomization(); + + // **** Build Object to populate Collection_Resource table + CollectionResource collectionResource = new CollectionResource(); + + collectionResource + .setModelName(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)); + collectionResource.setModelInvariantUUID( + networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)); + collectionResource + .setModelUUID(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)); + collectionResource + .setModelVersion(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)); + collectionResource + .setDescription(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)); + collectionResource.setToscaNodeType(networkNodeTemplate.getType()); + + toscaResourceStructure.setCatalogCollectionResource(collectionResource); + + // **** Build object to populate Collection_Resource_Customization table + NetworkCollectionResourceCustomization ncfc = new NetworkCollectionResourceCustomization(); + + ncfc.setFunction(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate, + "cr_function")); + ncfc.setRole(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate, + "cr_role")); + ncfc.setType(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate, + "cr_type")); + + ncfc.setModelInstanceName(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)); + ncfc.setModelCustomizationUUID( + networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)); + + Set<CollectionNetworkResourceCustomization> networkResourceCustomizationSet = new HashSet<>(); + networkResourceCustomizationSet.add(collectionNetworkResourceCustomization); + + ncfc.setNetworkResourceCustomization(networkResourceCustomizationSet); + + ncfc.setCollectionResource(collectionResource); + toscaResourceStructure.setCatalogCollectionResourceCustomization(ncfc); + + //*** Build object to populate the Instance_Group table + List<Group> groupList = toscaResourceStructure.getSdcCsarHelper() + .getGroupsOfOriginOfNodeTemplateByToscaGroupType(networkNodeTemplate, + "org.openecomp.groups.NetworkCollection"); + + List<NetworkInstanceGroup> networkInstanceGroupList = new ArrayList<>(); + + List<CollectionResourceInstanceGroupCustomization> collectionResourceInstanceGroupCustomizationList = new ArrayList<CollectionResourceInstanceGroupCustomization>(); + + for (Group group : groupList) { + + NetworkInstanceGroup networkInstanceGroup = new NetworkInstanceGroup(); + Metadata instanceMetadata = group.getMetadata(); + networkInstanceGroup.setModelName(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME)); + networkInstanceGroup + .setModelInvariantUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)); + networkInstanceGroup.setModelUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID)); + networkInstanceGroup.setModelVersion(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)); + networkInstanceGroup.setToscaNodeType(group.getType()); + networkInstanceGroup.setRole(SubType.SUB_INTERFACE.toString()); // Set + // Role + networkInstanceGroup.setType(InstanceGroupType.L3_NETWORK); // Set + // type + networkInstanceGroup.setCollectionResource(collectionResource); + + // ****Build object to populate + // Collection_Resource_Instance_Group_Customization table + CollectionResourceInstanceGroupCustomization crInstanceGroupCustomization = new CollectionResourceInstanceGroupCustomization(); + crInstanceGroupCustomization.setInstanceGroup(networkInstanceGroup); + crInstanceGroupCustomization.setModelUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID)); + crInstanceGroupCustomization.setModelCustomizationUUID( + networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)); + + // Loop through the template policy to find the subinterface_network_quantity property name. Then extract the value for it. + List<Policy> policyList = toscaResourceStructure.getSdcCsarHelper() + .getPoliciesOfOriginOfNodeTemplateByToscaPolicyType(networkNodeTemplate, + "org.openecomp.policies.scaling.Fixed"); + + if (policyList != null) { + for (Policy policy : policyList) { + for (String policyNetworkCollection : policy.getTargets()) { + + if (policyNetworkCollection.equalsIgnoreCase(group.getName())) { + + Map<String, Object> propMap = policy.getPolicyProperties(); + + if (propMap.get("quantity") != null) { + + String quantity = toscaResourceStructure.getSdcCsarHelper() + .getNodeTemplatePropertyLeafValue(networkNodeTemplate, + getPropertyInput(propMap.get("quantity").toString())); + + if (quantity != null) { + crInstanceGroupCustomization + .setSubInterfaceNetworkQuantity(Integer.parseInt(quantity)); + } + + } + + } + } + } + } + + crInstanceGroupCustomization.setDescription( + toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate, + instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME) + + "_network_collection_description")); + crInstanceGroupCustomization.setFunction( + toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate, + instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME) + + "_network_collection_function")); + crInstanceGroupCustomization.setCollectionResourceCust(ncfc); + collectionResourceInstanceGroupCustomizationList.add(crInstanceGroupCustomization); + + networkInstanceGroup + .setCollectionInstanceGroupCustomizations(collectionResourceInstanceGroupCustomizationList); + + networkInstanceGroupList.add(networkInstanceGroup); + + toscaResourceStructure.setCatalogNetworkInstanceGroup(networkInstanceGroupList); + + List<NodeTemplate> vlNodeList = toscaResourceStructure.getSdcCsarHelper() + .getNodeTemplateBySdcType(networkNodeTemplate, SdcTypes.VL); + + List<CollectionNetworkResourceCustomization> collectionNetworkResourceCustomizationList = new ArrayList<>(); + + //*****Build object to populate the NetworkResource table + NetworkResource networkResource = new NetworkResource(); + + for (NodeTemplate vlNodeTemplate : vlNodeList) { + + String providerNetwork = toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue( + vlNodeTemplate, SdcPropertyNames.PROPERTY_NAME_PROVIDERNETWORK_ISPROVIDERNETWORK); + + if ("true".equalsIgnoreCase(providerNetwork)) { + networkResource.setNeutronNetworkType(PROVIDER); + } else { + networkResource.setNeutronNetworkType(BASIC); + } + + networkResource + .setModelName(vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)); + + networkResource.setModelInvariantUUID( + vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)); + networkResource + .setModelUUID(vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)); + networkResource + .setModelVersion(vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)); + + networkResource.setAicVersionMax( + vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES)); + + TempNetworkHeatTemplateLookup tempNetworkLookUp = tempNetworkLookupRepo + .findFirstBynetworkResourceModelName( + vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)); + + if (tempNetworkLookUp != null) { + + HeatTemplate heatTemplate = heatRepo + .findByArtifactUuid(tempNetworkLookUp.getHeatTemplateArtifactUuid()); + networkResource.setHeatTemplate(heatTemplate); + + networkResource.setAicVersionMin(tempNetworkLookUp.getAicVersionMin()); + + } + + networkResource.setToscaNodeType(vlNodeTemplate.getType()); + networkResource + .setDescription(vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)); + networkResource.setOrchestrationMode(HEAT); + + // Build object to populate the + // Collection_Network_Resource_Customization table + for (NodeTemplate memberNode : group.getMemberNodes()) { + collectionNetworkResourceCustomization.setModelInstanceName(memberNode.getName()); + } + + collectionNetworkResourceCustomization.setModelCustomizationUUID( + vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)); + + collectionNetworkResourceCustomization.setNetworkTechnology( + toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(vlNodeTemplate, + SdcPropertyNames.PROPERTY_NAME_NETWORKTECHNOLOGY)); + collectionNetworkResourceCustomization.setNetworkType(toscaResourceStructure.getSdcCsarHelper() + .getNodeTemplatePropertyLeafValue(vlNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKTYPE)); + collectionNetworkResourceCustomization.setNetworkRole(toscaResourceStructure.getSdcCsarHelper() + .getNodeTemplatePropertyLeafValue(vlNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKROLE)); + collectionNetworkResourceCustomization.setNetworkScope(toscaResourceStructure.getSdcCsarHelper() + .getNodeTemplatePropertyLeafValue(vlNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKSCOPE)); + collectionNetworkResourceCustomization.setInstanceGroup(networkInstanceGroup); + collectionNetworkResourceCustomization.setNetworkResource(networkResource); + collectionNetworkResourceCustomization.setNetworkResourceCustomization(ncfc); + + collectionNetworkResourceCustomizationList.add(collectionNetworkResourceCustomization); + } + + } + + return collectionNetworkResourceCustomization; + } + + protected VnfcInstanceGroupCustomization createVNFCInstanceGroup(NodeTemplate vnfcNodeTemplate, Group group, + VnfResourceCustomization vnfResourceCustomization, ToscaResourceStructure toscaResourceStructure) { + + Metadata instanceMetadata = group.getMetadata(); + // Populate InstanceGroup + VFCInstanceGroup vfcInstanceGroup = new VFCInstanceGroup(); + + vfcInstanceGroup.setModelName(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME)); + vfcInstanceGroup.setModelInvariantUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)); + vfcInstanceGroup.setModelUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID)); + vfcInstanceGroup.setModelVersion(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)); + vfcInstanceGroup.setToscaNodeType(group.getType()); + vfcInstanceGroup.setRole("SUB-INTERFACE"); // Set Role + vfcInstanceGroup.setType(InstanceGroupType.VNFC); // Set type + + //Populate VNFCInstanceGroupCustomization + VnfcInstanceGroupCustomization vfcInstanceGroupCustom = new VnfcInstanceGroupCustomization(); + + vfcInstanceGroupCustom.setModelCustomizationUUID(vnfResourceCustomization.getModelCustomizationUUID()); + vfcInstanceGroupCustom.setModelUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID)); + vfcInstanceGroupCustom.setDescription(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)); + + String getInputName = null; + String groupProperty = toscaResourceStructure.getSdcCsarHelper() + .getGroupPropertyLeafValue(group, "vfc_instance_group_function"); + if (groupProperty != null) { + int getInputIndex = groupProperty.indexOf("{get_input="); + if (getInputIndex > -1) { + getInputName = groupProperty.substring(getInputIndex + 11, groupProperty.length() - 1); + } + } + vfcInstanceGroupCustom.setFunction( + toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(vnfcNodeTemplate, getInputName)); + + vfcInstanceGroupCustom.setInstanceGroup(vfcInstanceGroup); + vfcInstanceGroupCustom.setVnfResourceCust(vnfResourceCustomization); + + return vfcInstanceGroupCustom; + + } + + protected VfModuleCustomization createVFModuleResource(Group group, NodeTemplate vfTemplate, + ToscaResourceStructure toscaResourceStructure, VfResourceStructure vfResourceStructure, + IVfModuleData vfModuleData, VnfResourceCustomization vnfResource, Service service, + Set<CvnfcCustomization> existingCvnfcSet, Set<VnfcCustomization> existingVnfcSet) { + + VfModuleCustomization vfModuleCustomization = findExistingVfModuleCustomization(vnfResource, + vfModuleData.getVfModuleModelCustomizationUUID()); + if (vfModuleCustomization == null) { + VfModule vfModule = findExistingVfModule(vnfResource, + vfTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELUUID)); + Metadata vfMetadata = group.getMetadata(); + if (vfModule == null) { + vfModule = createVfModule(group, toscaResourceStructure, vfModuleData, vfMetadata); + } + + vfModuleCustomization = createVfModuleCustomization(group, toscaResourceStructure, vfModule, vfModuleData); + setHeatInformationForVfModule(toscaResourceStructure, vfResourceStructure, vfModule, vfModuleCustomization, + vfMetadata); + vfModuleCustomization.setVfModule(vfModule); + vfModule.getVfModuleCustomization().add(vfModuleCustomization); + vnfResource.getVfModuleCustomizations().add(vfModuleCustomization); + } else { + vfResourceStructure.setAlreadyDeployed(true); + } + + //****************************************************************************************************************** + //* Extract VFC's and CVFC's then add them to VFModule + //****************************************************************************************************************** + + Set<VnfVfmoduleCvnfcConfigurationCustomization> vnfVfmoduleCvnfcConfigurationCustomizations = new HashSet<VnfVfmoduleCvnfcConfigurationCustomization>(); + Set<CvnfcCustomization> cvnfcCustomizations = new HashSet<CvnfcCustomization>(); + Set<VnfcCustomization> vnfcCustomizations = new HashSet<VnfcCustomization>(); + + // Only set the CVNFC if this vfModule group is a member of it. + List<NodeTemplate> groupMembers = toscaResourceStructure.getSdcCsarHelper() + .getMembersOfVfModule(vfTemplate, group); + String vfModuleMemberName = null; + + for (NodeTemplate node : groupMembers) { + vfModuleMemberName = node.getName(); + } + + // Extract CVFC lists + List<NodeTemplate> cvfcList = toscaResourceStructure.getSdcCsarHelper() + .getNodeTemplateBySdcType(vfTemplate, SdcTypes.CVFC); + + for (NodeTemplate cvfcTemplate : cvfcList) { + + CvnfcCustomization existingCvnfcCustomization = findExistingCvfc(existingCvnfcSet, + cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)); + + if (vfModuleMemberName != null && vfModuleMemberName.equalsIgnoreCase(cvfcTemplate.getName())) { + + //Extract associated VFC - Should always be just one + List<NodeTemplate> vfcList = toscaResourceStructure.getSdcCsarHelper() + .getNodeTemplateBySdcType(cvfcTemplate, SdcTypes.VFC); + + for (NodeTemplate vfcTemplate : vfcList) { + + VnfcCustomization vnfcCustomization = new VnfcCustomization(); + VnfcCustomization existingVnfcCustomization = null; + + existingVnfcCustomization = findExistingVfc(existingVnfcSet, + vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)); + + if (existingVnfcCustomization == null) { + vnfcCustomization = new VnfcCustomization(); } else { - throw new ArtifactInstallerException ("No HeatTemplate found for artifactUUID: " - + tempNetworkLookUp.getHeatTemplateArtifactUuid ()); - } - } else { - NetworkResourceCustomization networkCustomization = createNetwork (vlNode, - toscaResourceStruct, - null, - null, - null, - service); - service.getNetworkCustomizations().add (networkCustomization); - logger.debug ("No NetworkResourceName found in TempNetworkHeatTemplateLookup for " - + networkResourceModelName); - } - - } - } - } - - protected void processAllottedResources(ToscaResourceStructure toscaResourceStruct, Service service, - List<NodeTemplate> allottedResourceList) { - if (allottedResourceList != null) { - for (NodeTemplate allottedNode : allottedResourceList) { - service.getAllottedCustomizations() - .add(createAllottedResource(allottedNode, toscaResourceStruct, service)); - } - } - } - - - protected ConfigurationResource getConfigurationResource(NodeTemplate nodeTemplate) { - Metadata metadata = nodeTemplate.getMetaData(); - ConfigurationResource configResource = new ConfigurationResource(); - configResource.setModelName(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME)); - configResource.setModelInvariantUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)); - configResource.setModelUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID)); - configResource.setModelVersion(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)); - configResource.setDescription(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)); - configResource.setToscaNodeType(nodeTemplate.getType()); - return configResource; - } - - protected ConfigurationResourceCustomization getConfigurationResourceCustomization(NodeTemplate nodeTemplate, ToscaResourceStructure toscaResourceStructure, - ServiceProxyResourceCustomization spResourceCustomization ) { - Metadata metadata = nodeTemplate.getMetaData(); - - ConfigurationResource configResource = getConfigurationResource(nodeTemplate); - - ConfigurationResourceCustomization configCustomizationResource = new ConfigurationResourceCustomization(); - - Set<ConfigurationResourceCustomization> configResourceCustomizationSet = new HashSet<>(); - - configCustomizationResource.setModelCustomizationUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)); - configCustomizationResource.setModelInstanceName(nodeTemplate.getName()); - - configCustomizationResource.setNfFunction(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFFUNCTION)); - configCustomizationResource.setNfRole(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFROLE)); - configCustomizationResource.setNfType(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFTYPE)); - configCustomizationResource.setServiceProxyResourceCustomizationUUID(spResourceCustomization.getModelCustomizationUUID()); - - configCustomizationResource.setConfigurationResource(configResource); - configResourceCustomizationSet.add(configCustomizationResource); - - configResource.setConfigurationResourceCustomization(configResourceCustomizationSet); - return configCustomizationResource; - } - - - protected Optional<ConfigurationResourceCustomization> getVnrNodeTemplate(List<NodeTemplate> configurationNodeTemplatesList, - ToscaResourceStructure toscaResourceStructure, ServiceProxyResourceCustomization spResourceCustomization) { - Optional<ConfigurationResourceCustomization> configurationResourceCust = Optional.empty(); - for (NodeTemplate nodeTemplate : configurationNodeTemplatesList) { - StatefulEntityType entityType = nodeTemplate.getTypeDefinition(); - String type = entityType.getType(); - - if(VLAN_NETWORK_RECEPTOR.equals(type)) { - configurationResourceCust= Optional.of(getConfigurationResourceCustomization(nodeTemplate, - toscaResourceStructure,spResourceCustomization)); - break; - } - } - - return configurationResourceCust; - } - - protected void processServiceProxyAndConfiguration(ToscaResourceStructure toscaResourceStruct, Service service) { - - List<NodeTemplate> serviceProxyResourceList = toscaResourceStruct.getSdcCsarHelper().getServiceNodeTemplateBySdcType(SdcTypes.SERVICE_PROXY); - - List<NodeTemplate> configurationNodeTemplatesList = toscaResourceStruct.getSdcCsarHelper().getServiceNodeTemplateBySdcType(SdcTypes.CONFIGURATION); - - List<ServiceProxyResourceCustomization> serviceProxyList = new ArrayList<ServiceProxyResourceCustomization>(); - List<ConfigurationResourceCustomization> configurationResourceList = new ArrayList<ConfigurationResourceCustomization>(); - - ServiceProxyResourceCustomization serviceProxy = null; - - if (serviceProxyResourceList != null) { - for (NodeTemplate spNode : serviceProxyResourceList) { - serviceProxy = createServiceProxy(spNode, service, toscaResourceStruct); - serviceProxyList.add(serviceProxy); - Optional<ConfigurationResourceCustomization> vnrResourceCustomization = getVnrNodeTemplate(configurationNodeTemplatesList,toscaResourceStruct,serviceProxy); - - for (NodeTemplate configNode : configurationNodeTemplatesList) { - - List<RequirementAssignment> requirementsList = toscaResourceStruct.getSdcCsarHelper().getRequirementsOf(configNode).getAll(); - for (RequirementAssignment requirement : requirementsList) { - if (requirement.getNodeTemplateName().equals(spNode.getName())) { - ConfigurationResourceCustomization configurationResource = createConfiguration(configNode, toscaResourceStruct, serviceProxy, vnrResourceCustomization); - - 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; - } - } - } - - } - } - - service.setConfigurationCustomizations(configurationResourceList); - service.setServiceProxyCustomizations(serviceProxyList); - } - - protected void processNetworkCollections(ToscaResourceStructure toscaResourceStruct, Service service) { - - List<NodeTemplate> networkCollectionList = toscaResourceStruct.getSdcCsarHelper().getServiceNodeTemplateBySdcType(SdcTypes.CR); - - if (networkCollectionList != null) { - for (NodeTemplate crNode : networkCollectionList) { - - createNetworkCollection(crNode, toscaResourceStruct, service); - collectionRepo.saveAndFlush(toscaResourceStruct.getCatalogCollectionResource()); - - List<NetworkInstanceGroup> networkInstanceGroupList = toscaResourceStruct.getCatalogNetworkInstanceGroup(); - for(NetworkInstanceGroup networkInstanceGroup : networkInstanceGroupList){ - instanceGroupRepo.saveAndFlush(networkInstanceGroup); - } - - } - } - service.getCollectionResourceCustomizations().add(toscaResourceStruct.getCatalogCollectionResourceCustomization()); - } - - - protected void processVFResources (ToscaResourceStructure toscaResourceStruct, Service service, VfResourceStructure vfResourceStructure) - throws Exception{ - logger.debug("processVFResources"); - - List<NodeTemplate> vfNodeTemplatesList = toscaResourceStruct.getSdcCsarHelper().getServiceVfList(); -// String servicecategory = toscaResourceStruct.getCatalogService().getCategory(); -// String serviceType = toscaResourceStruct.getCatalogService().getServiceType(); - - for (NodeTemplate nodeTemplate : vfNodeTemplatesList) { - Metadata metadata = nodeTemplate.getMetaData(); - String vfCustomizationCategory = metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CATEGORY); - logger.debug("VF Category is : " + vfCustomizationCategory); - - // Do not treat Allotted Resources as VNF resources - if(ALLOTTED_RESOURCE.equalsIgnoreCase(vfCustomizationCategory)){ - continue; - } - - String vfCustomizationUUID = metadata.getValue(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"); - - processVfModules(toscaResourceStruct, vfResourceStructure, service, nodeTemplate, metadata, - vfCustomizationCategory); - } else { - logger.debug("Notification VF ResourceCustomizationUUID: " - + vfNotificationResource.getResourceCustomizationUUID() + " doesn't match " - + "Tosca VF Customization UUID: " + vfCustomizationUUID); - } - } - } - - - protected void processVfModules(ToscaResourceStructure toscaResourceStruct, VfResourceStructure vfResourceStructure, - Service service, NodeTemplate nodeTemplate, Metadata metadata, String vfCustomizationCategory) throws Exception { - - logger.debug("VF Category is : " + vfCustomizationCategory); - - if(vfResourceStructure.getVfModuleStructure() != null && !vfResourceStructure.getVfModuleStructure().isEmpty()) - { - - 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); - } - } - } - - public void processWatchdog(String distributionId, String servideUUID, Optional<String> distributionNotification, - String consumerId) { - WatchdogServiceModVerIdLookup modVerIdLookup = new WatchdogServiceModVerIdLookup(distributionId, servideUUID, - distributionNotification, consumerId); - watchdogModVerIdLookupRepository.saveAndFlush(modVerIdLookup); - - try{ - - WatchdogDistributionStatus distributionStatus = new WatchdogDistributionStatus(distributionId); - watchdogDistributionStatusRepository.saveAndFlush(distributionStatus); - - } catch(ObjectOptimisticLockingFailureException e){ - logger.debug("ObjectOptimisticLockingFailureException in processWatchdog : " + e.toString()); - throw e; - } - } - - protected void extractHeatInformation(ToscaResourceStructure toscaResourceStruct, - VfResourceStructure vfResourceStructure) { - for (VfModuleArtifact vfModuleArtifact : vfResourceStructure.getArtifactsMapByUUID().values()) { - - switch (vfModuleArtifact.getArtifactInfo().getArtifactType()) { - case ASDCConfiguration.HEAT: - case ASDCConfiguration.HEAT_NESTED: - createHeatTemplateFromArtifact(vfResourceStructure, toscaResourceStruct, - vfModuleArtifact); - break; - case ASDCConfiguration.HEAT_VOL: - createHeatTemplateFromArtifact(vfResourceStructure, toscaResourceStruct, - vfModuleArtifact); - VfModuleArtifact envModuleArtifact = getHeatEnvArtifactFromGeneratedArtifact(vfResourceStructure, vfModuleArtifact); - createHeatEnvFromArtifact(vfResourceStructure, envModuleArtifact); - break; - case ASDCConfiguration.HEAT_ENV: - createHeatEnvFromArtifact(vfResourceStructure, vfModuleArtifact); - break; - case ASDCConfiguration.HEAT_ARTIFACT: - createHeatFileFromArtifact(vfResourceStructure, vfModuleArtifact, - toscaResourceStruct); - break; - case ASDCConfiguration.HEAT_NET: - case ASDCConfiguration.OTHER: - logger.warn("{} {} {} {}", MessageEnum.ASDC_ARTIFACT_TYPE_NOT_SUPPORT.toString(), - vfModuleArtifact.getArtifactInfo().getArtifactType() + "(Artifact Name:" + vfModuleArtifact.getArtifactInfo() - .getArtifactName() + ")", ErrorCode.DataError.getValue(), "Artifact type not supported"); - break; - default: - break; - - } - } - } - - protected VfModuleArtifact getHeatEnvArtifactFromGeneratedArtifact(VfResourceStructure vfResourceStructure, - VfModuleArtifact vfModuleArtifact) { - String artifactName = vfModuleArtifact.getArtifactInfo().getArtifactName(); - artifactName = artifactName.substring(0, artifactName.indexOf('.')); - for (VfModuleArtifact moduleArtifact : vfResourceStructure.getArtifactsMapByUUID().values()) { - if (moduleArtifact.getArtifactInfo().getArtifactName().contains(artifactName) - && moduleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_ENV)) { - return moduleArtifact; - } - } - return null; - } - - public String verifyTheFilePrefixInArtifacts(String filebody, VfResourceStructure vfResourceStructure, - List<String> listTypes) { - String newFileBody = filebody; - for (VfModuleArtifact moduleArtifact : vfResourceStructure.getArtifactsMapByUUID().values()) { - - if (listTypes.contains(moduleArtifact.getArtifactInfo().getArtifactType())) { - - newFileBody = verifyTheFilePrefixInString(newFileBody, - moduleArtifact.getArtifactInfo().getArtifactName()); - } - } - return newFileBody; - } - - public String verifyTheFilePrefixInString(final String body, final String filenameToVerify) { - - String needlePrefix = "file:///"; - String prefixedFilenameToVerify = needlePrefix + filenameToVerify; - - if ((body == null) || (body.length() == 0) || (filenameToVerify == null) || (filenameToVerify.length() == 0)) { - return body; - } - - StringBuilder sb = new StringBuilder(body.length()); - - int currentIndex = 0; - int startIndex = 0; - - while (currentIndex != -1) { - startIndex = currentIndex; - currentIndex = body.indexOf(prefixedFilenameToVerify, startIndex); - - if (currentIndex == -1) { - break; - } - // We append from the startIndex up to currentIndex (start of File - // Name) - sb.append(body.substring(startIndex, currentIndex)); - sb.append(filenameToVerify); - - currentIndex += prefixedFilenameToVerify.length(); - } - - sb.append(body.substring(startIndex)); - - return sb.toString(); - } - - protected void createHeatTemplateFromArtifact(VfResourceStructure vfResourceStructure, - ToscaResourceStructure toscaResourceStruct, VfModuleArtifact vfModuleArtifact) { - HeatTemplate heatTemplate = new HeatTemplate(); - List<String> typeList = new ArrayList<>(); - typeList.add(ASDCConfiguration.HEAT_NESTED); - typeList.add(ASDCConfiguration.HEAT_ARTIFACT); - - heatTemplate.setTemplateBody( - verifyTheFilePrefixInArtifacts(vfModuleArtifact.getResult(), vfResourceStructure, typeList)); - heatTemplate.setTemplateName(vfModuleArtifact.getArtifactInfo().getArtifactName()); - - if (vfModuleArtifact.getArtifactInfo().getArtifactTimeout() != null) { - heatTemplate.setTimeoutMinutes(vfModuleArtifact.getArtifactInfo().getArtifactTimeout()); - } else { - heatTemplate.setTimeoutMinutes(240); - } - - heatTemplate.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription()); - heatTemplate.setVersion(BigDecimalVersion - .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion())); - heatTemplate.setArtifactUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID()); - - if (vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null) { - heatTemplate.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum()); - } else { - heatTemplate.setArtifactChecksum(MANUAL_RECORD); - } - - Set<HeatTemplateParam> heatParam = extractHeatTemplateParameters( - vfModuleArtifact.getResult(), vfModuleArtifact.getArtifactInfo().getArtifactUUID()); - heatTemplate.setParameters(heatParam); - vfModuleArtifact.setHeatTemplate(heatTemplate); - } - - protected void createHeatEnvFromArtifact(VfResourceStructure vfResourceStructure, - VfModuleArtifact vfModuleArtifact) { - HeatEnvironment heatEnvironment = new HeatEnvironment(); - heatEnvironment.setName(vfModuleArtifact.getArtifactInfo().getArtifactName()); - List<String> typeList = new ArrayList<>(); - typeList.add(ASDCConfiguration.HEAT); - typeList.add(ASDCConfiguration.HEAT_VOL); - heatEnvironment.setEnvironment( - verifyTheFilePrefixInArtifacts(vfModuleArtifact.getResult(), vfResourceStructure, typeList)); - heatEnvironment.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription()); - heatEnvironment.setVersion(BigDecimalVersion - .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion())); - heatEnvironment.setArtifactUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID()); - - if (vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null) { - heatEnvironment.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum()); - } else { - heatEnvironment.setArtifactChecksum(MANUAL_RECORD); - } - vfModuleArtifact.setHeatEnvironment(heatEnvironment); - } - - protected void createHeatFileFromArtifact(VfResourceStructure vfResourceStructure, - VfModuleArtifact vfModuleArtifact, ToscaResourceStructure toscaResourceStruct) { - - HeatFiles heatFile = new HeatFiles(); - heatFile.setAsdcUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID()); - heatFile.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription()); - heatFile.setFileBody(vfModuleArtifact.getResult()); - heatFile.setFileName(vfModuleArtifact.getArtifactInfo().getArtifactName()); - heatFile.setVersion(BigDecimalVersion - .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion())); - toscaResourceStruct.setHeatFilesUUID(vfModuleArtifact.getArtifactInfo().getArtifactUUID()); - if (vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null) { - heatFile.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum()); - } else { - heatFile.setArtifactChecksum(MANUAL_RECORD); - } - vfModuleArtifact.setHeatFiles(heatFile); - } - - protected Service createService(ToscaResourceStructure toscaResourceStructure, - VfResourceStructure vfResourceStructure) { - - Metadata serviceMetadata = toscaResourceStructure.getServiceMetadata(); - - Service service = new Service(); - - if (serviceMetadata != null) { - - if (toscaResourceStructure.getServiceVersion() != null) { - service.setModelVersion(toscaResourceStructure.getServiceVersion()); - } - - service.setServiceType(serviceMetadata.getValue("serviceType")); - service.setServiceRole(serviceMetadata.getValue("serviceRole")); - - service.setDescription(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)); - service.setModelName(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME)); - service.setModelUUID(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID)); - service.setEnvironmentContext(serviceMetadata.getValue("environmentContext")); - - if (vfResourceStructure != null) - service.setWorkloadContext(vfResourceStructure.getNotification().getWorkloadContext()); - - service.setModelInvariantUUID(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)); - service.setCsar(toscaResourceStructure.getCatalogToscaCsar()); - } - - - toscaResourceStructure.setCatalogService(service); - return service; - } - - protected ServiceProxyResourceCustomization createServiceProxy(NodeTemplate nodeTemplate, Service service, ToscaResourceStructure toscaResourceStructure) { - - Metadata spMetadata = nodeTemplate.getMetaData(); - - ServiceProxyResourceCustomization spCustomizationResource = new ServiceProxyResourceCustomization(); - - Set<ServiceProxyResourceCustomization> serviceProxyCustomizationSet = new HashSet<>(); - - spCustomizationResource.setModelName(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME)); - spCustomizationResource.setModelInvariantUUID(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)); - spCustomizationResource.setModelUUID(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID)); - spCustomizationResource.setModelVersion(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)); - spCustomizationResource.setDescription(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)); - - spCustomizationResource.setModelCustomizationUUID(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)); - spCustomizationResource.setModelInstanceName(nodeTemplate.getName()); - spCustomizationResource.setToscaNodeType(nodeTemplate.getType()); - - String sourceServiceUUID = spMetadata.getValue("sourceModelUuid"); - - Service sourceService = serviceRepo.findOneByModelUUID(sourceServiceUUID); - - spCustomizationResource.setSourceService(sourceService); - spCustomizationResource.setToscaNodeType(nodeTemplate.getType()); - serviceProxyCustomizationSet.add(spCustomizationResource); - - - toscaResourceStructure.setCatalogServiceProxyResourceCustomization(spCustomizationResource); - - return spCustomizationResource; - } - - protected ConfigurationResourceCustomization createConfiguration(NodeTemplate nodeTemplate, - ToscaResourceStructure toscaResourceStructure, ServiceProxyResourceCustomization spResourceCustomization, - Optional<ConfigurationResourceCustomization> vnrResourceCustomization) { - - ConfigurationResourceCustomization configCustomizationResource = getConfigurationResourceCustomization(nodeTemplate, - toscaResourceStructure,spResourceCustomization); - - ConfigurationResource configResource = getConfigurationResource(nodeTemplate); - - Set<ConfigurationResourceCustomization> configResourceCustomizationSet = new HashSet<>(); - - StatefulEntityType entityType = nodeTemplate.getTypeDefinition(); - String type = entityType.getType(); - - if(NODES_VRF_ENTRY.equals(type)) { - configCustomizationResource.setConfigResourceCustomization(vnrResourceCustomization.orElse(null)); - } - - configCustomizationResource.setConfigurationResource(configResource); - - configResourceCustomizationSet.add(configCustomizationResource); - - configResource.setConfigurationResourceCustomization(configResourceCustomizationSet); - - toscaResourceStructure.setCatalogConfigurationResource(configResource); - - toscaResourceStructure.setCatalogConfigurationResourceCustomization(configCustomizationResource); - - return configCustomizationResource; - } - - protected ConfigurationResource createFabricConfiguration(NodeTemplate nodeTemplate, ToscaResourceStructure toscaResourceStructure) { - - Metadata fabricMetadata = nodeTemplate.getMetaData(); - - ConfigurationResource configResource = new ConfigurationResource(); - - configResource.setModelName(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME)); - configResource.setModelInvariantUUID(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)); - configResource.setModelUUID(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID)); - configResource.setModelVersion(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)); - configResource.setDescription(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)); - configResource.setToscaNodeType(nodeTemplate.getType()); - - return configResource; - } - - protected void createToscaCsar(ToscaResourceStructure toscaResourceStructure) { - ToscaCsar toscaCsar = new ToscaCsar(); - if (toscaResourceStructure.getToscaArtifact().getArtifactChecksum() != null) { - toscaCsar.setArtifactChecksum(toscaResourceStructure.getToscaArtifact().getArtifactChecksum()); - } else { - toscaCsar.setArtifactChecksum(MANUAL_RECORD); - } - toscaCsar.setArtifactUUID(toscaResourceStructure.getToscaArtifact().getArtifactUUID()); - toscaCsar.setName(toscaResourceStructure.getToscaArtifact().getArtifactName()); - toscaCsar.setVersion(toscaResourceStructure.getToscaArtifact().getArtifactVersion()); - toscaCsar.setDescription(toscaResourceStructure.getToscaArtifact().getArtifactDescription()); - toscaCsar.setUrl(toscaResourceStructure.getToscaArtifact().getArtifactURL()); - - toscaResourceStructure.setCatalogToscaCsar(toscaCsar); - } - - protected VnfcCustomization findExistingVfc(Set<VnfcCustomization> vnfcCustomizations, String customizationUUID) { - VnfcCustomization vnfcCustomization = null; - for(VnfcCustomization vnfcCustom : vnfcCustomizations){ - if (vnfcCustom != null && vnfcCustom.getModelCustomizationUUID().equals(customizationUUID)) { - vnfcCustomization = vnfcCustom; - } - } - - if(vnfcCustomization==null) - vnfcCustomization = vnfcCustomizationRepo.findOneByModelCustomizationUUID(customizationUUID); - - return vnfcCustomization; - } - - protected CvnfcCustomization findExistingCvfc(Set<CvnfcCustomization> cvnfcCustomizations, String customizationUUID) { - CvnfcCustomization cvnfcCustomization = null; - for(CvnfcCustomization cvnfcCustom : cvnfcCustomizations){ - if (cvnfcCustom != null && cvnfcCustom.getModelCustomizationUUID().equals(customizationUUID)) { - cvnfcCustomization = cvnfcCustom; - } - } - - if(cvnfcCustomization==null) - cvnfcCustomization = cvnfcCustomizationRepo.findOneByModelCustomizationUUID(customizationUUID); - - return cvnfcCustomization; - } - - protected NetworkResourceCustomization createNetwork(NodeTemplate networkNodeTemplate, - ToscaResourceStructure toscaResourceStructure, HeatTemplate heatTemplate, String aicMax, String aicMin,Service service) { - - NetworkResourceCustomization networkResourceCustomization=networkCustomizationRepo.findOneByModelCustomizationUUID(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)); - - 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){ - - NetworkResource networkResource = createNetworkResource(networkNodeTemplate, toscaResourceStructure, heatTemplate, - aicMax, aicMin); - - networkResourceCustomization.setNetworkResource(networkResource); - - networkCustomizationRepo.saveAndFlush(networkResourceCustomization); - - } - else if(networkResourceCustomization==null){ - networkResourceCustomization = createNetworkResourceCustomization(networkNodeTemplate, - toscaResourceStructure); - - NetworkResource networkResource = findExistingNetworkResource(service, - networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)); - if(networkResource == null) - networkResource = createNetworkResource(networkNodeTemplate, toscaResourceStructure, heatTemplate, - aicMax, aicMin); - - networkResource.addNetworkResourceCustomization(networkResourceCustomization); - networkResourceCustomization.setNetworkResource(networkResource); - } - - return networkResourceCustomization; - } - - protected NetworkResource findExistingNetworkResource(Service service, String modelUUID) { - NetworkResource networkResource = null; - for(NetworkResourceCustomization networkCustom : service.getNetworkCustomizations()){ - if (networkCustom.getNetworkResource() != null - && networkCustom.getNetworkResource().getModelUUID().equals(modelUUID)) { - networkResource = networkCustom.getNetworkResource(); - } - } - if(networkResource==null) - networkResource = networkRepo.findResourceByModelUUID(modelUUID); - - return networkResource; - } - - protected NetworkResourceCustomization createNetworkResourceCustomization(NodeTemplate networkNodeTemplate, - ToscaResourceStructure toscaResourceStructure) { - NetworkResourceCustomization networkResourceCustomization = new NetworkResourceCustomization(); - networkResourceCustomization.setModelInstanceName( - testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME))); - networkResourceCustomization.setModelCustomizationUUID( - testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID))); - - networkResourceCustomization.setNetworkTechnology( - testNull(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate, - SdcPropertyNames.PROPERTY_NAME_NETWORKTECHNOLOGY))); - networkResourceCustomization.setNetworkType(testNull(toscaResourceStructure.getSdcCsarHelper() - .getNodeTemplatePropertyLeafValue(networkNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKTYPE))); - networkResourceCustomization.setNetworkRole(testNull(toscaResourceStructure.getSdcCsarHelper() - .getNodeTemplatePropertyLeafValue(networkNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKROLE))); - networkResourceCustomization.setNetworkScope(testNull(toscaResourceStructure.getSdcCsarHelper() - .getNodeTemplatePropertyLeafValue(networkNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKSCOPE))); - return networkResourceCustomization; - } - - protected NetworkResource createNetworkResource(NodeTemplate networkNodeTemplate, - ToscaResourceStructure toscaResourceStructure, HeatTemplate heatTemplate, String aicMax, String aicMin) { - NetworkResource networkResource = new NetworkResource(); - String providerNetwork = toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue( - networkNodeTemplate, SdcPropertyNames.PROPERTY_NAME_PROVIDERNETWORK_ISPROVIDERNETWORK); - - if ("true".equalsIgnoreCase(providerNetwork)) { - networkResource.setNeutronNetworkType(PROVIDER); - } else { - networkResource.setNeutronNetworkType(BASIC); - } - - networkResource.setModelName( - testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME))); - - networkResource.setModelInvariantUUID( - testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID))); - networkResource.setModelUUID( - testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID))); - networkResource.setModelVersion( - testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION))); - - networkResource.setAicVersionMax(aicMax); - networkResource.setAicVersionMin(aicMin); - networkResource.setToscaNodeType(networkNodeTemplate.getType()); - networkResource.setDescription( - testNull(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION))); - networkResource.setOrchestrationMode(HEAT); - networkResource.setHeatTemplate(heatTemplate); - return networkResource; - } - - protected CollectionNetworkResourceCustomization createNetworkCollection(NodeTemplate networkNodeTemplate, - ToscaResourceStructure toscaResourceStructure, Service service) { - - CollectionNetworkResourceCustomization collectionNetworkResourceCustomization = new CollectionNetworkResourceCustomization(); - - // **** Build Object to populate Collection_Resource table - CollectionResource collectionResource = new CollectionResource(); - - collectionResource - .setModelName(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)); - collectionResource.setModelInvariantUUID( - networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)); - collectionResource - .setModelUUID(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)); - collectionResource - .setModelVersion(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)); - collectionResource - .setDescription(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)); - collectionResource.setToscaNodeType(networkNodeTemplate.getType()); - - toscaResourceStructure.setCatalogCollectionResource(collectionResource); - - // **** Build object to populate Collection_Resource_Customization table - NetworkCollectionResourceCustomization ncfc = new NetworkCollectionResourceCustomization(); - - ncfc.setFunction(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate, - "cr_function")); - ncfc.setRole(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate, - "cr_role")); - ncfc.setType(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate, - "cr_type")); - - ncfc.setModelInstanceName(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)); - ncfc.setModelCustomizationUUID( - networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)); - - Set<CollectionNetworkResourceCustomization> networkResourceCustomizationSet = new HashSet<>(); - networkResourceCustomizationSet.add(collectionNetworkResourceCustomization); - - ncfc.setNetworkResourceCustomization(networkResourceCustomizationSet); - - ncfc.setCollectionResource(collectionResource); - toscaResourceStructure.setCatalogCollectionResourceCustomization(ncfc); - - //*** Build object to populate the Instance_Group table - List<Group> groupList = toscaResourceStructure.getSdcCsarHelper() - .getGroupsOfOriginOfNodeTemplateByToscaGroupType(networkNodeTemplate, - "org.openecomp.groups.NetworkCollection"); - - List<NetworkInstanceGroup> networkInstanceGroupList = new ArrayList<>(); - - List<CollectionResourceInstanceGroupCustomization> collectionResourceInstanceGroupCustomizationList = new ArrayList<CollectionResourceInstanceGroupCustomization>(); - - for (Group group : groupList) { - - NetworkInstanceGroup networkInstanceGroup = new NetworkInstanceGroup(); - Metadata instanceMetadata = group.getMetadata(); - networkInstanceGroup.setModelName(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME)); - networkInstanceGroup - .setModelInvariantUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)); - networkInstanceGroup.setModelUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID)); - networkInstanceGroup.setModelVersion(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)); - networkInstanceGroup.setToscaNodeType(group.getType()); - networkInstanceGroup.setRole(SubType.SUB_INTERFACE.toString()); // Set - // Role - networkInstanceGroup.setType(InstanceGroupType.L3_NETWORK); // Set - // type - networkInstanceGroup.setCollectionResource(collectionResource); - - // ****Build object to populate - // Collection_Resource_Instance_Group_Customization table - CollectionResourceInstanceGroupCustomization crInstanceGroupCustomization = new CollectionResourceInstanceGroupCustomization(); - crInstanceGroupCustomization.setInstanceGroup(networkInstanceGroup); - crInstanceGroupCustomization.setModelUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID)); - crInstanceGroupCustomization.setModelCustomizationUUID( - networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)); - - // Loop through the template policy to find the subinterface_network_quantity property name. Then extract the value for it. - List<Policy> policyList = toscaResourceStructure.getSdcCsarHelper().getPoliciesOfOriginOfNodeTemplateByToscaPolicyType(networkNodeTemplate, "org.openecomp.policies.scaling.Fixed"); - - if(policyList != null){ - for(Policy policy : policyList){ - for(String policyNetworkCollection : policy.getTargets()){ - - if(policyNetworkCollection.equalsIgnoreCase(group.getName())){ - - Map<String, Object> propMap = policy.getPolicyProperties(); - - if(propMap.get("quantity") != null){ - - String quantity = toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate, getPropertyInput(propMap.get("quantity").toString())); - - if(quantity != null){ - crInstanceGroupCustomization.setSubInterfaceNetworkQuantity(Integer.parseInt(quantity)); - } - - } - - } - } - } - } - - crInstanceGroupCustomization.setDescription( - toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate, - instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME) - + "_network_collection_description")); - crInstanceGroupCustomization.setFunction( - toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate, - instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME) - + "_network_collection_function")); - crInstanceGroupCustomization.setCollectionResourceCust(ncfc); - collectionResourceInstanceGroupCustomizationList.add(crInstanceGroupCustomization); - - networkInstanceGroup - .setCollectionInstanceGroupCustomizations(collectionResourceInstanceGroupCustomizationList); - - networkInstanceGroupList.add(networkInstanceGroup); - - - toscaResourceStructure.setCatalogNetworkInstanceGroup(networkInstanceGroupList); - - List<NodeTemplate> vlNodeList = toscaResourceStructure.getSdcCsarHelper() - .getNodeTemplateBySdcType(networkNodeTemplate, SdcTypes.VL); - - List<CollectionNetworkResourceCustomization> collectionNetworkResourceCustomizationList = new ArrayList<>(); - - //*****Build object to populate the NetworkResource table - NetworkResource networkResource = new NetworkResource(); - - for(NodeTemplate vlNodeTemplate : vlNodeList){ - - String providerNetwork = toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue( - vlNodeTemplate, SdcPropertyNames.PROPERTY_NAME_PROVIDERNETWORK_ISPROVIDERNETWORK); - - if ("true".equalsIgnoreCase(providerNetwork)) { - networkResource.setNeutronNetworkType(PROVIDER); - } else { - networkResource.setNeutronNetworkType(BASIC); - } - - networkResource.setModelName(vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)); - - networkResource.setModelInvariantUUID( - vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)); - networkResource.setModelUUID(vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)); - networkResource - .setModelVersion(vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)); - - networkResource.setAicVersionMax( - vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES)); - - TempNetworkHeatTemplateLookup tempNetworkLookUp = tempNetworkLookupRepo.findFirstBynetworkResourceModelName( - vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)); - - if (tempNetworkLookUp != null ) { - - HeatTemplate heatTemplate = heatRepo - .findByArtifactUuid(tempNetworkLookUp.getHeatTemplateArtifactUuid()); - networkResource.setHeatTemplate(heatTemplate); - - networkResource.setAicVersionMin(tempNetworkLookUp.getAicVersionMin()); - - } - - networkResource.setToscaNodeType(vlNodeTemplate.getType()); - networkResource - .setDescription(vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)); - networkResource.setOrchestrationMode(HEAT); - - // Build object to populate the - // Collection_Network_Resource_Customization table - for (NodeTemplate memberNode : group.getMemberNodes()) { - collectionNetworkResourceCustomization.setModelInstanceName(memberNode.getName()); - } - - collectionNetworkResourceCustomization.setModelCustomizationUUID( - vlNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)); - - collectionNetworkResourceCustomization.setNetworkTechnology( - toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(vlNodeTemplate, - SdcPropertyNames.PROPERTY_NAME_NETWORKTECHNOLOGY)); - collectionNetworkResourceCustomization.setNetworkType(toscaResourceStructure.getSdcCsarHelper() - .getNodeTemplatePropertyLeafValue(vlNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKTYPE)); - collectionNetworkResourceCustomization.setNetworkRole(toscaResourceStructure.getSdcCsarHelper() - .getNodeTemplatePropertyLeafValue(vlNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKROLE)); - collectionNetworkResourceCustomization.setNetworkScope(toscaResourceStructure.getSdcCsarHelper() - .getNodeTemplatePropertyLeafValue(vlNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NETWORKSCOPE)); - collectionNetworkResourceCustomization.setInstanceGroup(networkInstanceGroup); - collectionNetworkResourceCustomization.setNetworkResource(networkResource); - collectionNetworkResourceCustomization.setNetworkResourceCustomization(ncfc); - - collectionNetworkResourceCustomizationList.add(collectionNetworkResourceCustomization); - } - - } - - return collectionNetworkResourceCustomization; - } - - protected VnfcInstanceGroupCustomization createVNFCInstanceGroup(NodeTemplate vnfcNodeTemplate, Group group, - VnfResourceCustomization vnfResourceCustomization, ToscaResourceStructure toscaResourceStructure) { - - Metadata instanceMetadata = group.getMetadata(); - // Populate InstanceGroup - VFCInstanceGroup vfcInstanceGroup = new VFCInstanceGroup(); - - vfcInstanceGroup.setModelName(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME)); - vfcInstanceGroup.setModelInvariantUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)); - vfcInstanceGroup.setModelUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID)); - vfcInstanceGroup.setModelVersion(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)); - vfcInstanceGroup.setToscaNodeType(group.getType()); - vfcInstanceGroup.setRole("SUB-INTERFACE"); // Set Role - vfcInstanceGroup.setType(InstanceGroupType.VNFC); // Set type - - //Populate VNFCInstanceGroupCustomization - VnfcInstanceGroupCustomization vfcInstanceGroupCustom = new VnfcInstanceGroupCustomization(); - - vfcInstanceGroupCustom.setModelCustomizationUUID(vnfResourceCustomization.getModelCustomizationUUID()); - vfcInstanceGroupCustom.setModelUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID)); - vfcInstanceGroupCustom.setDescription(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)); - - String getInputName = null; - String groupProperty = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group, "vfc_instance_group_function"); - if (groupProperty != null) { - int getInputIndex = groupProperty.indexOf("{get_input="); - if (getInputIndex > -1) { - getInputName = groupProperty.substring(getInputIndex+11, groupProperty.length()-1); - } - } - vfcInstanceGroupCustom.setFunction(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(vnfcNodeTemplate, getInputName)); - - vfcInstanceGroupCustom.setInstanceGroup(vfcInstanceGroup); - vfcInstanceGroupCustom.setVnfResourceCust(vnfResourceCustomization); - - return vfcInstanceGroupCustom; - - } - - protected VfModuleCustomization createVFModuleResource(Group group, NodeTemplate vfTemplate, - ToscaResourceStructure toscaResourceStructure, VfResourceStructure vfResourceStructure, - IVfModuleData vfModuleData, VnfResourceCustomization vnfResource, Service service, Set<CvnfcCustomization> existingCvnfcSet, Set<VnfcCustomization> existingVnfcSet) { - - VfModuleCustomization vfModuleCustomization = findExistingVfModuleCustomization(vnfResource, - vfModuleData.getVfModuleModelCustomizationUUID()); - if(vfModuleCustomization == null){ - VfModule vfModule = findExistingVfModule(vnfResource, - vfTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELUUID)); - Metadata vfMetadata = group.getMetadata(); - if(vfModule==null) - vfModule=createVfModule(group, toscaResourceStructure, vfModuleData, vfMetadata); - - vfModuleCustomization = createVfModuleCustomization(group, toscaResourceStructure, vfModule, vfModuleData); - setHeatInformationForVfModule(toscaResourceStructure, vfResourceStructure, vfModule, vfModuleCustomization, - vfMetadata); - vfModuleCustomization.setVfModule(vfModule); - vfModule.getVfModuleCustomization().add(vfModuleCustomization); - vnfResource.getVfModuleCustomizations().add(vfModuleCustomization); - } else { - vfResourceStructure.setAlreadyDeployed(true); - } - - //****************************************************************************************************************** - //* Extract VFC's and CVFC's then add them to VFModule - //****************************************************************************************************************** - - Set<VnfVfmoduleCvnfcConfigurationCustomization> vnfVfmoduleCvnfcConfigurationCustomizations = new HashSet<VnfVfmoduleCvnfcConfigurationCustomization>(); - Set<CvnfcCustomization> cvnfcCustomizations = new HashSet<CvnfcCustomization>(); - Set<VnfcCustomization> vnfcCustomizations = new HashSet<VnfcCustomization>(); - - // Only set the CVNFC if this vfModule group is a member of it. - List<NodeTemplate> groupMembers = toscaResourceStructure.getSdcCsarHelper().getMembersOfVfModule(vfTemplate, group); - String vfModuleMemberName = null; - - for(NodeTemplate node : groupMembers){ - vfModuleMemberName = node.getName(); - } - - // Extract CVFC lists - List<NodeTemplate> cvfcList = toscaResourceStructure.getSdcCsarHelper().getNodeTemplateBySdcType(vfTemplate, SdcTypes.CVFC); - - for(NodeTemplate cvfcTemplate : cvfcList) { - - if(vfModuleMemberName != null && vfModuleMemberName.equalsIgnoreCase(cvfcTemplate.getName())){ - - //Extract associated VFC - Should always be just one - List<NodeTemplate> vfcList = toscaResourceStructure.getSdcCsarHelper().getNodeTemplateBySdcType(cvfcTemplate, SdcTypes.VFC); - - for(NodeTemplate vfcTemplate : vfcList) { - - VnfcCustomization vnfcCustomization = new VnfcCustomization(); - VnfcCustomization existingVnfcCustomization = null; - - existingVnfcCustomization = findExistingVfc(existingVnfcSet, vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)); - - if(existingVnfcCustomization == null){ - vnfcCustomization = new VnfcCustomization(); - } else { - vnfcCustomization = existingVnfcCustomization; - } - - // Only Add Abstract VNFC's to our DB, ignore all others - if(existingVnfcCustomization == null && vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_SUBCATEGORY).equalsIgnoreCase("Abstract")){ - vnfcCustomization.setModelCustomizationUUID(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)); - vnfcCustomization.setModelInstanceName(vfcTemplate.getName()); - vnfcCustomization.setModelInvariantUUID(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)); - vnfcCustomization.setModelName(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)); - vnfcCustomization.setModelUUID(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)); - - vnfcCustomization.setModelVersion( - testNull(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION))); - vnfcCustomization.setDescription( - testNull(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION))); - vnfcCustomization.setToscaNodeType(testNull(vfcTemplate.getType())); - - vnfcCustomizations.add(vnfcCustomization); - existingVnfcSet.add(vnfcCustomization); - } - - // This check is needed incase the VFC subcategory is something other than Abstract. In that case we want to skip adding that record to our DB. - if(vnfcCustomization.getModelCustomizationUUID() != null){ - - CvnfcCustomization cvnfcCustomization = new CvnfcCustomization(); - - cvnfcCustomization = new CvnfcCustomization(); - cvnfcCustomization.setModelCustomizationUUID(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)); - cvnfcCustomization.setModelInstanceName(cvfcTemplate.getName()); - cvnfcCustomization.setModelInvariantUUID(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)); - cvnfcCustomization.setModelName(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)); - cvnfcCustomization.setModelUUID(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)); - - cvnfcCustomization.setModelVersion( - testNull(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION))); - cvnfcCustomization.setDescription( - testNull(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION))); - cvnfcCustomization.setToscaNodeType(testNull(cvfcTemplate.getType())); - - if(existingVnfcCustomization != null){ - cvnfcCustomization.setVnfcCustomization(existingVnfcCustomization); - }else{ - cvnfcCustomization.setVnfcCustomization(vnfcCustomization); - } - - cvnfcCustomization.setNfcFunction(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(cvfcTemplate, "nfc_function")); - cvnfcCustomization.setNfcNamingCode(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(cvfcTemplate, "nfc_naming_code")); - cvnfcCustomization.setVfModuleCustomization(vfModuleCustomization); - cvnfcCustomization.setVnfResourceCustomization(vnfResource); - - cvnfcCustomizations.add(cvnfcCustomization); - existingCvnfcSet.add(cvnfcCustomization); - - //***************************************************************************************************************************************** - //* Extract Fabric Configuration - //***************************************************************************************************************************************** - - List<NodeTemplate> fabricConfigList = toscaResourceStructure.getSdcCsarHelper().getNodeTemplateBySdcType(vfTemplate, SdcTypes.CONFIGURATION); - - for(NodeTemplate fabricTemplate : fabricConfigList) { - - ConfigurationResource fabricConfig = null; - - ConfigurationResource existingConfig = findExistingConfiguration(service, fabricTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)); - - if(existingConfig == null){ - - fabricConfig = createFabricConfiguration(fabricTemplate, toscaResourceStructure); - - }else { - fabricConfig = existingConfig; - } - - VnfVfmoduleCvnfcConfigurationCustomization vnfVfmoduleCvnfcConfigurationCustomization = createVfCnvfConfigCustomization(fabricTemplate, toscaResourceStructure, - vnfResource, vfModuleCustomization, cvnfcCustomization, fabricConfig, vfTemplate, vfModuleMemberName); - vnfVfmoduleCvnfcConfigurationCustomizations.add(vnfVfmoduleCvnfcConfigurationCustomization); - } - cvnfcCustomization.setVnfVfmoduleCvnfcConfigurationCustomization(vnfVfmoduleCvnfcConfigurationCustomizations); - } - - } - - } - } - vfModuleCustomization.setCvnfcCustomization(cvnfcCustomizations); - vfModuleCustomization.setVnfVfmoduleCvnfcConfigurationCustomization(vnfVfmoduleCvnfcConfigurationCustomizations); - - return vfModuleCustomization; - } - - protected VnfVfmoduleCvnfcConfigurationCustomization createVfCnvfConfigCustomization(NodeTemplate fabricTemplate, ToscaResourceStructure toscaResourceStruct, - VnfResourceCustomization vnfResource, VfModuleCustomization vfModuleCustomization, CvnfcCustomization cvnfcCustomization, - ConfigurationResource configResource, NodeTemplate vfTemplate, String vfModuleMemberName) { - - Metadata fabricMetadata = fabricTemplate.getMetaData(); - - VnfVfmoduleCvnfcConfigurationCustomization vfModuleToCvnfc = new VnfVfmoduleCvnfcConfigurationCustomization(); - - vfModuleToCvnfc.setConfigurationResource(configResource); - vfModuleToCvnfc.setCvnfcCustomization(cvnfcCustomization); - vfModuleToCvnfc.setModelCustomizationUUID(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)); - vfModuleToCvnfc.setModelInstanceName(fabricTemplate.getName()); - vfModuleToCvnfc.setVfModuleCustomization(vfModuleCustomization); - vfModuleToCvnfc.setVnfResourceCustomization(vnfResource); - - List<Policy> policyList = toscaResourceStruct.getSdcCsarHelper().getPoliciesOfOriginOfNodeTemplateByToscaPolicyType(vfTemplate, "org.openecomp.policies.External"); - - if(policyList != null){ - for(Policy policy : policyList){ - - for(String policyCvfcTarget : policy.getTargets()){ - - if(policyCvfcTarget.equalsIgnoreCase(vfModuleMemberName)){ - - Map<String, Object> propMap = policy.getPolicyProperties(); - - if(propMap.get("type").toString().equalsIgnoreCase("Fabric Policy")){ - vfModuleToCvnfc.setPolicyName(propMap.get("name").toString()); - } - } - } - } - } - - vfModuleToCvnfc.setConfigurationFunction(toscaResourceStruct.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(fabricTemplate, "function")); - vfModuleToCvnfc.setConfigurationRole(toscaResourceStruct.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(fabricTemplate, "role")); - vfModuleToCvnfc.setConfigurationType(toscaResourceStruct.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(fabricTemplate, "type")); - - return vfModuleToCvnfc; - } - - protected ConfigurationResource findExistingConfiguration(Service service, String modelUUID) { - ConfigurationResource configResource = null; - for(ConfigurationResourceCustomization configurationResourceCustom : service.getConfigurationCustomizations()){ - if (configurationResourceCustom.getConfigurationResource() != null - && configurationResourceCustom.getConfigurationResource().getModelUUID().equals(modelUUID)) { - configResource = configurationResourceCustom.getConfigurationResource(); - } - } - if(configResource==null) - configResource = configRepo.findResourceByModelUUID(modelUUID); - - return configResource; - } - - protected VfModuleCustomization findExistingVfModuleCustomization(VnfResourceCustomization vnfResource, - String vfModuleModelCustomizationUUID) { - VfModuleCustomization vfModuleCustomization = null; - for(VfModuleCustomization vfModuleCustom : vnfResource.getVfModuleCustomizations()){ - if(vfModuleCustom.getModelCustomizationUUID().equalsIgnoreCase(vfModuleModelCustomizationUUID)){ - vfModuleCustomization = vfModuleCustom; - } - } - if(vfModuleCustomization==null) - vfModuleCustomization = vfModuleCustomizationRepo - .findByModelCustomizationUUID(vfModuleModelCustomizationUUID); - - return vfModuleCustomization; - } - - protected VfModule findExistingVfModule(VnfResourceCustomization vnfResource, String modelUUID) { - VfModule vfModule = null; - for(VfModuleCustomization vfModuleCustom : vnfResource.getVfModuleCustomizations()){ - if(vfModuleCustom.getVfModule() != null && vfModuleCustom.getVfModule().getModelUUID().equals(modelUUID)){ - vfModule = vfModuleCustom.getVfModule(); - } - } - if(vfModule==null) - vfModule = vfModuleRepo.findByModelUUID(modelUUID); - - return vfModule; - } - - protected VfModuleCustomization createVfModuleCustomization(Group group, - ToscaResourceStructure toscaResourceStructure, VfModule vfModule, IVfModuleData vfModuleData) { - VfModuleCustomization vfModuleCustomization = new VfModuleCustomization(); - - vfModuleCustomization.setModelCustomizationUUID(vfModuleData.getVfModuleModelCustomizationUUID()); - - vfModuleCustomization.setVfModule(vfModule); - - String initialCount = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group, - SdcPropertyNames.PROPERTY_NAME_INITIALCOUNT); - if (initialCount != null && initialCount.length() > 0) { - vfModuleCustomization.setInitialCount(Integer.valueOf(initialCount)); - } - - vfModuleCustomization.setInitialCount(Integer.valueOf(toscaResourceStructure.getSdcCsarHelper() - .getGroupPropertyLeafValue(group, SdcPropertyNames.PROPERTY_NAME_INITIALCOUNT))); - - String availabilityZoneCount = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group, - SdcPropertyNames.PROPERTY_NAME_AVAILABILITYZONECOUNT); - if (availabilityZoneCount != null && availabilityZoneCount.length() > 0) { - vfModuleCustomization.setAvailabilityZoneCount(Integer.valueOf(availabilityZoneCount)); - } - - vfModuleCustomization.setLabel(toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group, - SdcPropertyNames.PROPERTY_NAME_VFMODULELABEL)); - - String maxInstances = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group, - SdcPropertyNames.PROPERTY_NAME_MAXVFMODULEINSTANCES); - if (maxInstances != null && maxInstances.length() > 0) { - vfModuleCustomization.setMaxInstances(Integer.valueOf(maxInstances)); - } - - String minInstances = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group, - SdcPropertyNames.PROPERTY_NAME_MINVFMODULEINSTANCES); - if (minInstances != null && minInstances.length() > 0) { - vfModuleCustomization.setMinInstances(Integer.valueOf(minInstances)); - } - return vfModuleCustomization; - } - - protected VfModule createVfModule(Group group, ToscaResourceStructure toscaResourceStructure, - IVfModuleData vfModuleData, Metadata vfMetadata) { - VfModule vfModule = new VfModule(); - String vfModuleModelUUID = vfModuleData.getVfModuleModelUUID(); - - if(vfModuleModelUUID == null) { - vfModuleModelUUID = testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata, - SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELUUID)); - } else if (vfModuleModelUUID.indexOf('.') > -1) { - vfModuleModelUUID = vfModuleModelUUID.substring(0, vfModuleModelUUID.indexOf('.')); - } - - vfModule.setModelInvariantUUID(testNull(toscaResourceStructure.getSdcCsarHelper() - .getMetadataPropertyValue(vfMetadata, SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELINVARIANTUUID))); - vfModule.setModelName(testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata, - SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELNAME))); - vfModule.setModelUUID(vfModuleModelUUID); - vfModule.setModelVersion(testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata, - SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELVERSION))); - vfModule.setDescription(testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata, - SdcPropertyNames.PROPERTY_NAME_DESCRIPTION))); - - String vfModuleType = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group, - SdcPropertyNames.PROPERTY_NAME_VFMODULETYPE); - if (vfModuleType != null && "Base".equalsIgnoreCase(vfModuleType)) { - vfModule.setIsBase(true); - } else { - vfModule.setIsBase(false); - } - return vfModule; - } - - protected void setHeatInformationForVfModule(ToscaResourceStructure toscaResourceStructure, - VfResourceStructure vfResourceStructure, VfModule vfModule, VfModuleCustomization vfModuleCustomization, - Metadata vfMetadata) { - - Optional<VfModuleStructure> matchingObject = vfResourceStructure.getVfModuleStructure().stream() - .filter(vfModuleStruct -> vfModuleStruct.getVfModuleMetadata().getVfModuleModelUUID() - .equalsIgnoreCase(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata, - SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELUUID))) - .findFirst(); - - if (matchingObject.isPresent()) { - List<HeatFiles> heatFilesList = new ArrayList<>(); - List<HeatTemplate> volumeHeatChildTemplates = new ArrayList<HeatTemplate>(); - List<HeatTemplate> heatChildTemplates = new ArrayList<HeatTemplate>(); - HeatTemplate parentHeatTemplate = new HeatTemplate(); - String parentArtifactType = null; - Set<String> artifacts = new HashSet<>(matchingObject.get().getVfModuleMetadata().getArtifacts()); - for (VfModuleArtifact vfModuleArtifact : vfResourceStructure.getArtifactsMapByUUID().values()) { - - List<HeatTemplate> childNestedHeatTemplates = new ArrayList<HeatTemplate>(); - - if (artifacts.contains(vfModuleArtifact.getArtifactInfo().getArtifactUUID())) { - checkVfModuleArtifactType(vfModule, vfModuleCustomization, heatFilesList, vfModuleArtifact, - childNestedHeatTemplates, parentHeatTemplate, vfResourceStructure); - } - - if(vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_NESTED)){ - parentArtifactType = identifyParentOfNestedTemplate(matchingObject.get(), vfModuleArtifact); - - if(!childNestedHeatTemplates.isEmpty()){ - - if (parentArtifactType != null && parentArtifactType.equalsIgnoreCase(ASDCConfiguration.HEAT_VOL)) { - volumeHeatChildTemplates.add(childNestedHeatTemplates.get(0)); - } else { - heatChildTemplates.add(childNestedHeatTemplates.get(0)); - } - } - } - - } - if(!heatFilesList.isEmpty()){ - vfModule.setHeatFiles(heatFilesList); - } - - - // Set all Child Templates related to HEAT_VOLUME - if(!volumeHeatChildTemplates.isEmpty()){ - if(vfModule.getVolumeHeatTemplate() != null){ - vfModule.getVolumeHeatTemplate().setChildTemplates(volumeHeatChildTemplates); - }else{ - logger.debug("VolumeHeatTemplate not set in setHeatInformationForVfModule()"); - } - } - - // Set all Child Templates related to HEAT - if(!heatChildTemplates.isEmpty()){ - if(vfModule.getModuleHeatTemplate() != null){ - vfModule.getModuleHeatTemplate().setChildTemplates(heatChildTemplates); - }else{ - logger.debug("ModuleHeatTemplate not set in setHeatInformationForVfModule()"); - } - } - } - } - - protected void checkVfModuleArtifactType(VfModule vfModule, VfModuleCustomization vfModuleCustomization, - List<HeatFiles> heatFilesList, VfModuleArtifact vfModuleArtifact, List<HeatTemplate> nestedHeatTemplates, - HeatTemplate parentHeatTemplate, VfResourceStructure vfResourceStructure) { - if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT)) { - vfModuleArtifact.incrementDeployedInDB(); - vfModule.setModuleHeatTemplate(vfModuleArtifact.getHeatTemplate()); - } else if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_VOL)) { - vfModule.setVolumeHeatTemplate(vfModuleArtifact.getHeatTemplate()); - VfModuleArtifact volVfModuleArtifact = this.getHeatEnvArtifactFromGeneratedArtifact(vfResourceStructure, vfModuleArtifact); - vfModuleCustomization.setVolumeHeatEnv(volVfModuleArtifact.getHeatEnvironment()); - vfModuleArtifact.incrementDeployedInDB(); - } else if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_ENV)) { - if(vfModuleArtifact.getHeatEnvironment().getName().contains("volume")) { - vfModuleCustomization.setVolumeHeatEnv(vfModuleArtifact.getHeatEnvironment()); - } else { - vfModuleCustomization.setHeatEnvironment(vfModuleArtifact.getHeatEnvironment()); - } - vfModuleArtifact.incrementDeployedInDB(); - } else if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_ARTIFACT)) { - heatFilesList.add(vfModuleArtifact.getHeatFiles()); - vfModuleArtifact.incrementDeployedInDB(); - } else if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_NESTED)) { - nestedHeatTemplates.add(vfModuleArtifact.getHeatTemplate()); - vfModuleArtifact.incrementDeployedInDB(); - } - } - - protected VnfResourceCustomization createVnfResource(NodeTemplate vfNodeTemplate, - ToscaResourceStructure toscaResourceStructure, Service service) { - VnfResourceCustomization vnfResourceCustomization = vnfCustomizationRepo.findOneByModelCustomizationUUID( - vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)); - if(vnfResourceCustomization == null){ - VnfResource vnfResource = findExistingVnfResource(service, - vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)); - - if(vnfResource==null) - vnfResource=createVnfResource(vfNodeTemplate); - - vnfResourceCustomization = createVnfResourceCustomization(vfNodeTemplate, toscaResourceStructure, - vnfResource); - vnfResourceCustomization.setVnfResources(vnfResource); - vnfResource.getVnfResourceCustomizations().add(vnfResourceCustomization); - - // Fetch VNFC Instance Group Info - List<Group> groupList = toscaResourceStructure.getSdcCsarHelper() - .getGroupsOfOriginOfNodeTemplateByToscaGroupType(vfNodeTemplate, - "org.openecomp.groups.VfcInstanceGroup"); - - for (Group group : groupList) { - - VnfcInstanceGroupCustomization vnfcInstanceGroupCustomization = createVNFCInstanceGroup(vfNodeTemplate, group, vnfResourceCustomization, toscaResourceStructure); - - vnfcInstanceGroupCustomizationRepo.saveAndFlush(vnfcInstanceGroupCustomization); - } - } - return vnfResourceCustomization; - } - - protected VnfResource findExistingVnfResource(Service service, String modelUUID) { - VnfResource vnfResource = null; - for(VnfResourceCustomization vnfResourceCustom : service.getVnfCustomizations()){ - if (vnfResourceCustom.getVnfResources() != null - && vnfResourceCustom.getVnfResources().getModelUUID().equals(modelUUID)) { - vnfResource = vnfResourceCustom.getVnfResources(); - } - } - if(vnfResource==null) - vnfResource = vnfRepo.findResourceByModelUUID(modelUUID); - - return vnfResource; - } - - protected VnfResourceCustomization createVnfResourceCustomization(NodeTemplate vfNodeTemplate, - ToscaResourceStructure toscaResourceStructure, VnfResource vnfResource) { - VnfResourceCustomization vnfResourceCustomization = new VnfResourceCustomization(); - vnfResourceCustomization.setModelCustomizationUUID( - testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID))); - vnfResourceCustomization.setModelInstanceName(vfNodeTemplate.getName()); - - vnfResourceCustomization.setNfFunction(testNull(toscaResourceStructure.getSdcCsarHelper() - .getNodeTemplatePropertyLeafValue(vfNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFFUNCTION))); - vnfResourceCustomization.setNfNamingCode(testNull(toscaResourceStructure.getSdcCsarHelper() - .getNodeTemplatePropertyLeafValue(vfNodeTemplate, "nf_naming_code"))); - vnfResourceCustomization.setNfRole(testNull(toscaResourceStructure.getSdcCsarHelper() - .getNodeTemplatePropertyLeafValue(vfNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFROLE))); - vnfResourceCustomization.setNfType(testNull(toscaResourceStructure.getSdcCsarHelper() - .getNodeTemplatePropertyLeafValue(vfNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFTYPE))); - - vnfResourceCustomization.setMultiStageDesign(toscaResourceStructure.getSdcCsarHelper() - .getNodeTemplatePropertyLeafValue(vfNodeTemplate, MULTI_STAGE_DESIGN)); - - vnfResourceCustomization.setVnfResources(vnfResource); - vnfResourceCustomization.setAvailabilityZoneMaxCount(Integer.getInteger( - vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_AVAILABILITYZONECOUNT))); - - CapabilityAssignments vnfCustomizationCapability = toscaResourceStructure.getSdcCsarHelper() - .getCapabilitiesOf(vfNodeTemplate); - - if (vnfCustomizationCapability != null) { - CapabilityAssignment capAssign = vnfCustomizationCapability.getCapabilityByName(SCALABLE); - - if (capAssign != null) { - vnfResourceCustomization.setMinInstances(Integer.getInteger(toscaResourceStructure.getSdcCsarHelper() - .getCapabilityPropertyLeafValue(capAssign, SdcPropertyNames.PROPERTY_NAME_MININSTANCES))); - vnfResourceCustomization.setMaxInstances(Integer.getInteger(toscaResourceStructure.getSdcCsarHelper() - .getCapabilityPropertyLeafValue(capAssign, SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES))); - } - - } - - toscaResourceStructure.setCatalogVnfResourceCustomization(vnfResourceCustomization); - - return vnfResourceCustomization; - } - - protected VnfResource createVnfResource(NodeTemplate vfNodeTemplate) { - VnfResource vnfResource = new VnfResource(); - vnfResource.setModelInvariantUUID( - testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID))); - vnfResource.setModelName(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME))); - vnfResource.setModelUUID(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID))); - - vnfResource.setModelVersion( - testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION))); - vnfResource.setDescription( - testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION))); - vnfResource.setOrchestrationMode(HEAT); - vnfResource.setToscaNodeType(testNull(vfNodeTemplate.getType())); - vnfResource.setAicVersionMax( - testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES))); - vnfResource.setAicVersionMin( - testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_MININSTANCES))); - vnfResource.setCategory(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CATEGORY)); - vnfResource.setSubCategory(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_SUBCATEGORY)); - - return vnfResource; - } - - protected AllottedResourceCustomization createAllottedResource(NodeTemplate nodeTemplate, - ToscaResourceStructure toscaResourceStructure, Service service) { - AllottedResourceCustomization allottedResourceCustomization = allottedCustomizationRepo - .findOneByModelCustomizationUUID( - nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)); - - if(allottedResourceCustomization == null){ - AllottedResource allottedResource = findExistingAllottedResource(service, - nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)); - - if(allottedResource==null) - allottedResource=createAR(nodeTemplate); - - toscaResourceStructure.setAllottedResource(allottedResource); - allottedResourceCustomization = createAllottedResourceCustomization(nodeTemplate, toscaResourceStructure); - allottedResourceCustomization.setAllottedResource(allottedResource); - allottedResource.getAllotedResourceCustomization().add(allottedResourceCustomization); - } - return allottedResourceCustomization; - } - - protected AllottedResource findExistingAllottedResource(Service service, String modelUUID) { - AllottedResource allottedResource = null; - for(AllottedResourceCustomization allottedResourceCustom : service.getAllottedCustomizations()){ - if (allottedResourceCustom.getAllottedResource() != null - && allottedResourceCustom.getAllottedResource().getModelUUID().equals(modelUUID)) { - allottedResource = allottedResourceCustom.getAllottedResource(); - } - } - if(allottedResource==null) - allottedResource = allottedRepo.findResourceByModelUUID(modelUUID); - - return allottedResource; - } - - protected AllottedResourceCustomization createAllottedResourceCustomization(NodeTemplate nodeTemplate, - ToscaResourceStructure toscaResourceStructure) { - AllottedResourceCustomization allottedResourceCustomization = new AllottedResourceCustomization(); - allottedResourceCustomization.setModelCustomizationUUID( - testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID))); - allottedResourceCustomization.setModelInstanceName(nodeTemplate.getName()); - - - allottedResourceCustomization.setNfFunction(testNull(toscaResourceStructure.getSdcCsarHelper() - .getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFFUNCTION))); - allottedResourceCustomization.setNfNamingCode(testNull(toscaResourceStructure.getSdcCsarHelper() - .getNodeTemplatePropertyLeafValue(nodeTemplate, "nf_naming_code"))); - allottedResourceCustomization.setNfRole(testNull(toscaResourceStructure.getSdcCsarHelper() - .getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFROLE))); - allottedResourceCustomization.setNfType(testNull(toscaResourceStructure.getSdcCsarHelper() - .getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFTYPE))); - - List<NodeTemplate> vfcNodes = toscaResourceStructure.getSdcCsarHelper().getVfcListByVf(allottedResourceCustomization.getModelCustomizationUUID()); - - if(vfcNodes != null){ - for(NodeTemplate vfcNode : vfcNodes){ - - allottedResourceCustomization.setProvidingServiceModelUUID(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(vfcNode, "providing_service_uuid")); - allottedResourceCustomization.setProvidingServiceModelInvariantUUID(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(vfcNode, "providing_service_invariant_uuid")); - allottedResourceCustomization.setProvidingServiceModelName(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(vfcNode, "providing_service_name")); - } - } - - - CapabilityAssignments arCustomizationCapability = toscaResourceStructure.getSdcCsarHelper() - .getCapabilitiesOf(nodeTemplate); - - if (arCustomizationCapability != null) { - CapabilityAssignment capAssign = arCustomizationCapability.getCapabilityByName(SCALABLE); - - if (capAssign != null) { - allottedResourceCustomization.setMinInstances( - Integer.getInteger(toscaResourceStructure.getSdcCsarHelper().getCapabilityPropertyLeafValue( - capAssign, SdcPropertyNames.PROPERTY_NAME_MININSTANCES))); - allottedResourceCustomization.setMaxInstances( - Integer.getInteger(toscaResourceStructure.getSdcCsarHelper().getCapabilityPropertyLeafValue( - capAssign, SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES))); - } - } - return allottedResourceCustomization; - } - - protected AllottedResource createAR(NodeTemplate nodeTemplate) { - AllottedResource allottedResource = new AllottedResource(); - allottedResource - .setModelUUID(testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID))); - allottedResource.setModelInvariantUUID( - testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID))); - allottedResource - .setModelName(testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME))); - allottedResource - .setModelVersion(testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION))); - allottedResource.setToscaNodeType(testNull(nodeTemplate.getType())); - allottedResource.setSubcategory( - testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_SUBCATEGORY))); - allottedResource - .setDescription(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)); - return allottedResource; - } - - protected Set<HeatTemplateParam> extractHeatTemplateParameters(String yamlFile, String artifactUUID) { - // Scan the payload downloadResult and extract the HeatTemplate - // parameters - YamlEditor yamlEditor = new YamlEditor(yamlFile.getBytes()); - return yamlEditor.getParameterList(artifactUUID); - } - - protected String testNull(Object object) { - - if (object == null) { - return null; - } else if (object.equals("NULL")) { - return null; - } else if (object instanceof Integer) { - return object.toString(); - } else if (object instanceof String) { - return (String) object; - } else { - return "Type not recognized"; - } - } - - protected static String identifyParentOfNestedTemplate(VfModuleStructure vfModuleStructure, - VfModuleArtifact heatNestedArtifact) { - - if (vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT) != null && vfModuleStructure - .getArtifactsMap().get(ASDCConfiguration.HEAT).get(0).getArtifactInfo().getRelatedArtifacts() != null) { - for (IArtifactInfo unknownArtifact : vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT).get(0) - .getArtifactInfo().getRelatedArtifacts()) { - if (heatNestedArtifact.getArtifactInfo().getArtifactUUID().equals(unknownArtifact.getArtifactUUID())) { - return ASDCConfiguration.HEAT; - } - - } - } - - if (vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT_VOL) != null - && vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT_VOL).get(0).getArtifactInfo() - .getRelatedArtifacts() != null) { - for (IArtifactInfo unknownArtifact : vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT_VOL) - .get(0).getArtifactInfo().getRelatedArtifacts()) { - if (heatNestedArtifact.getArtifactInfo().getArtifactUUID().equals(unknownArtifact.getArtifactUUID())) { - return ASDCConfiguration.HEAT_VOL; - } - - } - } - - // Does not belong to anything - return null; - - } - - protected static String createVNFName(VfResourceStructure vfResourceStructure) { - - return vfResourceStructure.getNotification().getServiceName() + "/" - + vfResourceStructure.getResourceInstance().getResourceInstanceName(); - } - - protected static String createVfModuleName(VfModuleStructure vfModuleStructure) { - - return createVNFName(vfModuleStructure.getParentVfResource()) + "::" - + vfModuleStructure.getVfModuleMetadata().getVfModuleModelName(); - } - - protected String getPropertyInput(String propertyName){ - - String inputName = new String(); - - if (propertyName != null) { - int getInputIndex = propertyName.indexOf("{get_input="); - if (getInputIndex > -1) { - inputName = propertyName.substring(getInputIndex+11, propertyName.length()-1); - } - } - - return inputName; - } - - - protected static Timestamp getCurrentTimeStamp() { - - return new Timestamp(new Date().getTime()); - } + vnfcCustomization = existingVnfcCustomization; + } + + // Only Add Abstract VNFC's to our DB, ignore all others + if (existingVnfcCustomization == null && vfcTemplate.getMetaData() + .getValue(SdcPropertyNames.PROPERTY_NAME_SUBCATEGORY).equalsIgnoreCase("Abstract")) { + vnfcCustomization.setModelCustomizationUUID( + vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)); + vnfcCustomization.setModelInstanceName(vfcTemplate.getName()); + vnfcCustomization.setModelInvariantUUID( + vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)); + vnfcCustomization + .setModelName(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)); + vnfcCustomization + .setModelUUID(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)); + + vnfcCustomization.setModelVersion( + testNull(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION))); + vnfcCustomization.setDescription( + testNull(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION))); + vnfcCustomization.setToscaNodeType(testNull(vfcTemplate.getType())); + + vnfcCustomizations.add(vnfcCustomization); + existingVnfcSet.add(vnfcCustomization); + } + + // This check is needed incase the VFC subcategory is something other than Abstract. In that case we want to skip adding that record to our DB. + if (vnfcCustomization.getModelCustomizationUUID() != null) { + + CvnfcCustomization cvnfcCustomization = null; + + if (existingCvnfcCustomization != null) { + cvnfcCustomization = existingCvnfcCustomization; + } else { + + cvnfcCustomization = new CvnfcCustomization(); + cvnfcCustomization.setModelCustomizationUUID( + cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)); + cvnfcCustomization.setModelInstanceName(cvfcTemplate.getName()); + cvnfcCustomization.setModelInvariantUUID( + cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)); + cvnfcCustomization + .setModelName(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)); + cvnfcCustomization + .setModelUUID(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)); + + cvnfcCustomization.setModelVersion( + testNull(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION))); + cvnfcCustomization.setDescription( + testNull( + cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION))); + cvnfcCustomization.setToscaNodeType(testNull(cvfcTemplate.getType())); + + if (existingVnfcCustomization != null) { + cvnfcCustomization.setVnfcCustomization(existingVnfcCustomization); + } else { + cvnfcCustomization.setVnfcCustomization(vnfcCustomization); + } + + cvnfcCustomization.setNfcFunction(toscaResourceStructure.getSdcCsarHelper() + .getNodeTemplatePropertyLeafValue(cvfcTemplate, "nfc_function")); + cvnfcCustomization.setNfcNamingCode(toscaResourceStructure.getSdcCsarHelper() + .getNodeTemplatePropertyLeafValue(cvfcTemplate, "nfc_naming_code")); + cvnfcCustomization.setVfModuleCustomization(vfModuleCustomization); + cvnfcCustomization.setVnfResourceCustomization(vnfResource); + + cvnfcCustomizations.add(cvnfcCustomization); + existingCvnfcSet.add(cvnfcCustomization); + } + + //***************************************************************************************************************************************** + //* Extract Fabric Configuration + //***************************************************************************************************************************************** + + List<NodeTemplate> fabricConfigList = toscaResourceStructure.getSdcCsarHelper() + .getNodeTemplateBySdcType(vfTemplate, SdcTypes.CONFIGURATION); + + for (NodeTemplate fabricTemplate : fabricConfigList) { + + ConfigurationResource fabricConfig = null; + + ConfigurationResource existingConfig = findExistingConfiguration(service, + fabricTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)); + + if (existingConfig == null) { + + fabricConfig = createFabricConfiguration(fabricTemplate, toscaResourceStructure); + + } else { + fabricConfig = existingConfig; + } + + VnfVfmoduleCvnfcConfigurationCustomization vnfVfmoduleCvnfcConfigurationCustomization = createVfCnvfConfigCustomization( + fabricTemplate, toscaResourceStructure, + vnfResource, vfModuleCustomization, cvnfcCustomization, fabricConfig, vfTemplate, + vfModuleMemberName); + + vnfVfmoduleCvnfcConfigurationCustomizations.add(vnfVfmoduleCvnfcConfigurationCustomization); + } + + } + + } + + } + + } + + vfModuleCustomization.setCvnfcCustomization(cvnfcCustomizations); + vfModuleCustomization + .setVnfVfmoduleCvnfcConfigurationCustomization(vnfVfmoduleCvnfcConfigurationCustomizations); + + return vfModuleCustomization; + } + + protected VnfVfmoduleCvnfcConfigurationCustomization createVfCnvfConfigCustomization(NodeTemplate fabricTemplate, + ToscaResourceStructure toscaResourceStruct, + VnfResourceCustomization vnfResource, VfModuleCustomization vfModuleCustomization, + CvnfcCustomization cvnfcCustomization, + ConfigurationResource configResource, NodeTemplate vfTemplate, String vfModuleMemberName) { + + Metadata fabricMetadata = fabricTemplate.getMetaData(); + + VnfVfmoduleCvnfcConfigurationCustomization vfModuleToCvnfc = new VnfVfmoduleCvnfcConfigurationCustomization(); + + vfModuleToCvnfc.setConfigurationResource(configResource); + vfModuleToCvnfc.setCvnfcCustomization(cvnfcCustomization); + vfModuleToCvnfc + .setModelCustomizationUUID(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)); + vfModuleToCvnfc.setModelInstanceName(fabricTemplate.getName()); + vfModuleToCvnfc.setVfModuleCustomization(vfModuleCustomization); + vfModuleToCvnfc.setVnfResourceCustomization(vnfResource); + + List<Policy> policyList = toscaResourceStruct.getSdcCsarHelper() + .getPoliciesOfOriginOfNodeTemplateByToscaPolicyType(vfTemplate, "org.openecomp.policies.External"); + + if (policyList != null) { + for (Policy policy : policyList) { + + for (String policyCvfcTarget : policy.getTargets()) { + + if (policyCvfcTarget.equalsIgnoreCase(vfModuleMemberName)) { + + Map<String, Object> propMap = policy.getPolicyProperties(); + + if (propMap.get("type").toString().equalsIgnoreCase("Fabric Policy")) { + vfModuleToCvnfc.setPolicyName(propMap.get("name").toString()); + } + } + } + } + } + + vfModuleToCvnfc.setConfigurationFunction( + toscaResourceStruct.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(fabricTemplate, "function")); + vfModuleToCvnfc.setConfigurationRole( + toscaResourceStruct.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(fabricTemplate, "role")); + vfModuleToCvnfc.setConfigurationType( + toscaResourceStruct.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(fabricTemplate, "type")); + + return vfModuleToCvnfc; + } + + protected ConfigurationResource findExistingConfiguration(Service service, String modelUUID) { + ConfigurationResource configResource = null; + for (ConfigurationResourceCustomization configurationResourceCustom : service + .getConfigurationCustomizations()) { + if (configurationResourceCustom.getConfigurationResource() != null + && configurationResourceCustom.getConfigurationResource().getModelUUID().equals(modelUUID)) { + configResource = configurationResourceCustom.getConfigurationResource(); + } + } + if (configResource == null) { + configResource = configRepo.findResourceByModelUUID(modelUUID); + } + + return configResource; + } + + protected VfModuleCustomization findExistingVfModuleCustomization(VnfResourceCustomization vnfResource, + String vfModuleModelCustomizationUUID) { + VfModuleCustomization vfModuleCustomization = null; + for (VfModuleCustomization vfModuleCustom : vnfResource.getVfModuleCustomizations()) { + if (vfModuleCustom.getModelCustomizationUUID().equalsIgnoreCase(vfModuleModelCustomizationUUID)) { + vfModuleCustomization = vfModuleCustom; + } + } + if (vfModuleCustomization == null) { + vfModuleCustomization = vfModuleCustomizationRepo + .findByModelCustomizationUUID(vfModuleModelCustomizationUUID); + } + + return vfModuleCustomization; + } + + protected VfModule findExistingVfModule(VnfResourceCustomization vnfResource, String modelUUID) { + VfModule vfModule = null; + for (VfModuleCustomization vfModuleCustom : vnfResource.getVfModuleCustomizations()) { + if (vfModuleCustom.getVfModule() != null && vfModuleCustom.getVfModule().getModelUUID().equals(modelUUID)) { + vfModule = vfModuleCustom.getVfModule(); + } + } + if (vfModule == null) { + vfModule = vfModuleRepo.findByModelUUID(modelUUID); + } + + return vfModule; + } + + protected VfModuleCustomization createVfModuleCustomization(Group group, + ToscaResourceStructure toscaResourceStructure, VfModule vfModule, IVfModuleData vfModuleData) { + VfModuleCustomization vfModuleCustomization = new VfModuleCustomization(); + + vfModuleCustomization.setModelCustomizationUUID(vfModuleData.getVfModuleModelCustomizationUUID()); + + vfModuleCustomization.setVfModule(vfModule); + + String initialCount = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group, + SdcPropertyNames.PROPERTY_NAME_INITIALCOUNT); + if (initialCount != null && initialCount.length() > 0) { + vfModuleCustomization.setInitialCount(Integer.valueOf(initialCount)); + } + + vfModuleCustomization.setInitialCount(Integer.valueOf(toscaResourceStructure.getSdcCsarHelper() + .getGroupPropertyLeafValue(group, SdcPropertyNames.PROPERTY_NAME_INITIALCOUNT))); + + String availabilityZoneCount = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group, + SdcPropertyNames.PROPERTY_NAME_AVAILABILITYZONECOUNT); + if (availabilityZoneCount != null && availabilityZoneCount.length() > 0) { + vfModuleCustomization.setAvailabilityZoneCount(Integer.valueOf(availabilityZoneCount)); + } + + vfModuleCustomization.setLabel(toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group, + SdcPropertyNames.PROPERTY_NAME_VFMODULELABEL)); + + String maxInstances = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group, + SdcPropertyNames.PROPERTY_NAME_MAXVFMODULEINSTANCES); + if (maxInstances != null && maxInstances.length() > 0) { + vfModuleCustomization.setMaxInstances(Integer.valueOf(maxInstances)); + } + + String minInstances = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group, + SdcPropertyNames.PROPERTY_NAME_MINVFMODULEINSTANCES); + if (minInstances != null && minInstances.length() > 0) { + vfModuleCustomization.setMinInstances(Integer.valueOf(minInstances)); + } + return vfModuleCustomization; + } + + protected VfModule createVfModule(Group group, ToscaResourceStructure toscaResourceStructure, + IVfModuleData vfModuleData, Metadata vfMetadata) { + VfModule vfModule = new VfModule(); + String vfModuleModelUUID = vfModuleData.getVfModuleModelUUID(); + + if (vfModuleModelUUID == null) { + vfModuleModelUUID = testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata, + SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELUUID)); + } else if (vfModuleModelUUID.indexOf('.') > -1) { + vfModuleModelUUID = vfModuleModelUUID.substring(0, vfModuleModelUUID.indexOf('.')); + } + + vfModule.setModelInvariantUUID(testNull(toscaResourceStructure.getSdcCsarHelper() + .getMetadataPropertyValue(vfMetadata, SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELINVARIANTUUID))); + vfModule.setModelName(testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata, + SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELNAME))); + vfModule.setModelUUID(vfModuleModelUUID); + vfModule.setModelVersion(testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata, + SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELVERSION))); + vfModule.setDescription(testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata, + SdcPropertyNames.PROPERTY_NAME_DESCRIPTION))); + + String vfModuleType = toscaResourceStructure.getSdcCsarHelper().getGroupPropertyLeafValue(group, + SdcPropertyNames.PROPERTY_NAME_VFMODULETYPE); + if (vfModuleType != null && "Base".equalsIgnoreCase(vfModuleType)) { + vfModule.setIsBase(true); + } else { + vfModule.setIsBase(false); + } + return vfModule; + } + + protected void setHeatInformationForVfModule(ToscaResourceStructure toscaResourceStructure, + VfResourceStructure vfResourceStructure, VfModule vfModule, VfModuleCustomization vfModuleCustomization, + Metadata vfMetadata) { + + Optional<VfModuleStructure> matchingObject = vfResourceStructure.getVfModuleStructure().stream() + .filter(vfModuleStruct -> vfModuleStruct.getVfModuleMetadata().getVfModuleModelUUID() + .equalsIgnoreCase(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata, + SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELUUID))) + .findFirst(); + + if (matchingObject.isPresent()) { + List<HeatFiles> heatFilesList = new ArrayList<>(); + List<HeatTemplate> volumeHeatChildTemplates = new ArrayList<HeatTemplate>(); + List<HeatTemplate> heatChildTemplates = new ArrayList<HeatTemplate>(); + HeatTemplate parentHeatTemplate = new HeatTemplate(); + String parentArtifactType = null; + Set<String> artifacts = new HashSet<>(matchingObject.get().getVfModuleMetadata().getArtifacts()); + for (VfModuleArtifact vfModuleArtifact : vfResourceStructure.getArtifactsMapByUUID().values()) { + + List<HeatTemplate> childNestedHeatTemplates = new ArrayList<HeatTemplate>(); + + if (artifacts.contains(vfModuleArtifact.getArtifactInfo().getArtifactUUID())) { + checkVfModuleArtifactType(vfModule, vfModuleCustomization, heatFilesList, vfModuleArtifact, + childNestedHeatTemplates, parentHeatTemplate, vfResourceStructure); + } + + if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_NESTED)) { + parentArtifactType = identifyParentOfNestedTemplate(matchingObject.get(), vfModuleArtifact); + + if (!childNestedHeatTemplates.isEmpty()) { + + if (parentArtifactType != null && parentArtifactType + .equalsIgnoreCase(ASDCConfiguration.HEAT_VOL)) { + volumeHeatChildTemplates.add(childNestedHeatTemplates.get(0)); + } else { + heatChildTemplates.add(childNestedHeatTemplates.get(0)); + } + } + } + + } + if (!heatFilesList.isEmpty()) { + vfModule.setHeatFiles(heatFilesList); + } + + // Set all Child Templates related to HEAT_VOLUME + if (!volumeHeatChildTemplates.isEmpty()) { + if (vfModule.getVolumeHeatTemplate() != null) { + vfModule.getVolumeHeatTemplate().setChildTemplates(volumeHeatChildTemplates); + } else { + logger.debug("VolumeHeatTemplate not set in setHeatInformationForVfModule()"); + } + } + + // Set all Child Templates related to HEAT + if (!heatChildTemplates.isEmpty()) { + if (vfModule.getModuleHeatTemplate() != null) { + vfModule.getModuleHeatTemplate().setChildTemplates(heatChildTemplates); + } else { + logger.debug("ModuleHeatTemplate not set in setHeatInformationForVfModule()"); + } + } + } + } + + protected void checkVfModuleArtifactType(VfModule vfModule, VfModuleCustomization vfModuleCustomization, + List<HeatFiles> heatFilesList, VfModuleArtifact vfModuleArtifact, List<HeatTemplate> nestedHeatTemplates, + HeatTemplate parentHeatTemplate, VfResourceStructure vfResourceStructure) { + if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT)) { + vfModuleArtifact.incrementDeployedInDB(); + vfModule.setModuleHeatTemplate(vfModuleArtifact.getHeatTemplate()); + } else if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_VOL)) { + vfModule.setVolumeHeatTemplate(vfModuleArtifact.getHeatTemplate()); + VfModuleArtifact volVfModuleArtifact = this + .getHeatEnvArtifactFromGeneratedArtifact(vfResourceStructure, vfModuleArtifact); + vfModuleCustomization.setVolumeHeatEnv(volVfModuleArtifact.getHeatEnvironment()); + vfModuleArtifact.incrementDeployedInDB(); + } else if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_ENV)) { + if (vfModuleArtifact.getHeatEnvironment().getName().contains("volume")) { + vfModuleCustomization.setVolumeHeatEnv(vfModuleArtifact.getHeatEnvironment()); + } else { + vfModuleCustomization.setHeatEnvironment(vfModuleArtifact.getHeatEnvironment()); + } + vfModuleArtifact.incrementDeployedInDB(); + } else if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_ARTIFACT)) { + heatFilesList.add(vfModuleArtifact.getHeatFiles()); + vfModuleArtifact.incrementDeployedInDB(); + } else if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_NESTED)) { + nestedHeatTemplates.add(vfModuleArtifact.getHeatTemplate()); + vfModuleArtifact.incrementDeployedInDB(); + } + } + + protected VnfResourceCustomization createVnfResource(NodeTemplate vfNodeTemplate, + ToscaResourceStructure toscaResourceStructure, Service service) { + VnfResourceCustomization vnfResourceCustomization = vnfCustomizationRepo.findOneByModelCustomizationUUID( + vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)); + if (vnfResourceCustomization == null) { + VnfResource vnfResource = findExistingVnfResource(service, + vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)); + + if (vnfResource == null) { + vnfResource = createVnfResource(vfNodeTemplate); + } + + vnfResourceCustomization = createVnfResourceCustomization(vfNodeTemplate, toscaResourceStructure, + vnfResource); + vnfResourceCustomization.setVnfResources(vnfResource); + vnfResource.getVnfResourceCustomizations().add(vnfResourceCustomization); + + // Fetch VNFC Instance Group Info + List<Group> groupList = toscaResourceStructure.getSdcCsarHelper() + .getGroupsOfOriginOfNodeTemplateByToscaGroupType(vfNodeTemplate, + "org.openecomp.groups.VfcInstanceGroup"); + + for (Group group : groupList) { + + VnfcInstanceGroupCustomization vnfcInstanceGroupCustomization = createVNFCInstanceGroup(vfNodeTemplate, + group, vnfResourceCustomization, toscaResourceStructure); + + vnfcInstanceGroupCustomizationRepo.saveAndFlush(vnfcInstanceGroupCustomization); + } + } + return vnfResourceCustomization; + } + + protected VnfResource findExistingVnfResource(Service service, String modelUUID) { + VnfResource vnfResource = null; + for (VnfResourceCustomization vnfResourceCustom : service.getVnfCustomizations()) { + if (vnfResourceCustom.getVnfResources() != null + && vnfResourceCustom.getVnfResources().getModelUUID().equals(modelUUID)) { + vnfResource = vnfResourceCustom.getVnfResources(); + } + } + if (vnfResource == null) { + vnfResource = vnfRepo.findResourceByModelUUID(modelUUID); + } + + return vnfResource; + } + + protected VnfResourceCustomization createVnfResourceCustomization(NodeTemplate vfNodeTemplate, + ToscaResourceStructure toscaResourceStructure, VnfResource vnfResource) { + VnfResourceCustomization vnfResourceCustomization = new VnfResourceCustomization(); + vnfResourceCustomization.setModelCustomizationUUID( + testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID))); + vnfResourceCustomization.setModelInstanceName(vfNodeTemplate.getName()); + + vnfResourceCustomization.setNfFunction(testNull(toscaResourceStructure.getSdcCsarHelper() + .getNodeTemplatePropertyLeafValue(vfNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFFUNCTION))); + vnfResourceCustomization.setNfNamingCode(testNull(toscaResourceStructure.getSdcCsarHelper() + .getNodeTemplatePropertyLeafValue(vfNodeTemplate, "nf_naming_code"))); + vnfResourceCustomization.setNfRole(testNull(toscaResourceStructure.getSdcCsarHelper() + .getNodeTemplatePropertyLeafValue(vfNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFROLE))); + vnfResourceCustomization.setNfType(testNull(toscaResourceStructure.getSdcCsarHelper() + .getNodeTemplatePropertyLeafValue(vfNodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFTYPE))); + + vnfResourceCustomization.setMultiStageDesign(toscaResourceStructure.getSdcCsarHelper() + .getNodeTemplatePropertyLeafValue(vfNodeTemplate, MULTI_STAGE_DESIGN)); + + vnfResourceCustomization.setBlueprintName(testNull(toscaResourceStructure.getSdcCsarHelper() + .getNodeTemplatePropertyLeafValue(vfNodeTemplate, SDNC_MODEL_NAME))); + + vnfResourceCustomization.setBlueprintVersion(testNull(toscaResourceStructure.getSdcCsarHelper() + .getNodeTemplatePropertyLeafValue(vfNodeTemplate, SDNC_MODEL_VERSION))); + + vnfResourceCustomization.setVnfResources(vnfResource); + vnfResourceCustomization.setAvailabilityZoneMaxCount(Integer.getInteger( + vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_AVAILABILITYZONECOUNT))); + + CapabilityAssignments vnfCustomizationCapability = toscaResourceStructure.getSdcCsarHelper() + .getCapabilitiesOf(vfNodeTemplate); + + if (vnfCustomizationCapability != null) { + CapabilityAssignment capAssign = vnfCustomizationCapability.getCapabilityByName(SCALABLE); + + if (capAssign != null) { + vnfResourceCustomization.setMinInstances(Integer.getInteger(toscaResourceStructure.getSdcCsarHelper() + .getCapabilityPropertyLeafValue(capAssign, SdcPropertyNames.PROPERTY_NAME_MININSTANCES))); + vnfResourceCustomization.setMaxInstances(Integer.getInteger(toscaResourceStructure.getSdcCsarHelper() + .getCapabilityPropertyLeafValue(capAssign, SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES))); + } + + } + + toscaResourceStructure.setCatalogVnfResourceCustomization(vnfResourceCustomization); + + return vnfResourceCustomization; + } + + protected VnfResource createVnfResource(NodeTemplate vfNodeTemplate) { + VnfResource vnfResource = new VnfResource(); + vnfResource.setModelInvariantUUID( + testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID))); + vnfResource.setModelName(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME))); + vnfResource.setModelUUID(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID))); + + vnfResource.setModelVersion( + testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION))); + vnfResource.setDescription( + testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION))); + vnfResource.setOrchestrationMode(HEAT); + vnfResource.setToscaNodeType(testNull(vfNodeTemplate.getType())); + vnfResource.setAicVersionMax( + testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES))); + vnfResource.setAicVersionMin( + testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_MININSTANCES))); + vnfResource.setCategory(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CATEGORY)); + vnfResource.setSubCategory(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_SUBCATEGORY)); + + return vnfResource; + } + + protected AllottedResourceCustomization createAllottedResource(NodeTemplate nodeTemplate, + ToscaResourceStructure toscaResourceStructure, Service service) { + AllottedResourceCustomization allottedResourceCustomization = allottedCustomizationRepo + .findOneByModelCustomizationUUID( + nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)); + + if (allottedResourceCustomization == null) { + AllottedResource allottedResource = findExistingAllottedResource(service, + nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)); + + if (allottedResource == null) { + allottedResource = createAR(nodeTemplate); + } + + toscaResourceStructure.setAllottedResource(allottedResource); + allottedResourceCustomization = createAllottedResourceCustomization(nodeTemplate, toscaResourceStructure); + allottedResourceCustomization.setAllottedResource(allottedResource); + allottedResource.getAllotedResourceCustomization().add(allottedResourceCustomization); + } + return allottedResourceCustomization; + } + + protected AllottedResource findExistingAllottedResource(Service service, String modelUUID) { + AllottedResource allottedResource = null; + for (AllottedResourceCustomization allottedResourceCustom : service.getAllottedCustomizations()) { + if (allottedResourceCustom.getAllottedResource() != null + && allottedResourceCustom.getAllottedResource().getModelUUID().equals(modelUUID)) { + allottedResource = allottedResourceCustom.getAllottedResource(); + } + } + if (allottedResource == null) { + allottedResource = allottedRepo.findResourceByModelUUID(modelUUID); + } + + return allottedResource; + } + + protected AllottedResourceCustomization createAllottedResourceCustomization(NodeTemplate nodeTemplate, + ToscaResourceStructure toscaResourceStructure) { + AllottedResourceCustomization allottedResourceCustomization = new AllottedResourceCustomization(); + allottedResourceCustomization.setModelCustomizationUUID( + testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID))); + allottedResourceCustomization.setModelInstanceName(nodeTemplate.getName()); + + allottedResourceCustomization.setNfFunction(testNull(toscaResourceStructure.getSdcCsarHelper() + .getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFFUNCTION))); + allottedResourceCustomization.setNfNamingCode(testNull(toscaResourceStructure.getSdcCsarHelper() + .getNodeTemplatePropertyLeafValue(nodeTemplate, "nf_naming_code"))); + allottedResourceCustomization.setNfRole(testNull(toscaResourceStructure.getSdcCsarHelper() + .getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFROLE))); + allottedResourceCustomization.setNfType(testNull(toscaResourceStructure.getSdcCsarHelper() + .getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFTYPE))); + + List<NodeTemplate> vfcNodes = toscaResourceStructure.getSdcCsarHelper() + .getVfcListByVf(allottedResourceCustomization.getModelCustomizationUUID()); + + if (vfcNodes != null) { + for (NodeTemplate vfcNode : vfcNodes) { + + allottedResourceCustomization.setProvidingServiceModelUUID(toscaResourceStructure.getSdcCsarHelper() + .getNodeTemplatePropertyLeafValue(vfcNode, "providing_service_uuid")); + allottedResourceCustomization.setProvidingServiceModelInvariantUUID( + toscaResourceStructure.getSdcCsarHelper() + .getNodeTemplatePropertyLeafValue(vfcNode, "providing_service_invariant_uuid")); + allottedResourceCustomization.setProvidingServiceModelName(toscaResourceStructure.getSdcCsarHelper() + .getNodeTemplatePropertyLeafValue(vfcNode, "providing_service_name")); + } + } + + CapabilityAssignments arCustomizationCapability = toscaResourceStructure.getSdcCsarHelper() + .getCapabilitiesOf(nodeTemplate); + + if (arCustomizationCapability != null) { + CapabilityAssignment capAssign = arCustomizationCapability.getCapabilityByName(SCALABLE); + + if (capAssign != null) { + allottedResourceCustomization.setMinInstances( + Integer.getInteger(toscaResourceStructure.getSdcCsarHelper().getCapabilityPropertyLeafValue( + capAssign, SdcPropertyNames.PROPERTY_NAME_MININSTANCES))); + allottedResourceCustomization.setMaxInstances( + Integer.getInteger(toscaResourceStructure.getSdcCsarHelper().getCapabilityPropertyLeafValue( + capAssign, SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES))); + } + } + return allottedResourceCustomization; + } + + protected AllottedResource createAR(NodeTemplate nodeTemplate) { + AllottedResource allottedResource = new AllottedResource(); + allottedResource + .setModelUUID(testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID))); + allottedResource.setModelInvariantUUID( + testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID))); + allottedResource + .setModelName(testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME))); + allottedResource + .setModelVersion(testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION))); + allottedResource.setToscaNodeType(testNull(nodeTemplate.getType())); + allottedResource.setSubcategory( + testNull(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_SUBCATEGORY))); + allottedResource + .setDescription(nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)); + return allottedResource; + } + + protected Set<HeatTemplateParam> extractHeatTemplateParameters(String yamlFile, String artifactUUID) { + // Scan the payload downloadResult and extract the HeatTemplate + // parameters + YamlEditor yamlEditor = new YamlEditor(yamlFile.getBytes()); + return yamlEditor.getParameterList(artifactUUID); + } + + protected String testNull(Object object) { + + if (object == null) { + return null; + } else if (object.equals("NULL")) { + return null; + } else if (object instanceof Integer) { + return object.toString(); + } else if (object instanceof String) { + return (String) object; + } else { + return "Type not recognized"; + } + } + + protected static String identifyParentOfNestedTemplate(VfModuleStructure vfModuleStructure, + VfModuleArtifact heatNestedArtifact) { + + if (vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT) != null && vfModuleStructure + .getArtifactsMap().get(ASDCConfiguration.HEAT).get(0).getArtifactInfo().getRelatedArtifacts() != null) { + for (IArtifactInfo unknownArtifact : vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT).get(0) + .getArtifactInfo().getRelatedArtifacts()) { + if (heatNestedArtifact.getArtifactInfo().getArtifactUUID().equals(unknownArtifact.getArtifactUUID())) { + return ASDCConfiguration.HEAT; + } + + } + } + + if (vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT_VOL) != null + && vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT_VOL).get(0).getArtifactInfo() + .getRelatedArtifacts() != null) { + for (IArtifactInfo unknownArtifact : vfModuleStructure.getArtifactsMap().get(ASDCConfiguration.HEAT_VOL) + .get(0).getArtifactInfo().getRelatedArtifacts()) { + if (heatNestedArtifact.getArtifactInfo().getArtifactUUID().equals(unknownArtifact.getArtifactUUID())) { + return ASDCConfiguration.HEAT_VOL; + } + + } + } + + // Does not belong to anything + return null; + + } + + protected static String createVNFName(VfResourceStructure vfResourceStructure) { + + return vfResourceStructure.getNotification().getServiceName() + "/" + + vfResourceStructure.getResourceInstance().getResourceInstanceName(); + } + + protected static String createVfModuleName(VfModuleStructure vfModuleStructure) { + + return createVNFName(vfModuleStructure.getParentVfResource()) + "::" + + vfModuleStructure.getVfModuleMetadata().getVfModuleModelName(); + } + + protected String getPropertyInput(String propertyName) { + + String inputName = new String(); + + if (propertyName != null) { + int getInputIndex = propertyName.indexOf("{get_input="); + if (getInputIndex > -1) { + inputName = propertyName.substring(getInputIndex + 11, propertyName.length() - 1); + } + } + + return inputName; + } + + + protected static Timestamp getCurrentTimeStamp() { + + return new Timestamp(new Date().getTime()); + } } |