Watcher: Return proper GetWatchResponse if watcher index is missing (elastic/x-pack-elasticsearch#1462)
This ensures that the same responses is returned, when a watch is missing and when the whole watch index is missing for the GetWatchResponse. relates elastic/x-pack-elasticsearch#1409 Original commit: elastic/x-pack-elasticsearch@88a7335fa9
This commit is contained in:
parent
adf480f8fd
commit
55359433ae
|
@ -12,6 +12,7 @@ import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.common.xcontent.XContentType;
|
import org.elasticsearch.common.xcontent.XContentType;
|
||||||
|
import org.elasticsearch.index.IndexNotFoundException;
|
||||||
import org.elasticsearch.license.XPackLicenseState;
|
import org.elasticsearch.license.XPackLicenseState;
|
||||||
import org.elasticsearch.threadpool.ThreadPool;
|
import org.elasticsearch.threadpool.ThreadPool;
|
||||||
import org.elasticsearch.transport.TransportService;
|
import org.elasticsearch.transport.TransportService;
|
||||||
|
@ -64,6 +65,13 @@ public class TransportGetWatchAction extends WatcherTransportAction<GetWatchRequ
|
||||||
} else {
|
} else {
|
||||||
listener.onResponse(new GetWatchResponse(request.getId()));
|
listener.onResponse(new GetWatchResponse(request.getId()));
|
||||||
}
|
}
|
||||||
}, listener::onFailure));
|
}, e -> {
|
||||||
|
// special case. This API should not care if the index is missing or not, it should respond with the watch not being found
|
||||||
|
if (e instanceof IndexNotFoundException) {
|
||||||
|
listener.onResponse(new GetWatchResponse(request.getId()));
|
||||||
|
} else {
|
||||||
|
listener.onFailure(e);
|
||||||
|
}
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,6 @@ import static org.elasticsearch.xpack.watcher.client.WatchSourceBuilders.watchBu
|
||||||
import static org.elasticsearch.xpack.watcher.input.InputBuilders.simpleInput;
|
import static org.elasticsearch.xpack.watcher.input.InputBuilders.simpleInput;
|
||||||
import static org.elasticsearch.xpack.watcher.trigger.TriggerBuilders.schedule;
|
import static org.elasticsearch.xpack.watcher.trigger.TriggerBuilders.schedule;
|
||||||
import static org.elasticsearch.xpack.watcher.trigger.schedule.Schedules.interval;
|
import static org.elasticsearch.xpack.watcher.trigger.schedule.Schedules.interval;
|
||||||
import static org.hamcrest.Matchers.containsString;
|
|
||||||
import static org.hamcrest.Matchers.hasKey;
|
import static org.hamcrest.Matchers.hasKey;
|
||||||
import static org.hamcrest.Matchers.is;
|
import static org.hamcrest.Matchers.is;
|
||||||
import static org.hamcrest.Matchers.not;
|
import static org.hamcrest.Matchers.not;
|
||||||
|
@ -55,16 +54,14 @@ public class GetWatchTests extends AbstractWatcherIntegrationTestCase {
|
||||||
assertThat(source, not(hasKey("status")));
|
assertThat(source, not(hasKey("status")));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetNotFoundOnNonExistingIndex() throws Exception {
|
public void testGetNotFound() throws Exception {
|
||||||
// ensure index/alias is deleted, test infra might have created it automatically
|
// does not matter if the watch does not exist or the index does not exist, we expect the same response
|
||||||
|
if (randomBoolean()) {
|
||||||
try {
|
try {
|
||||||
assertAcked(client().admin().indices().prepareDelete(Watch.INDEX));
|
assertAcked(client().admin().indices().prepareDelete(Watch.INDEX));
|
||||||
} catch (IndexNotFoundException e) {}
|
} catch (IndexNotFoundException e) {}
|
||||||
Exception e = expectThrows(Exception.class, () -> watcherClient().getWatch(new GetWatchRequest("_name")).get());
|
|
||||||
assertThat(e.getMessage(), containsString("no such index"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetNotFound() throws Exception {
|
|
||||||
GetWatchResponse getResponse = watcherClient().getWatch(new GetWatchRequest("_name")).get();
|
GetWatchResponse getResponse = watcherClient().getWatch(new GetWatchRequest("_name")).get();
|
||||||
assertThat(getResponse, notNullValue());
|
assertThat(getResponse, notNullValue());
|
||||||
assertThat(getResponse.getId(), is("_name"));
|
assertThat(getResponse.getId(), is("_name"));
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
---
|
---
|
||||||
"Test get watch api with missing watch":
|
"Test get watch api with missing watch on existing index":
|
||||||
- do:
|
- do:
|
||||||
cluster.health:
|
cluster.health:
|
||||||
wait_for_status: yellow
|
wait_for_status: yellow
|
||||||
|
@ -17,3 +17,21 @@
|
||||||
id: "missing_watch"
|
id: "missing_watch"
|
||||||
- match: { found : false}
|
- match: { found : false}
|
||||||
- match: { _id: "missing_watch" }
|
- match: { _id: "missing_watch" }
|
||||||
|
|
||||||
|
---
|
||||||
|
"Test get watch api with missing watch on missing index":
|
||||||
|
- do:
|
||||||
|
cluster.health:
|
||||||
|
wait_for_status: yellow
|
||||||
|
|
||||||
|
- do:
|
||||||
|
indices.delete:
|
||||||
|
index: .watches*
|
||||||
|
ignore: 404
|
||||||
|
|
||||||
|
- do:
|
||||||
|
catch: missing
|
||||||
|
xpack.watcher.get_watch:
|
||||||
|
id: "missing_watch"
|
||||||
|
- match: { found : false}
|
||||||
|
- match: { _id: "missing_watch" }
|
||||||
|
|
Loading…
Reference in New Issue