Example usage for com.amazonaws.services.dynamodbv2.model TableDescription getLocalSecondaryIndexes

List of usage examples for com.amazonaws.services.dynamodbv2.model TableDescription getLocalSecondaryIndexes

Introduction

In this page you can find the example usage for com.amazonaws.services.dynamodbv2.model TableDescription getLocalSecondaryIndexes.

Prototype


public java.util.List<LocalSecondaryIndexDescription> getLocalSecondaryIndexes() 

Source Link

Document

Represents one or more local secondary indexes on the table.

Usage

From source file:com.amazon.janusgraph.diskstorage.dynamodb.DynamoDbDelegate.java

License:Open Source License

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 {/*  w  ww . ja  v  a2  s .  c o m*/
            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");
    }
}

From source file:com.rapid7.diskstorage.dynamodb.DynamoDBDelegate.java

License:Open Source License

public boolean waitForTableCreation(String tableName, boolean verifyIndexesList,
        List<LocalSecondaryIndexDescription> expectedLsiList,
        List<GlobalSecondaryIndexDescription> expectedGsiList) throws BackendException {
    boolean successFlag = false;
    int retryCount = 0;
    while (!successFlag && retryCount < maxRetries) {
        try {/*from  www  .j  a va2 s  .  c  o  m*/
            boolean areAllGSIsActive = true;
            final TableDescription td = describeTable(tableName);
            if (verifyIndexesList) {
                Set<LocalSecondaryIndexDescription> expectedLSIs = new HashSet<LocalSecondaryIndexDescription>();
                if (expectedLsiList != null) {
                    expectedLSIs.addAll(expectedLsiList);
                }
                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 (GlobalSecondaryIndexDescription gDesc : td.getGlobalSecondaryIndexes()) {
                        if (!TableStatus.ACTIVE.toString().equals(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 = td.getTableStatus().equals(TableStatus.ACTIVE.toString()) && areAllGSIsActive;
        } catch (BackendNotFoundException e) {
            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");
    }
    return successFlag;
}

From source file:org.apache.metamodel.dynamodb.DynamoDbDataContext.java

License:Apache License

@Override
protected Schema getMainSchema() throws MetaModelException {
    final Map<String, SimpleTableDef> tableDefs = new HashMap<>();
    for (final SimpleTableDef tableDef : _tableDefs) {
        tableDefs.put(tableDef.getName(), tableDef);
    }/*from  w  w w  .  jav a2  s. c o  m*/

    final MutableSchema schema = new MutableSchema(getMainSchemaName());
    final ListTablesResult tables = _dynamoDb.listTables();
    final List<String> tableNames = tables.getTableNames();
    for (final String tableName : tableNames) {
        final MutableTable table = new MutableTable(tableName, schema);
        schema.addTable(table);

        final DescribeTableResult descripeTableResult = _dynamoDb.describeTable(tableName);
        final TableDescription tableDescription = descripeTableResult.getTable();

        // add primary keys
        addColumnFromKeySchema("Primary index", tableDescription.getKeySchema(), table, true);

        // add attributes from global and local indices
        final List<GlobalSecondaryIndexDescription> globalSecondaryIndexes = tableDescription
                .getGlobalSecondaryIndexes();
        if (globalSecondaryIndexes != null) {
            for (final GlobalSecondaryIndexDescription globalSecondaryIndex : globalSecondaryIndexes) {
                addColumnFromKeySchema(globalSecondaryIndex.getIndexName(), globalSecondaryIndex.getKeySchema(),
                        table, false);
            }
        }
        final List<LocalSecondaryIndexDescription> localSecondaryIndexes = tableDescription
                .getLocalSecondaryIndexes();
        if (localSecondaryIndexes != null) {
            for (final LocalSecondaryIndexDescription localSecondaryIndex : localSecondaryIndexes) {
                addColumnFromKeySchema(localSecondaryIndex.getIndexName(), localSecondaryIndex.getKeySchema(),
                        table, false);
            }
        }

        // add top-level attribute definitions
        final List<AttributeDefinition> attributeDefinitions = tableDescription.getAttributeDefinitions();
        for (final AttributeDefinition attributeDefinition : attributeDefinitions) {
            final String attributeName = attributeDefinition.getAttributeName();
            MutableColumn column = (MutableColumn) table.getColumnByName(attributeName);
            if (column == null) {
                column = new MutableColumn(attributeName, table);
                table.addColumn(column);
            }
            final String attributeType = attributeDefinition.getAttributeType();
            column.setType(DynamoDbUtils.toColumnType(attributeName, attributeType));
            column.setIndexed(true);
            column.setNativeType(attributeType);
        }

        // add additional metadata from SimpleTableDefs if available
        final SimpleTableDef tableDef = tableDefs.get(tableName);
        if (tableDef != null) {
            final String[] columnNames = tableDef.getColumnNames();
            final ColumnType[] columnTypes = tableDef.getColumnTypes();
            for (int i = 0; i < columnNames.length; i++) {
                final String columnName = columnNames[i];
                final ColumnType columnType = columnTypes[i];
                MutableColumn column = (MutableColumn) table.getColumnByName(columnName);
                if (column == null) {
                    column = new MutableColumn(columnName, table);
                    table.addColumn(column);
                }
                if (column.getType() == null && columnType != null) {
                    column.setType(columnType);
                }
            }
        }

        // add additional attributes based on global and local indices
        if (globalSecondaryIndexes != null) {
            for (final GlobalSecondaryIndexDescription globalSecondaryIndex : globalSecondaryIndexes) {
                final List<String> nonKeyAttributes = globalSecondaryIndex.getProjection()
                        .getNonKeyAttributes();
                for (final String attributeName : nonKeyAttributes) {
                    addColumnFromNonKeyAttribute(globalSecondaryIndex.getIndexName(), table, attributeName);
                }
            }
        }
        if (localSecondaryIndexes != null) {
            for (final LocalSecondaryIndexDescription localSecondaryIndex : localSecondaryIndexes) {
                final List<String> nonKeyAttributes = localSecondaryIndex.getProjection().getNonKeyAttributes();
                for (final String attributeName : nonKeyAttributes) {
                    addColumnFromNonKeyAttribute(localSecondaryIndex.getIndexName(), table, attributeName);
                }
            }
        }
    }
    return schema;
}

From source file:org.iternine.jeppetto.dao.dynamodb.DynamoDBQueryModelDAO.java

License:Apache License

private Map<String, Map<String, IndexData>> processIndexes(TableDescription tableDescription,
        ProjectionExpressionBuilder projectionExpressionBuilder, IndexData baseIndexData) {
    // Collect information about the local secondary indexes.  These will be included with the global indexes below.
    Map<String, IndexData> localIndexes;
    List<LocalSecondaryIndexDescription> localSecondaryIndexes = tableDescription.getLocalSecondaryIndexes();
    if (localSecondaryIndexes != null) {
        localIndexes = new HashMap<String, IndexData>(localSecondaryIndexes.size() + 2);

        // We include these as local indexes to make findUsingQueryModel() code below simpler
        localIndexes.put(rangeKeyField, baseIndexData);
        localIndexes.put(null, baseIndexData);

        for (LocalSecondaryIndexDescription description : localSecondaryIndexes) {
            String indexField = getKeyAttributeNames(description.getKeySchema()).getSecond();
            boolean projectsOverEntity = description.getProjection().getProjectionType().equals("ALL")
                    || projectionExpressionBuilder != null
                            && projectionExpressionBuilder.isCoveredBy(description.getProjection());

            List<String> keyFields = new ArrayList<String>(baseIndexData.keyFields);
            keyFields.add(indexField);/*from   w ww . j a va2s  . co  m*/

            localIndexes.put(indexField,
                    new IndexData(description.getIndexName(), keyFields, projectsOverEntity));
        }
    } else if (rangeKeyField != null) {
        localIndexes = new HashMap<String, IndexData>(2);

        localIndexes.put(rangeKeyField, baseIndexData);
        localIndexes.put(null, baseIndexData);
    } else {
        localIndexes = Collections.singletonMap(null, baseIndexData);
    }

    // Process the global secondary indexes.  When done, add the local index information.
    List<GlobalSecondaryIndexDescription> globalSecondaryIndexes = tableDescription.getGlobalSecondaryIndexes();
    if (globalSecondaryIndexes != null) {
        Map<String, Map<String, IndexData>> indexes = new HashMap<String, Map<String, IndexData>>(
                globalSecondaryIndexes.size() + 1);

        for (GlobalSecondaryIndexDescription description : globalSecondaryIndexes) {
            Pair<String, String> indexFields = getKeyAttributeNames(description.getKeySchema());
            boolean projectsOverEntity = description.getProjection().getProjectionType().equals("ALL")
                    || projectionExpressionBuilder != null
                            && projectionExpressionBuilder.isCoveredBy(description.getProjection());

            List<String> keyFields = new ArrayList<String>();
            keyFields.add(indexFields.getFirst());
            if (indexFields.getSecond() != null) {
                keyFields.add(indexFields.getSecond());
            }
            keyFields.add(hashKeyField);
            if (rangeKeyField != null) {
                keyFields.add(rangeKeyField);
            }

            IndexData indexData = new IndexData(description.getIndexName(), keyFields, projectsOverEntity);

            if (!indexes.containsKey(indexFields.getFirst())) {
                indexes.put(indexFields.getFirst(), new HashMap<String, IndexData>());
            }

            indexes.get(indexFields.getFirst()).put(indexFields.getSecond(), indexData);

            // In case a query doesn't specify a range key, we still want to select an index for this hash key.
            // If one has already been selected, pick one that projects over this entity to avoid extra DB reads.
            IndexData noRangeKeyIndexData = indexes.get(indexFields.getFirst()).get(null);
            if (noRangeKeyIndexData == null || !noRangeKeyIndexData.projectsOverEntity) {
                indexes.get(indexFields.getFirst()).put(null, indexData);
            }
        }

        indexes.put(hashKeyField, localIndexes);

        return indexes;
    } else {
        return Collections.singletonMap(hashKeyField, localIndexes);
    }
}

From source file:org.xmlsh.aws.util.AWSDDBCommand.java

License:BSD License

protected void writeTableDescription(TableDescription tableDescription) throws XMLStreamException {
    startElement("table");
    attribute("name", tableDescription.getTableName());
    attribute("status", tableDescription.getTableStatus());
    attribute("create-date", Util.formatXSDateTime(tableDescription.getCreationDateTime()));
    attribute("item-count", tableDescription.getItemCount());
    attribute("size", tableDescription.getTableSizeBytes());
    attribute("item-count", tableDescription.getItemCount());

    writeAttributeDefinitions(tableDescription.getAttributeDefinitions());
    writeKeySchemaList(tableDescription.getKeySchema());
    writeLocalSecondaryIndexes(tableDescription.getLocalSecondaryIndexes());
    writeGlobalSecondaryIndexes(tableDescription.getGlobalSecondaryIndexes());
    writeProvisionedThroughput(tableDescription.getProvisionedThroughput());

}