Example usage for com.amazonaws.regions Region getRegion

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

Introduction

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

Prototype

public static Region getRegion(Regions region) 

Source Link

Document

Returns the region with the id given, or null if it cannot be found in the current regions.xml file.

Usage

From source file:com.gu.logback.appender.kinesis.BaseKinesisAppender.java

License:Open Source License

/**
 * Determine region. If not specified tries to determine region from where the
 * application is running or fall back to the default.
 * //from   w  w  w  . ja va2s  .  c o m
 * @return Region to configure the client
 */
private Region findRegion() {
    boolean regionProvided = !Validator.isBlank(this.region);
    if (!regionProvided) {
        // Determine region from where application is running, or fall back to default region
        Region currentRegion = Regions.getCurrentRegion();
        if (currentRegion != null) {
            return currentRegion;
        }
        return Region.getRegion(Regions.fromName(AppenderConstants.DEFAULT_REGION));
    }
    return Region.getRegion(Regions.fromName(this.region));
}

From source file:com.gu.logback.appender.kinesis.KinesisAppender.java

License:Open Source License

/**
 * Configures this appender instance and makes it ready for use by the
 * consumers. It validates mandatory parameters and confirms if the configured
 * stream is ready for publishing data yet.
 * //from   w w  w . ja  va2 s  . c o  m
 * Error details are made available through the fallback handler for this
 * appender
 * 
 * @throws IllegalStateException
 *           if we encounter issues configuring this appender instance
 */
@Override
public void start() {
    if (layout == null) {
        initializationFailed = true;
        addError("Invalid configuration - No layout for appender: " + name);
        return;
    }

    if (streamName == null) {
        initializationFailed = true;
        addError("Invalid configuration - streamName cannot be null for appender: " + name);
        return;
    }

    ClientConfiguration clientConfiguration = new ClientConfiguration();
    clientConfiguration.setMaxErrorRetry(maxRetries);
    clientConfiguration.setRetryPolicy(new RetryPolicy(PredefinedRetryPolicies.DEFAULT_RETRY_CONDITION,
            PredefinedRetryPolicies.DEFAULT_BACKOFF_STRATEGY, maxRetries, true));
    clientConfiguration.setUserAgent(AppenderConstants.USER_AGENT_STRING);

    BlockingQueue<Runnable> taskBuffer = new LinkedBlockingDeque<Runnable>(bufferSize);
    ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(threadCount, threadCount,
            AppenderConstants.DEFAULT_THREAD_KEEP_ALIVE_SEC, TimeUnit.SECONDS, taskBuffer,
            new BlockFastProducerPolicy());
    threadPoolExecutor.prestartAllCoreThreads();
    kinesisClient = new AmazonKinesisAsyncClient(credentials, clientConfiguration, threadPoolExecutor);

    boolean regionProvided = !Validator.isBlank(region);
    if (!regionProvided) {
        region = AppenderConstants.DEFAULT_REGION;
    }
    kinesisClient.setRegion(Region.getRegion(Regions.fromName(region)));
    if (!Validator.isBlank(endpoint)) {
        if (regionProvided) {
            addError("Received configuration for both region as well as Amazon Kinesis endpoint. (" + endpoint
                    + ") will be used as endpoint instead of default endpoint for region (" + region + ")");
        }
        kinesisClient.setEndpoint(endpoint);
    }

    DescribeStreamResult describeResult = null;
    try {
        describeResult = kinesisClient.describeStream(streamName);
        String streamStatus = describeResult.getStreamDescription().getStreamStatus();
        if (!StreamStatus.ACTIVE.name().equals(streamStatus)
                && !StreamStatus.UPDATING.name().equals(streamStatus)) {
            initializationFailed = true;
            addError(
                    "Stream " + streamName + " is not ready (in active/updating status) for appender: " + name);
        }
    } catch (ResourceNotFoundException rnfe) {
        initializationFailed = true;
        addError("Stream " + streamName + " doesn't exist for appender: " + name, rnfe);
    }

    asyncCallHander = new AsyncPutCallStatsReporter(this);

    super.start();
}

