use of com.amazonaws.services.ec2.model.DescribeInstancesRequest in project druid by druid-io.
the class EC2AutoScaler method ipToIdLookup.
@Override
public List<String> ipToIdLookup(List<String> ips) {
final List<String> retVal = FluentIterable.from(Lists.partition(ips, MAX_AWS_FILTER_VALUES)).transformAndConcat(new Function<List<String>, Iterable<Reservation>>() {
@Override
public Iterable<Reservation> apply(List<String> input) {
return amazonEC2Client.describeInstances(new DescribeInstancesRequest().withFilters(new Filter("private-ip-address", input))).getReservations();
}
}).transformAndConcat(new Function<Reservation, Iterable<Instance>>() {
@Override
public Iterable<Instance> apply(Reservation reservation) {
return reservation.getInstances();
}
}).transform(new Function<Instance, String>() {
@Override
public String apply(Instance instance) {
return instance.getInstanceId();
}
}).toList();
log.debug("Performing lookup: %s --> %s", ips, retVal);
return retVal;
}
use of com.amazonaws.services.ec2.model.DescribeInstancesRequest in project GNS by MobilityFirst.
the class AWSStatusCheck method main.
/**
*
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
init();
/*
* Amazon EC2
*/
for (String endpoint : endpoints) {
try {
ec2.setEndpoint(endpoint);
System.out.println("**** Endpoint: " + endpoint);
DescribeAvailabilityZonesResult availabilityZonesResult = ec2.describeAvailabilityZones();
System.out.println("You have access to " + availabilityZonesResult.getAvailabilityZones().size() + " Availability Zones.");
for (AvailabilityZone zone : availabilityZonesResult.getAvailabilityZones()) {
System.out.println(zone.getZoneName());
}
DescribeInstancesResult describeInstancesRequest = ec2.describeInstances();
List<Reservation> reservations = describeInstancesRequest.getReservations();
Set<Instance> instances = new HashSet<Instance>();
System.out.println("Instances: ");
for (Reservation reservation : reservations) {
for (Instance instance : reservation.getInstances()) {
instances.add(instance);
System.out.println(instance.getPublicDnsName() + " is " + instance.getState().getName());
}
}
System.out.println("Security groups: ");
DescribeSecurityGroupsResult describeSecurityGroupsResult = ec2.describeSecurityGroups();
for (SecurityGroup securityGroup : describeSecurityGroupsResult.getSecurityGroups()) {
System.out.println(securityGroup.getGroupName());
}
//System.out.println("You have " + instances.size() + " Amazon EC2 instance(s) running.");
} catch (AmazonServiceException ase) {
System.out.println("Caught Exception: " + ase.getMessage());
System.out.println("Reponse Status Code: " + ase.getStatusCode());
System.out.println("Error Code: " + ase.getErrorCode());
System.out.println("Request ID: " + ase.getRequestId());
}
/*
* Amazon SimpleDB
*
*/
try {
ListDomainsRequest sdbRequest = new ListDomainsRequest().withMaxNumberOfDomains(100);
ListDomainsResult sdbResult = sdb.listDomains(sdbRequest);
int totalItems = 0;
for (String domainName : sdbResult.getDomainNames()) {
DomainMetadataRequest metadataRequest = new DomainMetadataRequest().withDomainName(domainName);
DomainMetadataResult domainMetadata = sdb.domainMetadata(metadataRequest);
totalItems += domainMetadata.getItemCount();
}
System.out.println("You have " + sdbResult.getDomainNames().size() + " Amazon SimpleDB domain(s)" + "containing a total of " + totalItems + " items.");
} catch (AmazonServiceException ase) {
System.out.println("Caught Exception: " + ase.getMessage());
System.out.println("Reponse Status Code: " + ase.getStatusCode());
System.out.println("Error Code: " + ase.getErrorCode());
System.out.println("Request ID: " + ase.getRequestId());
}
/*
* Amazon S3
*.
*/
try {
List<Bucket> buckets = s3.listBuckets();
long totalSize = 0;
int totalItems = 0;
for (Bucket bucket : buckets) {
/*
* In order to save bandwidth, an S3 object listing does not
* contain every object in the bucket; after a certain point the
* S3ObjectListing is truncated, and further pages must be
* obtained with the AmazonS3Client.listNextBatchOfObjects()
* method.
*/
ObjectListing objects = s3.listObjects(bucket.getName());
do {
for (S3ObjectSummary objectSummary : objects.getObjectSummaries()) {
totalSize += objectSummary.getSize();
totalItems++;
}
objects = s3.listNextBatchOfObjects(objects);
} while (objects.isTruncated());
}
System.out.println("You have " + buckets.size() + " Amazon S3 bucket(s), " + "containing " + totalItems + " objects with a total size of " + totalSize + " bytes.");
} catch (AmazonServiceException ase) {
/*
* AmazonServiceExceptions represent an error response from an AWS
* services, i.e. your request made it to AWS, but the AWS service
* either found it invalid or encountered an error trying to execute
* it.
*/
System.out.println("Error Message: " + ase.getMessage());
System.out.println("HTTP Status Code: " + ase.getStatusCode());
System.out.println("AWS Error Code: " + ase.getErrorCode());
System.out.println("Error Type: " + ase.getErrorType());
System.out.println("Request ID: " + ase.getRequestId());
} catch (AmazonClientException ace) {
/*
* AmazonClientExceptions represent an error that occurred inside
* the client on the local host, either while trying to send the
* request to AWS or interpret the response. For example, if no
* network connection is available, the client won't be able to
* connect to AWS to execute a request and will throw an
* AmazonClientException.
*/
System.out.println("Error Message: " + ace.getMessage());
}
}
}
use of com.amazonaws.services.ec2.model.DescribeInstancesRequest in project camel by apache.
the class EC2Producer method describeInstances.
private void describeInstances(AmazonEC2Client ec2Client, Exchange exchange) {
Collection instanceIds;
DescribeInstancesRequest request = new DescribeInstancesRequest();
if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(EC2Constants.INSTANCES_IDS))) {
instanceIds = exchange.getIn().getHeader(EC2Constants.INSTANCES_IDS, Collection.class);
request.withInstanceIds(instanceIds);
}
DescribeInstancesResult result;
try {
result = ec2Client.describeInstances(request);
} catch (AmazonServiceException ase) {
LOG.trace("Describe Instances command returned the error code {}", ase.getErrorCode());
throw ase;
}
Message message = getMessageForResponse(exchange);
message.setBody(result);
}
use of com.amazonaws.services.ec2.model.DescribeInstancesRequest in project camel by apache.
the class AmazonEC2ClientMock method describeInstances.
@Override
public DescribeInstancesResult describeInstances(DescribeInstancesRequest describeInstancesRequest) {
DescribeInstancesResult result = new DescribeInstancesResult();
if (describeInstancesRequest.getInstanceIds().isEmpty()) {
Collection<Reservation> list = new ArrayList<Reservation>();
Reservation res = new Reservation();
res.setOwnerId("1");
res.setRequesterId("user-test");
res.setReservationId("res-1");
Collection<Instance> instances = new ArrayList();
Instance ins = new Instance();
ins.setImageId("id-1");
ins.setInstanceType(InstanceType.T2Micro);
ins.setInstanceId("instance-1");
instances.add(ins);
Instance ins1 = new Instance();
ins1.setImageId("id-2");
ins1.setInstanceType(InstanceType.T2Micro);
ins1.setInstanceId("instance-2");
instances.add(ins1);
res.setInstances(instances);
list.add(res);
result.setReservations(list);
} else {
if (describeInstancesRequest.getInstanceIds().contains("instance-1")) {
Collection<Reservation> list = new ArrayList<Reservation>();
Reservation res = new Reservation();
res.setOwnerId("1");
res.setRequesterId("user-test");
res.setReservationId("res-1");
Collection<Instance> instances = new ArrayList();
Instance ins = new Instance();
ins.setImageId("id-1");
ins.setInstanceType(InstanceType.T2Micro);
ins.setInstanceId("instance-1");
instances.add(ins);
res.setInstances(instances);
list.add(res);
result.setReservations(list);
}
}
return result;
}
use of com.amazonaws.services.ec2.model.DescribeInstancesRequest in project ignite by apache.
the class TcpDiscoveryElbIpFinder method getRegisteredAddresses.
/**
* {@inheritDoc}
*/
@Override
public Collection<InetSocketAddress> getRegisteredAddresses() throws IgniteSpiException {
initClients();
List<String> instanceIds = new ArrayList<>();
DescribeLoadBalancersRequest req = new DescribeLoadBalancersRequest().withLoadBalancerNames(loadBalancerName);
List<LoadBalancerDescription> descs = amazonELBClient.describeLoadBalancers(req).getLoadBalancerDescriptions();
for (LoadBalancerDescription desc : descs) {
for (Instance instance : desc.getInstances()) instanceIds.add(instance.getInstanceId());
}
DescribeInstancesRequest instReq = new DescribeInstancesRequest().withInstanceIds(instanceIds);
List<Reservation> reservations = amazonEC2Client.describeInstances(instReq).getReservations();
List<InetSocketAddress> addrs = new ArrayList<>();
for (Reservation reservation : reservations) {
List<com.amazonaws.services.ec2.model.Instance> instances = reservation.getInstances();
for (com.amazonaws.services.ec2.model.Instance instance : instances) addrs.add(new InetSocketAddress(instance.getPrivateIpAddress(), 0));
}
return addrs;
}
Aggregations