Search in sources :

Example 1 with UmsOperationException

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;
        }
    }
}
Also used : UmsOperationException(com.sequenceiq.cloudbreak.auth.altus.exception.UmsOperationException) StatusRuntimeException(io.grpc.StatusRuntimeException) Retryable(org.springframework.retry.annotation.Retryable)

Example 2 with UmsOperationException

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;
        }
    }
}
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 3 with UmsOperationException

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());
}
Also used : UmsOperationException(com.sequenceiq.cloudbreak.auth.altus.exception.UmsOperationException) EnvDeleteEvent(com.sequenceiq.environment.environment.flow.deletion.event.EnvDeleteEvent) Environment(com.sequenceiq.environment.environment.domain.Environment) Test(org.junit.jupiter.api.Test)

Example 4 with UmsOperationException

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;
        }
    }
}
Also used : UmsOperationException(com.sequenceiq.cloudbreak.auth.altus.exception.UmsOperationException) StatusRuntimeException(io.grpc.StatusRuntimeException) Retryable(org.springframework.retry.annotation.Retryable)

Example 5 with UmsOperationException

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

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