diff options
Diffstat (limited to 'asdc-controller/src/main')
11 files changed, 626 insertions, 94 deletions
diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/Application.java b/asdc-controller/src/main/java/org/onap/so/asdc/Application.java index 1f66291283..a05eeea466 100644 --- a/asdc-controller/src/main/java/org/onap/so/asdc/Application.java +++ b/asdc-controller/src/main/java/org/onap/so/asdc/Application.java @@ -20,17 +20,25 @@ package org.onap.so.asdc; +import javax.annotation.PostConstruct; +import org.onap.so.asdc.activity.DeployActivitySpecs; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; import org.springframework.scheduling.annotation.EnableScheduling; @SpringBootApplication(scanBasePackages = {"org.onap.so"}) @EnableScheduling +@EnableJpaRepositories("org.onap.so.db.catalog.data.repository") public class Application { private static final String MSO_CONFIG_PATH = "mso.config.path"; private static final String LOGS_DIR = "logs_dir"; + @Autowired + DeployActivitySpecs deployActivitySpecs; + private static void setLogsDir() { if (System.getProperty(LOGS_DIR) == null) { System.getProperties().setProperty(LOGS_DIR, "./logs/asdc/"); @@ -42,6 +50,15 @@ public class Application { System.getProperties().setProperty(MSO_CONFIG_PATH, "."); } + @PostConstruct + private void deployActivities() { + try { + deployActivitySpecs.deployActivities(); + } catch (Exception e) { + } + + } + public static void main(String[] args) { SpringApplication.run(Application.class, args); System.getProperties().setProperty("mso.db", "MARIADB"); diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/activity/DeployActivitySpecs.java b/asdc-controller/src/main/java/org/onap/so/asdc/activity/DeployActivitySpecs.java index 46d0f78e35..87008f1d8f 100644 --- a/asdc-controller/src/main/java/org/onap/so/asdc/activity/DeployActivitySpecs.java +++ b/asdc-controller/src/main/java/org/onap/so/asdc/activity/DeployActivitySpecs.java @@ -20,14 +20,18 @@ package org.onap.so.asdc.activity; -import javax.annotation.PostConstruct; import java.util.ArrayList; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.env.Environment; import org.springframework.stereotype.Component; import org.onap.so.asdc.activity.beans.ActivitySpec; -import org.onap.so.db.catalog.client.CatalogDbClient; +import org.onap.so.asdc.activity.beans.Input; +import org.onap.so.asdc.activity.beans.Output; +import org.onap.so.db.catalog.beans.ActivitySpecActivitySpecCategories; +import org.onap.so.db.catalog.beans.ActivitySpecActivitySpecParameters; +import org.onap.so.db.catalog.beans.ActivitySpecParameters; +import org.onap.so.db.catalog.data.repository.ActivitySpecRepository; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -39,17 +43,24 @@ public class DeployActivitySpecs { @Autowired private Environment env; + @Autowired + private ActivitySpecRepository activitySpecRepository; + private static final String SDC_ENDPOINT = "mso.asdc.config.activity.endpoint"; + private static final String DIRECTION_INPUT = "input"; + private static final String DIRECTION_OUTPUT = "output"; protected static final Logger logger = LoggerFactory.getLogger(DeployActivitySpecs.class); - public void deployActivities() throws Exception { - String hostname = this.env.getProperty(SDC_ENDPOINT); - List<ActivitySpec> activitySpecs = new ArrayList<ActivitySpec>(); - // Initialize activitySpecs from Catalog DB - - for (ActivitySpec activitySpec : activitySpecs) { + public void deployActivities() throws Exception { + String hostname = env.getProperty(SDC_ENDPOINT); + if (hostname == null || hostname.isEmpty()) { + return; + } + List<org.onap.so.db.catalog.beans.ActivitySpec> activitySpecsFromCatalog = activitySpecRepository.findAll(); + for (org.onap.so.db.catalog.beans.ActivitySpec activitySpecFromCatalog : activitySpecsFromCatalog) { + ActivitySpec activitySpec = mapActivitySpecFromCatalogToSdc(activitySpecFromCatalog); String activitySpecId = activitySpecsActions.createActivitySpec(hostname, activitySpec); if (activitySpecId != null) { logger.info("{} {}", "Successfully created activitySpec", activitySpec.getName()); @@ -64,4 +75,62 @@ public class DeployActivitySpecs { } } } + + public ActivitySpec mapActivitySpecFromCatalogToSdc( + org.onap.so.db.catalog.beans.ActivitySpec activitySpecFromCatalog) { + ActivitySpec activitySpec = new ActivitySpec(); + activitySpec.setName(activitySpecFromCatalog.getName()); + activitySpec.setDescription(activitySpecFromCatalog.getDescription()); + mapCategoryList(activitySpecFromCatalog.getActivitySpecActivitySpecCategories(), activitySpec); + mapInputsAndOutputs(activitySpecFromCatalog.getActivitySpecActivitySpecParameters(), activitySpec); + return activitySpec; + } + + private void mapCategoryList(List<ActivitySpecActivitySpecCategories> activitySpecActivitySpecCategories, + ActivitySpec activitySpec) { + if (activitySpecActivitySpecCategories == null || activitySpecActivitySpecCategories.size() == 0) { + return; + } + List<String> categoryList = new ArrayList<String>(); + for (ActivitySpecActivitySpecCategories activitySpecCat : activitySpecActivitySpecCategories) { + if (activitySpecCat != null) { + if (activitySpecCat.getActivitySpecCategories() != null) { + categoryList.add(activitySpecCat.getActivitySpecCategories().getName()); + } + } + } + activitySpec.setCategoryList(categoryList); + } + + private void mapInputsAndOutputs(List<ActivitySpecActivitySpecParameters> activitySpecActivitySpecParameters, + ActivitySpec activitySpec) { + if (activitySpecActivitySpecParameters == null || activitySpecActivitySpecParameters.size() == 0) { + return; + } + List<Input> inputs = new ArrayList<Input>(); + List<Output> outputs = new ArrayList<Output>(); + for (ActivitySpecActivitySpecParameters activitySpecParam : activitySpecActivitySpecParameters) { + if (activitySpecParam != null) { + if (activitySpecParam.getActivitySpecParameters() != null) { + ActivitySpecParameters activitySpecParameters = activitySpecParam.getActivitySpecParameters(); + if (activitySpecParameters != null) { + if (activitySpecParameters.getDirection().equals(DIRECTION_INPUT)) { + Input input = new Input(); + input.setName(activitySpecParameters.getName()); + input.setType(activitySpecParameters.getType()); + inputs.add(input); + } else if (activitySpecParameters.getDirection().equals(DIRECTION_OUTPUT)) { + Output output = new Output(); + output.setName(activitySpecParameters.getName()); + output.setType(activitySpecParameters.getType()); + outputs.add(output); + } + } + } + } + } + activitySpec.setInputs(inputs); + activitySpec.setOutputs(outputs); + return; + } } diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/client/ASDCConfiguration.java b/asdc-controller/src/main/java/org/onap/so/asdc/client/ASDCConfiguration.java index 7d92c637ad..2eace7587f 100644 --- a/asdc-controller/src/main/java/org/onap/so/asdc/client/ASDCConfiguration.java +++ b/asdc-controller/src/main/java/org/onap/so/asdc/client/ASDCConfiguration.java @@ -47,24 +47,6 @@ public class ASDCConfiguration implements IConfiguration { private String asdcControllerName; - public static final String MSO_PROP_ASDC = "MSO_PROP_ASDC"; - public static final String PARAMETER_PATTERN = "asdc-connections"; - public static final String MSG_BUS_ADDRESS_ATTRIBUTE_NAME = "messageBusAddress"; - public static final String WATCHDOG_TIMEOUT_NAME = "watchDogTimeout"; - - public static final String CONSUMER_GROUP_ATTRIBUTE_NAME = "consumerGroup"; - public static final String CONSUMER_ID_ATTRIBUTE_NAME = "consumerId"; - public static final String ENVIRONMENT_NAME_ATTRIBUTE_NAME = "environmentName"; - public static final String PASSWORD_ATTRIBUTE_NAME = "password"; - public static final String POLLING_INTERVAL_ATTRIBUTE_NAME = "pollingInterval"; - public static final String RELEVANT_ARTIFACT_TYPES_ATTRIBUTE_NAME = "relevantArtifactTypes"; - public static final String USER_ATTRIBUTE_NAME = "user"; - public static final String ASDC_ADDRESS_ATTRIBUTE_NAME = "asdcAddress"; - public static final String POLLING_TIMEOUT_ATTRIBUTE_NAME = "pollingTimeout"; - public static final String ACTIVATE_SERVER_TLS_AUTH = "activateServerTLSAuth"; - public static final String KEY_STORE_PASSWORD = "keyStorePassword"; - public static final String KEY_STORE_PATH = "keyStorePath"; - public static final String HEAT = "HEAT"; public static final String HEAT_ARTIFACT = "HEAT_ARTIFACT"; public static final String HEAT_ENV = "HEAT_ENV"; @@ -73,7 +55,7 @@ public class ASDCConfiguration implements IConfiguration { public static final String HEAT_VOL = "HEAT_VOL"; public static final String OTHER = "OTHER"; public static final String TOSCA_CSAR = "TOSCA_CSAR"; - public static final String WORKFLOWS = "Workflows"; + public static final String WORKFLOW = "WORKFLOW"; public static final String VF_MODULES_METADATA = "VF_MODULES_METADATA"; private static final String[] SUPPORTED_ARTIFACT_TYPES = 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 f2e875fc0c..9b838c4d98 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 @@ -47,6 +47,7 @@ import org.onap.sdc.api.results.IDistributionClientResult; import org.onap.sdc.impl.DistributionClientFactory; import org.onap.sdc.utils.DistributionActionResultEnum; import org.onap.sdc.utils.DistributionStatusEnum; +import org.onap.so.asdc.activity.DeployActivitySpecs; import org.onap.so.asdc.client.exceptions.ASDCControllerException; import org.onap.so.asdc.client.exceptions.ASDCDownloadException; import org.onap.so.asdc.client.exceptions.ASDCParametersException; @@ -57,7 +58,6 @@ 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; import org.onap.so.asdc.installer.heat.ToscaResourceInstaller; import org.onap.so.asdc.tenantIsolation.DistributionStatus; import org.onap.so.asdc.tenantIsolation.WatchdogDistribution; @@ -89,9 +89,6 @@ public class ASDCController { private ToscaResourceInstaller toscaInstaller; @Autowired - private BpmnInstaller bpmnInstaller; - - @Autowired private WatchdogDistributionStatusRepository wdsRepo; @Autowired @@ -110,6 +107,9 @@ public class ASDCController { @Autowired private WatchdogDistribution wd; + @Autowired + DeployActivitySpecs deployActivitySpecs; + public int getNbOfNotificationsOngoing() { return nbOfNotificationsOngoing; } @@ -668,9 +668,6 @@ public class ASDCController { 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()) { @@ -679,7 +676,7 @@ public class ASDCController { logger.info("Processing Resource Type: {}, Model UUID: {}", resourceType, resource.getResourceUUID()); - if ("VF".equals(resourceType) && !"Allotted Resource".equalsIgnoreCase(category)) { + if ("VF".equals(resourceType)) { resourceStructure = new VfResourceStructure(iNotif, resource); } else if ("PNF".equals(resourceType)) { resourceStructure = new PnfResourceStructure(iNotif, resource); @@ -697,7 +694,7 @@ public class ASDCController { logger.debug("Processing Resource Type: " + resourceType + " and Model UUID: " + resourceStructure.getResourceInstance().getResourceUUID()); - if ("VF".equals(resourceType) && !"Allotted Resource".equalsIgnoreCase(category)) { + if ("VF".equals(resourceType)) { hasVFResource = true; for (IArtifactInfo artifact : resource.getArtifacts()) { IDistributionClientDownloadResult resultArtifact = @@ -711,8 +708,15 @@ public class ASDCController { .dumpVfModuleMetaDataList(((VfResourceStructure) resourceStructure) .decodeVfModuleArtifact(resultArtifact.getArtifactPayload()))); } - resourceStructure.addArtifactToStructure(distributionClient, artifact, - resultArtifact); + if (!ASDCConfiguration.WORKFLOW.equals(artifact.getArtifactType())) { + resourceStructure.addArtifactToStructure(distributionClient, artifact, + resultArtifact); + } else { + writeArtifactToFile(artifact, resultArtifact); + logger.debug( + "Adding workflow artifact to structure: " + artifact.getArtifactName()); + resourceStructure.addWorkflowArtifactToStructure(artifact, resultArtifact); + } } } @@ -801,7 +805,7 @@ public class ASDCController { "processCsarServiceArtifacts", ErrorCode.BusinessProcesssError.getValue(), "Exception in processCsarServiceArtifacts", e); } - } else if (artifact.getArtifactType().equals(ASDCConfiguration.WORKFLOWS)) { + } else if (artifact.getArtifactType().equals(ASDCConfiguration.WORKFLOW)) { try { 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 index 8aa9684426..2a6e77ed40 100644 --- 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 @@ -39,6 +39,12 @@ public class PnfResourceStructure extends ResourceStructure { } @Override + public void addWorkflowArtifactToStructure(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 index 9965a05294..8be3d6ba06 100644 --- 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 @@ -68,10 +68,16 @@ public abstract class ResourceStructure { */ protected final Map<String, VfModuleArtifact> artifactsMapByUUID; + /** + * The list of workflow artifacts existing in this resource + */ + protected final Map<String, WorkflowArtifact> workflowArtifactsMapByUUID; + public ResourceStructure(INotificationData notificationData, IResourceInstance resourceInstance) { this.notificationData = notificationData; this.resourceInstance = resourceInstance; artifactsMapByUUID = new HashMap<>(); + workflowArtifactsMapByUUID = new HashMap<>(); } /** @@ -85,6 +91,9 @@ public abstract class ResourceStructure { public abstract void addArtifactToStructure(IDistributionClient distributionClient, IArtifactInfo artifactinfo, IDistributionClientDownloadResult clientResult) throws UnsupportedEncodingException; + public abstract void addWorkflowArtifactToStructure(IArtifactInfo artifactinfo, + IDistributionClientDownloadResult clientResult) throws UnsupportedEncodingException; + /** * Prepare the resource for installation. * @@ -144,4 +153,8 @@ public abstract class ResourceStructure { return artifactsMapByUUID; } + public Map<String, WorkflowArtifact> getWorkflowArtifactsMapByUUID() { + return workflowArtifactsMapByUUID; + } + } 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 62408be922..16e9fda7c4 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 @@ -98,6 +98,12 @@ public class VfResourceStructure extends ResourceStructure { } } + public void addWorkflowArtifactToStructure(IArtifactInfo artifactinfo, + IDistributionClientDownloadResult clientResult) throws UnsupportedEncodingException { + WorkflowArtifact workflowArtifact = new WorkflowArtifact(artifactinfo, clientResult); + workflowArtifactsMapByUUID.put(artifactinfo.getArtifactUUID(), workflowArtifact); + } + protected void addArtifactByType(IArtifactInfo artifactinfo, IDistributionClientDownloadResult clientResult, VfModuleArtifact vfModuleArtifact) throws UnsupportedEncodingException { diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/installer/WorkflowArtifact.java b/asdc-controller/src/main/java/org/onap/so/asdc/installer/WorkflowArtifact.java new file mode 100644 index 0000000000..83b5614104 --- /dev/null +++ b/asdc-controller/src/main/java/org/onap/so/asdc/installer/WorkflowArtifact.java @@ -0,0 +1,65 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.asdc.installer; + + +import java.io.UnsupportedEncodingException; +import org.onap.so.db.catalog.beans.HeatEnvironment; +import org.onap.so.db.catalog.beans.HeatFiles; +import org.onap.so.db.catalog.beans.HeatTemplate; +import org.onap.sdc.api.notification.IArtifactInfo; +import org.onap.sdc.api.results.IDistributionClientDownloadResult; + +/** + * The structure that contains the artifactInfo and its associated DownloadedResult. + * + */ +public final class WorkflowArtifact { + private final IArtifactInfo artifactInfo; + private int deployedInDb = 0; + private final String result; + + public WorkflowArtifact(IArtifactInfo artifactinfo, IDistributionClientDownloadResult clientResult) + throws UnsupportedEncodingException { + result = new String(clientResult.getArtifactPayload(), "UTF-8"); + artifactInfo = artifactinfo; + + } + + public IArtifactInfo getArtifactInfo() { + return artifactInfo; + } + + public String getResult() { + return result; + } + + public int getDeployedInDb() { + return deployedInDb; + } + + public void incrementDeployedInDB() { + ++deployedInDb; + } + + + +} diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/installer/bpmn/BpmnInstaller.java b/asdc-controller/src/main/java/org/onap/so/asdc/installer/bpmn/BpmnInstaller.java index c98fb9b619..7945ad0174 100644 --- a/asdc-controller/src/main/java/org/onap/so/asdc/installer/bpmn/BpmnInstaller.java +++ b/asdc-controller/src/main/java/org/onap/so/asdc/installer/bpmn/BpmnInstaller.java @@ -58,7 +58,7 @@ public class BpmnInstaller { protected static final Logger logger = LoggerFactory.getLogger(BpmnInstaller.class); private static final String BPMN_SUFFIX = ".bpmn"; private static final String CAMUNDA_URL = "mso.camundaURL"; - private static final String CREATE_DEPLOYMENT_PATH = "/sobpmnengine/deployment/create"; + private static final String CREATE_DEPLOYMENT_PATH = "sobpmnengine/deployment/create"; @Autowired private Environment env; @@ -78,7 +78,7 @@ public class BpmnInstaller { Path p = Paths.get(name); String fileName = p.getFileName().toString(); extractBpmnFileFromCsar(csarFile, fileName); - HttpResponse response = sendDeploymentRequest(fileName); + HttpResponse response = sendDeploymentRequest(fileName, ""); logger.debug("Response status line: {}", response.getStatusLine()); logger.debug("Response entity: {}", response.getEntity().toString()); if (response.getStatusLine().getStatusCode() != 200) { @@ -125,21 +125,21 @@ public class BpmnInstaller { return workflowsInCsar; } - protected HttpResponse sendDeploymentRequest(String bpmnFileName) throws Exception { + protected HttpResponse sendDeploymentRequest(String bpmnFileName, String version) throws Exception { HttpClient client = HttpClientBuilder.create().build(); URI deploymentUri = new URI(this.env.getProperty(CAMUNDA_URL) + CREATE_DEPLOYMENT_PATH); HttpPost post = new HttpPost(deploymentUri); RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(1000000).setConnectTimeout(1000) .setConnectionRequestTimeout(1000).build(); post.setConfig(requestConfig); - HttpEntity requestEntity = buildMimeMultipart(bpmnFileName); + HttpEntity requestEntity = buildMimeMultipart(bpmnFileName, version); post.setEntity(requestEntity); return client.execute(post); } - protected HttpEntity buildMimeMultipart(String bpmnFileName) throws Exception { + protected HttpEntity buildMimeMultipart(String bpmnFileName, String version) throws Exception { FileInputStream bpmnFileStream = new FileInputStream( - Paths.get(System.getProperty("mso.config.path"), "ASDC", bpmnFileName).normalize().toString()); + Paths.get(System.getProperty("mso.config.path"), "ASDC", version, bpmnFileName).normalize().toString()); byte[] bytesToSend = IOUtils.toByteArray(bpmnFileStream); HttpEntity requestEntity = diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/installer/bpmn/WorkflowResource.java b/asdc-controller/src/main/java/org/onap/so/asdc/installer/bpmn/WorkflowResource.java new file mode 100644 index 0000000000..daeda2f976 --- /dev/null +++ b/asdc-controller/src/main/java/org/onap/so/asdc/installer/bpmn/WorkflowResource.java @@ -0,0 +1,215 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Modifications Copyright (c) 2019 Samsung + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.asdc.installer.bpmn; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import org.apache.http.HttpResponse; +import org.onap.sdc.api.notification.IArtifactInfo; +import org.onap.so.asdc.installer.VfResourceStructure; +import org.onap.so.asdc.installer.WorkflowArtifact; +import org.onap.so.db.catalog.beans.ActivitySpec; +import org.onap.so.db.catalog.beans.VnfResourceWorkflow; +import org.onap.so.db.catalog.beans.Workflow; +import org.onap.so.db.catalog.beans.WorkflowActivitySpecSequence; +import org.onap.so.db.catalog.data.repository.ActivitySpecRepository; +import org.onap.so.db.catalog.data.repository.WorkflowRepository; +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.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class WorkflowResource { + protected static final Logger logger = LoggerFactory.getLogger(WorkflowResource.class); + + private static final String pattern = ".*\\\"activity:(.*)\\\" .*"; + private static final String TARGET_RESOURCE_VNF = "vnf"; + private static final String SOURCE_SDC = "sdc"; + private static final String BPMN_SUFFIX = ".bpmn"; + + @Autowired + protected WorkflowRepository workflowRepo; + + @Autowired + protected ActivitySpecRepository activityRepo; + + @Autowired + private BpmnInstaller bpmnInstaller; + + public void processWorkflows(VfResourceStructure vfResourceStructure) throws Exception { + Map<String, WorkflowArtifact> artifactsMapByUUID = vfResourceStructure.getWorkflowArtifactsMapByUUID(); + String vfResourceModelUuid = vfResourceStructure.getResourceInstance().getResourceUUID(); + for (String uuid : artifactsMapByUUID.keySet()) { + WorkflowArtifact artifactToInstall = artifactsMapByUUID.get(uuid); + if (isLatestVersionAvailable(artifactsMapByUUID, artifactToInstall)) { + logger.debug("Installing the BPMN: " + artifactToInstall.getArtifactInfo().getArtifactName()); + deployWorkflowResourceToCamunda(artifactToInstall); + installWorkflowResource(artifactToInstall, vfResourceModelUuid); + } else { + logger.debug("Skipping installing - not the latest version: " + + artifactToInstall.getArtifactInfo().getArtifactName()); + } + } + } + + protected void deployWorkflowResourceToCamunda(WorkflowArtifact artifact) throws Exception { + String bpmnName = artifact.getArtifactInfo().getArtifactName(); + String version = artifact.getArtifactInfo().getArtifactVersion(); + logger.debug("BPMN Name: " + bpmnName); + try { + HttpResponse response = bpmnInstaller.sendDeploymentRequest(bpmnName, version); + logger.debug("Response status line: {}", response.getStatusLine()); + logger.debug("Response entity: {}", response.getEntity().toString()); + if (response.getStatusLine().getStatusCode() != 200) { + logger.debug("Failed deploying BPMN {}", bpmnName); + logger.error("{} {} {} {} {} {}", MessageEnum.ASDC_ARTIFACT_NOT_DEPLOYED_DETAIL.toString(), bpmnName, + bpmnName, Integer.toString(response.getStatusLine().getStatusCode()), + ErrorCode.DataError.getValue(), "ASDC BPMN deploy failed"); + throw (new Exception("Error from Camunda on deploying the BPMN: " + bpmnName)); + } else { + logger.debug("Successfully deployed to Camunda: {}", bpmnName); + } + } catch (Exception e) { + logger.debug("Exception :", e); + logger.error("{} {} {} {} {}", MessageEnum.ASDC_ARTIFACT_NOT_DEPLOYED_DETAIL.toString(), bpmnName, + e.getMessage(), ErrorCode.DataError.getValue(), "ASDC BPMN deploy failed"); + throw e; + } + } + + protected void installWorkflowResource(WorkflowArtifact artifact, String vfResourceModelUuid) throws Exception { + IArtifactInfo artifactInfo = artifact.getArtifactInfo(); + + Workflow workflow = new Workflow(); + + workflow.setArtifactChecksum(artifactInfo.getArtifactChecksum()); + workflow.setArtifactName(artifactInfo.getArtifactName()); + workflow.setArtifactUUID(artifactInfo.getArtifactUUID()); + workflow.setBody(artifact.getResult()); + workflow.setDescription(artifactInfo.getArtifactDescription()); + workflow.setName(getWorkflowNameFromArtifactName(artifactInfo.getArtifactName())); + workflow.setResourceTarget(TARGET_RESOURCE_VNF); + workflow.setSource(SOURCE_SDC); + workflow.setTimeoutMinutes(artifactInfo.getArtifactTimeout()); + workflow.setOperationName(getWorkflowNameFromArtifactName(artifactInfo.getArtifactName())); + workflow.setVersion(getWorkflowVersionFromArtifactName(artifactInfo.getArtifactName())); + + VnfResourceWorkflow vnfResourceWorkflow = new VnfResourceWorkflow(); + vnfResourceWorkflow.setVnfResourceModelUUID(vfResourceModelUuid); + List<VnfResourceWorkflow> vnfResourceWorkflows = new ArrayList<VnfResourceWorkflow>(); + vnfResourceWorkflows.add(vnfResourceWorkflow); + + workflow.setVnfResourceWorkflow(vnfResourceWorkflows); + + List<String> activityNames = getActivityNameList(artifact.getResult()); + List<WorkflowActivitySpecSequence> wfss = getWorkflowActivitySpecSequence(activityNames); + workflow.setWorkflowActivitySpecSequence(wfss); + + workflowRepo.save(workflow); + + } + + protected boolean isLatestVersionAvailable(Map<String, WorkflowArtifact> artifactsMapByUUID, + WorkflowArtifact artifact) { + String workflowName = getWorkflowNameFromArtifactName(artifact.getArtifactInfo().getArtifactName()); + Double workflowVersion = getWorkflowVersionFromArtifactName(artifact.getArtifactInfo().getArtifactName()); + if (workflowVersion == null) { + workflowVersion = 0.0; + } + for (WorkflowArtifact artifactInMap : artifactsMapByUUID.values()) { + Double versionInMap = getWorkflowVersionFromArtifactName(artifactInMap.getArtifactInfo().getArtifactName()); + if (versionInMap == null) { + versionInMap = 0.0; + } + if (workflowName.equals(getWorkflowNameFromArtifactName(artifactInMap.getArtifactInfo().getArtifactName())) + && Double.compare(workflowVersion, versionInMap) < 0) { + return false; + } + } + return true; + } + + protected List<String> getActivityNameList(String bpmnContent) { + List<String> activityNameList = new ArrayList<String>(); + + Pattern p = Pattern.compile(pattern); + Matcher m = p.matcher(bpmnContent); + while (m.find()) { + activityNameList.add(m.group(1)); + } + return activityNameList; + } + + protected List<WorkflowActivitySpecSequence> getWorkflowActivitySpecSequence(List<String> activityNames) + throws Exception { + if (activityNames == null || activityNames.size() == 0) { + return null; + } + List<WorkflowActivitySpecSequence> workflowActivitySpecs = new ArrayList<WorkflowActivitySpecSequence>(); + for (String activityName : activityNames) { + ActivitySpec activitySpec = activityRepo.findByName(activityName); + if (activitySpec != null) { + WorkflowActivitySpecSequence workflowActivitySpec = new WorkflowActivitySpecSequence(); + workflowActivitySpec.setActivitySpec(activitySpec); + workflowActivitySpecs.add(workflowActivitySpec); + } + } + return workflowActivitySpecs; + } + + public String getWorkflowNameFromArtifactName(String artifactName) { + if (artifactName == null) { + return null; + } else { + if (artifactName.contains(BPMN_SUFFIX)) { + return artifactName.substring(0, artifactName.lastIndexOf(BPMN_SUFFIX)).split("-")[0]; + } else { + return artifactName.split("-")[0]; + } + } + } + + public Double getWorkflowVersionFromArtifactName(String artifactName) { + if (artifactName == null) { + return null; + } else { + String[] workflowNameParts = null; + if (artifactName.contains(BPMN_SUFFIX)) { + workflowNameParts = artifactName.substring(0, artifactName.lastIndexOf(BPMN_SUFFIX)).split("-"); + } else { + workflowNameParts = artifactName.split("-"); + } + if (workflowNameParts.length < 2) { + return null; + } else { + return Double.valueOf(workflowNameParts[1].replaceAll("_", ".")); + } + } + } +} 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 f3a495825c..ddf1f3d84b 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 @@ -26,6 +26,7 @@ package org.onap.so.asdc.installer.heat; import java.sql.Timestamp; import java.util.ArrayList; +import java.util.Collections; import java.util.Date; import java.util.HashMap; import java.util.HashSet; @@ -35,6 +36,7 @@ import java.util.Map; import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; +import org.hibernate.StaleObjectStateException; import org.hibernate.exception.ConstraintViolationException; import org.hibernate.exception.LockAcquisitionException; import org.onap.sdc.api.notification.IArtifactInfo; @@ -55,7 +57,6 @@ import org.onap.sdc.toscaparser.api.Property; import org.onap.sdc.toscaparser.api.RequirementAssignment; import org.onap.sdc.toscaparser.api.RequirementAssignments; import org.onap.sdc.toscaparser.api.elements.Metadata; -import org.onap.sdc.toscaparser.api.elements.StatefulEntityType; import org.onap.sdc.toscaparser.api.functions.GetInput; import org.onap.sdc.toscaparser.api.parameters.Input; import org.onap.sdc.utils.DistributionStatusEnum; @@ -70,6 +71,7 @@ import org.onap.so.asdc.installer.ToscaResourceStructure; import org.onap.so.asdc.installer.VfModuleArtifact; import org.onap.so.asdc.installer.VfModuleStructure; import org.onap.so.asdc.installer.VfResourceStructure; +import org.onap.so.asdc.installer.bpmn.WorkflowResource; import org.onap.so.asdc.util.YamlEditor; import org.onap.so.db.catalog.beans.AllottedResource; import org.onap.so.db.catalog.beans.AllottedResourceCustomization; @@ -122,7 +124,6 @@ import org.onap.so.db.catalog.data.repository.ServiceRepository; import org.onap.so.db.catalog.data.repository.TempNetworkHeatTemplateRepository; import org.onap.so.db.catalog.data.repository.VFModuleCustomizationRepository; import org.onap.so.db.catalog.data.repository.VFModuleRepository; -import org.onap.so.db.catalog.data.repository.VnfCustomizationRepository; import org.onap.so.db.catalog.data.repository.VnfResourceRepository; import org.onap.so.db.catalog.data.repository.VnfcCustomizationRepository; import org.onap.so.db.catalog.data.repository.VnfcInstanceGroupCustomizationRepository; @@ -142,6 +143,7 @@ import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import org.springframework.util.CollectionUtils; @Component public class ToscaResourceInstaller { @@ -247,6 +249,9 @@ public class ToscaResourceInstaller { @Autowired protected PnfCustomizationRepository pnfCustomizationRepository; + @Autowired + protected WorkflowResource workflowResource; + protected static final Logger logger = LoggerFactory.getLogger(ToscaResourceInstaller.class); public boolean isResourceAlreadyDeployed(ResourceStructure vfResourceStruct, boolean serviceDeployed) @@ -308,6 +313,7 @@ public class ToscaResourceInstaller { } } + @Transactional(rollbackFor = {ArtifactInstallerException.class}) public void installTheResource(ToscaResourceStructure toscaResourceStruct, ResourceStructure resourceStruct) throws ArtifactInstallerException { @@ -400,6 +406,7 @@ public class ToscaResourceInstaller { vfCustomizationCategory); } + workflowResource.processWorkflows(vfResourceStructure); processResourceSequence(toscaResourceStruct, service); List<NodeTemplate> allottedResourceList = toscaResourceStruct.getSdcCsarHelper().getAllottedResources(); processAllottedResources(toscaResourceStruct, service, allottedResourceList); @@ -408,8 +415,10 @@ public class ToscaResourceInstaller { processNetworkCollections(toscaResourceStruct, service); // Process Service Proxy & Configuration processServiceProxyAndConfiguration(toscaResourceStruct, service); + logger.info("Saving Service: {} ", service.getModelName()); - serviceRepo.save(service); + service = serviceRepo.save(service); + correlateConfigCustomResources(service); WatchdogComponentDistributionStatus status = new WatchdogComponentDistributionStatus( vfResourceStruct.getNotification().getDistributionID(), MSO); @@ -637,7 +646,8 @@ public class ToscaResourceInstaller { } protected ConfigurationResourceCustomization getConfigurationResourceCustomization(NodeTemplate nodeTemplate, - ToscaResourceStructure toscaResourceStructure, ServiceProxyResourceCustomization spResourceCustomization) { + ToscaResourceStructure toscaResourceStructure, ServiceProxyResourceCustomization spResourceCustomization, + Service service) { Metadata metadata = nodeTemplate.getMetaData(); ConfigurationResource configResource = getConfigurationResource(nodeTemplate); @@ -660,31 +670,15 @@ public class ToscaResourceInstaller { .setServiceProxyResourceCustomizationUUID(spResourceCustomization.getModelCustomizationUUID()); configCustomizationResource.setConfigurationResource(configResource); + configCustomizationResource.setService(service); 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 = @@ -703,8 +697,6 @@ public class ToscaResourceInstaller { for (NodeTemplate spNode : serviceProxyResourceList) { serviceProxy = createServiceProxy(spNode, service, toscaResourceStruct); serviceProxyList.add(serviceProxy); - Optional<ConfigurationResourceCustomization> vnrResourceCustomization = - getVnrNodeTemplate(configurationNodeTemplatesList, toscaResourceStruct, serviceProxy); for (NodeTemplate configNode : configurationNodeTemplatesList) { @@ -712,19 +704,21 @@ public class ToscaResourceInstaller { 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(); + ConfigurationResourceCustomization configurationResource = + createConfiguration(configNode, toscaResourceStruct, serviceProxy, service); + + Optional<ConfigurationResourceCustomization> matchingObject = + configurationResourceList.stream() + .filter(configurationResourceCustomization -> configNode.getMetaData() + .getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID) + .equals(configurationResource.getModelCustomizationUUID())) + .filter(configurationResourceCustomization -> configurationResourceCustomization + .getModelInstanceName() + .equals(configurationResource.getModelInstanceName())) + .findFirst(); if (!matchingObject.isPresent()) { configurationResourceList.add(configurationResource); } - break; } } @@ -737,6 +731,37 @@ public class ToscaResourceInstaller { service.setServiceProxyCustomizations(serviceProxyList); } + /* + * ConfigurationResourceCustomization objects have their IDs auto incremented in the database. Unless we know their + * IDs we cannot possibly associate their related records. So these ConfigResourceCustomizations are persisted first + * and subsequently correlated. + */ + + protected void correlateConfigCustomResources(Service service) { + /* Assuming that we have only one pair of VRF-VNR */ + ConfigurationResourceCustomization vrfConfigCustomResource = null; + ConfigurationResourceCustomization vnrConfigCustomResource = null; + List<ConfigurationResourceCustomization> configCustomList = service.getConfigurationCustomizations(); + for (ConfigurationResourceCustomization configResource : configCustomList) { + String nodeType = configResource.getConfigurationResource().getToscaNodeType(); + if (NODES_VRF_ENTRY.equalsIgnoreCase(nodeType)) { + vrfConfigCustomResource = configResource; + } else if (VLAN_NETWORK_RECEPTOR.equalsIgnoreCase(nodeType)) { + vnrConfigCustomResource = configResource; + } + } + + if (vrfConfigCustomResource != null) { + vrfConfigCustomResource.setConfigResourceCustomization(vnrConfigCustomResource); + configCustomizationRepo.save(vrfConfigCustomResource); + + } + if (vnrConfigCustomResource != null) { + vnrConfigCustomResource.setConfigResourceCustomization(vrfConfigCustomResource); + configCustomizationRepo.save(vnrConfigCustomResource); + } + } + protected void processNetworkCollections(ToscaResourceStructure toscaResourceStruct, Service service) { List<NodeTemplate> networkCollectionList = @@ -960,8 +985,15 @@ public class ToscaResourceInstaller { vnfcInstanceGroupCustomizationRepo.saveAndFlush(vnfcInstanceGroupCustomization); } - - service.getVnfCustomizations().add(vnfResource); + List<String> seqResult = processVNFCGroupSequence(toscaResourceStruct, groupList); + if (!CollectionUtils.isEmpty(seqResult)) { + String resultStr = seqResult.stream().collect(Collectors.joining(",")); + vnfResource.setVnfcInstanceGroupOrder(resultStr); + logger.debug( + "vnfcGroupOrder result for service uuid(" + service.getModelUUID() + ") : " + resultStr); + } + // add this vnfResource with existing vnfResource for this service + addVnfCustomization(service, vnfResource); } else { logger.debug("Notification VF ResourceCustomizationUUID: " + vfNotificationResource.getResourceCustomizationUUID() + " doesn't match " @@ -970,6 +1002,85 @@ public class ToscaResourceInstaller { } } + private List<String> processVNFCGroupSequence(ToscaResourceStructure toscaResourceStructure, + List<Group> groupList) { + if (CollectionUtils.isEmpty(groupList)) { + return Collections.emptyList(); + } + + ISdcCsarHelper iSdcCsarHelper = toscaResourceStructure.getSdcCsarHelper(); + List<String> strSequence = new ArrayList<>(groupList.size()); + List<Group> tempGroupList = new ArrayList<>(groupList.size()); + List<NodeTemplate> nodes = new ArrayList<>(); + tempGroupList.addAll(groupList); + + for (Group group : groupList) { + List<NodeTemplate> nodeList = group.getMemberNodes(); + boolean hasRequirements = false; + for (NodeTemplate node : nodeList) { + RequirementAssignments requirements = iSdcCsarHelper.getRequirementsOf(node); + if (requirements != null && requirements.getAll() != null && !requirements.getAll().isEmpty()) { + hasRequirements = true; + break; + } + } + + if (!hasRequirements) { + strSequence.add(group.getName()); + tempGroupList.remove(group); + nodes.addAll(nodeList); + } + } + + getVNFCGroupSequenceList(strSequence, tempGroupList, nodes, iSdcCsarHelper); + + return strSequence; + + } + + private void getVNFCGroupSequenceList(List<String> strSequence, List<Group> groupList, List<NodeTemplate> nodes, + ISdcCsarHelper iSdcCsarHelper) { + if (CollectionUtils.isEmpty(groupList)) { + return; + } + + List<Group> tempGroupList = new ArrayList<>(); + tempGroupList.addAll(groupList); + + for (Group group : groupList) { + ArrayList<NodeTemplate> members = group.getMemberNodes(); + for (NodeTemplate memberNode : members) { + boolean isAllExists = true; + RequirementAssignments requirements = iSdcCsarHelper.getRequirementsOf(memberNode); + if (requirements == null || requirements.getAll() == null || requirements.getAll().isEmpty()) { + continue; + } + List<RequirementAssignment> rqaList = requirements.getAll(); + for (RequirementAssignment rqa : rqaList) { + String name = rqa.getNodeTemplateName(); + for (NodeTemplate node : nodes) { + if (name.equals(node.getName())) { + break; + } + } + + isAllExists = false; + break; + } + + if (isAllExists) { + strSequence.add(group.getName()); + tempGroupList.remove(group); + nodes.addAll(group.getMemberNodes()); + } + } + + if (tempGroupList.size() != 0 && tempGroupList.size() < groupList.size()) { + getVNFCGroupSequenceList(strSequence, tempGroupList, nodes, iSdcCsarHelper); + } + } + } + public void processWatchdog(String distributionId, String servideUUID, Optional<String> distributionNotification, String consumerId) { WatchdogServiceModVerIdLookup modVerIdLookup = @@ -1229,22 +1340,15 @@ public class ToscaResourceInstaller { protected ConfigurationResourceCustomization createConfiguration(NodeTemplate nodeTemplate, ToscaResourceStructure toscaResourceStructure, ServiceProxyResourceCustomization spResourceCustomization, - Optional<ConfigurationResourceCustomization> vnrResourceCustomization) { + Service service) { - ConfigurationResourceCustomization configCustomizationResource = - getConfigurationResourceCustomization(nodeTemplate, toscaResourceStructure, spResourceCustomization); + ConfigurationResourceCustomization configCustomizationResource = getConfigurationResourceCustomization( + nodeTemplate, toscaResourceStructure, spResourceCustomization, service); 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); @@ -1353,6 +1457,7 @@ public class ToscaResourceInstaller { networkCustomizationRepo.saveAndFlush(networkResourceCustomization); + } else if (networkResourceCustomization == null) { networkResourceCustomization = createNetworkResourceCustomization(networkNodeTemplate, toscaResourceStructure); @@ -1686,12 +1791,37 @@ public class ToscaResourceInstaller { vfcInstanceGroupCustom.setFunction(toscaResourceStructure.getSdcCsarHelper() .getNodeTemplatePropertyLeafValue(vnfcNodeTemplate, getInputName)); vfcInstanceGroupCustom.setInstanceGroup(vfcInstanceGroup); - + createVFCInstanceGroupMembers(vfcInstanceGroupCustom, group); return vfcInstanceGroupCustom; } + private void createVFCInstanceGroupMembers(VnfcInstanceGroupCustomization vfcInstanceGroupCustom, Group group) { + List<NodeTemplate> members = group.getMemberNodes(); + if (!CollectionUtils.isEmpty(members)) { + for (NodeTemplate vfcTemplate : members) { + VnfcCustomization vnfcCustomization = new VnfcCustomization(); + + Metadata metadata = vfcTemplate.getMetaData(); + vnfcCustomization + .setModelCustomizationUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)); + vnfcCustomization.setModelInstanceName(vfcTemplate.getName()); + vnfcCustomization.setModelUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID)); + vnfcCustomization + .setModelInvariantUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)); + vnfcCustomization.setModelVersion(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)); + vnfcCustomization.setModelName(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME)); + vnfcCustomization.setToscaNodeType(testNull(vfcTemplate.getType())); + vnfcCustomization + .setDescription(testNull(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION))); + + // @After vfcInstanceGroupCustom merged + // vfcInstanceGroupCustom.getVnfcCustomizations().add(vnfcCustomization); + } + } + } + protected VfModuleCustomization createVFModuleResource(Group group, NodeTemplate vfTemplate, ToscaResourceStructure toscaResourceStructure, VfResourceStructure vfResourceStructure, IVfModuleData vfModuleData, VnfResourceCustomization vnfResource, Service service, @@ -2123,19 +2253,24 @@ public class ToscaResourceInstaller { } protected VnfResourceCustomization createVnfResource(NodeTemplate vfNodeTemplate, - ToscaResourceStructure toscaResourceStructure, Service service) { + ToscaResourceStructure toscaResourceStructure, Service service) throws ArtifactInstallerException { VnfResourceCustomization vnfResourceCustomization = null; if (vnfResourceCustomization == null) { VnfResource vnfResource = findExistingVnfResource(service, vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)); - if (vnfResource == null) + if (vnfResource == null) { vnfResource = createVnfResource(vfNodeTemplate); + } vnfResourceCustomization = createVnfResourceCustomization(vfNodeTemplate, toscaResourceStructure, vnfResource); vnfResourceCustomization.setVnfResources(vnfResource); vnfResourceCustomization.setService(service); + + // setting resource input for vnf customization + vnfResourceCustomization.setResourceInput( + getResourceInput(toscaResourceStructure, vnfResourceCustomization.getModelCustomizationUUID())); vnfResource.getVnfResourceCustomizations().add(vnfResourceCustomization); } @@ -2206,6 +2341,13 @@ public class ToscaResourceInstaller { } + if (vnfResourceCustomization.getMinInstances() == null && vnfResourceCustomization.getMaxInstances() == null) { + vnfResourceCustomization.setMinInstances(Integer.getInteger(toscaResourceStructure.getSdcCsarHelper() + .getNodeTemplatePropertyLeafValue(vfNodeTemplate, SdcPropertyNames.PROPERTY_NAME_MININSTANCES))); + vnfResourceCustomization.setMaxInstances(Integer.getInteger(toscaResourceStructure.getSdcCsarHelper() + .getNodeTemplatePropertyLeafValue(vfNodeTemplate, SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES))); + } + toscaResourceStructure.setCatalogVnfResourceCustomization(vnfResourceCustomization); return vnfResourceCustomization; @@ -2418,6 +2560,19 @@ public class ToscaResourceInstaller { return inputName; } + // this method add provided vnfCustomization to service with + // existing customization available in db. + private void addVnfCustomization(Service service, VnfResourceCustomization vnfResourceCustomization) { + List<Service> services = serviceRepo.findByModelUUID(service.getModelUUID()); + if (services.size() > 0) { + // service exist in db + Service existingService = services.get(0); + List<VnfResourceCustomization> vnfCustomizations = existingService.getVnfCustomizations(); + vnfCustomizations.forEach(e -> service.getVnfCustomizations().add(e)); + } + service.getVnfCustomizations().add(vnfResourceCustomization); + } + protected static Timestamp getCurrentTimeStamp() { |