public void execute() { DomainMetadataRequest request = new DomainMetadataRequest() .withDomainName(determineDomainName()); log.trace("Sending request [{}] for exchange [{}]...", request, exchange); DomainMetadataResult result = this.sdbClient.domainMetadata(request); log.trace("Received result [{}]", result); Message msg = getMessageForResponse(exchange); msg.setHeader(SdbConstants.TIMESTAMP, result.getTimestamp()); msg.setHeader(SdbConstants.ITEM_COUNT, result.getItemCount()); msg.setHeader(SdbConstants.ATTRIBUTE_NAME_COUNT, result.getAttributeNameCount()); msg.setHeader(SdbConstants.ATTRIBUTE_VALUE_COUNT, result.getAttributeValueCount()); msg.setHeader(SdbConstants.ATTRIBUTE_NAME_SIZE, result.getAttributeNamesSizeBytes()); msg.setHeader(SdbConstants.ATTRIBUTE_VALUE_SIZE, result.getAttributeValuesSizeBytes()); msg.setHeader(SdbConstants.ITEM_NAME_SIZE, result.getItemNamesSizeBytes()); }
@Override public DomainMetadataResult domainMetadata(DomainMetadataRequest domainMetadataRequest) throws AmazonServiceException, AmazonClientException { this.domainMetadataRequest = domainMetadataRequest; if ("NonExistingDomain".equals(domainMetadataRequest.getDomainName())) { throw new NoSuchDomainException("Domain 'NonExistingDomain' doesn't exist."); } DomainMetadataResult result = new DomainMetadataResult(); result.setTimestamp(new Integer(10)); result.setItemCount(new Integer(11)); result.setAttributeNameCount(new Integer(12)); result.setAttributeValueCount(new Integer(13)); result.setAttributeNamesSizeBytes(new Long(1000000)); result.setAttributeValuesSizeBytes(new Long(2000000)); result.setItemNamesSizeBytes(new Long(3000000)); return result; }
@Test @Ignore public void getAttributeNamesEmptyStringTest() throws Exception { DomainMetadataResult metadataResult = mock(DomainMetadataResult.class); SelectResult result = mock(SelectResult.class); // List itemsList = mock(ArrayList.class); // Iterator iterator = mock(Iterator.class); // Attribute // when(itemsList.iterator()).thenReturn(iterator); when(metadataResult.getAttributeNameCount()).thenReturn(3); when(client.select(any(SelectRequest.class))).thenReturn(result); // when(client.domainMetadata(any(DomainMetadataRequest.class))).thenReturn(metadataResult); System.out.println(simpleDbApi.getAttributeNames(null)); }
public static void simpleDB_demo(){ System.out.println("- - - - - - - - - - - - - - - - - - - - - -"); System.out.println("SimpleDB DEMO"); /* * 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("Response Status Code: " + ase.getStatusCode()); System.out.println("Error Code: " + ase.getErrorCode()); System.out.println("Request ID: " + ase.getRequestId()); } }
/** * Collect data for SimpleDB. * * @param stats * current statistics object. * @param account * currently used credentials object. * @param region * currently used aws region. */ public static void scanSimpleDB(AwsStats stats, AwsAccount account, Regions region) { if (region == Regions.EU_CENTRAL_1) return; LOG.debug("Scan for SimpleDB in region " + region.getName() + " in account " + account.getAccountId()); /* * 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 { AmazonSimpleDB simpleDB = new AmazonSimpleDBClient(account.getCredentials()); simpleDB.setRegion(Region.getRegion(region)); ListDomainsRequest sdbRequest = new ListDomainsRequest().withMaxNumberOfDomains(100); ListDomainsResult sdbResult = simpleDB.listDomains(sdbRequest); int totalItems = 0; for (String domainName : sdbResult.getDomainNames()) { DomainMetadataRequest metadataRequest = new DomainMetadataRequest().withDomainName(domainName); DomainMetadataResult domainMetadata = simpleDB.domainMetadata(metadataRequest); int items = domainMetadata.getItemCount(); totalItems += items; AwsResource res = new AwsResource(domainName, account.getAccountId(), AwsResourceType.SimpleDB, region); res.addInfo(AwsTag.Items, items); stats.add(res); } LOG.info(sdbResult.getDomainNames().size() + " SimpleDB domains containing a total of " + totalItems + " items in region " + region.getName() + " in account " + account.getAccountId()); } catch (AmazonServiceException ase) { LOG.error("Exception of SimpleDB: " + ase.getMessage()); } catch (Exception ex) { LOG.error("Exception of SimpleDB: " + ex.getMessage()); } }