Search in sources :

Example 21 with Action

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

the class ApplicationControllerActionTest method runAppCCommand_Snapshot_Test.

@Test
public void runAppCCommand_Snapshot_Test() throws ApplicationControllerOrchestratorException, JsonProcessingException {
    // Prepare method
    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 vmId1 = "testlink:testVmId1";
    vmIdList.add(vmId1);
    String vmId2 = "testlink:testVmId2";
    vmIdList.add(vmId2);
    JSONObject vmIdListJson = new JSONObject();
    vmIdListJson.put("vmIds", vmIdList);
    payloadInfo.put("vmIdList", vmIdListJson.toString());
    ArrayList<String> vserverIdList = new ArrayList<String>();
    String vserverId1 = "testVserverId1";
    Optional<String> vserverIdString1 = Optional.of(vserverId1);
    vserverIdList.add(vserverId1);
    String vserverId2 = "testVserverId2";
    Optional<String> vserverIdString2 = Optional.of(vserverId2);
    vserverIdList.add(vserverId2);
    JSONObject vserverIdListJson = new JSONObject();
    vserverIdListJson.put("vserverIds", vserverIdList);
    payloadInfo.put("vserverIdList", vserverIdListJson.toString());
    String controllerType = "testControllerType";
    // Prepare mocks
    Status status = new Status();
    Optional<String> otherPayloadVm1 = PayloadClient.snapshotFormat(vmId1, payloadInfo.get("identityUrl"));
    Optional<String> otherPayloadVm2 = PayloadClient.snapshotFormat(vmId2, payloadInfo.get("identityUrl"));
    doReturn(status).when(client).vnfCommand(action, msoRequestId, vnfId, vserverIdString1, otherPayloadVm1, controllerType);
    doReturn(status).when(client).vnfCommand(action, msoRequestId, vnfId, vserverIdString2, otherPayloadVm2, controllerType);
    // Run method
    appCAction.runAppCCommand(action, msoRequestId, vnfId, payload, payloadInfo, controllerType);
    // Verify call
    verify(client, times(1)).vnfCommand(action, msoRequestId, vnfId, vserverIdString1, otherPayloadVm1, controllerType);
    verify(client, times(1)).vnfCommand(action, msoRequestId, vnfId, vserverIdString2, otherPayloadVm2, 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 22 with Action

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

the class ApplicationControllerActionTest method runAppCCommand_ConfigModify__NoPayload_Test.

@Test
public void runAppCCommand_ConfigModify__NoPayload_Test() throws ApplicationControllerOrchestratorException {
    // Prepare method
    Action action = Action.ConfigModify;
    String msoRequestId = "testMsoRequestId";
    String vnfId = "testVnfId";
    Optional<String> payload = Optional.empty();
    HashMap<String, String> payloadInfo = new HashMap<String, String>();
    String controllerType = "testControllerType";
    // Run method
    appCAction.runAppCCommand(action, msoRequestId, vnfId, payload, payloadInfo, controllerType);
    // Verify non call
    verify(client, times(0)).vnfCommand(any(), any(), any(), any(), any(), any());
    assertEquals("Payload is not present for " + action.toString(), appCAction.getErrorMessage());
}
Also used : Action(org.onap.appc.client.lcm.model.Action) HashMap(java.util.HashMap) Test(org.junit.Test) BaseTest(org.onap.so.BaseTest)

Example 23 with Action

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

the class ApplicationControllerActionTest method applicationControllerOrchestratorExceptionCaught_Test.

@Test
public void applicationControllerOrchestratorExceptionCaught_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
    Optional<String> otherPayload = PayloadClient.startStopFormat(payloadInfo.get("vnfName"));
    String expectedErrorMessage = "Test appc orchestrator error message";
    doThrow(new ApplicationControllerOrchestratorException(expectedErrorMessage, 0)).when(client).vnfCommand(action, msoRequestId, vnfId, vserverId, otherPayload, controllerType);
    // Run method
    appCAction.runAppCCommand(action, msoRequestId, vnfId, payload, payloadInfo, controllerType);
    // Verify error
    assertEquals(expectedErrorMessage, appCAction.getErrorMessage());
    String expectedErrorCode = "1002";
    assertEquals(expectedErrorCode, appCAction.getErrorCode());
}
Also used : Action(org.onap.appc.client.lcm.model.Action) HashMap(java.util.HashMap) Test(org.junit.Test) BaseTest(org.onap.so.BaseTest)

Example 24 with Action

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

the class ApplicationControllerActionTest method runAppCCommand_QuiesceTraffic_NoPayload_Test.

@Test
public void runAppCCommand_QuiesceTraffic_NoPayload_Test() throws ApplicationControllerOrchestratorException {
    // Prepare method
    Action action = Action.QuiesceTraffic;
    String msoRequestId = "testMsoRequestId";
    String vnfId = "testVnfId";
    Optional<String> payload = Optional.empty();
    HashMap<String, String> payloadInfo = new HashMap<String, String>();
    String controllerType = "testControllerType";
    // Run method
    appCAction.runAppCCommand(action, msoRequestId, vnfId, payload, payloadInfo, controllerType);
    // Verify non call
    verify(client, times(0)).vnfCommand(any(), any(), any(), any(), any(), any());
    assertEquals("Payload is not present for " + action.toString(), appCAction.getErrorMessage());
}
Also used : Action(org.onap.appc.client.lcm.model.Action) HashMap(java.util.HashMap) Test(org.junit.Test) BaseTest(org.onap.so.BaseTest)

Example 25 with Action

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

the class ConfigurationScaleOut method callAppcClient.

public void callAppcClient(BuildingBlockExecution execution) {
    logger.trace("Start runAppcCommand ");
    String appcCode = "1002";
    String appcMessage = "";
    try {
        Action commandAction = Action.valueOf(execution.getVariable(ACTION));
        String msoRequestId = execution.getVariable(MSO_REQUEST_ID);
        String vnfId = execution.getVariable(VNF_ID);
        Optional<String> payloadString = null;
        if (execution.getVariable(PAYLOAD) != null) {
            String pay = execution.getVariable(PAYLOAD);
            payloadString = Optional.of(pay);
        }
        String controllerType = execution.getVariable(CONTROLLER_TYPE);
        HashMap<String, String> payloadInfo = new HashMap<>();
        payloadInfo.put(VNF_NAME, execution.getVariable(VNF_NAME));
        payloadInfo.put(VFMODULE_ID, execution.getVariable(VFMODULE_ID));
        logger.debug("Running APP-C action: {}", commandAction.toString());
        logger.debug("VNFID: {}", vnfId);
        // PayloadInfo contains extra information that adds on to payload before making request to appc
        appCClient.runAppCCommand(commandAction, msoRequestId, vnfId, payloadString, payloadInfo, controllerType);
        appcCode = appCClient.getErrorCode();
        appcMessage = appCClient.getErrorMessage();
    } catch (Exception e) {
        logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION.toString(), "Caught exception in runAppcCommand in ConfigurationScaleOut", "BPMN", ErrorCode.UnknownError.getValue(), "APPC Error", e);
        appcMessage = e.getMessage();
    }
    logger.error("Error Message: " + appcMessage);
    logger.error("ERROR CODE: " + appcCode);
    logger.trace("End of runAppCommand ");
    if (appcCode != null && !("0").equals(appcCode)) {
        exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(appcCode), appcMessage);
    }
}
Also used : Action(org.onap.appc.client.lcm.model.Action) ApplicationControllerAction(org.onap.so.client.appc.ApplicationControllerAction) HashMap(java.util.HashMap)

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