List of usage examples for com.amazonaws.services.dynamodbv2 AmazonDynamoDBClient AmazonDynamoDBClient
AmazonDynamoDBClient(AwsSyncClientParams clientParams, boolean endpointDiscoveryEnabled)
From source file:com.rapid7.diskstorage.dynamodb.DynamoDBDelegate.java
License:Open Source License
public DynamoDBDelegate(String endpoint, AWSCredentialsProvider provider, ClientConfiguration clientConfig, Configuration titanConfig, Map<String, RateLimiter> readRateLimit, Map<String, RateLimiter> writeRateLimit, long maxRetries, long retryMillis, String prefix, String metricsPrefix, RateLimiter controlPlaneRateLimiter) { if (prefix == null) { throw new IllegalArgumentException("prefix must be set"); }//from w ww . j a v a2s .c o m if (metricsPrefix == null || metricsPrefix.isEmpty()) { throw new IllegalArgumentException("metrics-prefix may not be null or empty"); } this.metricsPrefix = metricsPrefix; executorGaugeName = String.format("%s.%s_executor-queue-size", this.metricsPrefix, prefix); if (clientThreadPool == null) { clientThreadPool = Client.getPoolFromNs(titanConfig); } if (!MetricManager.INSTANCE.getRegistry().getNames().contains(executorGaugeName)) { MetricManager.INSTANCE.getRegistry().register(executorGaugeName, new Gauge<Integer>() { @Override public Integer getValue() { return clientThreadPool.getQueue().size(); } }); } if (endpoint != null && !endpoint.isEmpty()) { client = new AmazonDynamoDBClient(provider, clientConfig); client.setEndpoint(endpoint); } else { throw new IllegalArgumentException("must provide an endpoint URL"); } this.readRateLimit = readRateLimit; this.writeRateLimit = writeRateLimit; this.controlPlaneRateLimiter = controlPlaneRateLimiter; this.maxConcurrentUsers = titanConfig.get(Constants.DYNAMODB_CLIENT_EXECUTOR_MAX_CONCURRENT_OPERATIONS); this.maxRetries = maxRetries; this.retryMillis = retryMillis; if (maxConcurrentUsers < 1) { throw new IllegalArgumentException("need at least one user otherwise wont make progress on scan"); } this.listTablesApiName = String.format("%s_ListTables", prefix); }
From source file:edu.utn.frba.grupo5303.serverenviolibre.repository.CalificacionDAODynamo.java
public CalificacionDAODynamo() { String regionName = "us-west-2"; Region region = Region.getRegion(Regions.fromName(regionName)); ClientConfiguration clientConfiguration = new ClientConfiguration().withMaxErrorRetry(20); ddb = new AmazonDynamoDBClient(new ProfileCredentialsProvider(), clientConfiguration); ddb.setRegion(region);/* ww w . j av a2 s.co m*/ mapper = new DynamoDBMapper(ddb); }
From source file:edu.utn.frba.grupo5303.serverenviolibre.repository.FacturasDAODynamo.java
public FacturasDAODynamo() { String regionName = "us-west-2"; Region region = Region.getRegion(Regions.fromName(regionName)); ClientConfiguration clientConfiguration = new ClientConfiguration().withMaxErrorRetry(20); ddb = new AmazonDynamoDBClient(new ProfileCredentialsProvider(), clientConfiguration); ddb.setRegion(region);/* w ww . ja va2 s . com*/ mapper = new DynamoDBMapper(ddb); }
From source file:edu.utn.frba.grupo5303.serverenviolibre.repository.ImagenUsuarioDAODynamo.java
public ImagenUsuarioDAODynamo() { String regionName = "us-west-2"; Region region = Region.getRegion(Regions.fromName(regionName)); ClientConfiguration clientConfiguration = new ClientConfiguration().withMaxErrorRetry(20); ddb = new AmazonDynamoDBClient(new ProfileCredentialsProvider(), clientConfiguration); ddb.setRegion(region);// ww w.ja v a 2 s. c om mapper = new DynamoDBMapper(ddb); }
From source file:edu.utn.frba.grupo5303.serverenviolibre.services.GeoPosicionamientoPublicacionesService.java
private void setupGeoDataManager() { String tableName = "Posicion"; String regionName = "us-west-2"; Region region = Region.getRegion(Regions.fromName(regionName)); ClientConfiguration clientConfiguration = new ClientConfiguration().withMaxErrorRetry(20); AmazonDynamoDBClient ddb = new AmazonDynamoDBClient(new ProfileCredentialsProvider(), clientConfiguration); ddb.setRegion(region);//www.jav a2 s.c om config = new GeoDataManagerConfiguration(ddb, tableName); geoDataManager = new GeoDataManager(config); }
From source file:edu.utn.frba.grupo5303.serverenviolibre.services.GeoPosicionamientoUsuariosService.java
private void setupGeoDataManager() { String tableName = "PosicionUsuarios"; String regionName = "us-west-2"; Region region = Region.getRegion(Regions.fromName(regionName)); ClientConfiguration clientConfiguration = new ClientConfiguration().withMaxErrorRetry(20); AmazonDynamoDBClient ddb = new AmazonDynamoDBClient(new ProfileCredentialsProvider(), clientConfiguration); ddb.setRegion(region);/*from w w w. j av a2 s. co m*/ config = new GeoDataManagerConfiguration(ddb, tableName); geoDataManager = new GeoDataManager(config); }
From source file:eu.roschi.obdkinesis.HttpReferrerCounterApplication.java
License:Open Source License
/** * Start the Kinesis Client application. * //from www. j a v a 2s. c o m * @param args Expecting 4 arguments: Application name to use for the Kinesis Client Application, Stream name to * read from, DynamoDB table name to persist counts into, and the AWS region in which these resources * exist or should be created. */ public static void main(String[] args) throws UnknownHostException { if (args.length != 2) { System.err.println("Using default values"); COMPUTE_RANGE_FOR_COUNTS_IN_MILLIS = 30000; COMPUTE_INTERVAL_IN_MILLIS = 2000; } else { COMPUTE_RANGE_FOR_COUNTS_IN_MILLIS = Integer.parseInt(args[0]); COMPUTE_INTERVAL_IN_MILLIS = Integer.parseInt(args[1]); System.err.println( "Using values " + Integer.parseInt(args[0]) + " width " + Integer.parseInt(args[1]) + " rate"); } String applicationName = "obd_kinesis"; String streamName = "obd_input_stream"; String countsTableName = "obd_kinesis_count"; Region region = SampleUtils.parseRegion("us-west-2"); AWSCredentialsProvider credentialsProvider = new DefaultAWSCredentialsProviderChain(); ClientConfiguration clientConfig = SampleUtils.configureUserAgentForSample(new ClientConfiguration()); AmazonKinesis kinesis = new AmazonKinesisClient(credentialsProvider, clientConfig); kinesis.setRegion(region); AmazonDynamoDB dynamoDB = new AmazonDynamoDBClient(credentialsProvider, clientConfig); dynamoDB.setRegion(region); // Creates a stream to write to, if it doesn't exist StreamUtils streamUtils = new StreamUtils(kinesis); streamUtils.createStreamIfNotExists(streamName, 2); LOG.info(String.format("%s stream is ready for use", streamName)); DynamoDBUtils dynamoDBUtils = new DynamoDBUtils(dynamoDB); dynamoDBUtils.createCountTableIfNotExists(countsTableName); LOG.info(String.format("%s DynamoDB table is ready for use", countsTableName)); String workerId = String.valueOf(UUID.randomUUID()); LOG.info(String.format("Using working id: %s", workerId)); KinesisClientLibConfiguration kclConfig = new KinesisClientLibConfiguration(applicationName, streamName, credentialsProvider, workerId); kclConfig.withCommonClientConfig(clientConfig); kclConfig.withRegionName(region.getName()); kclConfig.withInitialPositionInStream(InitialPositionInStream.LATEST); // Persist counts to DynamoDB DynamoDBCountPersister persister = new DynamoDBCountPersister( dynamoDBUtils.createMapperForTable(countsTableName)); IRecordProcessorFactory recordProcessor = new CountingRecordProcessorFactory<HttpReferrerPair>( HttpReferrerPair.class, persister, COMPUTE_RANGE_FOR_COUNTS_IN_MILLIS, COMPUTE_INTERVAL_IN_MILLIS); Worker worker = new Worker(recordProcessor, kclConfig); int exitCode = 0; try { worker.run(); } catch (Throwable t) { LOG.error("Caught throwable while processing data.", t); exitCode = 1; } System.exit(exitCode); }
From source file:eu.roschi.obdkinesis.WebServer.java
License:Open Source License
/** * Start an embedded web server./*from w w w . j ava 2s . c o m*/ * * @param args Expecting 4 arguments: Port number, File path to static content, the name of the * DynamoDB table where counts are persisted to, and the AWS region in which these resources * exist or should be created. * @throws Exception Error starting the web server. */ public static void main(String[] args) throws Exception { if (args.length != 1) { System.err.println("Usage: " + WebServer.class + " <directory for static content>"); System.exit(1); } Server server = new Server(8080); String wwwroot = args[0]; String countsTableName = "obd_kinesis_count"; Region region = SampleUtils.parseRegion("us-west-2"); // Servlet context ServletContextHandler context = new ServletContextHandler( ServletContextHandler.NO_SESSIONS | ServletContextHandler.NO_SECURITY); context.setContextPath("/api"); // Static resource context ResourceHandler resources = new ResourceHandler(); resources.setDirectoriesListed(false); resources.setWelcomeFiles(new String[] { "graph.html" }); resources.setResourceBase(wwwroot); // Create the servlet to handle /GetCounts AWSCredentialsProvider credentialsProvider = new DefaultAWSCredentialsProviderChain(); ClientConfiguration clientConfig = SampleUtils.configureUserAgentForSample(new ClientConfiguration()); AmazonDynamoDB dynamoDB = new AmazonDynamoDBClient(credentialsProvider, clientConfig); dynamoDB.setRegion(region); DynamoDBUtils dynamoDBUtils = new DynamoDBUtils(dynamoDB); context.addServlet( new ServletHolder(new GetCountsServlet(dynamoDBUtils.createMapperForTable(countsTableName))), "/GetCounts/*"); HandlerList handlers = new HandlerList(); handlers.addHandler(context); handlers.addHandler(resources); handlers.addHandler(new DefaultHandler()); server.setHandler(handlers); server.start(); server.join(); }
From source file:lumbermill.aws.kcl.internal.KinesisConsumerBootstrap.java
License:Apache License
public void start() { int mb = 1024 * 1024; LOG.info("Max memory: {} mb", Runtime.getRuntime().maxMemory() / mb); LOG.info("Starting up Kinesis Consumer... (may take a few seconds)"); AmazonKinesisClient kinesisClient = new AmazonKinesisClient(kinesisCfg.getKinesisCredentialsProvider(), kinesisCfg.getKinesisClientConfiguration()); AmazonDynamoDBClient dynamoDBClient = new AmazonDynamoDBClient(kinesisCfg.getDynamoDBCredentialsProvider(), kinesisCfg.getDynamoDBClientConfiguration()); AmazonCloudWatch cloudWatchClient = new AmazonCloudWatchClient( kinesisCfg.getCloudWatchCredentialsProvider(), kinesisCfg.getCloudWatchClientConfiguration()); Worker worker = new Worker.Builder() .recordProcessorFactory(//from w w w . ja v a2s.c o m () -> new RecordProcessor(unitOfWorkListener, exceptionStrategy, metricsCallback, dry)) .config(kinesisCfg).kinesisClient(kinesisClient).dynamoDBClient(dynamoDBClient) .cloudWatchClient(cloudWatchClient).build(); worker.run(); }
From source file:org.apache.hadoop.dynamodb.DynamoDBClient.java
License:Open Source License
private AmazonDynamoDBClient getDynamoDBClient(Configuration conf) { ClientConfiguration clientConfig = new ClientConfiguration().withMaxErrorRetry(1); applyProxyConfiguration(clientConfig, conf); return new AmazonDynamoDBClient(getAWSCredentialsProvider(conf), clientConfig); }