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);
}
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());
}
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());
}
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());
}
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);
}
}
Aggregations