Search in sources :

Example 1 with WaitUntilAvailableFailedToInstanceFailureEventConverter

use of com.sequenceiq.freeipa.flow.instance.reboot.failure.WaitUntilAvailableFailedToInstanceFailureEventConverter in project cloudbreak by hortonworks.

the class RebootActions method rebootFailureAction.

@Bean(name = "REBOOT_FAILED_STATE")
public Action<?, ?> rebootFailureAction() {
    return new AbstractRebootAction<>(InstanceFailureEvent.class) {

        @Inject
        private OperationService operationService;

        @Override
        protected void doExecute(RebootContext context, InstanceFailureEvent payload, Map<Object, Object> variables) {
            addMdcOperationId(variables);
            rebootService.handleInstanceRebootError(context);
            String message = String.format("Rebooting failed for %s.", context.getInstanceIds());
            LOGGER.error(message);
            Stack stack = context.getStack();
            SuccessDetails successDetails = new SuccessDetails(stack.getEnvironmentCrn());
            FailureDetails failureDetails = new FailureDetails(stack.getEnvironmentCrn(), message);
            operationService.failOperation(stack.getAccountId(), getOperationId(variables), message, List.of(successDetails), List.of(failureDetails));
            sendEvent(context, new InstanceEvent(RebootEvent.REBOOT_FAIL_HANDLED_EVENT.event(), context.getStack().getId(), context.getInstanceIdList()));
        }

        @Override
        protected RebootContext createFlowContext(FlowParameters flowParameters, StateContext<RebootState, RebootEvent> stateContext, InstanceFailureEvent payload) {
            Long stackId = payload.getResourceId();
            Stack stack = stackService.getStackById(stackId);
            MDCBuilder.buildMdcContext(stack);
            return new RebootContext(flowParameters, stack, payload.getInstanceIds().stream().map(instanceId -> {
                InstanceMetaData md = new InstanceMetaData();
                md.setInstanceId(instanceId);
                return md;
            }).collect(Collectors.toList()), null, null);
        }

        @Override
        protected Object getFailurePayload(InstanceFailureEvent payload, Optional<RebootContext> flowContext, Exception ex) {
            return new InstanceFailureEvent(payload.getResourceId(), ex, payload.getInstanceIds());
        }

        @Override
        protected void initPayloadConverterMap(List<PayloadConverter<InstanceFailureEvent>> payloadConverters) {
            payloadConverters.add(new RebootInstancesResultToCleanupFailureEventConverter());
            payloadConverters.add(new WaitUntilAvailableFailedToInstanceFailureEventConverter());
        }
    };
}
Also used : SuccessDetails(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails) InstanceFailureEvent(com.sequenceiq.freeipa.flow.instance.InstanceFailureEvent) Optional(java.util.Optional) StateContext(org.springframework.statemachine.StateContext) FailureDetails(com.sequenceiq.freeipa.api.v1.freeipa.user.model.FailureDetails) Stack(com.sequenceiq.freeipa.entity.Stack) RebootInstanceEvent(com.sequenceiq.freeipa.flow.instance.reboot.RebootInstanceEvent) InstanceEvent(com.sequenceiq.freeipa.flow.instance.InstanceEvent) RebootInstancesResultToCleanupFailureEventConverter(com.sequenceiq.freeipa.flow.freeipa.cleanup.event.failure.RebootInstancesResultToCleanupFailureEventConverter) InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) FlowParameters(com.sequenceiq.flow.core.FlowParameters) List(java.util.List) OperationService(com.sequenceiq.freeipa.service.operation.OperationService) WaitUntilAvailableFailedToInstanceFailureEventConverter(com.sequenceiq.freeipa.flow.instance.reboot.failure.WaitUntilAvailableFailedToInstanceFailureEventConverter) RebootContext(com.sequenceiq.freeipa.flow.instance.reboot.RebootContext) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Aggregations

FlowParameters (com.sequenceiq.flow.core.FlowParameters)1 FailureDetails (com.sequenceiq.freeipa.api.v1.freeipa.user.model.FailureDetails)1 SuccessDetails (com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails)1 InstanceMetaData (com.sequenceiq.freeipa.entity.InstanceMetaData)1 Stack (com.sequenceiq.freeipa.entity.Stack)1 RebootInstancesResultToCleanupFailureEventConverter (com.sequenceiq.freeipa.flow.freeipa.cleanup.event.failure.RebootInstancesResultToCleanupFailureEventConverter)1 InstanceEvent (com.sequenceiq.freeipa.flow.instance.InstanceEvent)1 InstanceFailureEvent (com.sequenceiq.freeipa.flow.instance.InstanceFailureEvent)1 RebootContext (com.sequenceiq.freeipa.flow.instance.reboot.RebootContext)1 RebootInstanceEvent (com.sequenceiq.freeipa.flow.instance.reboot.RebootInstanceEvent)1 WaitUntilAvailableFailedToInstanceFailureEventConverter (com.sequenceiq.freeipa.flow.instance.reboot.failure.WaitUntilAvailableFailedToInstanceFailureEventConverter)1 OperationService (com.sequenceiq.freeipa.service.operation.OperationService)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Bean (org.springframework.context.annotation.Bean)1 StateContext (org.springframework.statemachine.StateContext)1