public void setupTable() { setupGeoDataManager(); GeoDataManagerConfiguration config = geoDataManager.getGeoDataManagerConfiguration(); DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(config.getTableName()); try { config.getDynamoDBClient().describeTable(describeTableRequest); if (status == Status.NOT_STARTED) { status = Status.READY; } } catch (ResourceNotFoundException e) { PhotoLocationsTable photoLocationsTable = new PhotoLocationsTable(); photoLocationsTable.start(); } }
public void setupTable() { setupGeoDataManager(); GeoDataManagerConfiguration config = geoDataManager.getGeoDataManagerConfiguration(); DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(config.getTableName()); try { config.getDynamoDBClient().describeTable(describeTableRequest); if (status == Status.NOT_STARTED) { status = Status.READY; } } catch (ResourceNotFoundException e) { SchoolDataLoader schoolDataLoader = new SchoolDataLoader(); schoolDataLoader.start(); } }
private void waitForTableToBeReady() { GeoDataManagerConfiguration config = geoDataManager.getGeoDataManagerConfiguration(); DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(config.getTableName()); DescribeTableResult describeTableResult = config.getDynamoDBClient().describeTable(describeTableRequest); while (!describeTableResult.getTable().getTableStatus().equalsIgnoreCase("ACTIVE")) { try { Thread.sleep(2000); } catch (InterruptedException e) { throw new RuntimeException(e); } describeTableResult = config.getDynamoDBClient().describeTable(describeTableRequest); } }
public boolean tryMerge(GeohashRange range) { if (range.getRangeMin() - this.rangeMax <= GeoDataManagerConfiguration.MERGE_THRESHOLD && range.getRangeMin() - this.rangeMax > 0) { this.rangeMax = range.getRangeMax(); return true; } if (this.rangeMin - range.getRangeMax() <= GeoDataManagerConfiguration.MERGE_THRESHOLD && this.rangeMin - range.getRangeMax() > 0) { this.rangeMin = range.getRangeMin(); return true; } return false; }
/** * <p> * Construct a create table request object based on GeoDataManagerConfiguration. The users can update any aspect of * the request and call it. * </p> * Example: * * <pre> * AmazonDynamoDBClient ddb = new AmazonDynamoDBClient(new ClasspathPropertiesFileCredentialsProvider()); * Region usWest2 = Region.getRegion(Regions.US_WEST_2); * ddb.setRegion(usWest2); * * CreateTableRequest createTableRequest = GeoTableUtil.getCreateTableRequest(config); * CreateTableResult createTableResult = ddb.createTable(createTableRequest); * </pre> * * @return Generated create table request. */ public static CreateTableRequest getCreateTableRequest(GeoDataManagerConfiguration config) { CreateTableRequest createTableRequest = new CreateTableRequest() .withTableName(config.getTableName()) .withProvisionedThroughput( new ProvisionedThroughput().withReadCapacityUnits(10L).withWriteCapacityUnits(5L)) .withKeySchema( new KeySchemaElement().withKeyType(KeyType.HASH).withAttributeName( config.getHashKeyAttributeName()), new KeySchemaElement().withKeyType(KeyType.RANGE).withAttributeName( config.getRangeKeyAttributeName())) .withAttributeDefinitions( new AttributeDefinition().withAttributeType(ScalarAttributeType.N).withAttributeName( config.getHashKeyAttributeName()), new AttributeDefinition().withAttributeType(ScalarAttributeType.S).withAttributeName( config.getRangeKeyAttributeName()), new AttributeDefinition().withAttributeType(ScalarAttributeType.N).withAttributeName( config.getGeohashAttributeName())) .withLocalSecondaryIndexes( new LocalSecondaryIndex() .withIndexName(config.getGeohashIndexName()) .withKeySchema( new KeySchemaElement().withKeyType(KeyType.HASH).withAttributeName( config.getHashKeyAttributeName()), new KeySchemaElement().withKeyType(KeyType.RANGE).withAttributeName( config.getGeohashAttributeName())) .withProjection(new Projection().withProjectionType(ProjectionType.ALL))); return createTableRequest; }
private void setupGeoDataManager() { String accessKey = System.getProperty("AWS_ACCESS_KEY_ID"); String secretKey = System.getProperty("AWS_SECRET_KEY"); String tableName = System.getProperty("PARAM1"); String regionName = System.getProperty("PARAM2"); AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey); AmazonDynamoDBClient ddb = new AmazonDynamoDBClient(credentials); Region region = Region.getRegion(Regions.fromName(regionName)); ddb.setRegion(region); config = new GeoDataManagerConfiguration(ddb, tableName); geoDataManager = new GeoDataManager(config); }
public DynamoGeoService createDynamoGeoService(String tableName) { GeoDataManagerConfiguration config = new GeoDataManagerConfiguration(createDynamoClient(), tableName); return new DynamoGeoService(new GeoDataManager(config)); }
private GeoDataManagerConfiguration config() { return geoDataManager.getGeoDataManagerConfiguration(); }
public DynamoDBManager(GeoDataManagerConfiguration config) { this.config = config; }
public void run() { status = Status.CREATING_TABLE; GeoDataManagerConfiguration config = geoDataManager.getGeoDataManagerConfiguration(); CreateTableRequest createTableRequest = GeoTableUtil.getCreateTableRequest(config); config.getDynamoDBClient().createTable(createTableRequest); waitForTableToBeReady(); }
public void run() { status = Status.CREATING_TABLE; GeoDataManagerConfiguration config = geoDataManager.getGeoDataManagerConfiguration(); CreateTableRequest createTableRequest = GeoTableUtil.getCreateTableRequest(config); config.getDynamoDBClient().createTable(createTableRequest); waitForTableToBeReady(); insertData(); }