use of com.amazonaws.services.dynamodbv2.document.Table 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.getColumnName(), new AttributeValue(String.valueOf(service.getId())));
values.put(ColumnNames.NAME.getColumnName(), new AttributeValue(service.getName()));
values.put(ColumnNames.DESCRIPTION.getColumnName(), new AttributeValue(service.getDescription()));
values.put(ColumnNames.SERVICE_ID.getColumnName(), new AttributeValue(service.getServiceId()));
final ByteArrayOutputStream out = new ByteArrayOutputStream();
jsonSerializer.to(out, service);
values.put(ColumnNames.ENCODED.getColumnName(), new AttributeValue().withB(ByteBuffer.wrap(out.toByteArray())));
LOGGER.debug("Created attribute values [{}] based on provided service [{}]", values, service);
return values;
}
use of com.amazonaws.services.dynamodbv2.document.Table in project cas by apereo.
the class DynamoDbTicketRegistryFacilitator method createTicketTables.
/**
* Create ticket tables.
*
* @param deleteTables the delete tables
*/
public void createTicketTables(final boolean deleteTables) {
final Collection<TicketDefinition> metadata = this.ticketCatalog.findAll();
metadata.forEach(Unchecked.consumer(r -> {
final CreateTableRequest request = new CreateTableRequest().withAttributeDefinitions(new AttributeDefinition(ColumnNames.ID.getColumnName(), ScalarAttributeType.S)).withKeySchema(new KeySchemaElement(ColumnNames.ID.getColumnName(), KeyType.HASH)).withProvisionedThroughput(new ProvisionedThroughput(dynamoDbProperties.getReadCapacity(), dynamoDbProperties.getWriteCapacity())).withTableName(r.getProperties().getStorageName());
if (deleteTables) {
final DeleteTableRequest delete = new DeleteTableRequest(r.getProperties().getStorageName());
LOGGER.debug("Sending delete request [{}] to remove table if necessary", delete);
TableUtils.deleteTableIfExists(amazonDynamoDBClient, delete);
}
LOGGER.debug("Sending delete request [{}] to create table", request);
TableUtils.createTableIfNotExists(amazonDynamoDBClient, request);
LOGGER.debug("Waiting until table [{}] becomes active...", request.getTableName());
TableUtils.waitUntilActive(amazonDynamoDBClient, request.getTableName());
final DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(request.getTableName());
LOGGER.debug("Sending request [{}] to obtain table description...", describeTableRequest);
final TableDescription tableDescription = amazonDynamoDBClient.describeTable(describeTableRequest).getTable();
LOGGER.debug("Located newly created table with description: [{}]", tableDescription);
}));
}
use of com.amazonaws.services.dynamodbv2.document.Table in project cas by apereo.
the class DynamoDbCloudConfigBootstrapConfiguration method locate.
@Override
public PropertySource<?> locate(final Environment environment) {
final AmazonDynamoDB amazonDynamoDBClient = getAmazonDynamoDbClient(environment);
createSettingsTable(amazonDynamoDBClient, false);
final ScanRequest scan = new ScanRequest(TABLE_NAME);
LOGGER.debug("Scanning table with request [{}]", scan);
final ScanResult result = amazonDynamoDBClient.scan(scan);
LOGGER.debug("Scanned table with result [{}]", scan);
final Properties props = new Properties();
result.getItems().stream().map(DynamoDbCloudConfigBootstrapConfiguration::retrieveSetting).forEach(p -> props.put(p.getKey(), p.getValue()));
return new PropertiesPropertySource(getClass().getSimpleName(), props);
}
use of com.amazonaws.services.dynamodbv2.document.Table in project amos-ss17-alexa by c-i-ber.
the class DynamoDbMapper method dropTable.
/**
* drops table by a pojo class
*
* @param cl class which will be mapped to drop a table
*/
public void dropTable(Class cl) {
DeleteTableRequest tableRequest = mapper.generateDeleteTableRequest(cl);
Table table = dynamoDB.getTable(tableRequest.getTableName());
try {
dynamoDbClient.deleteTable(tableRequest);
table.waitForDelete();
} catch (ResourceNotFoundException e) {
// Table does not exist
} catch (InterruptedException e) {
e.printStackTrace();
}
}
use of com.amazonaws.services.dynamodbv2.document.Table in project amos-ss17-alexa by c-i-ber.
the class DynamoDbMapper method createTable.
/**
* creates a new table by a pojo class
*
* @param cl class which will be mapped to the new table
*/
public void createTable(Class cl) throws InterruptedException {
CreateTableRequest tableRequest = mapper.generateCreateTableRequest(cl);
tableRequest.setProvisionedThroughput(new ProvisionedThroughput(1L, 1L));
Table table = dynamoDB.createTable(tableRequest);
table.waitForActive();
}
Aggregations