use of software.amazon.awssdk.services.ec2.model.Instance in project SimianArmy by Netflix.
the class TestInstanceInVPC method setUp.
@BeforeMethod
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
List<Instance> instanceList = Lists.newArrayList();
Instance instance = new Instance().withInstanceId(VPC_INSTANCE_ID).withVpcId("12345");
instanceList.add(instance);
doReturn(instanceList).when(instanceInVPC).getAWSInstances(REGION, VPC_INSTANCE_ID);
List<Instance> instanceList2 = Lists.newArrayList();
Instance instance2 = new Instance().withInstanceId(INSTANCE_ID);
instanceList2.add(instance2);
doReturn(instanceList2).when(instanceInVPC).getAWSInstances(REGION, INSTANCE_ID);
}
use of software.amazon.awssdk.services.ec2.model.Instance in project SimianArmy by Netflix.
the class TestInstanceJanitorCrawler method testInstancesWithIds.
@Test
public void testInstancesWithIds() {
List<AutoScalingInstanceDetails> instanceDetailsList = createInstanceDetailsList();
List<Instance> instanceList = createInstanceList();
String[] ids = { "i-12345678901234560", "i-12345678901234561" };
AWSClient awsMock = createMockAWSClient(instanceDetailsList, instanceList, ids);
InstanceJanitorCrawler crawler = new InstanceJanitorCrawler(awsMock);
List<Resource> resources = crawler.resources(ids);
verifyInstanceList(resources, instanceDetailsList);
}
use of software.amazon.awssdk.services.ec2.model.Instance in project SimianArmy by Netflix.
the class TestInstanceJanitorCrawler method testInstancesNotExistingInASG.
@Test
public void testInstancesNotExistingInASG() {
List<AutoScalingInstanceDetails> instanceDetailsList = Collections.emptyList();
List<Instance> instanceList = createInstanceList();
AWSClient awsMock = createMockAWSClient(instanceDetailsList, instanceList);
InstanceJanitorCrawler crawler = new InstanceJanitorCrawler(awsMock);
List<Resource> resources = crawler.resources();
Assert.assertEquals(resources.size(), instanceList.size());
}
use of software.amazon.awssdk.services.ec2.model.Instance in project SimianArmy by Netflix.
the class AWSClient method listAttachedVolumes.
@Override
public List<String> listAttachedVolumes(String instanceId, boolean includeRoot) {
Validate.notEmpty(instanceId);
LOGGER.info(String.format("Listing volumes attached to instance %s in region %s.", instanceId, region));
try {
List<String> volumeIds = new ArrayList<String>();
for (Instance instance : describeInstances(instanceId)) {
String rootDeviceName = instance.getRootDeviceName();
for (InstanceBlockDeviceMapping ibdm : instance.getBlockDeviceMappings()) {
EbsInstanceBlockDevice ebs = ibdm.getEbs();
if (ebs == null) {
continue;
}
String volumeId = ebs.getVolumeId();
if (Strings.isNullOrEmpty(volumeId)) {
continue;
}
if (!includeRoot && rootDeviceName != null && rootDeviceName.equals(ibdm.getDeviceName())) {
continue;
}
volumeIds.add(volumeId);
}
}
return volumeIds;
} catch (AmazonServiceException e) {
if (e.getErrorCode().equals("InvalidInstanceID.NotFound")) {
throw new NotFoundException("AWS instance " + instanceId + " not found", e);
}
throw e;
}
}
use of software.amazon.awssdk.services.ec2.model.Instance in project SimianArmy by Netflix.
the class InstanceJanitorCrawler method getInstanceResources.
private List<Resource> getInstanceResources(String... instanceIds) {
List<Resource> resources = new LinkedList<Resource>();
AWSClient awsClient = getAWSClient();
Map<String, AutoScalingInstanceDetails> idToASGInstance = new HashMap<String, AutoScalingInstanceDetails>();
for (AutoScalingInstanceDetails instanceDetails : awsClient.describeAutoScalingInstances(instanceIds)) {
idToASGInstance.put(instanceDetails.getInstanceId(), instanceDetails);
}
for (Instance instance : awsClient.describeInstances(instanceIds)) {
Resource instanceResource = new AWSResource().withId(instance.getInstanceId()).withRegion(getAWSClient().region()).withResourceType(AWSResourceType.INSTANCE).withLaunchTime(instance.getLaunchTime());
for (Tag tag : instance.getTags()) {
instanceResource.setTag(tag.getKey(), tag.getValue());
}
String description = String.format("type=%s; host=%s", instance.getInstanceType(), instance.getPublicDnsName() == null ? "" : instance.getPublicDnsName());
instanceResource.setDescription(description);
instanceResource.setOwnerEmail(getOwnerEmailForResource(instanceResource));
String asgName = getAsgName(instanceResource, idToASGInstance);
if (asgName != null) {
instanceResource.setAdditionalField(INSTANCE_FIELD_ASG_NAME, asgName);
LOGGER.info(String.format("instance %s has a ASG tag name %s.", instanceResource.getId(), asgName));
}
String opsworksStackName = getOpsWorksStackName(instanceResource);
if (opsworksStackName != null) {
instanceResource.setAdditionalField(INSTANCE_FIELD_OPSWORKS_STACK_NAME, opsworksStackName);
LOGGER.info(String.format("instance %s is part of an OpsWorks stack named %s.", instanceResource.getId(), opsworksStackName));
}
if (instance.getState() != null) {
((AWSResource) instanceResource).setAWSResourceState(instance.getState().getName());
}
resources.add(instanceResource);
}
return resources;
}
Aggregations