Java 类com.amazonaws.services.dynamodbv2.model.DescribeTableRequest 实例源码

项目:emr-dynamodb-connector    文件:DynamoDBClient.java   
public TableDescription describeTable(String tableName) {
  final DescribeTableRequest describeTablesRequest = new DescribeTableRequest()
      .withTableName(tableName);
  try {
    RetryResult<DescribeTableResult> describeResult = getRetryDriver().runWithRetry(
        new Callable<DescribeTableResult>() {
          @Override
          public DescribeTableResult call() {
            DescribeTableResult result = dynamoDB.describeTable(describeTablesRequest);
            log.info("Describe table output: " + result);
            return result;
          }
        }, null, null);
    return describeResult.result.getTable();
  } catch (Exception e) {
    throw new RuntimeException("Could not lookup table " + tableName + " in DynamoDB.", e);
  }
}
项目:Camel    文件:DescribeTableCommand.java   
@Override
public void execute() {
    DescribeTableResult result = ddbClient.describeTable(new DescribeTableRequest()
            .withTableName(determineTableName()));

    Message msg = getMessageForResponse(exchange);
    msg.setHeader(DdbConstants.TABLE_NAME, result.getTable().getTableName());
    msg.setHeader(DdbConstants.TABLE_STATUS, result.getTable().getTableStatus());
    msg.setHeader(DdbConstants.CREATION_DATE, result.getTable().getCreationDateTime());
    msg.setHeader(DdbConstants.ITEM_COUNT, result.getTable().getItemCount());
    msg.setHeader(DdbConstants.KEY_SCHEMA, result.getTable().getKeySchema());
    msg.setHeader(DdbConstants.READ_CAPACITY,
            result.getTable().getProvisionedThroughput().getReadCapacityUnits());
    msg.setHeader(DdbConstants.WRITE_CAPACITY,
            result.getTable().getProvisionedThroughput().getWriteCapacityUnits());
    msg.setHeader(DdbConstants.TABLE_SIZE, result.getTable().getTableSizeBytes());
}
项目:Camel    文件:AmazonDDBClientMock.java   
@Override
public DescribeTableResult describeTable(DescribeTableRequest describeTableRequest) {
    this.describeTableRequest = describeTableRequest;
    String tableName = describeTableRequest.getTableName();
    if ("activeTable".equals(tableName)) {
        return tableWithStatus(TableStatus.ACTIVE);
    } else if ("creatibleTable".equals(tableName) && createTableRequest != null) {
        return tableWithStatus(TableStatus.ACTIVE);
    } else if ("FULL_DESCRIBE_TABLE".equals(tableName)) {
        return new DescribeTableResult().withTable(new TableDescription()
                .withTableName(tableName)
                .withTableStatus(TableStatus.ACTIVE)
                .withCreationDateTime(new Date(NOW))
                .withItemCount(100L)
                .withKeySchema(new KeySchemaElement().withAttributeName("name"))
                .withProvisionedThroughput(new ProvisionedThroughputDescription()
                        .withReadCapacityUnits(20L)
                        .withWriteCapacityUnits(10L))
                .withTableSizeBytes(1000L));
    }
    throw new ResourceNotFoundException(tableName + " is missing");
}
项目:Tank    文件:AmazonDynamoDatabaseDocApi.java   
private void waitForStatus(String tableName, TableStatus status) {
    logger.info("Waiting for " + tableName + " to become " + status.toString() + "...");

    long startTime = System.currentTimeMillis();
    long endTime = startTime + (10 * 60 * 1000);
    while (System.currentTimeMillis() < endTime) {
        try {
            Thread.sleep(1000 * 2);
        } catch (Exception e) {
        }
        try {
            DescribeTableRequest request = new DescribeTableRequest().withTableName(tableName);
            TableDescription tableDescription = dynamoDb.describeTable(request).getTable();
            String tableStatus = tableDescription.getTableStatus();
            logger.debug("  - current state: " + tableStatus);
            if (tableStatus.equals(status.toString()))
                return;
        } catch (AmazonServiceException ase) {
            if (ase.getErrorCode().equalsIgnoreCase("ResourceNotFoundException") == false)
                throw ase;
        }
    }

    throw new RuntimeException("Table " + tableName + " never went " + status.toString());
}
项目:dynamodb-streams-kafka    文件:KafkaDynamoStreamAdapter.java   
private String enableStreamForTable(AmazonDynamoDBClient client, StreamViewType viewType, String tableName) {
    DescribeTableRequest describeTableRequest = new DescribeTableRequest()
        .withTableName(tableName);
    DescribeTableResult describeResult = client.describeTable(describeTableRequest);
    if (describeResult.getTable().getStreamSpecification().isStreamEnabled()) {
        //TODO: what if the viewtype doesn't match
        return describeResult.getTable().getLatestStreamId();
    }

    StreamSpecification streamSpecification = new StreamSpecification();
    streamSpecification.setStreamEnabled(true);
    streamSpecification.setStreamViewType(viewType);
    UpdateTableRequest updateTableRequest = new UpdateTableRequest()
        .withTableName(tableName)
        .withStreamSpecification(streamSpecification);

    UpdateTableResult result = client.updateTable(updateTableRequest);
    return result.getTableDescription().getLatestStreamId();
}
项目:dynamodb-streams-kafka    文件:StreamAdapterDemoHelper.java   
public static String enableStreamForTable(AmazonDynamoDBClient client, StreamViewType viewType, String tableName) {
    DescribeTableRequest describeTableRequest = new DescribeTableRequest()
        .withTableName(tableName);
    DescribeTableResult describeResult = client.describeTable(describeTableRequest);
    if (describeResult.getTable().getStreamSpecification().isStreamEnabled()) {
        //TODO: what if the viewtype doesn't match
        return describeResult.getTable().getLatestStreamId();
    }

    StreamSpecification streamSpecification = new StreamSpecification();
    streamSpecification.setStreamEnabled(true);
    streamSpecification.setStreamViewType(viewType);
    UpdateTableRequest updateTableRequest = new UpdateTableRequest()
        .withTableName(tableName)
        .withStreamSpecification(streamSpecification);

    UpdateTableResult result = client.updateTable(updateTableRequest);
    return result.getTableDescription().getLatestStreamId();
}
项目:dynamodb-online-index-violation-detector    文件:TableManager.java   
private void waitForTableToBecomeAvailable(String tableName) {
    System.out.println("Waiting for " + tableName + " to become ACTIVE...");
    long startTime = System.currentTimeMillis();
    long endTime = startTime + (10 * 60 * 1000);
    while (System.currentTimeMillis() < endTime) {
        DescribeTableRequest request = new DescribeTableRequest()
                .withTableName(tableName);
        TableDescription tableDescription = client.describeTable(
                request).getTable();
        String tableStatus = tableDescription.getTableStatus();
        System.out.println("  - current state: " + tableStatus);
        if (tableStatus.equals(TableStatus.ACTIVE.toString()))
            return;
        try { Thread.sleep(1000 * 20); } catch (Exception e) { }
    }
    throw new RuntimeException("Table " + tableName + " never went active");
}
项目:milton-aws    文件:DynamoDBServiceImpl.java   
private void waitForTableAvailable(String tableName) {
    LOG.info("Waiting for table " + tableName + " to become ACTIVE...");

    long startTime = System.currentTimeMillis();
    long endTime = startTime + (10 * 60 * 1000);
    while (System.currentTimeMillis() < endTime) {
        DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(tableName);
        TableDescription tableDescription = dynamoDBClient.describeTable(describeTableRequest).getTable();

        // Display current status of table
        String tableStatus = tableDescription.getTableStatus();
        LOG.info("Current state for table " + tableName + ": " + tableStatus);
        if (tableStatus.equals(TableStatus.ACTIVE.toString())) {
            return;
        }

        try {
            Thread.sleep(1000 * 20);
        } catch (Exception ex) {
            LOG.warn(ex.getMessage());
        }
    }

    throw new RuntimeException("Table " + tableName + " never went active");
}
项目:gora    文件:DynamoDBStore.java   
/**
 * Waits up to 6 minutes to confirm if a table has been deleted or not
 * 
 * @param pTableName
 */
