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;
}
}
}
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;
}
}
}
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;
}
}
}
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);
}
}
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;
}
}
}
Aggregations