Add support for testing all REST endpoints.

This change adds support for testing all watcher REST endpoints.
It also updates the api docs to be current with the latest code.
Change GetWatchResponse to only have the information in needs
GetWatchResponse used to contain a GetResponse this is not needed. Now it just contains the needed fields.

Closes elastic/elasticsearch#35

Original commit: elastic/x-pack-elasticsearch@905c5da318
This commit is contained in:
Brian Murphy 2015-04-06 11:29:36 -04:00
parent 4b4c08af16
commit 31fbbcfc9a
29 changed files with 570 additions and 65 deletions

View File

@ -0,0 +1,25 @@
{
"ack_watch": {
"documentation": "http://www.elastic.co/guide/en/watcher/current/appendix-api-ack-watch.html",
"methods": [ "PUT", "POST" ],
"url": {
"path": "/_watcher/watch/{id}/_ack",
"paths": [ "/_watcher/watch/{id}/_ack" ],
"parts": {
"id": {
"type" : "string",
"description" : "Watch ID",
"required" : true
}
},
"params": {
"pretty": {
"type": "boolean",
"description": "Pretty the output",
"default": false
}
}
},
"body": null
}
}

View File

@ -0,0 +1,55 @@
{
"cluster.health": {
"documentation": "http://www.elasticsearch.org/guide/en/elasticsearch/reference/1.x/cluster-health.html",
"methods": ["GET"],
"url": {
"path": "/_cluster/health",
"paths": ["/_cluster/health", "/_cluster/health/{index}"],
"parts": {
"index": {
"type" : "string",
"description" : "Limit the information returned to a specific index"
}
},
"params": {
"level": {
"type" : "enum",
"options" : ["cluster","indices","shards"],
"default" : "cluster",
"description" : "Specify the level of detail for returned information"
},
"local": {
"type" : "boolean",
"description" : "Return local information, do not retrieve the state from master node (default: false)"
},
"master_timeout": {
"type" : "time",
"description" : "Explicit operation timeout for connection to master node"
},
"timeout": {
"type" : "time",
"description" : "Explicit operation timeout"
},
"wait_for_active_shards": {
"type" : "number",
"description" : "Wait until the specified number of shards is active"
},
"wait_for_nodes": {
"type" : "string",
"description" : "Wait until the specified number of nodes is available"
},
"wait_for_relocating_shards": {
"type" : "number",
"description" : "Wait until the specified number of relocating shards is finished"
},
"wait_for_status": {
"type" : "enum",
"options" : ["green","yellow","red"],
"default" : null,
"description" : "Wait until cluster is in a specific state"
}
}
},
"body": null
}
}

View File

@ -0,0 +1,25 @@
{
"delete_watch": {
"documentation": "http://www.elastic.co/guide/en/watcher/current/appendix-api-delete-watch.html",
"methods": [ "DELETE" ],
"url": {
"path": "/_watcher/watch/{id}",
"paths": [ "/_watcher/watch/{id}" ],
"parts": {
"id": {
"type" : "string",
"description" : "Watch ID",
"required" : true
}
},
"params": {
"pretty": {
"type": "boolean",
"description": "Pretty the output",
"default": false
}
}
},
"body": null
}
}

View File

@ -0,0 +1,25 @@
{
"get_watch": {
"documentation": "http://www.elastic.co/guide/en/watcher/current/appendix-api-get-watch.html",
"methods": [ "GET" ],
"url": {
"path": "/_watcher/watch/{id}",
"paths": [ "/_watcher/watch/{id}" ],
"parts": {
"id": {
"type" : "string",
"description" : "Watch ID",
"required" : true
}
},
"params": {
"pretty": {
"type": "boolean",
"description": "Pretty the output",
"default": false
}
}
},
"body": null
}
}

View File

@ -0,0 +1,15 @@
{
"info": {
"documentation": "http://www.elasticsearch.org/guide/",
"methods": ["GET"],
"url": {
"path": "/",
"paths": ["/"],
"parts": {
},
"params": {
}
},
"body": null
}
}

View File

