use of com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView in project cloudbreak by hortonworks.
the class AwsCredentialConnector method verifyAccessKeySecretKeyIsAssumable.
private CloudCredentialStatus verifyAccessKeySecretKeyIsAssumable(CloudCredential cloudCredential) {
AwsCredentialView awsCredential = new AwsCredentialView(cloudCredential);
try {
AmazonEC2Client access = awsClient.createAccess(cloudCredential);
DescribeRegionsRequest describeRegionsRequest = new DescribeRegionsRequest();
access.describeRegions(describeRegionsRequest);
} catch (AmazonClientException ae) {
String errorMessage = "Unable to verify AWS credentials: please make sure the access key and secret key is correct";
LOGGER.error(errorMessage, ae);
return new CloudCredentialStatus(cloudCredential, CredentialStatus.FAILED, ae, errorMessage);
} catch (RuntimeException e) {
String errorMessage = String.format("Could not verify keys '%s': check if the keys exists and if it's created with the correct external ID", awsCredential.getAccessKey());
LOGGER.error(errorMessage, e);
return new CloudCredentialStatus(cloudCredential, CredentialStatus.FAILED, e, errorMessage);
}
return new CloudCredentialStatus(cloudCredential, CredentialStatus.CREATED);
}
use of com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView in project cloudbreak by hortonworks.
the class AwsCredentialConnector method verify.
@Override
public CloudCredentialStatus verify(AuthenticatedContext authenticatedContext) {
CloudCredential credential = authenticatedContext.getCloudCredential();
LOGGER.info("Create credential: {}", credential);
AwsCredentialView awsCredential = new AwsCredentialView(credential);
String roleArn = awsCredential.getRoleArn();
String accessKey = awsCredential.getAccessKey();
String secretKey = awsCredential.getSecretKey();
String smartSenseId = smartSenseIdGenerator.getSmartSenseId(awsCredential);
if (isNoneEmpty(smartSenseId)) {
credential.putParameter(SMART_SENSE_ID, smartSenseId);
}
if (isNoneEmpty(roleArn) && isNoneEmpty(accessKey) && isNoneEmpty(secretKey)) {
String message = "Please only provide the 'role arn' or the 'access' and 'secret key'";
return new CloudCredentialStatus(credential, CredentialStatus.FAILED, new Exception(message), message);
}
if (isNoneEmpty(roleArn)) {
return verifyIamRoleIsAssumable(credential);
}
if (isEmpty(accessKey) || isEmpty(secretKey)) {
String message = "Please provide both the 'access' and 'secret key'";
return new CloudCredentialStatus(credential, CredentialStatus.FAILED, new Exception(message), message);
} else {
return verifyAccessKeySecretKeyIsAssumable(credential);
}
}
use of com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView in project cloudbreak by hortonworks.
the class AwsInstanceConnector method check.
@Override
public List<CloudVmInstanceStatus> check(AuthenticatedContext ac, List<CloudInstance> vms) {
List<CloudVmInstanceStatus> cloudVmInstanceStatuses = new ArrayList<>();
for (CloudInstance vm : vms) {
try {
String region = ac.getCloudContext().getLocation().getRegion().value();
DescribeInstancesResult result = awsClient.createAccess(new AwsCredentialView(ac.getCloudCredential()), ac.getCloudContext().getLocation().getRegion().value()).describeInstances(new DescribeInstancesRequest().withInstanceIds(vm.getInstanceId()));
for (Reservation reservation : result.getReservations()) {
for (Instance instance : reservation.getInstances()) {
if ("Stopped".equalsIgnoreCase(instance.getState().getName())) {
LOGGER.info("AWS instance [{}] is in {} state, region: {}, stack: {}", instance.getInstanceId(), instance.getState().getName(), region, ac.getCloudContext().getId());
cloudVmInstanceStatuses.add(new CloudVmInstanceStatus(vm, InstanceStatus.STOPPED));
} else if ("Running".equalsIgnoreCase(instance.getState().getName())) {
LOGGER.info("AWS instance [{}] is in {} state, region: {}, stack: {}", instance.getInstanceId(), instance.getState().getName(), region, ac.getCloudContext().getId());
cloudVmInstanceStatuses.add(new CloudVmInstanceStatus(vm, InstanceStatus.STARTED));
} else if ("Terminated".equalsIgnoreCase(instance.getState().getName())) {
LOGGER.info("AWS instance [{}] is in {} state, region: {}, stack: {}", instance.getInstanceId(), instance.getState().getName(), region, ac.getCloudContext().getId());
cloudVmInstanceStatuses.add(new CloudVmInstanceStatus(vm, InstanceStatus.TERMINATED));
} else {
LOGGER.info("AWS instance [{}] is in {} state, region: {}, stack: {}", instance.getInstanceId(), instance.getState().getName(), region, ac.getCloudContext().getId());
cloudVmInstanceStatuses.add(new CloudVmInstanceStatus(vm, InstanceStatus.IN_PROGRESS));
}
}
}
} catch (AmazonEC2Exception e) {
LOGGER.warn("Instance does not exist with this id: {}, original message: {}", vm.getInstanceId(), e.getMessage());
}
}
return cloudVmInstanceStatuses;
}
use of com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView in project cloudbreak by hortonworks.
the class AwsPlatformResources method securityGroups.
@Override
public CloudSecurityGroups securityGroups(CloudCredential cloudCredential, Region region, Map<String, String> filters) {
Map<String, Set<CloudSecurityGroup>> result = new HashMap<>();
Set<CloudSecurityGroup> cloudSecurityGroups = new HashSet<>();
AmazonEC2Client ec2Client = awsClient.createAccess(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 : ec2Client.describeSecurityGroups(describeSecurityGroupsRequest).getSecurityGroups()) {
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.view.AwsCredentialView in project cloudbreak by hortonworks.
the class AwsResourceConnector method suspendAutoScaling.
private void suspendAutoScaling(AuthenticatedContext ac, CloudStack stack) {
AmazonAutoScalingClient amazonASClient = awsClient.createAutoScalingClient(new AwsCredentialView(ac.getCloudCredential()), ac.getCloudContext().getLocation().getRegion().value());
for (Group group : stack.getGroups()) {
String asGroupName = cfStackUtil.getAutoscalingGroupName(ac, group.getName(), ac.getCloudContext().getLocation().getRegion().value());
amazonASClient.suspendProcesses(new SuspendProcessesRequest().withAutoScalingGroupName(asGroupName).withScalingProcesses(SUSPENDED_PROCESSES));
}
}
Aggregations