Search in sources :

Example 1 with SdxStartDetachRecoveryEvent

use of com.sequenceiq.datalake.flow.detach.event.SdxStartDetachRecoveryEvent in project cloudbreak by hortonworks.

the class SdxDetachRecoveryActions method sdxDetachRecoveryAction.

@Bean(name = "SDX_DETACH_RECOVERY_STATE")
public Action<?, ?> sdxDetachRecoveryAction() {
    return new AbstractSdxAction<>(SdxStartDetachRecoveryEvent.class) {

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

        @Override
        protected void doExecute(SdxContext context, SdxStartDetachRecoveryEvent payload, Map<Object, Object> variables) throws Exception {
            SdxCluster clusterToReattach = sdxService.getById(payload.getResourceId());
            clusterToReattach = sdxAttachService.reattachDetachedSdxCluster(clusterToReattach);
            LOGGER.info("Successfully restored detached SDX with ID {}.", clusterToReattach.getId());
            sendEvent(context, SDX_DETACH_RECOVERY_SUCCESS_EVENT.event(), payload);
        }

        @Override
        protected Object getFailurePayload(SdxStartDetachRecoveryEvent payload, Optional<SdxContext> flowContext, Exception e) {
            LOGGER.error("Failed to recover from detach of SDX with ID {}.", payload.getResourceId());
            return SdxDetachRecoveryFailedEvent.from(payload, e);
        }
    };
}
Also used : FlowParameters(com.sequenceiq.flow.core.FlowParameters) AbstractSdxAction(com.sequenceiq.datalake.service.AbstractSdxAction) Optional(java.util.Optional) StateContext(org.springframework.statemachine.StateContext) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) Map(java.util.Map) SdxStartDetachRecoveryEvent(com.sequenceiq.datalake.flow.detach.event.SdxStartDetachRecoveryEvent) SdxContext(com.sequenceiq.datalake.flow.SdxContext) Bean(org.springframework.context.annotation.Bean)

Aggregations

SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)1 SdxContext (com.sequenceiq.datalake.flow.SdxContext)1 SdxStartDetachRecoveryEvent (com.sequenceiq.datalake.flow.detach.event.SdxStartDetachRecoveryEvent)1 AbstractSdxAction (com.sequenceiq.datalake.service.AbstractSdxAction)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