Search in sources :

Example 1 with Action

use of org.onap.appc.client.lcm.model.Action in project so by onap.

the class GenericVnfHealthCheck method callAppcClient.

public void callAppcClient(BuildingBlockExecution execution) {
    logger.trace("Start runAppcCommand ");
    String appcCode = "1002";
    String appcMessage;
    try {
        Action action = Action.valueOf(execution.getVariable("action"));
        String msoRequestId = execution.getVariable("msoRequestId");
        String vnfId = execution.getVariable("vnfId");
        Optional<String> payload = Optional.empty();
        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<>();
        payloadInfo.put(VNF_NAME, execution.getVariable(VNF_NAME));
        payloadInfo.put("vfModuleId", execution.getVariable("vfModuleId"));
        payloadInfo.put(OAM_IP_ADDRESS, execution.getVariable(OAM_IP_ADDRESS));
        payloadInfo.put(VNF_HOST_IP_ADDRESS, execution.getVariable(VNF_HOST_IP_ADDRESS));
        logger.debug("Running APP-C action: {}", action);
        logger.debug("VNFID: {}", vnfId);
        // PayloadInfo contains extra information that adds on to payload before making request to appc
        appCClient.runAppCCommand(action, msoRequestId, vnfId, payload, payloadInfo, controllerType);
        appcCode = appCClient.getErrorCode();
        appcMessage = appCClient.getErrorMessage();
    } catch (BpmnError ex) {
        logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), "Caught exception in GenericVnfHealthCheck", "BPMN", ErrorCode.UnknownError.getValue(), ex);
        appcMessage = ex.getMessage();
        exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(appcCode), appcMessage);
    } catch (Exception e) {
        if (e instanceof java.util.concurrent.TimeoutException) {
            appcMessage = "Request to APPC timed out. ";
            logger.error(LoggingAnchor.FIVE, MessageEnum.RA_CONNECTION_EXCEPTION.toString(), "Caught timedOut exception in runAppcCommand in GenericVnfHealthCheck", "BPMN", ErrorCode.UnknownError.getValue(), "APPC Error", e);
            throw e;
        } else {
            logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION.toString(), "Caught exception in runAppcCommand in GenericVnfHealthCheck", "BPMN", ErrorCode.UnknownError.getValue(), "APPC Error", e);
            appcMessage = e.getMessage();
            exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(appcCode), appcMessage);
        }
    }
    logger.error("Error Message: " + appcMessage);
    logger.error("ERROR CODE: " + appcCode);
    if (appcCode != null && !("0").equals(appcCode)) {
        exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(appcCode), appcMessage);
    }
    execution.setVariable(CONTROLLER_STATUS, "Success");
    logger.debug("Successfully end of runAppCommand ");
}
Also used : Action(org.onap.appc.client.lcm.model.Action) ApplicationControllerAction(org.onap.so.client.appc.ApplicationControllerAction) HashMap(java.util.HashMap) BpmnError(org.camunda.bpm.engine.delegate.BpmnError)

Example 2 with Action

use of org.onap.appc.client.lcm.model.Action in project so by onap.

the class AppcOrchestratorPreProcessor method buildAppcTaskRequest.

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);
        String requestorId = gBBInput.getRequestContext().getRequestorId();
        appcTaskRequest.setRequestorId(requestorId);
        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);
            Map<String, String> configMap = new HashMap<>();
            ObjectMapper objectMapper = new ObjectMapper();
            String configParamsStr = JsonUtils.getJsonValue(payload, "configuration_parameters");
            if (configParamsStr != null) {
                configMap = objectMapper.readValue(configParamsStr, new TypeReference<HashMap<String, String>>() {
                });
            }
            appcTaskRequest.setConfigParams(configMap);
        }
        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);
        verifyApplicationControllerTaskRequest(execution, appcTaskRequest);
        execution.setVariable("appcOrchestratorRequest", appcTaskRequest);
        logger.debug("SET APPC ORCHESTRATOR REQUEST");
    } catch (Exception e) {
        logger.error("Error building ApplicationControllerTaskRequest Object", e.getMessage());
        exceptionUtil.buildAndThrowWorkflowException(execution, 7000, e);
    }
}
Also used : Action(org.onap.appc.client.lcm.model.Action) ApplicationControllerTaskRequest(org.onap.so.appc.orchestrator.service.beans.ApplicationControllerTaskRequest) GeneralBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock) GenericVnf(org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf) HashMap(java.util.HashMap) VfModule(org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule) BBObjectNotFoundException(org.onap.so.client.exception.BBObjectNotFoundException) ValidationException(org.onap.so.exceptions.ValidationException) BBObjectNotFoundException(org.onap.so.client.exception.BBObjectNotFoundException) ApplicationControllerVnf(org.onap.so.appc.orchestrator.service.beans.ApplicationControllerVnf) ControllerSelectionReference(org.onap.so.db.catalog.beans.ControllerSelectionReference) TypeReference(com.fasterxml.jackson.core.type.TypeReference) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 3 with Action

use of org.onap.appc.client.lcm.model.Action in project so by onap.

the class ApplicationControllerActionTest method runAppCCommand_QuiesceTraffic_PayloadPresent_Test.

