Search in sources :

Example 6 with Bucket

use of com.talend.shaded.com.amazonaws.services.s3.model.Bucket in project sandbox by irof.

the class S3Test method setup.

@Before
public void setup() {
    // bucketがなかったら作る
    if (!s3.doesBucketExist("irof-sandbox")) {
        Bucket bucket = s3.createBucket("irof-sandbox");
        logger.info("create {}", bucket.getName());
    }
}
Also used : Bucket(com.amazonaws.services.s3.model.Bucket) Before(org.junit.Before)

Example 7 with Bucket

use of com.talend.shaded.com.amazonaws.services.s3.model.Bucket in project testcontainers-java by testcontainers.

the class SimpleLocalstackS3Test method s3Test.

@Test
public void s3Test() throws IOException {
    AmazonS3 s3 = AmazonS3ClientBuilder.standard().withEndpointConfiguration(localstack.getEndpointConfiguration(S3)).withCredentials(localstack.getDefaultCredentialsProvider()).build();
    s3.createBucket("foo");
    s3.putObject("foo", "bar", "baz");
    final List<Bucket> buckets = s3.listBuckets();
    assertEquals("The created bucket is present", 1, buckets.size());
    final Bucket bucket = buckets.get(0);
    assertEquals("The created bucket has the right name", "foo", bucket.getName());
    assertEquals("The created bucket has the right name", "foo", bucket.getName());
    final ObjectListing objectListing = s3.listObjects("foo");
    assertEquals("The created bucket has 1 item in it", 1, objectListing.getObjectSummaries().size());
    final S3Object object = s3.getObject("foo", "bar");
    final String content = IOUtils.toString(object.getObjectContent(), Charset.forName("UTF-8"));
    assertEquals("The object can be retrieved", "baz", content);
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3) Bucket(com.amazonaws.services.s3.model.Bucket) ObjectListing(com.amazonaws.services.s3.model.ObjectListing) S3Object(com.amazonaws.services.s3.model.S3Object) Test(org.junit.Test)

Example 8 with Bucket

use of com.talend.shaded.com.amazonaws.services.s3.model.Bucket in project h2o-2 by h2oai.

the class TypeaheadFileRequest method serveS3.

protected JsonArray serveS3(String filter, int limit) {
    JsonArray array = new JsonArray();
    try {
        AmazonS3 s3 = PersistS3.getClient();
        filter = Strings.nullToEmpty(filter);
        for (Bucket b : s3.listBuckets()) {
            if (b.getName().startsWith(filter))
                array.add(new JsonPrimitive(b.getName()));
            if (array.size() == limit)
                break;
        }
    } catch (IllegalArgumentException xe) {
    }
    return array;
}
Also used : JsonArray(dontweave.gson.JsonArray) AmazonS3(com.amazonaws.services.s3.AmazonS3) Bucket(com.amazonaws.services.s3.model.Bucket) JsonPrimitive(dontweave.gson.JsonPrimitive)

Example 9 with Bucket

use of com.talend.shaded.com.amazonaws.services.s3.model.Bucket in project h2o-2 by h2oai.

the class TypeaheadS3BucketRequest method serve.

@Override
protected JsonArray serve(String filter, int limit) {
    JsonArray array = new JsonArray();
    try {
        AmazonS3 s3 = PersistS3.getClient();
        filter = Strings.nullToEmpty(filter);
        for (Bucket b : s3.listBuckets()) {
            if (b.getName().startsWith(filter))
                array.add(new JsonPrimitive(b.getName()));
            if (array.size() == limit)
                break;
        }
    } catch (IllegalArgumentException xe) {
    }
    return array;
}
Also used : JsonArray(dontweave.gson.JsonArray) AmazonS3(com.amazonaws.services.s3.AmazonS3) Bucket(com.amazonaws.services.s3.model.Bucket) JsonPrimitive(dontweave.gson.JsonPrimitive)

Example 10 with Bucket

