[LOGGING] Log an error message when we fail to parse a `Watch` or `WatchRecord`

If we failed to parse a `Watch` or `WatchRecord` at startup we currently get stuck as this behaviour is undefined.
This commit just adds some logging so we can tell that this is what happened.

Original commit: elastic/x-pack-elasticsearch@aa6d95c172
This commit is contained in:
Brian Murphy 2015-04-16 14:38:33 -04:00
parent 6309d2b5d3
commit 6e0cabac62
2 changed files with 27 additions and 13 deletions

View File

@ -11,6 +11,7 @@ import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.action.search.*;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.watcher.WatcherException;
import org.elasticsearch.watcher.support.TemplateUtils;
import org.elasticsearch.watcher.support.init.proxy.ClientProxy;
import org.elasticsearch.cluster.ClusterState;
@ -127,10 +128,15 @@ public class HistoryStore extends AbstractComponent {
while (response.getHits().hits().length != 0) {
for (SearchHit sh : response.getHits()) {
String id = sh.getId();
WatchRecord record = recordParser.parse(id, sh.version(), sh.getSourceRef());
assert record.state() == recordState;
logger.debug("loaded watch record [{}/{}/{}]", sh.index(), sh.type(), sh.id());
records.add(record);
try {
WatchRecord record = recordParser.parse(id, sh.version(), sh.getSourceRef());
assert record.state() == recordState;
logger.debug("loaded watch record [{}/{}/{}]", sh.index(), sh.type(), sh.id());
records.add(record);
} catch (WatcherException we) {
logger.error("while loading records, failed to parse watch record [{}]", we, id);
throw we;
}
}
response = client.searchScroll(response.getScrollId(), scrollTimeout);
}

View File

@ -13,11 +13,9 @@ import org.elasticsearch.action.delete.DeleteRequest;
import org.elasticsearch.action.delete.DeleteResponse;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.action.search.*;
import org.elasticsearch.watcher.WatcherException;
import org.elasticsearch.watcher.support.Callback;
import org.elasticsearch.watcher.support.TemplateUtils;
import org.elasticsearch.watcher.support.init.proxy.ClientProxy;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.cluster.ClusterChangedEvent;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.cluster.ClusterState;
@ -33,6 +31,11 @@ import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.watcher.WatcherException;
import org.elasticsearch.watcher.WatcherSettingsException;
import org.elasticsearch.watcher.support.Callback;
import org.elasticsearch.watcher.support.TemplateUtils;
import org.elasticsearch.watcher.support.init.proxy.ClientProxy;
import java.io.IOException;
import java.util.concurrent.ConcurrentMap;
@ -253,10 +256,15 @@ public class WatchStore extends AbstractComponent {
while (response.getHits().hits().length != 0) {
for (SearchHit hit : response.getHits()) {
String name = hit.getId();
Watch watch = watchParser.parse(name, true, hit.getSourceRef());
watch.status().version(hit.version());
watches.put(name, watch);
count++;
try {
Watch watch = watchParser.parse(name, true, hit.getSourceRef());
watch.status().version(hit.version());
watches.put(name, watch);
count++;
} catch (WatcherSettingsException wse) {
logger.error("while loading watches, failed to parse [{}]", wse, name);
throw wse;
}
}
response = client.searchScroll(response.getScrollId(), scrollTimeout);
}