Example usage for com.amazonaws.services.s3.model Region fromValue

List of usage examples for com.amazonaws.services.s3.model Region fromValue

Introduction

In this page you can find the example usage for com.amazonaws.services.s3.model Region fromValue.

Prototype

public static Region fromValue(final String s3RegionId) throws IllegalArgumentException 

Source Link

Document

Returns the Amazon S3 Region enumeration value representing the specified Amazon S3 Region ID string.

Usage

From source file:com.igeekinc.indelible.indeliblefs.uniblock.casstore.s3.S3CASStore.java

License:Open Source License

public S3CASStore(String accessKey, String secretKey, CASStoreID storeID, String regionString,
        File initPropertiesFile) throws IOException {
    super(null);/*from ww  w  .j  a va 2s.co  m*/
    this.initPropertiesFiles = initPropertiesFile;
    this.accessKey = accessKey;
    this.secretKey = secretKey;
    if (regionString != null)
        region = Region.fromValue(regionString);
    else
        region = null;
    Properties writeProperties = new Properties();
    writeProperties.put(kAmazonAccessKeyName, accessKey);
    writeProperties.put(kAmazonSecretName, secretKey);
    writeProperties.put(kStoreIDName, storeID.toString());
    if (region != null)
        writeProperties.put(kAmazonRegionName, region.toString());
    FileOutputStream initPropertiesOutStream = new FileOutputStream(initPropertiesFile);
    writeProperties.store(initPropertiesOutStream, "S3CASStore Properties saved at" + (new Date()).toString());
    initPropertiesOutStream.close();

    this.storeID = storeID;
    initInternal();
    setStatus(CASStoreStatus.kReady);
}

From source file:com.igeekinc.indelible.indeliblefs.uniblock.casstore.s3.S3CASStore.java

License:Open Source License

public S3CASStore(File initPropertiesFile) throws IOException {
    super(null);//from  ww  w.jav a  2s.  c o m
    FileInputStream initPropertiesInputStream = new FileInputStream(initPropertiesFile);
    Properties initProperties = new Properties();
    initProperties.load(initPropertiesInputStream);
    accessKey = initProperties.getProperty(kAmazonAccessKeyName);
    secretKey = initProperties.getProperty(kAmazonSecretName);
    String storeIDStr = initProperties.getProperty(kStoreIDName);
    String regionString = initProperties.getProperty(kAmazonRegionName);
    if (regionString != null)
        region = Region.fromValue(regionString);
    else
        region = null;
    storeID = (CASStoreID) ObjectIDFactory.reconstituteFromString(storeIDStr);
    initInternal();
    setStatus(CASStoreStatus.kReady);
}

From source file:com.logpig.mweagle.rolling.S3RollingFileAppender.java

License:Apache License

public void setRegionName(String regionName) {
    s3Settings.regionName = Region.fromValue(regionName);
}

From source file:com.mindtree.maven.S3Mojo.java

License:Apache License

/**
 * @param bucketName//from   w  w w .  j a v a2 s . co m
 * 
 *            Tries to create bucket in amazon S3. Since bucket name has to
 *            be unique, if the given bucket name is not available it aborts
 */
private Bucket createS3Bucket(String bucketName) {
    List<Bucket> buckets = S3Helper.getBuckets(s3);
    for (Bucket b : buckets) {
        if (b.getName().equals(bucketName)) {
            return b;
        }
    }
    if (bucketName.equalsIgnoreCase(UNIQUE)) {
        if (bucketRegion == null) {
            return S3Helper.createUniqueBucket(s3, bucketPrefix, bucketSuffix);
        } else {
            Region region = Region.fromValue(bucketRegion);
            return S3Helper.createUniqueBucket(s3, bucketPrefix, bucketSuffix, region);
        }
    } else {
        if (bucketRegion == null) {
            return S3Helper.createBucket(s3, bucketName);
        } else {
            Region region = Region.fromValue(bucketRegion);
            return S3Helper.createBucket(s3, bucketName, region);
        }
    }
}

From source file:jp.classmethod.aws.gradle.s3.CreateBucketTask.java

License:Apache License

private String getAwsRegionName(final String region) {
    try {/*from  w ww  .  j av  a2 s  . co m*/
        return Region.fromValue(region).toString();
    } catch (IllegalArgumentException e) {
        throw new GradleException(e.getMessage(), e);
    }
}

From source file:org.apache.jackrabbit.oak.blob.cloud.aws.s3.S3Backend.java

License:Apache License

public void init(CachingDataStore store, String homeDir, Properties prop) throws DataStoreException {

    ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
    try {/*  w  w w  . jav  a2  s  .c o  m*/
        startTime = new Date();
        Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
        LOG.debug("init");
        this.store = 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;
        }

        asyncWriteExecuter = (ThreadPoolExecutor) Executors.newFixedThreadPool(asyncWritePoolSize,
                new NamedThreadFactory("s3-write-worker"));
        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);
        Map<String, String> filteredMap = Maps.newHashMap();
        if (prop != null) {
            filteredMap = Maps.filterKeys(Maps.fromProperties(prop), new Predicate<String>() {
                @Override
                public boolean apply(String input) {
                    return !input.equals(S3Constants.ACCESS_KEY) && !input.equals(S3Constants.SECRET_KEY);
                }
            });
        }
        throw new DataStoreException("Could not initialize S3 from " + filteredMap, e);
    } finally {
        if (contextClassLoader != null) {
            Thread.currentThread().setContextClassLoader(contextClassLoader);
        }
    }
}