Search in sources :

Example 11 with PropertiesCredentials

use of com.amazonaws.auth.PropertiesCredentials in project GNS by MobilityFirst.

the class EC2Runner method initAndUpdateEC2Host.

/**
   * This is called to initialize an EC2 host for use as A GNS server in a region. It starts the host, loads all the necessary
   * software and copies the JAR files over. We also collect info about this host, like it's IP address and geographic location.
   * When every host is initialized and we have collected all the IPs, phase two is called.
   *
   * @param region - the EC2 region where we are starting this host
   * @param runSetName - so we can terminate them all together
   * @param id - the GNS ID of this server
   * @param elasticIP
   * @param timeout
   */
public static void initAndUpdateEC2Host(RegionRecord region, String runSetName, String id, String elasticIP, int timeout) {
    String installScript;
    AMIRecord amiRecord = AMIRecord.getAMI(amiRecordType, region);
    if (amiRecord == null) {
        System.out.println("Invalid combination of " + amiRecordType + " and Region " + region.name());
        return;
    }
    switch(dataStoreType) {
        case CASSANDRA:
            installScript = cassandraInstallScript;
            break;
        default:
            // MONGO
            if (amiRecordType.toString().contains("Amazon_Linux")) {
                installScript = mongoInstallScript;
            } else {
                switch(amiRecordType) {
                    case MongoDB_2_4_8_with_1000_IOPS:
                        installScript = mongoShortInstallScript;
                        break;
                    case Mongo_2014_5_6:
                        installScript = null;
                        break;
                    case Mongo_2014_5_6_micro:
                        installScript = null;
                        break;
                    case Mongo_2015_6_25_vpc:
                        installScript = null;
                        break;
                    case Mongo_2016_6_16_micro:
                        installScript = null;
                        break;
                    default:
                        System.out.println("Invalid combination of " + amiRecordType + " and " + dataStoreType);
                        return;
                }
            }
    }
    String idString = id.toString();
    //    StatusModel.getInstance().queueUpdate(id, region.name() + ": [Unknown hostname]", null, null);
    try {
        AWSCredentials credentials = new PropertiesCredentials(new File(CREDENTIALSFILE));
        //Create Amazon Client object
        AmazonEC2 ec2 = new AmazonEC2Client(credentials);
        String nodeName = "GNS Node " + idString;
        System.out.println("Starting install for " + nodeName + " in " + region.name() + " as part of run set " + runSetName);
        HashMap<String, String> tags = new HashMap<>();
        tags.put("runset", runSetName);
        tags.put("id", idString);
        //      StatusModel.getInstance().queueUpdate(id, "Creating instance");
        // create an instance
        Instance instance = AWSEC2.createAndInitInstance(ec2, region, amiRecord, nodeName, keyName, amiRecord.getSecurityGroup(), installScript, tags, elasticIP, timeout);
        if (instance != null) {
            //        StatusModel.getInstance().queueUpdate(id, "Instance created");
            //        StatusModel.getInstance().queueUpdate(id, StatusEntry.State.INITIALIZING);
            // toString our ip
            String hostname = instance.getPublicDnsName();
            InetAddress inetAddress = InetAddress.getByName(hostname);
            String ip = inetAddress.getHostAddress();
            // and take a guess at the location (lat, long) of this host
            Point2D location = GEOLocator.lookupIPLocation(ip);
            //        StatusModel.getInstance().queueUpdate(id, hostname, ip, location);
            // update our table of instance information
            hostTable.put(id, new HostInfo(id, hostname, location));
        // and we're done
        //        StatusModel.getInstance().queueUpdate(id, "Waiting for other servers");
        } else {
            System.out.println("EC2 Instance " + idString + " in " + region.name() + " did not in start.");
            //        StatusModel.getInstance().queueUpdate(id, StatusEntry.State.ERROR, "Did not start");
            hostsThatDidNotStart.put(id, id);
        }
    } catch (IOException e) {
        System.out.println("Problem creating EC2 instance " + idString + " in " + region.name() + ": " + e);
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        System.out.println("Problem creating EC2 instance " + idString + " in " + region.name() + ": " + e);
        e.printStackTrace();
    }
}
Also used : AmazonEC2Client(com.amazonaws.services.ec2.AmazonEC2Client) AMIRecord(edu.umass.cs.aws.support.AMIRecord) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Instance(com.amazonaws.services.ec2.model.Instance) AmazonEC2(com.amazonaws.services.ec2.AmazonEC2) IOException(java.io.IOException) AWSCredentials(com.amazonaws.auth.AWSCredentials) Point2D(java.awt.geom.Point2D) PropertiesCredentials(com.amazonaws.auth.PropertiesCredentials) File(java.io.File) InetAddress(java.net.InetAddress)

