コード例 #1
0
ファイル: ImportS3.java プロジェクト: pragnesh/h2o
 @Override
 protected String parse(String input) throws IllegalArgumentException {
   AmazonS3 s3 = PersistS3.getClient();
   if (!s3.doesBucketExist(input))
     throw new IllegalArgumentException("S3 Bucket " + input + " not found!");
   return input;
 }
コード例 #2
0
  private static void createResources() {
    ClasspathPropertiesFileCredentialsProvider provider =
        new ClasspathPropertiesFileCredentialsProvider();

    AmazonSQS sqs = new AmazonSQSClient(provider);
    sqs.setEndpoint(SQS_ENDPOINT);
    sqs.createQueue(new CreateQueueRequest().withQueueName(SQS_QUEUE));

    AmazonS3 s3 = new AmazonS3Client(provider);
    if (!s3.doesBucketExist(BUCKET_NAME)) {
      s3.createBucket(new CreateBucketRequest(BUCKET_NAME));
    }

    AmazonDynamoDBClient dynamo = new AmazonDynamoDBClient(provider);
    dynamo.setEndpoint(DYNAMO_ENDPOINT);

    if (!doesTableExist(dynamo, DYNAMO_TABLE_NAME)) {
      dynamo.createTable(
          new CreateTableRequest()
              .withTableName(DYNAMO_TABLE_NAME)
              .withProvisionedThroughput(
                  new ProvisionedThroughput()
                      .withReadCapacityUnits(50l)
                      .withWriteCapacityUnits(50l))
              .withKeySchema(
                  new KeySchema()
                      .withHashKeyElement(
                          new KeySchemaElement()
                              .withAttributeName("id")
                              .withAttributeType(ScalarAttributeType.S))));
      waitForTableToBecomeAvailable(dynamo, DYNAMO_TABLE_NAME);
    }
  }
コード例 #3
0
ファイル: AwsBucketTest.java プロジェクト: jcabi/jcabi-s3
 /**
  * AwsBucket can throw a proper exception.
  *
  * @throws IOException If succeeds
  */
 @Test(expected = IOException.class)
 public void existsThrowsIOException() throws IOException {
   final Region region = Mockito.mock(Region.class);
   final AmazonS3 aws = Mockito.mock(AmazonS3.class);
   Mockito.when(region.aws()).thenReturn(aws);
   final String name = "throwing.bucket.com";
   Mockito.when(aws.doesBucketExist(name)).thenThrow(new AmazonServiceException("Test exception"));
   final Bucket bucket = new AwsBucket(region, name);
   bucket.exists();
 }
コード例 #4
0
ファイル: AwsBucketTest.java プロジェクト: jcabi/jcabi-s3
 /**
  * AwsBucket can correctly check the existence of the non-existing bucket.
  *
  * @throws IOException If fails
  */
 @Test
 public void existsNonExistingBucket() throws IOException {
   final Region region = Mockito.mock(Region.class);
   final AmazonS3 aws = Mockito.mock(AmazonS3.class);
   Mockito.when(region.aws()).thenReturn(aws);
   final String name = "non.existing.bucket.com";
   Mockito.when(aws.doesBucketExist(name)).thenReturn(false);
   final Bucket bucket = new AwsBucket(region, name);
   Assert.assertFalse(bucket.exists());
 }
コード例 #5
0
ファイル: S3Storage.java プロジェクト: carriercomm/cosbench
  @Override
  public void createContainer(String container, Config config) {
    super.createContainer(container, config);
    try {
      if (!client.doesBucketExist(container)) {

        client.createBucket(container);
      }
    } catch (Exception e) {
      throw new StorageException(e);
    }
  }
コード例 #6
0
ファイル: S3Storage.java プロジェクト: carriercomm/cosbench
 @Override
 public void deleteContainer(String container, Config config) {
   super.deleteContainer(container, config);
   try {
     if (client.doesBucketExist(container)) {
       client.deleteBucket(container);
     }
   } catch (AmazonS3Exception awse) {
     if (awse.getStatusCode() != HttpStatus.SC_NOT_FOUND) {
       throw new StorageException(awse);
     }
   } catch (Exception e) {
     throw new StorageException(e);
   }
 }
コード例 #7
0
  @Inject
  public AmazonS3Storage(Configuration configuration) {
    bucketName = configuration.getString("storage.s3.bucket");

    String accessKey = configuration.getString("storage.s3.accesskey");
    String secretKey = configuration.getString("storage.s3.secretkey");
    credentials = new BasicAWSCredentials(accessKey, secretKey);

    AmazonS3 amazonS3 = new AmazonS3Client(credentials);

    try {
      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) {
      Logger.error(
          "Caught an AmazonServiceException, which "
              + "means your request made it "
              + "to Amazon S3, but was rejected with an error response "
              + "for some reason."
              + " Error Message: "
              + ase.getMessage()
              + " HTTP Status Code: "
              + ase.getStatusCode()
              + " AWS Error Code: "
              + ase.getErrorCode()
              + " Error Type: "
              + ase.getErrorType()
              + " Request ID: "
              + ase.getRequestId());
    } catch (AmazonClientException ace) {
      Logger.error(
          "Caught an AmazonClientException, which "
              + "means the client encountered "
              + "an internal error while trying to "
              + "communicate with S3, "
              + "such as not being able to access the network."
              + " Error Message: "
              + ace.getMessage());
    }
  }