fixed Java API docs

- wrote an intro where we tell how to get the watcher jar and we tall about the `WatcherClient`
- cleaned up the code snippets
- removed a reference to the `Watch.Parser`

- Also renamed `WatcherStatsResponse#getWatchServiceState` to `watcherStatsResponse.getWatcherState`

Original commit: elastic/x-pack-elasticsearch@814329cba7
This commit is contained in:
uboness 2015-05-06 02:51:26 +02:00
parent 5ecf1dbdcd
commit 1a9db6140a
7 changed files with 26 additions and 26 deletions

View File

@ -35,7 +35,7 @@ public class RestWatcherStatsAction extends WatcherRestHandler {
@Override @Override
public RestResponse buildResponse(WatcherStatsResponse watcherStatsResponse, XContentBuilder builder) throws Exception { public RestResponse buildResponse(WatcherStatsResponse watcherStatsResponse, XContentBuilder builder) throws Exception {
builder.startObject(); builder.startObject();
builder.field("watcher_state", watcherStatsResponse.getWatchServiceState().toString().toLowerCase(Locale.ROOT)) builder.field("watcher_state", watcherStatsResponse.getWatcherState().toString().toLowerCase(Locale.ROOT))
.field("watch_count", watcherStatsResponse.getWatchesCount()); .field("watch_count", watcherStatsResponse.getWatchesCount());
builder.startObject("execution_queue") builder.startObject("execution_queue")

View File

@ -58,7 +58,7 @@ public class TransportWatcherStatsAction extends WatcherTransportAction<WatcherS
@Override @Override
protected void masterOperation(WatcherStatsRequest request, ClusterState state, ActionListener<WatcherStatsResponse> listener) throws ElasticsearchException { protected void masterOperation(WatcherStatsRequest request, ClusterState state, ActionListener<WatcherStatsResponse> listener) throws ElasticsearchException {
WatcherStatsResponse statsResponse = new WatcherStatsResponse(); WatcherStatsResponse statsResponse = new WatcherStatsResponse();
statsResponse.setWatchServiceState(watcherService.state()); statsResponse.setWatcherState(watcherService.state());
statsResponse.setWatchExecutionQueueSize(executionService.queueSize()); statsResponse.setWatchExecutionQueueSize(executionService.queueSize());
statsResponse.setWatchesCount(watcherService.watchesCount()); statsResponse.setWatchesCount(watcherService.watchesCount());
statsResponse.setWatchExecutionQueueMaxSize(executionService.largestQueueSize()); statsResponse.setWatchExecutionQueueMaxSize(executionService.largestQueueSize());

View File

@ -19,7 +19,7 @@ public class WatcherStatsResponse extends ActionResponse {
private WatcherVersion version; private WatcherVersion version;
private WatcherBuild build; private WatcherBuild build;
private long watchesCount; private long watchesCount;
private WatcherState watchServiceState; private WatcherState watcherState;
private long watchExecutionQueueSize; private long watchExecutionQueueSize;
private long watchExecutionQueueMaxSize; private long watchExecutionQueueMaxSize;
@ -62,12 +62,12 @@ public class WatcherStatsResponse extends ActionResponse {
/** /**
* @return The state of the watch service. * @return The state of the watch service.
*/ */
public WatcherState getWatchServiceState() { public WatcherState getWatcherState() {
return watchServiceState; return watcherState;
} }
void setWatchServiceState(WatcherState watcherServiceState) { void setWatcherState(WatcherState watcherServiceState) {
this.watchServiceState = watcherServiceState; this.watcherState = watcherServiceState;
} }
/** /**
@ -98,7 +98,7 @@ public class WatcherStatsResponse extends ActionResponse {
watchesCount = in.readLong(); watchesCount = in.readLong();
watchExecutionQueueSize = in.readLong(); watchExecutionQueueSize = in.readLong();
watchExecutionQueueMaxSize = in.readLong(); watchExecutionQueueMaxSize = in.readLong();
watchServiceState = WatcherState.fromId(in.readByte()); watcherState = WatcherState.fromId(in.readByte());
version = WatcherVersion.readVersion(in); version = WatcherVersion.readVersion(in);
build = WatcherBuild.readBuild(in); build = WatcherBuild.readBuild(in);
} }
@ -109,7 +109,7 @@ public class WatcherStatsResponse extends ActionResponse {
out.writeLong(watchesCount); out.writeLong(watchesCount);
out.writeLong(watchExecutionQueueSize); out.writeLong(watchExecutionQueueSize);
out.writeLong(watchExecutionQueueMaxSize); out.writeLong(watchExecutionQueueMaxSize);
out.writeByte(watchServiceState.getId()); out.writeByte(watcherState.getId());
WatcherVersion.writeVersion(version, out); WatcherVersion.writeVersion(version, out);
WatcherBuild.writeBuild(build, out); WatcherBuild.writeBuild(build, out);
} }

View File

@ -185,14 +185,14 @@ public abstract class AbstractWatcherIntegrationTests extends ElasticsearchInteg
private void startWatcherIfNodesExist() throws Exception { private void startWatcherIfNodesExist() throws Exception {
if (internalTestCluster().size() > 0) { if (internalTestCluster().size() > 0) {
WatcherStatsResponse response = watcherClient().prepareWatcherStats().get(); WatcherStatsResponse response = watcherClient().prepareWatcherStats().get();
if (response.getWatchServiceState() == WatcherState.STOPPED) { if (response.getWatcherState() == WatcherState.STOPPED) {
logger.info("[{}#{}]: starting watcher", getTestClass().getSimpleName(), getTestName()); logger.info("[{}#{}]: starting watcher", getTestClass().getSimpleName(), getTestName());
startWatcher(); startWatcher();
} else if (response.getWatchServiceState() == WatcherState.STARTING) { } else if (response.getWatcherState() == WatcherState.STARTING) {
logger.info("[{}#{}]: watcher is starting, waiting for it to get in a started state", getTestClass().getSimpleName(), getTestName()); logger.info("[{}#{}]: watcher is starting, waiting for it to get in a started state", getTestClass().getSimpleName(), getTestName());
ensureWatcherStarted(false); ensureWatcherStarted(false);
} else { } else {
logger.info("[{}#{}]: not starting watcher, because watcher is in state [{}]", getTestClass().getSimpleName(), getTestName(), response.getWatchServiceState()); logger.info("[{}#{}]: not starting watcher, because watcher is in state [{}]", getTestClass().getSimpleName(), getTestName(), response.getWatcherState());
} }
} else { } else {
logger.info("[{}#{}]: not starting watcher, because test cluster has no nodes", getTestClass().getSimpleName(), getTestName()); logger.info("[{}#{}]: not starting watcher, because test cluster has no nodes", getTestClass().getSimpleName(), getTestName());
@ -403,7 +403,7 @@ public abstract class AbstractWatcherIntegrationTests extends ElasticsearchInteg
@Override @Override
public void run() { public void run() {
if (useClient) { if (useClient) {
assertThat(watcherClient().prepareWatcherStats().get().getWatchServiceState(), is(WatcherState.STARTED)); assertThat(watcherClient().prepareWatcherStats().get().getWatcherState(), is(WatcherState.STARTED));
} else { } else {
assertThat(getInstanceFromMaster(WatcherService.class).state(), is(WatcherState.STARTED)); assertThat(getInstanceFromMaster(WatcherService.class).state(), is(WatcherState.STARTED));
} }
@ -431,7 +431,7 @@ public abstract class AbstractWatcherIntegrationTests extends ElasticsearchInteg
@Override @Override
public void run() { public void run() {
if (useClient) { if (useClient) {
assertThat(watcherClient().prepareWatcherStats().get().getWatchServiceState(), is(WatcherState.STOPPED)); assertThat(watcherClient().prepareWatcherStats().get().getWatcherState(), is(WatcherState.STOPPED));
} else { } else {
assertThat(getInstanceFromMaster(WatcherService.class).state(), is(WatcherState.STOPPED)); assertThat(getInstanceFromMaster(WatcherService.class).state(), is(WatcherState.STOPPED));
} }

View File

@ -143,7 +143,7 @@ public class WatcherScheduleEngineBenchmark {
Clock clock = node.injector().getInstance(Clock.class); Clock clock = node.injector().getInstance(Clock.class);
WatcherClient watcherClient = node.injector().getInstance(WatcherClient.class); WatcherClient watcherClient = node.injector().getInstance(WatcherClient.class);
while (watcherClient.prepareWatcherStats().get().getWatchServiceState() != WatcherState.STARTED) { while (watcherClient.prepareWatcherStats().get().getWatcherState() != WatcherState.STARTED) {
Thread.sleep(100); Thread.sleep(100);
} }
long actualLoadedWatches = watcherClient.prepareWatcherStats().get().getWatchesCount(); long actualLoadedWatches = watcherClient.prepareWatcherStats().get().getWatchesCount();

View File

@ -116,7 +116,7 @@ public class BootStrapTests extends AbstractWatcherIntegrationTests {
startWatcher(); startWatcher();
WatcherStatsResponse response = watcherClient().prepareWatcherStats().get(); WatcherStatsResponse response = watcherClient().prepareWatcherStats().get();
assertThat(response.getWatchServiceState(), equalTo(WatcherState.STARTED)); assertThat(response.getWatcherState(), equalTo(WatcherState.STARTED));
// Only the valid watch should been loaded // Only the valid watch should been loaded
assertThat(response.getWatchesCount(), equalTo(1l)); assertThat(response.getWatchesCount(), equalTo(1l));
assertThat(watcherClient().prepareGetWatch("_id0").get().getId(), Matchers.equalTo("_id0")); assertThat(watcherClient().prepareGetWatch("_id0").get().getId(), Matchers.equalTo("_id0"));
@ -204,7 +204,7 @@ public class BootStrapTests extends AbstractWatcherIntegrationTests {
startWatcher(); startWatcher();
WatcherStatsResponse response = watcherClient().prepareWatcherStats().get(); WatcherStatsResponse response = watcherClient().prepareWatcherStats().get();
assertThat(response.getWatchServiceState(), equalTo(WatcherState.STARTED)); assertThat(response.getWatcherState(), equalTo(WatcherState.STARTED));
assertThat(response.getWatchesCount(), equalTo(1l)); assertThat(response.getWatchesCount(), equalTo(1l));
} }
@ -266,7 +266,7 @@ public class BootStrapTests extends AbstractWatcherIntegrationTests {
startWatcher(); startWatcher();
WatcherStatsResponse response = watcherClient().prepareWatcherStats().get(); WatcherStatsResponse response = watcherClient().prepareWatcherStats().get();
assertThat(response.getWatchServiceState(), equalTo(WatcherState.STARTED)); assertThat(response.getWatcherState(), equalTo(WatcherState.STARTED));
assertThat(response.getWatchesCount(), equalTo((long) numWatches)); assertThat(response.getWatchesCount(), equalTo((long) numWatches));
} }
@ -275,7 +275,7 @@ public class BootStrapTests extends AbstractWatcherIntegrationTests {
public void testWatchRecordLoading() throws Exception { public void testWatchRecordLoading() throws Exception {
createIndex("output"); createIndex("output");
WatcherStatsResponse response = watcherClient().prepareWatcherStats().get(); WatcherStatsResponse response = watcherClient().prepareWatcherStats().get();
assertThat(response.getWatchServiceState(), equalTo(WatcherState.STARTED)); assertThat(response.getWatcherState(), equalTo(WatcherState.STARTED));
assertThat(response.getWatchesCount(), equalTo(0L)); assertThat(response.getWatchesCount(), equalTo(0L));
String watchId = "_id"; String watchId = "_id";
@ -312,7 +312,7 @@ public class BootStrapTests extends AbstractWatcherIntegrationTests {
// We need to wait until all the records are processed from the internal execution queue, only then we can assert // We need to wait until all the records are processed from the internal execution queue, only then we can assert
// that numRecords watch records have been processed as part of starting up. // that numRecords watch records have been processed as part of starting up.
WatcherStatsResponse response = watcherClient().prepareWatcherStats().get(); WatcherStatsResponse response = watcherClient().prepareWatcherStats().get();
assertThat(response.getWatchServiceState(), equalTo(WatcherState.STARTED)); assertThat(response.getWatcherState(), equalTo(WatcherState.STARTED));
assertThat(response.getExecutionQueueSize(), equalTo(0l)); assertThat(response.getExecutionQueueSize(), equalTo(0l));
// but even then since the execution of the watch record is async it may take a little bit before // but even then since the execution of the watch record is async it may take a little bit before
@ -328,7 +328,7 @@ public class BootStrapTests extends AbstractWatcherIntegrationTests {
public void testMixedWatchRecordLoading() throws Exception { public void testMixedWatchRecordLoading() throws Exception {
createIndex("output"); createIndex("output");
WatcherStatsResponse response = watcherClient().prepareWatcherStats().get(); WatcherStatsResponse response = watcherClient().prepareWatcherStats().get();
assertThat(response.getWatchServiceState(), equalTo(WatcherState.STARTED)); assertThat(response.getWatcherState(), equalTo(WatcherState.STARTED));
assertThat(response.getWatchesCount(), equalTo(0L)); assertThat(response.getWatchesCount(), equalTo(0L));
String watchId = "_id"; String watchId = "_id";
@ -383,7 +383,7 @@ public class BootStrapTests extends AbstractWatcherIntegrationTests {
// We need to wait until all the records are processed from the internal execution queue, only then we can assert // We need to wait until all the records are processed from the internal execution queue, only then we can assert
// that numRecords watch records have been processed as part of starting up. // that numRecords watch records have been processed as part of starting up.
WatcherStatsResponse response = watcherClient().prepareWatcherStats().get(); WatcherStatsResponse response = watcherClient().prepareWatcherStats().get();
assertThat(response.getWatchServiceState(), equalTo(WatcherState.STARTED)); assertThat(response.getWatcherState(), equalTo(WatcherState.STARTED));
assertThat(response.getExecutionQueueSize(), equalTo(0l)); assertThat(response.getExecutionQueueSize(), equalTo(0l));
// but even then since the execution of the watch record is async it may take a little bit before // but even then since the execution of the watch record is async it may take a little bit before
@ -441,7 +441,7 @@ public class BootStrapTests extends AbstractWatcherIntegrationTests {
startWatcher(); startWatcher();
WatcherStatsResponse response = watcherClient().prepareWatcherStats().get(); WatcherStatsResponse response = watcherClient().prepareWatcherStats().get();
assertThat(response.getWatchServiceState(), equalTo(WatcherState.STARTED)); assertThat(response.getWatcherState(), equalTo(WatcherState.STARTED));
final long totalHistoryEntries = numberOfWatchRecordsPerIndex * numberOfWatchHistoryIndices; final long totalHistoryEntries = numberOfWatchRecordsPerIndex * numberOfWatchHistoryIndices;
assertBusy(new Runnable() { assertBusy(new Runnable() {

View File

@ -43,7 +43,7 @@ public class WatchStatsTests extends AbstractWatcherIntegrationTests {
WatcherStatsRequest watcherStatsRequest = watcherClient().prepareWatcherStats().request(); WatcherStatsRequest watcherStatsRequest = watcherClient().prepareWatcherStats().request();
WatcherStatsResponse response = watcherClient().watcherStats(watcherStatsRequest).actionGet(); WatcherStatsResponse response = watcherClient().watcherStats(watcherStatsRequest).actionGet();
assertThat(response.getWatchServiceState(), is(WatcherState.STARTED)); assertThat(response.getWatcherState(), is(WatcherState.STARTED));
assertThat(response.getExecutionQueueSize(), is(0L)); assertThat(response.getExecutionQueueSize(), is(0L));
assertThat(response.getWatchesCount(), is(0L)); assertThat(response.getWatchesCount(), is(0L));
assertThat(response.getWatchExecutionQueueMaxSize(), is(timeWarped() ? 1L : 0L)); assertThat(response.getWatchExecutionQueueMaxSize(), is(timeWarped() ? 1L : 0L));
@ -58,7 +58,7 @@ public class WatchStatsTests extends AbstractWatcherIntegrationTests {
WatcherStatsRequest watcherStatsRequest = watcherClient.prepareWatcherStats().request(); WatcherStatsRequest watcherStatsRequest = watcherClient.prepareWatcherStats().request();
WatcherStatsResponse response = watcherClient.watcherStats(watcherStatsRequest).actionGet(); WatcherStatsResponse response = watcherClient.watcherStats(watcherStatsRequest).actionGet();
assertThat(response.getWatchServiceState(), equalTo(WatcherState.STARTED)); assertThat(response.getWatcherState(), equalTo(WatcherState.STARTED));
SearchRequest searchRequest = WatcherTestUtils.newInputSearchRequest("idx").source(searchSource().query(termQuery("field", "value"))); SearchRequest searchRequest = WatcherTestUtils.newInputSearchRequest("idx").source(searchSource().query(termQuery("field", "value")));
watcherClient().preparePutWatch("_name") watcherClient().preparePutWatch("_name")
@ -78,7 +78,7 @@ public class WatchStatsTests extends AbstractWatcherIntegrationTests {
response = watcherClient().watcherStats(watcherStatsRequest).actionGet(); response = watcherClient().watcherStats(watcherStatsRequest).actionGet();
assertThat(response.getWatchServiceState(), is(WatcherState.STARTED)); assertThat(response.getWatcherState(), is(WatcherState.STARTED));
assertThat(response.getWatchesCount(), is(1L)); assertThat(response.getWatchesCount(), is(1L));
assertThat(response.getWatchExecutionQueueMaxSize(), greaterThan(0L)); assertThat(response.getWatchExecutionQueueMaxSize(), greaterThan(0L));
} }