List of usage examples for com.amazonaws.services.s3.model GetBucketLocationRequest GetBucketLocationRequest
public GetBucketLocationRequest(String bucketName)
From source file:com.carrotgarden.nexus.aws.s3.publish.amazon.AmazonServiceProvider.java
License:BSD License
private synchronized void checkAvailable() { reporter.requestCheckCount.inc();/*from www. jav a 2 s .c o m*/ reporter.requestTotalCount.inc(); try { final GetBucketLocationRequest request = // new GetBucketLocationRequest(mavenBucket()); final String result = client.getBucketLocation(request); setAvailable(true, null); } catch (final Exception e) { setAvailable(false, e); } mailer.sendAmazonReport(Report.AMAZON_HEALTH_REPORT, entry, this); checkCount++; }
From source file:com.handywedge.binarystore.store.aws.BinaryStoreManagerImpl.java
License:MIT License
/** * ?//from w w w .j a v a 2 s .co m * * @param bucketName * @return s3client * @throws StoreException * @throws Exception */ private AmazonS3 getS3Client(String bucketName) throws StoreException { logger.debug("get S3 Client start."); // ? AWSCredentialsProvider provider = new EnvironmentVariableCredentialsProvider(); // ClientConfiguration clientConfig = new ClientConfiguration() // .withProtocol(Protocol.HTTPS) // Proxy // .withProxyHost("proxyHost") // .withProxyPort(80) // .withProxyUsername("proxyUsername") // .withProxyPassword("proxyPassword") .withConnectionTimeout(10000); // ? AmazonS3 s3client = AmazonS3ClientBuilder.standard().withCredentials(provider) .withClientConfiguration(clientConfig).withRegion(DEFAULT_REGION) .withForceGlobalBucketAccessEnabled(true).build(); logger.debug("Region={}", s3client.getRegion()); try { // ?? if (!CommonUtils.isNullOrEmpty(bucketName) && !(s3client.doesBucketExistV2(bucketName))) { s3client.createBucket(new CreateBucketRequest(bucketName, DEFAULT_REGION.getName())); } // Get location. String bucketLocation = s3client.getBucketLocation(new GetBucketLocationRequest(bucketName)); logger.info("bucket location={}", bucketLocation); } catch (AmazonClientException ace) { throw new StoreException(HttpStatus.SC_CONFLICT, ErrorClassification.BS0003, ace, "?"); } logger.info("get S3 Client end."); return s3client; }
From source file:modules.storage.AmazonS3Storage.java
License:Open Source License
@Inject public AmazonS3Storage(Configuration configuration) { bucketName = configuration.getString("storage.s3.bucket", "thunderbit"); String accessKey = configuration.getString("storage.s3.accesskey"); String secretKey = configuration.getString("storage.s3.secretkey"); credentials = new BasicAWSCredentials(accessKey, secretKey); AmazonS3 amazonS3 = new AmazonS3Client(credentials); if (configuration.getBoolean("storage.s3.createBucket", true)) { try {//from w w w.j a v a 2 s .c o m if (!(amazonS3.doesBucketExist(bucketName))) { amazonS3.createBucket(new CreateBucketRequest(bucketName)); } String bucketLocation = amazonS3.getBucketLocation(new GetBucketLocationRequest(bucketName)); logger.info("Amazon S3 bucket created at " + bucketLocation); } catch (AmazonServiceException ase) { logAmazonServiceException(ase); } catch (AmazonClientException ace) { logAmazonClientException(ace); } } }
From source file:temp.zAmazonServiceProvider.java
License:BSD License
@Override public void checkAvailable() { try {/* w ww. ja v a2 s . c o m*/ final AmazonS3Client client = amazonConfig.client(); final String bucket = amazonConfig.bucket(); final GetBucketLocationRequest request = // new GetBucketLocationRequest(bucket); final String result = client.getBucketLocation(request); if (!setAvailable(true)) { log.info("amazon service available"); } } catch (final Exception e) { if (setAvailable(false)) { log.error("amazon service unavailable"); } } }