Search in sources :

Example 11 with CloudFileSystemView

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

the class AzureIDBrokerObjectStorageValidator method validateObjectStorage.

public ValidationResult validateObjectStorage(AzureClient client, SpiFileSystem spiFileSystem, String logsLocationBase, String backupLocationBase, String singleResourceGroupName, ValidationResultBuilder resultBuilder) {
    LOGGER.info("Validating Azure identities...");
    List<CloudFileSystemView> cloudFileSystems = spiFileSystem.getCloudFileSystems();
    validateHierarchicalNamespace(client, spiFileSystem, logsLocationBase, backupLocationBase, resultBuilder);
    if (Objects.nonNull(cloudFileSystems) && cloudFileSystems.size() > 0) {
        for (CloudFileSystemView cloudFileSystemView : cloudFileSystems) {
            CloudAdlsGen2View cloudFileSystem = (CloudAdlsGen2View) cloudFileSystemView;
            String managedIdentityId = cloudFileSystem.getManagedIdentity();
            Identity identity = client.getIdentityById(managedIdentityId);
            CloudIdentityType cloudIdentityType = cloudFileSystem.getCloudIdentityType();
            if (identity != null) {
                if (ID_BROKER.equals(cloudIdentityType)) {
                    List<RoleAssignmentInner> roleAssignments;
                    Optional<ResourceGroup> singleResourceGroup;
                    if (singleResourceGroupName != null) {
                        ResourceGroup resourceGroup = client.getResourceGroup(singleResourceGroupName);
                        roleAssignments = client.listRoleAssignmentsByScopeInner(resourceGroup.id());
                        singleResourceGroup = Optional.of(resourceGroup);
                    } else {
                        roleAssignments = client.listRoleAssignments();
                        singleResourceGroup = Optional.empty();
                    }
                    validateIDBroker(client, roleAssignments, identity, cloudFileSystem, singleResourceGroup, resultBuilder);
                } else if (LOG.equals(cloudIdentityType)) {
                    validateLog(client, identity, logsLocationBase, resultBuilder);
                }
            } else {
                addError(resultBuilder, String.format("%s Identity with id %s does not exist in the given Azure subscription. %s", getIdentityType(cloudIdentityType), managedIdentityId, getAdviceMessage(IDENTITY, cloudIdentityType)));
            }
        }
    }
    return resultBuilder.build();
}
Also used : CloudFileSystemView(com.sequenceiq.cloudbreak.cloud.model.filesystem.CloudFileSystemView) CloudAdlsGen2View(com.sequenceiq.cloudbreak.cloud.model.filesystem.CloudAdlsGen2View) CloudIdentityType(com.sequenceiq.common.model.CloudIdentityType) Identity(com.microsoft.azure.management.msi.Identity) RoleAssignmentInner(com.microsoft.azure.management.graphrbac.implementation.RoleAssignmentInner) ResourceGroup(com.microsoft.azure.management.resources.ResourceGroup)

Example 12 with CloudFileSystemView

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

the class GcpServiceAccountObjectStorageValidator method validateObjectStorage.

