use of com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client in project cloudbreak by hortonworks.
the class AwsNativeMetadataCollector method collect.
@Override
public List<CloudVmMetaDataStatus> collect(AuthenticatedContext ac, List<CloudResource> resources, List<CloudInstance> vms, List<CloudInstance> allInstances) {
LOGGER.debug("Collect AWS instance metadata, for cluster {} resources: {}, VMs: {}, allInstances: {}", ac.getCloudContext().getName(), resources.size(), vms.size(), allInstances.size());
try {
String region = ac.getCloudContext().getLocation().getRegion().value();
AmazonEc2Client ec2Client = awsClient.createEc2Client(new AwsCredentialView(ac.getCloudCredential()), region);
return collectInstances(vms, resources, ec2Client);
} catch (RuntimeException e) {
LOGGER.warn("Collection of instance metadata failed", e);
throw new CloudConnectorException(e.getMessage(), e);
}
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client in project cloudbreak by hortonworks.
the class AwsNativeMetadataCollector method describeInstances.
private List<CloudVmMetaDataStatus> describeInstances(List<CloudInstance> vms, List<String> instanceIdList, Map<String, CloudResource> resourcesByInstanceId, AmazonEc2Client ec2Client) {
LOGGER.info("Collecting metadata for instance IDs: '{}'", String.join(", ", instanceIdList));
List<CloudVmMetaDataStatus> result = new ArrayList<>();
DescribeInstancesRequest instancesRequest = new DescribeInstancesRequest().withInstanceIds(instanceIdList);
DescribeInstancesResult instancesResult = ec2Client.describeInstances(instancesRequest);
List<Instance> instances = instancesResult.getReservations().stream().flatMap(reservation -> reservation.getInstances().stream()).collect(Collectors.toList());
for (Instance instance : instances) {
String instanceId = instance.getInstanceId();
CloudResource connectedResource = findCloudResourceByInstanceId(resourcesByInstanceId, instanceId);
CloudInstance matchedInstance = findCloudInstanceByPrivateId(vms, connectedResource);
CloudInstance updatedInstance = new CloudInstance(connectedResource.getInstanceId(), matchedInstance.getTemplate(), matchedInstance.getAuthentication(), matchedInstance.getSubnetId(), matchedInstance.getAvailabilityZone());
CloudInstanceMetaData cloudInstanceMetaData = new CloudInstanceMetaData(instance.getPrivateIpAddress(), instance.getPublicIpAddress(), awsLifeCycleMapper.getLifeCycle(instance));
CloudVmInstanceStatus cloudVmInstanceStatus = new CloudVmInstanceStatus(updatedInstance, updatedInstance.getTemplate().getStatus());
CloudVmMetaDataStatus newMetadataStatus = new CloudVmMetaDataStatus(cloudVmInstanceStatus, cloudInstanceMetaData);
result.add(newMetadataStatus);
}
return result;
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client in project cloudbreak by hortonworks.
the class AwsSecurityGroupResourceBuilder method delete.
@Override
public CloudResource delete(AwsContext context, AuthenticatedContext auth, CloudResource resource, Network network) throws Exception {
AmazonEc2Client amazonEc2Client = context.getAmazonEc2Client();
if (resource.getReference() != null) {
DeleteSecurityGroupRequest request = new DeleteSecurityGroupRequest().withGroupId(resource.getReference());
DeleteSecurityGroupResult result = awsMethodExecutor.execute(() -> amazonEc2Client.deleteSecurityGroup(request), null);
return result == null ? null : resource;
}
SecurityGroup securityGroup = securityGroupBuilderUtil.getSecurityGroupSilent(amazonEc2Client, network.getStringParameter("vpcId"), resource.getName());
LOGGER.info("Reference is null, cannot be deleted on the provider. Maybe it is not a Cloudbreak managed security group: {}", securityGroup);
return null;
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client in project cloudbreak by hortonworks.
the class AwsSecurityGroupResourceBuilder method build.
@Override
public CloudResource build(AwsContext context, AuthenticatedContext auth, Group group, Network network, Security security, CloudResource resource) throws Exception {
AmazonEc2Client amazonEc2Client = context.getAmazonEc2Client();
String securityGroupId = securityGroupBuilderUtil.createSecurityGroup(network, group, amazonEc2Client, auth.getCloudContext(), auth);
LOGGER.info("Security group successfully created with id: {}", securityGroupId);
return CloudResource.builder().cloudResource(resource).reference(securityGroupId).build();
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client in project cloudbreak by hortonworks.
the class AwsNativeEIPResourceBuilder method create.
@Override
public List<CloudResource> create(AwsContext context, CloudInstance instance, long privateId, AuthenticatedContext auth, Group group, Image image) {
List<CloudResource> resources = new ArrayList<>();
if (InstanceGroupType.GATEWAY.equals(group.getType())) {
CloudContext cloudContext = auth.getCloudContext();
AmazonEc2Client amazonEC2Client = context.getAmazonEc2Client();
boolean mapPublicIpOnLaunch = awsNetworkService.isMapPublicOnLaunch(List.of(instance.getSubnetId()), amazonEC2Client);
if (mapPublicIpOnLaunch) {
String resourceName = getResourceNameService().resourceName(resourceType(), cloudContext.getName(), group.getName(), privateId);
return singletonList(CloudResource.builder().group(group.getName()).type(resourceType()).status(CommonStatus.REQUESTED).name(resourceName).persistent(true).reference(String.valueOf(privateId)).build());
} else {
LOGGER.debug("EIp doesn't need because no public ip on launch");
}
}
return resources;
}
Aggregations