use of com.amazonaws.services.ec2.model.Instance in project SimianArmy by Netflix.
the class TestInstanceJanitorCrawler method testInstancesWithResourceType.
@Test
public void testInstancesWithResourceType() {
List<AutoScalingInstanceDetails> instanceDetailsList = createInstanceDetailsList();
List<Instance> instanceList = createInstanceList();
AWSClient awsMock = createMockAWSClient(instanceDetailsList, instanceList);
InstanceJanitorCrawler crawler = new InstanceJanitorCrawler(awsMock);
for (AWSResourceType resourceType : AWSResourceType.values()) {
List<Resource> resources = crawler.resources(resourceType);
if (resourceType == AWSResourceType.INSTANCE) {
verifyInstanceList(resources, instanceDetailsList);
} else {
Assert.assertTrue(resources.isEmpty());
}
}
}
use of com.amazonaws.services.ec2.model.Instance in project eureka by Netflix.
the class ElasticNetworkInterfaceBinder method bind.
/**
* Binds an ENI to the instance.
*
* The candidate ENI's are deduced in the same wa the EIP binder works: Via dns records or via service urls,
* depending on configuration.
*
* It will try to attach the first ENI that is:
* Available
* For this subnet
* In the list of candidate ENI's
*
* @throws MalformedURLException
*/
public void bind() throws MalformedURLException {
InstanceInfo myInfo = ApplicationInfoManager.getInstance().getInfo();
String myInstanceId = ((AmazonInfo) myInfo.getDataCenterInfo()).get(AmazonInfo.MetaDataKey.instanceId);
String myZone = ((AmazonInfo) myInfo.getDataCenterInfo()).get(AmazonInfo.MetaDataKey.availabilityZone);
final List<String> ips = getCandidateIps();
Ordering<NetworkInterface> ipsOrder = Ordering.natural().onResultOf(new Function<NetworkInterface, Integer>() {
public Integer apply(NetworkInterface networkInterface) {
return ips.indexOf(networkInterface.getPrivateIpAddress());
}
});
AmazonEC2 ec2Service = getEC2Service();
String subnetId = instanceData(myInstanceId, ec2Service).getSubnetId();
DescribeNetworkInterfacesResult result = ec2Service.describeNetworkInterfaces(new DescribeNetworkInterfacesRequest().withFilters(new Filter("private-ip-address", ips)).withFilters(new Filter("status", Lists.newArrayList("available"))).withFilters(new Filter("subnet-id", Lists.newArrayList(subnetId))));
if (result.getNetworkInterfaces().isEmpty()) {
logger.info("No ip is free to be associated with this instance. Candidate ips are: {} for zone: ", ips, myZone);
} else {
NetworkInterface selected = ipsOrder.min(result.getNetworkInterfaces());
ec2Service.attachNetworkInterface(new AttachNetworkInterfaceRequest().withNetworkInterfaceId(selected.getNetworkInterfaceId()).withDeviceIndex(1).withInstanceId(myInstanceId));
}
}
use of com.amazonaws.services.ec2.model.Instance in project eureka by Netflix.
the class ElasticNetworkInterfaceBinder method alreadyBound.
public boolean alreadyBound() throws MalformedURLException {
InstanceInfo myInfo = applicationInfoManager.getInfo();
String myInstanceId = ((AmazonInfo) myInfo.getDataCenterInfo()).get(AmazonInfo.MetaDataKey.instanceId);
AmazonEC2 ec2Service = getEC2Service();
List<InstanceNetworkInterface> instanceNetworkInterfaces = instanceData(myInstanceId, ec2Service).getNetworkInterfaces();
List<String> candidateIPs = getCandidateIps();
for (String ip : candidateIPs) {
for (InstanceNetworkInterface ini : instanceNetworkInterfaces) {
if (ip.equals(ini.getPrivateIpAddress())) {
logger.info("My instance {} seems to be already associated with the ip {}", myInstanceId, ip);
return true;
}
}
}
return false;
}
use of com.amazonaws.services.ec2.model.Instance in project chassis by Kixeye.
the class AwsUtils method getInstanceName.
/**
* Fetches and instance's name Tag or null if it does not have one
* @param instanceId
* @param amazonEC2
* @return
*/
public static String getInstanceName(String instanceId, AmazonEC2 amazonEC2) {
DescribeTagsResult result = amazonEC2.describeTags(new DescribeTagsRequest().withFilters(new Filter().withName("resource-id").withValues(instanceId), new Filter().withName("resource-type").withValues("instance"), new Filter().withName("key").withValues(TAG_KEY_NAME)));
if (result.getTags().isEmpty()) {
return null;
}
String name = result.getTags().get(0).getValue();
return name == null || name.trim().equals("") ? null : name;
}
use of com.amazonaws.services.ec2.model.Instance in project GNS by MobilityFirst.
the class AWSEC2 method describeInstances.
/**
* Describe Current Instances
*
* @param ec2
*/
public static void describeInstances(AmazonEC2 ec2) {
StringBuilder output = new StringBuilder();
String prefix = currentTab + "Current Instances: ";
DescribeInstancesResult describeInstancesResult = ec2.describeInstances();
List<Reservation> reservations = describeInstancesResult.getReservations();
Set<Instance> instances = new HashSet<Instance>();
// add all instances to a Set.
for (Reservation reservation : reservations) {
instances.addAll(reservation.getInstances());
}
prefix = prefix.concat(" [" + instances.size() + " total] ");
for (Instance ins : instances) {
// instance state
output.append(prefix);
prefix = ", ";
output.append(ins.getPublicDnsName());
output.append(" (");
output.append(ins.getInstanceId());
output.append(") ");
output.append(ins.getState().getName());
}
System.out.println(output);
}
Aggregations