Search in sources :

Example 21 with SuccessDetails

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

Example 22 with SuccessDetails

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

the class PasswordService method internalSetPasswords.

private void internalSetPasswords(String operationId, String accountId, String userCrn, String password, List<Stack> stacks) {
    try {
        String userId = getUserIdFromUserCrn(userCrn);
        Optional<Instant> expirationInstant = calculateExpirationTime(userCrn, accountId);
        List<SetPasswordRequest> requests = new ArrayList<>();
        for (Stack stack : stacks) {
            requests.add(triggerSetPassword(stack, stack.getEnvironmentCrn(), userId, userCrn, password, expirationInstant));
        }
        List<SuccessDetails> success = new ArrayList<>();
        List<FailureDetails> failure = new ArrayList<>();
        for (SetPasswordRequest request : requests) {
            try {
                waitSetPassword(request);
                success.add(new SuccessDetails(request.getEnvironment()));
            } catch (InterruptedException e) {
                LOGGER.error("Interrupted while setting passwords for user {} in account {}", userCrn, accountId);
                throw e;
            } catch (Exception e) {
                LOGGER.debug("Failed to set password for user {} in environment {}", userCrn, request.getEnvironment(), e);
                failure.add(new FailureDetails(request.getEnvironment(), e.getLocalizedMessage()));
            }
        }
        operationService.completeOperation(accountId, operationId, success, failure);
    } catch (InterruptedException e) {
        operationService.failOperation(accountId, operationId, e.getLocalizedMessage());
        Thread.currentThread().interrupt();
    } catch (RuntimeException e) {
        operationService.failOperation(accountId, operationId, e.getLocalizedMessage());
        throw e;
    }
}
Also used : SuccessDetails(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails) Instant(java.time.Instant) ArrayList(java.util.ArrayList) FailureDetails(com.sequenceiq.freeipa.api.v1.freeipa.user.model.FailureDetails) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) OperationException(com.sequenceiq.cloudbreak.service.OperationException) Stack(com.sequenceiq.freeipa.entity.Stack) SetPasswordRequest(com.sequenceiq.freeipa.flow.freeipa.user.event.SetPasswordRequest)

Example 23 with SuccessDetails

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

the class FreeIpaUpgradeCcmService method alreadyFinishedOperationStatus.

private OperationStatus alreadyFinishedOperationStatus(String environmentCrn) {
    SuccessDetails successDetails = new SuccessDetails(environmentCrn);
    long timestamp = System.currentTimeMillis();
    return new OperationStatus(UUID.randomUUID().toString(), OperationType.UPGRADE_CCM, OperationState.COMPLETED, List.of(successDetails), null, null, timestamp, timestamp);
}
Also used : SuccessDetails(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails) OperationStatus(com.sequenceiq.freeipa.api.v1.operation.model.OperationStatus)

Example 24 with SuccessDetails

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

the class UserSyncService method internalSynchronizeUsers.

private void internalSynchronizeUsers(String operationId, String accountId, List<Stack> stacks, UserSyncRequestFilter userSyncFilter, UserSyncOptions options) {
    tryWithOperationCleanup(operationId, accountId, () -> {
        Set<String> environmentCrns = stacks.stream().map(Stack::getEnvironmentCrn).collect(Collectors.toSet());
        Optional<String> requestId = MDCUtils.getRequestId();
        UmsEventGenerationIds umsEventGenerationIds = options.isFullSync() ? umsEventGenerationIdsProvider.getEventGenerationIds(accountId, requestId) : null;
        LogEvent logUserSyncEvent = options.isFullSync() ? LogEvent.FULL_USER_SYNC : LogEvent.PARTIAL_USER_SYNC;
        LOGGER.info("Starting {} for environments {} with operationId {} ...", logUserSyncEvent, environmentCrns, operationId);
        Map<String, Future<SyncStatusDetail>> statusFutures;
        if (userSyncFilter.getDeletedWorkloadUser().isEmpty()) {
            LogEvent logRetrieveUmsEvent = options.isFullSync() ? LogEvent.RETRIEVE_FULL_UMS_STATE : LogEvent.RETRIEVE_PARTIAL_UMS_STATE;
            LOGGER.debug("Starting {} for environments {} ...", logRetrieveUmsEvent, environmentCrns);
            Map<String, UmsUsersState> envToUmsStateMap = umsUsersStateProviderDispatcher.getEnvToUmsUsersStateMap(accountId, environmentCrns, userSyncFilter.getUserCrnFilter(), userSyncFilter.getMachineUserCrnFilter(), requestId);
            LOGGER.debug("Finished {}.", logRetrieveUmsEvent);
            statusFutures = stacks.stream().collect(Collectors.toMap(Stack::getEnvironmentCrn, stack -> asyncSynchronizeStack(stack, envToUmsStateMap.get(stack.getEnvironmentCrn()), umsEventGenerationIds, options, operationId, accountId)));
        } else {
            String deletedWorkloadUser = userSyncFilter.getDeletedWorkloadUser().get();
            statusFutures = stacks.stream().collect(Collectors.toMap(Stack::getEnvironmentCrn, stack -> asyncSynchronizeStackForDeleteUser(stack, deletedWorkloadUser)));
        }
        List<SuccessDetails> success = new ArrayList<>();
        List<FailureDetails> failure = new ArrayList<>();
        statusFutures.forEach((envCrn, statusFuture) -> {
            try {
                SyncStatusDetail statusDetail = statusFuture.get();
                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 (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) UmsUsersState(com.sequenceiq.freeipa.service.freeipa.user.model.UmsUsersState) ArrayList(java.util.ArrayList) FailureDetails(com.sequenceiq.freeipa.api.v1.freeipa.user.model.FailureDetails) Stack(com.sequenceiq.freeipa.entity.Stack) UmsEventGenerationIds(com.sequenceiq.freeipa.service.freeipa.user.model.UmsEventGenerationIds) SyncStatusDetail(com.sequenceiq.freeipa.service.freeipa.user.model.SyncStatusDetail) Future(java.util.concurrent.Future) ExecutionException(java.util.concurrent.ExecutionException)

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