From source file:com.haskins.cloudtrailviewer.dialog.resourcedetail.detailpanels.AsGroupDetail.java

License:Open Source License

@Override
public String retrieveDetails(ResourceDetailRequest detailRequest) {

    String response = null;//from  w  ww. j  a v  a  2  s  .c  o  m

    try {

        AmazonAutoScaling asClient = new AmazonAutoScalingClient(credentials);
        asClient.setRegion(Region.getRegion(Regions.fromName(detailRequest.getRegion())));

        DescribeAutoScalingGroupsRequest request = new DescribeAutoScalingGroupsRequest();
        request.setAutoScalingGroupNames(Collections.singletonList(detailRequest.getResourceName()));

        DescribeAutoScalingGroupsResult result = asClient.describeAutoScalingGroups(request);
        buildUI(result);

    } catch (IllegalArgumentException | AmazonClientException e) {
        LOGGER.log(Level.WARNING, "Problem retrieving AS detail from AWS", e);
        response = e.getMessage();
    }

    return response;
}

From source file:com.haskins.cloudtrailviewer.dialog.resourcedetail.detailpanels.AsLaunchDetail.java

License:Open Source License

@Override
public String retrieveDetails(ResourceDetailRequest detailRequest) {

    String response = null;//from   w  ww . j  av  a 2  s. c  om

    try {

        AmazonAutoScaling asClient = new AmazonAutoScalingClient(credentials);
        asClient.setRegion(Region.getRegion(Regions.fromName(detailRequest.getRegion())));

        DescribeLaunchConfigurationsRequest request = new DescribeLaunchConfigurationsRequest();
        request.setLaunchConfigurationNames(Collections.singletonList(detailRequest.getResourceName()));

        DescribeLaunchConfigurationsResult result = asClient.describeLaunchConfigurations(request);
        buildUI(result);

    } catch (IllegalArgumentException | AmazonClientException e) {
        response = e.getMessage();
    }

    return response;
}

From source file:com.haskins.cloudtrailviewer.dialog.resourcedetail.detailpanels.CfStackDetail.java

License:Open Source License

@Override
public String retrieveDetails(ResourceDetailRequest detailRequest) {

    String response = null;/*from w  ww.j  ava2 s. com*/

    try {

        AmazonCloudFormation client = new AmazonCloudFormationClient(credentials);
        client.setRegion(Region.getRegion(Regions.fromName(detailRequest.getRegion())));

        DescribeStacksRequest request = new DescribeStacksRequest();
        request.setStackName(detailRequest.getResourceName());

        DescribeStacksResult result = client.describeStacks(request);
        buildUI(result);

    } catch (IllegalArgumentException | AmazonClientException e) {
        response = e.getMessage();
        LOGGER.log(Level.WARNING, "Problem retrieving CloudFormation details from AWS", e);
    }

    return response;
}

From source file:com.haskins.cloudtrailviewer.dialog.resourcedetail.detailpanels.CsDomainDetail.java

License:Open Source License

@Override
public String retrieveDetails(ResourceDetailRequest detailRequest) {

    String response = null;//from   w  ww .  ja  va2s.  c o m

    try {

        AmazonCloudSearch client = new AmazonCloudSearchClient(credentials);
        client.setRegion(Region.getRegion(Regions.fromName(detailRequest.getRegion())));

        DescribeDomainsRequest request = new DescribeDomainsRequest();
        request.setDomainNames(Collections.singletonList(detailRequest.getResourceName()));

        DescribeDomainsResult result = client.describeDomains(request);
        buildUI(result);

    } catch (IllegalArgumentException | AmazonClientException e) {
        response = e.getMessage();
        LOGGER.log(Level.WARNING, "Problem retrieving CloudSearch details from AWS", e);
    }

    return response;
}

