diff options
Diffstat (limited to 'bpmn')
5 files changed, 80 insertions, 238 deletions
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetup.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetup.java index 009686d0fc..a371839244 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetup.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetup.java @@ -1852,8 +1852,9 @@ public class BBInputSetup implements JavaDelegate { } private void mapRelationship(ServiceInstance serviceInstance, Relationships relationships) { - this.mapProject(relationships.getByType(AAIObjectType.PROJECT), serviceInstance); - this.mapOwningEntity(relationships.getByType(AAIObjectType.OWNING_ENTITY), serviceInstance); + this.mapProject(relationships.getByType(AAIObjectType.PROJECT, uri -> uri.nodesOnly(true)), serviceInstance); + this.mapOwningEntity(relationships.getByType(AAIObjectType.OWNING_ENTITY, uri -> uri.nodesOnly(true)), + serviceInstance); this.mapL3Networks(relationships.getRelatedAAIUris(AAIObjectType.L3_NETWORK), serviceInstance.getNetworks()); this.mapGenericVnfs(relationships.getRelatedAAIUris(AAIObjectType.GENERIC_VNF), serviceInstance.getVnfs()); this.mapPnfs(relationships.getRelatedAAIUris(AAIObjectType.PNF), serviceInstance.getPnfs()); diff --git a/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/common/workflow/service/AutoProcessInstanceMigrationService.java b/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/common/workflow/service/AutoProcessInstanceMigrationService.java deleted file mode 100644 index 58d0c6d374..0000000000 --- a/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/common/workflow/service/AutoProcessInstanceMigrationService.java +++ /dev/null @@ -1,111 +0,0 @@ -package org.onap.so.bpmn.common.workflow.service; - -import java.util.ArrayList; -import java.util.List; -import org.camunda.bpm.engine.ProcessEngine; -import org.camunda.bpm.engine.RepositoryService; -import org.camunda.bpm.engine.RuntimeService; -import org.camunda.bpm.engine.migration.MigrationInstruction; -import org.camunda.bpm.engine.migration.MigrationPlan; -import org.camunda.bpm.engine.migration.MigrationPlanExecutionBuilder; -import org.camunda.bpm.engine.repository.ProcessDefinition; -import org.camunda.bpm.engine.runtime.ProcessInstance; -import org.camunda.bpm.engine.runtime.ProcessInstanceQuery; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.context.event.ApplicationReadyEvent; -import org.springframework.context.event.EventListener; -import org.springframework.core.env.Environment; -import org.springframework.stereotype.Service; - -@Service -public class AutoProcessInstanceMigrationService { - - private static Logger logger = LoggerFactory.getLogger(AutoProcessInstanceMigrationService.class); - - @Autowired - private Environment env; - @Autowired - protected ProcessEngine processEngine; - - @Value("${migration.autoMigrationEnabled:false}") - private boolean autoMigrationEnabled; - - private RuntimeService runtimeService; - private RepositoryService repositoryService; - private List<String> processDefinitionKeys; - - @EventListener(ApplicationReadyEvent.class) - protected void executeAutoProcessInstanceMigrations() { - if (autoMigrationEnabled) { - runtimeService = processEngine.getRuntimeService(); - repositoryService = processEngine.getRepositoryService(); - for (ProcessDefinition definition : getProcessDefinitions()) { - for (ProcessDefinition procDefOld : getOldProcessDefinitions(definition.getKey(), - definition.getVersion())) { - migrate(procDefOld.getId(), definition.getId()); - } - } - } - } - - protected List<ProcessDefinition> getProcessDefinitions() { - - List<ProcessDefinition> processDefinitions = new ArrayList<ProcessDefinition>(); - processDefinitionKeys = env.getProperty("migration.processDefinitionKeys", List.class, new ArrayList<String>()); - for (String key : processDefinitionKeys) { - processDefinitions.add(repositoryService.createProcessDefinitionQuery().processDefinitionKey(key) - .latestVersion().singleResult()); - } - return processDefinitions; - } - - private void migrate(String sourceProcessDefinitionId, String targetProcessDefinitionId) { - MigrationPlan migrationPlan = - runtimeService.createMigrationPlan(sourceProcessDefinitionId, targetProcessDefinitionId) - .mapEqualActivities().updateEventTriggers().build(); - List<String> activityIds = new ArrayList<>(); - - for (MigrationInstruction instruction : migrationPlan.getInstructions()) { - activityIds.add(instruction.getSourceActivityId()); - } - for (String activityId : activityIds) { - ProcessInstanceQuery activeProcessInstancesQuery = runtimeService.createProcessInstanceQuery() - .processDefinitionId(sourceProcessDefinitionId).activityIdIn(activityId).active(); - if (!activeProcessInstancesQuery.list().isEmpty()) { - logger.info("Migrating {} process instance(s) from {} to {}", - Long.valueOf(activeProcessInstancesQuery.count()), sourceProcessDefinitionId, - targetProcessDefinitionId); - MigrationPlanExecutionBuilder migration = - runtimeService.newMigration(migrationPlan).processInstanceQuery(activeProcessInstancesQuery); - migration.executeAsync(); - } - } - suspendEmptyProcessDefinition(sourceProcessDefinitionId); - } - - private void suspendEmptyProcessDefinition(String sourceProcessDefinitionId) { - List<ProcessInstance> activeProcessInstances = runtimeService.createProcessInstanceQuery() - .processDefinitionId(sourceProcessDefinitionId).active().list(); - if (activeProcessInstances.isEmpty()) { - repositoryService.suspendProcessDefinitionById(sourceProcessDefinitionId); - } else { - logger.info("Unable to migrate {} process instance(s) from {}", - Integer.valueOf(activeProcessInstances.size()), sourceProcessDefinitionId); - } - } - - protected List<ProcessDefinition> getOldProcessDefinitions(String key, int version) { - List<ProcessDefinition> processDefinitions = - repositoryService.createProcessDefinitionQuery().processDefinitionKey(key).list(); - List<ProcessDefinition> oldProcessDefinitions = new ArrayList<>(); - for (ProcessDefinition processDef : processDefinitions) { - if (!processDef.isSuspended() && (processDef.getVersion() != version)) { - oldProcessDefinitions.add(processDef); - } - } - return oldProcessDefinitions; - } -} diff --git a/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/common/workflow/service/AutoProcessInstanceMigrationServiceTest.java b/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/common/workflow/service/AutoProcessInstanceMigrationServiceTest.java deleted file mode 100644 index 36e828448d..0000000000 --- a/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/common/workflow/service/AutoProcessInstanceMigrationServiceTest.java +++ /dev/null @@ -1,124 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2020 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.bpmn.common.workflow.service; - -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.doReturn; -import java.util.ArrayList; -import java.util.List; -import org.camunda.bpm.engine.ProcessEngine; -import org.camunda.bpm.engine.RepositoryService; -import org.camunda.bpm.engine.repository.ProcessDefinition; -import org.camunda.bpm.engine.repository.ProcessDefinitionQuery; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.Spy; -import org.mockito.junit.MockitoJUnitRunner; -import org.springframework.core.env.Environment; - -@RunWith(MockitoJUnitRunner.class) -public class AutoProcessInstanceMigrationServiceTest { - - @Mock - private ProcessEngine processEngine; - - @Mock - private ProcessDefinition outdated; - - @Mock - private ProcessDefinition newDef; - - @Mock - private ProcessDefinition key; - - @Mock - private ProcessDefinition testKey; - - @Mock - private ProcessDefinition suspendedDef; - - @Mock - private RepositoryService repositoryService; - - @Mock - private ProcessDefinitionQuery query; - - @Mock - private ProcessDefinitionQuery keyQuery; - - @Mock - private Environment env; - - @Spy - @InjectMocks - private AutoProcessInstanceMigrationService migrationService; - - - @Test - public void getOldProcessDefinitionsTest() { - List<ProcessDefinition> expectedList = new ArrayList<>(); - expectedList.add(outdated); - - List<ProcessDefinition> defList = new ArrayList<>(); - defList.add(outdated); - defList.add(newDef); - defList.add(suspendedDef); - - - doReturn(query).when(repositoryService).createProcessDefinitionQuery(); - doReturn(query).when(query).processDefinitionKey("test"); - doReturn(defList).when(query).list(); - doReturn(3).when(outdated).getVersion(); - doReturn(4).when(newDef).getVersion(); - doReturn(true).when(suspendedDef).isSuspended(); - List<ProcessDefinition> outdatedList = migrationService.getOldProcessDefinitions("test", 4); - - assertEquals(expectedList, outdatedList); - } - - @Test - public void getProcessDefinitionsTest() { - List<ProcessDefinition> expected = new ArrayList<ProcessDefinition>(); - expected.add(testKey); - expected.add(key); - - List<String> processDefinitionKeys = new ArrayList<String>(); - processDefinitionKeys.add("testKey"); - processDefinitionKeys.add("key"); - - doReturn(processDefinitionKeys).when(env).getProperty("migration.processDefinitionKeys", List.class, - new ArrayList<String>()); - - doReturn(query).when(repositoryService).createProcessDefinitionQuery(); - doReturn(query).when(query).processDefinitionKey("testKey"); - doReturn(query).when(query).latestVersion(); - doReturn(testKey).when(query).singleResult(); - - doReturn(keyQuery).when(query).processDefinitionKey("key"); - doReturn(keyQuery).when(keyQuery).latestVersion(); - doReturn(key).when(keyQuery).singleResult(); - - List<ProcessDefinition> actualProcessDefinitions = migrationService.getProcessDefinitions(); - - assertEquals(expected, actualProcessDefinitions); - } -} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java index feb5444d5b..9b9433afdb 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java @@ -571,6 +571,10 @@ public class WorkflowAction { WorkflowResourceIds workflowIdsCopy = SerializationUtils.clone(dataObj.getWorkflowResourceIds()); org.onap.aai.domain.yang.Configuration configuration = getRelatedResourcesInVnfc(vnfc, org.onap.aai.domain.yang.Configuration.class, AAIObjectType.CONFIGURATION); + if (configuration == null) { + logger.warn(String.format("No configuration found for VNFC %s in AAI", vnfc.getVnfcName())); + continue; + } workflowIdsCopy.setConfigurationId(configuration.getConfigurationId()); for (OrchestrationFlow orchFlow : result) { dataObj.getResourceKey().setVfModuleCustomizationId(vfModuleCustomizationUUID); @@ -587,7 +591,6 @@ public class WorkflowAction { dataObj.getRequestAction(), dataObj.isaLaCarte(), dataObj.getVnfType(), workflowIdsCopy, dataObj.getRequestDetails(), false, null, vnfcName, true, null); flowsToExecuteConfigs.add(ebb); - } } return flowsToExecuteConfigs; diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java index 407a844c4e..c1970ec32c 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java @@ -1601,6 +1601,79 @@ public class WorkflowActionTest extends BaseTaskTest { } @Test + public void getConfigBuildingBlocksNullConfigurationTest() throws Exception { + String gAction = "deleteInstance"; + ObjectMapper mapper = new ObjectMapper(); + mapper.disable(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES); + + WorkflowType resourceType = WorkflowType.VFMODULE; + execution.setVariable("mso-request-id", "00f704ca-c5e5-4f95-a72c-6889db7b0688"); + execution.setVariable("requestAction", gAction); + String bpmnRequest = + new String(Files.readAllBytes(Paths.get("src/test/resources/__files/VfModuleCreateWithFabric.json"))); + execution.setVariable("bpmnRequest", bpmnRequest); + execution.setVariable("vnfId", "1234"); + execution.setVariable("vfModuleId", "vfModuleId1234"); + execution.setVariable("requestUri", + "v7/serviceInstances/f647e3ef-6d2e-4cd3-bff4-8df4634208de/vnfs/b80b16a5-f80d-4ffa-91c8-bd47c7438a3d/vfModules"); + ServiceInstancesRequest sIRequest = mapper.readValue(bpmnRequest, ServiceInstancesRequest.class); + RequestDetails requestDetails = sIRequest.getRequestDetails(); + String requestAction = "deleteInstance"; + String requestId = "9c944122-d161-4280-8594-48c06a9d96d5"; + boolean aLaCarte = true; + String apiVersion = "7"; + String vnfType = "vnfType"; + String key = "00d15ebb-c80e-43c1-80f0-90c40dde70b0"; + String resourceId = "d1d35800-783d-42d3-82f6-d654c5054a6e"; + Resource resourceKey = new Resource(resourceType, key, aLaCarte); + WorkflowResourceIds workflowResourceIds = SPY_workflowAction.populateResourceIdsFromApiHandler(execution); + + List<OrchestrationFlow> orchFlows = createFlowList("DeactivateVfModuleBB", "DeleteVfModuleBB", + "UnassignVfModuleBB", "DeleteFabricConfigurationBB"); + + ConfigBuildingBlocksDataObject dataObj = new ConfigBuildingBlocksDataObject().setsIRequest(sIRequest) + .setOrchFlows(orchFlows).setRequestId(requestId).setResourceKey(resourceKey).setApiVersion(apiVersion) + .setResourceId(resourceId).setRequestAction(requestAction).setaLaCarte(aLaCarte).setVnfType(vnfType) + .setWorkflowResourceIds(workflowResourceIds).setRequestDetails(requestDetails).setExecution(execution); + + org.onap.aai.domain.yang.GenericVnf vnf = new org.onap.aai.domain.yang.GenericVnf(); + vnf.setVnfId("vnf0"); + vnf.setModelCustomizationId("modelCustomizationId"); + when(bbSetupUtils.getAAIGenericVnf(any())).thenReturn(vnf); + + org.onap.aai.domain.yang.VfModule vfModule = new org.onap.aai.domain.yang.VfModule(); + vfModule.setModelCustomizationId("modelCustomizationId"); + + /* this is a test case where configuration for vnfc is null */ + org.onap.aai.domain.yang.Configuration config1 = null; + org.onap.aai.domain.yang.Configuration config2 = new org.onap.aai.domain.yang.Configuration(); + config2.setConfigurationId("config2"); + + List<org.onap.aai.domain.yang.Vnfc> vnfcs = new ArrayList<org.onap.aai.domain.yang.Vnfc>(); + org.onap.aai.domain.yang.Vnfc vnfc1 = new org.onap.aai.domain.yang.Vnfc(); + vnfc1.setVnfcName("zauk53avetd02svm001"); + org.onap.aai.domain.yang.Vnfc vnfc2 = new org.onap.aai.domain.yang.Vnfc(); + vnfc2.setVnfcName("zauk53avetd02tvm001"); + vnfcs.add(vnfc1); + vnfcs.add(vnfc2); + + when(bbSetupUtils.getAAIVfModule(any(), any())).thenReturn(vfModule); + doReturn(vnfcs).when(SPY_workflowAction).getRelatedResourcesInVfModule(any(), any(), + eq(org.onap.aai.domain.yang.Vnfc.class), eq(AAIObjectType.VNFC)); + doReturn(config1).when(SPY_workflowAction).getRelatedResourcesInVnfc(eq(vnfc1), + eq(org.onap.aai.domain.yang.Configuration.class), eq(AAIObjectType.CONFIGURATION)); + doReturn(config2).when(SPY_workflowAction).getRelatedResourcesInVnfc(eq(vnfc2), + eq(org.onap.aai.domain.yang.Configuration.class), eq(AAIObjectType.CONFIGURATION)); + + List<ExecuteBuildingBlock> results = SPY_workflowAction.getConfigBuildingBlocks(dataObj); + + assertFalse(results.isEmpty()); + assertEquals(1, results.size()); + assertEquals("config2", results.get(0).getWorkflowResourceIds().getConfigurationId()); + assertEquals("zauk53avetd02tvm001", results.get(0).getConfigurationResourceKeys().getVnfcName()); + } + + @Test public void selectExecutionListALaCarteVfModuleNoFabricDeleteTest() throws Exception { String gAction = "deleteInstance"; String resource = "VfModule"; |