Search in sources :

Example 26 with Region

use of software.amazon.awssdk.services.ec2.model.Region in project aws-doc-sdk-examples by awsdocs.

the class DescribeRegionsAndZones method main.

public static void main(String[] args) {
    final AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient();
    // snippet-start:[ec2.java1.describe_region_and_zones.regions]
    DescribeRegionsResult regions_response = ec2.describeRegions();
    for (Region region : regions_response.getRegions()) {
        System.out.printf("Found region %s " + "with endpoint %s", region.getRegionName(), region.getEndpoint());
    }
    // snippet-end:[ec2.java1.describe_region_and_zones.regions]
    // snippet-start:[ec2.java1.describe_region_and_zones.zones]
    DescribeAvailabilityZonesResult zones_response = ec2.describeAvailabilityZones();
    for (AvailabilityZone zone : zones_response.getAvailabilityZones()) {
        System.out.printf("Found availability zone %s " + "with status %s " + "in region %s", zone.getZoneName(), zone.getState(), zone.getRegionName());
    }
// snippet-end:[ec2.java1.describe_region_and_zones.zones]
}
Also used : DescribeRegionsResult(com.amazonaws.services.ec2.model.DescribeRegionsResult) Region(com.amazonaws.services.ec2.model.Region) AvailabilityZone(com.amazonaws.services.ec2.model.AvailabilityZone) AmazonEC2(com.amazonaws.services.ec2.AmazonEC2) DescribeAvailabilityZonesResult(com.amazonaws.services.ec2.model.DescribeAvailabilityZonesResult)

Example 27 with Region

use of software.amazon.awssdk.services.ec2.model.Region in project jackrabbit by apache.

the class S3Backend method init.

public void init(CachingDataStore store, String homeDir, Properties prop) throws DataStoreException {
    ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
    try {
        startTime = new Date();
        Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
        LOG.debug("init");
        setDataStore(store);
        s3ReqDecorator = new S3RequestDecorator(prop);
        s3service = Utils.openService(prop);
        if (bucket == null || "".equals(bucket.trim())) {
            bucket = prop.getProperty(S3Constants.S3_BUCKET);
        }
        String region = prop.getProperty(S3Constants.S3_REGION);
        Region s3Region = null;
        if (StringUtils.isNullOrEmpty(region)) {
            com.amazonaws.regions.Region ec2Region = Regions.getCurrentRegion();
            if (ec2Region != null) {
                s3Region = Region.fromValue(ec2Region.getName());
            } else {
                throw new AmazonClientException("parameter [" + S3Constants.S3_REGION + "] not configured and cannot be derived from environment");
            }
        } else {
            if (Utils.DEFAULT_AWS_BUCKET_REGION.equals(region)) {
                s3Region = Region.US_Standard;
            } else if (Region.EU_Ireland.toString().equals(region)) {
                s3Region = Region.EU_Ireland;
            } else {
                s3Region = Region.fromValue(region);
            }
        }
        if (!s3service.doesBucketExist(bucket)) {
            s3service.createBucket(bucket, s3Region);
            LOG.info("Created bucket [{}] in [{}] ", bucket, region);
        } else {
            LOG.info("Using bucket [{}] in [{}] ", bucket, region);
        }
        int writeThreads = 10;
        String writeThreadsStr = prop.getProperty(S3Constants.S3_WRITE_THREADS);
        if (writeThreadsStr != null) {
            writeThreads = Integer.parseInt(writeThreadsStr);
        }
        LOG.info("Using thread pool of [{}] threads in S3 transfer manager.", writeThreads);
        tmx = new TransferManager(s3service, (ThreadPoolExecutor) Executors.newFixedThreadPool(writeThreads, new NamedThreadFactory("s3-transfer-manager-worker")));
        int asyncWritePoolSize = 10;
        String maxConnsStr = prop.getProperty(S3Constants.S3_MAX_CONNS);
        if (maxConnsStr != null) {
            asyncWritePoolSize = Integer.parseInt(maxConnsStr) - writeThreads;
        }
        setAsyncWritePoolSize(asyncWritePoolSize);
        String renameKeyProp = prop.getProperty(S3Constants.S3_RENAME_KEYS);
        boolean renameKeyBool = (renameKeyProp == null || "".equals(renameKeyProp)) ? false : Boolean.parseBoolean(renameKeyProp);
        LOG.info("Rename keys [{}]", renameKeyBool);
        if (renameKeyBool) {
            renameKeys();
        }
        LOG.debug("S3 Backend initialized in [{}] ms", +(System.currentTimeMillis() - startTime.getTime()));
    } catch (Exception e) {
        LOG.debug("  error ", e);
        throw new DataStoreException("Could not initialize S3 from " + prop, e);
    } finally {
        if (contextClassLoader != null) {
            Thread.currentThread().setContextClassLoader(contextClassLoader);
        }
    }
}
Also used : TransferManager(com.amazonaws.services.s3.transfer.TransferManager) DataStoreException(org.apache.jackrabbit.core.data.DataStoreException) NamedThreadFactory(org.apache.jackrabbit.core.data.util.NamedThreadFactory) AmazonClientException(com.amazonaws.AmazonClientException) Date(java.util.Date) AmazonServiceException(com.amazonaws.AmazonServiceException) AmazonClientException(com.amazonaws.AmazonClientException) DataStoreException(org.apache.jackrabbit.core.data.DataStoreException) IOException(java.io.IOException) S3RequestDecorator(org.apache.jackrabbit.aws.ext.S3RequestDecorator) Region(com.amazonaws.services.s3.model.Region) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Aggregations

Region (software.amazon.awssdk.regions.Region)20 Ec2Client (software.amazon.awssdk.services.ec2.Ec2Client)20 AmazonClientException (com.amazonaws.AmazonClientException)3 AmazonServiceException (com.amazonaws.AmazonServiceException)3 DescribeRegionsResult (com.amazonaws.services.ec2.model.DescribeRegionsResult)3 Region (com.amazonaws.services.ec2.model.Region)3 Region (com.amazonaws.services.s3.model.Region)3 TransferManager (com.amazonaws.services.s3.transfer.TransferManager)3 IOException (java.io.IOException)3 Date (java.util.Date)3 DataStoreException (org.apache.jackrabbit.core.data.DataStoreException)3 NamedThreadFactory (org.apache.jackrabbit.core.data.util.NamedThreadFactory)3 Regions (com.amazonaws.regions.Regions)2 AmazonEC2 (com.amazonaws.services.ec2.AmazonEC2)2 Map (java.util.Map)2 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)2 AsyncHandler (com.amazonaws.handlers.AsyncHandler)1 AvailabilityZone (com.amazonaws.services.ec2.model.AvailabilityZone)1 DescribeAvailabilityZonesResult (com.amazonaws.services.ec2.model.DescribeAvailabilityZonesResult)1 DescribeRegionsRequest (com.amazonaws.services.ec2.model.DescribeRegionsRequest)1