Search in sources :

Example 21 with SpiFileSystem

use of com.sequenceiq.cloudbreak.cloud.model.SpiFileSystem in project cloudbreak by hortonworks.

the class AzureIDBrokerObjectStorageValidatorTest method testValidateObjectStorageNonExistingMapperIdentity.

@Test
public void testValidateObjectStorageNonExistingMapperIdentity() {
    SpiFileSystem fileSystem = setupSpiFileSystem(true);
    PagedList<Identity> identityPagedList = Mockito.spy(PagedList.class);
    identityPagedList.add(assumer);
    identityPagedList.add(logger);
    when(client.listIdentities()).thenReturn(identityPagedList);
    new RoleASsignmentBuilder(client).withAssignment(ASSUMER_IDENTITY_PRINCIPAL_ID, SUBSCRIPTION_FULL_ID).withAssignment(LOG_IDENTITY_PRINCIPAL_ID, STORAGE_RESOURCE_GROUP_NAME);
    ValidationResultBuilder resultBuilder = new ValidationResultBuilder();
    underTest.validateObjectStorage(client, fileSystem, STORAGE_LOCATION_RANGER, null, null, resultBuilder);
    ValidationResult validationResult = resultBuilder.build();
    assertTrue(validationResult.hasError());
    assertEquals(2, validationResult.getErrors().size());
    List<String> actual = validationResult.getErrors();
    assertTrue(actual.stream().anyMatch(item -> item.contains(String.format("Identity with id %s does not exist in the given Azure subscription.", USER_IDENTITY_1))));
    assertTrue(actual.stream().anyMatch(item -> item.contains(String.format("Identity with id %s does not exist in the given Azure subscription.", GROUP_IDENTITY_1))));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) AzureClient(com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient) AdlsGen2Config(com.sequenceiq.cloudbreak.telemetry.fluent.cloud.AdlsGen2Config) StorageAccount(com.microsoft.azure.management.storage.StorageAccount) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) Identity(com.microsoft.azure.management.msi.Identity) SpiFileSystem(com.sequenceiq.cloudbreak.cloud.model.SpiFileSystem) AccountMappingBase(com.sequenceiq.common.api.cloudstorage.AccountMappingBase) PagedList(com.microsoft.azure.PagedList) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) Map(java.util.Map) Spy(org.mockito.Spy) ResourceGroup(com.microsoft.azure.management.resources.ResourceGroup) Before(org.junit.Before) InjectMocks(org.mockito.InjectMocks) Subscription(com.microsoft.azure.management.resources.Subscription) AzureStorage(com.sequenceiq.cloudbreak.cloud.azure.AzureStorage) AdlsGen2ConfigGenerator(com.sequenceiq.cloudbreak.telemetry.fluent.cloud.AdlsGen2ConfigGenerator) CloudStorageCdpService(com.sequenceiq.common.model.CloudStorageCdpService) StorageLocationBase(com.sequenceiq.common.api.cloudstorage.StorageLocationBase) Assert.assertTrue(org.junit.Assert.assertTrue) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) CloudFileSystemView(com.sequenceiq.cloudbreak.cloud.model.filesystem.CloudFileSystemView) Mockito.verify(org.mockito.Mockito.verify) CloudAdlsGen2View(com.sequenceiq.cloudbreak.cloud.model.filesystem.CloudAdlsGen2View) Mockito(org.mockito.Mockito) List(java.util.List) Assert.assertFalse(org.junit.Assert.assertFalse) FileSystemType(com.sequenceiq.common.model.FileSystemType) Optional(java.util.Optional) CloudIdentityType(com.sequenceiq.common.model.CloudIdentityType) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) RoleAssignmentInner(com.microsoft.azure.management.graphrbac.implementation.RoleAssignmentInner) Assert.assertEquals(org.junit.Assert.assertEquals) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Mockito.mock(org.mockito.Mockito.mock) ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) SpiFileSystem(com.sequenceiq.cloudbreak.cloud.model.SpiFileSystem) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Identity(com.microsoft.azure.management.msi.Identity) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) Test(org.junit.Test)

