Search in sources :

Example 1 with OperationService

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

the class FreeIpaUpscaleActions method upscaleFailureAction.

@Bean(name = "UPSCALE_FAIL_STATE")
public Action<?, ?> upscaleFailureAction() {
    return new AbstractUpscaleAction<>(UpscaleFailureEvent.class) {

        @Inject
        private OperationService operationService;

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

        @Override
        protected void doExecute(StackContext context, UpscaleFailureEvent payload, Map<Object, Object> variables) {
            LOGGER.error("Upscale 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 = "Upscale 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 upscaling FreeIPA");
            enableNodeStatusChecker(stack, "Failed upscaling FreeIPA");
            sendEvent(context, FAIL_HANDLED_EVENT.event(), payload);
        }

        @Override
        protected void initPayloadConverterMap(List<PayloadConverter<UpscaleFailureEvent>> payloadConverters) {
            payloadConverters.add(new UpscaleStackResultToUpscaleFailureEventConverter());
            payloadConverters.add(new CollectMetadataResultToUpscaleFailureEventConverter());
            payloadConverters.add(new BootstrapMachinesFailedToUpscaleFailureEventConverter());
            payloadConverters.add(new HostMetadataSetupFailedToUpscaleFailureEventConverter());
            payloadConverters.add(new InstallFreeIpaServicesFailedToUpscaleFailureEventConverter());
            payloadConverters.add(new ClusterProxyUpdateRegistrationFailedToUpscaleFailureEventConverter());
            payloadConverters.add(new PostInstallFreeIpaFailedToUpscaleFailureEventConverter());
        }
    };
}
Also used : SuccessDetails(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails) ClusterProxyUpdateRegistrationFailedToUpscaleFailureEventConverter(com.sequenceiq.freeipa.flow.freeipa.upscale.failure.ClusterProxyUpdateRegistrationFailedToUpscaleFailureEventConverter) StateContext(org.springframework.statemachine.StateContext) ArrayList(java.util.ArrayList) PostInstallFreeIpaFailedToUpscaleFailureEventConverter(com.sequenceiq.freeipa.flow.freeipa.upscale.failure.PostInstallFreeIpaFailedToUpscaleFailureEventConverter) BootstrapMachinesFailedToUpscaleFailureEventConverter(com.sequenceiq.freeipa.flow.freeipa.upscale.failure.BootstrapMachinesFailedToUpscaleFailureEventConverter) FailureDetails(com.sequenceiq.freeipa.api.v1.freeipa.user.model.FailureDetails) Flow(com.sequenceiq.flow.core.Flow) Stack(com.sequenceiq.freeipa.entity.Stack) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) HostMetadataSetupFailedToUpscaleFailureEventConverter(com.sequenceiq.freeipa.flow.freeipa.upscale.failure.HostMetadataSetupFailedToUpscaleFailureEventConverter) FlowParameters(com.sequenceiq.flow.core.FlowParameters) StackContext(com.sequenceiq.freeipa.flow.stack.StackContext) UpscaleStackResultToUpscaleFailureEventConverter(com.sequenceiq.freeipa.flow.freeipa.upscale.failure.UpscaleStackResultToUpscaleFailureEventConverter) UpscaleFailureEvent(com.sequenceiq.freeipa.flow.freeipa.upscale.event.UpscaleFailureEvent) ArrayList(java.util.ArrayList) List(java.util.List) OperationService(com.sequenceiq.freeipa.service.operation.OperationService) InstallFreeIpaServicesFailedToUpscaleFailureEventConverter(com.sequenceiq.freeipa.flow.freeipa.upscale.failure.InstallFreeIpaServicesFailedToUpscaleFailureEventConverter) Map(java.util.Map) CollectMetadataResultToUpscaleFailureEventConverter(com.sequenceiq.freeipa.flow.freeipa.upscale.failure.CollectMetadataResultToUpscaleFailureEventConverter) Bean(org.springframework.context.annotation.Bean)

Example 2 with OperationService

use of com.sequenceiq.freeipa.service.operation.OperationService 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)

Example 3 with OperationService

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

the class FreeIpaCleanupActions method cleanupFinishedAction.

