Search in sources :

Example 1 with IdbmmsOperationException

use of com.sequenceiq.cloudbreak.idbmms.exception.IdbmmsOperationException in project cloudbreak by hortonworks.

the class IdBrokerMappingsDeleteHandlerTest method acceptTestEnvironmentAndIdbmmsAndFailure.

@Test
void acceptTestEnvironmentAndIdbmmsAndFailure() {
    when(environmentService.findEnvironmentById(ENVIRONMENT_ID)).thenReturn(Optional.of(createEnvironment(IdBrokerMappingSource.IDBMMS)));
    Exception exception = new IdbmmsOperationException(MESSAGE, createStatusRuntimeException(Status.Code.ABORTED));
    doThrow(exception).when(idbmmsClient).deleteMappings(INTERNAL_ACTOR_CRN, ENVIRONMENT_CRN, Optional.empty());
    underTest.accept(environmentDtoEvent);
    verify(idbmmsClient).deleteMappings(INTERNAL_ACTOR_CRN, ENVIRONMENT_CRN, Optional.empty());
    verify(mockExceptionProcessor, times(1)).handle(any(), any(), any(), any());
    verify(mockExceptionProcessor, times(1)).handle(any(HandlerFailureConjoiner.class), any(Logger.class), eq(eventSender), eq(DELETE_IDBROKER_MAPPINGS_EVENT.selector()));
}
Also used : IdbmmsOperationException(com.sequenceiq.cloudbreak.idbmms.exception.IdbmmsOperationException) Logger(org.slf4j.Logger) IdbmmsOperationException(com.sequenceiq.cloudbreak.idbmms.exception.IdbmmsOperationException) StatusRuntimeException(io.grpc.StatusRuntimeException) Test(org.junit.jupiter.api.Test)

Example 2 with IdbmmsOperationException

use of com.sequenceiq.cloudbreak.idbmms.exception.IdbmmsOperationException in project cloudbreak by hortonworks.

the class IdBrokerMappingsDeleteHandlerTest method acceptTestEnvironmentAndIdbmmsAndNoMappings.

@Test
void acceptTestEnvironmentAndIdbmmsAndNoMappings() {
    when(environmentService.findEnvironmentById(ENVIRONMENT_ID)).thenReturn(Optional.of(createEnvironment(IdBrokerMappingSource.IDBMMS)));
    doThrow(new IdbmmsOperationException(MESSAGE, createStatusRuntimeException(Status.Code.NOT_FOUND))).when(idbmmsClient).deleteMappings(INTERNAL_ACTOR_CRN, ENVIRONMENT_CRN, Optional.empty());
    underTest.accept(environmentDtoEvent);
    verify(idbmmsClient).deleteMappings(INTERNAL_ACTOR_CRN, ENVIRONMENT_CRN, Optional.empty());
    verify(eventSender).sendEvent(eventArgumentCaptor.capture(), headersArgumentCaptor.capture());
    verifyEnvDeleteEvent();
}
Also used : IdbmmsOperationException(com.sequenceiq.cloudbreak.idbmms.exception.IdbmmsOperationException) Test(org.junit.jupiter.api.Test)

Example 3 with IdbmmsOperationException

use of com.sequenceiq.cloudbreak.idbmms.exception.IdbmmsOperationException in project cloudbreak by hortonworks.

the class GrpcIdbmmsClient method deleteMappings.

/**
 * Deletes IDBroker mappings in IDBMMS for a particular environment.
 *
 * @param actorCrn the actor CRN; must not be {@code null}
 * @param environmentCrn the environment CRN to delete mappings for; must not be {@code null}
 * @param requestId an optional request ID; must not be {@code null}
 * @throws NullPointerException if either argument is {@code null}
 * @throws IdbmmsOperationException if any problem is encountered during the IDBMMS call processing
 */
public void deleteMappings(String actorCrn, String environmentCrn, Optional<String> requestId) {
    checkNotNull(actorCrn, "actorCrn should not be null.");
    checkNotNull(environmentCrn);
    checkNotNull(requestId, "requestId should not be null.");
    try (ManagedChannelWrapper channelWrapper = makeWrapper()) {
        IdbmmsClient client = makeClient(channelWrapper.getChannel(), actorCrn);
        String effectiveRequestId = requestId.orElse(UUID.randomUUID().toString());
        LOGGER.debug("Deleting IDBroker mappings for environment {} using request ID {}", environmentCrn, effectiveRequestId);
        client.deleteMappings(effectiveRequestId, environmentCrn);
        LOGGER.debug("Deleted IDBroker mappings for environment {}", environmentCrn);
    } catch (RuntimeException e) {
        throw new IdbmmsOperationException(String.format("Error during IDBMMS operation: %s", e.getMessage()), e);
    }
}
Also used : IdbmmsOperationException(com.sequenceiq.cloudbreak.idbmms.exception.IdbmmsOperationException) ManagedChannelWrapper(com.sequenceiq.cloudbreak.grpc.ManagedChannelWrapper)

Example 4 with IdbmmsOperationException

