X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=bpmn%2Fso-bpmn-tasks%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fso%2Fbpmn%2Finfrastructure%2Fadapter%2Fcnfm%2Ftasks%2FMonitorCnfmJobTask.java;fp=bpmn%2Fso-bpmn-tasks%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fso%2Fbpmn%2Finfrastructure%2Fadapter%2Fcnfm%2Ftasks%2FMonitorCnfmCreateJobTask.java;h=f84120e558a227412739d424b08fc1b2f7e23b19;hb=fb516859f920197eba4cbc1f5b82279f3e3753c6;hp=eb1cd1c1b68e272777cb77d02ec969e32415deea;hpb=d0493f954a48021662b5b6d3ba45b262750690c9;p=so.git diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/MonitorCnfmCreateJobTask.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/MonitorCnfmJobTask.java similarity index 56% rename from bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/MonitorCnfmCreateJobTask.java rename to bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/MonitorCnfmJobTask.java index eb1cd1c1b6..f84120e558 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/MonitorCnfmCreateJobTask.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/MonitorCnfmJobTask.java @@ -18,73 +18,75 @@ package org.onap.so.bpmn.infrastructure.adapter.cnfm.tasks; -import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.Constants.CREATE_CNF_STATUS_RESPONSE_PARAM_NAME; +import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.Constants.CNF_STATUS_RESPONSE_PARAM_NAME; import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.Constants.OPERATION_STATUS_PARAM_NAME; import java.net.URI; import java.util.Optional; -import org.onap.logging.filter.base.ONAPComponents; +import java.util.Set; +import org.camunda.bpm.engine.delegate.BpmnError; import org.onap.so.bpmn.common.BuildingBlockExecution; import org.onap.so.client.exception.ExceptionBuilder; +import org.onap.so.cnfm.lcm.model.AsLcmOpOcc; +import org.onap.so.cnfm.lcm.model.AsLcmOpOcc.OperationStateEnum; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import com.google.common.collect.ImmutableSet; -import org.onap.so.cnfm.lcm.model.AsLcmOpOcc; -import org.onap.so.cnfm.lcm.model.AsLcmOpOcc.OperationStateEnum; - /** * @author sagar.shetty@est.tech + * @author Raviteja Karumuri (raviteja.karumuri@est.tech) */ @Component -public class MonitorCnfmCreateJobTask { +public class MonitorCnfmJobTask { - public static final ImmutableSet OPERATION_FINISHED_STATES = - ImmutableSet.of(OperationStateEnum.COMPLETED, OperationStateEnum.FAILED, OperationStateEnum.ROLLED_BACK); private static final String CNFM_REQUEST_STATUS_CHECK_URL = "CnfmStatusCheckUrl"; - private static final Logger LOGGER = LoggerFactory.getLogger(MonitorCnfmCreateJobTask.class); + private static final String MONITOR_JOB_NAME = "MonitorJobName"; + public static final Set OPERATION_FINISHED_STATES = + Set.of(OperationStateEnum.COMPLETED, OperationStateEnum.FAILED, OperationStateEnum.ROLLED_BACK); + private static final Logger LOGGER = LoggerFactory.getLogger(MonitorCnfmJobTask.class); protected final ExceptionBuilder exceptionUtil; private final CnfmHttpServiceProvider cnfmHttpServiceProvider; @Autowired - public MonitorCnfmCreateJobTask(final CnfmHttpServiceProvider cnfmHttpServiceProvider, + public MonitorCnfmJobTask(final CnfmHttpServiceProvider cnfmHttpServiceProvider, final ExceptionBuilder exceptionUtil) { this.cnfmHttpServiceProvider = cnfmHttpServiceProvider; this.exceptionUtil = exceptionUtil; } /** - * Get the current operation status of instantiation job - * + * Get the current operation status of cnfm job + * * @param execution {@link org.onap.so.bpmn.common.DelegateExecutionImpl} */ public void getCurrentOperationStatus(final BuildingBlockExecution execution) { try { LOGGER.debug("Executing getCurrentOperationStatus ..."); - final URI operationStatusURL = execution.getVariable(CNFM_REQUEST_STATUS_CHECK_URL); + final Optional operationStatusURL = Optional.of(execution.getVariable(CNFM_REQUEST_STATUS_CHECK_URL)); LOGGER.debug("Executing getCurrentOperationStatus for CNF... :{}", operationStatusURL); - final Optional instantiateOperationJobStatus = - cnfmHttpServiceProvider.getInstantiateOperationJobStatus(operationStatusURL.toString()); - if (instantiateOperationJobStatus.isPresent()) { - final AsLcmOpOcc asLcmOpOccResponse = instantiateOperationJobStatus.get(); - if (asLcmOpOccResponse.getOperationState() != null) { - final OperationStateEnum operationStatus = asLcmOpOccResponse.getOperationState(); - LOGGER.debug("Operation {} with {} and operation retrieval status : {}", asLcmOpOccResponse.getId(), - operationStatus, asLcmOpOccResponse.getOperationState()); - execution.setVariable(OPERATION_STATUS_PARAM_NAME, asLcmOpOccResponse.getOperationState()); - } + final Optional operationalJobStatus = + cnfmHttpServiceProvider.getOperationJobStatus(String.valueOf(operationStatusURL + .orElseThrow(() -> new BpmnError("Operational Status check url Not found")))); - LOGGER.debug("Operation {} without operationStatus and operation retrieval status :{}", - asLcmOpOccResponse.getId(), asLcmOpOccResponse.getOperationState()); + final AsLcmOpOcc asLcmOpOccResponse = operationalJobStatus + .orElseThrow(() -> new BpmnError("Unable to get operational Job status from the CNFM")); + + if (asLcmOpOccResponse.getOperationState() != null) { + final OperationStateEnum operationStatus = asLcmOpOccResponse.getOperationState(); + LOGGER.debug("Operation {} with {} and operation retrieval status : {}", asLcmOpOccResponse.getId(), + operationStatus, operationStatus); + execution.setVariable(OPERATION_STATUS_PARAM_NAME, operationStatus); + } else { + LOGGER.debug("Operation {} without operationStatus", asLcmOpOccResponse.getId()); + exceptionUtil.buildAndThrowWorkflowException(execution, 1206, + new Exception("Operation Status is empty")); } - execution.setVariable(CREATE_CNF_STATUS_RESPONSE_PARAM_NAME, instantiateOperationJobStatus.orElseThrow()); + execution.setVariable(CNF_STATUS_RESPONSE_PARAM_NAME, asLcmOpOccResponse); LOGGER.debug("Finished executing getCurrentOperationStatus for CNF..."); } catch (final Exception exception) { - final String message = "Unable to invoke get current Operation status"; - LOGGER.error(message); - exceptionUtil.buildAndThrowWorkflowException(execution, 1209, message, ONAPComponents.SO); - + LOGGER.error("Unable to invoke get current Operation status"); + exceptionUtil.buildAndThrowWorkflowException(execution, 1209, exception); } } @@ -93,36 +95,30 @@ public class MonitorCnfmCreateJobTask { * * @param execution {@link org.onap.so.bpmn.common.DelegateExecutionImpl} */ - public void timeOutLogFailue(final BuildingBlockExecution execution) { - final String message = "CNF Instantiation operation time out"; + public void timeOutLogFailure(final BuildingBlockExecution execution) { + String message = "CNF" + execution.getVariable(MONITOR_JOB_NAME) + "operation time out"; LOGGER.error(message); - exceptionUtil.buildAndThrowWorkflowException(execution, 1205, message, ONAPComponents.SO); + exceptionUtil.buildAndThrowWorkflowException(execution, 1205, new Exception(message)); } /** - * Check the final status of instantiation throw exception if not completed successfully - * + * Check the final status of cnfm job throw exception if not completed successfully + * * @param execution {@link org.onap.so.bpmn.common.DelegateExecutionImpl} */ public void checkIfOperationWasSuccessful(final BuildingBlockExecution execution) { LOGGER.debug("Executing CNF checkIfOperationWasSuccessful ..."); final OperationStateEnum operationStatusOption = execution.getVariable(OPERATION_STATUS_PARAM_NAME); - final AsLcmOpOcc cnfInstantiateStautusResponse = execution.getVariable(CREATE_CNF_STATUS_RESPONSE_PARAM_NAME); - if (operationStatusOption == null) { - final String message = "Unable to instantiate CNF jobId: " - + (cnfInstantiateStautusResponse != null ? cnfInstantiateStautusResponse.getId() : "null") - + "Unable to retrieve OperationStatus"; + final AsLcmOpOcc cnfStautusResponse = execution.getVariable(CNF_STATUS_RESPONSE_PARAM_NAME); + if ((operationStatusOption == OperationStateEnum.FAILED) + || (operationStatusOption == OperationStateEnum.FAILED_TEMP)) { + final String message = "Unable to" + execution.getVariable(MONITOR_JOB_NAME) + "CNF jobId: " + + (cnfStautusResponse != null ? cnfStautusResponse.getId() : "null"); LOGGER.error(message); - exceptionUtil.buildAndThrowWorkflowException(execution, 1206, message, ONAPComponents.SO); - } else { - if (operationStatusOption != OperationStateEnum.COMPLETED) { - final String message = "Unable to instantiate jobId: " - + (cnfInstantiateStautusResponse != null ? cnfInstantiateStautusResponse.getId() : "null") - + " OperationStatus: " + operationStatusOption; - LOGGER.error(message); - exceptionUtil.buildAndThrowWorkflowException(execution, 1207, message, ONAPComponents.SO); - } - LOGGER.debug("Successfully completed CNF instatiation of job status {}", cnfInstantiateStautusResponse); + exceptionUtil.buildAndThrowWorkflowException(execution, 1206, new Exception()); + } else if ((operationStatusOption == OperationStateEnum.COMPLETED)) { + String monitorJobName = execution.getVariable(MONITOR_JOB_NAME); + LOGGER.debug("Successfully completed CNF {} job", monitorJobName); } }