ViPR S3 Smart Client

In the 2.0 release of the ViPR Services Java SDK, the ViPR S3 client now supports auto-discovery of cluster nodes and client-side load balancing and failover.  This is made possible by the new list-data-nodes call (?endpoint).  List-data-nodes will return a list of all active ViPR Services nodes that belong to the ViPR cluster.


To enable the smart client, pass a ViPRConfig instance to the constructor of ViPRS3Client like so:

 

BasicAWSCredentials creds = new BasicAWSCredentials(accessKey, secretKey);

ViPRS3Config viprConfig = new ViPRS3Config();
viprConfig.withS3Endpoints("http://vipr-ds1.company.com:9020,http://vipr-ds2.company.com:9020");
viprConfig.setCredentialsProvider(new StaticCredentialsProvider(creds));
   
AmazonS3 s3 = new ViPRS3Client(viprConfig);
ViPRS3 viprS3 = (ViPRS3) s3; // cast to ViPRS3 to use ViPR S3 extensions




 

That’s it!  Just use the resulting client normally.  Note that line 4 specifies a list of seed nodes or hints to start with.  The smart client will then poll the cluster for the complete list of nodes and update it periodically. It will also track response times for each node and whether or not a node is down, removing it from the list temporarily until it comes back up.

 

In fact, since it leverages the Ribbon framework, you can access the load balancing statistics as an instance of LoadBalancerStats like this:

 

LoadBalancerStats lbStats = ((ViPRS3Client) viprS3).getLoadBalancerStats();
System.out.println(lbStats); // toString() creates a nice summary




 

It’s important to note that since the smart client uses client-side load balancing, you must use S3 path-style requests, which are enabled by default with this constructor.