Alerting : rename alerting package to alerts and fix test.

This commit renames the alerting package to alerts and will create the
alerts index on addAlert if needed.

Original commit: elastic/x-pack-elasticsearch@7cd691bd9b
This commit is contained in:
Brian Murphy 2014-10-24 13:01:45 +01:00
parent db9fae8021
commit ac979c880d
24 changed files with 75 additions and 75 deletions

View File

@ -3,10 +3,10 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.alerting;
package org.elasticsearch.alerts;
import org.elasticsearch.alerting.actions.AlertAction;
import org.elasticsearch.alerting.triggers.AlertTrigger;
import org.elasticsearch.alerts.actions.AlertAction;
import org.elasticsearch.alerts.triggers.AlertTrigger;
import org.elasticsearch.common.joda.time.DateTime;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.ToXContent;

View File

@ -3,7 +3,7 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.alerting;
package org.elasticsearch.alerts;
import org.elasticsearch.ElasticsearchException;
@ -20,11 +20,11 @@ import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.update.UpdateRequest;
import org.elasticsearch.alerting.actions.AlertAction;
import org.elasticsearch.alerting.actions.AlertActionManager;
import org.elasticsearch.alerting.scheduler.AlertScheduler;
import org.elasticsearch.alerting.triggers.AlertTrigger;
import org.elasticsearch.alerting.triggers.TriggerManager;
import org.elasticsearch.alerts.actions.AlertAction;
import org.elasticsearch.alerts.actions.AlertActionManager;
import org.elasticsearch.alerts.scheduler.AlertScheduler;
import org.elasticsearch.alerts.triggers.AlertTrigger;
import org.elasticsearch.alerts.triggers.TriggerManager;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.Requests;
import org.elasticsearch.common.Nullable;
@ -49,10 +49,10 @@ import java.util.concurrent.atomic.AtomicBoolean;
public class AlertManager extends AbstractLifecycleComponent {
public final String ALERT_INDEX = ".alerts";
public final String ALERT_TYPE = "alert";
public final String ALERT_HISTORY_INDEX = "alerthistory";
public final String ALERT_HISTORY_TYPE = "alertHistory";
public static final String ALERT_INDEX = ".alerts";
public static final String ALERT_TYPE = "alert";
public static final String ALERT_HISTORY_INDEX = "alerthistory";
public static final String ALERT_HISTORY_TYPE = "alertHistory";
public static final ParseField QUERY_FIELD = new ParseField("query");
public static final ParseField SCHEDULE_FIELD = new ParseField("schedule");
@ -78,6 +78,8 @@ public class AlertManager extends AbstractLifecycleComponent {
private AlertActionManager actionManager;
final TimeValue defaultTimePeriod = new TimeValue(300*1000); //TODO : read from config
class StarterThread implements Runnable {
@Override
public void run() {
@ -86,7 +88,7 @@ public class AlertManager extends AbstractLifecycleComponent {
while (attempts < 2) {
try {
logger.warn("Sleeping [{}]", attempts);
Thread.sleep(20000);
Thread.sleep(5000);
logger.warn("Slept");
break;
} catch (InterruptedException ie) {
@ -260,11 +262,11 @@ public class AlertManager extends AbstractLifecycleComponent {
}
private void loadAlerts() {
if (!client.admin().indices().prepareExists(ALERT_INDEX).execute().actionGet().isExists()) {
createAlertsIndex();
}
synchronized (alertMap) {
if (!client.admin().indices().prepareExists(ALERT_INDEX).execute().actionGet().isExists()) {
createAlertsIndex();
}
SearchResponse searchResponse = client.prepareSearch().setSource(
"{ \"query\" : " +
"{ \"match_all\" : {}}," +
@ -391,6 +393,10 @@ public class AlertManager extends AbstractLifecycleComponent {
public boolean addAlert(String alertName, Alert alert, boolean persist) {
synchronized (alertMap) {
if (!client.admin().indices().prepareExists(ALERT_INDEX).execute().actionGet().isExists()) {
createAlertsIndex();
}
if (alertMap.containsKey(alertName)) {
throw new ElasticsearchIllegalArgumentException("There is already an alert named ["+alertName+"]");
} else {

View File

@ -3,11 +3,11 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.alerting;
package org.elasticsearch.alerts;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.alerting.triggers.AlertTrigger;
import org.elasticsearch.alerts.triggers.AlertTrigger;
import org.elasticsearch.common.joda.time.DateTime;
import java.util.Arrays;

View File

@ -3,12 +3,12 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.alerting;
package org.elasticsearch.alerts;
import org.elasticsearch.alerting.actions.AlertActionManager;
import org.elasticsearch.alerting.rest.AlertRestHandler;
import org.elasticsearch.alerting.scheduler.AlertScheduler;
import org.elasticsearch.alerting.triggers.TriggerManager;
import org.elasticsearch.alerts.actions.AlertActionManager;
import org.elasticsearch.alerts.rest.AlertRestHandler;
import org.elasticsearch.alerts.scheduler.AlertScheduler;
import org.elasticsearch.alerts.triggers.TriggerManager;
import org.elasticsearch.common.inject.AbstractModule;
public class AlertingModule extends AbstractModule {

View File

@ -3,9 +3,9 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.alerting.actions;
package org.elasticsearch.alerts.actions;
import org.elasticsearch.alerting.AlertResult;
import org.elasticsearch.alerts.AlertResult;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;

View File

@ -3,7 +3,7 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.alerting.actions;
package org.elasticsearch.alerts.actions;
public interface AlertActionFactory {
AlertAction createAction(Object parameters);

View File

@ -3,15 +3,11 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.alerting.actions;
package org.elasticsearch.alerts.actions;
import org.elasticsearch.alerting.Alert;
import org.elasticsearch.alerting.AlertManager;
import org.elasticsearch.alerting.AlertResult;
import org.elasticsearch.alerting.actions.AlertAction;
import org.elasticsearch.alerting.actions.AlertActionFactory;
import org.elasticsearch.alerting.actions.EmailAlertActionFactory;
import org.elasticsearch.alerting.actions.IndexAlertActionFactory;
import org.elasticsearch.alerts.Alert;
import org.elasticsearch.alerts.AlertManager;
import org.elasticsearch.alerts.AlertResult;
import org.elasticsearch.client.Client;
import org.elasticsearch.common.component.AbstractComponent;
import org.elasticsearch.common.inject.Inject;

View File

@ -3,10 +3,10 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.alerting.actions;
package org.elasticsearch.alerts.actions;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.alerting.AlertResult;
import org.elasticsearch.alerts.AlertResult;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.search.SearchHit;

View File

@ -3,7 +3,7 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.alerting.actions;
package org.elasticsearch.alerts.actions;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.ElasticsearchIllegalArgumentException;

View File

@ -3,11 +3,11 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.alerting.actions;
package org.elasticsearch.alerts.actions;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.alerting.AlertResult;
import org.elasticsearch.alerts.AlertResult;
import org.elasticsearch.client.Client;
import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.Loggers;

View File

@ -3,7 +3,7 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.alerting.actions;
package org.elasticsearch.alerts.actions;
import org.elasticsearch.ElasticsearchIllegalArgumentException;
import org.elasticsearch.client.Client;

View File

@ -5,4 +5,4 @@
*/
/**
*/
package org.elasticsearch.alerting.actions;
package org.elasticsearch.alerts.actions;

View File

@ -6,4 +6,4 @@
/**
* Created by brian on 8/12/14.
*/
package org.elasticsearch.alerting;
package org.elasticsearch.alerts;

View File

@ -3,11 +3,11 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.alerting.rest;
package org.elasticsearch.alerts.rest;
import org.elasticsearch.ElasticsearchIllegalArgumentException;
import org.elasticsearch.alerting.Alert;
import org.elasticsearch.alerting.AlertManager;
import org.elasticsearch.alerts.Alert;
import org.elasticsearch.alerts.AlertManager;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.Loggers;

View File

@ -5,4 +5,4 @@
*/
/**
*/
package org.elasticsearch.alerting.rest;
package org.elasticsearch.alerts.rest;

View File

@ -3,9 +3,8 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.alerting.scheduler;
package org.elasticsearch.alerts.scheduler;
import org.elasticsearch.alerting.scheduler.AlertScheduler;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

View File

@ -3,16 +3,16 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.alerting.scheduler;
package org.elasticsearch.alerts.scheduler;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.alerting.Alert;
import org.elasticsearch.alerting.actions.AlertActionManager;
import org.elasticsearch.alerting.AlertManager;
import org.elasticsearch.alerting.AlertResult;
import org.elasticsearch.alerting.triggers.TriggerManager;
import org.elasticsearch.alerts.Alert;
import org.elasticsearch.alerts.actions.AlertActionManager;
import org.elasticsearch.alerts.AlertManager;
import org.elasticsearch.alerts.AlertResult;
import org.elasticsearch.alerts.triggers.TriggerManager;
import org.elasticsearch.client.Client;
import org.elasticsearch.cluster.ClusterChangedEvent;
import org.elasticsearch.cluster.ClusterService;

View File

@ -5,4 +5,4 @@
*/
/**
*/
package org.elasticsearch.alerting.triggers;
package org.elasticsearch.alerts.scheduler;

View File

@ -3,10 +3,9 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.alerting.triggers;
package org.elasticsearch.alerts.triggers;
import org.elasticsearch.ElasticsearchIllegalArgumentException;
import org.elasticsearch.alerting.triggers.ScriptedAlertTrigger;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;

View File

@ -3,9 +3,8 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.alerting.triggers;
package org.elasticsearch.alerts.triggers;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.script.ScriptService;

View File

@ -3,13 +3,13 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.alerting.triggers;
package org.elasticsearch.alerts.triggers;
import org.elasticsearch.ElasticsearchIllegalArgumentException;
import org.elasticsearch.ElasticsearchIllegalStateException;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.alerting.Alert;
import org.elasticsearch.alerting.AlertManager;
import org.elasticsearch.alerts.Alert;
import org.elasticsearch.alerts.AlertManager;
import org.elasticsearch.common.component.AbstractComponent;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;

View File

@ -5,4 +5,4 @@
*/
/**
*/
package org.elasticsearch.alerting.scheduler;
package org.elasticsearch.alerts.triggers;

View File

@ -5,9 +5,9 @@
*/
package org.elasticsearch.plugin.alerting;
import org.elasticsearch.alerting.AlertManager;
import org.elasticsearch.alerting.scheduler.AlertScheduler;
import org.elasticsearch.alerting.AlertingModule;
import org.elasticsearch.alerts.AlertManager;
import org.elasticsearch.alerts.scheduler.AlertScheduler;
import org.elasticsearch.alerts.AlertingModule;
import org.elasticsearch.common.collect.Lists;
import org.elasticsearch.common.component.LifecycleComponent;
import org.elasticsearch.common.inject.Module;

View File

@ -3,14 +3,14 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.alerting;
package org.elasticsearch.alerts;
import org.elasticsearch.alerting.actions.AlertAction;
import org.elasticsearch.alerting.actions.AlertActionFactory;
import org.elasticsearch.alerting.actions.AlertActionManager;
import org.elasticsearch.alerting.scheduler.AlertScheduler;
import org.elasticsearch.alerting.triggers.AlertTrigger;
import org.elasticsearch.alerting.triggers.ScriptedAlertTrigger;
import org.elasticsearch.alerts.actions.AlertAction;
import org.elasticsearch.alerts.actions.AlertActionFactory;
import org.elasticsearch.alerts.actions.AlertActionManager;
import org.elasticsearch.alerts.scheduler.AlertScheduler;
import org.elasticsearch.alerts.triggers.AlertTrigger;
import org.elasticsearch.alerts.triggers.ScriptedAlertTrigger;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
@ -48,6 +48,7 @@ public class BasicAlertingTest extends ElasticsearchIntegrationTest {
public void testAlerSchedulerStartsProperly() throws Exception {
createIndex("my-index");
createIndex(ScriptService.SCRIPT_INDEX);
client().admin().cluster().prepareHealth().setWaitForGreenStatus().execute().actionGet();
client().prepareIndex(ScriptService.SCRIPT_INDEX, "mustache", "query")
.setSource(jsonBuilder().startObject().startObject("template").startObject("match_all").endObject().endObject().endObject())