Search in sources :

Example 6 with SuccessDetails

use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails in project cloudbreak by hortonworks.

the class UserSyncForEnvService method synchronizeUsers.

public void synchronizeUsers(String operationId, String accountId, List<Stack> stacks, UserSyncRequestFilter userSyncFilter, UserSyncOptions options, long startTime) {
    operationService.tryWithOperationCleanup(operationId, accountId, () -> {
        Set<String> environmentCrns = stacks.stream().map(Stack::getEnvironmentCrn).collect(Collectors.toSet());
        UserSyncLogEvent logUserSyncEvent = options.isFullSync() ? FULL_USER_SYNC : PARTIAL_USER_SYNC;
        LOGGER.info("Starting {} for environments {} with operationId {} ...", logUserSyncEvent, environmentCrns, operationId);
        if (options.isFullSync()) {
            umsVirtualGroupCreateService.createVirtualGroups(accountId, stacks);
        }
        Map<String, Future<SyncStatusDetail>> statusFutures = startAsyncSyncsForStacks(operationId, accountId, stacks, userSyncFilter, options, environmentCrns);
        List<SuccessDetails> success = new ArrayList<>();
        List<FailureDetails> failure = new ArrayList<>();
        statusFutures.forEach((envCrn, statusFuture) -> {
            try {
                SyncStatusDetail statusDetail = waitForSyncStatusDetailResult(startTime, statusFuture, accountId);
                switch(statusDetail.getStatus()) {
                    case COMPLETED:
                        success.add(new SuccessDetails(envCrn));
                        break;
                    case FAILED:
                        failure.add(createFailureDetails(envCrn, statusDetail.getDetails(), statusDetail.getWarnings()));
                        break;
                    default:
                        failure.add(createFailureDetails(envCrn, "Unexpected status: " + statusDetail.getStatus(), statusDetail.getWarnings()));
                        break;
                }
            } catch (TimeoutException e) {
                LOGGER.warn("Sync timed out for env: {}", envCrn, e);
                statusFuture.cancel(true);
                failure.add(new FailureDetails(envCrn, "Timed out"));
            } catch (InterruptedException | ExecutionException e) {
                LOGGER.error("Sync is interrupted for env: {}", envCrn, e);
                failure.add(new FailureDetails(envCrn, e.getLocalizedMessage()));
            }
        });
        operationService.completeOperation(accountId, operationId, success, failure);
        LOGGER.info("Finished {} for environments {} with operationId {}.", logUserSyncEvent, environmentCrns, operationId);
    });
}
Also used : SuccessDetails(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails) ArrayList(java.util.ArrayList) FailureDetails(com.sequenceiq.freeipa.api.v1.freeipa.user.model.FailureDetails) SyncStatusDetail(com.sequenceiq.freeipa.service.freeipa.user.model.SyncStatusDetail) Future(java.util.concurrent.Future) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException)

Example 7 with SuccessDetails

use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails 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 8 with SuccessDetails

use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails 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)

Example 9 with SuccessDetails

use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails 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 10 with SuccessDetails

use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails 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

SuccessDetails (com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails)24 Stack (com.sequenceiq.freeipa.entity.Stack)14 OperationService (com.sequenceiq.freeipa.service.operation.OperationService)12 Map (java.util.Map)12 Bean (org.springframework.context.annotation.Bean)12 FailureDetails (com.sequenceiq.freeipa.api.v1.freeipa.user.model.FailureDetails)10 ArrayList (java.util.ArrayList)8 List (java.util.List)6 Test (org.junit.jupiter.api.Test)6 FlowParameters (com.sequenceiq.flow.core.FlowParameters)5 SyncStatusDetail (com.sequenceiq.freeipa.service.freeipa.user.model.SyncStatusDetail)5 UmsEventGenerationIds (com.sequenceiq.freeipa.service.freeipa.user.model.UmsEventGenerationIds)5 StateContext (org.springframework.statemachine.StateContext)5 UserSyncStatus (com.sequenceiq.freeipa.entity.UserSyncStatus)4 StackContext (com.sequenceiq.freeipa.flow.stack.StackContext)4 Optional (java.util.Optional)4 Future (java.util.concurrent.Future)4 Flow (com.sequenceiq.flow.core.Flow)3 StackEvent (com.sequenceiq.freeipa.flow.stack.StackEvent)3 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)2