类com.amazonaws.services.dynamodbv2.model.ProvisionedThroughputDescription源码实例Demo

下面列出了怎么用com.amazonaws.services.dynamodbv2.model.ProvisionedThroughputDescription的API类实例代码及写法,或者点击链接到github查看源代码。

@Before
public void setup() {
  when(dynamoDBClient.describeTable(TABLE_NAME)).thenReturn(new TableDescription()
      .withBillingModeSummary(
          new BillingModeSummary().withBillingMode(DynamoDBConstants.BILLING_MODE_PROVISIONED))
      .withProvisionedThroughput(
          new ProvisionedThroughputDescription().withWriteCapacityUnits(WRITE_CAPACITY_UNITS)));

  JobConf jobConf = new JobConf();
  jobConf.setNumMapTasks(TOTAL_MAP_TASKS);
  jobConf.set("mapreduce.task.attempt.id", "attempt_m_1");
  jobConf.set(DynamoDBConstants.THROUGHPUT_WRITE_PERCENT, String.valueOf
      (THROUGHPUT_WRITE_PERCENT));
  when(jobClient.getConf()).thenReturn(jobConf);

  writeIopsCalculator = new WriteIopsCalculator(jobClient, dynamoDBClient, TABLE_NAME) {
    @Override
    int calculateMaxMapTasks(int totalMapTasks) {
      return MAX_CONCURRENT_MAP_TASKS;
    }
  };
}
 
private TableDescription getTableDescription(String hashType, String rangeType) {
  List<KeySchemaElement> keySchema = new ArrayList<>();
  List<AttributeDefinition> definitions = new ArrayList<>();

  keySchema.add(new KeySchemaElement().withAttributeName("hashKey").withKeyType(KeyType.HASH));
  definitions.add(new AttributeDefinition().withAttributeName("hashKey").withAttributeType
      (hashType));

  if (rangeType != null) {
    keySchema.add(new KeySchemaElement().withAttributeName("rangeKey").withKeyType(KeyType
        .RANGE));
    definitions.add(new AttributeDefinition().withAttributeName("rangeKey").withAttributeType
        (rangeType));
  }

  TableDescription description = new TableDescription().withKeySchema(keySchema)
      .withAttributeDefinitions(definitions).withProvisionedThroughput(new
          ProvisionedThroughputDescription().withReadCapacityUnits(1000L)
          .withWriteCapacityUnits(1000L));
  return description;
}
 
/**
 * returns the approximate number of segments a table should be broken up
 * when parallel scanning. This function is based off of either read and
 * write capacity, with which you can scan much faster, or the size of your
 * table, which should need many more segments in order to scan the table
 * fast enough in parallel so that one worker does not finish long before
 * other workers.
 * 
 * @throws NullReadCapacityException
 *             if the table returns a null readCapacity units.
 */
public static int getNumberOfSegments(TableDescription description)
        throws NullReadCapacityException {
    ProvisionedThroughputDescription provisionedThroughput = description
            .getProvisionedThroughput();
    double tableSizeInGigabytes = Math.ceil(description.getTableSizeBytes()
            / BootstrapConstants.GIGABYTE);
    Long readCapacity = provisionedThroughput.getReadCapacityUnits();
    Long writeCapacity = provisionedThroughput.getWriteCapacityUnits();
    if (writeCapacity == null) {
        writeCapacity = 1L;
    }
    if (readCapacity == null) {
        throw new NullReadCapacityException(
                "Cannot scan with a null readCapacity provisioned throughput");
    }
    double throughput = (readCapacity + 3 * writeCapacity) / 3000.0;
    return (int) (10 * Math.max(Math.ceil(throughput),
            Math.ceil(tableSizeInGigabytes) / 10));
}
 
