/**
  * An optional list of the instances to describe.
  *
  * <p>Returns a reference to this object so that method calls can be chained together.
  *
  * @param instanceIds An optional list of the instances to describe.
  * @return A reference to this updated object so that method calls can be chained together.
  */
 public DescribeInstancesRequest withInstanceIds(String... instanceIds) {
   if (getInstanceIds() == null)
     setInstanceIds(new java.util.ArrayList<String>(instanceIds.length));
   for (String value : instanceIds) {
     getInstanceIds().add(value);
   }
   return this;
 }
Esempio n. 2
0
  /**
   * Provisions a new EC2 slave based on the currently running instance on EC2, instead of starting
   * a new one.
   */
  public EC2AbstractSlave attach(String instanceId, TaskListener listener)
      throws AmazonClientException, IOException {
    PrintStream logger = listener.getLogger();
    AmazonEC2 ec2 = getParent().connect();

    try {
      logger.println("Attaching to " + instanceId);
      LOGGER.info("Attaching to " + instanceId);
      DescribeInstancesRequest request = new DescribeInstancesRequest();
      request.setInstanceIds(Collections.singletonList(instanceId));
      Instance inst = ec2.describeInstances(request).getReservations().get(0).getInstances().get(0);
      return newOndemandSlave(inst);
    } catch (FormException e) {
      throw new AssertionError(); // we should have discovered all
      // configuration issues upfront
    }
  }
  public static Instance getInstance(String instanceId, EC2Cloud cloud) {
    if (instanceId == null || instanceId == "" || cloud == null) return null;

    Instance i = null;
    try {
      DescribeInstancesRequest request = new DescribeInstancesRequest();
      request.setInstanceIds(Collections.<String>singletonList(instanceId));
      AmazonEC2 ec2 = cloud.connect();
      List<Reservation> reservations = ec2.describeInstances(request).getReservations();
      if (!reservations.isEmpty()) {
        List<Instance> instances = reservations.get(0).getInstances();
        if (!instances.isEmpty()) {
          i = instances.get(0);
        }
      }
    } catch (AmazonClientException e) {
      LOGGER.log(Level.WARNING, "Failed to fetch EC2 instance: " + instanceId, e);
    }
    return i;
  }
Esempio n. 4
0
  @Override
  // @HystrixCommand(fallback = my coole exception)
  // command for account id and client type -> generate new credentials
  public void processEvent(final CloudTrailEvent event) {

    String parameters = event.getEventData().getRequestParameters();
    String instanceId = getFromParameters(parameters);

    AmazonEC2Client client =
        getClientForAccount(
            event.getEventData().getUserIdentity().getAccountId(),
            Region.getRegion(Regions.fromName(event.getEventData().getAwsRegion())));

    DescribeInstancesRequest request = new DescribeInstancesRequest();
    request.setInstanceIds(Collections.singleton(instanceId));

    // try
    DescribeInstancesResult result = client.describeInstances(request);
    // catch credentials are old
    // throw new my coole exception ( account id, CLIENTTYPE.EC2, exception) -> this will trigger
    // hystrix

    LOG.info("SAVING RESULT INTO MAGIC DB", result);
  }