use of org.onap.appc.client.lcm.model.Status in project so by onap.
the class ApplicationControllerOrchestrator method vnfCommand.
public Status vnfCommand(Action action, String requestId, String vnfId, Optional<String> vserverId, Optional<String> request, String controllerType) throws ApplicationControllerOrchestratorException {
ApplicationControllerClient client = new ApplicationControllerClient(controllerType);
Status status;
ActionIdentifiers actionIdentifiers = new ActionIdentifiers();
actionIdentifiers.setVnfId(vnfId);
if (vserverId.isPresent()) {
actionIdentifiers.setVserverId(vserverId.get());
}
Payload payload = null;
if (request.isPresent()) {
payload = new Payload(request.get());
}
status = client.runCommand(action, actionIdentifiers, payload, requestId);
if (ApplicationControllerSupport.getCategoryOf(status).equals(StatusCategory.ERROR)) {
throw new ApplicationControllerOrchestratorException(status.getMessage(), status.getCode());
} else {
return status;
}
}
use of org.onap.appc.client.lcm.model.Status in project so by onap.
the class ApplicationControllerAction method runAppCCommand.
public void runAppCCommand(Action action, String msoRequestId, String vnfId, Optional<String> payload, Map<String, String> payloadInfo, String controllerType) {
Status appCStatus = null;
try {
String vnfName = payloadInfo.getOrDefault("vnfName", "");
String aicIdentity = payloadInfo.getOrDefault("vnfName", "");
String vnfHostIpAddress = payloadInfo.getOrDefault("vnfHostIpAddress", "");
String vmIdList = payloadInfo.getOrDefault("vmIdList", "");
String vserverIdList = payloadInfo.getOrDefault("vserverIdList", "");
String identityUrl = payloadInfo.getOrDefault("identityUrl", "");
switch(action) {
case ResumeTraffic:
appCStatus = resumeTrafficAction(msoRequestId, vnfId, vnfName, controllerType);
break;
case Start:
case Stop:
appCStatus = startStopAction(action, msoRequestId, vnfId, aicIdentity, controllerType);
break;
case Unlock:
case Lock:
appCStatus = client.vnfCommand(action, msoRequestId, vnfId, Optional.empty(), Optional.empty(), controllerType);
break;
case QuiesceTraffic:
appCStatus = quiesceTrafficAction(msoRequestId, vnfId, payload, vnfName, controllerType);
break;
case DistributeTraffic:
appCStatus = distributeTrafficAction(msoRequestId, vnfId, payload, vnfName, controllerType);
break;
case DistributeTrafficCheck:
appCStatus = distributeTrafficCheckAction(msoRequestId, vnfId, payload, vnfName, controllerType);
break;
case HealthCheck:
appCStatus = healthCheckAction(msoRequestId, vnfId, vnfName, vnfHostIpAddress, controllerType);
break;
case Snapshot:
if (vmIdList.isEmpty()) {
logger.warn("vmIdList is Empty in AppCClient");
break;
}
String vmIds = JsonUtils.getJsonValue(vmIdList, "vmIds");
if (vmIds == null) {
logger.warn("vmIds null in AppCClient");
break;
}
if (vserverIdList.isEmpty()) {
logger.warn("vserverIdList is empty in AppCClient");
break;
}
String vserverIds = JsonUtils.getJsonValue(vserverIdList, "vserverIds");
if (vserverIds == null) {
logger.warn("vserverIds null in AppCClient");
break;
}
appCStatus = getSnapshotActionAppcStatus(msoRequestId, vnfId, controllerType, identityUrl, vmIds, vserverIds);
break;
case ConfigModify:
case ConfigScaleOut:
appCStatus = payloadAction(action, msoRequestId, vnfId, payload, controllerType);
break;
case UpgradePreCheck:
case UpgradePostCheck:
case UpgradeSoftware:
case UpgradeBackup:
appCStatus = upgradeAction(action, msoRequestId, vnfId, payload, vnfName, controllerType);
break;
default:
errorMessage = "Unable to idenify Action request for AppCClient";
break;
}
if (appCStatus != null) {
errorCode = Integer.toString(appCStatus.getCode());
errorMessage = appCStatus.getMessage();
if (ApplicationControllerSupport.getCategoryOf(appCStatus).equals(StatusCategory.NORMAL)) {
errorCode = "0";
}
}
} catch (JsonProcessingException e) {
logger.error("Incorrect Payload format for action request: {}", action.toString(), e);
errorMessage = e.getMessage();
} catch (ApplicationControllerOrchestratorException e) {
logger.error("Error building Appc request: {}", e.getMessage(), e);
errorCode = "1002";
errorMessage = e.getMessage();
} catch (Exception e) {
logger.error("Error building Appc request: {}", e.getMessage(), e);
errorMessage = e.getMessage();
}
}
use of org.onap.appc.client.lcm.model.Status in project so by onap.
the class ApplicationControllerCallbackTest method onException_appcCallback_failure_Test.
@Test
public void onException_appcCallback_failure_Test() throws Exception {
String testFailure = "test failure";
AppcClientException appcException = new AppcClientException(testFailure);
Status status = new Status();
status.setCode(200);
String exceptionMessage = "Exception on APPC request: " + testFailure;
status.setMessage(exceptionMessage);
doReturn(status).when(applicationControllerSupport).buildStatusFromAppcException(appcException);
doReturn(StatusCategory.ERROR).when(applicationControllerSupport).getCategoryOf(status);
appcTaskCallback.onException(appcException);
Mockito.verify(mockExternalTaskService).handleBpmnError(mockExternalTask, "MSOWorkflowException", exceptionMessage);
}
use of org.onap.appc.client.lcm.model.Status in project so by onap.
the class ApplicationControllerCallbackTest method onResponse_appcCallback_failure_Test.
@Test
public void onResponse_appcCallback_failure_Test() throws Exception {
String testFailure = "test failure";
Status status = new Status();
status.setCode(200);
status.setMessage(testFailure);
ResumeTrafficOutput response = new ResumeTrafficOutput();
response.setStatus(status);
doReturn(status).when(applicationControllerSupport).getStatusFromGenericResponse(response);
doReturn(true).when(applicationControllerSupport).getFinalityOf(status);
doReturn(StatusCategory.ERROR).when(applicationControllerSupport).getCategoryOf(status);
appcTaskCallback.onResponse(response);
Mockito.verify(mockExternalTaskService).handleBpmnError(mockExternalTask, "MSOWorkflowException", testFailure);
}
use of org.onap.appc.client.lcm.model.Status in project so by onap.
the class ApplicationControllerSupportTest method buildStatusFromAppcException_Test.
@Test
public void buildStatusFromAppcException_Test() {
String errorMessage = "errormessage";
AppcClientException exception = new AppcClientException(errorMessage);
Status status = applicationControllerSupport.buildStatusFromAppcException(exception);
assertThat(status.getCode() == 200);
assertThat((status.getMessage()).equals(("Exception on APPC request: " + errorMessage)));
}
Aggregations