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