From 3cea07cfa59720df58e85f25081a5e8ff8d004cf Mon Sep 17 00:00:00 2001 From: "Brittany Plummer (bp896r)" Date: Tue, 28 Aug 2018 15:58:07 -0400 Subject: Added GenericVnfHealthCheckBB, tasks, and tests Issue-ID: SO-777 Change-Id: I8a46f1802feb18ab4df098472fef5373ac42208b Signed-off-by: Brittany Plummer (bp896r) --- .../client/appc/ApplicationControllerAction.java | 3 +- .../BuildingBlock/GenericVnfHealthCheckBB.bpmn | 56 +++++++++++ .../test/java/org/onap/so/bpmn/BaseBPMNTest.java | 4 + .../subprocess/GenericVnfHealthCheckBBTest.java | 41 ++++++++ .../src/test/resources/application-test.yaml | 3 + .../flowspecific/tasks/GenericVnfHealthCheck.java | 103 +++++++++++++++++++++ .../test/java/org/onap/so/bpmn/BaseTaskTest.java | 4 + .../tasks/GenericVnfHealthCheckTest.java | 101 ++++++++++++++++++++ 8 files changed, 314 insertions(+), 1 deletion(-) create mode 100644 bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/GenericVnfHealthCheckBB.bpmn create mode 100644 bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/infrastructure/bpmn/subprocess/GenericVnfHealthCheckBBTest.java create mode 100644 bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericVnfHealthCheck.java create mode 100644 bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericVnfHealthCheckTest.java (limited to 'bpmn') diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/appc/ApplicationControllerAction.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/appc/ApplicationControllerAction.java index 9feee14640..8fae2816b2 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/appc/ApplicationControllerAction.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/appc/ApplicationControllerAction.java @@ -31,12 +31,13 @@ import org.onap.so.bpmn.core.json.JsonUtils; import org.onap.so.client.appc.ApplicationControllerSupport.StatusCategory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; - +@Component public class ApplicationControllerAction { protected ApplicationControllerOrchestrator client = new ApplicationControllerOrchestrator(); private String errorCode = "1002"; diff --git a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/GenericVnfHealthCheckBB.bpmn b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/GenericVnfHealthCheckBB.bpmn new file mode 100644 index 0000000000..d7828c5163 --- /dev/null +++ b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/GenericVnfHealthCheckBB.bpmn @@ -0,0 +1,56 @@ + + + + + SequenceFlow_06ab7wm + + + SequenceFlow_06ab7wm + SequenceFlow_1yhmh9s + + + + SequenceFlow_12srn62 + + + + + SequenceFlow_1yhmh9s + SequenceFlow_12srn62 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/BaseBPMNTest.java b/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/BaseBPMNTest.java index f6d81ba771..21b6dd402b 100644 --- a/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/BaseBPMNTest.java +++ b/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/BaseBPMNTest.java @@ -51,6 +51,7 @@ import org.onap.so.bpmn.infrastructure.flowspecific.tasks.AssignNetworkBBUtils; import org.onap.so.bpmn.infrastructure.flowspecific.tasks.AssignVnf; import org.onap.so.bpmn.infrastructure.flowspecific.tasks.CreateNetwork; import org.onap.so.bpmn.infrastructure.flowspecific.tasks.CreateNetworkCollection; +import org.onap.so.bpmn.infrastructure.flowspecific.tasks.GenericVnfHealthCheck; import org.onap.so.bpmn.infrastructure.flowspecific.tasks.UnassignNetworkBB; import org.onap.so.bpmn.infrastructure.flowspecific.tasks.UnassignVnf; import org.onap.so.bpmn.infrastructure.sdnc.tasks.SDNCActivateTasks; @@ -182,6 +183,9 @@ public abstract class BaseBPMNTest { @MockBean protected WorkflowActionBBTasks workflowActionBBTasks; + @MockBean + protected GenericVnfHealthCheck genericVnfHealthCheck; + @LocalServerPort private int port; diff --git a/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/infrastructure/bpmn/subprocess/GenericVnfHealthCheckBBTest.java b/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/infrastructure/bpmn/subprocess/GenericVnfHealthCheckBBTest.java new file mode 100644 index 0000000000..1c882e85d1 --- /dev/null +++ b/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/infrastructure/bpmn/subprocess/GenericVnfHealthCheckBBTest.java @@ -0,0 +1,41 @@ +package org.onap.so.bpmn.infrastructure.bpmn.subprocess; + +import static org.camunda.bpm.engine.test.assertions.bpmn.BpmnAwareAssertions.assertThat; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.doThrow; + +import java.io.IOException; + +import org.camunda.bpm.engine.delegate.BpmnError; +import org.camunda.bpm.engine.runtime.ProcessInstance; +import org.junit.Test; +import org.onap.so.bpmn.BaseBPMNTest; +import org.onap.so.bpmn.common.BuildingBlockExecution; + + + +public class GenericVnfHealthCheckBBTest extends BaseBPMNTest { + + @Test + public void sunnyDayGenericVnfHealthCheckBBTest() throws InterruptedException, IOException { + + ProcessInstance pi = runtimeService.startProcessInstanceByKey("GenericVnfHealthCheckBB", variables); + assertThat(pi).isNotNull(); + assertThat(pi).isStarted().hasPassedInOrder("Start_GenericVnfHealthChkBB", "SetParamsHealthCheck", + "Call-AppC-HealthCheck", "End_GenericVnfHealthChkBB"); + assertThat(pi).isEnded(); + } + + @Test + public void genericVnfHealthCheckBBExceptionTest() throws Exception { + doThrow(new BpmnError("7000", "TESTING ERRORS")).when(genericVnfHealthCheck).setParamsForGenericVnfHealthCheck(any(BuildingBlockExecution.class)); + ProcessInstance pi = runtimeService.startProcessInstanceByKey("GenericVnfHealthCheckBB", variables); + assertThat(pi).isNotNull(); + assertThat(pi).isStarted() + .hasPassedInOrder("Start_GenericVnfHealthChkBB", "SetParamsHealthCheck") + .hasNotPassed("Call-AppC-HealthCheck", "End_GenericVnfHealthChkBB"); + assertThat(pi).isEnded(); + } +} + + diff --git a/bpmn/so-bpmn-building-blocks/src/test/resources/application-test.yaml b/bpmn/so-bpmn-building-blocks/src/test/resources/application-test.yaml index d7bb084195..2d102afe9f 100644 --- a/bpmn/so-bpmn-building-blocks/src/test/resources/application-test.yaml +++ b/bpmn/so-bpmn-building-blocks/src/test/resources/application-test.yaml @@ -67,6 +67,9 @@ mso: workflow: message: endpoint: http://localhost:28090/workflows/messages/message + requestDb: + auth: Basic YnBlbDptc28tZGItMTUwNyE= + endpoint: http://localhost:8081 async: core-pool-size: 50 diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericVnfHealthCheck.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericVnfHealthCheck.java new file mode 100644 index 0000000000..772def739b --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericVnfHealthCheck.java @@ -0,0 +1,103 @@ +/*- + * ============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.bpmn.infrastructure.flowspecific.tasks; + +import java.util.HashMap; +import java.util.Optional; + +import org.onap.appc.client.lcm.model.Action; +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; +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.appc.ApplicationControllerAction; +import org.onap.so.client.exception.ExceptionBuilder; +import org.onap.so.db.catalog.client.CatalogDbClient; +import org.onap.so.db.catalog.beans.ControllerSelectionReference; +import org.onap.so.logger.MsoLogger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class GenericVnfHealthCheck { + + private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, GenericVnfHealthCheck.class); + @Autowired + private ExceptionBuilder exceptionUtil; + @Autowired + private ExtractPojosForBB extractPojosForBB; + @Autowired + private CatalogDbClient catalogDbClient; + @Autowired + private ApplicationControllerAction appCClient; + + public void setParamsForGenericVnfHealthCheck(BuildingBlockExecution execution) { + + GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock(); + + try { + ControllerSelectionReference controllerSelectionReference; + GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID)); + String vnfId = vnf.getVnfId(); + String vnfName = vnf.getVnfName(); + String vnfType = vnf.getVnfType(); + String oamIpAddress = vnf.getIpv4OamAddress(); + String actionCategory = Action.HealthCheck.toString(); + controllerSelectionReference = catalogDbClient.getControllerSelectionReferenceByVnfTypeAndActionCategory(vnfType, actionCategory); + String controllerName = controllerSelectionReference.getControllerName(); + + execution.setVariable("vnfId", vnfId); + execution.setVariable("vnfName", vnfName); + execution.setVariable("oamIpAddress", oamIpAddress); + execution.setVariable("msoRequestId", gBBInput.getRequestContext().getMsoRequestId()); + execution.setVariable("action", actionCategory); + execution.setVariable("controllerType", controllerName); + + } catch (Exception ex) { + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); + } + } + + public void callAppcClient(BuildingBlockExecution execution) { + + try { + Action action = null; + action = Action.valueOf(execution.getVariable("action")); + String msoRequestId = execution.getVariable("msoRequestId"); + String vnfId = execution.getVariable("vnfId"); + Optional payload = null; + if(execution.getVariable("payload") != null){ + String pay = execution.getVariable("payload"); + payload = Optional.of(pay); + } + String controllerType = execution.getVariable("controllerType"); + HashMap payloadInfo = new HashMap(); + payloadInfo.put("vnfName", execution.getVariable("vnfName")); + payloadInfo.put("vfModuleId",execution.getVariable("vfModuleId")); + payloadInfo.put("oamIpAddress",execution.getVariable("oamIpAddress")); + //PayloadInfo contains extra information that adds on to payload before making request to appc + appCClient.runAppCCommand(action, msoRequestId, vnfId, payload, payloadInfo, controllerType); + + } catch (Exception ex) { + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); + } + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java index 87852e9922..3fce15a6c4 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java @@ -27,6 +27,7 @@ import org.onap.so.bpmn.infrastructure.flowspecific.tasks.AssignNetworkBBUtils; import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetup; import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetupUtils; import org.onap.so.client.adapter.network.mapper.NetworkAdapterObjectMapper; +import org.onap.so.client.appc.ApplicationControllerAction; import org.onap.so.client.db.request.RequestsDbClient; import org.onap.so.client.orchestration.AAICollectionResources; import org.onap.so.client.orchestration.AAIInstanceGroupResources; @@ -120,4 +121,7 @@ public abstract class BaseTaskTest extends TestDataSetup { @SpyBean protected SDNCClient SPY_sdncClient; + + @MockBean + protected ApplicationControllerAction appCClient; } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericVnfHealthCheckTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericVnfHealthCheckTest.java new file mode 100644 index 0000000000..3aaf15cf11 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericVnfHealthCheckTest.java @@ -0,0 +1,101 @@ +/*- + * ============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.bpmn.infrastructure.flowspecific.tasks; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import java.util.HashMap; +import java.util.Optional; +import java.util.UUID; + +import org.junit.Before; +import org.junit.Test; +import org.onap.appc.client.lcm.model.Action; +import org.onap.so.bpmn.BaseTaskTest; +import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; +import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; +import org.onap.so.db.catalog.beans.ControllerSelectionReference; +import org.springframework.beans.factory.annotation.Autowired; + +public class GenericVnfHealthCheckTest extends BaseTaskTest { + + @Autowired + private GenericVnfHealthCheck genericVnfHealthCheck; + + private GenericVnf genericVnf; + private RequestContext requestContext; + private String msoRequestId; + + @Before + public void before() { + genericVnf = setGenericVnf(); + msoRequestId = UUID.randomUUID().toString(); + requestContext = setRequestContext(); + requestContext.setMsoRequestId(msoRequestId); + gBBInput.setRequestContext(requestContext); + } + + @Test + public void setParamsForGenericVnfHealthCheckTest() throws Exception { + ControllerSelectionReference controllerSelectionReference = new ControllerSelectionReference(); + controllerSelectionReference.setControllerName("testName"); + controllerSelectionReference.setActionCategory("testAction"); + controllerSelectionReference.setVnfType("testVnfType"); + + doReturn(controllerSelectionReference).when(catalogDbClient).getControllerSelectionReferenceByVnfTypeAndActionCategory(genericVnf.getVnfType(), Action.HealthCheck.toString()); + + genericVnfHealthCheck.setParamsForGenericVnfHealthCheck(execution); + + assertEquals(genericVnf.getVnfId(), execution.getVariable("vnfId")); + assertEquals(genericVnf.getVnfName(), execution.getVariable("vnfName")); + assertEquals(genericVnf.getIpv4OamAddress(), execution.getVariable("oamIpAddress")); + assertEquals("HealthCheck", execution.getVariable("action")); + assertEquals(requestContext.getMsoRequestId(), execution.getVariable("msoRequestId")); + assertEquals(controllerSelectionReference.getControllerName(), execution.getVariable("controllerType")); + } + @Test + public void callAppcClientTest() throws Exception { + Action action = Action.HealthCheck; + String vnfId = genericVnf.getVnfId(); + String payload = "{\"testName\":\"testValue\",}"; + String controllerType = "testType"; + HashMap payloadInfo = new HashMap(); + payloadInfo.put("vnfName", "testVnfName"); + payloadInfo.put("vfModuleId", "testVfModuleId"); + payloadInfo.put("oamIpAddress", "testOamIpAddress"); + execution.setVariable("action", Action.HealthCheck.toString()); + execution.setVariable("msoRequestId", msoRequestId); + execution.setVariable("controllerType", controllerType); + execution.setVariable("vnfId", "testVnfId1"); + execution.setVariable("vnfName", "testVnfName"); + execution.setVariable("vfModuleId", "testVfModuleId"); + execution.setVariable("oamIpAddress", "testOamIpAddress"); + execution.setVariable("payload", payload); + + doNothing().when(appCClient).runAppCCommand(action, msoRequestId, vnfId, Optional.of(payload), payloadInfo, controllerType); + + genericVnfHealthCheck.callAppcClient(execution); + verify(appCClient, times(1)).runAppCCommand(action, msoRequestId, vnfId, Optional.of(payload), payloadInfo, controllerType); + } +} -- cgit 1.2.3-korg