Search in sources :

Example 6 with ResourceNotFoundException

use of com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException in project gora by apache.

the class DynamoDBUtils method waitForTableToBecomeAvailable.

/**
   * Waits up to 6 minutes to confirm if a table has been created or not
   * 
   * @param awsClient
   * @param tableName
   */
public static void waitForTableToBecomeAvailable(AmazonDynamoDB awsClient, String tableName) {
    LOG.debug("Waiting for {} to become available", tableName);
    long startTime = System.currentTimeMillis();
    long endTime = startTime + WAIT_TIME;
    while (System.currentTimeMillis() < endTime) {
        try {
            Thread.sleep(SLEEP_TIME);
        } catch (Exception e) {
        }
        try {
            DescribeTableRequest request = new DescribeTableRequest().withTableName(tableName);
            TableDescription tableDescription = awsClient.describeTable(request).getTable();
            String tableStatus = tableDescription.getTableStatus();
            LOG.debug("{} - current state: {}", tableName, tableStatus);
            if (tableStatus.equals(TableStatus.ACTIVE.toString()))
                return;
        } catch (AmazonServiceException ase) {
            if (ase.getErrorCode().equalsIgnoreCase("ResourceNotFoundException") == false)
                throw ase;
        }
    }
    throw new RuntimeException("Table " + tableName + " never became active");
}
Also used : AmazonServiceException(com.amazonaws.AmazonServiceException) DescribeTableRequest(com.amazonaws.services.dynamodbv2.model.DescribeTableRequest) TableDescription(com.amazonaws.services.dynamodbv2.model.TableDescription) ResourceInUseException(com.amazonaws.services.dynamodbv2.model.ResourceInUseException) AmazonServiceException(com.amazonaws.AmazonServiceException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 7 with ResourceNotFoundException

use of com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException in project aws-doc-sdk-examples by awsdocs.

the class PutItem method main.

public static void main(String[] args) {
    final String USAGE = "\n" + "Usage:\n" + "    PutItem <table> <name> [field=value ...]\n\n" + "Where:\n" + "    table    - the table to put the item in.\n" + "    name     - a name to add to the table. If the name already\n" + "               exists, its entry will be updated.\n" + "Additional fields can be added by appending them to the end of the\n" + "input.\n\n" + "Example:\n" + "    PutItem Cellists Pau Language=ca Born=1876\n";
    if (args.length < 2) {
        System.out.println(USAGE);
        System.exit(1);
    }
    String table_name = args[0];
    String name = args[1];
    ArrayList<String[]> extra_fields = new ArrayList<String[]>();
    // any additional args (fields to add to database)?
    for (int x = 2; x < args.length; x++) {
        String[] fields = args[x].split("=", 2);
        if (fields.length == 2) {
            extra_fields.add(fields);
        } else {
            System.out.format("Invalid argument: %s\n", args[x]);
            System.out.println(USAGE);
            System.exit(1);
        }
    }
    System.out.format("Adding \"%s\" to \"%s\"", name, table_name);
    if (extra_fields.size() > 0) {
        System.out.println("Additional fields:");
        for (String[] field : extra_fields) {
            System.out.format("  %s: %s\n", field[0], field[1]);
        }
    }
    HashMap<String, AttributeValue> item_values = new HashMap<String, AttributeValue>();
    item_values.put("Name", new AttributeValue(name));
    for (String[] field : extra_fields) {
        item_values.put(field[0], new AttributeValue(field[1]));
    }
    final AmazonDynamoDB ddb = AmazonDynamoDBClientBuilder.defaultClient();
    try {
        ddb.putItem(table_name, item_values);
    } catch (ResourceNotFoundException e) {
        System.err.format("Error: The table \"%s\" can't be found.\n", table_name);
        System.err.println("Be sure that it exists and that you've typed its name correctly!");
        System.exit(1);
    } catch (AmazonServiceException e) {
        System.err.println(e.getMessage());
        System.exit(1);
    }
    System.out.println("Done!");
}
Also used : AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AmazonServiceException(com.amazonaws.AmazonServiceException) AmazonDynamoDB(com.amazonaws.services.dynamodbv2.AmazonDynamoDB) ResourceNotFoundException(com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException)

Example 8 with ResourceNotFoundException

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

use of com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException in project gora by apache.

the class DynamoDBStore method getTableSchema.

/**
   * Retrieves the table description for the specific resource name
   * 
   * @param tableName
   * @return
   */
private TableDescription getTableSchema(String tableName) {
    TableDescription tableDescription = null;
    try {
        DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(tableName);
        tableDescription = getDynamoDBClient().describeTable(describeTableRequest).getTable();
    } catch (ResourceNotFoundException e) {
        LOG.error("Error while getting table schema: " + tableName);
        return tableDescription;
    }
    return tableDescription;
}
Also used : DescribeTableRequest(com.amazonaws.services.dynamodbv2.model.DescribeTableRequest) ResourceNotFoundException(com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException) TableDescription(com.amazonaws.services.dynamodbv2.model.TableDescription)

Example 10 with ResourceNotFoundException

use of com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException in project gora by apache.

the class GoraDynamoDBTestDriver method checkResource.

/**
   * Checks if a resource exists or not
   * 
   * @param tableName
   *          Table name to be checked
   * @return
   */
public TableDescription checkResource(String tableName) {
    TableDescription tableDescription = null;
    try {
        DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(tableName);
        tableDescription = dynamoDBClient.describeTable(describeTableRequest).getTable();
    } catch (ResourceNotFoundException e) {
        tableDescription = null;
    }
    return tableDescription;
}
Also used : DescribeTableRequest(com.amazonaws.services.dynamodbv2.model.DescribeTableRequest) ResourceNotFoundException(com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException) TableDescription(com.amazonaws.services.dynamodbv2.model.TableDescription)

Aggregations

ResourceNotFoundException (com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException)10 TableDescription (com.amazonaws.services.dynamodbv2.model.TableDescription)7 DescribeTableRequest (com.amazonaws.services.dynamodbv2.model.DescribeTableRequest)6 AmazonServiceException (com.amazonaws.AmazonServiceException)5 HashMap (java.util.HashMap)3 AmazonDynamoDB (com.amazonaws.services.dynamodbv2.AmazonDynamoDB)2 AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 AmazonClientException (com.amazonaws.AmazonClientException)1 AttributeValueUpdate (com.amazonaws.services.dynamodbv2.model.AttributeValueUpdate)1 CreateTableRequest (com.amazonaws.services.dynamodbv2.model.CreateTableRequest)1 DescribeTableResult (com.amazonaws.services.dynamodbv2.model.DescribeTableResult)1 GlobalSecondaryIndex (com.amazonaws.services.dynamodbv2.model.GlobalSecondaryIndex)1 KeySchemaElement (com.amazonaws.services.dynamodbv2.model.KeySchemaElement)1 ProvisionedThroughput (com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput)1 ProvisionedThroughputDescription (com.amazonaws.services.dynamodbv2.model.ProvisionedThroughputDescription)1 ResourceInUseException (com.amazonaws.services.dynamodbv2.model.ResourceInUseException)1 FileNotFoundException (java.io.FileNotFoundException)1 Collection (java.util.Collection)1