Search in sources :

Example 1 with HealthcheckInstanceResponse

use of org.onap.so.client.adapter.cnf.entities.HealthcheckInstanceResponse in project so by onap.

the class CnfHealthCheckTasks method processAsyncResponse.

public void processAsyncResponse(BuildingBlockExecution execution) {
    // Value from CNF Async Handler activity
    String asyncResponse = execution.getVariable("asyncCallbackResponse");
    ExecuteBuildingBlock executeBuildingBlock = execution.getVariable(BUILDING_BLOCK);
    BuildingBlock buildingBlock = executeBuildingBlock.getBuildingBlock();
    String action = Optional.ofNullable(buildingBlock.getBpmnAction()).orElseThrow(() -> new NullPointerException("BPMN Action is NULL in the orchestration_flow_reference table "));
    LOGGER.debug("action: {}", action);
    if (asyncResponse.contains("error")) {
        exceptionUtil.buildAndThrowWorkflowException(execution, 500, asyncResponse, ONAPComponents.SO);
    }
    if (STATUS_CHECK_SCOPE.equals(action)) {
        StatusCheckResponse statusCheckResponse = new StatusCheckResponse();
        try {
            statusCheckResponse = mapper.readValue(asyncResponse, StatusCheckResponse.class);
        } catch (JsonProcessingException e) {
            LOGGER.error("Error in parsing JSON response");
        }
        LOGGER.debug("statusCheckResponse: {}", statusCheckResponse);
        List<StatusCheckInstanceResponse> listOfStatusInstanceResponse = statusCheckResponse.getInstanceResponse();
        for (StatusCheckInstanceResponse statusCheckInstanceResponse : listOfStatusInstanceResponse) {
            if (!statusCheckInstanceResponse.isStatus()) {
                exceptionUtil.buildAndThrowWorkflowException(execution, 500, asyncResponse, ONAPComponents.SO);
            }
        }
        String statusCheckResponseJson = "";
        try {
            statusCheckResponseJson = mapper.writeValueAsString(statusCheckResponse);
        } catch (JsonProcessingException e) {
            LOGGER.error("Error in PARSING statusCheckResponse");
        }
        execution.setVariable("StatusMessage", statusCheckResponseJson);
    } else if (HEALTH_CHECK_SCOPE.equals(action)) {
        HealthcheckResponse healthCheckResponse = new HealthcheckResponse();
        try {
            healthCheckResponse = mapper.readValue(asyncResponse, HealthcheckResponse.class);
        } catch (JsonProcessingException e) {
            LOGGER.error("Error in parsing JSON");
        }
        List<HealthcheckInstanceResponse> listOfHealthcheckInstanceResponses = healthCheckResponse.getInstanceResponse();
        for (HealthcheckInstanceResponse healthcheckInstanceResponse : listOfHealthcheckInstanceResponses) {
            if ("Failed".equalsIgnoreCase(healthcheckInstanceResponse.getStatus()) || "Unknown".equalsIgnoreCase(healthcheckInstanceResponse.getStatus())) {
                exceptionUtil.buildAndThrowWorkflowException(execution, 500, asyncResponse, ONAPComponents.SO);
            }
        }
        String healthCheckResponseJson = "";
        try {
            healthCheckResponseJson = mapper.writeValueAsString(healthCheckResponse);
        } catch (JsonProcessingException e) {
            LOGGER.error("Error in PARSING statusCheckResponse");
        }
        execution.setVariable("StatusMessage", healthCheckResponseJson);
        LOGGER.debug("healthCheckResponse: {}", healthCheckResponse);
    }
}
Also used : HealthcheckInstanceResponse(org.onap.so.client.adapter.cnf.entities.HealthcheckInstanceResponse) ExecuteBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock) ExecuteBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock) GeneralBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock) BuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock) StatusCheckInstanceResponse(org.onap.so.client.adapter.cnf.entities.StatusCheckInstanceResponse) HealthcheckResponse(org.onap.so.client.adapter.cnf.entities.HealthcheckResponse) ArrayList(java.util.ArrayList) List(java.util.List) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) StatusCheckResponse(org.onap.so.client.adapter.cnf.entities.StatusCheckResponse)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 BuildingBlock (org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock)1 ExecuteBuildingBlock (org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock)1 GeneralBuildingBlock (org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock)1 HealthcheckInstanceResponse (org.onap.so.client.adapter.cnf.entities.HealthcheckInstanceResponse)1 HealthcheckResponse (org.onap.so.client.adapter.cnf.entities.HealthcheckResponse)1 StatusCheckInstanceResponse (org.onap.so.client.adapter.cnf.entities.StatusCheckInstanceResponse)1 StatusCheckResponse (org.onap.so.client.adapter.cnf.entities.StatusCheckResponse)1