Search in sources :

Example 1 with RemoveHostsResponseToDownscaleFailureEventConverter

use of com.sequenceiq.freeipa.flow.freeipa.downscale.failure.RemoveHostsResponseToDownscaleFailureEventConverter in project cloudbreak by hortonworks.

the class FreeIpaDownscaleActions method downscaleFailureAction.

@Bean(name = "DOWNSCALE_FAIL_STATE")
public Action<?, ?> downscaleFailureAction() {
    return new AbstractDownscaleAction<>(DownscaleFailureEvent.class) {

        @Inject
        private OperationService operationService;

        @Override
        protected StackContext createFlowContext(FlowParameters flowParameters, StateContext<DownscaleState, DownscaleFlowEvent> stateContext, DownscaleFailureEvent payload) {
            Flow flow = getFlow(flowParameters.getFlowId());
            flow.setFlowFailed(payload.getException());
            return super.createFlowContext(flowParameters, stateContext, payload);
        }

        @Override
        protected void doExecute(StackContext context, DownscaleFailureEvent payload, Map<Object, Object> variables) {
            LOGGER.error("Downscale failed with payload: " + payload);
            Stack stack = context.getStack();
            String environmentCrn = stack.getEnvironmentCrn();
            SuccessDetails successDetails = new SuccessDetails(environmentCrn);
            successDetails.getAdditionalDetails().put(payload.getFailedPhase(), payload.getSuccess() == null ? List.of() : new ArrayList<>(payload.getSuccess()));
            String message = "Downscale failed during " + payload.getFailedPhase();
            FailureDetails failureDetails = new FailureDetails(environmentCrn, message);
            if (payload.getFailureDetails() != null) {
                failureDetails.getAdditionalDetails().putAll(payload.getFailureDetails());
            }
            String errorReason = getErrorReason(payload.getException());
            stackUpdater.updateStackStatus(context.getStack().getId(), getFailedStatus(variables), errorReason);
            operationService.failOperation(stack.getAccountId(), getOperationId(variables), message, List.of(successDetails), List.of(failureDetails));
            enableStatusChecker(stack, "Failed downscaling FreeIPA");
            enableNodeStatusChecker(stack, "Failed downscaling FreeIPA");
            sendEvent(context, FAIL_HANDLED_EVENT.event(), payload);
        }

        @Override
        protected void initPayloadConverterMap(List<PayloadConverter<DownscaleFailureEvent>> payloadConverters) {
            payloadConverters.add(new ClusterProxyUpdateRegistrationFailedToDownscaleFailureEventConverter());
            payloadConverters.add(new DownscaleStackCollectResourcesResultToDownscaleFailureEventConverter());
            payloadConverters.add(new DownscaleStackResultToDownscaleFailureEventConverter());
            payloadConverters.add(new RemoveServersResponseToDownscaleFailureEventConverter());
            payloadConverters.add(new RemoveDnsResponseToDownscaleFailureEventConverter());
            payloadConverters.add(new RemoveHostsResponseToDownscaleFailureEventConverter());
            payloadConverters.add(new RevokeCertsResponseToDownscaleFailureEventConverter());
        }
    };
}
Also used : SuccessDetails(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails) DownscaleStackResultToDownscaleFailureEventConverter(com.sequenceiq.freeipa.flow.freeipa.downscale.failure.DownscaleStackResultToDownscaleFailureEventConverter) StateContext(org.springframework.statemachine.StateContext) ArrayList(java.util.ArrayList) RemoveHostsResponseToDownscaleFailureEventConverter(com.sequenceiq.freeipa.flow.freeipa.downscale.failure.RemoveHostsResponseToDownscaleFailureEventConverter) DownscaleFailureEvent(com.sequenceiq.freeipa.flow.freeipa.downscale.event.DownscaleFailureEvent) DownscaleStackCollectResourcesResultToDownscaleFailureEventConverter(com.sequenceiq.freeipa.flow.freeipa.downscale.failure.DownscaleStackCollectResourcesResultToDownscaleFailureEventConverter) FailureDetails(com.sequenceiq.freeipa.api.v1.freeipa.user.model.FailureDetails) Flow(com.sequenceiq.flow.core.Flow) Stack(com.sequenceiq.freeipa.entity.Stack) ClusterProxyUpdateRegistrationFailedToDownscaleFailureEventConverter(com.sequenceiq.freeipa.flow.freeipa.downscale.failure.ClusterProxyUpdateRegistrationFailedToDownscaleFailureEventConverter) RemoveServersResponseToDownscaleFailureEventConverter(com.sequenceiq.freeipa.flow.freeipa.downscale.failure.RemoveServersResponseToDownscaleFailureEventConverter) RemoveDnsResponseToDownscaleFailureEventConverter(com.sequenceiq.freeipa.flow.freeipa.downscale.failure.RemoveDnsResponseToDownscaleFailureEventConverter) FlowParameters(com.sequenceiq.flow.core.FlowParameters) StackContext(com.sequenceiq.freeipa.flow.stack.StackContext) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) RevokeCertsResponseToDownscaleFailureEventConverter(com.sequenceiq.freeipa.flow.freeipa.downscale.failure.RevokeCertsResponseToDownscaleFailureEventConverter) OperationService(com.sequenceiq.freeipa.service.operation.OperationService) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Aggregations

Flow (com.sequenceiq.flow.core.Flow)1 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 Stack (com.sequenceiq.freeipa.entity.Stack)1 DownscaleFailureEvent (com.sequenceiq.freeipa.flow.freeipa.downscale.event.DownscaleFailureEvent)1 ClusterProxyUpdateRegistrationFailedToDownscaleFailureEventConverter (com.sequenceiq.freeipa.flow.freeipa.downscale.failure.ClusterProxyUpdateRegistrationFailedToDownscaleFailureEventConverter)1 DownscaleStackCollectResourcesResultToDownscaleFailureEventConverter (com.sequenceiq.freeipa.flow.freeipa.downscale.failure.DownscaleStackCollectResourcesResultToDownscaleFailureEventConverter)1 DownscaleStackResultToDownscaleFailureEventConverter (com.sequenceiq.freeipa.flow.freeipa.downscale.failure.DownscaleStackResultToDownscaleFailureEventConverter)1 RemoveDnsResponseToDownscaleFailureEventConverter (com.sequenceiq.freeipa.flow.freeipa.downscale.failure.RemoveDnsResponseToDownscaleFailureEventConverter)1 RemoveHostsResponseToDownscaleFailureEventConverter (com.sequenceiq.freeipa.flow.freeipa.downscale.failure.RemoveHostsResponseToDownscaleFailureEventConverter)1 RemoveServersResponseToDownscaleFailureEventConverter (com.sequenceiq.freeipa.flow.freeipa.downscale.failure.RemoveServersResponseToDownscaleFailureEventConverter)1 RevokeCertsResponseToDownscaleFailureEventConverter (com.sequenceiq.freeipa.flow.freeipa.downscale.failure.RevokeCertsResponseToDownscaleFailureEventConverter)1 StackContext (com.sequenceiq.freeipa.flow.stack.StackContext)1 OperationService (com.sequenceiq.freeipa.service.operation.OperationService)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 Bean (org.springframework.context.annotation.Bean)1