Search in sources :

Example 6 with AttributeValue

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

the class DynamoDbServiceRegistryFacilitator method buildTableAttributeValuesMapFromService.

/**
     * Build table attribute values from map.
     *
     * @param service the service
     * @return the map
     */
public Map<String, AttributeValue> buildTableAttributeValuesMapFromService(final RegisteredService service) {
    final Map<String, AttributeValue> values = new HashMap<>();
    values.put(ColumnNames.ID.getName(), new AttributeValue(String.valueOf(service.getId())));
    values.put(ColumnNames.NAME.getName(), new AttributeValue(service.getName()));
    values.put(ColumnNames.DESCRIPTION.getName(), new AttributeValue(service.getDescription()));
    values.put(ColumnNames.SERVICE_ID.getName(), new AttributeValue(service.getServiceId()));
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    jsonSerializer.to(out, service);
    values.put(ColumnNames.ENCODED.getName(), new AttributeValue().withB(ByteBuffer.wrap(out.toByteArray())));
    LOGGER.debug("Created attribute values [{}] based on provided service [{}]", values, service);
    return values;
}
Also used : AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) HashMap(java.util.HashMap) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 7 with AttributeValue

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

the class DynamoDbTicketRegistryFacilitator method get.

/**
     * Get ticket.
     *
     * @param ticketId the ticket id
     * @return the ticket
     */
public Ticket get(final String ticketId) {
    final TicketDefinition metadata = this.ticketCatalog.find(ticketId);
    if (metadata != null) {
        final Map<String, AttributeValue> keys = new HashMap<>();
        keys.put(ColumnNames.ID.getName(), new AttributeValue(ticketId));
        final GetItemRequest request = new GetItemRequest().withKey(keys).withTableName(metadata.getProperties().getStorageName());
        LOGGER.debug("Submitting request [{}] to get ticket item [{}]", request, ticketId);
        final Map<String, AttributeValue> returnItem = amazonDynamoDBClient.getItem(request).getItem();
        if (returnItem != null) {
            final Ticket ticket = deserializeTicket(returnItem);
            LOGGER.debug("Located ticket [{}]", ticket);
            return ticket;
        }
    } else {
        LOGGER.warn("No ticket definition could be found in the catalog to match [{}]", ticketId);
    }
    return null;
}
Also used : Ticket(org.apereo.cas.ticket.Ticket) AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) HashMap(java.util.HashMap) TicketDefinition(org.apereo.cas.ticket.TicketDefinition) GetItemRequest(com.amazonaws.services.dynamodbv2.model.GetItemRequest)

Example 8 with AttributeValue

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

the class DynamoDbTicketRegistryFacilitator method delete.

/**
     * Delete.
     *
     * @param ticketId the ticket id
     * @return the boolean
     */
public boolean delete(final String ticketId) {
    final TicketDefinition metadata = this.ticketCatalog.find(ticketId);
    if (metadata != null) {
        final DeleteItemRequest del = new DeleteItemRequest().withTableName(metadata.getProperties().getStorageName()).withKey(Collections.singletonMap(ColumnNames.ID.getName(), new AttributeValue(ticketId)));
        LOGGER.debug("Submitting delete request [{}] for ticket [{}]", del, ticketId);
        final DeleteItemResult res = amazonDynamoDBClient.deleteItem(del);
        LOGGER.debug("Delete request came back with result [{}]", res);
        return res != null;
    }
    return false;
}
Also used : AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) DeleteItemRequest(com.amazonaws.services.dynamodbv2.model.DeleteItemRequest) TicketDefinition(org.apereo.cas.ticket.TicketDefinition) DeleteItemResult(com.amazonaws.services.dynamodbv2.model.DeleteItemResult)

Example 9 with AttributeValue

use of com.amazonaws.services.dynamodbv2.model.AttributeValue 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 10 with AttributeValue

use of com.amazonaws.services.dynamodbv2.model.AttributeValue 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)

Aggregations

AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)32 HashMap (java.util.HashMap)23 Test (org.junit.Test)8 Condition (com.amazonaws.services.dynamodbv2.model.Condition)5 AmazonServiceException (com.amazonaws.AmazonServiceException)4 AmazonDynamoDB (com.amazonaws.services.dynamodbv2.AmazonDynamoDB)4 ConsumedCapacity (com.amazonaws.services.dynamodbv2.model.ConsumedCapacity)4 Map (java.util.Map)4 ExpectedAttributeValue (com.amazonaws.services.dynamodbv2.model.ExpectedAttributeValue)3 GetItemRequest (com.amazonaws.services.dynamodbv2.model.GetItemRequest)3 ScanResult (com.amazonaws.services.dynamodbv2.model.ScanResult)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 TicketDefinition (org.apereo.cas.ticket.TicketDefinition)3 DynamoDBScanExpression (com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBScanExpression)2 AttributeValueUpdate (com.amazonaws.services.dynamodbv2.model.AttributeValueUpdate)2 ComparisonOperator (com.amazonaws.services.dynamodbv2.model.ComparisonOperator)2 DeleteItemRequest (com.amazonaws.services.dynamodbv2.model.DeleteItemRequest)2 DeleteItemResult (com.amazonaws.services.dynamodbv2.model.DeleteItemResult)2 KeysAndAttributes (com.amazonaws.services.dynamodbv2.model.KeysAndAttributes)2