Search in sources :

Example 1 with ScanRequest

use of com.amazonaws.services.dynamodbv2.model.ScanRequest in project archaius by Netflix.

the class DynamoDbConfigurationSource method loadPropertiesFromTable.

@Override
protected synchronized Map<String, Object> loadPropertiesFromTable(String table) {
    Map<String, Object> propertyMap = new HashMap<String, Object>();
    Map<String, AttributeValue> lastKeysEvaluated = null;
    do {
        ScanRequest scanRequest = new ScanRequest().withTableName(table).withExclusiveStartKey(lastKeysEvaluated);
        ScanResult result = dbScanWithThroughputBackOff(scanRequest);
        for (Map<String, AttributeValue> item : result.getItems()) {
            propertyMap.put(item.get(keyAttributeName.get()).getS(), item.get(valueAttributeName.get()).getS());
        }
        lastKeysEvaluated = result.getLastEvaluatedKey();
    } while (lastKeysEvaluated != null);
    return propertyMap;
}
Also used : ScanRequest(com.amazonaws.services.dynamodbv2.model.ScanRequest) AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) ScanResult(com.amazonaws.services.dynamodbv2.model.ScanResult) HashMap(java.util.HashMap)

Example 2 with ScanRequest

use of com.amazonaws.services.dynamodbv2.model.ScanRequest in project archaius by Netflix.

the class DynamoDbDeploymentContextTableCache method loadPropertiesFromTable.

/**
     * Scan the table in dynamo and create a map with the results.  In this case the map has a complex type as the value,
     * so that Deployment Context is taken into account.
     *
     * @param table
     * @return
     */
@Override
protected Map<String, PropertyWithDeploymentContext> loadPropertiesFromTable(String table) {
    Map<String, PropertyWithDeploymentContext> propertyMap = new HashMap<String, PropertyWithDeploymentContext>();
    Map<String, AttributeValue> lastKeysEvaluated = null;
    do {
        ScanRequest scanRequest = new ScanRequest().withTableName(table).withExclusiveStartKey(lastKeysEvaluated);
        ScanResult result = dbScanWithThroughputBackOff(scanRequest);
        for (Map<String, AttributeValue> item : result.getItems()) {
            String keyVal = item.get(keyAttributeName.get()).getS();
            //Need to deal with the fact that these attributes might not exist
            DeploymentContext.ContextKey contextKey = item.containsKey(contextKeyAttributeName.get()) ? DeploymentContext.ContextKey.valueOf(item.get(contextKeyAttributeName.get()).getS()) : null;
            String contextVal = item.containsKey(contextValueAttributeName.get()) ? item.get(contextValueAttributeName.get()).getS() : null;
            String key = keyVal + ";" + contextKey + ";" + contextVal;
            propertyMap.put(key, new PropertyWithDeploymentContext(contextKey, contextVal, keyVal, item.get(valueAttributeName.get()).getS()));
        }
        lastKeysEvaluated = result.getLastEvaluatedKey();
    } while (lastKeysEvaluated != null);
    return propertyMap;
}
Also used : ScanRequest(com.amazonaws.services.dynamodbv2.model.ScanRequest) AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) ScanResult(com.amazonaws.services.dynamodbv2.model.ScanResult) HashMap(java.util.HashMap)

Example 3 with ScanRequest

use of com.amazonaws.services.dynamodbv2.model.ScanRequest in project cas by apereo.

the class DynamoDbServiceRegistryFacilitator method count.

/**
     * Count long.
     *
     * @return the long
     */
public long count() {
    final ScanRequest scan = new ScanRequest(TABLE_NAME);
    LOGGER.debug("Scanning table with request [{}] to count items", scan);
    final ScanResult result = this.amazonDynamoDBClient.scan(scan);
    LOGGER.debug("Scanned table with result [{}]", scan);
    return result.getCount();
}
Also used : ScanRequest(com.amazonaws.services.dynamodbv2.model.ScanRequest) ScanResult(com.amazonaws.services.dynamodbv2.model.ScanResult)

Example 4 with ScanRequest

use of com.amazonaws.services.dynamodbv2.model.ScanRequest in project cas by apereo.

the class DynamoDbServiceRegistryFacilitator method getAll.

/**
     * Gets all.
     *
     * @return the all
     */
public List<RegisteredService> getAll() {
    final List<RegisteredService> services = new ArrayList<>();
    final ScanRequest scan = new ScanRequest(TABLE_NAME);
    LOGGER.debug("Scanning table with request [{}]", scan);
    final ScanResult result = this.amazonDynamoDBClient.scan(scan);
    LOGGER.debug("Scanned table with result [{}]", scan);
    services.addAll(result.getItems().stream().map(this::deserializeServiceFromBinaryBlob).sorted((o1, o2) -> Integer.valueOf(o1.getEvaluationOrder()).compareTo(o2.getEvaluationOrder())).collect(Collectors.toList()));
    return services;
}
Also used : ScanRequest(com.amazonaws.services.dynamodbv2.model.ScanRequest) ScanResult(com.amazonaws.services.dynamodbv2.model.ScanResult) ArrayList(java.util.ArrayList)

Example 5 with ScanRequest

use of com.amazonaws.services.dynamodbv2.model.ScanRequest in project cas by apereo.

the class DynamoDbTicketRegistryFacilitator method deleteAll.

/**
     * Delete all.
     *
     * @return the int
     */
public int deleteAll() {
    final AtomicInteger count = new AtomicInteger();
    final Collection<TicketDefinition> metadata = this.ticketCatalog.findAll();
    metadata.forEach(r -> {
        final ScanRequest scan = new ScanRequest(r.getProperties().getStorageName());
        LOGGER.debug("Submitting scan request [{}] to table [{}]", scan, r.getProperties().getStorageName());
        count.addAndGet(this.amazonDynamoDBClient.scan(scan).getCount());
    });
    createTicketTables(true);
    return count.get();
}
Also used : ScanRequest(com.amazonaws.services.dynamodbv2.model.ScanRequest) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TicketDefinition(org.apereo.cas.ticket.TicketDefinition)

Aggregations

ScanRequest (com.amazonaws.services.dynamodbv2.model.ScanRequest)7 ScanResult (com.amazonaws.services.dynamodbv2.model.ScanResult)7 HashMap (java.util.HashMap)4 AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)3 ArrayList (java.util.ArrayList)2 TicketDefinition (org.apereo.cas.ticket.TicketDefinition)2 ConsumedCapacity (com.amazonaws.services.dynamodbv2.model.ConsumedCapacity)1 Map (java.util.Map)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Ticket (org.apereo.cas.ticket.Ticket)1