Search in sources :

Example 1 with RegionRecord

use of edu.umass.cs.aws.support.RegionRecord in project GNS by MobilityFirst.

the class EC2Runner method terminateRunSet.

/**
   * Terminates all the hosts in the named run set.
   *
   * @param name
   */
public static void terminateRunSet(String name) {
    try {
        AWSCredentials credentials = new PropertiesCredentials(new File(CREDENTIALSFILE));
        //Create Amazon Client object
        AmazonEC2 ec2 = new AmazonEC2Client(credentials);
        for (RegionRecord region : RegionRecord.values()) {
            AWSEC2.setRegion(ec2, region);
            for (Instance instance : AWSEC2.getInstances(ec2)) {
                if (!instance.getState().getName().equals(InstanceStateRecord.TERMINATED.getName())) {
                    String idString = getTagValue(instance, "id");
                    if (name.equals(getTagValue(instance, "runset"))) {
                        if (idString != null) {
                        //                StatusModel.getInstance().queueUpdate(new String(idString), "Terminating");
                        }
                        AWSEC2.terminateInstance(ec2, instance.getInstanceId());
                        if (idString != null) {
                        //                StatusModel.getInstance().queueUpdate(new String(idString), StatusEntry.State.TERMINATED, "");
                        }
                    }
                }
            }
        }
    } catch (IOException e) {
        System.out.println("Problem terminating EC2 instances: " + e);
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        System.out.println("Problem terminating EC2 instances: " + e);
        e.printStackTrace();
    }
}
Also used : AmazonEC2Client(com.amazonaws.services.ec2.AmazonEC2Client) Instance(com.amazonaws.services.ec2.model.Instance) PropertiesCredentials(com.amazonaws.auth.PropertiesCredentials) AmazonEC2(com.amazonaws.services.ec2.AmazonEC2) IOException(java.io.IOException) AWSCredentials(com.amazonaws.auth.AWSCredentials) File(java.io.File) RegionRecord(edu.umass.cs.aws.support.RegionRecord)

Example 2 with RegionRecord

use of edu.umass.cs.aws.support.RegionRecord in project GNS by MobilityFirst.

the class EC2Runner method populateIDTableForRunset.

private static void populateIDTableForRunset(String name) {
    AWSCredentials credentials = null;
    try {
        //
        credentials = new PropertiesCredentials(new File(CREDENTIALSFILE));
    } catch (IOException e) {
        System.out.println("Problem contacting EC2 instances: " + e);
    }
    //Create Amazon Client object
    AmazonEC2 ec2 = new AmazonEC2Client(credentials);
    for (RegionRecord region : RegionRecord.values()) {
        AWSEC2.setRegion(ec2, region);
        System.out.println("Retrieving instance information in " + region.name() + "...");
        for (Instance instance : AWSEC2.getInstances(ec2)) {
            if (!instance.getState().getName().equals(InstanceStateRecord.TERMINATED.getName())) {
                String idString = getTagValue(instance, "id");
                if (idString != null && name.equals(getTagValue(instance, "runset"))) {
                    String id = new String(idString);
                    String hostname = instance.getPublicDnsName();
                    String ip = getHostIPSafe(hostname);
                    // and take a guess at the location (lat, long) of this host
                    Point2D location = GEOLocator.lookupIPLocation(ip);
                    hostTable.put(id, new HostInfo(id, hostname, location));
                }
            }
        }
    }
}
Also used : AmazonEC2Client(com.amazonaws.services.ec2.AmazonEC2Client) Instance(com.amazonaws.services.ec2.model.Instance) Point2D(java.awt.geom.Point2D) PropertiesCredentials(com.amazonaws.auth.PropertiesCredentials) IOException(java.io.IOException) AmazonEC2(com.amazonaws.services.ec2.AmazonEC2) AWSCredentials(com.amazonaws.auth.AWSCredentials) File(java.io.File) RegionRecord(edu.umass.cs.aws.support.RegionRecord)

Aggregations

AWSCredentials (com.amazonaws.auth.AWSCredentials)2 PropertiesCredentials (com.amazonaws.auth.PropertiesCredentials)2 AmazonEC2 (com.amazonaws.services.ec2.AmazonEC2)2 AmazonEC2Client (com.amazonaws.services.ec2.AmazonEC2Client)2 Instance (com.amazonaws.services.ec2.model.Instance)2 RegionRecord (edu.umass.cs.aws.support.RegionRecord)2 File (java.io.File)2 IOException (java.io.IOException)2 Point2D (java.awt.geom.Point2D)1