From 0bac473ab80a2f64b85df51dbaf432ecde73341e Mon Sep 17 00:00:00 2001 From: Elena Kuleshov Date: Thu, 6 Jun 2019 01:10:32 -0400 Subject: Beans fixes to workflow record creation Changes to enable cascading creates and proper id referencing Issue-ID: SO-1998 Signed-off-by: Kuleshov, Elena Change-Id: I6c08fc22fbbba1d0d2b8dc04e390cd0b3de64327 --- .../so/asdc/installer/bpmn/WorkflowResource.java | 11 ++- .../asdc/installer/bpmn/WorkflowResourceTest.java | 81 ++++++++++++++-------- .../WorkflowBpmn/workflow-distribution.json | 2 +- 3 files changed, 60 insertions(+), 34 deletions(-) (limited to 'asdc-controller/src') 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 index daeda2f976..a769b6a2e4 100644 --- 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 @@ -122,13 +122,14 @@ public class WorkflowResource { VnfResourceWorkflow vnfResourceWorkflow = new VnfResourceWorkflow(); vnfResourceWorkflow.setVnfResourceModelUUID(vfResourceModelUuid); + vnfResourceWorkflow.setWorkflow(workflow); List vnfResourceWorkflows = new ArrayList(); vnfResourceWorkflows.add(vnfResourceWorkflow); workflow.setVnfResourceWorkflow(vnfResourceWorkflows); List activityNames = getActivityNameList(artifact.getResult()); - List wfss = getWorkflowActivitySpecSequence(activityNames); + List wfss = getWorkflowActivitySpecSequence(activityNames, workflow); workflow.setWorkflowActivitySpecSequence(wfss); workflowRepo.save(workflow); @@ -166,17 +167,21 @@ public class WorkflowResource { return activityNameList; } - protected List getWorkflowActivitySpecSequence(List activityNames) - throws Exception { + protected List getWorkflowActivitySpecSequence(List activityNames, + Workflow workflow) throws Exception { if (activityNames == null || activityNames.size() == 0) { return null; } List workflowActivitySpecs = new ArrayList(); + int seqNo = 1; for (String activityName : activityNames) { ActivitySpec activitySpec = activityRepo.findByName(activityName); if (activitySpec != null) { WorkflowActivitySpecSequence workflowActivitySpec = new WorkflowActivitySpecSequence(); workflowActivitySpec.setActivitySpec(activitySpec); + workflowActivitySpec.setWorkflow(workflow); + workflowActivitySpec.setSeqNo(seqNo); + seqNo++; workflowActivitySpecs.add(workflowActivitySpec); } } diff --git a/asdc-controller/src/test/java/org/onap/so/asdc/installer/bpmn/WorkflowResourceTest.java b/asdc-controller/src/test/java/org/onap/so/asdc/installer/bpmn/WorkflowResourceTest.java index e655245c31..5a736217b7 100644 --- a/asdc-controller/src/test/java/org/onap/so/asdc/installer/bpmn/WorkflowResourceTest.java +++ b/asdc-controller/src/test/java/org/onap/so/asdc/installer/bpmn/WorkflowResourceTest.java @@ -22,45 +22,27 @@ package org.onap.so.asdc.installer.bpmn; -import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import java.io.File; -import java.io.FileInputStream; -import java.io.InputStream; import java.nio.file.Files; -import java.nio.file.Path; import java.nio.file.Paths; +import java.util.ArrayList; import java.util.List; import javax.transaction.Transactional; -import org.apache.commons.io.IOUtils; -import org.apache.http.HttpEntity; -import org.apache.http.HttpResponse; -import org.apache.http.ProtocolVersion; -import org.apache.http.client.HttpClient; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.message.BasicHttpResponse; -import org.apache.http.message.BasicStatusLine; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.onap.sdc.api.notification.IArtifactInfo; +import org.onap.so.asdc.BaseTest; +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.WorkflowRepository; +import org.springframework.beans.factory.annotation.Autowired; -@Transactional -public class WorkflowResourceTest { +public class WorkflowResourceTest extends BaseTest { - private WorkflowResource workflowResource = new WorkflowResource(); + @Autowired + private WorkflowResource workflowResource; - private static final String TEST_CSAR = "src/test/resources/resource-examples/WorkflowBpmn/service-CxSvc-csar.csar"; - private Path tempDirectoryPath; + @Autowired + private WorkflowRepository workflowRepo; @Test public void getActivityNameList_Test() throws Exception { @@ -106,4 +88,43 @@ public class WorkflowResourceTest { assertTrue(workflowVersion == 1.0); } + @Transactional + @Test + public void installWorkflowResource_Test() throws Exception { + Workflow workflow = new Workflow(); + + workflow.setArtifactChecksum("12345"); + workflow.setArtifactName("myTestWorkflow1"); + workflow.setArtifactUUID("a5c59864-8407-4175-8060-de8ff95eab41"); + workflow.setBody("my body"); + workflow.setDescription("testing workflow"); + workflow.setName("myTestWorkflow1"); + workflow.setResourceTarget("vnf"); + workflow.setSource("sdc"); + workflow.setTimeoutMinutes(5000); + workflow.setOperationName("myTestWorkflow"); + workflow.setVersion(1.0); + + VnfResourceWorkflow vnfResourceWorkflow = new VnfResourceWorkflow(); + vnfResourceWorkflow.setVnfResourceModelUUID("ff2ae348-214a-11e7-93ae-92361f002671"); + + vnfResourceWorkflow.setWorkflow(workflow); + List vnfResourceWorkflows = new ArrayList(); + vnfResourceWorkflows.add(vnfResourceWorkflow); + + workflow.setVnfResourceWorkflow(vnfResourceWorkflows); + + WorkflowActivitySpecSequence wfss1 = new WorkflowActivitySpecSequence(); + wfss1.setActivitySpecId(1); + wfss1.setWorkflow(workflow); + wfss1.setSeqNo(1); + + List wfss = new ArrayList(); + wfss.add(wfss1); + workflow.setWorkflowActivitySpecSequence(wfss); + + workflowRepo.save(workflow); + + } + } diff --git a/asdc-controller/src/test/resources/resource-examples/WorkflowBpmn/workflow-distribution.json b/asdc-controller/src/test/resources/resource-examples/WorkflowBpmn/workflow-distribution.json index 9f49be5bbb..85a73aa239 100644 --- a/asdc-controller/src/test/resources/resource-examples/WorkflowBpmn/workflow-distribution.json +++ b/asdc-controller/src/test/resources/resource-examples/WorkflowBpmn/workflow-distribution.json @@ -11,7 +11,7 @@ "resourceName": "TestVF", "resourceVersion": "1.0", "resoucreType": "VF", - "resourceUUID": "5185253e-4bef-4eb4-bbf9-8c328c787ebd", + "resourceUUID": "ff2ae348-214a-11e7-93ae-92361f002671", "resourceInvariantUUID": "ea8264db-3e24-4324-87cc-12c6903ed43d", "resourceCustomizationUUID": "a959a3cb-4988-435c-9cb7-5a40ef2ef2ac", "category": "Allotted Resource", -- cgit 1.2.3-korg From ac2b66be54faa91e6269e2ca4d2b5c08e8273feb Mon Sep 17 00:00:00 2001 From: Elena Kuleshov Date: Mon, 24 Jun 2019 14:05:26 -0400 Subject: Process workflow artifacts last Workflow artifacts need to be processed last, check for existence of VNF resource Issue-ID: SO-2045 Signed-off-by: Kuleshov, Elena Change-Id: Ia46a6ecaef905287ce837c04b389ab2a13d3f24e --- .../so/asdc/installer/bpmn/WorkflowResource.java | 36 ++++++++++++++++------ .../installer/heat/ToscaResourceInstaller.java | 3 +- 2 files changed, 28 insertions(+), 11 deletions(-) (limited to 'asdc-controller/src') 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 index a769b6a2e4..b3c7776c9a 100644 --- 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 @@ -32,16 +32,19 @@ 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.VnfResource; 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.VnfResourceRepository; 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.http.HttpStatus; import org.springframework.stereotype.Component; @Component @@ -59,21 +62,34 @@ public class WorkflowResource { @Autowired protected ActivitySpecRepository activityRepo; + @Autowired + protected VnfResourceRepository vnfResourceRepo; + @Autowired private BpmnInstaller bpmnInstaller; public void processWorkflows(VfResourceStructure vfResourceStructure) throws Exception { Map 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()); + if (artifactsMapByUUID != null && !artifactsMapByUUID.isEmpty()) { + String vfResourceModelUuid = vfResourceStructure.getResourceInstance().getResourceUUID(); + VnfResource vnfResource = vnfResourceRepo.findResourceByModelUUID(vfResourceModelUuid); + if (vnfResource == null) { + logger.debug("Failed deploying BPMN for vfResourceModelUUID {}", vfResourceModelUuid); + logger.error("{} {} {} {} {} {}", MessageEnum.ASDC_ARTIFACT_NOT_DEPLOYED_DETAIL.toString(), + vfResourceModelUuid, vfResourceModelUuid, HttpStatus.NOT_FOUND, ErrorCode.DataError.getValue(), + "ASDC BPMN deploy failed"); + throw (new Exception("VF Resource not present in Catalog DB: " + vfResourceModelUuid)); + } + 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()); + } } } } 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 6f0d2d7180..ca5cdf4fde 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 @@ -442,7 +442,6 @@ public class ToscaResourceInstaller { vfCustomizationCategory); } - workflowResource.processWorkflows(vfResourceStructure); processResourceSequence(toscaResourceStruct, service); List allottedResourceList = toscaResourceStruct.getSdcCsarHelper().getAllottedResources(); processAllottedResources(toscaResourceStruct, service, allottedResourceList); @@ -456,6 +455,8 @@ public class ToscaResourceInstaller { service = serviceRepo.save(service); correlateConfigCustomResources(service); + workflowResource.processWorkflows(vfResourceStructure); + WatchdogComponentDistributionStatus status = new WatchdogComponentDistributionStatus( vfResourceStruct.getNotification().getDistributionID(), MSO); status.setComponentDistributionStatus(DistributionStatusEnum.COMPONENT_DONE_OK.name()); -- cgit 1.2.3-korg