use of software.amazon.awssdk.services.ec2.model.Reservation 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 software.amazon.awssdk.services.ec2.model.Reservation in project camel by apache.
the class AmazonEC2ClientMock method runInstances.
@Override
public RunInstancesResult runInstances(RunInstancesRequest runInstancesRequest) {
RunInstancesResult result = new RunInstancesResult();
if (runInstancesRequest.getImageId().equals("test-1")) {
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(runInstancesRequest.getImageId());
ins.setInstanceType(runInstancesRequest.getInstanceType());
ins.setInstanceId("instance-1");
if (runInstancesRequest.getSecurityGroups() != null) {
if (runInstancesRequest.getSecurityGroups().contains("secgroup-1") && runInstancesRequest.getSecurityGroups().contains("secgroup-2")) {
GroupIdentifier id1 = new GroupIdentifier();
id1.setGroupId("id-1");
id1.setGroupName("secgroup-1");
GroupIdentifier id2 = new GroupIdentifier();
id2.setGroupId("id-2");
id2.setGroupName("secgroup-2");
Collection secGroups = new ArrayList<GroupIdentifier>();
secGroups.add(id1);
secGroups.add(id2);
ins.setSecurityGroups(secGroups);
} else if (ObjectHelper.isNotEmpty(runInstancesRequest.getKeyName())) {
if (ObjectHelper.isNotEmpty(runInstancesRequest.getKeyName().contains("keypair-1"))) {
GroupIdentifier id1 = new GroupIdentifier();
id1.setGroupId("id-3");
id1.setGroupName("secgroup-3");
GroupIdentifier id2 = new GroupIdentifier();
id2.setGroupId("id-4");
id2.setGroupName("secgroup-4");
Collection secGroups = new ArrayList<GroupIdentifier>();
secGroups.add(id1);
secGroups.add(id2);
ins.setSecurityGroups(secGroups);
}
}
}
instances.add(ins);
res.setInstances(instances);
result.setReservation(res);
} else {
throw new AmazonServiceException("The image-id doesn't exists");
}
return result;
}
use of software.amazon.awssdk.services.ec2.model.Reservation 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;
}
use of software.amazon.awssdk.services.ec2.model.Reservation in project photon-model by vmware.
the class AWSRemoteCleanup method deleteStaleAwsEc2instances.
/**
* Delete stale AWS EC2 Instances.
*/
@Test
public void deleteStaleAwsEc2instances() {
AmazonEC2 usEastEc2Client = this.ec2Clients.get(US_EAST_1_TAG);
List<String> instanceIdsToBeDeleted = new ArrayList<>();
DescribeInstancesResult instancesResult = usEastEc2Client.describeInstances();
List<Reservation> reservations = instancesResult.getReservations();
for (Reservation reservation : reservations) {
List<Instance> instances = reservation.getInstances();
for (Instance instance : instances) {
long instanceLaunchTimeMicros = TimeUnit.MILLISECONDS.toMicros(instance.getLaunchTime().getTime());
long timeDifference = Utils.getNowMicrosUtc() - instanceLaunchTimeMicros;
if (timeDifference > TimeUnit.HOURS.toMicros(1) && shouldDelete(instance)) {
this.host.log(Level.INFO, "Marking %s instance for deletion", instance.getInstanceId());
instanceIdsToBeDeleted.add(instance.getInstanceId());
}
}
}
triggerEC2Deletion(instanceIdsToBeDeleted, usEastEc2Client);
}
use of software.amazon.awssdk.services.ec2.model.Reservation in project airavata by apache.
the class AmazonUtil method loadInstances.
/**
* Load instances
*
* @return list of instances
*/
public static List<Instance> loadInstances() {
List<Instance> resultList = new ArrayList<Instance>();
DescribeInstancesResult describeInstancesResult = getEC2Client().describeInstances();
List<Reservation> reservations = describeInstancesResult.getReservations();
for (Iterator<Reservation> iterator = reservations.iterator(); iterator.hasNext(); ) {
Reservation reservation = iterator.next();
for (Instance instance : reservation.getInstances()) {
resultList.add(instance);
}
}
return resultList;
}
Aggregations