Skip to content

Commit 0da5f82

Browse files
committed
Merge pull request #104 from basho/BR-add-status
Br add status
2 parents 3cabc61 + ee66d0f commit 0da5f82

File tree

18 files changed

+1798
-20
lines changed

18 files changed

+1798
-20
lines changed

pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
<name>Russell Brown</name>
3434
<email>russelldb@basho.com</email>
3535
</developer>
36+
<developer>
37+
<name>Brian Roach</name>
38+
<email>roach@basho.com</email>
39+
</developer>
3640
</developers>
3741

3842
<scm>

src/main/java/com/basho/riak/client/DefaultRiakClient.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
import com.basho.riak.client.query.BucketKeyMapReduce;
1414
import com.basho.riak.client.query.BucketMapReduce;
1515
import com.basho.riak.client.query.IndexMapReduce;
16-
import com.basho.riak.client.query.LinkWalk;
1716
import com.basho.riak.client.query.SearchMapReduce;
17+
import com.basho.riak.client.query.LinkWalk;
18+
import com.basho.riak.client.query.NodeStats;
1819
import com.basho.riak.client.raw.RawClient;
1920
import com.basho.riak.client.raw.Transport;
2021
import com.basho.riak.client.raw.http.HTTPClientAdapter;
@@ -220,4 +221,15 @@ public Transport getTransport() {
220221
public void shutdown(){
221222
rawClient.shutdown();
222223
}
224+
225+
/* (non-Javadoc)
226+
* @see com.basho.riak.client.IRiakClient#stats()
227+
*/
228+
public Iterable<NodeStats> stats() throws RiakException {
229+
try {
230+
return rawClient.stats();
231+
} catch (Exception e) {
232+
throw new RiakException(e);
233+
}
234+
}
223235
}

src/main/java/com/basho/riak/client/IRiakClient.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,11 @@
1919
import com.basho.riak.client.bucket.FetchBucket;
2020
import com.basho.riak.client.bucket.WriteBucket;
2121
import com.basho.riak.client.cap.ClientId;
22-
import com.basho.riak.client.query.BucketKeyMapReduce;
23-
import com.basho.riak.client.query.BucketMapReduce;
24-
import com.basho.riak.client.query.IndexMapReduce;
25-
import com.basho.riak.client.query.LinkWalk;
26-
import com.basho.riak.client.query.MapReduce;
27-
import com.basho.riak.client.query.SearchMapReduce;
22+
import com.basho.riak.client.query.*;
2823
import com.basho.riak.client.query.indexes.FetchIndex;
2924
import com.basho.riak.client.raw.Transport;
3025
import com.basho.riak.client.raw.query.indexes.IndexQuery;
26+
import java.util.Iterator;
3127

3228
/**
3329
* Primary high-level interface for accessing Riak.
@@ -207,4 +203,17 @@ public interface IRiakClient {
207203
Transport getTransport();
208204

209205
void shutdown();
206+
207+
/**
208+
*
209+
* Perform the Riak <code>/stats</code> operation on the node(s) this client
210+
* is connected to.
211+
* <p>
212+
* <b>This is not supported by the Riak Protobuf API</b>
213+
* <p>
214+
* @return an {@link Iterable} object that contains one or more {@link NodeStats}
215+
*
216+
* @throws RiakException If Riak does not respond or if the protobuf API is being used
217+
*/
218+
Iterable<NodeStats> stats() throws RiakException;
210219
}

src/main/java/com/basho/riak/client/http/RiakClient.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,16 @@ public HttpResponse ping() {
498498
return helper.ping();
499499
}
500500

501+
/**
502+
* GET Riak's <code>/stats</code> (status) resource.
503+
*
504+
* @return an {@link HttpResponse} with the result of GET
505+
*/
506+
public HttpResponse stats() {
507+
return helper.stats();
508+
}
509+
510+
501511
/**
502512
* Fetch the keys for <code>index</code> with <code>value</code>
503513
*

src/main/java/com/basho/riak/client/http/RiakConfig.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public class RiakConfig {
3232
private String baseUrl = null;
3333
private String mapredPath = "/mapred";
3434
private String pingPath = "/ping";
35+
private String statsPath = "/stats";
3536
private HttpClient httpClient = null;
3637
private Integer timeout = null;
3738
private Integer maxConnections = null;
@@ -105,6 +106,14 @@ public String getPingUrl() {
105106
return baseUrl + pingPath;
106107
}
107108

109+
/**
110+
* The full URL of the Riak status (stats) resource, which is calculated by
111+
* combining the host and port from the Riak URL and the stats path.
112+
*/
113+
public String getStatsUrl() {
114+
return baseUrl + statsPath;
115+
}
116+
108117
/**
109118
* The host and port of the Riak server, which is extracted from the
110119
* specified Riak URL.

src/main/java/com/basho/riak/client/http/util/ClientHelper.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,17 @@ public RiakExceptionHandler getExceptionHandler() {
351351
return exceptionHandler;
352352
}
353353

354+
/**
355+
* Same as {@link RiakClient#stats}
356+
*
357+
* @return an {@link HttpResponse} whose body should be the result of asking
358+
* Riak for its stats (status).
359+
*/
360+
public HttpResponse stats() {
361+
HttpGet get = new HttpGet(config.getStatsUrl());
362+
return executeMethod(null, null, get, null);
363+
}
364+
354365
/**
355366
* Install an exception handler. If an exception handler is provided, then
356367
* the Riak client will hand exceptions to the handler rather than throwing

0 commit comments

Comments
 (0)