private void waitForTableToBeDeleted(String pTableName) {
  LOG.debug("Waiting for " + pTableName + " to be deleted.");
  long startTime = System.currentTimeMillis();
  long endTime = startTime + WAIT_TIME;
  while (System.currentTimeMillis() < endTime) {
    try {
      Thread.sleep(SLEEP_DELETE_TIME);
    } catch (Exception e) {
    }
    try {
      DescribeTableRequest request = new DescribeTableRequest()
          .withTableName(pTableName);
      TableDescription tableDescription = getDynamoDBClient().describeTable(
          request).getTable();
      String tableStatus = tableDescription.getTableStatus();
      LOG.debug(pTableName + " - current state: " + tableStatus);
    } catch (AmazonServiceException ase) {
      if (ase.getErrorCode().equalsIgnoreCase("ResourceNotFoundException") == true)
        return;
      LOG.error(ase.getMessage());
    }
  }
  LOG.debug(pTableName + " deleted.");
}
项目:gora    文件:GoraDynamoDBTestDriver.java   
/**
 * Checks if a resource exists or not
 * 
 * @param tableName
 *          Table name to be checked
 * @return
 */
public TableDescription checkResource(String tableName){
  TableDescription tableDescription = null;

  try{
    DescribeTableRequest describeTableRequest = new DescribeTableRequest()
        .withTableName(tableName);
    tableDescription = dynamoDBClient.describeTable(describeTableRequest)
        .getTable();
  }
  catch(ResourceNotFoundException e){
    tableDescription = null;
  }

  return tableDescription;
}
项目:aws-dynamodb-examples    文件:LowLevelTableExample.java   
private static void waitForTableToBecomeAvailable(String tableName) {
    System.out.println("Waiting for " + tableName + " to become ACTIVE...");

    long startTime = System.currentTimeMillis();
    long endTime = startTime + (10 * 60 * 1000);
    while (System.currentTimeMillis() < endTime) {
        DescribeTableRequest request = new DescribeTableRequest()
                .withTableName(tableName);
        TableDescription tableDescription = client.describeTable(
                request).getTable();
        String tableStatus = tableDescription.getTableStatus();
        System.out.println("  - current state: " + tableStatus);
        if (tableStatus.equals(TableStatus.ACTIVE.toString()))
            return;
        try { Thread.sleep(1000 * 20); } catch (Exception e) { }
    }
    throw new RuntimeException("Table " + tableName + " never went active");
}
项目:aws-dynamodb-examples    文件:LowLevelLocalSecondaryIndexExample.java   
private static void waitForTableToBecomeAvailable(String tableName) {
    System.out.println("Waiting for " + tableName + " to become ACTIVE...");

    long startTime = System.currentTimeMillis();
    long endTime = startTime + (10 * 60 * 1000);
    while (System.currentTimeMillis() < endTime) {
        DescribeTableRequest request = new DescribeTableRequest()
                .withTableName(tableName);
        TableDescription tableDescription = client.describeTable(
                request).getTable();
        String tableStatus = tableDescription.getTableStatus();
        System.out.println("  - current state: " + tableStatus);
        if (tableStatus.equals(TableStatus.ACTIVE.toString()))
            return;
        try { Thread.sleep(1000 * 20); } catch (Exception e) { }
    }
    throw new RuntimeException("Table " + tableName + " never went active");
}
项目:aws-dynamodb-examples    文件:LowLevelGlobalSecondaryIndexExample.java   
private static void waitForTableToBecomeAvailable(String tableName) {
    System.out.println("Waiting for " + tableName + " to become ACTIVE...");

    long startTime = System.currentTimeMillis();
    long endTime = startTime + (10 * 60 * 1000);

    while (System.currentTimeMillis() < endTime) {
        DescribeTableRequest request = 
            new DescribeTableRequest().withTableName(tableName);
        TableDescription tableDescription = 
            client.describeTable(request).getTable();
        String tableStatus = tableDescription.getTableStatus();

        System.out.println("  - current state: " + tableStatus);

        if (tableStatus.equals(TableStatus.ACTIVE.toString()))
            return;
            try {
                Thread.sleep(1000 * 20);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    throw new RuntimeException("Table " + tableName + " never went active");
}
项目:aws-dynamodb-examples    文件:LowLevelParallelScan.java   
private static void waitForTableToBecomeAvailable(String tableName) {
    System.out.println("Waiting for " + tableName + " to become ACTIVE...");

    long startTime = System.currentTimeMillis();
    long endTime = startTime + (10 * 60 * 1000);
    while (System.currentTimeMillis() < endTime) {
        DescribeTableRequest request = new DescribeTableRequest()
                .withTableName(tableName);
        TableDescription tableDescription = client.describeTable(
                request).getTable();
        String tableStatus = tableDescription.getTableStatus();
        System.out.println("  - current state: " + tableStatus);
        if (tableStatus.equals(TableStatus.ACTIVE.toString()))
            return;
        try { Thread.sleep(1000 * 20); } catch (Exception e) { }
    }
    throw new RuntimeException("Table " + tableName + " never went active");
}
项目:reinvent2013-mobile-photo-share    文件:Utilities.java   
public void setupTable() {
    setupGeoDataManager();

    GeoDataManagerConfiguration config = geoDataManager.getGeoDataManagerConfiguration();
    DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(config.getTableName());

    try {
        config.getDynamoDBClient().describeTable(describeTableRequest);

        if (status == Status.NOT_STARTED) {
            status = Status.READY;
        }
    } catch (ResourceNotFoundException e) {
        PhotoLocationsTable photoLocationsTable = new PhotoLocationsTable();
        photoLocationsTable.start();
    }

}
项目:quartz-dynamodb    文件:DynamoDbJobStore.java   
private void waitForTable(String name) {
    log.info(String.format("Waiting for creation of table '%s' to complete.", name));
    long startTime = System.currentTimeMillis();
    long endTime = startTime + (10 * 60 * 1000);
    while (System.currentTimeMillis() < endTime) {
        sleep(1000 * 20);
        try {
            DescribeTableRequest request = new DescribeTableRequest().withTableName(name);
            TableDescription tableDescription = client.describeTable(request).getTable();
            String tableStatus = tableDescription.getTableStatus();
            log.info(String.format("Table '%s' is in state: '%s'.", name, tableStatus));
            if (tableStatus.equals(TableStatus.ACTIVE.toString())) {
                return;
            }
        } catch (ResourceNotFoundException e) {
            // nop - maybe the table isn't showing up yet.
        }
    }

    throw new RuntimeException(String.format("Table '%s' never went active.", name));
}
项目:jcabi-dynamo    文件:MadeTable.java   
/**
 * Create table.
 * @throws InterruptedException If something fails
 */
public void create() throws InterruptedException {
    final AmazonDynamoDB aws = this.region.aws();
    final String name = this.request.getTableName();
    aws.createTable(this.request);
    Logger.info(this, "DynamoDB table '%s' creation requested...", name);
    final DescribeTableRequest req = new DescribeTableRequest()
        .withTableName(name);
    while (true) {
        final DescribeTableResult result = aws.describeTable(req);
        if ("ACTIVE".equals(result.getTable().getTableStatus())) {
            Logger.info(
                this,
                "DynamoDB table '%s' is %s",
                name, result.getTable().getTableStatus()
            );
            break;
        }
        Logger.info(
            this,
            "waiting for DynamoDB table '%s': %s",
            name, result.getTable().getTableStatus()
        );
        TimeUnit.SECONDS.sleep((long) Tv.TEN);
    }
}
项目:aws-sdk-android-samples    文件:DynamoDBManager.java   
public static String getTestTableStatus() {

        try {
            AmazonDynamoDBClient ddb = UserPreferenceDemoActivity.clientManager
                    .ddb();

            DescribeTableRequest request = new DescribeTableRequest()
                    .withTableName(Constants.TEST_TABLE_NAME);
            DescribeTableResult result = ddb.describeTable(request);

            String status = result.getTable().getTableStatus();
            return status == null ? "" : status;

        } catch (ResourceNotFoundException e) {
        } catch (AmazonServiceException ex) {
            UserPreferenceDemoActivity.clientManager
                    .wipeCredentialsOnAuthError(ex);
        }

        return "";
    }
项目:dynamodb-geo    文件:Utilities.java   
public void setupTable() {
    setupGeoDataManager();

    GeoDataManagerConfiguration config = geoDataManager.getGeoDataManagerConfiguration();
    DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(config.getTableName());

    try {
        config.getDynamoDBClient().describeTable(describeTableRequest);

        if (status == Status.NOT_STARTED) {
            status = Status.READY;
        }
    } catch (ResourceNotFoundException e) {
        SchoolDataLoader schoolDataLoader = new SchoolDataLoader();
        schoolDataLoader.start();
    }

}
项目:cas-5.1.0    文件:DynamoDbTicketRegistryFacilitator.java   
/**
 * Create ticket tables.
 *
 * @param deleteTables the delete tables
 */
public void createTicketTables(final boolean deleteTables) {
    final Collection<TicketDefinition> metadata = this.ticketCatalog.findAll();
    metadata.forEach(Unchecked.consumer(r -> {
        final CreateTableRequest request = new CreateTableRequest()
                .withAttributeDefinitions(new AttributeDefinition(ColumnNames.ID.getName(), ScalarAttributeType.S))
                .withKeySchema(new KeySchemaElement(ColumnNames.ID.getName(), KeyType.HASH))
                .withProvisionedThroughput(new ProvisionedThroughput(dynamoDbProperties.getReadCapacity(),
                        dynamoDbProperties.getWriteCapacity()))
                .withTableName(r.getProperties().getStorageName());


        if (deleteTables) {
            final DeleteTableRequest delete = new DeleteTableRequest(r.getProperties().getStorageName());
            LOGGER.debug("Sending delete request [{}] to remove table if necessary", delete);
            TableUtils.deleteTableIfExists(amazonDynamoDBClient, delete);
        }
        LOGGER.debug("Sending delete request [{}] to create table", request);
        TableUtils.createTableIfNotExists(amazonDynamoDBClient, request);

        LOGGER.debug("Waiting until table [{}] becomes active...", request.getTableName());
        TableUtils.waitUntilActive(amazonDynamoDBClient, request.getTableName());

        final DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(request.getTableName());
        LOGGER.debug("Sending request [{}] to obtain table description...", describeTableRequest);

        final TableDescription tableDescription = amazonDynamoDBClient.describeTable(describeTableRequest).getTable();
        LOGGER.debug("Located newly created table with description: [{}]", tableDescription);
    }));
}
项目:cas-5.1.0    文件:DynamoDbServiceRegistryFacilitator.java   
/**
 * Create tables.
 *
 * @param deleteTables the delete tables
 */
public void createServicesTable(final boolean deleteTables) {
    try {
        final CreateTableRequest request = new CreateTableRequest()
                .withAttributeDefinitions(new AttributeDefinition(ColumnNames.ID.getName(), ScalarAttributeType.S))
                .withKeySchema(new KeySchemaElement(ColumnNames.ID.getName(), KeyType.HASH))
                .withProvisionedThroughput(new ProvisionedThroughput(dynamoDbProperties.getReadCapacity(),
                        dynamoDbProperties.getWriteCapacity()))
                .withTableName(TABLE_NAME);

        if (deleteTables) {
            final DeleteTableRequest delete = new DeleteTableRequest(request.getTableName());
            LOGGER.debug("Sending delete request [{}] to remove table if necessary", delete);
            TableUtils.deleteTableIfExists(amazonDynamoDBClient, delete);
        }
        LOGGER.debug("Sending delete request [{}] to create table", request);
        TableUtils.createTableIfNotExists(amazonDynamoDBClient, request);

        LOGGER.debug("Waiting until table [{}] becomes active...", request.getTableName());
        TableUtils.waitUntilActive(amazonDynamoDBClient, request.getTableName());

        final DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(request.getTableName());
        LOGGER.debug("Sending request [{}] to obtain table description...", describeTableRequest);

        final TableDescription tableDescription = amazonDynamoDBClient.describeTable(describeTableRequest).getTable();
        LOGGER.debug("Located newly created table with description: [{}]", tableDescription);
    } catch (final Exception e) {
        throw Throwables.propagate(e);
    }
}
项目:cas-5.1.0    文件:DynamoDbCloudConfigBootstrapConfiguration.java   
private static void createSettingsTable(final AmazonDynamoDBClient amazonDynamoDBClient, final boolean deleteTables) {
    try {
        final CreateTableRequest request = new CreateTableRequest()
                .withAttributeDefinitions(new AttributeDefinition(ColumnNames.ID.getName(), ScalarAttributeType.S))
                .withKeySchema(new KeySchemaElement(ColumnNames.ID.getName(), KeyType.HASH))
                .withProvisionedThroughput(new ProvisionedThroughput(PROVISIONED_THROUGHPUT, PROVISIONED_THROUGHPUT))
                .withTableName(TABLE_NAME);

        if (deleteTables) {
            final DeleteTableRequest delete = new DeleteTableRequest(request.getTableName());
            LOGGER.debug("Sending delete request [{}] to remove table if necessary", delete);
            TableUtils.deleteTableIfExists(amazonDynamoDBClient, delete);
        }
        LOGGER.debug("Sending delete request [{}] to create table", request);
        TableUtils.createTableIfNotExists(amazonDynamoDBClient, request);

        LOGGER.debug("Waiting until table [{}] becomes active...", request.getTableName());
        TableUtils.waitUntilActive(amazonDynamoDBClient, request.getTableName());

        final DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(request.getTableName());
        LOGGER.debug("Sending request [{}] to obtain table description...", describeTableRequest);

        final TableDescription tableDescription = amazonDynamoDBClient.describeTable(describeTableRequest).getTable();
        LOGGER.debug("Located newly created table with description: [{}]", tableDescription);
    } catch (final Exception e) {
        throw Throwables.propagate(e);
    }
}
项目:outland    文件:DynamoCreateGroupsTableTask.java   
private void createAppsTable(String tableName) {
  final AttributeDefinition appKey =
      new AttributeDefinition().withAttributeName(HASH_KEY).withAttributeType(
          ScalarAttributeType.S);

  final ArrayList<AttributeDefinition>
      tableAttributeDefinitions = Lists.newArrayList(appKey);

  final ArrayList<KeySchemaElement> tableKeySchema = Lists.newArrayList();
  tableKeySchema.add(
      new KeySchemaElement().withAttributeName(HASH_KEY).withKeyType(KeyType.HASH));

  final ProvisionedThroughput tableProvisionedThroughput =
      new ProvisionedThroughput()
          .withReadCapacityUnits(10L)
          .withWriteCapacityUnits(10L);

  final CreateTableRequest createTableRequest =
      new CreateTableRequest()
          .withTableName(tableName)
          .withKeySchema(tableKeySchema)
          .withAttributeDefinitions(tableAttributeDefinitions)
          .withProvisionedThroughput(tableProvisionedThroughput);

  final TableDescription tableDescription =
      amazonDynamoDB.createTable(createTableRequest).getTableDescription();

  logger.info("created_table {}", tableDescription);

  final DescribeTableRequest describeTableRequest =
      new DescribeTableRequest().withTableName(tableName);

  final TableDescription description =
      amazonDynamoDB.describeTable(describeTableRequest).getTable();

  logger.info("table_description: " + description);
}
项目:Camel    文件:DdbEndpoint.java   
private void waitForTableToBecomeAvailable(String tableName) {
    LOG.trace("Waiting for [{}] to become ACTIVE...", tableName);

    long waitTime = 5 * 60 * 1000;
    while (waitTime > 0) {
        try {
            Thread.sleep(1000 * 5);
            waitTime -= 5000;
        } catch (Exception e) {
        }
        try {
            DescribeTableRequest request = new DescribeTableRequest().withTableName(tableName);
            TableDescription tableDescription = getDdbClient().describeTable(request).getTable();
            if (isTableActive(tableDescription)) {
                LOG.trace("Table [{}] became active", tableName);
                return;
            }
            LOG.trace("Table [{}] not active yet", tableName);
        } catch (AmazonServiceException ase) {
            if (!ase.getErrorCode().equalsIgnoreCase("ResourceNotFoundException")) {
                throw ase;
            }
        }
    }

    throw new RuntimeException("Table " + tableName + " never went active");
}
项目:dynamodb-janusgraph-storage-backend    文件:DynamoDbDelegate.java   
private DescribeTableResult describeTable(final DescribeTableRequest request) throws BackendException {
    controlPlaneRateLimiter.acquire();
    final Timer.Context apiTimerContext = getTimerContext(DESCRIBE_TABLE, request.getTableName());
    DescribeTableResult result;
    try {
        result = client.describeTable(request);
    } catch (final Exception e) {
        throw processDynamoDbApiException(e, DESCRIBE_TABLE, request.getTableName());
    } finally {
        apiTimerContext.stop();
    }
    return result;
}
项目:datacollector    文件:KinesisSource.java   
private boolean leaseTableExists() {
    DescribeTableRequest request = new DescribeTableRequest();
    request.setTableName(conf.applicationName);
    DescribeTableResult result;
    try {
      result = dynamoDBClient.describeTable(request);
    } catch (ResourceNotFoundException e) {
      LOG.debug("Lease table '{}' does not exist", conf.applicationName);
      return false;
    }

    TableStatus tableStatus = TableStatus.fromValue(result.getTable().getTableStatus());
    LOG.debug("Lease table exists and is in '{}' state", tableStatus);
    return tableStatus == TableStatus.ACTIVE;
}
项目:milton-aws    文件:DynamoDBServiceImpl.java   
/**
 * Retrieves information about the table, including the current status of
 * the table, the primary key schema and when the table was created.
 * 
 * If the table does not exist, Amazon DynamoDB returns a
 * ResourceNotFoundException.
 * 
 * @param tableName
 *            - The name of the table
 * @return The response from the DescribeTable service method, as returned by AmazonDynamoDB
 */
private TableDescription describeTable(String tableName) {
    try {
        DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(tableName);
        TableDescription tableDescription = dynamoDBClient.describeTable(describeTableRequest).getTable();
        if (tableDescription != null) {
            LOG.info("Table description of " + tableName + ": " + tableDescription);
        }
        return tableDescription;
    } catch (ResourceNotFoundException rnfe) {
        LOG.warn(rnfe.getMessage());
    }
    return null;
}
项目:milton-aws    文件:DynamoDBServiceImpl.java   
private void waitForTableDeleted(String tableName) {
    LOG.info("Waiting for table " + tableName + " while status DELETING...");

    long startTime = System.currentTimeMillis();
    long endTime = startTime + (10 * 60 * 1000);
    while (System.currentTimeMillis() < endTime) {
        try {
            DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(tableName);
            TableDescription tableDescription = dynamoDBClient.describeTable(describeTableRequest)
                    .getTable();
            String tableStatus = tableDescription.getTableStatus();
            LOG.info("Current state for table " + tableName + ": " + tableStatus);
            if (tableStatus.equals(TableStatus.ACTIVE.toString())) {
                return;
            }
        } catch (ResourceNotFoundException rne) {
            LOG.warn("Table " + tableName + " is not found. It was deleted.");
            return;
        }

        try {
            Thread.sleep(1000 * 20);
        } catch (Exception ex) {
            LOG.warn(ex.getMessage());
        }
    }
    throw new RuntimeException("Table " + tableName + " was never deleted");
}
项目:gora    文件:DynamoDBUtils.java   
/**
 * Waits up to 6 minutes to confirm if a table has been created or not
 * 
 * @param awsClient
 * @param tableName
 */
public static void waitForTableToBecomeAvailable(AmazonDynamoDB awsClient,
    String tableName) {
  LOG.debug("Waiting for {} to become available", tableName);
  long startTime = System.currentTimeMillis();
  long endTime = startTime + WAIT_TIME;
  while (System.currentTimeMillis() < endTime) {
    try {
      Thread.sleep(SLEEP_TIME);
    } catch (Exception e) {
    }
    try {
      DescribeTableRequest request = new DescribeTableRequest()
          .withTableName(tableName);
      TableDescription tableDescription = awsClient.describeTable(request)
          .getTable();
      String tableStatus = tableDescription.getTableStatus();
      LOG.debug("{} - current state: {}", tableName, tableStatus);
      if (tableStatus.equals(TableStatus.ACTIVE.toString()))
        return;
    } catch (AmazonServiceException ase) {
      if (ase.getErrorCode().equalsIgnoreCase("ResourceNotFoundException") == false)
        throw ase;
    }
  }
  throw new RuntimeException("Table " + tableName + " never became active");
}
项目:gora    文件:DynamoDBStore.java   
/**
 * Retrieves the table description for the specific resource name
 * 
 * @param tableName
 * @return
 */
private TableDescription getTableSchema(String tableName) {
  TableDescription tableDescription = null;
  try {
    DescribeTableRequest describeTableRequest = new DescribeTableRequest()
        .withTableName(tableName);
    tableDescription = getDynamoDBClient()
        .describeTable(describeTableRequest).getTable();
  } catch (ResourceNotFoundException e) {
    LOG.error("Error while getting table schema: " + tableName);
    return tableDescription;
  }
  return tableDescription;
}
项目:aws-dynamodb-examples    文件:LowLevelTableExample.java   
static void getTableInformation() {

    TableDescription tableDescription = client.describeTable(
            new DescribeTableRequest().withTableName(tableName)).getTable();
    System.out.format("Name: %s:\n" +
            "Status: %s \n" + 
            "Provisioned Throughput (read capacity units/sec): %d \n" +
            "Provisioned Throughput (write capacity units/sec): %d \n",
            tableDescription.getTableName(),
            tableDescription.getTableStatus(),
            tableDescription.getProvisionedThroughput().getReadCapacityUnits(),
            tableDescription.getProvisionedThroughput().getWriteCapacityUnits());
}
项目:aws-dynamodb-examples    文件:DynamoDBDynamicFaultInjection.java   
private static void waitForTableToBecomeAvailable(String tableName)
{
    logger.info("Waiting for " + tableName + " to become ACTIVE...");

    long startTime = System.currentTimeMillis();
    long endTime = startTime + (10 * 60 * 1000);
    while (System.currentTimeMillis() < endTime)
    {
        try
        {
            Thread.sleep(1000 * 20);
        }
        catch (Exception e)
        {
        }
        try
        {
            DescribeTableRequest request = new DescribeTableRequest().withTableName(tableName);
            TableDescription tableDescription = dynamoDBClient.describeTable(request).getTable();
            String tableStatus = tableDescription.getTableStatus();
            logger.info("  - current state: " + tableStatus);
            if (tableStatus.equals(TableStatus.ACTIVE.toString()))
                return;
        }
        catch (AmazonServiceException ase)
        {
            if (ase.getErrorCode().equalsIgnoreCase("ResourceNotFoundException") == false)
                throw ase;
        }
    }

    throw new RuntimeException("Table " + tableName + " never went active");
}
项目:UnitedWayRESTBackend    文件:DynamoGeoService.java   
private void createTableIfNotExisting() {
    DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(config().getTableName());
    try {
        config().getDynamoDBClient().describeTable(describeTableRequest);
    } catch (ResourceNotFoundException e) {
        createTable();
    }
}
项目:UnitedWayRESTBackend    文件:DynamoGeoService.java   
private void waitForTableToBeReady() {
    DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(config().getTableName());
    DescribeTableResult describeTableResult = config().getDynamoDBClient().describeTable(describeTableRequest);
    while (!describeTableResult.getTable().getTableStatus().equalsIgnoreCase("ACTIVE")) {
        try {
            Thread.sleep(2000); //FIXME no endless retry
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        describeTableResult = config().getDynamoDBClient().describeTable(describeTableRequest);
    }
}
项目:reinvent2013-mobile-photo-share    文件:BaseAdmin.java   
protected boolean doesTableExist(String tableName) {
    try {
        DescribeTableRequest request = new DescribeTableRequest().withTableName(tableName);
        DescribeTableResult result = ddb.describeTable(request);
        return (result != null && "ACTIVE".equals(result.getTable().getTableStatus()));
    } catch (ResourceNotFoundException e) {
        return false;
    }
}
项目:reinvent2013-mobile-photo-share    文件:BaseAdmin.java   
protected boolean doesTableExist(String tableName) {
    try {
        DescribeTableRequest request = new DescribeTableRequest().withTableName(tableName);
        DescribeTableResult result = ddb.describeTable(request);
        return (result != null && "ACTIVE".equals(result.getTable().getTableStatus()));
    } catch (ResourceNotFoundException e) {
        return false;
    }
}
项目:reinvent2013-mobile-photo-share    文件:Utilities.java   
private void waitForTableToBeReady() {
    GeoDataManagerConfiguration config = geoDataManager.getGeoDataManagerConfiguration();

    DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(config.getTableName());
    DescribeTableResult describeTableResult = config.getDynamoDBClient().describeTable(describeTableRequest);

    while (!describeTableResult.getTable().getTableStatus().equalsIgnoreCase("ACTIVE")) {
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        describeTableResult = config.getDynamoDBClient().describeTable(describeTableRequest);
    }
}
项目:quartz-dynamodb    文件:DynamoDbJobStore.java   
private boolean tableExists(String name) {
    try {
        client.describeTable(new DescribeTableRequest().withTableName(name));
    } catch (ResourceNotFoundException e) {
        return false;
    }

    return true;
}
项目:aws-dynamodb-session-tomcat    文件:DynamoDBSessionManagerIntegrationTest.java   
/**
 * Returns true if the specified table exists, and is active and ready for use.
 */
private static boolean doesTableExist(String tableName) {
    try {
        TableDescription table = dynamo.describeTable(new DescribeTableRequest().withTableName(tableName))
                .getTable();
        return "ACTIVE".equals(table.getTableStatus());
    } catch (AmazonServiceException ase) {
        if (ase.getErrorCode().equals("ResourceNotFoundException")) {
            return false;
        }
        throw ase;
    }
}
项目:tweetamo    文件:PersistentStore.java   
private boolean tablesExist() {
    try {
        DescribeTableRequest describeTableRequest = new DescribeTableRequest()
                .withTableName(TABLE_NAME);
        dynamoDB.describeTable(describeTableRequest).getTable();
        return true;
    } catch (Exception e) {
        return false;
    }
}