use of com.talend.shaded.com.amazonaws.services.s3.model.Bucket in project GNS by MobilityFirst.

the class AWSStatusCheck method main.

/**
   *
   * @param args
   * @throws Exception
   */
public static void main(String[] args) throws Exception {
    init();
    /*
     * Amazon EC2
     */
    for (String endpoint : endpoints) {
        try {
            ec2.setEndpoint(endpoint);
            System.out.println("**** Endpoint: " + endpoint);
            DescribeAvailabilityZonesResult availabilityZonesResult = ec2.describeAvailabilityZones();
            System.out.println("You have access to " + availabilityZonesResult.getAvailabilityZones().size() + " Availability Zones.");
            for (AvailabilityZone zone : availabilityZonesResult.getAvailabilityZones()) {
                System.out.println(zone.getZoneName());
            }
            DescribeInstancesResult describeInstancesRequest = ec2.describeInstances();
            List<Reservation> reservations = describeInstancesRequest.getReservations();
            Set<Instance> instances = new HashSet<Instance>();
            System.out.println("Instances: ");
            for (Reservation reservation : reservations) {
                for (Instance instance : reservation.getInstances()) {
                    instances.add(instance);
                    System.out.println(instance.getPublicDnsName() + " is " + instance.getState().getName());
                }
            }
            System.out.println("Security groups: ");
            DescribeSecurityGroupsResult describeSecurityGroupsResult = ec2.describeSecurityGroups();
            for (SecurityGroup securityGroup : describeSecurityGroupsResult.getSecurityGroups()) {
                System.out.println(securityGroup.getGroupName());
            }
        //System.out.println("You have " + instances.size() + " Amazon EC2 instance(s) running.");
        } catch (AmazonServiceException ase) {
            System.out.println("Caught Exception: " + ase.getMessage());
            System.out.println("Reponse Status Code: " + ase.getStatusCode());
            System.out.println("Error Code: " + ase.getErrorCode());
            System.out.println("Request ID: " + ase.getRequestId());
        }
        /*
       * Amazon SimpleDB
       *
       */
        try {
            ListDomainsRequest sdbRequest = new ListDomainsRequest().withMaxNumberOfDomains(100);
            ListDomainsResult sdbResult = sdb.listDomains(sdbRequest);
            int totalItems = 0;
            for (String domainName : sdbResult.getDomainNames()) {
                DomainMetadataRequest metadataRequest = new DomainMetadataRequest().withDomainName(domainName);
                DomainMetadataResult domainMetadata = sdb.domainMetadata(metadataRequest);
                totalItems += domainMetadata.getItemCount();
            }
            System.out.println("You have " + sdbResult.getDomainNames().size() + " Amazon SimpleDB domain(s)" + "containing a total of " + totalItems + " items.");
        } catch (AmazonServiceException ase) {
            System.out.println("Caught Exception: " + ase.getMessage());
            System.out.println("Reponse Status Code: " + ase.getStatusCode());
            System.out.println("Error Code: " + ase.getErrorCode());
            System.out.println("Request ID: " + ase.getRequestId());
        }
        /*
       * Amazon S3
       *.
       */
        try {
            List<Bucket> buckets = s3.listBuckets();
            long totalSize = 0;
            int totalItems = 0;
            for (Bucket bucket : buckets) {
                /*
           * In order to save bandwidth, an S3 object listing does not
           * contain every object in the bucket; after a certain point the
           * S3ObjectListing is truncated, and further pages must be
           * obtained with the AmazonS3Client.listNextBatchOfObjects()
           * method.
           */
                ObjectListing objects = s3.listObjects(bucket.getName());
                do {
                    for (S3ObjectSummary objectSummary : objects.getObjectSummaries()) {
                        totalSize += objectSummary.getSize();
                        totalItems++;
                    }
                    objects = s3.listNextBatchOfObjects(objects);
                } while (objects.isTruncated());
            }
            System.out.println("You have " + buckets.size() + " Amazon S3 bucket(s), " + "containing " + totalItems + " objects with a total size of " + totalSize + " bytes.");
        } catch (AmazonServiceException ase) {
            /*
         * AmazonServiceExceptions represent an error response from an AWS
         * services, i.e. your request made it to AWS, but the AWS service
         * either found it invalid or encountered an error trying to execute
         * it.
         */
            System.out.println("Error Message:    " + ase.getMessage());
            System.out.println("HTTP Status Code: " + ase.getStatusCode());
            System.out.println("AWS Error Code:   " + ase.getErrorCode());
            System.out.println("Error Type:       " + ase.getErrorType());
            System.out.println("Request ID:       " + ase.getRequestId());
        } catch (AmazonClientException ace) {
            /*
         * AmazonClientExceptions represent an error that occurred inside
         * the client on the local host, either while trying to send the
         * request to AWS or interpret the response. For example, if no
         * network connection is available, the client won't be able to
         * connect to AWS to execute a request and will throw an
         * AmazonClientException.
         */
            System.out.println("Error Message: " + ace.getMessage());
        }
    }
}
Also used : ListDomainsResult(com.amazonaws.services.simpledb.model.ListDomainsResult) Instance(com.amazonaws.services.ec2.model.Instance) DomainMetadataResult(com.amazonaws.services.simpledb.model.DomainMetadataResult) AmazonClientException(com.amazonaws.AmazonClientException) AvailabilityZone(com.amazonaws.services.ec2.model.AvailabilityZone) ObjectListing(com.amazonaws.services.s3.model.ObjectListing) S3ObjectSummary(com.amazonaws.services.s3.model.S3ObjectSummary) DescribeAvailabilityZonesResult(com.amazonaws.services.ec2.model.DescribeAvailabilityZonesResult) SecurityGroup(com.amazonaws.services.ec2.model.SecurityGroup) DescribeInstancesResult(com.amazonaws.services.ec2.model.DescribeInstancesResult) DomainMetadataRequest(com.amazonaws.services.simpledb.model.DomainMetadataRequest) Reservation(com.amazonaws.services.ec2.model.Reservation) Bucket(com.amazonaws.services.s3.model.Bucket) ListDomainsRequest(com.amazonaws.services.simpledb.model.ListDomainsRequest) AmazonServiceException(com.amazonaws.AmazonServiceException) DescribeSecurityGroupsResult(com.amazonaws.services.ec2.model.DescribeSecurityGroupsResult) HashSet(java.util.HashSet)

