diff options
author | Brittany Plummer (bp896r) <bp896r@att.com> | 2018-08-28 15:58:07 -0400 |
---|---|---|
committer | Brittany Plummer (bp896r) <bp896r@att.com> | 2018-08-28 15:58:07 -0400 |
commit | 3cea07cfa59720df58e85f25081a5e8ff8d004cf (patch) | |
tree | dab1b8d87da6c02642abf29f758391029ca421b9 /bpmn/so-bpmn-tasks/src | |
parent | eb94991c543a1d9cf3c9b6c4dfca921dedf48da5 (diff) |
Added GenericVnfHealthCheckBB, tasks, and tests
Issue-ID: SO-777
Change-Id: I8a46f1802feb18ab4df098472fef5373ac42208b
Signed-off-by: Brittany Plummer (bp896r) <bp896r@att.com>
Diffstat (limited to 'bpmn/so-bpmn-tasks/src')
3 files changed, 208 insertions, 0 deletions
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<String> payload = null; + if(execution.getVariable("payload") != null){ + String pay = execution.getVariable("payload"); + payload = Optional.of(pay); + } + String controllerType = execution.getVariable("controllerType"); + HashMap<String, String> payloadInfo = new HashMap<String, String>(); + 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<String, String> payloadInfo = new HashMap<String, String>(); + 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); + } +} |