Example 22 with SpiFileSystem

use of com.sequenceiq.cloudbreak.cloud.model.SpiFileSystem in project cloudbreak by hortonworks.

the class AzureIDBrokerObjectStorageValidatorTest method testValidateObjectStorageWithoutFileSystems.

@Test
public void testValidateObjectStorageWithoutFileSystems() {
    SpiFileSystem fileSystem = new SpiFileSystem("test", FileSystemType.ADLS_GEN_2, null);
    ValidationResultBuilder resultBuilder = new ValidationResultBuilder();
    underTest.validateObjectStorage(client, fileSystem, "", null, null, resultBuilder);
    assertFalse(resultBuilder.build().hasError());
}
Also used : ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) SpiFileSystem(com.sequenceiq.cloudbreak.cloud.model.SpiFileSystem) Test(org.junit.Test)

Example 23 with SpiFileSystem

use of com.sequenceiq.cloudbreak.cloud.model.SpiFileSystem in project cloudbreak by hortonworks.

the class AzureIDBrokerObjectStorageValidatorTest method testValidateObjectStorageWithNoStorageAccount.

@Test
public void testValidateObjectStorageWithNoStorageAccount() {
    SpiFileSystem fileSystem = setupSpiFileSystem(false);
    new RoleASsignmentBuilder(client).withAssignment(ASSUMER_IDENTITY_PRINCIPAL_ID, SUBSCRIPTION_FULL_ID).withAssignment(LOG_IDENTITY_PRINCIPAL_ID, STORAGE_RESOURCE_GROUP_NAME);
    when(azureStorage.findStorageAccountIdInVisibleSubscriptions(any(), anyString())).thenReturn(Optional.empty());
    ValidationResultBuilder resultBuilder = new ValidationResultBuilder();
    underTest.validateObjectStorage(client, fileSystem, "", null, null, resultBuilder);
    ValidationResult validationResult = resultBuilder.build();
    assertTrue(validationResult.hasError());
    assertEquals(1, validationResult.getErrors().size());
    String actual = validationResult.getErrors().get(0);
    assertEquals(actual, String.format("Storage account with name %s not found in the given Azure subscription. " + "Please check if you've used the correct Storage Location when setting up Data Access.", ABFS_STORAGE_ACCOUNT_NAME));
}
Also used : ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) SpiFileSystem(com.sequenceiq.cloudbreak.cloud.model.SpiFileSystem) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) Test(org.junit.Test)

Example 24 with SpiFileSystem

use of com.sequenceiq.cloudbreak.cloud.model.SpiFileSystem in project cloudbreak by hortonworks.

the class AzureIDBrokerObjectStorageValidatorTest method testValidateObjectStorageWithNoSubscriptionScopeRoleAssignment.

@Test
public void testValidateObjectStorageWithNoSubscriptionScopeRoleAssignment() {
    SpiFileSystem fileSystem = setupSpiFileSystem(false);
    new RoleASsignmentBuilder(client).withAssignment(LOG_IDENTITY_PRINCIPAL_ID, STORAGE_RESOURCE_GROUP_NAME);
    ValidationResultBuilder resultBuilder = new ValidationResultBuilder();
    underTest.validateObjectStorage(client, fileSystem, "", null, null, resultBuilder);
    ValidationResult validationResult = resultBuilder.build();
    assertTrue(validationResult.hasError());
    assertEquals(2, validationResult.getErrors().size());
    assertEquals(validationResult.getErrors().get(1), String.format("Identity with id %s has no role assignment. " + "Please check if you've used the correct Identity when setting up Data Access.", ASSUMER_IDENTITY));
    assertEquals(validationResult.getErrors().get(0), String.format("Identity with id %s has no role assignment on scope(s) [/subscriptions/%s]. " + "Please check if you've used the correct Identity when setting up Data Access.", ASSUMER_IDENTITY, SUBSCRIPTION_ID));
}
Also used : ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) SpiFileSystem(com.sequenceiq.cloudbreak.cloud.model.SpiFileSystem) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) Test(org.junit.Test)

