@Override public Iterable<Instance> apply(Reservation reservation) { return reservation.getInstances(); } })
@Override public Iterable<Instance> apply(Reservation reservation) { return reservation.getInstances(); } })
private Instance instanceData(String myInstanceId, AmazonEC2 ec2) { return ec2.describeInstances(new DescribeInstancesRequest().withInstanceIds(myInstanceId)).getReservations().get(0).getInstances().get(0); }
@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getGroups() == null) ? 0 : getGroups().hashCode()); hashCode = prime * hashCode + ((getInstances() == null) ? 0 : getInstances().hashCode()); hashCode = prime * hashCode + ((getOwnerId() == null) ? 0 : getOwnerId().hashCode()); hashCode = prime * hashCode + ((getRequesterId() == null) ? 0 : getRequesterId().hashCode()); hashCode = prime * hashCode + ((getReservationId() == null) ? 0 : getReservationId().hashCode()); hashCode = prime * hashCode + ((getGroupNames() == null) ? 0 : getGroupNames().hashCode()); return hashCode; }
/** * Returns a string representation of this object. This is useful for testing and debugging. Sensitive data will be * redacted from this string using a placeholder value. * * @return A string representation of this object. * * @see java.lang.Object#toString() */ @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("{"); if (getGroups() != null) sb.append("Groups: ").append(getGroups()).append(","); if (getInstances() != null) sb.append("Instances: ").append(getInstances()).append(","); if (getOwnerId() != null) sb.append("OwnerId: ").append(getOwnerId()).append(","); if (getRequesterId() != null) sb.append("RequesterId: ").append(getRequesterId()).append(","); if (getReservationId() != null) sb.append("ReservationId: ").append(getReservationId()).append(","); if (getGroupNames() != null) sb.append("GroupNames: ").append(getGroupNames()); sb.append("}"); return sb.toString(); }
/** * Queries instances with given Ids on AWS * * @param instanceIds List of instance IDs * @return */ protected Collection<com.amazonaws.services.ec2.model.Instance> getEC2Instances( Collection<String> instanceIds ) { if( instanceIds == null || instanceIds.size() == 0 ) { return new ArrayList<com.amazonaws.services.ec2.model.Instance>(); } Collection<com.amazonaws.services.ec2.model.Instance> instances = new LinkedList<com.amazonaws.services.ec2.model.Instance>(); DescribeInstancesRequest request = new DescribeInstancesRequest(); request = request.withInstanceIds( instanceIds ); DescribeInstancesResult result = null; try { result = client.describeInstances( request ); } catch ( Exception e ) { LOG.error( "Error while getting instance information from AWS.", e ); return Collections.EMPTY_LIST; } for ( Reservation reservation : result.getReservations() ) { for ( com.amazonaws.services.ec2.model.Instance in : reservation.getInstances() ) { instances.add( in ); } } return instances; }
instances.addAll(reservation.getInstances());
for ( com.amazonaws.services.ec2.model.Instance in : reservation.getInstances() ) { instances.add( in );
/** {@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; }
if (other.getGroups() != null && other.getGroups().equals(this.getGroups()) == false) return false; if (other.getInstances() == null ^ this.getInstances() == null) return false; if (other.getInstances() != null && other.getInstances().equals(this.getInstances()) == false) return false; if (other.getOwnerId() == null ^ this.getOwnerId() == null)
public String retriableCall() throws IllegalStateException { DescribeInstancesRequest desc = new DescribeInstancesRequest().withInstanceIds(getInstanceId()); DescribeInstancesResult res = client.describeInstances(desc); for (Reservation resr : res.getReservations()) { for (Instance ins : resr.getInstances()) { for (com.amazonaws.services.ec2.model.Tag tag : ins.getTags()) { if (tag.getKey().equals("aws:autoscaling:groupName")) return tag.getValue(); } } } throw new IllegalStateException("Couldn't determine ASG name"); } }.call();
/*** * Get list of EC2 {@link Instance}s for a auto scaling group * * @param groupName Auto scaling group name * @param status Instance status (eg. running) * @return List of EC2 instances found for the input auto scaling group */ public List<Instance> getInstancesForGroup(String groupName, String status) { final AmazonEC2 amazonEC2 = getEc2Client(); final DescribeInstancesResult instancesResult = amazonEC2.describeInstances(new DescribeInstancesRequest() .withFilters(new Filter().withName("tag:aws:autoscaling:groupName").withValues(groupName))); final List<Instance> instances = new ArrayList<>(); for (Reservation reservation : instancesResult.getReservations()) { for (Instance instance : reservation.getInstances()) { if (null == status|| null == instance.getState() || status.equals(instance.getState().getName())) { instances.add(instance); LOGGER.info("Found instance: " + instance + " which qualified filter: " + status); } else { LOGGER.info("Found instance: " + instance + " but did not qualify for filter: " + status); } } } return instances; }
List<Instance> instances = new ArrayList<Instance>(); for( Reservation reservation : reservations ) for( Instance instance : reservation.getInstances() ) if( ip(instance) != null ) instances.add(instance);
for( Instance instance : reservation.getInstances() ) { String ip = ip(instance); if( ip != null ) { for( Instance instance : runRes.getReservation().getInstances() ) ids.add(instance.getInstanceId());
EasyMock.replay(describeInstancesResult); EasyMock.expect(reservation.getInstances()).andReturn(Collections.singletonList(instance)).atLeastOnce(); EasyMock.replay(reservation);
EasyMock.replay(describeInstancesResult); EasyMock.expect(reservation.getInstances()).andReturn(Collections.singletonList(instance)).times(n); EasyMock.replay(reservation);
EasyMock.replay(describeInstancesResult); EasyMock.expect(reservation.getInstances()).andReturn(Collections.singletonList(instance)).times(n); EasyMock.replay(reservation);
String reservation_id = run_response.getReservation().getInstances().get(0).getInstanceId();
for(Instance instance : reservation.getInstances()) { System.out.printf( "Found instance with id %s, " +
result.getReservation().getInstances(), new Function<Instance, String>() result.getReservation().getInstances(), new Function<Instance, String>()