Example usage for com.amazonaws.services.simpledb.model ListDomainsResult getDomainNames

List of usage examples for com.amazonaws.services.simpledb.model ListDomainsResult getDomainNames

Introduction

In this page you can find the example usage for com.amazonaws.services.simpledb.model ListDomainsResult getDomainNames.

Prototype


public java.util.List<String> getDomainNames() 

Source Link

Document

A list of domain names that match the expression.

Usage

From source file:AwsConsoleApp.java

License:Open Source License

public static void main(String[] args) throws Exception {

    System.out.println("===========================================");
    System.out.println("Welcome to the AWS Java SDK!");
    System.out.println("===========================================");

    init();// w ww .  j a  va  2  s  .  co  m

    /*
     * Amazon EC2
     *
     * The AWS EC2 client allows you to create, delete, and administer
     * instances programmatically.
     *
     * In this sample, we use an EC2 client to get a list of all the
     * availability zones, and all instances sorted by reservation id.
     */
    try {
        DescribeAvailabilityZonesResult availabilityZonesResult = ec2.describeAvailabilityZones();
        System.out.println("You have access to " + availabilityZonesResult.getAvailabilityZones().size()
                + " Availability Zones.");

        DescribeInstancesResult describeInstancesRequest = ec2.describeInstances();
        List<Reservation> reservations = describeInstancesRequest.getReservations();
        Set<Instance> instances = new HashSet<Instance>();

        for (Reservation reservation : reservations) {
            instances.addAll(reservation.getInstances());
        }

        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
     *
     * The AWS SimpleDB client allows you to query and manage your data
     * stored in SimpleDB domains (similar to tables in a relational DB).
     *
     * In this sample, we use a SimpleDB client to iterate over all the
     * domains owned by the current user, and add up the number of items
     * (similar to rows of data in a relational DB) in each domain.
     */
    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
     *
     * The AWS S3 client allows you to manage buckets and programmatically
     * put and get objects to those buckets.
     *
     * In this sample, we use an S3 client to iterate over all the buckets
     * owned by the current user, and all the object metadata in each
     * bucket, to obtain a total object and space usage count. This is done
     * without ever actually downloading a single object -- the requests
     * work with object metadata only.
     */
    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());
    }
}

From source file:aws.sample.AwsConsoleApp.java

License:Open Source License

public static void main(String[] args) throws Exception {

    System.out.println("===========================================");
    System.out.println("Welcome to the AWS Java SDK!");
    System.out.println("===========================================");

    init();/*from w w  w .  j  a  va  2 s  . c  o m*/

    /*
     * Amazon EC2
     * 
     * The AWS EC2 client allows you to create, delete, and administer instances programmatically.
     * 
     * In this sample, we use an EC2 client to get a list of all the availability zones, and all instances sorted by reservation id.
     */
    try {
        DescribeAvailabilityZonesResult availabilityZonesResult = ec2.describeAvailabilityZones();
        System.out.println("You have access to " + availabilityZonesResult.getAvailabilityZones().size()
                + " Availability Zones.");

        DescribeInstancesResult describeInstancesRequest = ec2.describeInstances();
        List<Reservation> reservations = describeInstancesRequest.getReservations();
        Set<Instance> instances = new HashSet<Instance>();

        for (Reservation reservation : reservations) {
            instances.addAll(reservation.getInstances());
        }

        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
     * 
     * The AWS SimpleDB client allows you to query and manage your data stored in SimpleDB domains (similar to tables in a relational DB).
     * 
     * In this sample, we use a SimpleDB client to iterate over all the domains owned by the current user, and add up the number of items (similar to rows of data in a relational DB) in each domain.
     */
    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
     * 
     * The AWS S3 client allows you to manage buckets and programmatically put and get objects to those buckets.
     * 
     * In this sample, we use an S3 client to iterate over all the buckets owned by the current user, and all the object metadata in each bucket, to obtain a total object and space usage count. This is done without ever actually downloading a single object -- the requests work with object metadata only.
     */
    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());
    }
}

From source file:com.amazon.aws.demo.anonymous.sdb.SimpleDB.java

License:Open Source License

private static List<String> getDomainNames(int numDomains, String nextToken) {
    ListDomainsRequest req = new ListDomainsRequest();
    req.setMaxNumberOfDomains(numDomains);
    if (nextToken != null)
        req.setNextToken(nextToken);/*from  w ww .  j a  v a 2s  . c o m*/
    ListDomainsResult result = getInstance().listDomains(req);
    List domains = result.getDomainNames();
    SimpleDB.nextToken = result.getNextToken();
    return domains;
}

From source file:com.amazon.SimpleDB.java

License:Open Source License

private static List<String> getDomainNames(int numDomains, String nextToken) {
    ListDomainsRequest req = new ListDomainsRequest();
    req.setMaxNumberOfDomains(numDomains);
    if (nextToken != null)
        req.setNextToken(nextToken);//from   w  w w.  j  a v a2  s . c o m
    ListDomainsResult result = getInstance().listDomains(req);
    List<String> domains = result.getDomainNames();
    SimpleDB.nextToken = result.getNextToken();
    return domains;
}

From source file:com.brighttag.agathon.dao.sdb.SdbDaoModule.java

License:Apache License

