Search in sources :

Example 1 with DatalakeStatusUpdateException

use of com.sequenceiq.datalake.service.sdx.status.DatalakeStatusUpdateException in project cloudbreak by hortonworks.

the class SdxCreateActions method failedAction.

@Bean(name = "SDX_CREATION_FAILED_STATE")
public Action<?, ?> failedAction() {
    return new AbstractSdxAction<>(SdxCreateFailedEvent.class) {

        @Override
        protected SdxContext createFlowContext(FlowParameters flowParameters, StateContext<FlowState, FlowEvent> stateContext, SdxCreateFailedEvent payload) {
            return SdxContext.from(flowParameters, payload);
        }

        @Override
        protected void doExecute(SdxContext context, SdxCreateFailedEvent payload, Map<Object, Object> variables) throws Exception {
            Exception exception = payload.getException();
            String statusReason = "Datalake creation failed";
            String errorMessage = webApplicationExceptionMessageExtractor.getErrorMessage(exception);
            if (StringUtils.hasText(errorMessage)) {
                statusReason = statusReason + ". " + errorMessage;
            } else if (exception.getMessage() != null) {
                statusReason = statusReason + ". " + exception.getMessage();
            }
            LOGGER.error(statusReason, exception);
            try {
                SdxCluster sdxCluster = sdxStatusService.setStatusForDatalakeAndNotify(DatalakeStatusEnum.PROVISIONING_FAILED, statusReason, payload.getResourceId());
                metricService.incrementMetricCounter(MetricType.SDX_CREATION_FAILED, sdxCluster);
                eventSenderService.notifyEvent(context, ResourceEvent.SDX_CLUSTER_CREATION_FAILED);
            } catch (NotFoundException notFoundException) {
                LOGGER.info("Can not set status to SDX_CREATION_FAILED because data lake was not found");
            } catch (DatalakeStatusUpdateException datalakeStatusUpdateException) {
                LOGGER.info("Status update for data lake failed (possible reason: ongoing parallel deletion flow): {}", exception.getMessage());
            }
            Flow flow = getFlow(context.getFlowParameters().getFlowId());
            flow.setFlowFailed(payload.getException());
            sendEvent(context, SDX_CREATE_FAILED_HANDLED_EVENT.event(), payload);
        }

        @Override
        protected Object getFailurePayload(SdxCreateFailedEvent payload, Optional<SdxContext> flowContext, Exception ex) {
            return null;
        }
    };
}
Also used : Optional(java.util.Optional) StateContext(org.springframework.statemachine.StateContext) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) DatalakeStatusUpdateException(com.sequenceiq.datalake.service.sdx.status.DatalakeStatusUpdateException) DatalakeStatusUpdateException(com.sequenceiq.datalake.service.sdx.status.DatalakeStatusUpdateException) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) SdxContext(com.sequenceiq.datalake.flow.SdxContext) Flow(com.sequenceiq.flow.core.Flow) FlowParameters(com.sequenceiq.flow.core.FlowParameters) AbstractSdxAction(com.sequenceiq.datalake.service.AbstractSdxAction) SdxCreateFailedEvent(com.sequenceiq.datalake.flow.create.event.SdxCreateFailedEvent) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Aggregations

NotFoundException (com.sequenceiq.cloudbreak.common.exception.NotFoundException)1 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)1 SdxContext (com.sequenceiq.datalake.flow.SdxContext)1 SdxCreateFailedEvent (com.sequenceiq.datalake.flow.create.event.SdxCreateFailedEvent)1 AbstractSdxAction (com.sequenceiq.datalake.service.AbstractSdxAction)1 DatalakeStatusUpdateException (com.sequenceiq.datalake.service.sdx.status.DatalakeStatusUpdateException)1 Flow (com.sequenceiq.flow.core.Flow)1 FlowParameters (com.sequenceiq.flow.core.FlowParameters)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Bean (org.springframework.context.annotation.Bean)1 StateContext (org.springframework.statemachine.StateContext)1