public ValidationResultBuilder validateObjectStorage(CloudCredential cloudCredential, SpiFileSystem spiFileSystem, ValidationResultBuilder resultBuilder) throws IOException {
    LOGGER.info("Validating Gcp identities...");
    Iam iam = gcpIamFactory.buildIam(cloudCredential);
    List<CloudFileSystemView> cloudFileSystems = spiFileSystem.getCloudFileSystems();
    if (Objects.nonNull(cloudFileSystems) && cloudFileSystems.size() > 0) {
        String projectId = gcpStackUtil.getProjectId(cloudCredential);
        Set<String> serviceAccountEmailsToFind = cloudFileSystems.stream().map(cloudFileSystemView -> ((CloudGcsView) cloudFileSystemView).getServiceAccountEmail()).collect(Collectors.toSet());
        Iam.Projects.ServiceAccounts.List listServiceAccountEmailsRequest = iam.projects().serviceAccounts().list("projects/" + projectId).setPageSize(DEFAULT_PAGE_SIZE);
        ListServiceAccountsResponse response;
        do {
            response = listServiceAccountEmailsRequest.execute();
            response.getAccounts().forEach(serviceAccount -> serviceAccountEmailsToFind.remove(serviceAccount.getEmail()));
            listServiceAccountEmailsRequest.setPageToken(response.getNextPageToken());
        } while (response.getNextPageToken() != null && !serviceAccountEmailsToFind.isEmpty());
        if (!serviceAccountEmailsToFind.isEmpty()) {
            addError(resultBuilder, String.format("Service Account with email(s) '%s' could not be found in the configured Google Cloud project '%s'.", String.join(", ", serviceAccountEmailsToFind), projectId));
        }
    }
    return resultBuilder;
}
Also used : Logger(org.slf4j.Logger) ListServiceAccountsResponse(com.google.api.services.iam.v1.model.ListServiceAccountsResponse) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) SpiFileSystem(com.sequenceiq.cloudbreak.cloud.model.SpiFileSystem) IOException(java.io.IOException) CloudFileSystemView(com.sequenceiq.cloudbreak.cloud.model.filesystem.CloudFileSystemView) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) Inject(javax.inject.Inject) List(java.util.List) Component(org.springframework.stereotype.Component) ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) Iam(com.google.api.services.iam.v1.Iam) GcpIamFactory(com.sequenceiq.cloudbreak.cloud.gcp.client.GcpIamFactory) CloudGcsView(com.sequenceiq.cloudbreak.cloud.model.filesystem.CloudGcsView) GcpStackUtil(com.sequenceiq.cloudbreak.cloud.gcp.util.GcpStackUtil) ListServiceAccountsResponse(com.google.api.services.iam.v1.model.ListServiceAccountsResponse) CloudGcsView(com.sequenceiq.cloudbreak.cloud.model.filesystem.CloudGcsView) Iam(com.google.api.services.iam.v1.Iam) CloudFileSystemView(com.sequenceiq.cloudbreak.cloud.model.filesystem.CloudFileSystemView)

Example 13 with CloudFileSystemView

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

the class CloudStorageConverter method getCloudFileSystemView.

private FileSystemType getCloudFileSystemView(CloudStorageBase cloudStorageRequest, List<CloudFileSystemView> cloudFileSystemViews, StorageIdentityBase storageIdentity) {
    FileSystemType type = null;
    if (storageIdentity != null) {
        CloudFileSystemView cloudFileSystemView = null;
        if (storageIdentity.getAdls() != null) {
            cloudFileSystemView = cloudStorageParametersConverter.adlsToCloudView(storageIdentity);
            type = FileSystemType.ADLS;
        } else if (storageIdentity.getGcs() != null) {
            cloudFileSystemView = cloudStorageParametersConverter.gcsToCloudView(storageIdentity);
            type = FileSystemType.GCS;
        } else if (storageIdentity.getS3() != null) {
            cloudFileSystemView = cloudStorageParametersConverter.s3ToCloudView(storageIdentity);
            setDynamoDBTableName((CloudS3View) cloudFileSystemView, cloudStorageRequest);
            type = FileSystemType.S3;
        } else if (storageIdentity.getWasb() != null) {
            cloudFileSystemView = cloudStorageParametersConverter.wasbToCloudView(storageIdentity);
            type = FileSystemType.WASB;
        } else if (storageIdentity.getAdlsGen2() != null) {
            cloudFileSystemView = cloudStorageParametersConverter.adlsGen2ToCloudView(storageIdentity);
            type = FileSystemType.ADLS_GEN_2;
        }
        if (cloudFileSystemView != null) {
            cloudFileSystemView.setAccountMapping(cloudStorageRequest.getAccountMapping());
            cloudFileSystemView.setLocations(cloudStorageRequest.getLocations());
            cloudFileSystemViews.add(cloudFileSystemView);
        }
    }
    return type;
}
Also used : FileSystemType(com.sequenceiq.common.model.FileSystemType) CloudFileSystemView(com.sequenceiq.cloudbreak.cloud.model.filesystem.CloudFileSystemView)

Example 14 with CloudFileSystemView

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

the class CloudFileSystemViewProviderTest method testBuild.

