Search in sources :

Example 6 with PropertiesCredentials

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();
    }
}
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 7 with PropertiesCredentials

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));
                }
            }
        }
    }
}
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 8 with PropertiesCredentials

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);
    }
}
Also used : DynamoDbServiceRegistryProperties(org.apereo.cas.configuration.model.support.dynamodb.DynamoDbServiceRegistryProperties) PropertiesCredentials(com.amazonaws.auth.PropertiesCredentials) AmazonDynamoDBClient(com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) AWSCredentials(com.amazonaws.auth.AWSCredentials) ClientConfiguration(com.amazonaws.ClientConfiguration) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) Bean(org.springframework.context.annotation.Bean)

Example 9 with PropertiesCredentials

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);
}
Also used : AmazonS3Client(com.amazonaws.services.s3.AmazonS3Client) AmazonSimpleDBClient(com.amazonaws.services.simpledb.AmazonSimpleDBClient) InputStream(java.io.InputStream) PersistenceException(javax.persistence.PersistenceException) PropertiesCredentials(com.amazonaws.auth.PropertiesCredentials) IOException(java.io.IOException) AWSCredentials(com.amazonaws.auth.AWSCredentials) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials)

Example 10 with PropertiesCredentials

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();
    }
}
Also used : CommandLine(org.apache.commons.cli.CommandLine) PosixParser(org.apache.commons.cli.PosixParser) PropertiesCredentials(com.amazonaws.auth.PropertiesCredentials) CommandLineParser(org.apache.commons.cli.CommandLineParser) File(java.io.File) AWSCredentials(com.amazonaws.auth.AWSCredentials) UnrecognizedOptionException(org.apache.commons.cli.UnrecognizedOptionException)

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