@Bean(name = "CLEANUP_FINISHED_STATE")
public Action<?, ?> cleanupFinishedAction() {
    return new AbstractFreeIpaCleanupAction<>(RemoveRolesResponse.class) {

        @Inject
        private OperationService operationService;

        @Override
        protected void doExecute(FreeIpaContext context, RemoveRolesResponse payload, Map<Object, Object> variables) {
            CleanupEvent cleanupEvent = new CleanupEvent(FreeIpaCleanupEvent.CLEANUP_FINISHED_EVENT.event(), payload.getResourceId(), payload.getUsers(), payload.getHosts(), payload.getRoles(), payload.getIps(), payload.getStatesToSkip(), payload.getAccountId(), payload.getOperationId(), payload.getClusterName(), payload.getEnvironmentCrn());
            SuccessDetails successDetails = new SuccessDetails(payload.getEnvironmentCrn());
            successDetails.getAdditionalDetails().put("Hosts", payload.getHosts() == null ? List.of() : new ArrayList<>(payload.getHosts()));
            successDetails.getAdditionalDetails().put("Users", payload.getUsers() == null ? List.of() : new ArrayList<>(payload.getUsers()));
            successDetails.getAdditionalDetails().put("Roles", payload.getRoles() == null ? List.of() : new ArrayList<>(payload.getRoles()));
            successDetails.getAdditionalDetails().put("IPs", payload.getIps() == null ? List.of() : new ArrayList<>(payload.getIps()));
            operationService.completeOperation(payload.getAccountId(), payload.getOperationId(), List.of(successDetails), Collections.emptyList());
            LOGGER.info("Cleanup successfully finished with: " + successDetails);
            sendEvent(context, cleanupEvent);
        }
    };
}
Also used : RemoveRolesResponse(com.sequenceiq.freeipa.flow.freeipa.cleanup.event.roles.RemoveRolesResponse) SuccessDetails(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails) ArrayList(java.util.ArrayList) OperationService(com.sequenceiq.freeipa.service.operation.OperationService) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Example 4 with OperationService

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

the class FullBackupActions method backupFailedAction.

@Bean(name = "BACKUP_FAILED_STATE")
public Action<?, ?> backupFailedAction() {
    return new AbstractBackupAction<>(StackFailureEvent.class) {

        @Inject
        private OperationService operationService;

        @Override
        protected void doExecute(BackupContext context, StackFailureEvent payload, Map<Object, Object> variables) {
            LOGGER.error("Full backup failed", payload.getException());
            failFlow(context, payload);
            if (isOperationIdSet(variables)) {
                LOGGER.debug("Fail operation with id: [{}]", getOperationId(variables));
                operationService.failOperation(context.getStack().getAccountId(), getOperationId(variables), payload.getException().getMessage());
            }
            sendEvent(context, new StackEvent(FULL_BACKUP_FAILURE_HANDLED_EVENT.event(), payload.getResourceId()));
        }

        private void failFlow(BackupContext context, StackFailureEvent payload) {
            Flow flow = getFlow(context.getFlowParameters().getFlowId());
            flow.setFlowFailed(payload.getException());
        }
    };
}
Also used : StackEvent(com.sequenceiq.freeipa.flow.stack.StackEvent) StackFailureEvent(com.sequenceiq.freeipa.flow.stack.StackFailureEvent) BackupContext(com.sequenceiq.freeipa.flow.freeipa.backup.full.BackupContext) OperationService(com.sequenceiq.freeipa.service.operation.OperationService) Map(java.util.Map) Flow(com.sequenceiq.flow.core.Flow) Bean(org.springframework.context.annotation.Bean)

Example 5 with OperationService

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

the class FullBackupActions method backupFinishedAction.

@Bean(name = "BACKUP_FINISHED_STATE")
public Action<?, ?> backupFinishedAction() {
    return new AbstractBackupAction<>(StackEvent.class) {

        @Inject
        private OperationService operationService;

        @Override
        protected void doExecute(BackupContext context, StackEvent payload, Map<Object, Object> variables) {
            LOGGER.info("Full backup flow finished");
            if (isOperationIdSet(variables) && (!isChainedAction(variables) || isFinalChain(variables))) {
                LOGGER.debug("Complete operation with id: [{}]", getOperationId(variables));
                Stack stack = context.getStack();
                SuccessDetails successDetails = new SuccessDetails(stack.getEnvironmentCrn());
                operationService.completeOperation(stack.getAccountId(), getOperationId(variables), Set.of(successDetails), Set.of());
            }
            sendEvent(context, new StackEvent(FULL_BACKUP_FINISHED_EVENT.event(), payload.getResourceId()));
        }
    };
}
Also used : SuccessDetails(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails) StackEvent(com.sequenceiq.freeipa.flow.stack.StackEvent) BackupContext(com.sequenceiq.freeipa.flow.freeipa.backup.full.BackupContext) 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