use of software.amazon.awssdk.services.ec2.model.Instance in project airavata by apache.
the class InstancesLoader method load.
/**
* Load instance list.
*
* @param list instance list
*/
public void load(final XbayaEnhancedList<EC2InstanceResult> list) {
new Thread(new Runnable() {
@Override
public void run() {
try {
List<EC2InstanceResult> tmpList = new ArrayList<EC2InstanceResult>();
List<Instance> instances = AmazonUtil.loadInstances();
for (Instance instance : instances) {
tmpList.add(new EC2InstanceResult(instance));
}
if (!InstancesLoader.this.canceled) {
list.setListData(tmpList);
}
} catch (AmazonServiceException ex) {
InstancesLoader.this.engine.getGUI().getErrorWindow().error(InstancesLoader.this.parent, "Cannot load EC2 instances", ex);
} catch (AmazonClientException ex) {
InstancesLoader.this.engine.getGUI().getErrorWindow().error(InstancesLoader.this.parent, "Cannot load EC2 instances", ex);
} finally {
InstancesLoader.this.loadingDialog.hide();
}
}
}).start();
this.loadingDialog.show();
}
use of software.amazon.awssdk.services.ec2.model.Instance in project cloudbreak by hortonworks.
the class TagsUtil method checkTagsAws.
protected static void checkTagsAws(Regions region, Collection<String> instanceIdList, Map<String, String> tagsToCheckMap) {
Map<String, String> extractedTagsToCheck = new HashMap<>();
List<Tag> extractedTags;
AmazonEC2 ec2 = AmazonEC2ClientBuilder.standard().withRegion(region).build();
DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest();
describeInstancesRequest.withInstanceIds(instanceIdList);
DescribeInstancesResult describeInstancesResultAll = ec2.describeInstances(describeInstancesRequest);
List<Reservation> reservationsAll = describeInstancesResultAll.getReservations();
for (Reservation reservation : reservationsAll) {
for (Instance instance : reservation.getInstances()) {
extractedTags = instance.getTags();
Assert.assertNotNull(extractedTags);
for (Tag tag : extractedTags) {
extractedTagsToCheck.put(tag.getKey(), tag.getValue());
}
checkTags(tagsToCheckMap, extractedTagsToCheck);
extractedTags.clear();
}
}
}
use of software.amazon.awssdk.services.ec2.model.Instance in project cloudbreak by hortonworks.
the class AwsMetaDataCollectorTest method collectMigratedExistingOneGroup.
@Test
public void collectMigratedExistingOneGroup() {
List<CloudInstance> vms = new ArrayList<>();
List<Volume> volumes = new ArrayList<>();
InstanceAuthentication instanceAuthentication = new InstanceAuthentication("sshkey", "", "cloudbreak");
vms.add(new CloudInstance("i-1", new InstanceTemplate("fla", "cbgateway", 5L, volumes, InstanceStatus.CREATED, null, 0L), instanceAuthentication));
when(awsClient.createCloudFormationClient(any(AwsCredentialView.class), eq("region"))).thenReturn(amazonCFClient);
when(awsClient.createAutoScalingClient(any(AwsCredentialView.class), eq("region"))).thenReturn(amazonASClient);
when(awsClient.createAccess(any(AwsCredentialView.class), eq("region"))).thenReturn(amazonEC2Client);
when(cloudFormationStackUtil.getAutoscalingGroupName(any(AuthenticatedContext.class), any(AmazonCloudFormationClient.class), eq("cbgateway"))).thenReturn("cbgateway-AAA");
List<String> gatewayIds = Collections.singletonList("i-1");
when(cloudFormationStackUtil.getInstanceIds(any(AmazonAutoScalingClient.class), eq("cbgateway-AAA"))).thenReturn(gatewayIds);
when(cloudFormationStackUtil.createDescribeInstancesRequest(eq(gatewayIds))).thenReturn(describeInstancesRequestGw);
when(amazonEC2Client.describeInstances(describeInstancesRequestGw)).thenReturn(describeInstancesResultGw);
Instance instance = Mockito.mock(Instance.class);
when(instance.getInstanceId()).thenReturn("i-1");
when(instance.getPrivateIpAddress()).thenReturn("privateIp");
when(instance.getPublicIpAddress()).thenReturn("publicIp");
List<Reservation> gatewayReservations = Collections.singletonList(getReservation(instance));
when(describeInstancesResultGw.getReservations()).thenReturn(gatewayReservations);
AuthenticatedContext ac = authenticatedContext();
List<CloudVmMetaDataStatus> statuses = awsMetadataCollector.collect(ac, null, vms);
verify(amazonEC2Client).createTags(any(CreateTagsRequest.class));
Assert.assertEquals(1, statuses.size());
Assert.assertEquals("i-1", statuses.get(0).getCloudVmInstanceStatus().getCloudInstance().getInstanceId());
Assert.assertEquals("privateIp", statuses.get(0).getMetaData().getPrivateIp());
Assert.assertEquals("publicIp", statuses.get(0).getMetaData().getPublicIp());
}
use of software.amazon.awssdk.services.ec2.model.Instance in project cloudbreak by hortonworks.
the class AwsMetaDataCollectorTest method collectNewAndExistingOneGroup.
@Test
public void collectNewAndExistingOneGroup() {
List<CloudInstance> vms = new ArrayList<>();
List<Volume> volumes = new ArrayList<>();
InstanceAuthentication instanceAuthentication = new InstanceAuthentication("sshkey", "", "cloudbreak");
vms.add(new CloudInstance(null, new InstanceTemplate("fla", "cbgateway", 5L, volumes, InstanceStatus.CREATED, null, 0L), instanceAuthentication));
vms.add(new CloudInstance("i-1", new InstanceTemplate("fla", "cbgateway", 5L, volumes, InstanceStatus.CREATED, null, 0L), instanceAuthentication));
when(awsClient.createCloudFormationClient(any(AwsCredentialView.class), eq("region"))).thenReturn(amazonCFClient);
when(awsClient.createAutoScalingClient(any(AwsCredentialView.class), eq("region"))).thenReturn(amazonASClient);
when(awsClient.createAccess(any(AwsCredentialView.class), eq("region"))).thenReturn(amazonEC2Client);
when(cloudFormationStackUtil.getAutoscalingGroupName(any(AuthenticatedContext.class), any(AmazonCloudFormationClient.class), eq("cbgateway"))).thenReturn("cbgateway-AAA");
List<String> gatewayIds = Arrays.asList("i-1", "i-2");
when(cloudFormationStackUtil.getInstanceIds(any(AmazonAutoScalingClient.class), eq("cbgateway-AAA"))).thenReturn(gatewayIds);
when(cloudFormationStackUtil.createDescribeInstancesRequest(eq(gatewayIds))).thenReturn(describeInstancesRequestGw);
when(amazonEC2Client.describeInstances(describeInstancesRequestGw)).thenReturn(describeInstancesResultGw);
Instance instance1 = Mockito.mock(Instance.class);
when(instance1.getInstanceId()).thenReturn("i-1");
when(instance1.getPrivateIpAddress()).thenReturn("privateIp1");
when(instance1.getPublicIpAddress()).thenReturn("publicIp1");
Instance instance2 = Mockito.mock(Instance.class);
when(instance2.getInstanceId()).thenReturn("i-2");
when(instance2.getPrivateIpAddress()).thenReturn("privateIp2");
when(instance2.getPublicIpAddress()).thenReturn("publicIp2");
List<Reservation> gatewayReservations = Collections.singletonList(getReservation(instance1, instance2));
when(describeInstancesResultGw.getReservations()).thenReturn(gatewayReservations);
AuthenticatedContext ac = authenticatedContext();
List<CloudVmMetaDataStatus> statuses = awsMetadataCollector.collect(ac, null, vms);
verify(amazonEC2Client, times(2)).createTags(any(CreateTagsRequest.class));
Assert.assertEquals(2, statuses.size());
Assert.assertEquals("i-1", statuses.get(0).getCloudVmInstanceStatus().getCloudInstance().getInstanceId());
Assert.assertEquals("privateIp1", statuses.get(0).getMetaData().getPrivateIp());
Assert.assertEquals("publicIp1", statuses.get(0).getMetaData().getPublicIp());
Assert.assertEquals("i-2", statuses.get(1).getCloudVmInstanceStatus().getCloudInstance().getInstanceId());
Assert.assertEquals("privateIp2", statuses.get(1).getMetaData().getPrivateIp());
Assert.assertEquals("publicIp2", statuses.get(1).getMetaData().getPublicIp());
}
use of software.amazon.awssdk.services.ec2.model.Instance in project onebusaway-application-modules by camsys.
the class BundleServerServiceImpl method getInstance.
private Instance getInstance(String instanceId) {
try {
DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest();
List<String> list = new ArrayList<String>();
list.add(instanceId);
describeInstancesRequest.setInstanceIds(list);
// this call can timeout and throw AmazonClientException if AWS is having
// a bad day
DescribeInstancesResult result = _ec2.describeInstances(describeInstancesRequest);
if (!result.getReservations().isEmpty()) {
if (!result.getReservations().get(0).getInstances().isEmpty()) {
Instance i = result.getReservations().get(0).getInstances().get(0);
return i;
}
}
} catch (Exception e) {
_log.error("Call to AWS threw exception", e);
}
return null;
}
Aggregations