List of usage examples for com.amazonaws.services.s3.model Region EU_Ireland
Region EU_Ireland
To view the source code for com.amazonaws.services.s3.model Region EU_Ireland.
Click Source Link
From source file:com.openkm.util.backup.RepositoryS3Backup.java
License:Open Source License
/** * Performs a recursive repository content export with metadata *//*from w w w. ja va2 s . c o m*/ public static ImpExpStats backup(String token, String fldPath, String bucket, boolean metadata, Writer out, InfoDecorator deco) throws PathNotFoundException, AccessDeniedException, RepositoryException, FileNotFoundException, ParseException, NoSuchGroupException, IOException, DatabaseException, GeneralException { log.debug("backup({}, {}, {}, {}, {}, {})", new Object[] { token, fldPath, bucket, metadata, out, deco }); ImpExpStats stats = null; if (running) { throw new GeneralException("Backup in progress"); } else { running = true; try { if (!Config.AMAZON_ACCESS_KEY.equals("") && !Config.AMAZON_SECRET_KEY.equals("")) { AmazonS3 s3 = new AmazonS3Client( new BasicAWSCredentials(Config.AMAZON_ACCESS_KEY, Config.AMAZON_SECRET_KEY)); if (!s3.doesBucketExist(bucket)) { s3.createBucket(bucket, Region.EU_Ireland); } stats = backupHelper(token, fldPath, s3, bucket, metadata, out, deco); log.info("Backup finished!"); } else { throw new GeneralException("Missing Amazon Web Service keys"); } } finally { running = false; } } log.debug("exportDocuments: {}", stats); return stats; }
From source file:fr.eurecom.hybris.kvs.drivers.AmazonKvs.java
License:Apache License
private void createContainer() throws IOException { try {//from w w w. jav a 2s . com if (!this.s3.doesBucketExist(this.rootContainer)) this.s3.createBucket(this.rootContainer, Region.EU_Ireland); // XXX hardcoded bucket location } catch (AmazonClientException e) { throw new IOException(e); } }
From source file:org.akvo.flow.InstanceConfigurator.java
License:Open Source License
public static void main(String[] args) throws Exception { Options opts = getOptions();// w w w . j ava 2s . c om CommandLineParser parser = new BasicParser(); CommandLine cli = null; try { cli = parser.parse(opts, args); } catch (Exception e) { System.err.println(e.getMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(InstanceConfigurator.class.getName(), opts); System.exit(1); } String awsAccessKey = cli.getOptionValue("ak"); String awsSecret = cli.getOptionValue("as"); String bucketName = cli.getOptionValue("bn"); String gaeId = cli.getOptionValue("gae"); String outFolder = cli.getOptionValue("o"); String flowServices = cli.getOptionValue("fs"); String alias = cli.getOptionValue("a"); String emailFrom = cli.getOptionValue("ef"); String emailTo = cli.getOptionValue("et"); String orgName = cli.getOptionValue("on"); String signingKey = cli.getOptionValue("sk"); File out = new File(outFolder); if (!out.exists()) { out.mkdirs(); } Map<String, AccessKey> accessKeys = new HashMap<String, AccessKey>(); String apiKey = UUID.randomUUID().toString().replaceAll("-", ""); AWSCredentials creds = new BasicAWSCredentials(awsAccessKey, awsSecret); AmazonIdentityManagementClient iamClient = new AmazonIdentityManagementClient(creds); AmazonS3Client s3Client = new AmazonS3Client(creds); // Creating bucket System.out.println("Creating bucket: " + bucketName); try { if (s3Client.doesBucketExist(bucketName)) { System.out.println(bucketName + " already exists, skipping creation"); } else { s3Client.createBucket(bucketName, Region.EU_Ireland); } } catch (Exception e) { System.err.println("Error trying to create bucket " + bucketName + " : " + e.getMessage()); System.exit(1); } // Creating users and groups String gaeUser = bucketName + GAE_SUFFIX; String apkUser = bucketName + APK_SUFFIX; // GAE System.out.println("Creating user: " + gaeUser); GetUserRequest gaeUserRequest = new GetUserRequest(); gaeUserRequest.setUserName(gaeUser); try { iamClient.getUser(gaeUserRequest); System.out.println("User already exists, skipping creation"); } catch (NoSuchEntityException e) { iamClient.createUser(new CreateUserRequest(gaeUser)); } System.out.println("Requesting security credentials for " + gaeUser); CreateAccessKeyRequest gaeAccessRequest = new CreateAccessKeyRequest(); gaeAccessRequest.setUserName(gaeUser); CreateAccessKeyResult gaeAccessResult = iamClient.createAccessKey(gaeAccessRequest); accessKeys.put(gaeUser, gaeAccessResult.getAccessKey()); // APK System.out.println("Creating user: " + apkUser); GetUserRequest apkUserRequest = new GetUserRequest(); apkUserRequest.setUserName(apkUser); try { iamClient.getUser(apkUserRequest); System.out.println("User already exists, skipping creation"); } catch (NoSuchEntityException e) { iamClient.createUser(new CreateUserRequest(apkUser)); } System.out.println("Requesting security credentials for " + apkUser); CreateAccessKeyRequest apkAccessRequest = new CreateAccessKeyRequest(); apkAccessRequest.setUserName(apkUser); CreateAccessKeyResult apkAccessResult = iamClient.createAccessKey(apkAccessRequest); accessKeys.put(apkUser, apkAccessResult.getAccessKey()); System.out.println("Configuring security policies..."); Configuration cfg = new Configuration(); cfg.setClassForTemplateLoading(InstanceConfigurator.class, "/org/akvo/flow/templates"); cfg.setObjectWrapper(new DefaultObjectWrapper()); cfg.setDefaultEncoding("UTF-8"); Map<String, Object> data = new HashMap<String, Object>(); data.put("bucketName", bucketName); data.put("version", new SimpleDateFormat("yyyy-MM-dd").format(new Date())); data.put("accessKey", accessKeys); Template t1 = cfg.getTemplate("apk-s3-policy.ftl"); StringWriter apkPolicy = new StringWriter(); t1.process(data, apkPolicy); Template t2 = cfg.getTemplate("gae-s3-policy.ftl"); StringWriter gaePolicy = new StringWriter(); t2.process(data, gaePolicy); iamClient.putUserPolicy( new PutUserPolicyRequest(apkUser, apkUser, Policy.fromJson(apkPolicy.toString()).toJson())); iamClient.putUserPolicy( new PutUserPolicyRequest(gaeUser, gaeUser, Policy.fromJson(gaePolicy.toString()).toJson())); System.out.println("Creating configuration files..."); // survey.properties Map<String, Object> apkData = new HashMap<String, Object>(); apkData.put("awsBucket", bucketName); apkData.put("awsAccessKeyId", accessKeys.get(apkUser).getAccessKeyId()); apkData.put("awsSecretKey", accessKeys.get(apkUser).getSecretAccessKey()); apkData.put("serverBase", "https://" + gaeId + ".appspot.com"); apkData.put("restApiKey", apiKey); Template t3 = cfg.getTemplate("survey.properties.ftl"); FileWriter fw = new FileWriter(new File(out, "/survey.properties")); t3.process(apkData, fw); // appengine-web.xml Map<String, Object> webData = new HashMap<String, Object>(); webData.put("awsBucket", bucketName); webData.put("awsAccessKeyId", accessKeys.get(gaeUser).getAccessKeyId()); webData.put("awsSecretAccessKey", accessKeys.get(gaeUser).getSecretAccessKey()); webData.put("s3url", "https://" + bucketName + ".s3.amazonaws.com"); webData.put("instanceId", gaeId); webData.put("alias", alias); webData.put("flowServices", flowServices); webData.put("apiKey", apiKey); webData.put("emailFrom", emailFrom); webData.put("emailTo", emailTo); webData.put("organization", orgName); webData.put("signingKey", signingKey); Template t5 = cfg.getTemplate("appengine-web.xml.ftl"); FileWriter fw3 = new FileWriter(new File(out, "/appengine-web.xml")); t5.process(webData, fw3); System.out.println("Done"); }
From source file:org.apache.jackrabbit.aws.ext.ds.S3Backend.java
License:Apache License
public void init(CachingDataStore store, String homeDir, Properties prop) throws DataStoreException { ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); try {/*from w w w . j a va2 s . co m*/ startTime = new Date(); Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); LOG.debug("init"); this.store = store; s3service = Utils.openService(prop); if (bucket == null || "".equals(bucket.trim())) { bucket = prop.getProperty(S3Constants.S3_BUCKET); } String region = prop.getProperty(S3Constants.S3_REGION); String endpoint = null; if (!s3service.doesBucketExist(bucket)) { if (DEFAULT_AWS_BUCKET_REGION.equals(region)) { s3service.createBucket(bucket, Region.US_Standard); endpoint = S3 + DOT + AWSDOTCOM; } else if (Region.EU_Ireland.toString().equals(region)) { s3service.createBucket(bucket, Region.EU_Ireland); endpoint = "s3-eu-west-1" + DOT + AWSDOTCOM; } else { s3service.createBucket(bucket, region); endpoint = S3 + DASH + region + DOT + AWSDOTCOM; } LOG.info("Created bucket [{}] in [{}] ", bucket, region); } else { LOG.info("Using bucket [{}]", bucket); if (DEFAULT_AWS_BUCKET_REGION.equals(region)) { endpoint = S3 + DOT + AWSDOTCOM; } else if (Region.EU_Ireland.toString().equals(region)) { endpoint = "s3-eu-west-1" + DOT + AWSDOTCOM; } else { endpoint = S3 + DASH + region + DOT + AWSDOTCOM; } } String propEndPoint = prop.getProperty(S3Constants.S3_END_POINT); if (propEndPoint != null & !"".equals(propEndPoint)) { endpoint = propEndPoint; } /* * setting endpoint to remove latency of redirection. If endpoint is * not set, invocation first goes us standard region, which * redirects it to correct location. */ s3service.setEndpoint(endpoint); LOG.info("S3 service endpoint [{}] ", endpoint); 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)) ? true : Boolean.parseBoolean(renameKeyProp); 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); } } }
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 . j a v a 2s. c om*/ 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); } } }
From source file:org.apache.jackrabbit.oak.blob.cloud.aws.s3.Utils.java
License:Apache License
/** * Create AmazonS3Client from properties. * // w w w . j a va 2 s. c o m * @param prop properties to configure @link {@link AmazonS3Client} * @return {@link AmazonS3Client} */ public static AmazonS3Client openService(final Properties prop) { String accessKey = prop.getProperty(S3Constants.ACCESS_KEY); String secretKey = prop.getProperty(S3Constants.SECRET_KEY); AmazonS3Client s3service = null; if (StringUtils.isNullOrEmpty(accessKey) || StringUtils.isNullOrEmpty(secretKey)) { LOG.info("Configuring Amazon Client from environment"); s3service = new AmazonS3Client(getClientConfiguration(prop)); } else { LOG.info("Configuring Amazon Client from property file."); AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey); s3service = new AmazonS3Client(credentials, getClientConfiguration(prop)); } String region = prop.getProperty(S3Constants.S3_REGION); String endpoint = null; String propEndPoint = prop.getProperty(S3Constants.S3_END_POINT); if ((propEndPoint != null) & !"".equals(propEndPoint)) { endpoint = propEndPoint; } else { if (StringUtils.isNullOrEmpty(region)) { com.amazonaws.regions.Region s3Region = Regions.getCurrentRegion(); if (s3Region != null) { region = s3Region.getName(); } else { throw new AmazonClientException("parameter [" + S3Constants.S3_REGION + "] not configured and cannot be derived from environment"); } } if (DEFAULT_AWS_BUCKET_REGION.equals(region)) { endpoint = S3 + DOT + AWSDOTCOM; } else if (Region.EU_Ireland.toString().equals(region)) { endpoint = "s3-eu-west-1" + DOT + AWSDOTCOM; } else { endpoint = S3 + DASH + region + DOT + AWSDOTCOM; } } /* * setting endpoint to remove latency of redirection. If endpoint is * not set, invocation first goes us standard region, which * redirects it to correct location. */ s3service.setEndpoint(endpoint); LOG.info("S3 service endpoint [{}] ", endpoint); return s3service; }
From source file:shnakkydoodle.notifying.provider.aws.AwsProvider.java
License:Open Source License
/** * Get the SNS Client already initialised * /*from w w w .ja v a 2 s . c o m*/ * @return */ private AmazonSNSClient getSNSClient() { AmazonSNSClient snsClient = new AmazonSNSClient(this.credentials); snsClient.setRegion(Region.EU_Ireland.toAWSRegion()); return snsClient; }
From source file:shnakkydoodle.queueing.provider.aws.AwsProvider.java
License:Open Source License
/** * Delete the queue//from www . j a va 2 s. c om * * @param queueName */ @Override public void deleteQueue(String queueName) throws Exception { AmazonSQS sqs = new AmazonSQSClient(credentials); sqs.setRegion(Region.EU_Ireland.toAWSRegion()); CreateQueueRequest createQueueRequest = new CreateQueueRequest(queueName); sqs.deleteQueue(sqs.createQueue(createQueueRequest).getQueueUrl()); }
From source file:shnakkydoodle.queueing.provider.aws.AwsProvider.java
License:Open Source License
/** * Enqueue a message/*from ww w . j av a 2 s .co m*/ * * @param queuename * @param message */ @Override public void enqueue(String queueName, String message) throws Exception { AmazonSQS sqs = new AmazonSQSClient(credentials); sqs.setRegion(Region.EU_Ireland.toAWSRegion()); sqs.createQueue(queueName); CreateQueueRequest createQueueRequest = new CreateQueueRequest(queueName); String myQueueUrl = sqs.createQueue(createQueueRequest).getQueueUrl(); sqs.sendMessage(new SendMessageRequest(myQueueUrl, message)); }
From source file:shnakkydoodle.queueing.provider.aws.AwsProvider.java
License:Open Source License
/** * Enqueue a bunch of message//w w w . j ava2s .c o m * * @param queuename * @param message */ @Override public void enqueue(String queueName, ArrayList<String> messages) throws Exception { AmazonSQS sqs = new AmazonSQSClient(credentials); sqs.setRegion(Region.EU_Ireland.toAWSRegion()); sqs.createQueue(queueName); CreateQueueRequest createQueueRequest = new CreateQueueRequest(queueName); String myQueueUrl = sqs.createQueue(createQueueRequest).getQueueUrl(); SendMessageBatchRequest batchRequest = new SendMessageBatchRequest(myQueueUrl); batchRequest.setQueueUrl(myQueueUrl); List<SendMessageBatchRequestEntry> entries = new ArrayList<SendMessageBatchRequestEntry>(); for (String message : messages) { entries.add(new SendMessageBatchRequestEntry(UUID.randomUUID().toString(), message)); } batchRequest.setEntries(entries); sqs.sendMessageBatch(batchRequest); }