Search in sources :

Example 6 with UmsOperationException

use of com.sequenceiq.cloudbreak.auth.altus.exception.UmsOperationException in project cloudbreak by hortonworks.

the class GrpcUmsClient method assignMachineUserResourceRole.

@Retryable(value = UmsOperationException.class, maxAttempts = 10, backoff = @Backoff(delay = 5000))
public void assignMachineUserResourceRole(String accountId, String machineUserCrn, String resourceRoleCrn, String resourceCrn, Optional<String> requestId, RegionAwareInternalCrnGeneratorFactory regionAwareInternalCrnGeneratorFactory) {
    try {
        UmsClient client = makeClient(channelWrapper.getChannel(), regionAwareInternalCrnGeneratorFactory);
        client.assignMachineUserResourceRole(RequestIdUtil.getOrGenerate(requestId), accountId, machineUserCrn, resourceRoleCrn, resourceCrn);
    } catch (StatusRuntimeException ex) {
        if (Status.UNAVAILABLE.getCode().equals(ex.getStatus().getCode())) {
            String errMessage = String.format("Cannot assign resource role '%s' to machine user '%s' and resource '%s' as " + "UMS API is UNAVAILABLE at the moment", machineUserCrn, resourceRoleCrn, resourceCrn);
            LOGGER.debug(errMessage, ex);
            throw new UmsOperationException(errMessage, ex);
        } else {
            throw ex;
        }
    }
}
Also used : UmsOperationException(com.sequenceiq.cloudbreak.auth.altus.exception.UmsOperationException) StatusRuntimeException(io.grpc.StatusRuntimeException) Retryable(org.springframework.retry.annotation.Retryable)

Example 7 with UmsOperationException

use of com.sequenceiq.cloudbreak.auth.altus.exception.UmsOperationException in project cloudbreak by hortonworks.

the class GrpcUmsClient method getOrCreateMachineUserWithoutAccessKey.

/**
 * Get or Create new machine user for given machineUserName.
 *
 * @param machineUserName new machine user name
 * @param accountId       the accountId
 * @param requestId       an optional request Id
 * @return the machineUser
 */
@Retryable(value = UmsOperationException.class, maxAttempts = 10, backoff = @Backoff(delay = 5000))
public MachineUser getOrCreateMachineUserWithoutAccessKey(String machineUserName, String accountId, Optional<String> requestId) {
    try {
        UmsClient client = makeClient(channelWrapper.getChannel(), regionAwareInternalCrnGeneratorFactory);
        String generatedRequestId = RequestIdUtil.getOrGenerate(requestId);
        LOGGER.debug("Creating machine user {} for accountId {} using request ID {}", machineUserName, accountId, generatedRequestId);
        MachineUser machineUser = client.getOrCreateMachineUserWithoutAccessKey(generatedRequestId, accountId, machineUserName);
        LOGGER.debug("Machine User retrieved for machineUserName: {}, machineUser: {}", machineUserName, machineUser);
        return machineUser;
    } catch (StatusRuntimeException ex) {
        if (Status.UNAVAILABLE.getCode().equals(ex.getStatus().getCode())) {
            String errMessage = String.format("Cannot create machine user '%s' for '%s' as " + "UMS API is UNAVAILABLE at the moment", machineUserName, accountId);
            LOGGER.debug(errMessage, ex);
            throw new UmsOperationException(errMessage, ex);
        } else {
            throw ex;
        }
    }
}
Also used : UmsOperationException(com.sequenceiq.cloudbreak.auth.altus.exception.UmsOperationException) StatusRuntimeException(io.grpc.StatusRuntimeException) MachineUser(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.MachineUser) Retryable(org.springframework.retry.annotation.Retryable)

Example 8 with UmsOperationException

use of com.sequenceiq.cloudbreak.auth.altus.exception.UmsOperationException in project cloudbreak by hortonworks.

the class GrpcUmsClient method generateAccessSecretKeyPair.

/**
 * Generate access / private keypair
 *
 * @param actorCrn       actor that executes the key generation
 * @param machineUserCrn machine user (owner of the access key)
 * @param requestId      id for the request
 * @param accessKeyType  algorithm type used for the access key
 * @return access / private key holder object
 */
@Retryable(value = UmsOperationException.class, maxAttempts = 10, backoff = @Backoff(delay = 5000))
public AltusCredential generateAccessSecretKeyPair(String actorCrn, String accountId, String machineUserCrn, Optional<String> requestId, AccessKeyType.Value accessKeyType, RegionAwareInternalCrnGeneratorFactory regionAwareInternalCrnGeneratorFactory) {
    try {
        UmsClient client = makeClient(channelWrapper.getChannel(), regionAwareInternalCrnGeneratorFactory);
        LOGGER.info("Generating new access / secret key pair for {}", machineUserCrn);
        CreateAccessKeyResponse accessKeyResponse = client.createAccessPrivateKeyPair(RequestIdUtil.getOrGenerate(requestId), actorCrn, accountId, machineUserCrn, accessKeyType);
        return new AltusCredential(accessKeyResponse.getAccessKey().getAccessKeyId(), accessKeyResponse.getPrivateKey().toCharArray());
    } catch (StatusRuntimeException ex) {
        if (Status.UNAVAILABLE.getCode().equals(ex.getStatus().getCode())) {
            String errMessage = String.format("Cannot generate access key pair for machine user '%s' as " + "UMS API is UNAVAILABLE at the moment", machineUserCrn);
            LOGGER.debug(errMessage, ex);
            throw new UmsOperationException(errMessage, ex);
        } else {
            throw ex;
        }
    }
}
Also used : UmsOperationException(com.sequenceiq.cloudbreak.auth.altus.exception.UmsOperationException) AltusCredential(com.sequenceiq.cloudbreak.auth.altus.model.AltusCredential) CreateAccessKeyResponse(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.CreateAccessKeyResponse) StatusRuntimeException(io.grpc.StatusRuntimeException) Retryable(org.springframework.retry.annotation.Retryable)

