use of com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView in project cloudbreak by hortonworks.
the class AwsObjectStorageConnector method getObjectStorageMetadata.
@Override
public ObjectStorageMetadataResponse getObjectStorageMetadata(ObjectStorageMetadataRequest request) {
AwsCredentialView awsCredentialView = new AwsCredentialView(request.getCredential());
try {
AmazonS3Client s3Client = awsClient.createS3Client(awsCredentialView);
String bucketLocation = fixBucketLocation(s3Client.getBucketLocation(request.getObjectStoragePath()));
return ObjectStorageMetadataResponse.builder().withRegion(bucketLocation).withStatus(ResponseStatus.OK).build();
} catch (AmazonS3Exception e) {
// the same error code will be returned. However, this hack is mainly for QAAS.
if (e.getStatusCode() != ACCESS_DENIED_ERROR_CODE) {
throw new CloudConnectorException(String.format("We were not able to query S3 object storage location for %s. " + "Refer to Cloudera documentation at %s for the required setup. " + "The message from Amazon S3 was: %s.", request.getObjectStoragePath(), DocumentationLinkProvider.awsCloudStorageSetupLink(), e.getErrorMessage()), e);
}
return ObjectStorageMetadataResponse.builder().withStatus(ResponseStatus.ACCESS_DENIED).build();
}
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView in project cloudbreak by hortonworks.
the class AwsPlatformResources method securityGroups.
@Override
public CloudSecurityGroups securityGroups(ExtendedCloudCredential cloudCredential, Region region, Map<String, String> filters) {
Map<String, Set<CloudSecurityGroup>> result = new HashMap<>();
Set<CloudSecurityGroup> cloudSecurityGroups = new HashSet<>();
AmazonEc2Client ec2Client = awsClient.createEc2Client(new AwsCredentialView(cloudCredential), region.value());
// create securitygroup filter view
PlatformResourceSecurityGroupFilterView filter = new PlatformResourceSecurityGroupFilterView(filters);
DescribeSecurityGroupsRequest describeSecurityGroupsRequest = new DescribeSecurityGroupsRequest();
// If the filtervalue is provided then we should filter only for those securitygroups
if (!Strings.isNullOrEmpty(filter.getVpcId())) {
describeSecurityGroupsRequest.withFilters(new Filter("vpc-id", singletonList(filter.getVpcId())));
}
if (!Strings.isNullOrEmpty(filter.getGroupId())) {
describeSecurityGroupsRequest.withGroupIds(filter.getGroupId());
}
if (!Strings.isNullOrEmpty(filter.getGroupName())) {
describeSecurityGroupsRequest.withGroupNames(filter.getGroupName());
}
for (SecurityGroup securityGroup : fetchSecurityGroups(ec2Client, describeSecurityGroupsRequest)) {
Map<String, Object> properties = new HashMap<>();
properties.put("vpcId", securityGroup.getVpcId());
properties.put("description", securityGroup.getDescription());
properties.put("ipPermissions", securityGroup.getIpPermissions());
properties.put("ipPermissionsEgress", securityGroup.getIpPermissionsEgress());
cloudSecurityGroups.add(new CloudSecurityGroup(securityGroup.getGroupName(), securityGroup.getGroupId(), properties));
}
result.put(region.value(), cloudSecurityGroups);
return new CloudSecurityGroups(result);
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView in project cloudbreak by hortonworks.
the class AwsPlatformResources method getCloudVmTypes.
private CloudVmTypes getCloudVmTypes(ExtendedCloudCredential cloudCredential, Region region, Map<String, String> filters, Predicate<VmType> enabledInstanceTypeFilter, boolean enableMinimalHardwareFilter) {
Map<String, Set<VmType>> cloudVmResponses = new HashMap<>();
Map<String, VmType> defaultCloudVmResponses = new HashMap<>();
if (region != null && !Strings.isNullOrEmpty(region.value())) {
CloudRegions regions = regions(cloudCredential, region, filters, true);
AwsCredentialView awsCredentialView = new AwsCredentialView(cloudCredential);
AmazonEc2Client ec2Client = awsClient.createEc2Client(awsCredentialView, region.getRegionName());
List<String> instanceTypes = ec2Client.describeInstanceTypeOfferings(getOfferingsRequest(region)).getInstanceTypeOfferings().stream().map(e -> e.getInstanceType()).collect(Collectors.toList());
Set<VmType> awsInstances = new HashSet<>();
for (int actualSegment = 0; actualSegment < instanceTypes.size(); actualSegment += SEGMENT) {
DescribeInstanceTypesRequest request = new DescribeInstanceTypesRequest();
request.setInstanceTypes(getInstanceTypes(instanceTypes, actualSegment));
getVmTypesWithAwsCall(awsInstances, ec2Client.describeInstanceTypes(request));
}
if (enableMinimalHardwareFilter) {
awsInstances = awsInstances.stream().filter(e -> minimalHardwareFilter.suitableAsMinimumHardware(e.getMetaData().getCPU(), e.getMetaData().getMemoryInGb())).collect(Collectors.toSet());
}
fillUpAvailabilityZones(region, enabledInstanceTypeFilter, regions, cloudVmResponses, defaultCloudVmResponses, awsInstances);
filterInstancesByFilters(enabledInstanceTypeFilter, cloudVmResponses);
}
return new CloudVmTypes(cloudVmResponses, defaultCloudVmResponses);
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView in project cloudbreak by hortonworks.
the class AwsPlatformResources method networks.
@Override
public CloudNetworks networks(ExtendedCloudCredential cloudCredential, Region region, Map<String, String> filters) {
AmazonEc2Client ec2Client = awsClient.createEc2Client(new AwsCredentialView(cloudCredential), region.value());
try {
LOGGER.debug("Describing route tables in region {}", region.getRegionName());
List<RouteTable> allRouteTables = AwsPageCollector.getAllRouteTables(ec2Client, new DescribeRouteTablesRequest());
DescribeVpcsRequest describeVpcsRequest = getDescribeVpcsRequestWithFilters(filters);
Set<CloudNetwork> cloudNetworks = new HashSet<>();
DescribeVpcsResult describeVpcsResult = null;
boolean first = true;
while (first || !isNullOrEmpty(describeVpcsResult.getNextToken())) {
LOGGER.debug("Getting VPC list in region {}{}", region.getRegionName(), first ? "" : " (continuation)");
first = false;
describeVpcsRequest.setNextToken(describeVpcsResult == null ? null : describeVpcsResult.getNextToken());
describeVpcsResult = ec2Client.describeVpcs(describeVpcsRequest);
Set<CloudNetwork> partialNetworks = getCloudNetworks(ec2Client, allRouteTables, describeVpcsResult);
cloudNetworks.addAll(partialNetworks);
}
Map<String, Set<CloudNetwork>> result = new HashMap<>();
result.put(region.value(), cloudNetworks);
return new CloudNetworks(result);
} catch (SdkClientException e) {
LOGGER.error(String.format("Unable to enumerate networks in region '%s'. Check exception for details.", region.getRegionName()), e);
throw e;
}
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView in project cloudbreak by hortonworks.
the class AwsPublicKeyConnector method register.
@Override
public void register(PublicKeyRegisterRequest request) {
LOGGER.debug("Importing public key {} to {} region on AWS", request.getPublicKeyId(), request.getRegion());
AwsCredentialView awsCredential = new AwsCredentialView(request.getCredential());
try {
AmazonEc2Client client = awsClient.createEc2Client(awsCredential, request.getRegion());
if (!exists(client, request.getPublicKeyId())) {
ImportKeyPairRequest importKeyPairRequest = new ImportKeyPairRequest(request.getPublicKeyId(), request.getPublicKey());
client.importKeyPair(importKeyPairRequest);
}
} catch (Exception e) {
String errorMessage = String.format("Failed to import public key [%s:'%s', region: '%s'], detailed message: %s", getType(awsCredential), getAwsId(awsCredential), request.getRegion(), e.getMessage());
LOGGER.error(errorMessage, e);
throw new CloudConnectorException(e.getMessage(), e);
}
}
Aggregations