@ -0,0 +1,28 @@
{
"put_watch": {
"documentation": "http://www.elastic.co/guide/en/watcher/current/appendix-api-put-watch.html",
"methods": [ "PUT", "POST" ],
"url": {
"path": "/_watcher/watch/{id}",
"paths": [ "/_watcher/watch/{id}" ],
"parts": {
"id": {
"type" : "string",
"description" : "Watch ID",
"required" : true
}
},
"params": {
"pretty": {
"type": "boolean",
"description": "Pretty the output",
"default": false
}
}
},
"body": {
"description" : "The watch",
"required" : true
}
}
}

View File

@ -0,0 +1,15 @@
{
"restart_watcher": {
"documentation": "http://www.elastic.co/guide/en/watcher/current/appendix-api-service.html",
"methods": [ "PUT" ],
"url": {
"path": "/_watcher/_restart",
"paths": [ "/_watcher/_restart" ],
"parts": {
},
"params": {
}
},
"body": null
}
}

View File

@ -0,0 +1,15 @@
{
"start_watcher": {
"documentation": "http://www.elastic.co/guide/en/watcher/current/appendix-api-service.html",
"methods": [ "PUT" ],
"url": {
"path": "/_watcher/_start",
"paths": [ "/_watcher/_start" ],
"parts": {
},
"params": {
}
},
"body": null
}
}

View File

@ -0,0 +1,15 @@
{
"stop_watcher": {
"documentation": "http://www.elastic.co/guide/en/watcher/current/appendix-api-service.html",
"methods": [ "PUT" ],
"url": {
"path": "/_watcher/_stop",
"paths": [ "/_watcher/_stop" ],
"parts": {
},
"params": {
}
},
"body": null
}
}

View File

@ -0,0 +1,15 @@
{
"watcher_info": {
"documentation": "http://www.elastic.co/guide/en/watcher/current/appendix-api-info.html",
"methods": [ "GET" ],
"url": {
"path": "/_watcher/",
"paths": [ "/_watcher/" ],
"parts": {
},
"params": {
}
},
"body": null
}
}

View File

