use of com.amazonaws.auth.PropertiesCredentials 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();
}
}
use of com.amazonaws.auth.PropertiesCredentials 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));
}
}
}
}
}
use of com.amazonaws.auth.PropertiesCredentials in project cas by apereo.
the class DynamoDbServiceRegistryConfiguration method amazonDynamoDbClient.
@RefreshScope
@Bean
public AmazonDynamoDBClient amazonDynamoDbClient() {
try {
final DynamoDbServiceRegistryProperties dynamoDbProperties = casProperties.getServiceRegistry().getDynamoDb();
final ClientConfiguration cfg = new ClientConfiguration();
cfg.setConnectionTimeout(dynamoDbProperties.getConnectionTimeout());
cfg.setMaxConnections(dynamoDbProperties.getMaxConnections());
cfg.setRequestTimeout(dynamoDbProperties.getRequestTimeout());
cfg.setSocketTimeout(dynamoDbProperties.getSocketTimeout());
cfg.setUseGzip(dynamoDbProperties.isUseGzip());
cfg.setUseReaper(dynamoDbProperties.isUseReaper());
cfg.setUseThrottleRetries(dynamoDbProperties.isUseThrottleRetries());
cfg.setUseTcpKeepAlive(dynamoDbProperties.isUseTcpKeepAlive());
cfg.setProtocol(Protocol.valueOf(dynamoDbProperties.getProtocol().toUpperCase()));
cfg.setClientExecutionTimeout(dynamoDbProperties.getClientExecutionTimeout());
cfg.setCacheResponseMetadata(dynamoDbProperties.isCacheResponseMetadata());
if (StringUtils.isNotBlank(dynamoDbProperties.getLocalAddress())) {
cfg.setLocalAddress(InetAddress.getByName(dynamoDbProperties.getLocalAddress()));
}
AWSCredentials credentials = null;
if (dynamoDbProperties.getCredentialsPropertiesFile() != null) {
credentials = new PropertiesCredentials(dynamoDbProperties.getCredentialsPropertiesFile().getInputStream());
} else if (StringUtils.isNotBlank(dynamoDbProperties.getCredentialAccessKey()) && StringUtils.isNotBlank(dynamoDbProperties.getCredentialSecretKey())) {
credentials = new BasicAWSCredentials(dynamoDbProperties.getCredentialAccessKey(), dynamoDbProperties.getCredentialSecretKey());
}
final AmazonDynamoDBClient client;
if (credentials == null) {
client = new AmazonDynamoDBClient(cfg);
} else {
client = new AmazonDynamoDBClient(credentials, cfg);
}
if (StringUtils.isNotBlank(dynamoDbProperties.getEndpoint())) {
client.setEndpoint(dynamoDbProperties.getEndpoint());
}
if (StringUtils.isNotBlank(dynamoDbProperties.getRegion())) {
client.setRegion(Region.getRegion(Regions.valueOf(dynamoDbProperties.getRegion())));
}
if (StringUtils.isNotBlank(dynamoDbProperties.getRegionOverride())) {
client.setSignerRegionOverride(dynamoDbProperties.getRegionOverride());
}
if (StringUtils.isNotBlank(dynamoDbProperties.getServiceNameIntern())) {
client.setServiceNameIntern(dynamoDbProperties.getServiceNameIntern());
}
if (dynamoDbProperties.getTimeOffset() != 0) {
client.setTimeOffset(dynamoDbProperties.getTimeOffset());
}
return client;
} catch (final Exception e) {
throw Throwables.propagate(e);
}
}
use of com.amazonaws.auth.PropertiesCredentials in project simplejpa by appoxy.
the class EntityManagerFactoryImpl method createClients.
private void createClients() {
AWSCredentials awsCredentials = null;
InputStream credentialsFile = getClass().getClassLoader().getResourceAsStream("AwsCredentials.properties");
if (credentialsFile != null) {
logger.info("Loading credentials from AwsCredentials.properties");
try {
awsCredentials = new PropertiesCredentials(credentialsFile);
} catch (IOException e) {
throw new PersistenceException("Failed loading credentials from AwsCredentials.properties.", e);
}
} else {
logger.info("Loading credentials from simplejpa.properties");
String awsAccessKey = (String) this.props.get(AWSACCESS_KEY_PROP_NAME);
String awsSecretKey = (String) this.props.get(AWSSECRET_KEY_PROP_NAME);
if (awsAccessKey == null || awsAccessKey.length() == 0) {
throw new PersistenceException("AWS Access Key not found. It is a required property.");
}
if (awsSecretKey == null || awsSecretKey.length() == 0) {
throw new PersistenceException("AWS Secret Key not found. It is a required property.");
}
awsCredentials = new BasicAWSCredentials(awsAccessKey, awsSecretKey);
}
this.simpleDbClient = new AmazonSimpleDBClient(awsCredentials, createConfiguration(sdbSecure));
this.simpleDbClient.setEndpoint(sdbEndpoint);
this.s3Client = new AmazonS3Client(awsCredentials, createConfiguration(s3Secure));
this.s3Client.setEndpoint(s3Endpoint);
}
use of com.amazonaws.auth.PropertiesCredentials in project glacier-cli by carlossg.
the class Glacier method main.
public static void main(String[] args) throws Exception {
options = commonOptions();
try {
CommandLineParser parser = new PosixParser();
CommandLine cmd = parser.parse(options, args);
List<String> arguments = Arrays.asList(cmd.getArgs());
if (cmd.hasOption("help")) {
usage();
// Not reached
}
if (arguments.isEmpty()) {
throw new GlacierCliException("Must provide at least one command.");
}
GlacierCliCommand command = GlacierCliCommand.get(arguments.get(0));
if (command == null) {
throw new GlacierCliException("Invalid command given: " + arguments.get(0));
}
String defaultPropertiesPath = System.getProperty("user.home") + "/AwsCredentials.properties";
String propertiesPath = cmd.getOptionValue("properties", defaultPropertiesPath);
File props = new File(propertiesPath);
AWSCredentials credentials = new PropertiesCredentials(props);
Glacier glacier = new Glacier(credentials, cmd.getOptionValue("region", "us-east-1"));
switch(command) {
// Archive commands
case UPLOAD:
if (arguments.size() < 3) {
throw new GlacierCliException("The upload command requires at least three parameters.");
}
for (String archive : arguments.subList(2, arguments.size())) {
glacier.upload(arguments.get(1), archive);
}
break;
case DELETE:
if (arguments.size() != 3) {
throw new GlacierCliException("The delete command requires exactly three parameters.");
}
glacier.delete(arguments.get(1), arguments.get(2));
break;
case DOWNLOAD:
if (arguments.size() != 4) {
throw new GlacierCliException("The download command requires exactly four parameters.");
}
glacier.download(arguments.get(1), arguments.get(2), arguments.get(3));
break;
// Vault commands
case CREATE_VAULT:
if (arguments.size() != 2) {
throw new GlacierCliException("The create-vault command requires exactly one parameter.");
}
glacier.createVault(arguments.get(1));
break;
case DELETE_VAULT:
if (arguments.size() != 2) {
throw new GlacierCliException("The delete-vault command requires exactly two parameters.");
}
glacier.deleteVault(arguments.get(1));
break;
case INVENTORY:
if (arguments.size() != 2) {
throw new GlacierCliException("The inventory command requires exactly two parameters.");
}
glacier.inventory(arguments.get(1), cmd.getOptionValue("topic", "glacier"), cmd.getOptionValue("queue", "glacier"), cmd.getOptionValue("file", "glacier.json"));
break;
case INFO:
if (arguments.size() != 2) {
throw new GlacierCliException("The info command requires exactly two parameters.");
}
glacier.info(arguments.get(1));
break;
case LIST:
glacier.list();
break;
}
} catch (GlacierCliException e) {
System.err.println("error: " + e.getMessage());
System.err.println();
usage();
} catch (UnrecognizedOptionException e) {
System.err.println("error: Invalid argument: " + e.getOption());
usage();
}
}
Aggregations