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