List of usage examples for com.amazonaws.auth PropertiesCredentials PropertiesCredentials
public PropertiesCredentials(InputStream inputStream) throws IOException
From source file:edu.umass.cs.aws.support.Amazontool.java
License:Apache License
/** * @param args the command line arguments * @throws java.io.IOException/*ww w .jav a2s .c o m*/ */ 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); }
From source file:edu.umass.cs.aws.support.AWSEC2.java
License:Apache License
/** * * @param args/*w ww .ja va 2 s . c o m*/ * @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"); }
From source file:edu.umass.cs.aws.support.examples.AWSStatusCheck.java
License:Apache License
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); }
From source file:edu.umass.cs.aws.support.Route53.java
License:Apache License
/** * * @param args/* w ww .j a va 2 s.co m*/ * @throws Exception */ public static void main(String[] args) throws Exception { AWSCredentials credentials = new PropertiesCredentials( AWSEC2.class.getResourceAsStream("resources/AwsCredentials.properties")); //Create Amazon Client object route53 = new AmazonRoute53Client(credentials); listRecordSetsForHostedZone(); }
From source file:edu.umass.cs.gnsserver.installer.EC2Runner.java
License:Apache License
/** * 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/*from www . j a v a 2 s . c o m*/ * @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().queueAddEntry(id); // for the gui // 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(); } }
From source file:edu.umass.cs.gnsserver.installer.EC2Runner.java
License:Apache License
/** * Terminates all the hosts in the named run set. * * @param name//from w w w . j a va 2s. c o m */ 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(); } }
From source file:edu.umass.cs.gnsserver.installer.EC2Runner.java
License:Apache License
private static void populateIDTableForRunset(String name) { AWSCredentials credentials = null;// w ww . jav a 2s .com 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)); } } } } }
From source file:fr.xebia.cloud.amazon.aws.iam.AmazonAwsIamAccountCreator.java
License:Apache License
public AmazonAwsIamAccountCreator(Environment environment) { this.environment = Preconditions.checkNotNull(environment); try {/*from w w w . j ava2 s .c o m*/ keyPairGenerator = KeyPairGenerator.getInstance("RSA", BOUNCY_CASTLE_PROVIDER_NAME); keyPairGenerator.initialize(1024, new SecureRandom()); String credentialsFileName = "AwsCredentials-" + environment.getIdentifier() + ".properties"; InputStream credentialsAsStream = Thread.currentThread().getContextClassLoader() .getResourceAsStream(credentialsFileName); Preconditions.checkNotNull(credentialsAsStream, "File '/" + credentialsFileName + "' NOT found in the classpath"); AWSCredentials awsCredentials = new PropertiesCredentials(credentialsAsStream); iam = new AmazonIdentityManagementClient(awsCredentials); ses = new AmazonSimpleEmailServiceClient(awsCredentials); ec2 = new AmazonEC2Client(awsCredentials); ec2.setEndpoint("ec2.eu-west-1.amazonaws.com"); InputStream smtpPropertiesAsStream = Thread.currentThread().getContextClassLoader() .getResourceAsStream("smtp.properties"); Preconditions.checkNotNull(smtpPropertiesAsStream, "File '/smtp.properties' NOT found in the classpath"); final Properties smtpProperties = new Properties(); smtpProperties.load(smtpPropertiesAsStream); mailSession = Session.getInstance(smtpProperties, null); mailTransport = mailSession.getTransport(); if (smtpProperties.containsKey("mail.username")) { mailTransport.connect(smtpProperties.getProperty("mail.username"), smtpProperties.getProperty("mail.password")); } else { mailTransport.connect(); } try { mailFrom = new InternetAddress(smtpProperties.getProperty("mail.from")); } catch (Exception e) { throw new MessagingException("Exception parsing 'mail.from' from 'smtp.properties'", e); } } catch (Exception e) { throw Throwables.propagate(e); } }
From source file:fr.xebia.cloud.amazon.aws.tools.AmazonAwsToolsSender.java
License:Apache License
public AmazonAwsToolsSender() { try {/*from ww w . j av a2 s. c o m*/ InputStream credentialsAsStream = Thread.currentThread().getContextClassLoader() .getResourceAsStream("AwsCredentials.properties"); Preconditions.checkNotNull(credentialsAsStream, "File '/AwsCredentials.properties' NOT found in the classpath"); AWSCredentials awsCredentials = new PropertiesCredentials(credentialsAsStream); iam = new AmazonIdentityManagementClient(awsCredentials); ses = new AmazonSimpleEmailServiceClient(awsCredentials); ec2 = new AmazonEC2Client(awsCredentials); ec2.setEndpoint("ec2.eu-west-1.amazonaws.com"); InputStream smtpPropertiesAsStream = Thread.currentThread().getContextClassLoader() .getResourceAsStream("smtp.properties"); Preconditions.checkNotNull(smtpPropertiesAsStream, "File '/smtp.properties' NOT found in the classpath"); final Properties smtpProperties = new Properties(); smtpProperties.load(smtpPropertiesAsStream); mailSession = Session.getInstance(smtpProperties, null); mailTransport = mailSession.getTransport(); if (smtpProperties.containsKey("mail.username")) { mailTransport.connect(smtpProperties.getProperty("mail.username"), smtpProperties.getProperty("mail.password")); } else { mailTransport.connect(); } try { mailFrom = new InternetAddress(smtpProperties.getProperty("mail.from")); } catch (Exception e) { throw new MessagingException("Exception parsing 'mail.from' from 'smtp.properties'", e); } } catch (Exception e) { throw Throwables.propagate(e); } }
From source file:fr.xebia.cloud.amazon.aws.tools.AmazonAwsUtils.java
License:Apache License
/** * Load {@link AWSCredentials} from '<code>AwsCredentials.properties</code> * './*ww w . ja va2 s .com*/ */ @Nonnull public static AWSCredentials loadAwsCredentials() { String credentialsFilePath = "AwsCredentials.properties"; InputStream credentialsAsStream = Thread.currentThread().getContextClassLoader() .getResourceAsStream(credentialsFilePath); Preconditions.checkState(credentialsAsStream != null, "File '" + credentialsFilePath + "' NOT found in the classpath"); try { return new PropertiesCredentials(credentialsAsStream); } catch (IOException e) { throw new IllegalStateException("Exception loading '" + credentialsFilePath + "'", e); } }