Search in sources :

Example 11 with SpiFileSystem

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

the class CloudFileSystemViewProvider method getCloudFileSystemView.

public Optional<CloudFileSystemView> getCloudFileSystemView(FileSystem fileSystem, Map<String, Set<String>> componentsByHostGroup, InstanceGroup instanceGroup) {
    Optional<CloudFileSystemView> fileSystemView;
    if (fileSystem != null) {
        SpiFileSystem spiFileSystem = fileSystemConverter.fileSystemToSpi(fileSystem);
        Set<String> components = componentsByHostGroup.get(instanceGroup.getGroupName());
        CloudIdentityType identityType = cloudIdentityTypeDecider.getIdentityType(components);
        if (identityType == CloudIdentityType.ID_BROKER) {
            instanceGroupService.setCloudIdentityType(instanceGroup, CloudIdentityType.ID_BROKER);
            fileSystemView = spiFileSystem.getCloudFileSystems().stream().filter(cloudFileSystemView -> CloudIdentityType.ID_BROKER.equals(cloudFileSystemView.getCloudIdentityType())).findFirst();
        } else {
            instanceGroupService.setCloudIdentityType(instanceGroup, CloudIdentityType.LOG);
            fileSystemView = spiFileSystem.getCloudFileSystems().stream().filter(cloudFileSystemView -> CloudIdentityType.LOG.equals(cloudFileSystemView.getCloudIdentityType())).findFirst();
        }
    } else {
        fileSystemView = Optional.empty();
    }
    return fileSystemView;
}
Also used : CloudFileSystemView(com.sequenceiq.cloudbreak.cloud.model.filesystem.CloudFileSystemView) SpiFileSystem(com.sequenceiq.cloudbreak.cloud.model.SpiFileSystem) CloudIdentityType(com.sequenceiq.common.model.CloudIdentityType)

Example 12 with SpiFileSystem

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

the class StackToCloudStackConverter method convert.

public CloudStack convert(Stack stack, Collection<String> deleteRequestedInstances) {
    Image image = null;
    String environmentCrn = stack.getEnvironmentCrn();
    DetailedEnvironmentResponse environment = environmentClientService.getByCrnAsInternal(environmentCrn);
    List<Group> instanceGroups = buildInstanceGroups(stack, stack.getInstanceGroupsAsList(), stack.getStackAuthentication(), deleteRequestedInstances, environment);
    try {
        image = imageService.getImage(stack.getId());
    } catch (CloudbreakImageNotFoundException e) {
        LOGGER.debug(e.getMessage());
    }
    Network network = buildNetwork(stack);
    StackTemplate stackTemplate = componentConfigProviderService.getStackTemplate(stack.getId());
    InstanceAuthentication instanceAuthentication = buildInstanceAuthentication(stack.getStackAuthentication());
    SpiFileSystem cloudFileSystem = buildSpiFileSystem(stack);
    SpiFileSystem additionalCloudFileSystem = buildAdditionalSpiFileSystem(stack);
    String template = null;
    if (stackTemplate != null) {
        template = stackTemplate.getTemplate();
    }
    Map<String, String> parameters = buildCloudStackParameters(stack, environment);
    List<CloudLoadBalancer> cloudLoadBalancers = buildLoadBalancers(stack, instanceGroups);
    return new CloudStack(instanceGroups, network, image, parameters, getUserDefinedTags(stack), template, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey(), cloudFileSystem, cloudLoadBalancers, additionalCloudFileSystem);
}
Also used : Group(com.sequenceiq.cloudbreak.cloud.model.Group) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) TargetGroup(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroup) AzureResourceGroup(com.sequenceiq.environment.api.v1.environment.model.request.azure.AzureResourceGroup) SecurityGroup(com.sequenceiq.cloudbreak.domain.SecurityGroup) InstanceAuthentication(com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) SpiFileSystem(com.sequenceiq.cloudbreak.cloud.model.SpiFileSystem) Image(com.sequenceiq.cloudbreak.cloud.model.Image) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) CloudLoadBalancer(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer) GroupNetwork(com.sequenceiq.cloudbreak.cloud.model.GroupNetwork) Network(com.sequenceiq.cloudbreak.cloud.model.Network) InstanceGroupNetwork(com.sequenceiq.cloudbreak.domain.stack.instance.network.InstanceGroupNetwork) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) StackTemplate(com.sequenceiq.cloudbreak.cloud.model.StackTemplate)

Example 13 with SpiFileSystem

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

the class GcpInstanceResourceBuilderTest method extraxtServiceAccountWhenServiceEmailNotEmpty.

@Test
public void extraxtServiceAccountWhenServiceEmailNotEmpty() throws Exception {
    // GIVEN
    String email = "service@email.com";
    CloudGcsView cloudGcsView = new CloudGcsView(CloudIdentityType.LOG);
    cloudGcsView.setServiceAccountEmail(email);
    CloudStack cloudStack = new CloudStack(Collections.emptyList(), new Network(null), image, emptyMap(), emptyMap(), null, null, null, null, new SpiFileSystem("test", FileSystemType.GCS, List.of(cloudGcsView)));
    Group group = newGroupWithParams(ImmutableMap.of(), cloudGcsView);
    List<CloudResource> buildableResources = builder.create(context, group.getInstances().get(0), privateId, authenticatedContext, group, image);
    context.addComputeResources(0L, buildableResources);
    // WHEN
    when(compute.instances()).thenReturn(instances);
    when(instances.insert(anyString(), anyString(), any(Instance.class))).thenReturn(insert);
    when(insert.setPrettyPrint(anyBoolean())).thenReturn(insert);
    when(insert.execute()).thenReturn(operation);
    builder.build(context, group.getInstances().get(0), privateId, authenticatedContext, group, buildableResources, cloudStack);
    // THEN
    verify(compute).instances();
    verify(instances).insert(anyString(), anyString(), instanceArg.capture());
    assertEquals(instanceArg.getValue().getServiceAccounts().get(0).getEmail(), email);
}
Also used : InstanceGroup(com.google.api.services.compute.model.InstanceGroup) Group(com.sequenceiq.cloudbreak.cloud.model.Group) CloudGcsView(com.sequenceiq.cloudbreak.cloud.model.filesystem.CloudGcsView) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) Instance(com.google.api.services.compute.model.Instance) GroupNetwork(com.sequenceiq.cloudbreak.cloud.model.GroupNetwork) Network(com.sequenceiq.cloudbreak.cloud.model.Network) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SpiFileSystem(com.sequenceiq.cloudbreak.cloud.model.SpiFileSystem) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Test(org.junit.Test)

Example 14 with SpiFileSystem

use of com.sequenceiq.cloudbreak.cloud.model.SpiFileSystem 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 15 with SpiFileSystem

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

the class CloudProviderService method validateObjectStorage.

public ObjectStorageValidateResponse validateObjectStorage(ObjectStorageValidateRequest request) {
    ObjectStorageConnector objectStorageConnector = getCloudConnector(request).objectStorage();
    if (request.getMockAccountMappingSettings() != null) {
        objectStorageValidateRequestDecorator.decorateWithMockAccountMapping(request);
    }
    SpiFileSystem spiFileSystem = cloudStorageConverter.requestToSpiFileSystem(request.getCloudStorageRequest());
    request.setSpiFileSystem(spiFileSystem);
    return objectStorageConnector.validateObjectStorage(request);
}
Also used : ObjectStorageConnector(com.sequenceiq.cloudbreak.cloud.ObjectStorageConnector) SpiFileSystem(com.sequenceiq.cloudbreak.cloud.model.SpiFileSystem)

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