diff options
Diffstat (limited to 'bpmn/so-bpmn-tasks')
5 files changed, 371 insertions, 2 deletions
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIFlagTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIFlagTasks.java index 1add5e6d24..997d20036f 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIFlagTasks.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIFlagTasks.java @@ -35,6 +35,8 @@ import org.springframework.stereotype.Component; @Component public class AAIFlagTasks { + private static final Logger logger = LoggerFactory.getLogger(AAIFlagTasks.class); + @Autowired private AAIVnfResources aaiVnfResources; @@ -107,7 +109,7 @@ public class AAIFlagTasks { String vnfId = vnf.getVnfId(); inPserversLocked = aaiVnfResources.checkVnfPserversLockedFlag(vnfId); } catch (Exception ex) { - exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); + logger.warn("Exception on checking pservers: " + ex.getMessage()); } if (inPserversLocked) { exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "VNF PServers in Locked in A&AI"); diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/appc/tasks/AppcOrchestratorPreProcessor.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/appc/tasks/AppcOrchestratorPreProcessor.java new file mode 100644 index 0000000000..4b967c7bc4 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/appc/tasks/AppcOrchestratorPreProcessor.java @@ -0,0 +1,189 @@ +package org.onap.so.bpmn.infrastructure.appc.tasks; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import org.onap.aai.domain.yang.Vserver; +import org.onap.appc.client.lcm.model.Action; +import org.onap.so.appc.orchestrator.service.beans.ApplicationControllerTaskRequest; +import org.onap.so.appc.orchestrator.service.beans.ApplicationControllerVm; +import org.onap.so.appc.orchestrator.service.beans.ApplicationControllerVnf; +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.core.json.JsonUtils; +import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; +import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; +import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock; +import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; +import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; +import org.onap.so.client.aai.AAIObjectType; +import org.onap.so.client.aai.entities.AAIResultWrapper; +import org.onap.so.client.aai.entities.Relationships; +import org.onap.so.client.aai.entities.uri.AAIResourceUri; +import org.onap.so.client.exception.BBObjectNotFoundException; +import org.onap.so.client.exception.ExceptionBuilder; +import org.onap.so.client.orchestration.AAIVnfResources; +import org.onap.so.db.catalog.beans.ControllerSelectionReference; +import org.onap.so.db.catalog.client.CatalogDbClient; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class AppcOrchestratorPreProcessor { + private static final Logger logger = LoggerFactory.getLogger(AppcOrchestratorPreProcessor.class); + public static final String CONTROLLER_TYPE_DEFAULT = "APPC"; + + @Autowired + private ExceptionBuilder exceptionUtil; + @Autowired + private ExtractPojosForBB extractPojosForBB; + @Autowired + private CatalogDbClient catalogDbClient; + @Autowired + private AAIVnfResources aaiVnfResources; + + public void buildAppcTaskRequest(BuildingBlockExecution execution, String actionName) { + try { + Action action = Action.valueOf(actionName); + ApplicationControllerTaskRequest appcTaskRequest = new ApplicationControllerTaskRequest(); + appcTaskRequest.setAction(action); + GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock(); + GenericVnf vnf = null; + try { + vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID); + } catch (BBObjectNotFoundException e) { + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "No valid VNF exists"); + } + String vnfId = null; + String vnfName = null; + String vnfType = null; + String vnfHostIpAddress = null; + + if (vnf != null) { + vnfId = vnf.getVnfId(); + vnfName = vnf.getVnfName(); + vnfType = vnf.getVnfType(); + vnfHostIpAddress = vnf.getIpv4OamAddress(); + } + String msoRequestId = gBBInput.getRequestContext().getMsoRequestId(); + + String aicIdentity = execution.getVariable("aicIdentity"); + String identityUrl = execution.getVariable("identityUrl"); + appcTaskRequest.setIdentityUrl(identityUrl); + + if (gBBInput.getRequestContext().getRequestParameters() != null) { + String payload = gBBInput.getRequestContext().getRequestParameters().getPayload(); + if (payload == null) { + payload = ""; + } + String existingSoftwareVersion = JsonUtils.getJsonValue(payload, "existing-software-version"); + appcTaskRequest.setExistingSoftwareVersion(existingSoftwareVersion); + String newSoftwareVersion = JsonUtils.getJsonValue(payload, "new-software-version"); + appcTaskRequest.setNewSoftwareVersion(newSoftwareVersion); + String operationsTimeout = JsonUtils.getJsonValue(payload, "operations-timeout"); + appcTaskRequest.setOperationsTimeout(operationsTimeout); + } + + ControllerSelectionReference controllerSelectionReference = catalogDbClient + .getControllerSelectionReferenceByVnfTypeAndActionCategory(vnfType, action.toString()); + String controllerType = null; + if (controllerSelectionReference != null) { + controllerType = controllerSelectionReference.getControllerName(); + } else { + controllerType = CONTROLLER_TYPE_DEFAULT; + } + appcTaskRequest.setControllerType(controllerType); + + execution.setVariable("vmIdList", null); + execution.setVariable("vserverIdList", null); + execution.setVariable("vmIndex", 0); + execution.setVariable("vmIdListSize", 0); + + String vfModuleId = null; + VfModule vfModule = null; + try { + vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID); + } catch (BBObjectNotFoundException e) { + } + if (vfModule != null) { + vfModuleId = vfModule.getVfModuleId(); + } + if (action.equals(Action.Snapshot)) { + try { + getVserversForAppc(execution, vnf); + } catch (Exception e) { + logger.warn("Unable to retrieve vservers for vnf: " + vnfId); + } + } + + ApplicationControllerVnf applicationControllerVnf = new ApplicationControllerVnf(); + applicationControllerVnf.setVnfHostIpAddress(vnfHostIpAddress); + applicationControllerVnf.setVnfId(vnfId); + applicationControllerVnf.setVnfName(vnfName); + appcTaskRequest.setApplicationControllerVnf(applicationControllerVnf); + + execution.setVariable("appcOrchestratorRequest", appcTaskRequest); + } catch (Exception e) { + logger.error("Error building ApplicationControllerTaskRequest Object", e); + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, e); + } + } + + public void addVmInfoToAppcTaskRequest(BuildingBlockExecution execution) { + try { + ApplicationControllerTaskRequest appcTaskRequest = + (ApplicationControllerTaskRequest) execution.getVariable("appcOrchestratorRequest"); + ArrayList<String> vmIdList = execution.getVariable("vmIdList"); + ArrayList<String> vserverIdList = execution.getVariable("vserverIdList"); + Integer vmIndex = (Integer) execution.getVariable("vmIndex"); + + if (vmIdList != null && !vmIdList.isEmpty() && vserverIdList != null && !vserverIdList.isEmpty()) { + execution.setVariable("vmIdListSize", vmIdList.size()); + if (vmIndex < vmIdList.size()) { + ApplicationControllerVm applicationControllerVm = new ApplicationControllerVm(); + applicationControllerVm.setVmId(vmIdList.get(vmIndex)); + applicationControllerVm.setVserverId(vserverIdList.get(vmIndex)); + if (appcTaskRequest.getApplicationControllerVnf() == null) { + ApplicationControllerVnf applicationControllerVnf = new ApplicationControllerVnf(); + appcTaskRequest.setApplicationControllerVnf(applicationControllerVnf); + } + appcTaskRequest.getApplicationControllerVnf().setApplicationControllerVm(applicationControllerVm); + execution.setVariable("appcOrchestratorRequest", appcTaskRequest); + vmIndex++; + execution.setVariable("vmIndex", vmIndex); + } + } + } catch (Exception e) { + logger.error("Error adding VM info to ApplicationControllerTaskRequest Object", e); + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, e); + } + } + + protected void getVserversForAppc(BuildingBlockExecution execution, GenericVnf vnf) throws Exception { + AAIResultWrapper aaiRW = aaiVnfResources.queryVnfWrapperById(vnf); + + if (aaiRW != null && aaiRW.getRelationships().isPresent()) { + Relationships relationships = aaiRW.getRelationships().get(); + if (relationships != null) { + List<AAIResourceUri> vserverUris = relationships.getRelatedAAIUris(AAIObjectType.VSERVER); + ArrayList<String> vserverIds = new ArrayList<String>(); + ArrayList<String> vserverSelfLinks = new ArrayList<String>(); + for (AAIResourceUri j : vserverUris) { + String vserverId = j.getURIKeys().get("vserver-id"); + vserverIds.add(vserverId); + Optional<Vserver> oVserver = aaiVnfResources.getVserver(j); + if (oVserver.isPresent()) { + Vserver vserver = oVserver.get(); + String vserverSelfLink = vserver.getVserverSelflink(); + vserverSelfLinks.add(vserverSelfLink); + } + } + logger.debug("vmIdsArray is: {}", vserverSelfLinks); + logger.debug("vserverIdsArray is: {}", vserverIds); + execution.setVariable("vmIdList", vserverSelfLinks); + execution.setVariable("vserverIdList", vserverIds); + } + } + } +} 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 99ba35232c..356fe8d9a2 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 @@ -1555,7 +1555,7 @@ public class WorkflowAction { if (flows == null) flows = new ArrayList<>(); for (OrchestrationFlow flow : flows) { - if (!flow.getFlowName().contains("BB")) { + if (!flow.getFlowName().contains("BB") && !flow.getFlowName().contains("Activity")) { List<OrchestrationFlow> macroQueryFlows = catalogDbClient.getOrchestrationFlowByAction(flow.getFlowName()); for (OrchestrationFlow macroFlow : macroQueryFlows) { diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/appc/tasks/AppcOrchestratorPreProcessorTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/appc/tasks/AppcOrchestratorPreProcessorTest.java new file mode 100644 index 0000000000..c78b652bd0 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/appc/tasks/AppcOrchestratorPreProcessorTest.java @@ -0,0 +1,166 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2018 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.bpmn.infrastructure.appc.tasks; + +import static com.shazam.shazamcrest.MatcherAssert.assertThat; +import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.when; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Optional; +import org.junit.Test; +import org.mockito.ArgumentMatchers; +import org.mockito.InjectMocks; +import org.onap.aai.domain.yang.Vserver; +import org.onap.appc.client.lcm.model.Action; +import org.onap.so.appc.orchestrator.service.beans.ApplicationControllerTaskRequest; +import org.onap.so.appc.orchestrator.service.beans.ApplicationControllerVnf; +import org.onap.so.bpmn.BaseTaskTest; +import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; +import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; +import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; +import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; +import org.onap.so.client.aai.entities.AAIResultWrapper; +import org.onap.so.client.aai.entities.uri.AAIResourceUri; +import org.onap.so.client.policy.JettisonStyleMapperProvider; +import org.onap.so.db.catalog.beans.ControllerSelectionReference; +import com.fasterxml.jackson.databind.ObjectMapper; + +public class AppcOrchestratorPreProcessorTest extends BaseTaskTest { + + private final static String JSON_FILE_LOCATION = "src/test/resources/__files/BuildingBlocks/"; + + @InjectMocks + private AppcOrchestratorPreProcessor appcOrchestratorPreProcessor = new AppcOrchestratorPreProcessor(); + + private ObjectMapper mapper = new JettisonStyleMapperProvider().getMapper(); + + @Test + public void buildAppcTaskRequestTest() throws Exception { + final String expectedRequestJson = + new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "appcTaskRequest.json"))); + ApplicationControllerTaskRequest expectedTaskRequest = + mapper.readValue(expectedRequestJson, ApplicationControllerTaskRequest.class); + execution.getLookupMap().put(ResourceKey.GENERIC_VNF_ID, "-TEST"); + fillRequiredAppcExecutionFields(); + GenericVnf genericVnf = getTestGenericVnf(); + when(extractPojosForBB.extractByKey(eq(execution), eq(ResourceKey.GENERIC_VNF_ID))).thenReturn(genericVnf); + mockReferenceResponse(); + execution.getLookupMap().put(ResourceKey.VF_MODULE_ID, "VF-MODULE-ID-TEST"); + VfModule vfModule = new VfModule(); + vfModule.setVfModuleId("VF-MODULE-ID"); + when(extractPojosForBB.extractByKey(eq(execution), eq(ResourceKey.VF_MODULE_ID))).thenReturn(vfModule); + appcOrchestratorPreProcessor.buildAppcTaskRequest(execution, "Lock"); + ApplicationControllerTaskRequest actualTaskRequest = execution.getVariable("appcOrchestratorRequest"); + assertThat(actualTaskRequest, sameBeanAs(expectedTaskRequest)); + } + + @Test + public void getVserversForAppcTest() throws Exception { + + GenericVnf genericVnf = getTestGenericVnf(); + + final String aaiVnfJson = + new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "aaiGenericVnfWithVservers.json"))); + final String aaiVserverJson = + new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "aaiVserverQueryResponse.json"))); + AAIResultWrapper aaiResultWrapper = new AAIResultWrapper(aaiVnfJson); + ObjectMapper mapper = new ObjectMapper(); + Vserver vserver = mapper.readValue(aaiVserverJson, Vserver.class); + doReturn(aaiResultWrapper).when(aaiVnfResources).queryVnfWrapperById(genericVnf); + doReturn(Optional.of(vserver)).when(aaiVnfResources).getVserver(ArgumentMatchers.any(AAIResourceUri.class)); + appcOrchestratorPreProcessor.getVserversForAppc(execution, genericVnf); + ArrayList<String> vserverIdList = execution.getVariable("vserverIdList"); + ArrayList<String> expectedVserverIdList = new ArrayList<String>(); + expectedVserverIdList.add("1b3f44e5-d96d-4aac-bd9a-310e8cfb0af5"); + expectedVserverIdList.add("14551849-1e70-45cd-bc5d-a256d49548a2"); + expectedVserverIdList.add("48bd7f11-408f-417c-b834-b41c1b98f7d7"); + ArrayList<String> vmIdList = execution.getVariable("vmIdList"); + ArrayList<String> expectedVmIdList = new ArrayList<String>(); + expectedVmIdList.add("http://VSERVER-link.com"); + expectedVmIdList.add("http://VSERVER-link.com"); + expectedVmIdList.add("http://VSERVER-link.com"); + assertEquals(vserverIdList, expectedVserverIdList); + assertEquals(vmIdList, expectedVmIdList); + } + + @Test + public void addVmInfoToAppcTaskRequestTest() throws Exception { + ApplicationControllerTaskRequest appcTaskRequest = new ApplicationControllerTaskRequest(); + ApplicationControllerVnf applicationControllerVnf = new ApplicationControllerVnf(); + appcTaskRequest.setApplicationControllerVnf(applicationControllerVnf); + execution.setVariable("appcOrchestratorRequest", appcTaskRequest); + ArrayList<String> vmIdList = new ArrayList<String>(); + vmIdList.add("http://VSERVER-link.com"); + vmIdList.add("http://VSERVER-link.com"); + vmIdList.add("http://VSERVER-link.com"); + execution.setVariable("vmIdList", vmIdList); + ArrayList<String> vserverIdList = new ArrayList<String>(); + vserverIdList.add("1b3f44e5-d96d-4aac-bd9a-310e8cfb0af5"); + vserverIdList.add("14551849-1e70-45cd-bc5d-a256d49548a2"); + vserverIdList.add("48bd7f11-408f-417c-b834-b41c1b98f7d7"); + execution.setVariable("vserverIdList", vserverIdList); + execution.setVariable("vmIndex", 1); + appcOrchestratorPreProcessor.addVmInfoToAppcTaskRequest(execution); + Integer nextVmIndex = execution.getVariable("vmIndex"); + assertThat(nextVmIndex == 2); + Integer vmIdListSize = execution.getVariable("vmIdListSize"); + assertThat(vmIdListSize == 3); + appcTaskRequest = execution.getVariable("appcOrchestratorRequest"); + assertEquals(appcTaskRequest.getApplicationControllerVnf().getApplicationControllerVm().getVserverId(), + "14551849-1e70-45cd-bc5d-a256d49548a2"); + assertEquals(appcTaskRequest.getApplicationControllerVnf().getApplicationControllerVm().getVmId(), + "http://VSERVER-link.com"); + } + + private void mockReferenceResponse() { + ControllerSelectionReference reference = new ControllerSelectionReference(); + reference.setControllerName("TEST-CONTROLLER-NAME"); + when(catalogDbClient.getControllerSelectionReferenceByVnfTypeAndActionCategory(eq("TEST-VNF-TYPE"), + eq(Action.Lock.toString()))).thenReturn(reference); + } + + private void fillRequiredAppcExecutionFields() { + RequestContext context = new RequestContext(); + context.setMsoRequestId("TEST-MSO-ID"); + execution.setVariable("aicIdentity", "AIC-TEST"); + execution.setVariable("vmIdList", "VM-ID-LIST-TEST"); + execution.setVariable("vserverIdList", "VSERVER-ID-LIST"); + execution.setVariable("identityUrl", "IDENTITY-URL-TEST"); + execution.getGeneralBuildingBlock().setRequestContext(context); + } + + private GenericVnf getTestGenericVnf() { + GenericVnf genericVnf = new GenericVnf(); + genericVnf.setVnfId("TEST-VNF-ID"); + genericVnf.setVnfType("TEST-VNF-TYPE"); + genericVnf.setVnfName("TEST-VNF-NAME"); + genericVnf.setIpv4OamAddress("127.0.0.1"); + return genericVnf; + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/appcTaskRequest.json b/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/appcTaskRequest.json new file mode 100644 index 0000000000..957c603dc9 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/appcTaskRequest.json @@ -0,0 +1,12 @@ +{ + "ApplicationControllerTaskRequest": { + "controllerType": "TEST-CONTROLLER-NAME", + "action": "Lock", + "identityUrl": "IDENTITY-URL-TEST", + "applicationControllerVnf": { + "vnfId": "TEST-VNF-ID", + "vnfName": "TEST-VNF-NAME", + "vnfHostIpAddress": "127.0.0.1" + } + } +}
\ No newline at end of file |