Search in sources :

Example 1 with ListDomainsResult

use of com.amazonaws.services.simpledb.model.ListDomainsResult in project camel by apache.

the class AmazonSDBClientMock method listDomains.

@Override
public ListDomainsResult listDomains(ListDomainsRequest listDomainsRequest) throws AmazonServiceException, AmazonClientException {
    this.listDomainsRequest = listDomainsRequest;
    ListDomainsResult result = new ListDomainsResult();
    result.getDomainNames().add("DOMAIN1");
    result.getDomainNames().add("DOMAIN2");
    result.setNextToken("TOKEN2");
    return result;
}
Also used : ListDomainsResult(com.amazonaws.services.simpledb.model.ListDomainsResult)

Example 2 with ListDomainsResult

use of com.amazonaws.services.simpledb.model.ListDomainsResult in project simplejpa by appoxy.

the class EntityManagerFactoryImpl method loadDomains.

private synchronized void loadDomains() {
    if (domainSet != null)
        return;
    try {
        domainSet = new HashSet<String>();
        logger.info("getting all domains");
        AmazonSimpleDB db = getSimpleDb();
        ListDomainsResult listDomainsResult = db.listDomains();
        domainSet.addAll(listDomainsResult.getDomainNames());
        while (listDomainsResult.getNextToken() != null) {
            ListDomainsRequest request = new ListDomainsRequest().withNextToken(listDomainsResult.getNextToken());
            listDomainsResult = db.listDomains(request);
            domainSet.addAll(listDomainsResult.getDomainNames());
        }
    } catch (AmazonClientException e) {
        throw new PersistenceException(e);
    }
}
Also used : ListDomainsResult(com.amazonaws.services.simpledb.model.ListDomainsResult) ListDomainsRequest(com.amazonaws.services.simpledb.model.ListDomainsRequest) AmazonSimpleDB(com.amazonaws.services.simpledb.AmazonSimpleDB) AmazonClientException(com.amazonaws.AmazonClientException) PersistenceException(javax.persistence.PersistenceException)

Example 3 with ListDomainsResult

use of com.amazonaws.services.simpledb.model.ListDomainsResult 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)

Example 4 with ListDomainsResult

use of com.amazonaws.services.simpledb.model.ListDomainsResult in project camel by apache.

the class ListDomainsCommand method execute.

public void execute() {
    ListDomainsRequest request = new ListDomainsRequest().withMaxNumberOfDomains(determineMaxNumberOfDomains()).withNextToken(determineNextToken());
    log.trace("Sending request [{}] for exchange [{}]...", request, exchange);
    ListDomainsResult result = this.sdbClient.listDomains(request);
    log.trace("Received result [{}]", result);
    Message msg = getMessageForResponse(exchange);
    msg.setHeader(SdbConstants.NEXT_TOKEN, result.getNextToken());
    msg.setHeader(SdbConstants.DOMAIN_NAMES, result.getDomainNames());
}
Also used : ListDomainsResult(com.amazonaws.services.simpledb.model.ListDomainsResult) Message(org.apache.camel.Message) ListDomainsRequest(com.amazonaws.services.simpledb.model.ListDomainsRequest)

Example 5 with ListDomainsResult

use of com.amazonaws.services.simpledb.model.ListDomainsResult in project teiid by teiid.

the class SimpleDbAPIClassTest method getDomainsTest.

@Test
public void getDomainsTest() throws Exception {
    ListDomainsResult listDomainResult = Mockito.mock(ListDomainsResult.class);
    List<String> resultList = new ArrayList<String>();
    resultList.add("Test");
    resultList.add("Test1");
    when(client.listDomains()).thenReturn(listDomainResult);
    when(listDomainResult.getDomainNames()).thenReturn(resultList);
    assertEquals(resultList, simpleDbApi.getDomains());
}
Also used : ListDomainsResult(com.amazonaws.services.simpledb.model.ListDomainsResult) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

ListDomainsResult (com.amazonaws.services.simpledb.model.ListDomainsResult)6 AmazonClientException (com.amazonaws.AmazonClientException)3 ListDomainsRequest (com.amazonaws.services.simpledb.model.ListDomainsRequest)3 AmazonServiceException (com.amazonaws.AmazonServiceException)1 AvailabilityZone (com.amazonaws.services.ec2.model.AvailabilityZone)1 DescribeAvailabilityZonesResult (com.amazonaws.services.ec2.model.DescribeAvailabilityZonesResult)1 DescribeInstancesResult (com.amazonaws.services.ec2.model.DescribeInstancesResult)1 DescribeSecurityGroupsResult (com.amazonaws.services.ec2.model.DescribeSecurityGroupsResult)1 Instance (com.amazonaws.services.ec2.model.Instance)1 Reservation (com.amazonaws.services.ec2.model.Reservation)1 SecurityGroup (com.amazonaws.services.ec2.model.SecurityGroup)1 Bucket (com.amazonaws.services.s3.model.Bucket)1 ObjectListing (com.amazonaws.services.s3.model.ObjectListing)1 S3ObjectSummary (com.amazonaws.services.s3.model.S3ObjectSummary)1 AmazonSimpleDB (com.amazonaws.services.simpledb.AmazonSimpleDB)1 CreateDomainRequest (com.amazonaws.services.simpledb.model.CreateDomainRequest)1 DomainMetadataRequest (com.amazonaws.services.simpledb.model.DomainMetadataRequest)1 DomainMetadataResult (com.amazonaws.services.simpledb.model.DomainMetadataResult)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1