use of com.sequenceiq.cloudbreak.domain.cloudstorage.CloudStorage in project cloudbreak by hortonworks.
the class CloudStorageConverter method fileSystemToRequest.
public CloudStorageRequest fileSystemToRequest(FileSystem fileSystem) {
CloudStorageRequest result = new CloudStorageRequest();
CloudStorage cloudStorage = fileSystem.getCloudStorage();
if (cloudStorage != null) {
List<StorageIdentityBase> storageIdentityRequests = cloudStorage.getCloudIdentities().stream().map(this::cloudIdentityToRequest).collect(Collectors.toList());
result.setIdentities(storageIdentityRequests);
List<StorageLocationBase> storageLocationRequests = cloudStorage.getLocations().stream().map(this::storageLocationToRequest).collect(Collectors.toList());
result.setLocations(storageLocationRequests);
NullUtil.doIfNotNull(cloudStorage.getS3GuardDynamoTableName(), tableName -> {
AwsStorageParameters awsStorageParameters = new AwsStorageParameters();
S3Guard s3Guard = new S3Guard();
s3Guard.setDynamoTableName(tableName);
awsStorageParameters.setS3Guard(s3Guard);
result.setAws(awsStorageParameters);
});
result.setAccountMapping(accountMappingToAccountMappingRequest(cloudStorage.getAccountMapping()));
}
return result;
}
use of com.sequenceiq.cloudbreak.domain.cloudstorage.CloudStorage in project cloudbreak by hortonworks.
the class CloudStorageConverter method requestToAdditionalFileSystem.
public FileSystem requestToAdditionalFileSystem(CloudStorageBase cloudStorageRequest) {
FileSystem fileSystem = new FileSystem();
AwsEfsParameters efsParameters = cloudStorageRequest.getAws() == null ? null : cloudStorageRequest.getAws().getEfsParameters();
if (efsParameters == null || StringUtils.isEmpty(efsParameters.getName())) {
return null;
}
fileSystem.setName(efsParameters.getName());
FileSystemType fileSystemType = FileSystemType.EFS;
fileSystem.setType(fileSystemType);
Map<String, Object> configurations = new HashMap<>();
configurations.put(CloudEfsConfiguration.KEY_BACKUP_POLICY_STATUS, efsParameters.getBackupPolicyStatus());
configurations.put(CloudEfsConfiguration.KEY_ENCRYPTED, efsParameters.getEncrypted());
configurations.put(CloudEfsConfiguration.KEY_FILESYSTEM_POLICY, efsParameters.getFileSystemPolicy());
configurations.put(CloudEfsConfiguration.KEY_FILESYSTEM_TAGS, efsParameters.getFileSystemTags());
configurations.put(CloudEfsConfiguration.KEY_KMSKEYID, efsParameters.getKmsKeyId());
configurations.put(CloudEfsConfiguration.KEY_LIFECYCLE_POLICIES, efsParameters.getLifeCyclePolicies());
configurations.put(CloudEfsConfiguration.KEY_PERFORMANCE_MODE, efsParameters.getPerformanceMode());
configurations.put(CloudEfsConfiguration.KEY_PROVISIONED_THROUGHPUT_INMIBPS, efsParameters.getProvisionedThroughputInMibps());
configurations.put(CloudEfsConfiguration.KEY_THROUGHPUT_MODE, efsParameters.getThroughputMode());
String configString;
try {
configString = JsonUtil.writeValueAsString(configurations);
} catch (JsonProcessingException ignored) {
configString = configurations.toString();
}
fileSystem.setConfigurations(new Json(configString));
CloudStorage cloudStorage = new CloudStorage();
if (cloudStorageRequest.getIdentities() != null) {
Optional<CloudIdentity> cloudIdentity = cloudStorageRequest.getIdentities().stream().map(this::identityRequestToCloudIdentity).filter(currCloudIdentity -> currCloudIdentity.getEfsIdentity() != null).findFirst();
if (cloudIdentity != null && cloudIdentity.get() != null) {
cloudStorage.setCloudIdentities(List.of(cloudIdentity.get()));
}
}
cloudStorage.setAccountMapping(accountMappingRequestToAccountMapping(cloudStorageRequest.getAccountMapping()));
fileSystem.setCloudStorage(cloudStorage);
return fileSystem;
}
use of com.sequenceiq.cloudbreak.domain.cloudstorage.CloudStorage in project cloudbreak by hortonworks.
the class CloudStorageConverter method fileSystemToResponse.
public CloudStorageResponse fileSystemToResponse(FileSystem fileSystem) {
CloudStorageResponse response = new CloudStorageResponse();
CloudStorage cloudStorage = fileSystem.getCloudStorage();
if (cloudStorage != null) {
if (StringUtils.isNotEmpty(cloudStorage.getS3GuardDynamoTableName())) {
AwsStorageParameters awsStorageParameters = new AwsStorageParameters();
S3Guard s3Guard = new S3Guard();
s3Guard.setDynamoTableName(cloudStorage.getS3GuardDynamoTableName());
awsStorageParameters.setS3Guard(s3Guard);
response.setAws(awsStorageParameters);
}
List<StorageIdentityBase> storageIdentities = cloudStorage.getCloudIdentities().stream().map(this::cloudIdentityToStorageIdentityBase).collect(Collectors.toList());
response.setIdentities(storageIdentities);
List<StorageLocationBase> storageLocations = cloudStorage.getLocations().stream().map(storageLocation -> {
StorageLocationBase storageLocationBase = new StorageLocationBase();
storageLocationBase.setType(storageLocation.getType());
storageLocationBase.setValue(storageLocation.getValue());
return storageLocationBase;
}).collect(Collectors.toList());
response.setLocations(storageLocations);
response.setAccountMapping(accountMappingToAccountMappingRequest(cloudStorage.getAccountMapping()));
}
return response;
}
use of com.sequenceiq.cloudbreak.domain.cloudstorage.CloudStorage 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());
}
use of com.sequenceiq.cloudbreak.domain.cloudstorage.CloudStorage 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);
}
Aggregations