use of com.sequenceiq.cloudbreak.idbmms.exception.IdbmmsOperationException in project cloudbreak by hortonworks.

the class StackRequestManifester method setupCloudStorageAccountMapping.

@VisibleForTesting
void setupCloudStorageAccountMapping(StackV4Request stackRequest, String environmentCrn, IdBrokerMappingSource mappingSource, String cloudPlatform) {
    String stackName = stackRequest.getName();
    CloudStorageRequest cloudStorage = stackRequest.getCluster().getCloudStorage();
    if (cloudStorage != null && cloudStorage.getAccountMapping() == null) {
        // getAccountMapping() == null means we need to fetch mappings from IDBMMS.
        if (mappingSource == IdBrokerMappingSource.IDBMMS) {
            LOGGER.info("Fetching account mappings from IDBMMS associated with environment {} for stack {}.", environmentCrn, stackName);
            MappingsConfig mappingsConfig;
            try {
                // Must pass the internal actor here as this operation is internal-use only; requests with other actors will be always rejected.
                mappingsConfig = idbmmsClient.getMappingsConfig(regionAwareInternalCrnGeneratorFactory.iam().getInternalCrnForServiceAsString(), environmentCrn, Optional.empty());
                validateMappingsConfig(mappingsConfig, stackRequest);
            } catch (IdbmmsOperationException e) {
                throw new BadRequestException(String.format("Unable to get mappings: %s", e.getMessage()), e);
            }
            AccountMappingBase accountMapping = new AccountMappingBase();
            accountMapping.setGroupMappings(mappingsConfig.getGroupMappings());
            accountMapping.setUserMappings(mappingsConfig.getActorMappings());
            cloudStorage.setAccountMapping(accountMapping);
            LOGGER.info("Initial account mappings fetched from IDBMMS: {}", JsonUtil.writeValueAsStringSilent(accountMapping));
        } else {
            LOGGER.info("IDBMMS usage is disabled for environment {}. Proceeding with {} mappings for stack {}.", environmentCrn, mappingSource == IdBrokerMappingSource.MOCK && (CloudPlatform.AWS.name().equals(cloudPlatform) || CloudPlatform.AZURE.name().equals(cloudPlatform) || CloudPlatform.GCP.name().equals(cloudPlatform)) ? "mock" : "missing", stackName);
        }
    } else {
        // getAccountMapping() != null is possible only in case of SdxInternalClusterRequest, in which case the user-given values will be honored.
        LOGGER.info("{} for stack {} in environment {}.", cloudStorage == null ? "Cloud storage is disabled" : "Applying user-provided mappings", stackName, environmentCrn);
    }
}
Also used : AccountMappingBase(com.sequenceiq.common.api.cloudstorage.AccountMappingBase) CloudStorageRequest(com.sequenceiq.common.api.cloudstorage.CloudStorageRequest) MappingsConfig(com.sequenceiq.cloudbreak.idbmms.model.MappingsConfig) IdbmmsOperationException(com.sequenceiq.cloudbreak.idbmms.exception.IdbmmsOperationException) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 5 with IdbmmsOperationException

use of com.sequenceiq.cloudbreak.idbmms.exception.IdbmmsOperationException in project cloudbreak by hortonworks.

the class StackRequestManifesterTest method testSetupCloudStorageAccountMappingWhenCloudStorageWithNoAccountMappingAndIdbmmsSourceAndFailure.

@Test
public void testSetupCloudStorageAccountMappingWhenCloudStorageWithNoAccountMappingAndIdbmmsSourceAndFailure() {
    when(stackV4Request.getCluster()).thenReturn(clusterV4Request);
    when(stackV4Request.getName()).thenReturn(STACK_NAME);
    when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn");
    when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
    when(idbmmsClient.getMappingsConfig("crn", BAD_ENVIRONMENT_CRN, Optional.empty())).thenThrow(new IdbmmsOperationException("Houston, we have a problem."));
    clusterV4Request.setCloudStorage(cloudStorage);
    Assertions.assertThrows(BadRequestException.class, () -> underTest.setupCloudStorageAccountMapping(stackV4Request, BAD_ENVIRONMENT_CRN, IdBrokerMappingSource.IDBMMS, CLOUD_PLATFORM_AWS));
}
Also used : IdbmmsOperationException(com.sequenceiq.cloudbreak.idbmms.exception.IdbmmsOperationException) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

IdbmmsOperationException (com.sequenceiq.cloudbreak.idbmms.exception.IdbmmsOperationException)6 Test (org.junit.jupiter.api.Test)3 ManagedChannelWrapper (com.sequenceiq.cloudbreak.grpc.ManagedChannelWrapper)2 MappingsConfig (com.sequenceiq.cloudbreak.idbmms.model.MappingsConfig)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)1 AccountMappingBase (com.sequenceiq.common.api.cloudstorage.AccountMappingBase)1 CloudStorageRequest (com.sequenceiq.common.api.cloudstorage.CloudStorageRequest)1 StatusRuntimeException (io.grpc.StatusRuntimeException)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 Logger (org.slf4j.Logger)1