Example 9 with UmsOperationException

use of com.sequenceiq.cloudbreak.auth.altus.exception.UmsOperationException in project cloudbreak by hortonworks.

the class UmsUsersStateProviderDispatcher method getEnvToUmsUsersStateMap.

public Map<String, UmsUsersState> getEnvToUmsUsersStateMap(String accountId, Collection<String> environmentCrns, Set<String> userCrns, Set<String> machineUserCrns, Optional<String> requestIdOptional) {
    try {
        LOGGER.debug("Getting UMS state for environments {} with requestId {}", environmentCrns, requestIdOptional);
        boolean fullSync = userCrns.isEmpty() && machineUserCrns.isEmpty();
        if (fullSync) {
            return dispatchBulk(accountId, environmentCrns, userCrns, machineUserCrns, requestIdOptional, fullSync);
        } else {
            return dispatchDefault(accountId, environmentCrns, userCrns, machineUserCrns, requestIdOptional, fullSync);
        }
    } catch (RuntimeException e) {
        throw new UmsOperationException(String.format("Error during UMS operation: '%s'", e.getLocalizedMessage()), e);
    }
}
Also used : UmsOperationException(com.sequenceiq.cloudbreak.auth.altus.exception.UmsOperationException)

Example 10 with UmsOperationException

use of com.sequenceiq.cloudbreak.auth.altus.exception.UmsOperationException in project cloudbreak by hortonworks.

the class GrpcUmsClient method generateAccessSecretKeyPair.

/**
 * Generate access / private keypair
 *
 * @param actorCrn       actor that executes the key generation
 * @param machineUserCrn machine user (owner of the access key)
 * @param requestId      id for the request
 * @param accessKeyType  algorithm type used for the access key
 * @return access / private key holder object
 */
@Retryable(value = UmsOperationException.class, maxAttempts = 10, backoff = @Backoff(delay = 5000))
public AltusCredential generateAccessSecretKeyPair(String actorCrn, String accountId, String machineUserCrn, Optional<String> requestId, AccessKeyType.Value accessKeyType) {
    try {
        UmsClient client = makeClient(channelWrapper.getChannel());
        LOGGER.info("Generating new access / secret key pair for {}", machineUserCrn);
        CreateAccessKeyResponse accessKeyResponse = client.createAccessPrivateKeyPair(RequestIdUtil.getOrGenerate(requestId), actorCrn, accountId, machineUserCrn, accessKeyType);
        return new AltusCredential(accessKeyResponse.getAccessKey().getAccessKeyId(), accessKeyResponse.getPrivateKey().toCharArray());
    } catch (StatusRuntimeException ex) {
        if (Status.UNAVAILABLE.getCode().equals(ex.getStatus().getCode())) {
            String errMessage = String.format("Cannot generate access key pair for machine user '%s' as " + "UMS API is UNAVAILABLE at the moment", machineUserCrn);
            LOGGER.debug(errMessage, ex);
            throw new UmsOperationException(errMessage, ex);
        } else {
            throw ex;
        }
    }
}
Also used : UmsOperationException(com.sequenceiq.cloudbreak.auth.altus.exception.UmsOperationException) AltusCredential(com.sequenceiq.cloudbreak.auth.altus.model.AltusCredential) CreateAccessKeyResponse(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.CreateAccessKeyResponse) StatusRuntimeException(io.grpc.StatusRuntimeException) Retryable(org.springframework.retry.annotation.Retryable)

Aggregations

UmsOperationException (com.sequenceiq.cloudbreak.auth.altus.exception.UmsOperationException)10 StatusRuntimeException (io.grpc.StatusRuntimeException)8 Retryable (org.springframework.retry.annotation.Retryable)8 MachineUser (com.cloudera.thunderhead.service.usermanagement.UserManagementProto.MachineUser)3 CreateAccessKeyResponse (com.cloudera.thunderhead.service.usermanagement.UserManagementProto.CreateAccessKeyResponse)2 AltusCredential (com.sequenceiq.cloudbreak.auth.altus.model.AltusCredential)2 Environment (com.sequenceiq.environment.environment.domain.Environment)1 EnvDeleteEvent (com.sequenceiq.environment.environment.flow.deletion.event.EnvDeleteEvent)1 Test (org.junit.jupiter.api.Test)1