Example 25 with SpiFileSystem

use of com.sequenceiq.cloudbreak.cloud.model.SpiFileSystem in project cloudbreak by hortonworks.

the class GcpObjectStorageConnector method validateObjectStorage.

@Override
public ObjectStorageValidateResponse validateObjectStorage(ObjectStorageValidateRequest request) {
    String accountId = Crn.safeFromString(request.getCredential().getId()).getAccountId();
    if (!entitlementService.gcpCloudStorageValidationEnabled(accountId)) {
        LOGGER.info("Gcp Cloud storage validation entitlement is missing, not validating cloudStorageRequest: {}", JsonUtil.writeValueAsStringSilent(request));
        return ObjectStorageValidateResponse.builder().withStatus(ResponseStatus.OK).build();
    }
    Storage storage = gcpStorageFactory.buildStorage(request.getCredential(), request.getCredential().getName());
    ValidationResult.ValidationResultBuilder resultBuilder = new ValidationResult.ValidationResultBuilder();
    for (StorageLocationBase location : request.getCloudStorageRequest().getLocations()) {
        String bucketName = gcpStackUtil.getBucketName(location.getValue());
        try {
            storage.buckets().get(bucketName).execute();
        } catch (Exception e) {
            String message = String.format("The specified bucket with %s name does not exist", bucketName);
            LOGGER.debug(message + ":" + e.getMessage());
            resultBuilder.error(message);
        }
    }
    SpiFileSystem spiFileSystem = request.getSpiFileSystem();
    try {
        resultBuilder = gcpServiceAccountObjectStorageValidator.validateObjectStorage(request.getCredential(), spiFileSystem, resultBuilder);
    } catch (Exception e) {
        LOGGER.debug(e.getMessage());
        resultBuilder.error(e.getMessage());
    }
    ValidationResult validationResult = resultBuilder.build();
    if (validationResult.hasError()) {
        return ObjectStorageValidateResponse.builder().withStatus(ResponseStatus.ERROR).withError(validationResult.getFormattedErrors()).build();
    }
    return ObjectStorageValidateResponse.builder().withStatus(ResponseStatus.OK).build();
}
Also used : Storage(com.google.api.services.storage.Storage) SpiFileSystem(com.sequenceiq.cloudbreak.cloud.model.SpiFileSystem) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) StorageLocationBase(com.sequenceiq.common.api.cloudstorage.StorageLocationBase)

Aggregations

SpiFileSystem (com.sequenceiq.cloudbreak.cloud.model.SpiFileSystem)28 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)16 ValidationResultBuilder (com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder)16 Test (org.junit.Test)15 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)7 CloudFileSystemView (com.sequenceiq.cloudbreak.cloud.model.filesystem.CloudFileSystemView)5 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)4 Identity (com.microsoft.azure.management.msi.Identity)3 AzureClient (com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient)3 Group (com.sequenceiq.cloudbreak.cloud.model.Group)3 GroupNetwork (com.sequenceiq.cloudbreak.cloud.model.GroupNetwork)3 Network (com.sequenceiq.cloudbreak.cloud.model.Network)3 StorageLocationBase (com.sequenceiq.common.api.cloudstorage.StorageLocationBase)3 List (java.util.List)3 PagedList (com.microsoft.azure.PagedList)2 RoleAssignmentInner (com.microsoft.azure.management.graphrbac.implementation.RoleAssignmentInner)2 ResourceGroup (com.microsoft.azure.management.resources.ResourceGroup)2 Subscription (com.microsoft.azure.management.resources.Subscription)2 StorageAccount (com.microsoft.azure.management.storage.StorageAccount)2 AzureStorage (com.sequenceiq.cloudbreak.cloud.azure.AzureStorage)2