Search in sources :

Example 21 with Operation

use of com.sequenceiq.freeipa.entity.Operation in project cloudbreak by hortonworks.

the class OperationService method getOperationForAccountIdAndOperationId.

public Operation getOperationForAccountIdAndOperationId(String accountId, String operationId) {
    Optional<Operation> operationOptional = operationRepository.findByOperationIdAndAccountId(operationId, accountId);
    if (!operationOptional.isPresent()) {
        LOGGER.info("Operation [{}] in account [{}] not found", operationId, accountId);
        throw NotFoundException.notFound("Operation", operationId).get();
    } else {
        Operation operation = operationOptional.get();
        LOGGER.debug("Operation found: {}", operation);
        return operation;
    }
}
Also used : Operation(com.sequenceiq.freeipa.entity.Operation)

Example 22 with Operation

use of com.sequenceiq.freeipa.entity.Operation in project cloudbreak by hortonworks.

the class OperationService method startOperation.

public Operation startOperation(String accountId, OperationType operationType, Collection<String> environmentCrns, Collection<String> userCrns) {
    Operation requestedOperation = requestOperation(accountId, operationType, environmentCrns, userCrns);
    OperationAcceptor acceptor = operationAcceptorMap.get(operationType);
    AcceptResult acceptResult = acceptor.accept(requestedOperation);
    if (acceptResult.isAccepted()) {
        return acceptOperation(requestedOperation);
    } else {
        return rejectOperation(requestedOperation, acceptResult.getRejectionMessage().orElse("Rejected for unspecified reason."));
    }
}
Also used : Operation(com.sequenceiq.freeipa.entity.Operation) AcceptResult(com.sequenceiq.freeipa.service.freeipa.user.AcceptResult)

Example 23 with Operation

use of com.sequenceiq.freeipa.entity.Operation in project cloudbreak by hortonworks.

the class UserSyncService method performSyncForStacks.

private Operation performSyncForStacks(String accountId, UserSyncRequestFilter userSyncFilter, UserSyncOptions options, List<Stack> stacks) {
    logAffectedStacks(stacks);
    Set<String> environmentCrns = stacks.stream().map(Stack::getEnvironmentCrn).collect(Collectors.toSet());
    Operation operation = operationService.startOperation(accountId, OperationType.USER_SYNC, environmentCrns, union(userSyncFilter.getUserCrnFilter(), userSyncFilter.getMachineUserCrnFilter()));
    LOGGER.info("Starting operation [{}] with status [{}]", operation.getOperationId(), operation.getStatus());
    if (operation.getStatus() == OperationState.RUNNING) {
        operationService.tryWithOperationCleanup(operation.getOperationId(), accountId, () -> ThreadBasedUserCrnProvider.doAs(regionAwareInternalCrnGeneratorFactory.iam().getInternalCrnForServiceAsString(), () -> {
            if (userSyncFilter.isFullSync()) {
                stacks.forEach(stack -> updateUserSyncStatusForStack(operation, stack));
            }
            asyncSynchronizeUsers(operation.getOperationId(), accountId, stacks, userSyncFilter, options);
        }));
    }
    return operation;
}
Also used : EntitlementService(com.sequenceiq.cloudbreak.auth.altus.EntitlementService) LoggerFactory(org.slf4j.LoggerFactory) CustomCheckUtil(com.sequenceiq.authorization.service.CustomCheckUtil) MDCBuilder(com.sequenceiq.cloudbreak.logger.MDCBuilder) Inject(javax.inject.Inject) Value(org.springframework.beans.factory.annotation.Value) Future(java.util.concurrent.Future) ThreadBasedUserCrnProvider(com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider) Service(org.springframework.stereotype.Service) Operation(com.sequenceiq.freeipa.entity.Operation) Map(java.util.Map) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Qualifier(org.springframework.beans.factory.annotation.Qualifier) WorkloadCredentialsUpdateType(com.sequenceiq.freeipa.api.v1.freeipa.user.model.WorkloadCredentialsUpdateType) OperationType(com.sequenceiq.freeipa.api.v1.operation.model.OperationType) UsersyncConfig(com.sequenceiq.freeipa.configuration.UsersyncConfig) StackService(com.sequenceiq.freeipa.service.stack.StackService) CommonPermissionCheckingUtils(com.sequenceiq.authorization.service.CommonPermissionCheckingUtils) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) ExecutorService(java.util.concurrent.ExecutorService) Stack(com.sequenceiq.freeipa.entity.Stack) Logger(org.slf4j.Logger) OperationState(com.sequenceiq.freeipa.api.v1.operation.model.OperationState) UserSyncOptions(com.sequenceiq.freeipa.service.freeipa.user.model.UserSyncOptions) Collection(java.util.Collection) Set(java.util.Set) UserSyncStatus(com.sequenceiq.freeipa.entity.UserSyncStatus) Collectors(java.util.stream.Collectors) RegionAwareInternalCrnGeneratorFactory(com.sequenceiq.cloudbreak.auth.crn.RegionAwareInternalCrnGeneratorFactory) OperationService(com.sequenceiq.freeipa.service.operation.OperationService) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Stream(java.util.stream.Stream) Optional(java.util.Optional) AuthorizationResourceAction(com.sequenceiq.authorization.resource.AuthorizationResourceAction) Operation(com.sequenceiq.freeipa.entity.Operation)