@ -1,10 +1,10 @@
{ {
"watcher_stats": { "watcher_stats": {
"documentation": "http://elastic.co/alertsdocs", "documentation": "http://www.elastic.co/guide/en/watcher/current/appendix-api-stats.html",
"methods": ["GET"], "methods": [ "GET" ],
"url": { "url": {
"path": "/_watcher/stats", "path": "/_watcher/stats",
"paths": ["/_watcher/stats"], "paths": [ "/_watcher/stats" ],
"parts": { "parts": {
}, },
"params": { "params": {

View File

@ -0,0 +1,53 @@
---
"Test ack watch api":
- do:
cluster.health:
wait_for_status: green
- do:
put_watch:
id: "my_watch"
body: >
{
"trigger": {
"schedule": {
"hourly": {
"minute": [ 0, 5 ]
}
}
},
"input": {
"simple": {
"payload": {
"send": "yes"
}
}
},
"condition": {
"always_true": {}
},
"actions": [
{
"test_index": {
"index": {
"index": "test",
"type": "test2"
}
}
} ]
}
- match: { _id: "my_watch" }
- do:
cluster.health:
wait_for_status: green
- do:
ack_watch:
id: "my_watch"
- match: { "status.ack.state" : "awaits_execution" }
- do:
delete_watch:
id: "my_watch"
- match: { found: true }

View File

@ -0,0 +1,44 @@
---
"Test delete watch api":
- do:
cluster.health:
wait_for_status: green
- do:
put_watch:
id: "my_watch"
body: >
{
"trigger": {
"schedule": {
"hourly": {
"minute": [ 0, 5 ]
}
}
},
"input": {
"simple": {
"payload": {
"send": "yes"
}
}
},
"condition": {
"always_true": {}
},
"actions": [
{
"test_index": {
"index": {
"index": "test",
"type": "test2"
}
}
} ]
}
- match: { _id: "my_watch" }
- do:
delete_watch:
id: "my_watch"
- match: { found: true }

View File

@ -0,0 +1,46 @@
---
"Test get watch api":
- do:
cluster.health:
wait_for_status: green
- do:
put_watch:
id: "my_watch"
body: >
{
"trigger": {
"schedule": {
"hourly": {
"minute": [ 0, 5 ]
}
}
},
"input": {
"simple": {
"payload": {
"send": "yes"
}
}
},
"condition": {
"always_true": {}
},
"actions": [
{
"test_index": {
"index": {
"index": "test",
"type": "test2"
}
}
} ]
}
- match: { _id: "my_watch" }
- match: { created: true }
- do:
get_watch:
id: "my_watch"
- match: { found : true}
- match: { _id: "my_watch" }

View File

@ -0,0 +1,39 @@
---
"Test put watch api":
- do:
cluster.health:
wait_for_status: green
- do:
put_watch:
id: "my_watch"
body: >
{
"trigger": {
"schedule": {
"hourly": {
"minute": [ 0, 5 ]
}
}
},
"input": {
"simple": {
"payload": {
"send": "yes"
}
}
},
"condition": {
"always_true": {}
},
"actions": [
{
"test_index": {
"index": {
"index": "test",
"type": "test2"
}
}
} ]
}
- match: { _id: "my_watch" }

View File

@ -0,0 +1,8 @@
---
"Test restart watcher api":
- do:
cluster.health:
wait_for_status: green
- do: {restart_watcher: {}}
- match: { acknowledged: true }

View File

@ -0,0 +1,8 @@
---
"Test start watcher api":
- do:
cluster.health:
wait_for_status: green
- do: {start_watcher: {}}
- match: { acknowledged: true }

View File

@ -0,0 +1,11 @@
---
"Test stop watcher api":
- do:
cluster.health:
wait_for_status: green
- do: {stop_watcher: {}}
- match: { acknowledged: true }
- do: {start_watcher: {}}
- match: { acknowledged: true }

View File

@ -0,0 +1,6 @@
---
"Test watcher info api":
- do: {watcher_info: {}}
- is_true: version.build_hash
- is_true: version.build_timestamp
- is_true: version.build_snapshot

View File

@ -26,6 +26,7 @@ public class RestAckWatchAction extends WatcherRestHandler {
protected RestAckWatchAction(Settings settings, RestController controller, Client client) { protected RestAckWatchAction(Settings settings, RestController controller, Client client) {
super(settings, controller, client); super(settings, controller, client);
controller.registerHandler(RestRequest.Method.PUT, URI_BASE + "/watch/{name}/_ack", this); controller.registerHandler(RestRequest.Method.PUT, URI_BASE + "/watch/{name}/_ack", this);
controller.registerHandler(RestRequest.Method.POST, URI_BASE + "/watch/{name}/_ack", this);
} }
@Override @Override
@ -35,7 +36,7 @@ public class RestAckWatchAction extends WatcherRestHandler {
@Override @Override
public RestResponse buildResponse(AckWatchResponse response, XContentBuilder builder) throws Exception { public RestResponse buildResponse(AckWatchResponse response, XContentBuilder builder) throws Exception {
return new BytesRestResponse(RestStatus.OK, builder.startObject() return new BytesRestResponse(RestStatus.OK, builder.startObject()
.field(Watch.Parser.STATUS_FIELD.getPreferredName(), response.getStatus().toString()) .field(Watch.Parser.STATUS_FIELD.getPreferredName(), response.getStatus())
.endObject()); .endObject());
} }

View File

@ -5,7 +5,6 @@
*/ */
package org.elasticsearch.watcher.rest.action; package org.elasticsearch.watcher.rest.action;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.client.Client; import org.elasticsearch.client.Client;
import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
@ -35,15 +34,14 @@ public class RestGetWatchAction extends WatcherRestHandler {
client.getWatch(getWatchRequest, new RestBuilderListener<GetWatchResponse>(channel) { client.getWatch(getWatchRequest, new RestBuilderListener<GetWatchResponse>(channel) {
@Override @Override
public RestResponse buildResponse(GetWatchResponse response, XContentBuilder builder) throws Exception { public RestResponse buildResponse(GetWatchResponse response, XContentBuilder builder) throws Exception {
GetResponse getResponse = response.getResponse();
builder.startObject() builder.startObject()
.field("found", getResponse.isExists()) .field("found", response.exists())
.field("_id", getResponse.getId()) .field("_id", response.id())
.field("_version", getResponse.getVersion()) .field("_version", response.version())
.field("watch", getResponse.getSource()) .field("watch", response.sourceAsMap())
.endObject(); .endObject();
RestStatus status = getResponse.isExists() ? OK : NOT_FOUND; RestStatus status = response.exists() ? OK : NOT_FOUND;
return new BytesRestResponse(status, builder); return new BytesRestResponse(status, builder);
} }
}); });

View File

@ -5,10 +5,6 @@
*/ */
package org.elasticsearch.watcher.rest.action; package org.elasticsearch.watcher.rest.action;
import org.elasticsearch.watcher.watch.WatchStore;
import org.elasticsearch.watcher.client.WatcherClient;
import org.elasticsearch.watcher.transport.actions.service.WatcherServiceRequest;
import org.elasticsearch.watcher.transport.actions.service.WatcherServiceResponse;
import org.elasticsearch.client.Client; import org.elasticsearch.client.Client;
import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
@ -17,45 +13,58 @@ import org.elasticsearch.rest.RestChannel;
import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.action.support.AcknowledgedRestListener; import org.elasticsearch.rest.action.support.AcknowledgedRestListener;
import org.elasticsearch.watcher.client.WatcherClient;
import org.elasticsearch.watcher.rest.WatcherRestHandler;
import org.elasticsearch.watcher.transport.actions.service.WatcherServiceRequest;
import org.elasticsearch.watcher.transport.actions.service.WatcherServiceResponse;
/** /**
*/ */
public class RestWatchServiceAction extends BaseRestHandler { public class RestWatchServiceAction extends WatcherRestHandler {
private final WatcherClient watcherClient;
@Inject @Inject
protected RestWatchServiceAction(Settings settings, RestController controller, Client client) { protected RestWatchServiceAction(Settings settings, RestController controller, Client client, WatcherClient watcherClient) {
super(settings, controller, client); super(settings, controller, client);
controller.registerHandler(RestRequest.Method.PUT, WatchStore.INDEX + "/_restart", this); controller.registerHandler(RestRequest.Method.PUT, URI_BASE + "/_restart", this);
controller.registerHandler(RestRequest.Method.PUT, WatchStore.INDEX + "/_start", new StartRestHandler(settings, controller, client)); controller.registerHandler(RestRequest.Method.PUT, URI_BASE + "/_start", new StartRestHandler(settings, controller, client, watcherClient));
controller.registerHandler(RestRequest.Method.PUT, WatchStore.INDEX + "/_stop", new StopRestHandler(settings, controller, client)); controller.registerHandler(RestRequest.Method.PUT, URI_BASE + "/_stop", new StopRestHandler(settings, controller, client, watcherClient));
this.watcherClient = watcherClient;
} }
@Override @Override
protected void handleRequest(RestRequest request, RestChannel channel, Client client) throws Exception { protected void handleRequest(RestRequest request, RestChannel channel, WatcherClient client) throws Exception {
new WatcherClient(client).watcherService(new WatcherServiceRequest().restart(), new AcknowledgedRestListener<WatcherServiceResponse>(channel)); watcherClient.watcherService(new WatcherServiceRequest().restart(), new AcknowledgedRestListener<WatcherServiceResponse>(channel));
} }
static class StartRestHandler extends BaseRestHandler { static class StartRestHandler extends BaseRestHandler {
public StartRestHandler(Settings settings, RestController controller, Client client) { private final WatcherClient watcherClient;
public StartRestHandler(Settings settings, RestController controller, Client client, WatcherClient watcherClient) {
super(settings, controller, client); super(settings, controller, client);
this.watcherClient = watcherClient;
} }
@Override @Override
public void handleRequest(RestRequest request, RestChannel channel, Client client) throws Exception { public void handleRequest(RestRequest request, RestChannel channel, Client client) throws Exception {
new WatcherClient(client).watcherService(new WatcherServiceRequest().start(), new AcknowledgedRestListener<WatcherServiceResponse>(channel)); watcherClient.watcherService(new WatcherServiceRequest().start(), new AcknowledgedRestListener<WatcherServiceResponse>(channel));
} }
} }
static class StopRestHandler extends BaseRestHandler { static class StopRestHandler extends BaseRestHandler {
public StopRestHandler(Settings settings, RestController controller, Client client) { private final WatcherClient watcherClient;
public StopRestHandler(Settings settings, RestController controller, Client client, WatcherClient watcherClient) {
super(settings, controller, client); super(settings, controller, client);
this.watcherClient = watcherClient;
} }
@Override @Override
public void handleRequest(RestRequest request, RestChannel channel, Client client) throws Exception { public void handleRequest(RestRequest request, RestChannel channel, Client client) throws Exception {
new WatcherClient(client).watcherService(new WatcherServiceRequest().stop(), new AcknowledgedRestListener<WatcherServiceResponse>(channel)); watcherClient.watcherService(new WatcherServiceRequest().stop(), new AcknowledgedRestListener<WatcherServiceResponse>(channel));
} }
} }
} }

View File

@ -35,12 +35,13 @@ public class RestWatcherInfoAction extends WatcherRestHandler {
watcherClient.watcherStats(new WatcherStatsRequest(), new RestBuilderListener<WatcherStatsResponse>(restChannel) { watcherClient.watcherStats(new WatcherStatsRequest(), new RestBuilderListener<WatcherStatsResponse>(restChannel) {
@Override @Override
public RestResponse buildResponse(WatcherStatsResponse watcherStatsResponse, XContentBuilder builder) throws Exception { public RestResponse buildResponse(WatcherStatsResponse watcherStatsResponse, XContentBuilder builder) throws Exception {
builder.startObject();
builder.startObject("version") builder.startObject("version")
.field("number", watcherStatsResponse.getVersion().number()) .field("number", watcherStatsResponse.getVersion().number())
.field("build_hash", watcherStatsResponse.getBuild().hash()) .field("build_hash", watcherStatsResponse.getBuild().hash())
.field("build_timestamp", watcherStatsResponse.getBuild().timestamp()) .field("build_timestamp", watcherStatsResponse.getBuild().timestamp())
.field("build_snapshot", watcherStatsResponse.getVersion().snapshot) .field("build_snapshot", watcherStatsResponse.getVersion().snapshot)
.endObject(); .endObject().endObject();
return new BytesRestResponse(OK, builder); return new BytesRestResponse(OK, builder);

View File

@ -5,49 +5,85 @@
*/ */
package org.elasticsearch.watcher.transport.actions.get; package org.elasticsearch.watcher.transport.actions.get;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.action.ActionResponse; import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.action.get.GetResponse; import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.search.lookup.SourceLookup;
import java.io.IOException; import java.io.IOException;
import java.util.Map;
public class GetWatchResponse extends ActionResponse { public class GetWatchResponse extends ActionResponse {
private GetResponse getResponse; private boolean exists = false;
private String id;
private long version;
private BytesReference source;
private Map<String, Object> sourceAsMap;
public GetWatchResponse(boolean found, String id, long version, BytesReference source) {
this.exists = found;
this.id = id;
this.version = version;
this.source = source;
GetResponse foo;
}
public GetWatchResponse() { public GetWatchResponse() {
} }
public GetWatchResponse(GetResponse getResponse) { public BytesReference source() {
this.getResponse = getResponse; return source;
} }
/** public Map<String, Object> sourceAsMap() throws ElasticsearchParseException {
* Sets the GetResponse containing the watch source if (source == null) {
*/ return null;
public void getResponse(GetResponse getResponse) { }
this.getResponse = getResponse; if (sourceAsMap != null) {
return sourceAsMap;
}
sourceAsMap = SourceLookup.sourceAsMap(source);
return sourceAsMap;
} }
public GetResponse getResponse() {
return this.getResponse; public boolean exists() {
return exists;
}
public String id() {
return id;
}
public long version() {
return version;
} }
@Override @Override
public void readFrom(StreamInput in) throws IOException { public void readFrom(StreamInput in) throws IOException {
super.readFrom(in); super.readFrom(in);
if (in.readBoolean()) { exists = in.readBoolean();
getResponse = GetResponse.readGetResponse(in); if (exists) {
id = in.readString();
version = in.readLong();
source = in.readBytesReference();
} }
} }
@Override @Override
public void writeTo(StreamOutput out) throws IOException { public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out); super.writeTo(out);
out.writeBoolean(getResponse != null); out.writeBoolean(exists);
if (getResponse != null) { if (exists) {
getResponse.writeTo(out); out.writeString(id);
out.writeLong(version);
out.writeBytesReference(source);
} }
} }
} }

View File

@ -7,7 +7,6 @@ package org.elasticsearch.watcher.transport.actions.get;
import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.support.ActionFilters; import org.elasticsearch.action.support.ActionFilters;
import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.ClusterState;
@ -60,21 +59,27 @@ public class TransportGetWatchAction extends WatcherTransportAction<GetWatchRequ
@Override @Override
protected void masterOperation(GetWatchRequest request, ClusterState state, ActionListener<GetWatchResponse> listener) throws ElasticsearchException { protected void masterOperation(GetWatchRequest request, ClusterState state, ActionListener<GetWatchResponse> listener) throws ElasticsearchException {
Watch watch = watchService.getWatch(request.watchName()); try {
GetResult getResult; Watch watch = watchService.getWatch(request.watchName());
if (watch != null) { GetResult getResult;
BytesReference watchSource = null; if (watch != null) {
try (XContentBuilder builder = JsonXContent.contentBuilder()) { BytesReference watchSource = null;
builder.value(watch); try (XContentBuilder builder = JsonXContent.contentBuilder()) {
watchSource = builder.bytes(); builder.value(watch);
} catch (IOException e) { watchSource = builder.bytes();
listener.onFailure(e); } catch (IOException e) {
listener.onFailure(e);
return;
}
getResult = new GetResult(WatchStore.INDEX, WatchStore.DOC_TYPE, watch.name(), watch.status().version(), true, watchSource, null);
} else {
getResult = new GetResult(WatchStore.INDEX, WatchStore.DOC_TYPE, request.watchName(), -1, false, null, null);
} }
getResult = new GetResult(WatchStore.INDEX, WatchStore.DOC_TYPE, watch.name(), watch.status().version(), true, watchSource, null); listener.onResponse(new GetWatchResponse(getResult.isExists(), getResult.getId(), getResult.getVersion(), getResult.sourceRef()));
} else { } catch (Throwable t) {
getResult = new GetResult(WatchStore.INDEX, WatchStore.DOC_TYPE, request.watchName(), -1, false, null, null); logger.error("failed to get watch [{}]", t, request.watchName());
throw t;
} }
listener.onResponse(new GetWatchResponse(new GetResponse(getResult)));
} }
@Override @Override

View File

@ -8,14 +8,14 @@ package org.elasticsearch.watcher.watch;
import org.elasticsearch.ElasticsearchIllegalStateException; import org.elasticsearch.ElasticsearchIllegalStateException;
import org.elasticsearch.action.index.IndexResponse; import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.watcher.WatcherException;
import org.elasticsearch.watcher.history.HistoryService;
import org.elasticsearch.watcher.support.Callback;
import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.component.AbstractComponent;
import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.watcher.WatcherException;
import org.elasticsearch.watcher.history.HistoryService;
import org.elasticsearch.watcher.support.Callback;
import org.elasticsearch.watcher.trigger.TriggerService; import org.elasticsearch.watcher.trigger.TriggerService;
import java.io.IOException; import java.io.IOException;
@ -109,6 +109,9 @@ public class WatchService extends AbstractComponent {
triggerService.add(result.current()); triggerService.add(result.current());
} }
return result.indexResponse(); return result.indexResponse();
} catch (Exception e) {
logger.warn("failed to put watch [{}]", e, name);
throw new WatcherException("failed to put [" + watchSource.toUtf8() + "]", e);
} finally { } finally {
lock.release(); lock.release();
} }

View File

@ -77,8 +77,8 @@ public class BasicWatcherTests extends AbstractWatcherIntegrationTests {
assertWatchWithMinimumPerformedActionsCount("_name", 1); assertWatchWithMinimumPerformedActionsCount("_name", 1);
GetWatchResponse getWatchResponse = watcherClient().prepareGetWatch().setWatchName("_name").get(); GetWatchResponse getWatchResponse = watcherClient().prepareGetWatch().setWatchName("_name").get();
assertThat(getWatchResponse.getResponse().isExists(), is(true)); assertThat(getWatchResponse.exists(), is(true));
assertThat(getWatchResponse.getResponse().isSourceEmpty(), is(false)); assertThat(getWatchResponse.source().length(), greaterThan(0));
} }
@Test @Test

View File

@ -100,10 +100,10 @@ public class WatchThrottleTests extends AbstractWatcherIntegrationTests {
} }
GetWatchResponse getWatchResponse = watcherClient.prepareGetWatch("_name").get(); GetWatchResponse getWatchResponse = watcherClient.prepareGetWatch("_name").get();
assertThat(getWatchResponse.getResponse().isExists(), is(true)); assertThat(getWatchResponse.exists(), is(true));
Watch parsedWatch = watchParser().parse(getWatchResponse.getResponse().getId(), true, Watch parsedWatch = watchParser().parse(getWatchResponse.id(), true,
getWatchResponse.getResponse().getSourceAsBytesRef()); getWatchResponse.source());
assertThat(parsedWatch.status().ackStatus().state(), is(Watch.Status.AckStatus.State.AWAITS_EXECUTION)); assertThat(parsedWatch.status().ackStatus().state(), is(Watch.Status.AckStatus.State.AWAITS_EXECUTION));
long throttledCount = docCount(HistoryStore.INDEX_PREFIX + "*", null, long throttledCount = docCount(HistoryStore.INDEX_PREFIX + "*", null,

View File

@ -73,6 +73,8 @@ public class WatcherRestTests extends ElasticsearchRestTests {
return ImmutableSettings.builder() return ImmutableSettings.builder()
.put("plugin.types", WatcherPlugin.class.getName()) .put("plugin.types", WatcherPlugin.class.getName())
.put(InternalNode.HTTP_ENABLED, true) .put(InternalNode.HTTP_ENABLED, true)
.put("plugin.types", WatcherPlugin.class.getName() + ","
+ "," + LicensePlugin.class.getName())
.build(); .build();
} }
@ -93,6 +95,8 @@ public class WatcherRestTests extends ElasticsearchRestTests {
return ImmutableSettings.builder() return ImmutableSettings.builder()
.put("plugin.types", WatcherPlugin.class.getName()) .put("plugin.types", WatcherPlugin.class.getName())
.put(InternalNode.HTTP_ENABLED, true) .put(InternalNode.HTTP_ENABLED, true)
.put("plugin.types", WatcherPlugin.class.getName() + ","
+ "," + LicensePlugin.class.getName())
.build(); .build();
} }
@ -139,7 +143,7 @@ public class WatcherRestTests extends ElasticsearchRestTests {
.put("shield.user", "test:changeme") .put("shield.user", "test:changeme")
.put("shield.authc.realms.esusers.type", ESUsersRealm.TYPE) .put("shield.authc.realms.esusers.type", ESUsersRealm.TYPE)
.put("shield.authc.anonymous.username","anonymous_user") .put("shield.authc.anonymous.username","anonymous_user")
.put("shield.authc.anonymous.roles", "monitor") .put("shield.authc.anonymous.roles", "admin")
.put("shield.authc.realms.esusers.order", 0) .put("shield.authc.realms.esusers.order", 0)
.put("shield.authc.realms.esusers.files.users", writeFile(folder, "users", USERS)) .put("shield.authc.realms.esusers.files.users", writeFile(folder, "users", USERS))
.put("shield.authc.realms.esusers.files.users_roles", writeFile(folder, "users_roles", USER_ROLES)) .put("shield.authc.realms.esusers.files.users_roles", writeFile(folder, "users_roles", USER_ROLES))