Aggregations

Bucket (com.amazonaws.services.s3.model.Bucket)22 AmazonS3 (com.amazonaws.services.s3.AmazonS3)7 AmazonS3Exception (com.amazonaws.services.s3.model.AmazonS3Exception)4 HashSet (java.util.HashSet)4 Test (org.junit.Test)4 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)3 OperationContext (com.vmware.xenon.common.OperationContext)3 AmazonClientException (com.amazonaws.AmazonClientException)2 Regions (com.amazonaws.regions.Regions)2 BucketTaggingConfiguration (com.amazonaws.services.s3.model.BucketTaggingConfiguration)2 ObjectListing (com.amazonaws.services.s3.model.ObjectListing)2 S3Object (com.amazonaws.services.s3.model.S3Object)2 EnumerationAction (com.vmware.photon.controller.model.adapterapi.EnumerationAction)2 AWSConstants (com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants)2 AWSResourceType (com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AWSResourceType)2 AwsClientType (com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AwsClientType)2 BUCKET_OWNER_NAME (com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.BUCKET_OWNER_NAME)2 STORAGE_TYPE_S3 (com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.STORAGE_TYPE_S3)2 AWSConstants.getQueryResultLimit (com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.getQueryResultLimit)2 AWSUriPaths (com.vmware.photon.controller.model.adapters.awsadapter.AWSUriPaths)2