Example 24 with Operation

use of com.sequenceiq.freeipa.entity.Operation in project cloudbreak by hortonworks.

the class EnvironmentUserSyncStateCalculator method createExceptionForUnexpectedOperationStatus.

private IllegalStateException createExceptionForUnexpectedOperationStatus(String envCrnString, UserSyncStatus userSyncStatus) {
    Operation lastSync = userSyncStatus.getLastStartedFullSync();
    LOGGER.error("UserSyncStatus.lastStartedFullSync '{}' in unexpected state {} for environment '{}'", lastSync, lastSync.getStatus(), envCrnString);
    return new IllegalStateException(String.format("Last sync operation [%s] for environment '%s' is in unexpected state %s", lastSync.getOperationId(), envCrnString, lastSync.getStatus()));
}
Also used : Operation(com.sequenceiq.freeipa.entity.Operation)

Example 25 with Operation

use of com.sequenceiq.freeipa.entity.Operation in project cloudbreak by hortonworks.

the class BindUserCreateService method createBindUser.

public OperationStatus createBindUser(String accountId, BindUserCreateRequest request) {
    Stack stack = stackService.getByEnvironmentCrnAndAccountId(request.getEnvironmentCrn(), accountId);
    MDCBuilder.buildMdcContext(stack);
    LOGGER.info("Start 'BIND_USER_CREATE' operation from request: {}", request);
    Operation operation = operationService.startOperation(accountId, OperationType.BIND_USER_CREATE, List.of(request.getEnvironmentCrn()), List.of(request.getBindUserNameSuffix()));
    if (RUNNING == operation.getStatus()) {
        return operationConverter.convert(startCreateBindUserFLow(accountId, request, stack.getId(), operation));
    } else {
        LOGGER.info("Operation isn't in RUNNING state: {}", operation);
        return operationConverter.convert(operation);
    }
}
Also used : Operation(com.sequenceiq.freeipa.entity.Operation) Stack(com.sequenceiq.freeipa.entity.Stack)

Aggregations

Operation (com.sequenceiq.freeipa.entity.Operation)88 Test (org.junit.jupiter.api.Test)55 Stack (com.sequenceiq.freeipa.entity.Stack)23 UserSyncStatus (com.sequenceiq.freeipa.entity.UserSyncStatus)18 SyncOperationStatus (com.sequenceiq.freeipa.api.v1.freeipa.user.model.SyncOperationStatus)15 OperationToSyncOperationStatus (com.sequenceiq.freeipa.converter.freeipa.user.OperationToSyncOperationStatus)12 AcceptResult (com.sequenceiq.freeipa.service.freeipa.user.AcceptResult)11 UserSyncRequestFilter (com.sequenceiq.freeipa.service.freeipa.user.UserSyncRequestFilter)10 InstanceMetaData (com.sequenceiq.freeipa.entity.InstanceMetaData)9 FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)8 EnvironmentUserSyncState (com.sequenceiq.freeipa.api.v1.freeipa.user.model.EnvironmentUserSyncState)7 OperationType (com.sequenceiq.freeipa.api.v1.operation.model.OperationType)7 OperationStatus (com.sequenceiq.freeipa.api.v1.operation.model.OperationStatus)6 UserSyncOptions (com.sequenceiq.freeipa.service.freeipa.user.model.UserSyncOptions)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 Acceptable (com.sequenceiq.cloudbreak.common.event.Acceptable)5 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)5 FreeIpaUpgradeResponse (com.sequenceiq.freeipa.api.v1.freeipa.upgrade.model.FreeIpaUpgradeResponse)4 SynchronizeAllUsersRequest (com.sequenceiq.freeipa.api.v1.freeipa.user.model.SynchronizeAllUsersRequest)4 CustomPermissionCheck (com.sequenceiq.authorization.annotation.CustomPermissionCheck)3