Search in sources :

Example 11 with OperationService

use of com.sequenceiq.freeipa.service.operation.OperationService in project cloudbreak by hortonworks.

the class ChangePrimaryGatewayActions method failureAction.

@Bean(name = "CHANGE_PRIMARY_GATEWAY_FAIL_STATE")
public Action<?, ?> failureAction() {
    return new AbstractChangePrimaryGatewayAction<>(ChangePrimaryGatewayFailureEvent.class) {

        @Inject
        private OperationService operationService;

        @Override
        protected ChangePrimaryGatewayContext createFlowContext(FlowParameters flowParameters, StateContext<ChangePrimaryGatewayState, ChangePrimaryGatewayFlowEvent> stateContext, ChangePrimaryGatewayFailureEvent payload) {
            Flow flow = getFlow(flowParameters.getFlowId());
            flow.setFlowFailed(payload.getException());
            return super.createFlowContext(flowParameters, stateContext, payload);
        }

        @Override
        protected void doExecute(ChangePrimaryGatewayContext context, ChangePrimaryGatewayFailureEvent payload, Map<Object, Object> variables) {
            LOGGER.error("Change primary gateway 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 = "Change primary gateway 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(), DetailedStackStatus.REPAIR_FAILED, errorReason);
            operationService.failOperation(stack.getAccountId(), getOperationId(variables), message, List.of(successDetails), List.of(failureDetails));
            LOGGER.info("Enabling the status checker for stack ID {} after failing repairing", stack.getId());
            enableStatusChecker(stack, "Failed to repair FreeIPA");
            enableNodeStatusChecker(stack, "Failed to repair FreeIPA");
            sendEvent(context, FAIL_HANDLED_EVENT.event(), payload);
        }

        @Override
        protected void initPayloadConverterMap(List<PayloadConverter<ChangePrimaryGatewayFailureEvent>> payloadConverters) {
            payloadConverters.add(new ClusterProxyUpdateRegistrationFailedToChangePrimaryGatewayFailureEventConverter());
            payloadConverters.add(new HealthCheckFailedToChangePrimaryGatewayFailureEventConverter());
        }
    };
}
Also used : SuccessDetails(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails) ChangePrimaryGatewayFailureEvent(com.sequenceiq.freeipa.flow.freeipa.repair.changeprimarygw.event.ChangePrimaryGatewayFailureEvent) HealthCheckFailedToChangePrimaryGatewayFailureEventConverter(com.sequenceiq.freeipa.flow.freeipa.repair.changeprimarygw.failure.HealthCheckFailedToChangePrimaryGatewayFailureEventConverter) StateContext(org.springframework.statemachine.StateContext) ArrayList(java.util.ArrayList) FailureDetails(com.sequenceiq.freeipa.api.v1.freeipa.user.model.FailureDetails) Flow(com.sequenceiq.flow.core.Flow) Stack(com.sequenceiq.freeipa.entity.Stack) FlowParameters(com.sequenceiq.flow.core.FlowParameters) ClusterProxyUpdateRegistrationFailedToChangePrimaryGatewayFailureEventConverter(com.sequenceiq.freeipa.flow.freeipa.repair.changeprimarygw.failure.ClusterProxyUpdateRegistrationFailedToChangePrimaryGatewayFailureEventConverter) ChangePrimaryGatewayContext(com.sequenceiq.freeipa.flow.freeipa.repair.changeprimarygw.ChangePrimaryGatewayContext) ArrayList(java.util.ArrayList) List(java.util.List) OperationService(com.sequenceiq.freeipa.service.operation.OperationService) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Example 12 with OperationService

use of com.sequenceiq.freeipa.service.operation.OperationService in project cloudbreak by hortonworks.

the class ChangePrimaryGatewayActions method finsihedAction.

