Search in sources :

Example 26 with Status

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;
    }
}
Also used : Status(org.onap.appc.client.lcm.model.Status) Payload(org.onap.appc.client.lcm.model.Payload) ActionIdentifiers(org.onap.appc.client.lcm.model.ActionIdentifiers)

Example 27 with 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();
    }
}
Also used : Status(org.onap.appc.client.lcm.model.Status) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 28 with Status

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);
}
Also used : Status(org.onap.appc.client.lcm.model.Status) AppcClientException(org.onap.appc.client.lcm.exceptions.AppcClientException) Test(org.junit.Test)

Example 29 with Status

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);
}
Also used : Status(org.onap.appc.client.lcm.model.Status) ResumeTrafficOutput(org.onap.appc.client.lcm.model.ResumeTrafficOutput) Test(org.junit.Test)

Example 30 with Status

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)));
}
Also used : Status(org.onap.appc.client.lcm.model.Status) AppcClientException(org.onap.appc.client.lcm.exceptions.AppcClientException) Test(org.junit.Test)

Aggregations

Status (org.onap.appc.client.lcm.model.Status)42 Test (org.junit.Test)27 HashMap (java.util.HashMap)14 Action (org.onap.appc.client.lcm.model.Action)10 BaseTest (org.onap.so.BaseTest)10 ConfigurationParameters (org.onap.so.adapters.appc.orchestrator.client.beans.ConfigurationParameters)8 Parameters (org.onap.so.adapters.appc.orchestrator.client.beans.Parameters)8 RequestParameters (org.onap.so.adapters.appc.orchestrator.client.beans.RequestParameters)8 JSONObject (org.json.JSONObject)4 ArrayList (java.util.ArrayList)3 ResumeTrafficOutput (org.onap.appc.client.lcm.model.ResumeTrafficOutput)3 AppcClientException (org.onap.appc.client.lcm.exceptions.AppcClientException)2 ActionIdentifiers (org.onap.appc.client.lcm.model.ActionIdentifiers)2 Payload (org.onap.appc.client.lcm.model.Payload)2 ApplicationControllerCallback (org.onap.so.adapters.appc.orchestrator.client.ApplicationControllerCallback)2 Identity (org.onap.so.adapters.appc.orchestrator.client.beans.Identity)2 ApplicationControllerTaskRequest (org.onap.so.appc.orchestrator.service.beans.ApplicationControllerTaskRequest)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 IOException (java.io.IOException)1