private double getThroughput() {
  TableDescription tableDescription = dynamoDBClient.describeTable(tableName);
  if (tableDescription.getBillingModeSummary() == null || tableDescription.getBillingModeSummary()
      .getBillingMode().equalsIgnoreCase(DynamoDBConstants.BILLING_MODE_PROVISIONED)) {
    ProvisionedThroughputDescription provisionedThroughput =
        tableDescription.getProvisionedThroughput();
    return provisionedThroughput.getWriteCapacityUnits();
  }
  return DynamoDBConstants.DEFAULT_CAPACITY_FOR_ON_DEMAND;
}
 
private double getThroughput() {
  TableDescription tableDescription = dynamoDBClient.describeTable(tableName);
  if (tableDescription.getBillingModeSummary() == null ||
      tableDescription.getBillingModeSummary().getBillingMode()
          .equalsIgnoreCase(DynamoDBConstants.BILLING_MODE_PROVISIONED)) {
    ProvisionedThroughputDescription provisionedThroughput = tableDescription
        .getProvisionedThroughput();
    return provisionedThroughput.getReadCapacityUnits();
  }
  return DynamoDBConstants.DEFAULT_CAPACITY_FOR_ON_DEMAND;
}
 
@Before
public void setup() {
  when(dynamoDBClient.describeTable(TABLE_NAME)).thenReturn(new TableDescription()
      .withBillingModeSummary(
          new BillingModeSummary().withBillingMode(DynamoDBConstants.BILLING_MODE_PROVISIONED))
      .withProvisionedThroughput(
          new ProvisionedThroughputDescription().withReadCapacityUnits(READ_CAPACITY_UNITS)));

  JobConf jobConf = new JobConf();
  jobConf.set(DynamoDBConstants.THROUGHPUT_READ_PERCENT, String.valueOf(THROUGHPUT_READ_PERCENT));
  when(jobClient.getConf()).thenReturn(jobConf);

  readIopsCalculator = new ReadIopsCalculator(jobClient, dynamoDBClient, TABLE_NAME,
      TOTAL_SEGMETNS, LOCAL_SEGMENTS);
}
 
源代码7 项目: aws-doc-sdk-examples   文件: DescribeTable.java
public static void main(String[] args)
{
    final String USAGE = "\n" +
        "Usage:\n" +
        "    DescribeTable <table>\n\n" +
        "Where:\n" +
        "    table - the table to get information about.\n\n" +
        "Example:\n" +
        "    DescribeTable HelloTable\n";

    if (args.length < 1) {
        System.out.println(USAGE);
        System.exit(1);
    }

    String table_name = args[0];
    System.out.format("Getting description for %s\n\n", table_name);

    final AmazonDynamoDB ddb = AmazonDynamoDBClientBuilder.defaultClient();

    try {
        TableDescription table_info =
           ddb.describeTable(table_name).getTable();

        if (table_info != null) {
            System.out.format("Table name  : %s\n",
                  table_info.getTableName());
            System.out.format("Table ARN   : %s\n",
                  table_info.getTableArn());
            System.out.format("Status      : %s\n",
                  table_info.getTableStatus());
            System.out.format("Item count  : %d\n",
                  table_info.getItemCount().longValue());
            System.out.format("Size (bytes): %d\n",
                  table_info.getTableSizeBytes().longValue());

            ProvisionedThroughputDescription throughput_info =
               table_info.getProvisionedThroughput();
            System.out.println("Throughput");
            System.out.format("  Read Capacity : %d\n",
                  throughput_info.getReadCapacityUnits().longValue());
            System.out.format("  Write Capacity: %d\n",
                  throughput_info.getWriteCapacityUnits().longValue());

            List<AttributeDefinition> attributes =
               table_info.getAttributeDefinitions();
            System.out.println("Attributes");
            for (AttributeDefinition a : attributes) {
                System.out.format("  %s (%s)\n",
                      a.getAttributeName(), a.getAttributeType());
            }
        }
    } catch (AmazonServiceException e) {
        System.err.println(e.getErrorMessage());
        System.exit(1);
    }
    System.out.println("\nDone!");
}
 
 类方法
 同包方法