@Bean(name = "CHANGE_PRIMARY_GATEWAY_FINISHED_STATE")
public Action<?, ?> finsihedAction() {
    return new AbstractChangePrimaryGatewayAction<>(StackEvent.class) {

        @Inject
        private OperationService operationService;

        @Override
        protected void doExecute(ChangePrimaryGatewayContext context, StackEvent payload, Map<Object, Object> variables) {
            Stack stack = context.getStack();
            SuccessDetails successDetails = new SuccessDetails(stack.getEnvironmentCrn());
            if (isFinalChain(variables)) {
                successDetails.getAdditionalDetails().put("DownscaleHosts", getDownscaleHosts(variables));
                successDetails.getAdditionalDetails().put("UpscaleHosts", getUpscaleHosts(variables));
                operationService.completeOperation(stack.getAccountId(), getOperationId(variables), List.of(successDetails), Collections.emptyList());
            } else {
                stackUpdater.updateStackStatus(stack.getId(), DetailedStackStatus.REPAIR_IN_PROGRESS, "Finished changing the primary gateway");
            }
            sendEvent(context, CHANGE_PRIMARY_GATEWAY_FINISHED_EVENT.selector(), new StackEvent(stack.getId()));
        }
    };
}
Also used : SuccessDetails(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails) StackEvent(com.sequenceiq.freeipa.flow.stack.StackEvent) ChangePrimaryGatewayContext(com.sequenceiq.freeipa.flow.freeipa.repair.changeprimarygw.ChangePrimaryGatewayContext) OperationService(com.sequenceiq.freeipa.service.operation.OperationService) Map(java.util.Map) Stack(com.sequenceiq.freeipa.entity.Stack) Bean(org.springframework.context.annotation.Bean)

Example 13 with OperationService

use of com.sequenceiq.freeipa.service.operation.OperationService in project cloudbreak by hortonworks.

the class FreeIpaDownscaleActions method downscaleFinsihedAction.

@Bean(name = "DOWNSCALE_FINISHED_STATE")
public Action<?, ?> downscaleFinsihedAction() {
    return new AbstractDownscaleAction<>(StackEvent.class) {

        @Inject
        private OperationService operationService;

        @Override
        protected void doExecute(StackContext context, StackEvent payload, Map<Object, Object> variables) {
            Stack stack = context.getStack();
            stackUpdater.updateStackStatus(stack.getId(), getDownscaleCompleteStatus(variables), "Downscale complete");
            if (shouldCompleteOperation(variables)) {
                SuccessDetails successDetails = new SuccessDetails(stack.getEnvironmentCrn());
                successDetails.getAdditionalDetails().put("Hosts", getDownscaleHosts(variables));
                operationService.completeOperation(stack.getAccountId(), getOperationId(variables), List.of(successDetails), Collections.emptyList());
            }
            sendEvent(context, DOWNSCALE_FINISHED_EVENT.selector(), new StackEvent(stack.getId()));
        }
    };
}
Also used : SuccessDetails(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails) StackEvent(com.sequenceiq.freeipa.flow.stack.StackEvent) StackContext(com.sequenceiq.freeipa.flow.stack.StackContext) OperationService(com.sequenceiq.freeipa.service.operation.OperationService) Map(java.util.Map) Stack(com.sequenceiq.freeipa.entity.Stack) Bean(org.springframework.context.annotation.Bean)

Aggregations

OperationService (com.sequenceiq.freeipa.service.operation.OperationService)13 Map (java.util.Map)13 Bean (org.springframework.context.annotation.Bean)13 SuccessDetails (com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails)12 Stack (com.sequenceiq.freeipa.entity.Stack)9 FailureDetails (com.sequenceiq.freeipa.api.v1.freeipa.user.model.FailureDetails)6 List (java.util.List)6 FlowParameters (com.sequenceiq.flow.core.FlowParameters)5 StackEvent (com.sequenceiq.freeipa.flow.stack.StackEvent)5 ArrayList (java.util.ArrayList)5 StateContext (org.springframework.statemachine.StateContext)5 Flow (com.sequenceiq.flow.core.Flow)4 StackContext (com.sequenceiq.freeipa.flow.stack.StackContext)4 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)2 InstanceMetaData (com.sequenceiq.freeipa.entity.InstanceMetaData)2 BackupContext (com.sequenceiq.freeipa.flow.freeipa.backup.full.BackupContext)2 RebootInstancesResultToCleanupFailureEventConverter (com.sequenceiq.freeipa.flow.freeipa.cleanup.event.failure.RebootInstancesResultToCleanupFailureEventConverter)2 ChangePrimaryGatewayContext (com.sequenceiq.freeipa.flow.freeipa.repair.changeprimarygw.ChangePrimaryGatewayContext)2 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)1 RebootInstancesRequest (com.sequenceiq.cloudbreak.cloud.event.instance.RebootInstancesRequest)1