mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-09 06:25:07 +00:00
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:
parent
4b4c08af16
commit
31fbbcfc9a
25
rest-api-spec/api/ack_watch.json
Normal file
25
rest-api-spec/api/ack_watch.json
Normal 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
|
||||
}
|
||||
}
|
55
rest-api-spec/api/cluster.health.json
Normal file
55
rest-api-spec/api/cluster.health.json
Normal 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
|
||||
}
|
||||
}
|
25
rest-api-spec/api/delete_watch.json
Normal file
25
rest-api-spec/api/delete_watch.json
Normal 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
|
||||
}
|
||||
}
|
25
rest-api-spec/api/get_watch.json
Normal file
25
rest-api-spec/api/get_watch.json
Normal 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
|
||||
}
|
||||
}
|
15
rest-api-spec/api/info.json
Normal file
15
rest-api-spec/api/info.json
Normal file
@ -0,0 +1,15 @@
|
||||
{
|
||||
"info": {
|
||||
"documentation": "http://www.elasticsearch.org/guide/",
|
||||
"methods": ["GET"],
|
||||
"url": {
|
||||
"path": "/",
|
||||
"paths": ["/"],
|
||||
"parts": {
|
||||
},
|
||||
"params": {
|
||||
}
|
||||
},
|
||||
"body": null
|
||||
}
|
||||
}
|
28
rest-api-spec/api/put_watch.json
Normal file
28
rest-api-spec/api/put_watch.json
Normal 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
|
||||
}
|
||||
}
|
||||
}
|
15
rest-api-spec/api/restart_watcher.json
Normal file
15
rest-api-spec/api/restart_watcher.json
Normal 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
|
||||
}
|
||||
}
|
15
rest-api-spec/api/start_watcher.json
Normal file
15
rest-api-spec/api/start_watcher.json
Normal 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
|
||||
}
|
||||
}
|
15
rest-api-spec/api/stop_watcher.json
Normal file
15
rest-api-spec/api/stop_watcher.json
Normal 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
|
||||
}
|
||||
}
|
15
rest-api-spec/api/watcher_info.json
Normal file
15
rest-api-spec/api/watcher_info.json
Normal 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
|
||||
}
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
{
|
||||
"watcher_stats": {
|
||||
"documentation": "http://elastic.co/alertsdocs",
|
||||
"methods": ["GET"],
|
||||
"documentation": "http://www.elastic.co/guide/en/watcher/current/appendix-api-stats.html",
|
||||
"methods": [ "GET" ],
|
||||
"url": {
|
||||
"path": "/_watcher/stats",
|
||||
"paths": ["/_watcher/stats"],
|
||||
"paths": [ "/_watcher/stats" ],
|
||||
"parts": {
|
||||
},
|
||||
"params": {
|
53
rest-api-spec/test/ack_watch/10_basic.yaml
Normal file
53
rest-api-spec/test/ack_watch/10_basic.yaml
Normal 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 }
|
44
rest-api-spec/test/delete_watch/10_basic.yaml
Normal file
44
rest-api-spec/test/delete_watch/10_basic.yaml
Normal 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 }
|
46
rest-api-spec/test/get_watch/10_basic.yaml
Normal file
46
rest-api-spec/test/get_watch/10_basic.yaml
Normal 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" }
|
39
rest-api-spec/test/put_watch/10_basic.yaml
Normal file
39
rest-api-spec/test/put_watch/10_basic.yaml
Normal 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" }
|
8
rest-api-spec/test/restart_watcher/10_basic.yaml
Normal file
8
rest-api-spec/test/restart_watcher/10_basic.yaml
Normal file
@ -0,0 +1,8 @@
|
||||
---
|
||||
"Test restart watcher api":
|
||||
- do:
|
||||
cluster.health:
|
||||
wait_for_status: green
|
||||
|
||||
- do: {restart_watcher: {}}
|
||||
- match: { acknowledged: true }
|
8
rest-api-spec/test/start_watcher/10_basic.yaml
Normal file
8
rest-api-spec/test/start_watcher/10_basic.yaml
Normal file
@ -0,0 +1,8 @@
|
||||
---
|
||||
"Test start watcher api":
|
||||
- do:
|
||||
cluster.health:
|
||||
wait_for_status: green
|
||||
|
||||
- do: {start_watcher: {}}
|
||||
- match: { acknowledged: true }
|
11
rest-api-spec/test/stop_watcher/10_basic.yaml
Normal file
11
rest-api-spec/test/stop_watcher/10_basic.yaml
Normal 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 }
|
6
rest-api-spec/test/watch_info/10_basic.yaml
Normal file
6
rest-api-spec/test/watch_info/10_basic.yaml
Normal 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
|
@ -26,6 +26,7 @@ public class RestAckWatchAction extends WatcherRestHandler {
|
||||
protected RestAckWatchAction(Settings settings, RestController controller, Client client) {
|
||||
super(settings, controller, client);
|
||||
controller.registerHandler(RestRequest.Method.PUT, URI_BASE + "/watch/{name}/_ack", this);
|
||||
controller.registerHandler(RestRequest.Method.POST, URI_BASE + "/watch/{name}/_ack", this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -35,7 +36,7 @@ public class RestAckWatchAction extends WatcherRestHandler {
|
||||
@Override
|
||||
public RestResponse buildResponse(AckWatchResponse response, XContentBuilder builder) throws Exception {
|
||||
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());
|
||||
|
||||
}
|
||||
|
@ -5,7 +5,6 @@
|
||||
*/
|
||||
package org.elasticsearch.watcher.rest.action;
|
||||
|
||||
import org.elasticsearch.action.get.GetResponse;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
@ -35,15 +34,14 @@ public class RestGetWatchAction extends WatcherRestHandler {
|
||||
client.getWatch(getWatchRequest, new RestBuilderListener<GetWatchResponse>(channel) {
|
||||
@Override
|
||||
public RestResponse buildResponse(GetWatchResponse response, XContentBuilder builder) throws Exception {
|
||||
GetResponse getResponse = response.getResponse();
|
||||
builder.startObject()
|
||||
.field("found", getResponse.isExists())
|
||||
.field("_id", getResponse.getId())
|
||||
.field("_version", getResponse.getVersion())
|
||||
.field("watch", getResponse.getSource())
|
||||
.field("found", response.exists())
|
||||
.field("_id", response.id())
|
||||
.field("_version", response.version())
|
||||
.field("watch", response.sourceAsMap())
|
||||
.endObject();
|
||||
|
||||
RestStatus status = getResponse.isExists() ? OK : NOT_FOUND;
|
||||
RestStatus status = response.exists() ? OK : NOT_FOUND;
|
||||
return new BytesRestResponse(status, builder);
|
||||
}
|
||||
});
|
||||
|
@ -5,10 +5,6 @@
|
||||
*/
|
||||
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.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
@ -17,45 +13,58 @@ import org.elasticsearch.rest.RestChannel;
|
||||
import org.elasticsearch.rest.RestController;
|
||||
import org.elasticsearch.rest.RestRequest;
|
||||
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
|
||||
protected RestWatchServiceAction(Settings settings, RestController controller, Client client) {
|
||||
protected RestWatchServiceAction(Settings settings, RestController controller, Client client, WatcherClient watcherClient) {
|
||||
super(settings, controller, client);
|
||||
controller.registerHandler(RestRequest.Method.PUT, WatchStore.INDEX + "/_restart", this);
|
||||
controller.registerHandler(RestRequest.Method.PUT, WatchStore.INDEX + "/_start", new StartRestHandler(settings, controller, client));
|
||||
controller.registerHandler(RestRequest.Method.PUT, WatchStore.INDEX + "/_stop", new StopRestHandler(settings, controller, client));
|
||||
controller.registerHandler(RestRequest.Method.PUT, URI_BASE + "/_restart", this);
|
||||
controller.registerHandler(RestRequest.Method.PUT, URI_BASE + "/_start", new StartRestHandler(settings, controller, client, watcherClient));
|
||||
controller.registerHandler(RestRequest.Method.PUT, URI_BASE + "/_stop", new StopRestHandler(settings, controller, client, watcherClient));
|
||||
this.watcherClient = watcherClient;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleRequest(RestRequest request, RestChannel channel, Client client) throws Exception {
|
||||
new WatcherClient(client).watcherService(new WatcherServiceRequest().restart(), new AcknowledgedRestListener<WatcherServiceResponse>(channel));
|
||||
protected void handleRequest(RestRequest request, RestChannel channel, WatcherClient client) throws Exception {
|
||||
watcherClient.watcherService(new WatcherServiceRequest().restart(), new AcknowledgedRestListener<WatcherServiceResponse>(channel));
|
||||
}
|
||||
|
||||
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);
|
||||
this.watcherClient = watcherClient;
|
||||
}
|
||||
|
||||
@Override
|
||||
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 {
|
||||
|
||||
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);
|
||||
this.watcherClient = watcherClient;
|
||||
}
|
||||
|
||||
@Override
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -35,12 +35,13 @@ public class RestWatcherInfoAction extends WatcherRestHandler {
|
||||
watcherClient.watcherStats(new WatcherStatsRequest(), new RestBuilderListener<WatcherStatsResponse>(restChannel) {
|
||||
@Override
|
||||
public RestResponse buildResponse(WatcherStatsResponse watcherStatsResponse, XContentBuilder builder) throws Exception {
|
||||
builder.startObject();
|
||||
builder.startObject("version")
|
||||
.field("number", watcherStatsResponse.getVersion().number())
|
||||
.field("build_hash", watcherStatsResponse.getBuild().hash())
|
||||
.field("build_timestamp", watcherStatsResponse.getBuild().timestamp())
|
||||
.field("build_snapshot", watcherStatsResponse.getVersion().snapshot)
|
||||
.endObject();
|
||||
.endObject().endObject();
|
||||
|
||||
return new BytesRestResponse(OK, builder);
|
||||
|
||||
|
@ -5,49 +5,85 @@
|
||||
*/
|
||||
package org.elasticsearch.watcher.transport.actions.get;
|
||||
|
||||
import org.elasticsearch.ElasticsearchParseException;
|
||||
import org.elasticsearch.action.ActionResponse;
|
||||
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.StreamOutput;
|
||||
import org.elasticsearch.search.lookup.SourceLookup;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
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(GetResponse getResponse) {
|
||||
this.getResponse = getResponse;
|
||||
public BytesReference source() {
|
||||
return source;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the GetResponse containing the watch source
|
||||
*/
|
||||
public void getResponse(GetResponse getResponse) {
|
||||
this.getResponse = getResponse;
|
||||
public Map<String, Object> sourceAsMap() throws ElasticsearchParseException {
|
||||
if (source == null) {
|
||||
return null;
|
||||
}
|
||||
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
|
||||
public void readFrom(StreamInput in) throws IOException {
|
||||
super.readFrom(in);
|
||||
if (in.readBoolean()) {
|
||||
getResponse = GetResponse.readGetResponse(in);
|
||||
exists = in.readBoolean();
|
||||
if (exists) {
|
||||
id = in.readString();
|
||||
version = in.readLong();
|
||||
source = in.readBytesReference();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
super.writeTo(out);
|
||||
out.writeBoolean(getResponse != null);
|
||||
if (getResponse != null) {
|
||||
getResponse.writeTo(out);
|
||||
out.writeBoolean(exists);
|
||||
if (exists) {
|
||||
out.writeString(id);
|
||||
out.writeLong(version);
|
||||
out.writeBytesReference(source);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ package org.elasticsearch.watcher.transport.actions.get;
|
||||
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.get.GetResponse;
|
||||
import org.elasticsearch.action.support.ActionFilters;
|
||||
import org.elasticsearch.cluster.ClusterService;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
@ -60,21 +59,27 @@ public class TransportGetWatchAction extends WatcherTransportAction<GetWatchRequ
|
||||
|
||||
@Override
|
||||
protected void masterOperation(GetWatchRequest request, ClusterState state, ActionListener<GetWatchResponse> listener) throws ElasticsearchException {
|
||||
Watch watch = watchService.getWatch(request.watchName());
|
||||
GetResult getResult;
|
||||
if (watch != null) {
|
||||
BytesReference watchSource = null;
|
||||
try (XContentBuilder builder = JsonXContent.contentBuilder()) {
|
||||
builder.value(watch);
|
||||
watchSource = builder.bytes();
|
||||
} catch (IOException e) {
|
||||
listener.onFailure(e);
|
||||
try {
|
||||
Watch watch = watchService.getWatch(request.watchName());
|
||||
GetResult getResult;
|
||||
if (watch != null) {
|
||||
BytesReference watchSource = null;
|
||||
try (XContentBuilder builder = JsonXContent.contentBuilder()) {
|
||||
builder.value(watch);
|
||||
watchSource = builder.bytes();
|
||||
} 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);
|
||||
} else {
|
||||
getResult = new GetResult(WatchStore.INDEX, WatchStore.DOC_TYPE, request.watchName(), -1, false, null, null);
|
||||
listener.onResponse(new GetWatchResponse(getResult.isExists(), getResult.getId(), getResult.getVersion(), getResult.sourceRef()));
|
||||
} catch (Throwable t) {
|
||||
logger.error("failed to get watch [{}]", t, request.watchName());
|
||||
throw t;
|
||||
}
|
||||
listener.onResponse(new GetWatchResponse(new GetResponse(getResult)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -8,14 +8,14 @@ package org.elasticsearch.watcher.watch;
|
||||
|
||||
import org.elasticsearch.ElasticsearchIllegalStateException;
|
||||
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.common.bytes.BytesReference;
|
||||
import org.elasticsearch.common.component.AbstractComponent;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
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 java.io.IOException;
|
||||
@ -109,6 +109,9 @@ public class WatchService extends AbstractComponent {
|
||||
triggerService.add(result.current());
|
||||
}
|
||||
return result.indexResponse();
|
||||
} catch (Exception e) {
|
||||
logger.warn("failed to put watch [{}]", e, name);
|
||||
throw new WatcherException("failed to put [" + watchSource.toUtf8() + "]", e);
|
||||
} finally {
|
||||
lock.release();
|
||||
}
|
||||
|
@ -77,8 +77,8 @@ public class BasicWatcherTests extends AbstractWatcherIntegrationTests {
|
||||
assertWatchWithMinimumPerformedActionsCount("_name", 1);
|
||||
|
||||
GetWatchResponse getWatchResponse = watcherClient().prepareGetWatch().setWatchName("_name").get();
|
||||
assertThat(getWatchResponse.getResponse().isExists(), is(true));
|
||||
assertThat(getWatchResponse.getResponse().isSourceEmpty(), is(false));
|
||||
assertThat(getWatchResponse.exists(), is(true));
|
||||
assertThat(getWatchResponse.source().length(), greaterThan(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -100,10 +100,10 @@ public class WatchThrottleTests extends AbstractWatcherIntegrationTests {
|
||||
}
|
||||
|
||||
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,
|
||||
getWatchResponse.getResponse().getSourceAsBytesRef());
|
||||
Watch parsedWatch = watchParser().parse(getWatchResponse.id(), true,
|
||||
getWatchResponse.source());
|
||||
assertThat(parsedWatch.status().ackStatus().state(), is(Watch.Status.AckStatus.State.AWAITS_EXECUTION));
|
||||
|
||||
long throttledCount = docCount(HistoryStore.INDEX_PREFIX + "*", null,
|
||||
|
@ -73,6 +73,8 @@ public class WatcherRestTests extends ElasticsearchRestTests {
|
||||
return ImmutableSettings.builder()
|
||||
.put("plugin.types", WatcherPlugin.class.getName())
|
||||
.put(InternalNode.HTTP_ENABLED, true)
|
||||
.put("plugin.types", WatcherPlugin.class.getName() + ","
|
||||
+ "," + LicensePlugin.class.getName())
|
||||
.build();
|
||||
}
|
||||
|
||||
@ -93,6 +95,8 @@ public class WatcherRestTests extends ElasticsearchRestTests {
|
||||
return ImmutableSettings.builder()
|
||||
.put("plugin.types", WatcherPlugin.class.getName())
|
||||
.put(InternalNode.HTTP_ENABLED, true)
|
||||
.put("plugin.types", WatcherPlugin.class.getName() + ","
|
||||
+ "," + LicensePlugin.class.getName())
|
||||
.build();
|
||||
}
|
||||
|
||||
@ -139,7 +143,7 @@ public class WatcherRestTests extends ElasticsearchRestTests {
|
||||
.put("shield.user", "test:changeme")
|
||||
.put("shield.authc.realms.esusers.type", ESUsersRealm.TYPE)
|
||||
.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.files.users", writeFile(folder, "users", USERS))
|
||||
.put("shield.authc.realms.esusers.files.users_roles", writeFile(folder, "users_roles", USER_ROLES))
|
||||
|
Loading…
x
Reference in New Issue
Block a user