private void printStateChanges(TerminateInstancesResult tir) {
   List<InstanceStateChange> states = tir.getTerminatingInstances();
   out.println("Terminated " + states.size() + " instances:");
   for (InstanceStateChange state : states) {
     out.println(
         state.getInstanceId()
             + ": "
             + state.getPreviousState()
             + " -> "
             + state.getCurrentState());
   }
 }
Exemple #2
0
  // Terminates an instances and returns a list of terminated instance ids.
  public static List<String> terminateInstances(AmazonEC2 ec2, Collection<String> ids) {
    for (String id : ids) {
      logger.info("Terminating instance id: " + id);
    }

    TerminateInstancesRequest request = new TerminateInstancesRequest();
    request.setInstanceIds(ids);

    ArrayList<String> terminated = new ArrayList<String>();
    for (InstanceStateChange state : ec2.terminateInstances(request).getTerminatingInstances()) {
      terminated.add(state.getInstanceId());
    }

    return terminated;
  }
  @Override
  public boolean equals(Object obj) {
    if (this == obj) return true;
    if (obj == null) return false;

    if (obj instanceof InstanceStateChange == false) return false;
    InstanceStateChange other = (InstanceStateChange) obj;
    if (other.getInstanceId() == null ^ this.getInstanceId() == null) return false;
    if (other.getInstanceId() != null
        && other.getInstanceId().equals(this.getInstanceId()) == false) return false;
    if (other.getCurrentState() == null ^ this.getCurrentState() == null) return false;
    if (other.getCurrentState() != null
        && other.getCurrentState().equals(this.getCurrentState()) == false) return false;
    if (other.getPreviousState() == null ^ this.getPreviousState() == null) return false;
    if (other.getPreviousState() != null
        && other.getPreviousState().equals(this.getPreviousState()) == false) return false;
    return true;
  }