Properly catch errors on startup and return false from start if we get errors looking for the alert history indices.
Original commit: elastic/x-pack-elasticsearch@9db4691783
This commit is contained in:
parent
779e7e83c0
commit
193865925c
|
@ -102,25 +102,29 @@ public class AlertActionManager extends AbstractComponent {
|
||||||
if (started.get()) {
|
if (started.get()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
String[] indices = state.metaData().concreteIndices(IndicesOptions.lenientExpandOpen(), ALERT_HISTORY_INDEX_PREFIX + "*");
|
try {
|
||||||
if (indices.length == 0) {
|
String[] indices = state.metaData().concreteIndices(IndicesOptions.lenientExpandOpen(), ALERT_HISTORY_INDEX_PREFIX + "*");
|
||||||
logger.info("No previous .alerthistory index, skip loading of alert actions");
|
if (indices.length == 0) {
|
||||||
templateHelper.checkAndUploadIndexTemplate(state, "alerthistory");
|
logger.info("No previous .alerthistory index, skip loading of alert actions");
|
||||||
doStart();
|
templateHelper.checkAndUploadIndexTemplate(state, "alerthistory");
|
||||||
return true;
|
doStart();
|
||||||
}
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
for (String index : indices) {
|
for (String index : indices) {
|
||||||
IndexMetaData indexMetaData = state.getMetaData().index(index);
|
IndexMetaData indexMetaData = state.getMetaData().index(index);
|
||||||
if (indexMetaData != null) {
|
if (indexMetaData != null) {
|
||||||
if (!state.routingTable().index(index).allPrimaryShardsActive()) {
|
if (!state.routingTable().index(index).allPrimaryShardsActive()) {
|
||||||
logger.info("Not all primary shards of the [{}] index are started", index);
|
logger.info("Not all primary shards of the [{}] index are started", index);
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (Exception e){
|
||||||
|
logger.error("Unable to check index availability", e);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
loadQueue();
|
loadQueue();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -258,12 +262,15 @@ public class AlertActionManager extends AbstractComponent {
|
||||||
|
|
||||||
public void addAlertAction(Alert alert, DateTime scheduledFireTime, DateTime fireTime) throws IOException {
|
public void addAlertAction(Alert alert, DateTime scheduledFireTime, DateTime fireTime) throws IOException {
|
||||||
ensureStarted();
|
ensureStarted();
|
||||||
|
logger.debug("Adding alert action for alert [{}]", alert.alertName());
|
||||||
|
|
||||||
AlertActionEntry entry = new AlertActionEntry(alert, scheduledFireTime, fireTime, AlertActionState.SEARCH_NEEDED);
|
AlertActionEntry entry = new AlertActionEntry(alert, scheduledFireTime, fireTime, AlertActionState.SEARCH_NEEDED);
|
||||||
IndexResponse response = client.prepareIndex(getAlertHistoryIndexNameForTime(scheduledFireTime), ALERT_HISTORY_TYPE, entry.getId())
|
String alertHistoryIndex = getAlertHistoryIndexNameForTime(scheduledFireTime);
|
||||||
|
IndexResponse response = client.prepareIndex(alertHistoryIndex, ALERT_HISTORY_TYPE, entry.getId())
|
||||||
.setSource(XContentFactory.jsonBuilder().value(entry))
|
.setSource(XContentFactory.jsonBuilder().value(entry))
|
||||||
.setOpType(IndexRequest.OpType.CREATE)
|
.setOpType(IndexRequest.OpType.CREATE)
|
||||||
.get();
|
.get();
|
||||||
logger.debug("Adding alert action for alert [{}]", alert.alertName());
|
|
||||||
entry.setVersion(response.getVersion());
|
entry.setVersion(response.getVersion());
|
||||||
long currentSize = actionsToBeProcessed.size() + 1;
|
long currentSize = actionsToBeProcessed.size() + 1;
|
||||||
actionsToBeProcessed.add(entry);
|
actionsToBeProcessed.add(entry);
|
||||||
|
|
Loading…
Reference in New Issue