Search in sources :

Example 11 with AmazonEC2Client

use of com.amazonaws.services.ec2.AmazonEC2Client in project GNS by MobilityFirst.

the class AWSStatusCheck method init.

private static void init() throws Exception {
    AWSCredentials credentials = new PropertiesCredentials(new File(CREDENTIALSFILE));
    ec2 = new AmazonEC2Client(credentials);
    s3 = new AmazonS3Client(credentials);
    sdb = new AmazonSimpleDBClient(credentials);
}
Also used : AmazonEC2Client(com.amazonaws.services.ec2.AmazonEC2Client) AmazonS3Client(com.amazonaws.services.s3.AmazonS3Client) AmazonSimpleDBClient(com.amazonaws.services.simpledb.AmazonSimpleDBClient) PropertiesCredentials(com.amazonaws.auth.PropertiesCredentials) AWSCredentials(com.amazonaws.auth.AWSCredentials) File(java.io.File)

Example 12 with AmazonEC2Client

use of com.amazonaws.services.ec2.AmazonEC2Client in project GNS by MobilityFirst.

the class AWSEC2 method main.

/**
   *
   * @param args
   * @throws Exception
   */
public static void main(String[] args) throws Exception {
    AWSCredentials credentials = new PropertiesCredentials(AWSEC2.class.getResourceAsStream(System.getProperty("user.home") + FILESEPARATOR + ".aws" + FILESEPARATOR + "credentials"));
    //Create Amazon Client object
    AmazonEC2 ec2 = new AmazonEC2Client(credentials);
    RegionRecord region = RegionRecord.US_EAST_1;
    String keyName = "aws";
    String installScript = "#!/bin/bash\n" + "cd /home/ec2-user\n" + "yum --quiet --assumeyes update\n";
    HashMap<String, String> tags = new HashMap<>();
    tags.put("runset", new Date().toString());
    createAndInitInstance(ec2, region, AMIRecord.getAMI(AMIRecordType.Amazon_Linux_AMI_2013_03_1, region), "Test Instance", keyName, DEFAULT_SECURITY_GROUP_NAME, installScript, tags, "23.21.120.250");
}
Also used : AmazonEC2Client(com.amazonaws.services.ec2.AmazonEC2Client) HashMap(java.util.HashMap) PropertiesCredentials(com.amazonaws.auth.PropertiesCredentials) AmazonEC2(com.amazonaws.services.ec2.AmazonEC2) AWSCredentials(com.amazonaws.auth.AWSCredentials) Date(java.util.Date)

Example 13 with AmazonEC2Client

use of com.amazonaws.services.ec2.AmazonEC2Client 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 14 with AmazonEC2Client

use of com.amazonaws.services.ec2.AmazonEC2Client 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)

Example 15 with AmazonEC2Client

use of com.amazonaws.services.ec2.AmazonEC2Client in project druid by druid-io.

the class EC2AutoScalerTest method setUp.

@Before
public void setUp() throws Exception {
    amazonEC2Client = EasyMock.createMock(AmazonEC2Client.class);
    describeInstancesResult = EasyMock.createMock(DescribeInstancesResult.class);
    reservation = EasyMock.createMock(Reservation.class);
    instance = new Instance().withInstanceId(INSTANCE_ID).withLaunchTime(new Date()).withImageId(AMI_ID).withPrivateIpAddress(IP);
    managementConfig = new SimpleWorkerResourceManagementConfig().setWorkerPort(8080).setWorkerVersion("");
}
Also used : AmazonEC2Client(com.amazonaws.services.ec2.AmazonEC2Client) DescribeInstancesResult(com.amazonaws.services.ec2.model.DescribeInstancesResult) Reservation(com.amazonaws.services.ec2.model.Reservation) Instance(com.amazonaws.services.ec2.model.Instance) Date(java.util.Date) Before(org.junit.Before)

Aggregations

AmazonEC2Client (com.amazonaws.services.ec2.AmazonEC2Client)15 AmazonServiceException (com.amazonaws.AmazonServiceException)12 Collection (java.util.Collection)11 Message (org.apache.camel.Message)10 AmazonEC2 (com.amazonaws.services.ec2.AmazonEC2)8 AWSCredentials (com.amazonaws.auth.AWSCredentials)7 PropertiesCredentials (com.amazonaws.auth.PropertiesCredentials)6 DescribeInstancesRequest (com.amazonaws.services.ec2.model.DescribeInstancesRequest)4 Instance (com.amazonaws.services.ec2.model.Instance)4 File (java.io.File)4 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)3 Reservation (com.amazonaws.services.ec2.model.Reservation)3 EC2AutoScaler (io.druid.indexing.overlord.autoscaling.ec2.EC2AutoScaler)3 IOException (java.io.IOException)3 Date (java.util.Date)3 Test (org.junit.Test)3 InstanceProfileCredentialsProvider (com.amazonaws.auth.InstanceProfileCredentialsProvider)2 DescribeInstancesResult (com.amazonaws.services.ec2.model.DescribeInstancesResult)2 Filter (com.amazonaws.services.ec2.model.Filter)2 RunInstancesRequest (com.amazonaws.services.ec2.model.RunInstancesRequest)2