List of usage examples for com.amazonaws.services.dynamodbv2.model TableDescription getGlobalSecondaryIndexes
public java.util.List<GlobalSecondaryIndexDescription> getGlobalSecondaryIndexes()
The global secondary indexes, if any, on the table.
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 w w .ja v a2 s. com 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 {// w w w.jav a 2s. co 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:jp.classmethod.aws.dynamodb.DynamoDbRepository.java
License:Open Source License
private TableDescription updateTable(TableDescription desc) { Preconditions.checkNotNull(desc, "table description must not be null"); UpdateTableSpec spec = null;/*from w ww . j a v a 2 s . c o m*/ if (false == ptMap.get(tableNameSuffix).equals(convert(desc.getProvisionedThroughput()))) { //if the throughput of the table is not the same as the throughput in the ptMap configuration, //update the thruput of the table spec = new UpdateTableSpec().withProvisionedThroughput(ptMap.get(tableNameSuffix)); } final List<GlobalSecondaryIndexUpdate> gsiUpdates = new ArrayList<>(); if (desc.getGlobalSecondaryIndexes() != null && false == desc.getGlobalSecondaryIndexes().isEmpty()) { //if the table description has updates to secondary indexes desc.getGlobalSecondaryIndexes().forEach(gsi -> { //for each gsi in the table description final String indexName = gsi.getIndexName(); ProvisionedThroughput pt = ptMap.get(indexName); if (pt != null && false == pt.equals(convert(gsi.getProvisionedThroughput()))) { //if the throughput of the gsi in the description is not the same as the throughput in the pt map //add an update to the gsi's thruput gsiUpdates .add(new GlobalSecondaryIndexUpdate().withUpdate(new UpdateGlobalSecondaryIndexAction() .withIndexName(indexName).withProvisionedThroughput(pt))); } }); } if (false == gsiUpdates.isEmpty()) { if (spec == null) { spec = new UpdateTableSpec(); } spec.withGlobalSecondaryIndexUpdates(gsiUpdates); } return spec == null ? null : table.updateTable(spec); }
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 .j av a 2s .co 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);// ww w .j a v a 2 s . c o 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.socialsignin.spring.data.dynamodb.repository.util.Entity2DynamoDBTableSynchronizer.java
License:Apache License
/** * @param entityInformation/*from w ww . j ava 2s . com*/ * The entity to check for it's table * @throws IllegalStateException * is thrown if the existing table doesn't match the entity's * annotation */ private DescribeTableResult performValidate(DynamoDBEntityInformation<T, ID> entityInformation) throws IllegalStateException { Class<T> domainType = entityInformation.getJavaType(); CreateTableRequest expected = mapper.generateCreateTableRequest(domainType); DescribeTableResult result = amazonDynamoDB.describeTable(expected.getTableName()); TableDescription actual = result.getTable(); if (!expected.getKeySchema().equals(actual.getKeySchema())) { throw new IllegalStateException("KeySchema is not as expected. Expected: <" + expected.getKeySchema() + "> but found <" + actual.getKeySchema() + ">"); } LOGGER.debug("KeySchema is valid"); if (expected.getGlobalSecondaryIndexes() != null) { if (!Arrays.deepEquals(expected.getGlobalSecondaryIndexes().toArray(), actual.getGlobalSecondaryIndexes().toArray())) { throw new IllegalStateException("Global Secondary Indexes are not as expected. Expected: <" + expected.getGlobalSecondaryIndexes() + "> but found <" + actual.getGlobalSecondaryIndexes() + ">"); } } LOGGER.debug("Global Secondary Indexes are valid"); LOGGER.info("Validated table {} for entity{}", expected.getTableName(), domainType); return result; }
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()); }