Example 12 with PropertiesCredentials

use of com.amazonaws.auth.PropertiesCredentials in project GNS by MobilityFirst.

the class Amazontool method main.

/**
   * @param args the command line arguments
   * @throws java.io.IOException
   */
public static void main(String[] args) throws IOException {
    AWSCredentials credentials = new PropertiesCredentials(AWSEC2.class.getResourceAsStream("resources/AwsCredentials.properties"));
    //Create Amazon Client object
    AmazonEC2 ec2 = new AmazonEC2Client(credentials);
    AWSEC2.describeAllEndpoints(ec2);
//    Instance instance = AWSEC2.findInstance(ec2, "i-86983af6");
//    Address elasticIP = AWSEC2.findElasticIP(ec2, "23.21.120.250");
//    System.out.println(instance.getPublicDnsName());
//    System.out.println(elasticIP.getPublicIp());
//AWSEC2.associateAddress(ec2, "23.21.120.250", instance);
}
Also used : AmazonEC2Client(com.amazonaws.services.ec2.AmazonEC2Client) PropertiesCredentials(com.amazonaws.auth.PropertiesCredentials) AmazonEC2(com.amazonaws.services.ec2.AmazonEC2) AWSCredentials(com.amazonaws.auth.AWSCredentials)

Example 13 with PropertiesCredentials

use of com.amazonaws.auth.PropertiesCredentials in project gora by apache.

the class DynamoDBStore method setDynamoDBProperties.

private void setDynamoDBProperties(Properties properties) throws IOException {
    setSerializationType(properties.getProperty(SERIALIZATION_TYPE));
    PropertiesCredentials creds = DynamoDBUtils.getCredentials(this.getClass());
    setPreferredSchema(properties.getProperty(PREF_SCH_NAME));
    setDynamoDBClient(DynamoDBUtils.getClient(properties.getProperty(CLI_TYP_PROP), creds));
    getDynamoDBClient().setEndpoint(properties.getProperty(ENDPOINT_PROP));
    setDynamoDbMapping(readMapping());
    setConsistency(properties.getProperty(CONSISTENCY_READS));
}
Also used : PropertiesCredentials(com.amazonaws.auth.PropertiesCredentials)

Example 14 with PropertiesCredentials

use of com.amazonaws.auth.PropertiesCredentials in project gora by apache.

the class DynamoDBUtils method getCredentials.

/**
   * Creates the AWSCredentials object based on the properties file.
   *
   * @param clazz
   * @return
   */
public static PropertiesCredentials getCredentials(Class<?> clazz) {
    PropertiesCredentials awsCredentials = null;
    try {
        InputStream awsCredInpStr = clazz.getClassLoader().getResourceAsStream(AWS_CREDENTIALS_PROPERTIES);
        if (awsCredInpStr == null)
            LOG.error("AWS Credentials File was not found on the classpath!");
        awsCredentials = new PropertiesCredentials(awsCredInpStr);
    } catch (IOException e) {
        LOG.error("Error loading AWS Credentials File from the classpath!", e.getMessage());
        throw new RuntimeException(e);
    }
    return awsCredentials;
}
Also used : InputStream(java.io.InputStream) PropertiesCredentials(com.amazonaws.auth.PropertiesCredentials) IOException(java.io.IOException)

Aggregations

PropertiesCredentials (com.amazonaws.auth.PropertiesCredentials)14 AWSCredentials (com.amazonaws.auth.AWSCredentials)12 AmazonEC2Client (com.amazonaws.services.ec2.AmazonEC2Client)6 File (java.io.File)6 AmazonEC2 (com.amazonaws.services.ec2.AmazonEC2)5 IOException (java.io.IOException)5 ClientConfiguration (com.amazonaws.ClientConfiguration)3 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)3 AmazonDynamoDBClient (com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient)3 Instance (com.amazonaws.services.ec2.model.Instance)3 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)2 AmazonSimpleDBClient (com.amazonaws.services.simpledb.AmazonSimpleDBClient)2 RegionRecord (edu.umass.cs.aws.support.RegionRecord)2 Point2D (java.awt.geom.Point2D)2 InputStream (java.io.InputStream)2 HashMap (java.util.HashMap)2 RefreshScope (org.springframework.cloud.context.config.annotation.RefreshScope)2 Bean (org.springframework.context.annotation.Bean)2 AmazonClientException (com.amazonaws.AmazonClientException)1 AmazonServiceException (com.amazonaws.AmazonServiceException)1