@Test
public void testBuild() {
    List<CloudIdentity> cloudIdentities = getCloudIdentities();
    CloudStorage cloudStorage = getCloudStorage(cloudIdentities);
    FileSystem fileSystem = getFileSystem(cloudStorage);
    Map<String, Set<String>> componentsByHostGroup = new HashMap<>();
    InstanceGroup idBrokerGroup = getIdBrokerGroup(componentsByHostGroup);
    InstanceGroup computeGroup = new InstanceGroup();
    computeGroup.setGroupName(COMPUTE_INSTANCE_GROUP_NAME);
    componentsByHostGroup.put(COMPUTE_INSTANCE_GROUP_NAME, new HashSet<>());
    Optional<CloudFileSystemView> idBrokerGroupResult = cloudFileSystemViewProvider.getCloudFileSystemView(fileSystem, componentsByHostGroup, idBrokerGroup);
    Assertions.assertEquals(idBrokerGroupResult.get().getCloudIdentityType(), CloudIdentityType.ID_BROKER);
    Optional<CloudFileSystemView> computeGroupResult = cloudFileSystemViewProvider.getCloudFileSystemView(fileSystem, componentsByHostGroup, computeGroup);
    Assertions.assertEquals(computeGroupResult.get().getCloudIdentityType(), CloudIdentityType.LOG);
    Mockito.verify(instanceGroupService, Mockito.times(2)).setCloudIdentityType(any(), any());
}
Also used : CloudStorage(com.sequenceiq.cloudbreak.domain.cloudstorage.CloudStorage) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) CloudIdentity(com.sequenceiq.cloudbreak.domain.cloudstorage.CloudIdentity) FileSystem(com.sequenceiq.cloudbreak.domain.FileSystem) CloudFileSystemView(com.sequenceiq.cloudbreak.cloud.model.filesystem.CloudFileSystemView) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) Test(org.junit.Test)

Example 15 with CloudFileSystemView

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

the class CloudFileSystemViewProviderTest method testBuildWithNullComponents.

@Test
public void testBuildWithNullComponents() {
    List<CloudIdentity> cloudIdentities = getCloudIdentities();
    CloudStorage cloudStorage = getCloudStorage(cloudIdentities);
    FileSystem fileSystem = getFileSystem(cloudStorage);
    Map<String, Set<String>> componentsByHostGroup = new HashMap<>();
    InstanceGroup idBrokerGroup = getIdBrokerGroup(componentsByHostGroup);
    InstanceGroup computeGroup = new InstanceGroup();
    computeGroup.setGroupName(COMPUTE_INSTANCE_GROUP_NAME);
    componentsByHostGroup.put(COMPUTE_INSTANCE_GROUP_NAME, null);
    Optional<CloudFileSystemView> idBrokerGroupResult = cloudFileSystemViewProvider.getCloudFileSystemView(fileSystem, componentsByHostGroup, idBrokerGroup);
    Assertions.assertEquals(idBrokerGroupResult.get().getCloudIdentityType(), CloudIdentityType.ID_BROKER);
    Optional<CloudFileSystemView> computeGroupResult = cloudFileSystemViewProvider.getCloudFileSystemView(fileSystem, componentsByHostGroup, computeGroup);
    Assertions.assertEquals(computeGroupResult.get().getCloudIdentityType(), CloudIdentityType.LOG);
}
Also used : CloudStorage(com.sequenceiq.cloudbreak.domain.cloudstorage.CloudStorage) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) CloudIdentity(com.sequenceiq.cloudbreak.domain.cloudstorage.CloudIdentity) FileSystem(com.sequenceiq.cloudbreak.domain.FileSystem) CloudFileSystemView(com.sequenceiq.cloudbreak.cloud.model.filesystem.CloudFileSystemView) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) Test(org.junit.Test)

Aggregations

CloudFileSystemView (com.sequenceiq.cloudbreak.cloud.model.filesystem.CloudFileSystemView)18 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 Set (java.util.Set)4 Group (com.sequenceiq.cloudbreak.cloud.model.Group)3 SpiFileSystem (com.sequenceiq.cloudbreak.cloud.model.SpiFileSystem)3 InstanceGroup (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)3 Telemetry (com.sequenceiq.common.api.telemetry.model.Telemetry)3 CloudIdentityType (com.sequenceiq.common.model.CloudIdentityType)3 Backup (com.sequenceiq.freeipa.api.model.Backup)3 HashSet (java.util.HashSet)3 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)2 InstanceAuthentication (com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication)2 CloudGcsView (com.sequenceiq.cloudbreak.cloud.model.filesystem.CloudGcsView)2 FileSystem (com.sequenceiq.cloudbreak.domain.FileSystem)2 CloudIdentity (com.sequenceiq.cloudbreak.domain.cloudstorage.CloudIdentity)2 CloudStorage (com.sequenceiq.cloudbreak.domain.cloudstorage.CloudStorage)2 Logging (com.sequenceiq.common.api.telemetry.model.Logging)2 FileSystemType (com.sequenceiq.common.model.FileSystemType)2 AzureResourceGroup (com.sequenceiq.environment.api.v1.environment.model.request.azure.AzureResourceGroup)2