From source file:com.haskins.cloudtrailviewer.dialog.resourcedetail.detailpanels.DbTableDetail.java

License:Open Source License

@Override
public String retrieveDetails(ResourceDetailRequest detailRequest) {

    String response = null;//  w ww  .  ja  va2s .co  m

    try {

        AmazonDynamoDB client = new AmazonDynamoDBClient(credentials);
        client.setRegion(Region.getRegion(Regions.fromName(detailRequest.getRegion())));

        DescribeTableRequest request = new DescribeTableRequest();
        request.setTableName(detailRequest.getResourceName());

        DescribeTableResult result = client.describeTable(request);
        buildUI(result);

    } catch (IllegalArgumentException | AmazonClientException e) {
        response = e.getMessage();
        LOGGER.log(Level.WARNING, "Problem retrieving DynamoDb details from AWS", e);
    }

    return response;
}

From source file:com.haskins.cloudtrailviewer.dialog.resourcedetail.detailpanels.EC2InstanceDetail.java

License:Open Source License

@Override
public String retrieveDetails(ResourceDetailRequest detailRequest) {

    String response = null;/*ww  w . ja  va 2 s  .c  o m*/

    try {

        AmazonEC2 ec2Client = new AmazonEC2Client(credentials);
        ec2Client.setRegion(Region.getRegion(Regions.fromName(detailRequest.getRegion())));

        DescribeInstancesRequest request = new DescribeInstancesRequest();
        request.setInstanceIds(Collections.singletonList(detailRequest.getResourceName()));

        DescribeInstancesResult result = ec2Client.describeInstances(request);
        buildUI(result);

    } catch (IllegalArgumentException | AmazonClientException e) {
        response = e.getMessage();
        LOGGER.log(Level.WARNING, "Problem retrieving EC2 details from AWS", e);
    }

    return response;
}

From source file:com.haskins.cloudtrailviewer.dialog.resourcedetail.detailpanels.EC2SecurityGroupDetail.java

License:Open Source License

@Override
public String retrieveDetails(ResourceDetailRequest detailRequest) {

    String response = null;//from w  w  w . jav  a2  s.c om

    try {
        AmazonEC2 ec2Client = new AmazonEC2Client(credentials);
        ec2Client.setRegion(Region.getRegion(Regions.fromName(detailRequest.getRegion())));

        DescribeSecurityGroupsRequest request = new DescribeSecurityGroupsRequest();
        request.setGroupIds(Collections.singletonList(detailRequest.getResourceName()));

        DescribeSecurityGroupsResult result = ec2Client.describeSecurityGroups(request);
        buildUI(result);

    } catch (IllegalArgumentException | AmazonClientException e) {
        response = e.getMessage();
        LOGGER.log(Level.WARNING, "Problem retrieving EC2 Securuty Group details from AWS", e);
    }

    return response;
}

From source file:com.haskins.cloudtrailviewer.dialog.resourcedetail.detailpanels.ElbDetail.java

License:Open Source License

@Override
public String retrieveDetails(ResourceDetailRequest detailRequest) {

    String response = null;/* ww  w.  j  a  v a2 s.  com*/

    try {

        AmazonElasticLoadBalancingClient elbClient = new AmazonElasticLoadBalancingClient(credentials);
        elbClient.setRegion(Region.getRegion(Regions.fromName(detailRequest.getRegion())));

        DescribeLoadBalancersRequest request = new DescribeLoadBalancersRequest();
        request.setLoadBalancerNames(Collections.singletonList(detailRequest.getResourceName()));

        DescribeLoadBalancersResult result = elbClient.describeLoadBalancers(request);
        buildUI(result);

    } catch (IllegalArgumentException | AmazonClientException e) {
        response = e.getMessage();
        LOGGER.log(Level.WARNING, "Problem retrieving ELB details from AWS", e);
    }

    return response;
}