@Test
public void runAppCCommand_QuiesceTraffic_PayloadPresent_Test() throws ApplicationControllerOrchestratorException, JsonProcessingException {
    // Prepare method
    Action action = Action.QuiesceTraffic;
    String msoRequestId = "testMsoRequestId";
    String vnfId = "testVnfId";
    Optional<String> payload = Optional.of("testPayload");
    Optional<String> vserverId = Optional.empty();
    HashMap<String, String> payloadInfo = new HashMap<String, String>();
    payloadInfo.put("vnfName", "testVnfName");
    String controllerType = "testControllerType";
    // Prepare mocks
    Status status = new Status();
    Optional<String> modifiedPayload = PayloadClient.quiesceTrafficFormat(payload, payloadInfo.get("vnfName"));
    doReturn(status).when(client).vnfCommand(action, msoRequestId, vnfId, vserverId, modifiedPayload, controllerType);
    // Run method
    appCAction.runAppCCommand(action, msoRequestId, vnfId, payload, payloadInfo, controllerType);
    // Verify call
    verify(client, times(1)).vnfCommand(action, msoRequestId, vnfId, vserverId, modifiedPayload, controllerType);
}
Also used : Status(org.onap.appc.client.lcm.model.Status) Action(org.onap.appc.client.lcm.model.Action) HashMap(java.util.HashMap) Test(org.junit.Test) BaseTest(org.onap.so.BaseTest)

Example 4 with Action

use of org.onap.appc.client.lcm.model.Action in project so by onap.

the class ApplicationControllerActionTest method runAppCCommand_Snapshot_vserverIdList_Empty_Test.

@Test
public void runAppCCommand_Snapshot_vserverIdList_Empty_Test() throws ApplicationControllerOrchestratorException, JsonProcessingException {
    Action action = Action.Snapshot;
    String msoRequestId = "testMsoRequestId";
    String vnfId = "testVnfId";
    Optional<String> payload = Optional.empty();
    HashMap<String, String> payloadInfo = new HashMap<String, String>();
    payloadInfo.put("identityUrl", "testIdentityUrl");
    ArrayList<String> vmIdList = new ArrayList<String>();
    String vmId = "testlink:testVmId";
    vmIdList.add(vmId);
    JSONObject vmIdListJson = new JSONObject();
    vmIdListJson.put("vmIds", vmIdList);
    payloadInfo.put("vmIdList", vmIdListJson.toString());
    String controllerType = "testControllerType";
    Status status = new Status();
    Optional<String> otherPayloadVm = PayloadClient.snapshotFormat(vmId, payloadInfo.get("identityUrl"));
    doReturn(status).when(client).vnfCommand(action, msoRequestId, vnfId, null, otherPayloadVm, controllerType);
    appCAction.runAppCCommand(action, msoRequestId, vnfId, payload, payloadInfo, controllerType);
    verify(client, times(0)).vnfCommand(action, msoRequestId, vnfId, null, otherPayloadVm, controllerType);
}
Also used : Status(org.onap.appc.client.lcm.model.Status) Action(org.onap.appc.client.lcm.model.Action) JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Test(org.junit.Test) BaseTest(org.onap.so.BaseTest)

Example 5 with Action

use of org.onap.appc.client.lcm.model.Action in project so by onap.

the class ApplicationControllerActionTest method runAppCCommand_NormalAppCStatusGetErrorCode_Test.

@Test
public void runAppCCommand_NormalAppCStatusGetErrorCode_Test() throws ApplicationControllerOrchestratorException, JsonProcessingException {
    // Prepare method
    Action action = Action.Start;
    String msoRequestId = "testMsoRequestId";
    String vnfId = "testVnfId";
    Optional<String> payload = Optional.empty();
    Optional<String> vserverId = Optional.empty();
    HashMap<String, String> payloadInfo = new HashMap<String, String>();
    payloadInfo.put("vnfName", "testVnfName");
    String controllerType = "testControllerType";
    // Prepare mocks
    Status status = new Status();
    status.setCode(100);
    Optional<String> otherPayload = PayloadClient.startStopFormat(payloadInfo.get("vnfName"));
    doReturn(status).when(client).vnfCommand(action, msoRequestId, vnfId, vserverId, otherPayload, controllerType);
    // Run method
    appCAction.runAppCCommand(action, msoRequestId, vnfId, payload, payloadInfo, controllerType);
    // Verify call
    String expectedErrorCode = "0";
    assertEquals(expectedErrorCode, appCAction.getErrorCode());
}
Also used : Status(org.onap.appc.client.lcm.model.Status) Action(org.onap.appc.client.lcm.model.Action) HashMap(java.util.HashMap) Test(org.junit.Test) BaseTest(org.onap.so.BaseTest)

Aggregations

Action (org.onap.appc.client.lcm.model.Action)25 HashMap (java.util.HashMap)23 Test (org.junit.Test)20 BaseTest (org.onap.so.BaseTest)14 Status (org.onap.appc.client.lcm.model.Status)10 ApplicationControllerAction (org.onap.so.client.appc.ApplicationControllerAction)5 JSONObject (org.json.JSONObject)4 ArrayList (java.util.ArrayList)3 BpmnError (org.camunda.bpm.engine.delegate.BpmnError)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ActionIdentifiers (org.onap.appc.client.lcm.model.ActionIdentifiers)2 CommonHeader (org.onap.appc.client.lcm.model.CommonHeader)2 Payload (org.onap.appc.client.lcm.model.Payload)2 BaseTaskTest (org.onap.so.bpmn.BaseTaskTest)2 BuildingBlockExecution (org.onap.so.bpmn.common.BuildingBlockExecution)2 ControllerSelectionReference (org.onap.so.db.catalog.beans.ControllerSelectionReference)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Ignore (org.junit.Ignore)1 BaseIntegrationTest (org.onap.so.BaseIntegrationTest)1