Example usage for com.amazonaws.regions RegionUtils getRegion

List of usage examples for com.amazonaws.regions RegionUtils getRegion

Introduction

In this page you can find the example usage for com.amazonaws.regions RegionUtils getRegion.

Prototype

public static Region getRegion(String regionName) 

Source Link

Document

Returns the region with the given regionName and proper partition if found in region metadata.

Usage

From source file:AbstractAmazonKinesisFirehoseDelivery.java

License:Open Source License

/**
 * Method to initialize the clients using the specified AWSCredentials.
 *
 * @param Exception/*w w  w  . ja  v a2 s  .  com*/
 */
protected static void initClients() throws Exception {
    /*
     * The ProfileCredentialsProvider will return your [default] credential
     * profile by reading from the credentials file located at
     * (~/.aws/credentials).
     */
    AWSCredentials credentials = null;
    try {
        credentials = new ProfileCredentialsProvider().getCredentials();
    } catch (Exception e) {
        throw new AmazonClientException("Cannot load the credentials from the credential profiles file. "
                + "Please make sure that your credentials file is at the correct "
                + "location (~/.aws/credentials), and is in valid format.", e);
    }

    // S3 client
    s3Client = new AmazonS3Client(credentials);
    Region s3Region = RegionUtils.getRegion(s3RegionName);
    s3Client.setRegion(s3Region);

    // Firehose client
    firehoseClient = new AmazonKinesisFirehoseClient(credentials);
    firehoseClient.setRegion(RegionUtils.getRegion(firehoseRegion));

    // IAM client
    iamClient = new AmazonIdentityManagementClient(credentials);
    iamClient.setRegion(RegionUtils.getRegion(iamRegion));
}

From source file:br.com.ingenieux.mojo.aws.AbstractAWSMojo.java

License:Apache License

protected Region getRegion() {
    if (null != regionObj) {
        return regionObj;
    }/*from ww  w. j a  va 2 s.c om*/

    regionObj = RegionUtils.getRegion(regionName);

    Validate.notNull(regionObj, "Invalid region: " + regionName);

    return regionObj;
}

From source file:com.alertlogic.aws.analytics.poc.Utils.java

License:Open Source License

/**
 * Creates a Region object corresponding to the AWS Region. If an invalid region is passed in
 * then the JVM is terminated with an exit code of 1.
 * /*from  w  w  w  . j av a  2s.c  om*/
 * @param regionStr the common name of the region for e.g. 'us-east-1'.
 * @return A Region object corresponding to regionStr.
 */
public static Region parseRegion(String regionStr) {
    Region region = RegionUtils.getRegion(regionStr);

    if (region == null) {
        System.err.println(regionStr + " is not a valid AWS region.");
        System.exit(1);
    }
    return region;
}

From source file:com.barryku.karaf.MyServiceImpl.java

License:Apache License

public Response getJobLog(String jobId) {

    DynamoLogger logger = new DynamoLogger(RegionUtils.getRegion("us-west-2"));
    List<Item> items = logger.getLog(jobId);
    StringBuilder sb = new StringBuilder();
    sb.append("[");
    for (Item item : items) {
        sb.append(item.toJSONPretty()).append(",");
    }//  ww w  .  j a  v a2 s. co  m

    return Response.ok().entity(sb.length() > 1 ? sb.substring(0, sb.length() - 1) + "]" : "[]")
            .header("Access-Control-Allow-Origin", "*")
            .header("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT").allow("OPTIONS").build();

}

From source file:com.calamp.services.kinesis.events.processor.CalAmpEventProcessor.java

License:Open Source License

public static void main(String[] args) throws Exception {
    checkUsage(args);//  w  w  w.  ja  v  a 2 s.  c  om
    //String applicationName = args[0];
    //String streamName = args[1];
    //Region region = RegionUtils.getRegion(args[2]);
    boolean isUnordered = Boolean.valueOf(args[3]);
    String applicationName = isUnordered ? CalAmpParameters.sortAppName : CalAmpParameters.consumeAppName;
    String streamName = isUnordered ? CalAmpParameters.unorderdStreamName : CalAmpParameters.orderedStreamName;
    Region region = RegionUtils.getRegion(CalAmpParameters.regionName);

    if (region == null) {
        System.err.println(args[2] + " is not a valid AWS region.");
        System.exit(1);
    }

    setLogLevels();
    AWSCredentialsProvider credentialsProvider = CredentialUtils.getCredentialsProvider();
    ClientConfiguration cc = ConfigurationUtils.getClientConfigWithUserAgent(true);
    AmazonKinesis kinesisClient = new AmazonKinesisClient(credentialsProvider, cc);
    kinesisClient.setRegion(region);

    //Utils.kinesisClient = kinesisClient;

    String workerId = String.valueOf(UUID.randomUUID());
    KinesisClientLibConfiguration kclConfig = new KinesisClientLibConfiguration(applicationName, streamName,
            credentialsProvider, workerId).withRegionName(region.getName()).withCommonClientConfig(cc)
                    .withMaxRecords(com.calamp.services.kinesis.events.utils.CalAmpParameters.maxRecPerPoll)
                    .withIdleTimeBetweenReadsInMillis(
                            com.calamp.services.kinesis.events.utils.CalAmpParameters.pollDelayMillis)
                    .withCallProcessRecordsEvenForEmptyRecordList(CalAmpParameters.alwaysPoll)
                    .withInitialPositionInStream(InitialPositionInStream.TRIM_HORIZON);

    IRecordProcessorFactory processorFactory = new RecordProcessorFactory(isUnordered);

    // Create the KCL worker with the stock trade record processor factory
    Worker worker = new Worker(processorFactory, kclConfig);

    int exitCode = 0;
    try {
        worker.run();
    } catch (Throwable t) {
        LOG.error("Caught throwable while processing data.", t);
        exitCode = 1;
    }
    System.exit(exitCode);
}

