use of com.sequenceiq.cloudbreak.auth.altus.exception.UmsOperationException in project cloudbreak by hortonworks.
the class GrpcUmsClient method assignMachineUserRole.
/**
* Add role to machine user
*
* @param userCrn actor that will assign the role
* @param machineUserCrn machine user
* @param roleCrn role that will be assigned
* @param requestId id for the request
*/
@Retryable(value = UmsOperationException.class, maxAttempts = 10, backoff = @Backoff(delay = 5000))
public void assignMachineUserRole(String userCrn, String accountId, String machineUserCrn, String roleCrn, Optional<String> requestId) {
try {
UmsClient client = makeClient(channelWrapper.getChannel());
client.assignMachineUserRole(RequestIdUtil.getOrGenerate(requestId), userCrn, accountId, machineUserCrn, roleCrn);
} catch (StatusRuntimeException ex) {
if (Status.UNAVAILABLE.getCode().equals(ex.getStatus().getCode())) {
String errMessage = String.format("Cannot assign role '%s' to machine user '%s' as " + "UMS API is UNAVAILABLE at the moment", machineUserCrn, roleCrn);
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 createMachineUser.
/**
* Creates new machine user, it queries against the machine user if it has already exist
*
* @param machineUserName new machine user name
* @param userCrn the CRN of the user
* @param requestId an optional request Id
* @return the machine user crn
*/
@Retryable(value = UmsOperationException.class, maxAttempts = 10, backoff = @Backoff(delay = 5000))
public Optional<String> createMachineUser(String machineUserName, String userCrn, String accountId, Optional<String> requestId) {
try {
UmsClient client = makeClient(channelWrapper.getChannel());
String generatedRequestId = RequestIdUtil.getOrGenerate(requestId);
LOGGER.debug("Creating machine user {} for {} using request ID {}", machineUserName, userCrn, generatedRequestId);
Optional<String> machineUserCrn = client.createMachineUser(generatedRequestId, userCrn, accountId, machineUserName);
if (machineUserCrn.isEmpty()) {
MachineUser machineUser = client.getMachineUserForUser(RequestIdUtil.getOrGenerate(requestId), userCrn, accountId, machineUserName, true, true);
machineUserCrn = Optional.of(machineUser.getCrn());
}
LOGGER.debug("Machine User information retrieved for userCrn: {}", machineUserCrn.orElse(null));
return machineUserCrn;
} catch (StatusRuntimeException ex) {
if (Status.NOT_FOUND.getCode().equals(ex.getStatus().getCode())) {
String errMessage = String.format("Machine user with name %s is not found yet", machineUserName);
LOGGER.debug(errMessage, ex);
throw new UmsOperationException(errMessage, ex);
} else if (Status.UNAVAILABLE.getCode().equals(ex.getStatus().getCode())) {
String errMessage = String.format("Cannot create machinue user '%s' for '%s' as " + "UMS API is UNAVAILABLE at the moment", machineUserName, userCrn);
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 EnvironmentUMSResourceDeleteHandlerTest method testAcceptWithException.
@Test
public void testAcceptWithException() {
// GIVEN
given(environmentDtoEvent.getData()).willReturn(environmentDeletionDto);
given(environmentDeletionDto.getEnvironmentDto()).willReturn(environmentDto);
given(environmentDto.getResourceCrn()).willReturn(TEST_CRN);
given(environmentService.findEnvironmentById(any())).willReturn(Optional.of(new Environment()));
doThrow(new UmsOperationException("ums exception")).when(ownerAssignmentService).notifyResourceDeleted(eq(TEST_CRN), any());
// WHEN
underTest.accept(environmentDtoEvent);
// THEN
verify(environmentService, times(1)).findEnvironmentById(any());
verify(ownerAssignmentService, times(1)).notifyResourceDeleted(eq(TEST_CRN), any());
verify(eventSender, times(1)).sendEvent(any(EnvDeleteEvent.class), any());
}
use of com.sequenceiq.cloudbreak.auth.altus.exception.UmsOperationException in project cloudbreak by hortonworks.
the class GrpcUmsClient method assignMachineUserRole.
/**
* Add role to machine user
*
* @param userCrn actor that will assign the role
* @param machineUserCrn machine user
* @param roleCrn role that will be assigned
* @param requestId id for the request
*/
@Retryable(value = UmsOperationException.class, maxAttempts = 10, backoff = @Backoff(delay = 5000))
public void assignMachineUserRole(String userCrn, String accountId, String machineUserCrn, String roleCrn, Optional<String> requestId, RegionAwareInternalCrnGeneratorFactory regionAwareInternalCrnGeneratorFactory) {
try {
UmsClient client = makeClient(channelWrapper.getChannel(), regionAwareInternalCrnGeneratorFactory);
client.assignMachineUserRole(RequestIdUtil.getOrGenerate(requestId), userCrn, accountId, machineUserCrn, roleCrn);
} catch (StatusRuntimeException ex) {
if (Status.UNAVAILABLE.getCode().equals(ex.getStatus().getCode())) {
String errMessage = String.format("Cannot assign role '%s' to machine user '%s' as " + "UMS API is UNAVAILABLE at the moment", machineUserCrn, roleCrn);
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 createMachineUser.
/**
* Creates new machine user, it queries against the machine user if it has already exist
*
* @param machineUserName new machine user name
* @param userCrn the CRN of the user
* @param requestId an optional request Id
* @return the machine user crn
*/
@Retryable(value = UmsOperationException.class, maxAttempts = 10, backoff = @Backoff(delay = 5000))
public Optional<String> createMachineUser(String machineUserName, String userCrn, String accountId, Optional<String> requestId, RegionAwareInternalCrnGeneratorFactory regionAwareInternalCrnGeneratorFactory) {
try {
UmsClient client = makeClient(channelWrapper.getChannel(), regionAwareInternalCrnGeneratorFactory);
String generatedRequestId = RequestIdUtil.getOrGenerate(requestId);
LOGGER.debug("Creating machine user {} for {} using request ID {}", machineUserName, userCrn, generatedRequestId);
Optional<String> machineUserCrn = client.createMachineUser(generatedRequestId, userCrn, accountId, machineUserName);
if (machineUserCrn.isEmpty()) {
MachineUser machineUser = client.getMachineUserForUser(RequestIdUtil.getOrGenerate(requestId), userCrn, accountId, machineUserName, true, true);
machineUserCrn = Optional.of(machineUser.getCrn());
}
LOGGER.debug("Machine User information retrieved for userCrn: {}", machineUserCrn.orElse(null));
return machineUserCrn;
} catch (StatusRuntimeException ex) {
if (Status.NOT_FOUND.getCode().equals(ex.getStatus().getCode())) {
String errMessage = String.format("Machine user with name %s is not found yet", machineUserName);
LOGGER.debug(errMessage, ex);
throw new UmsOperationException(errMessage, ex);
} else if (Status.UNAVAILABLE.getCode().equals(ex.getStatus().getCode())) {
String errMessage = String.format("Cannot create machinue user '%s' for '%s' as " + "UMS API is UNAVAILABLE at the moment", machineUserName, userCrn);
LOGGER.debug(errMessage, ex);
throw new UmsOperationException(errMessage, ex);
} else {
throw ex;
}
}
}
Aggregations