@Provides
@Named(RINGS_PROPERTY)//ww  w. ja  va2s .c  o m
Set<String> provideRings(AmazonSimpleDBClient client, CassandraDomainFactory domainFactory) {
    List<String> rings = Lists.newArrayList();
    String nextToken = null;

    do {
        ListDomainsRequest request = new ListDomainsRequest().withNextToken(nextToken);
        ListDomainsResult result = client.listDomains(request);
        for (String domain : result.getDomainNames()) {
            CassandraDomain cassandraDomain = domainFactory.createFromDomain(domain);
            if (cassandraDomain != null) {
                rings.add(cassandraDomain.getRing());
            }
        }
        nextToken = result.getNextToken();
    } while (nextToken != null);
    return ImmutableSet.copyOf(rings);
}

From source file:com.kikini.logging.simpledb.SimpleDBAppender.java

License:Apache License

/**
 * Obtain a SimpleDB instance from the Factory and get the logging domain
 * //from  w w w  .j a v a  2  s.com
 * @see ch.qos.logback.core.AppenderBase#start()
 */
@Override
public void start() {
    boolean requiredPropsSet = true;

    if (null == accessId) {
        addStatus(new ErrorStatus("Access ID not set", this));
        requiredPropsSet = false;
    }
    if (null == secretKey) {
        addStatus(new ErrorStatus("Secret key not set", this));
        requiredPropsSet = false;
    }
    if (null == domainName) {
        addStatus(new ErrorStatus("Domain name not set", this));
        requiredPropsSet = false;
    }
    if (null == endPoint) {
        addStatus(new ErrorStatus("EndPoint not set", this));
        requiredPropsSet = false;
    }
    if (!requiredPropsSet)
        return;

    if (sdb == null) {
        try {
            if (instanceRole != null && !instanceRole.equals("")) {
                //Use instance profile credentials
                sdb = new AmazonSimpleDBClient();
            } else {
                final AWSCredentials credentials = new BasicAWSCredentials(accessId, secretKey);
                sdb = new AmazonSimpleDBClient(credentials);
            }
            sdb.setEndpoint(this.endPoint);

            // See if the domain exists
            boolean found = false;
            ListDomainsResult result = sdb.listDomains();
            for (String dom : result.getDomainNames()) {
                if (dom.equals(domainName)) {
                    found = true;
                    break;
                }
            }
            // Didn't find it, so create it
            if (!found) {
                sdb.createDomain(new CreateDomainRequest(domainName));
            }
        } catch (AmazonClientException e) {
            addStatus(new ErrorStatus("Could not get access SimpleDB", this, e));
            return;
        }
    }

    if (queue == null) {
        this.queue = new DelayQueue<SimpleDBRow>();
    }

    if (writer == null) {
        this.writer = new SimpleDBWriter(sdb, domainName);
    }

    if (timeZone != null) {
        writer.setTimeZone(DateTimeZone.forID(timeZone));
    }

    if (consumer == null) {
        consumer = new SimpleDBConsumer(queue, writer);
    }

    Thread consumerThread = new Thread(consumer);
    Runnable shutdown = new SimpleDBShutdownHook(queue, writer, consumerThread);
    Runtime.getRuntime().addShutdownHook(new Thread(shutdown));
    consumerThread.setDaemon(true);
    consumerThread.start();
    super.start();
}

From source file:com.netflix.simianarmy.aws.SimpleDBRecorder.java

License:Apache License

/**
 * Creates the SimpleDB domain, if it does not already exist.
 */// ww  w. ja  v  a 2 s .c om
public void init() {
    try {
        if (this.region == null || this.region.equals("region-null")) {
            // This is a mock with an invalid region; avoid a slow timeout
            LOGGER.debug("Region=null; skipping SimpleDB domain creation");
            return;
        }
        ListDomainsResult listDomains = sdbClient().listDomains();
        for (String d : listDomains.getDomainNames()) {
            if (d.equals(domain)) {
                LOGGER.debug("SimpleDB domain found: {}", domain);
                return;
            }
        }
        LOGGER.info("Creating SimpleDB domain: {}", domain);
        CreateDomainRequest createDomainRequest = new CreateDomainRequest(domain);
        sdbClient().createDomain(createDomainRequest);
    } catch (AmazonClientException e) {
        LOGGER.warn("Error while trying to auto-create SimpleDB domain", e);
    }
}

From source file:com.threepillar.labs.quartz.simpledb.SimpleDbJobStore.java

License:Apache License

private List<String> getSimpleDbDomainNames() {

    ListDomainsResult result = amazonSimpleDb.listDomains();
    List<String> names = result.getDomainNames();
    String nextToken = result.getNextToken();
    while (nextToken != null && !nextToken.isEmpty()) {
        result = amazonSimpleDb.listDomains(new ListDomainsRequest().withNextToken(nextToken));
        names.addAll(result.getDomainNames());
        nextToken = result.getNextToken();
    }/*from  www .  ja va  2s.  co m*/
    return names;
}

From source file:com.zotoh.cloudapi.aws.SDB.java

License:Open Source License

@Override
public Iterable<String> list() throws CloudException, InternalException {
    List<String> rc = LT();
    ListDomainsRequest req;/*from   w  w w  .  j av  a2 s .c  o m*/
    ListDomainsResult res;
    List<String> lst;
    String token = null;
    do {
        req = new ListDomainsRequest().withMaxNumberOfDomains(100);
        if (!isEmpty(token)) {
            req.setNextToken(token);
        }
        res = _svc.getCloud().getSDB().listDomains(req);
        lst = res == null ? null : res.getDomainNames();
        if (lst != null) {
            rc.addAll(lst);
        }
        token = res.getNextToken();
    } while (!isEmpty(token));
    return rc;
}

From source file:edu.umass.cs.aws.support.examples.AWSStatusCheck.java

License:Apache License

/**
 *
 * @param args/*from w  w  w . j a  va2  s  .  com*/
 * @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());
        }
    }
}