Search in sources :

Example 6 with OperationService

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

the class CreateBindUserActions method createBindUserFinishedAction.

@Bean("CREATE_BIND_USER_FINISHED_STATE")
public Action<?, ?> createBindUserFinishedAction() {
    return new AbstractBindUserCreateAction<>(CreateBindUserEvent.class) {

        @Inject
        private OperationService operationService;

        @Override
        protected void doExecute(CommonContext context, CreateBindUserEvent payload, Map<Object, Object> variables) throws Exception {
            LOGGER.info("Bind user creation successfully finished with payload: {}", payload);
            SuccessDetails successDetails = new SuccessDetails(payload.getEnvironmentCrn());
            successDetails.getAdditionalDetails().put("suffix", List.of(payload.getSuffix()));
            operationService.completeOperation(payload.getAccountId(), payload.getOperationId(), Set.of(successDetails), Set.of());
            LOGGER.debug("Finalizing user creation finished");
            sendEvent(context, CreateBindUserFlowEvent.CREATE_BIND_USER_FINISHED_EVENT.event(), payload);
        }
    };
}
Also used : SuccessDetails(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails) CommonContext(com.sequenceiq.flow.core.CommonContext) CreateBindUserEvent(com.sequenceiq.freeipa.flow.freeipa.binduser.create.event.CreateBindUserEvent) OperationService(com.sequenceiq.freeipa.service.operation.OperationService) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Example 7 with OperationService

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

Example 8 with OperationService

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

the class FreeIpaCleanupActions method cleanupFailureAction.

@Bean(name = "CLEANUP_FAILED_STATE")
public Action<?, ?> cleanupFailureAction() {
    return new AbstractFreeIpaCleanupAction<>(CleanupFailureEvent.class) {

        @Inject
        private OperationService operationService;

        @Override
        protected void doExecute(FreeIpaContext context, CleanupFailureEvent payload, Map<Object, Object> variables) {
            LOGGER.error("Cleanup failed with payload: " + payload);
            String environmentCrn = payload.getEnvironmentCrn();
            SuccessDetails successDetails = new SuccessDetails(environmentCrn);
            successDetails.getAdditionalDetails().put(payload.getFailedPhase(), payload.getSuccess() == null ? List.of() : new ArrayList<>(payload.getSuccess()));
            String message = "Cleanup failed during " + payload.getFailedPhase();
            FailureDetails failureDetails = new FailureDetails(environmentCrn, message);
            if (payload.getFailureDetails() != null) {
                failureDetails.getAdditionalDetails().putAll(payload.getFailureDetails());
            }
            operationService.failOperation(payload.getAccountId(), payload.getOperationId(), message, List.of(successDetails), List.of(failureDetails));
            sendEvent(context, FreeIpaCleanupEvent.CLEANUP_FAILURE_HANDLED_EVENT.event(), payload);
        }

        @Override
        protected void initPayloadConverterMap(List<PayloadConverter<CleanupFailureEvent>> payloadConverters) {
            payloadConverters.add(new RemoveDnsResponseToCleanupFailureEventConverter());
            payloadConverters.add(new RemoveHostsResponseToCleanupFailureEventConverter());
            payloadConverters.add(new RemoveRolesResponseToCleanupFailureEventConverter());
            payloadConverters.add(new RemoveUsersResponseToCleanupFailureEventConverter());
            payloadConverters.add(new RevokeCertsResponseToCleanupFailureEventConverter());
            payloadConverters.add(new RemoveVaultEntriesResponseToCleanupFailureEventConverter());
        }
    };
}
Also used : SuccessDetails(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails) RemoveDnsResponseToCleanupFailureEventConverter(com.sequenceiq.freeipa.flow.freeipa.cleanup.event.failure.RemoveDnsResponseToCleanupFailureEventConverter) RemoveRolesResponseToCleanupFailureEventConverter(com.sequenceiq.freeipa.flow.freeipa.cleanup.event.failure.RemoveRolesResponseToCleanupFailureEventConverter) RemoveVaultEntriesResponseToCleanupFailureEventConverter(com.sequenceiq.freeipa.flow.freeipa.cleanup.event.failure.RemoveVaultEntriesResponseToCleanupFailureEventConverter) ArrayList(java.util.ArrayList) FailureDetails(com.sequenceiq.freeipa.api.v1.freeipa.user.model.FailureDetails) RemoveUsersResponseToCleanupFailureEventConverter(com.sequenceiq.freeipa.flow.freeipa.cleanup.event.failure.RemoveUsersResponseToCleanupFailureEventConverter) RevokeCertsResponseToCleanupFailureEventConverter(com.sequenceiq.freeipa.flow.freeipa.cleanup.event.failure.RevokeCertsResponseToCleanupFailureEventConverter) RemoveHostsResponseToCleanupFailureEventConverter(com.sequenceiq.freeipa.flow.freeipa.cleanup.event.failure.RemoveHostsResponseToCleanupFailureEventConverter) ArrayList(java.util.ArrayList) List(java.util.List) OperationService(com.sequenceiq.freeipa.service.operation.OperationService) Map(java.util.Map) CleanupFailureEvent(com.sequenceiq.freeipa.flow.freeipa.cleanup.event.failure.CleanupFailureEvent) Bean(org.springframework.context.annotation.Bean)

