Search in sources :

Example 81 with Table

use of com.amazonaws.services.dynamodbv2.document.Table in project openhab1-addons by openhab.

the class BaseIntegrationTest method initService.

@BeforeClass
public static void initService() throws InterruptedException {
    items.put("dimmer", new DimmerItem("dimmer"));
    items.put("number", new NumberItem("number"));
    items.put("string", new StringItem("string"));
    items.put("switch", new SwitchItem("switch"));
    items.put("contact", new ContactItem("contact"));
    items.put("color", new ColorItem("color"));
    items.put("rollershutter", new RollershutterItem("rollershutter"));
    items.put("datetime", new DateTimeItem("datetime"));
    items.put("call", new CallItem("call"));
    items.put("location", new LocationItem("location"));
    service = new DynamoDBPersistenceService();
    service.setItemRegistry(new ItemRegistry() {

        @Override
        public void removeItemRegistryChangeListener(ItemRegistryChangeListener listener) {
            throw new NotImplementedException();
        }

        @Override
        public boolean isValidItemName(String itemName) {
            throw new NotImplementedException();
        }

        @Override
        public Collection<Item> getItems(String pattern) {
            throw new NotImplementedException();
        }

        @Override
        public Collection<Item> getItems() {
            throw new NotImplementedException();
        }

        @Override
        public Item getItemByPattern(String name) throws ItemNotFoundException, ItemNotUniqueException {
            throw new NotImplementedException();
        }

        @Override
        public Item getItem(String name) throws ItemNotFoundException {
            Item item = items.get(name);
            if (item == null) {
                throw new ItemNotFoundException(name);
            }
            return item;
        }

        @Override
        public void addItemRegistryChangeListener(ItemRegistryChangeListener listener) {
            throw new NotImplementedException();
        }
    });
    HashMap<String, Object> config = new HashMap<>();
    config.put("region", System.getProperty("DYNAMODBTEST_REGION"));
    config.put("accessKey", System.getProperty("DYNAMODBTEST_ACCESS"));
    config.put("secretKey", System.getProperty("DYNAMODBTEST_SECRET"));
    config.put("tablePrefix", "dynamodb-integration-tests-");
    for (Entry<String, Object> entry : config.entrySet()) {
        if (entry.getValue() == null) {
            logger.warn(String.format("Expecting %s to have value for integration tests. Integration tests will be skipped", entry.getKey()));
            service = null;
            return;
        }
    }
    service.activate(null, config);
    // Clear data
    for (String table : new String[] { "dynamodb-integration-tests-bigdecimal", "dynamodb-integration-tests-string" }) {
        try {
            service.getDb().getDynamoClient().deleteTable(table);
            service.getDb().getDynamoDB().getTable(table).waitForDelete();
        } catch (ResourceNotFoundException e) {
        }
    }
}
Also used : LocationItem(org.openhab.core.library.items.LocationItem) HashMap(java.util.HashMap) NotImplementedException(org.apache.commons.lang.NotImplementedException) ColorItem(org.openhab.core.library.items.ColorItem) DateTimeItem(org.openhab.core.library.items.DateTimeItem) ItemRegistry(org.openhab.core.items.ItemRegistry) DimmerItem(org.openhab.core.library.items.DimmerItem) SwitchItem(org.openhab.core.library.items.SwitchItem) RollershutterItem(org.openhab.core.library.items.RollershutterItem) CallItem(org.openhab.library.tel.items.CallItem) Item(org.openhab.core.items.Item) ColorItem(org.openhab.core.library.items.ColorItem) DateTimeItem(org.openhab.core.library.items.DateTimeItem) StringItem(org.openhab.core.library.items.StringItem) ContactItem(org.openhab.core.library.items.ContactItem) NumberItem(org.openhab.core.library.items.NumberItem) LocationItem(org.openhab.core.library.items.LocationItem) DimmerItem(org.openhab.core.library.items.DimmerItem) RollershutterItem(org.openhab.core.library.items.RollershutterItem) ItemRegistryChangeListener(org.openhab.core.items.ItemRegistryChangeListener) ResourceNotFoundException(com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException) SwitchItem(org.openhab.core.library.items.SwitchItem) ContactItem(org.openhab.core.library.items.ContactItem) ItemNotUniqueException(org.openhab.core.items.ItemNotUniqueException) StringItem(org.openhab.core.library.items.StringItem) NumberItem(org.openhab.core.library.items.NumberItem) Collection(java.util.Collection) CallItem(org.openhab.library.tel.items.CallItem) ItemNotFoundException(org.openhab.core.items.ItemNotFoundException) BeforeClass(org.junit.BeforeClass)

Example 82 with Table

use of com.amazonaws.services.dynamodbv2.document.Table in project camel by apache.