From source file:com.calamp.services.kinesis.events.processor.UnorderedRecordProcessor.java

License:Open Source License

public UnorderedRecordProcessor() {
    try {/*from  w w  w. j  ava 2  s . c o m*/
        Region region = RegionUtils.getRegion(CalAmpParameters.regionName);
        AWSCredentials credentials = CredentialUtils.getCredentialsProvider().getCredentials();
        ClientConfiguration ccuord = ConfigurationUtils.getClientConfigWithUserAgent(true);
        ClientConfiguration ccord = ConfigurationUtils.getClientConfigWithUserAgent(false);
        kinesisClientToUnordered = new AmazonKinesisClient(credentials, ccuord);
        kinesisClientToOrdered = new AmazonKinesisClient(credentials, ccord);
        kinesisClientToUnordered.setRegion(region);
        kinesisClientToOrdered.setRegion(region);
        Utils.validateStream(kinesisClientToUnordered, CalAmpParameters.unorderdStreamName);
        Utils.validateStream(kinesisClientToOrdered, CalAmpParameters.orderedStreamName);
        Utils.initLazyLog(CalAmpParameters.bufferLogName, "Sort Buffer Start");
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.calamp.services.kinesis.events.writer.CalAmpEventWriter.java

License:Open Source License

public static void main(String[] args) throws Exception {
    checkUsage(args);/*from   w  ww .j a v  a 2  s . c o m*/
    String streamName = CalAmpParameters.unorderdStreamName; //args[0];
    String regionName = CalAmpParameters.regionName;
    Region region = RegionUtils.getRegion(regionName);
    if (region == null) {
        System.err.println(regionName + " is not a valid AWS region.");
        System.exit(1);
    }
    AWSCredentials credentials = CredentialUtils.getCredentialsProvider().getCredentials();

    ClientConfiguration ccuo = ConfigurationUtils.getClientConfigWithUserAgent(true);
    AmazonKinesis kinesisClient = new AmazonKinesisClient(credentials, ccuo);
    kinesisClient.setRegion(region);

    // Validate that the stream exists and is active
    Utils.validateStream(kinesisClient, streamName);

    int numToGen = 50000;
    String filePath = "kinesis-rand-events.in";

    //genRandEventsToFile( filePath, numToGen );
    List<CalAmpEvent> buffer = readEventsFromFile(filePath);
    Utils.initLazyLog(CalAmpParameters.writeLogName, "Producer Send Start");

    Utils.putByParts(buffer, CalAmpParameters.unorderdStreamName, kinesisClient, CalAmpParameters.writeLogName);
    //Utils.putObo(buffer, CalAmpParameters.unorderdStreamName, kinesisClient, CalAmpParameters.writeLogName);

    //runningLoop(new RandomEventSender(kinesisClient, filePath, CalAmpParameters.pollDelayMillis));
    System.out.println("Writer Done");
}

From source file:com.cloudbees.jenkins.plugins.amazonecs.ECSCloud.java

License:Open Source License

public static Region getRegion(String regionName) {
    if (StringUtils.isNotEmpty(regionName)) {
        return RegionUtils.getRegion(regionName);
    } else {//from ww  w  .j  a  va  2s. co m
        return Region.getRegion(Regions.US_EAST_1);
    }
}

From source file:com.cloudbees.jenkins.plugins.amazonecs.ECSService.java

License:Open Source License

Region getRegion(String regionName) {
    if (StringUtils.isNotEmpty(regionName)) {
        return RegionUtils.getRegion(regionName);
    } else {/* w w  w .  j a va2 s  .  co m*/
        return Region.getRegion(Regions.US_EAST_1);
    }
}

From source file:com.cloudera.director.aws.ec2.EC2Provider.java

License:Apache License

/**
 * Returns the KMS endpoint URL for the specified region.
 *
 * @param kmsClient  the KMS client//from   w  w  w.j a v a  2s . co  m
 * @param regionName the desired region
 * @return the endpoint URL for the specified region
 * @throws IllegalArgumentException if the endpoint cannot be determined
 */
private static String getKMSEndpointForRegion(AWSKMSClient kmsClient, String regionName) {
    checkNotNull(kmsClient, "kmsClient is null");
    checkNotNull(regionName, "regionName is null");

    com.amazonaws.regions.Region region = RegionUtils.getRegion(regionName);

    if (region == null) {
        throw new IllegalArgumentException(String.format("Unable to find the region %s", regionName));
    }

    String serviceName = kmsClient.getServiceName();
    String protocolPrefix = region.hasHttpsEndpoint(serviceName) ? "https://" : "http://";
    return protocolPrefix + region.getServiceEndpoint(serviceName);
}