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

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

public void waitForTableCreation(final String tableName, final boolean verifyIndexesList,
    final List<LocalSecondaryIndexDescription> expectedLsiList, final List<GlobalSecondaryIndexDescription> expectedGsiList) throws BackendException {
    boolean successFlag = false;
    int retryCount = 0;
    while (!successFlag && retryCount < maxRetries) {
        try {
            boolean areAllGsisActive = true;
            final TableDescription td = describeTable(tableName);
            if (verifyIndexesList) {
                final Set<LocalSecondaryIndexDescription> expectedLSIs = new HashSet<LocalSecondaryIndexDescription>();
                if (expectedLsiList != null) {
                    expectedLSIs.addAll(expectedLsiList);
                }
                final Set<LocalSecondaryIndexDescription> actualLSIs = new HashSet<LocalSecondaryIndexDescription>();
                if (td.getLocalSecondaryIndexes() != null) {
                    actualLSIs.addAll(td.getLocalSecondaryIndexes());
                }
                // the lsi list should be there even if the table is in creating state
                if (!(expectedLsiList == null && td.getLocalSecondaryIndexes() == null || expectedLSIs.equals(actualLSIs))) {
                    throw new PermanentBackendException("LSI list is not as expected during table creation. expectedLsiList="
                        + expectedLsiList.toString() + "; table description=" + td.toString());
                }

                // ignore the status of all GSIs since they will mess up .equals()
                if (td.getGlobalSecondaryIndexes() != null) {
                    for (final GlobalSecondaryIndexDescription gDesc : td.getGlobalSecondaryIndexes()) {
                        if (!isTableAcceptingWrites(gDesc.getIndexStatus())) {
                            areAllGsisActive = false;
                            break;
                        }
                    }
                }

                // the gsi list should be there even if the table is in creating state
                if (!areGsisSameConfiguration(expectedGsiList, td.getGlobalSecondaryIndexes())) {
                    throw new PermanentBackendException("GSI list is not as expected during table creation. expectedGsiList="
                        + expectedGsiList.toString() + "; table description=" + td.toString());
                }
            }
            successFlag = isTableAcceptingWrites(td.getTableStatus()) && areAllGsisActive;
        } catch (BackendNotFoundException ignore) {
            successFlag = false;
        }

        if (!successFlag) {
            interruptibleSleep(CONTROL_PLANE_RETRY_DELAY_MS);
        }
        retryCount++;
    }
    if (!successFlag) {
        throw new PermanentBackendException("Table creation not completed for table " + tableName + " after retrying "
                + this.maxRetries + " times for a duration of " + CONTROL_PLANE_RETRY_DELAY_MS * this.maxRetries + " ms");
    }
}
 
源代码2 项目: dynamodb-transactions   文件: TableHelper.java
public String verifyTableExists( 
    String tableName, 
    List<AttributeDefinition> definitions, 
    List<KeySchemaElement> keySchema,
    List<LocalSecondaryIndex> localIndexes) {
    
    DescribeTableResult describe = client.describeTable(new DescribeTableRequest().withTableName(tableName));
    if(! new HashSet<AttributeDefinition>(definitions).equals(new HashSet<AttributeDefinition>(describe.getTable().getAttributeDefinitions()))) {
        throw new ResourceInUseException("Table " + tableName + " had the wrong AttributesToGet." 
            + " Expected: " + definitions + " "
            + " Was: " + describe.getTable().getAttributeDefinitions());
    }
    
    if(! keySchema.equals(describe.getTable().getKeySchema())) {
        throw new ResourceInUseException("Table " + tableName + " had the wrong KeySchema." 
            + " Expected: " + keySchema + " "
            + " Was: " + describe.getTable().getKeySchema());
    }
    
    List<LocalSecondaryIndex> theirLSIs = null;
    if(describe.getTable().getLocalSecondaryIndexes() != null) {
        theirLSIs = new ArrayList<LocalSecondaryIndex>();
        for(LocalSecondaryIndexDescription description : describe.getTable().getLocalSecondaryIndexes()) {
            LocalSecondaryIndex lsi = new LocalSecondaryIndex()
                .withIndexName(description.getIndexName())
                .withKeySchema(description.getKeySchema())
                .withProjection(description.getProjection());
            theirLSIs.add(lsi);
        }
    }
    
    if(localIndexes != null) {
        if(! new HashSet<LocalSecondaryIndex>(localIndexes).equals(new HashSet<LocalSecondaryIndex>(theirLSIs))) {
            throw new ResourceInUseException("Table " + tableName + " did not have the expected LocalSecondaryIndexes."
                + " Expected: " + localIndexes
                + " Was: " + theirLSIs);
        }
    } else {
        if(theirLSIs != null) {
            throw new ResourceInUseException("Table " + tableName + " had local secondary indexes, but expected none."
                + " Indexes: " + theirLSIs);
        }
    }

    return describe.getTable().getTableStatus();
}
 
 类方法
 同包方法