the class ShardIteratorHandlerTest method setup.

@Before
public void setup() throws Exception {
    endpoint.setAmazonDynamoDbStreamsClient(amazonDynamoDBStreams);
    undertest = new ShardIteratorHandler(endpoint);
    when(amazonDynamoDBStreams.listStreams(any(ListStreamsRequest.class))).thenReturn(new ListStreamsResult().withStreams(new Stream().withStreamArn("arn:aws:dynamodb:region:12345:table/table_name/stream/timestamp")));
    when(amazonDynamoDBStreams.describeStream(any(DescribeStreamRequest.class))).thenReturn(new DescribeStreamResult().withStreamDescription(new StreamDescription().withTableName("table_name").withShards(ShardListTest.createShardsWithSequenceNumbers(null, "a", "1", "5", "b", "8", "15", "c", "16", "16", "d", "20", null))));
    when(amazonDynamoDBStreams.getShardIterator(any(GetShardIteratorRequest.class))).thenAnswer(new Answer<GetShardIteratorResult>() {

        @Override
        public GetShardIteratorResult answer(InvocationOnMock invocation) throws Throwable {
            return new GetShardIteratorResult().withShardIterator("shard_iterator_" + ((GetShardIteratorRequest) invocation.getArguments()[0]).getShardId() + "_000");
        }
    });
}
Also used : GetShardIteratorRequest(com.amazonaws.services.dynamodbv2.model.GetShardIteratorRequest) ListStreamsRequest(com.amazonaws.services.dynamodbv2.model.ListStreamsRequest) DescribeStreamRequest(com.amazonaws.services.dynamodbv2.model.DescribeStreamRequest) StreamDescription(com.amazonaws.services.dynamodbv2.model.StreamDescription) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ListStreamsResult(com.amazonaws.services.dynamodbv2.model.ListStreamsResult) GetShardIteratorResult(com.amazonaws.services.dynamodbv2.model.GetShardIteratorResult) Stream(com.amazonaws.services.dynamodbv2.model.Stream) DescribeStreamResult(com.amazonaws.services.dynamodbv2.model.DescribeStreamResult) Before(org.junit.Before)

Example 83 with Table

use of com.amazonaws.services.dynamodbv2.document.Table in project gora by apache.

the class DynamoDBStore method readMapping.

/** 
   * Reads the schema file and converts it into a data structure to be used
   *
   * @return DynamoDBMapping Object containing all necessary information to
   *         create tables
   * @throws IOException
   */
@SuppressWarnings("unchecked")
private DynamoDBMapping readMapping() throws IOException {
    DynamoDBMappingBuilder mappingBuilder = new DynamoDBMappingBuilder();
    try {
        SAXBuilder builder = new SAXBuilder();
        Document doc = builder.build(getClass().getClassLoader().getResourceAsStream(MAPPING_FILE));
        if (doc == null || doc.getRootElement() == null)
            throw new GoraException("Unable to load " + MAPPING_FILE + ". Please check its existance!");
        Element root = doc.getRootElement();
        List<Element> tableElements = root.getChildren("table");
        boolean keys = false;
        for (Element tableElement : tableElements) {
            String tableName = tableElement.getAttributeValue("name");
            long readCapacUnits = Long.parseLong(tableElement.getAttributeValue("readcunit"));
            long writeCapacUnits = Long.parseLong(tableElement.getAttributeValue("writecunit"));
            mappingBuilder.setProvisionedThroughput(tableName, readCapacUnits, writeCapacUnits);
            LOG.debug("Basic table properties have been set: Name, and Provisioned throughput.");
            // Retrieving attributes
            List<Element> fieldElements = tableElement.getChildren("attribute");
            for (Element fieldElement : fieldElements) {
                String key = fieldElement.getAttributeValue("key");
                String attributeName = fieldElement.getAttributeValue("name");
                String attributeType = fieldElement.getAttributeValue("type");
                mappingBuilder.addAttribute(tableName, attributeName, attributeType);
                // Retrieving key's features
                if (key != null) {
                    mappingBuilder.setKeySchema(tableName, attributeName, key);
                    keys = true;
                }
            }
            LOG.debug("Attributes for table '" + tableName + "' have been read.");
            if (!keys)
                LOG.warn("Keys for table '" + tableName + "' have NOT been set.");
        }
    } catch (IOException ex) {
        LOG.error("Error while performing xml mapping.", ex.getMessage());
        throw new IOException(ex);
    } catch (Exception ex) {
        LOG.error("Error while performing xml mapping.", ex.getMessage());
        throw new RuntimeException(ex);
    }
    return mappingBuilder.build();
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) GoraException(org.apache.gora.util.GoraException) KeySchemaElement(com.amazonaws.services.dynamodbv2.model.KeySchemaElement) Element(org.jdom.Element) DynamoDBMappingBuilder(org.apache.gora.dynamodb.store.DynamoDBMapping.DynamoDBMappingBuilder) IOException(java.io.IOException) Document(org.jdom.Document) GoraException(org.apache.gora.util.GoraException) AmazonServiceException(com.amazonaws.AmazonServiceException) IOException(java.io.IOException) ResourceNotFoundException(com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException)

