Search in sources :

Example 16 with Action

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

the class ApplicationControllerClient method createRequest.

public Object createRequest(Action action, ActionIdentifiers identifier, Payload payload, String requestId) {
    Object requestObject = appCSupport.getInput(action.name());
    try {
        CommonHeader commonHeader = buildCommonHeader(requestId);
        requestObject.getClass().getDeclaredMethod("setCommonHeader", CommonHeader.class).invoke(requestObject, commonHeader);
        requestObject.getClass().getDeclaredMethod("setAction", Action.class).invoke(requestObject, action);
        requestObject.getClass().getDeclaredMethod("setActionIdentifiers", ActionIdentifiers.class).invoke(requestObject, identifier);
        if (payload != null) {
            requestObject.getClass().getDeclaredMethod("setPayload", Payload.class).invoke(requestObject, payload);
        }
    } catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
        logger.error("Error building Appc request", e);
    }
    return requestObject;
}
Also used : CommonHeader(org.onap.appc.client.lcm.model.CommonHeader) Action(org.onap.appc.client.lcm.model.Action) Payload(org.onap.appc.client.lcm.model.Payload) ActionIdentifiers(org.onap.appc.client.lcm.model.ActionIdentifiers) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 17 with Action

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

the class GenericVnfHealthCheckTest method callAppcClientTimeOutExceptionTest.

@Test
// The runAppCCommand method in not capable of throwing this exception
@Ignore
public void callAppcClientTimeOutExceptionTest() {
    expectedException.expect(java.util.concurrent.TimeoutException.class);
    Action action = Action.HealthCheck;
    String vnfId = genericVnf.getVnfId();
    String payload = "{\"testName\":\"testValue\",}";
    String controllerType = "testType";
    HashMap<String, String> payloadInfo = new HashMap<>();
    payloadInfo.put("vnfName", "testVnfName");
    payloadInfo.put("vfModuleId", "testVfModuleId");
    payloadInfo.put("oamIpAddress", "testOamIpAddress");
    payloadInfo.put("vnfHostIpAddress", "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("vnfHostIpAddress", "testOamIpAddress");
    execution.setVariable("payload", payload);
    doThrow(java.util.concurrent.TimeoutException.class).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);
}
Also used : Action(org.onap.appc.client.lcm.model.Action) ApplicationControllerAction(org.onap.so.client.appc.ApplicationControllerAction) HashMap(java.util.HashMap) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 18 with Action

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

the class ConfigurationScaleOutTest method callAppcClientExceptionTest.

@Test
public void callAppcClientExceptionTest() throws Exception {
    expectedException.expect(BpmnError.class);
    Action action = Action.ConfigScaleOut;
    String vnfId = genericVnf.getVnfId();
    String controllerType = "testType";
    String payload = "{\"request-parameters\":{\"vnf-host-ip-address\":\"10.222.22.2\"," + "\"vf-module-id\":\"testVfModuleId1\"},\"configuration-parameters\"" + ":{\"vnf-id\":\"66dac89b-2a5b-4cb9-b22e-a7e4488fb3db\",\"availability-zone\":\"AZ-MN02\"}}";
    HashMap<String, String> payloadInfo = new HashMap<String, String>();
    payloadInfo.put("vnfName", "testVnfName");
    payloadInfo.put("vfModuleId", "testVfModuleId");
    execution.setVariable("action", Action.ConfigScaleOut.toString());
    execution.setVariable("msoRequestId", msoRequestId);
    execution.setVariable("controllerType", controllerType);
    execution.setVariable("vnfId", "testVnfId1");
    execution.setVariable("vnfName", "testVnfName");
    execution.setVariable("vfModuleId", "testVfModuleId");
    execution.setVariable("payload", payload);
    doThrow(new BpmnError("BPMN Error")).when(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(1002), eq("APPC Client Failed"));
    doThrow(new RuntimeException("APPC Client Failed")).when(appCClient).runAppCCommand(action, msoRequestId, vnfId, Optional.of(payload), payloadInfo, controllerType);
    configurationScaleOut.callAppcClient(execution);
    verify(appCClient, times(1)).runAppCCommand(action, msoRequestId, vnfId, Optional.of(payload), payloadInfo, controllerType);
}
Also used : Action(org.onap.appc.client.lcm.model.Action) BuildingBlockExecution(org.onap.so.bpmn.common.BuildingBlockExecution) HashMap(java.util.HashMap) BpmnError(org.camunda.bpm.engine.delegate.BpmnError) BaseTaskTest(org.onap.so.bpmn.BaseTaskTest) Test(org.junit.Test)

Example 19 with Action

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

the class ApplicationControllerActionTest method runAppCCommand_Snapshot_vmIdList_Empty_Test.

@Test
public void runAppCCommand_Snapshot_vmIdList_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");
    String controllerType = "testControllerType";
    Status status = new Status();
    Optional<String> otherPayloadVm = PayloadClient.snapshotFormat("", "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) HashMap(java.util.HashMap) Test(org.junit.Test) BaseTest(org.onap.so.BaseTest)

Example 20 with Action

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

the class ApplicationControllerActionTest method runAppCCommand_HealthCheck_Test.

@Test
public void runAppCCommand_HealthCheck_Test() throws ApplicationControllerOrchestratorException, JsonProcessingException {
    // Prepare method
    Action action = Action.HealthCheck;
    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");
    payloadInfo.put("vnfHostIpAddress", "testVnfHostIpAddress");
    String controllerType = "testControllerType";
    // Prepare mocks
    Status status = new Status();
    Optional<String> otherPayload = PayloadClient.healthCheckFormat(payloadInfo.get("vnfName"), payloadInfo.get("vnfHostIpAddress"));
    doReturn(status).when(client).vnfCommand(action, msoRequestId, vnfId, vserverId, otherPayload, controllerType);
    // Run method
    appCAction.runAppCCommand(action, msoRequestId, vnfId, payload, payloadInfo, controllerType);
    // Verify call
    verify(client, times(1)).vnfCommand(action, msoRequestId, vnfId, vserverId, otherPayload, 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)

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