Example 9 with OperationService

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

the class FreeIpaUpscaleActions method upscaleFinsihedAction.

@Bean(name = "UPSCALE_FINISHED_STATE")
public Action<?, ?> upscaleFinsihedAction() {
    return new AbstractUpscaleAction<>(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(), getUpscaleCompleteStatus(variables), "Upscale complete");
            if (shouldCompleteOperation(variables)) {
                SuccessDetails successDetails = new SuccessDetails(stack.getEnvironmentCrn());
                successDetails.getAdditionalDetails().put("Hosts", getUpscaleHosts(variables));
                operationService.completeOperation(stack.getAccountId(), getOperationId(variables), List.of(successDetails), Collections.emptyList());
            }
            sendEvent(context, UPSCALE_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) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Bean(org.springframework.context.annotation.Bean)

Example 10 with OperationService

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

the class RebootActions method rebootFinishedAction.

@Bean(name = "REBOOT_FINISHED_STATE")
public Action<?, ?> rebootFinishedAction() {
    return new AbstractRebootAction<>(HealthCheckSuccess.class) {

        @Inject
        private OperationService operationService;

        @Override
        protected void doExecute(RebootContext context, HealthCheckSuccess payload, Map<Object, Object> variables) {
            addMdcOperationId(variables);
            rebootService.finishInstanceReboot(context);
            LOGGER.info("Finished rebooting {}.", context.getInstanceIds());
            Stack stack = context.getStack();
            SuccessDetails successDetails = new SuccessDetails(stack.getEnvironmentCrn());
            successDetails.getAdditionalDetails().put("InstanceIds", context.getInstanceIdList());
            operationService.completeOperation(stack.getAccountId(), getOperationId(variables), List.of(successDetails), Collections.emptyList());
            sendEvent(context);
        }

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

        @Override
        protected Selectable createRequest(RebootContext context) {
            return new InstanceEvent(RebootEvent.REBOOT_FINALIZED_EVENT.event(), context.getStack().getId(), context.getInstanceIdList());
        }

        @Override
        protected RebootContext createFlowContext(FlowParameters flowParameters, StateContext<RebootState, RebootEvent> stateContext, HealthCheckSuccess payload) {
            Long stackId = payload.getResourceId();
            Stack stack = stackService.getByIdWithListsInTransaction(stackId);
            MDCBuilder.buildMdcContext(stack);
            List<InstanceMetaData> instances = instanceMetaDataService.findNotTerminatedForStack(stackId).stream().filter(instanceMetaData -> payload.getInstanceIds().contains(instanceMetaData.getInstanceId())).collect(Collectors.toList());
            return new RebootContext(flowParameters, stack, instances, null, null);
        }
    };
}
Also used : Action(org.springframework.statemachine.action.Action) InstanceMetaDataToCloudInstanceConverter(com.sequenceiq.freeipa.converter.cloud.InstanceMetaDataToCloudInstanceConverter) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) RebootInstancesRequest(com.sequenceiq.cloudbreak.cloud.event.instance.RebootInstancesRequest) LoggerFactory(org.slf4j.LoggerFactory) MDCBuilder(com.sequenceiq.cloudbreak.logger.MDCBuilder) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) RebootInstanceEvent(com.sequenceiq.freeipa.flow.instance.reboot.RebootInstanceEvent) ResourceToCloudResourceConverter(com.sequenceiq.freeipa.converter.cloud.ResourceToCloudResourceConverter) InstanceEvent(com.sequenceiq.freeipa.flow.instance.InstanceEvent) Inject(javax.inject.Inject) HealthCheckRequest(com.sequenceiq.freeipa.flow.stack.HealthCheckRequest) StateContext(org.springframework.statemachine.StateContext) Credential(com.sequenceiq.freeipa.dto.Credential) ResourceService(com.sequenceiq.freeipa.service.resource.ResourceService) InstanceFailureEvent(com.sequenceiq.freeipa.flow.instance.InstanceFailureEvent) Map(java.util.Map) Resource(com.sequenceiq.freeipa.entity.Resource) StackService(com.sequenceiq.freeipa.service.stack.StackService) RebootEvent(com.sequenceiq.freeipa.flow.instance.reboot.RebootEvent) InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) Stack(com.sequenceiq.freeipa.entity.Stack) RebootInstancesResultToCleanupFailureEventConverter(com.sequenceiq.freeipa.flow.freeipa.cleanup.event.failure.RebootInstancesResultToCleanupFailureEventConverter) RebootState(com.sequenceiq.freeipa.flow.instance.reboot.RebootState) PayloadConverter(com.sequenceiq.flow.core.PayloadConverter) InstanceMetaDataService(com.sequenceiq.freeipa.service.stack.instance.InstanceMetaDataService) Logger(org.slf4j.Logger) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) FailureDetails(com.sequenceiq.freeipa.api.v1.freeipa.user.model.FailureDetails) FlowParameters(com.sequenceiq.flow.core.FlowParameters) CredentialToCloudCredentialConverter(com.sequenceiq.freeipa.converter.cloud.CredentialToCloudCredentialConverter) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Collectors(java.util.stream.Collectors) HealthCheckSuccess(com.sequenceiq.freeipa.flow.stack.HealthCheckSuccess) OperationService(com.sequenceiq.freeipa.service.operation.OperationService) Configuration(org.springframework.context.annotation.Configuration) List(java.util.List) RebootContext(com.sequenceiq.freeipa.flow.instance.reboot.RebootContext) RebootService(com.sequenceiq.freeipa.flow.instance.reboot.RebootService) RebootInstancesResult(com.sequenceiq.cloudbreak.cloud.event.instance.RebootInstancesResult) WaitUntilAvailableFailedToInstanceFailureEventConverter(com.sequenceiq.freeipa.flow.instance.reboot.failure.WaitUntilAvailableFailedToInstanceFailureEventConverter) Optional(java.util.Optional) SuccessDetails(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails) Bean(org.springframework.context.annotation.Bean) Collections(java.util.Collections) CredentialService(com.sequenceiq.freeipa.service.CredentialService) SuccessDetails(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails) InstanceFailureEvent(com.sequenceiq.freeipa.flow.instance.InstanceFailureEvent) Optional(java.util.Optional) HealthCheckSuccess(com.sequenceiq.freeipa.flow.stack.HealthCheckSuccess) StateContext(org.springframework.statemachine.StateContext) Stack(com.sequenceiq.freeipa.entity.Stack) RebootInstanceEvent(com.sequenceiq.freeipa.flow.instance.reboot.RebootInstanceEvent) InstanceEvent(com.sequenceiq.freeipa.flow.instance.InstanceEvent) InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) FlowParameters(com.sequenceiq.flow.core.FlowParameters) OperationService(com.sequenceiq.freeipa.service.operation.OperationService) RebootContext(com.sequenceiq.freeipa.flow.instance.reboot.RebootContext) Map(java.util.Map) 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