Example 84 with Table

use of com.amazonaws.services.dynamodbv2.document.Table in project cas by apereo.

the class DynamoDbCloudConfigBootstrapConfiguration method createSettingsTable.

@SneakyThrows
private static void createSettingsTable(final AmazonDynamoDB amazonDynamoDBClient, final boolean deleteTables) {
    final String name = ColumnNames.ID.getColumnName();
    final CreateTableRequest request = new CreateTableRequest().withAttributeDefinitions(new AttributeDefinition(name, ScalarAttributeType.S)).withKeySchema(new KeySchemaElement(name, KeyType.HASH)).withProvisionedThroughput(new ProvisionedThroughput(PROVISIONED_THROUGHPUT, PROVISIONED_THROUGHPUT)).withTableName(TABLE_NAME);
    if (deleteTables) {
        final DeleteTableRequest delete = new DeleteTableRequest(request.getTableName());
        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);
}
Also used : DeleteTableRequest(com.amazonaws.services.dynamodbv2.model.DeleteTableRequest) AttributeDefinition(com.amazonaws.services.dynamodbv2.model.AttributeDefinition) ProvisionedThroughput(com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput) DescribeTableRequest(com.amazonaws.services.dynamodbv2.model.DescribeTableRequest) CreateTableRequest(com.amazonaws.services.dynamodbv2.model.CreateTableRequest) TableDescription(com.amazonaws.services.dynamodbv2.model.TableDescription) KeySchemaElement(com.amazonaws.services.dynamodbv2.model.KeySchemaElement) SneakyThrows(lombok.SneakyThrows)

Example 85 with Table

use of com.amazonaws.services.dynamodbv2.document.Table in project cas by apereo.

the class DynamoDbServiceRegistryFacilitator method createServicesTable.

/**
 * Create tables.
 *
 * @param deleteTables the delete tables
 */
@SneakyThrows
public void createServicesTable(final boolean deleteTables) {
    LOGGER.debug("Attempting to create DynamoDb services table");
    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(dynamoDbProperties.getTableName());
    if (deleteTables) {
        final DeleteTableRequest delete = new DeleteTableRequest(request.getTableName());
        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);
}
Also used : DeleteTableRequest(com.amazonaws.services.dynamodbv2.model.DeleteTableRequest) AttributeDefinition(com.amazonaws.services.dynamodbv2.model.AttributeDefinition) ProvisionedThroughput(com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput) DescribeTableRequest(com.amazonaws.services.dynamodbv2.model.DescribeTableRequest) CreateTableRequest(com.amazonaws.services.dynamodbv2.model.CreateTableRequest) TableDescription(com.amazonaws.services.dynamodbv2.model.TableDescription) KeySchemaElement(com.amazonaws.services.dynamodbv2.model.KeySchemaElement) SneakyThrows(lombok.SneakyThrows)

Aggregations

Table (com.amazonaws.services.dynamodbv2.document.Table)63 Item (com.amazonaws.services.dynamodbv2.document.Item)40 AmazonDynamoDB (com.amazonaws.services.dynamodbv2.AmazonDynamoDB)38 AmazonServiceException (com.amazonaws.AmazonServiceException)35 AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)31 KeySchemaElement (com.amazonaws.services.dynamodbv2.model.KeySchemaElement)28 ProvisionedThroughput (com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput)28 IOException (java.io.IOException)24 CreateTableRequest (com.amazonaws.services.dynamodbv2.model.CreateTableRequest)23 DescribeTableRequest (com.amazonaws.services.dynamodbv2.model.DescribeTableRequest)23 ResourceNotFoundException (com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException)23 HashMap (java.util.HashMap)23 AttributeDefinition (com.amazonaws.services.dynamodbv2.model.AttributeDefinition)22 TableDescription (com.amazonaws.services.dynamodbv2.model.TableDescription)22 DynamoDB (com.amazonaws.services.dynamodbv2.document.DynamoDB)17 ValueMap (com.amazonaws.services.dynamodbv2.document.utils.ValueMap)17 ArrayList (java.util.ArrayList)17 AmazonClientException (com.amazonaws.AmazonClientException)14 Test (org.junit.Test)14 QueryOutcome (com.amazonaws.services.dynamodbv2.document.QueryOutcome)10