applied feedback

Original commit: elastic/x-pack-elasticsearch@115429ae67
This commit is contained in:
Martijn van Groningen 2015-02-27 11:00:10 +01:00
parent 127aee514c
commit 9e8405e619
2 changed files with 16 additions and 21 deletions

View File

@ -7,6 +7,7 @@ package org.elasticsearch.alerts;
import org.elasticsearch.cluster.ClusterChangedEvent; import org.elasticsearch.cluster.ClusterChangedEvent;
import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.ClusterStateListener; import org.elasticsearch.cluster.ClusterStateListener;
import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.component.AbstractComponent;
import org.elasticsearch.common.component.LifecycleListener; import org.elasticsearch.common.component.LifecycleListener;
@ -39,19 +40,26 @@ public class AlertsLifeCycleService extends AbstractComponent implements Cluster
indicesService.addLifecycleListener(new LifecycleListener() { indicesService.addLifecycleListener(new LifecycleListener() {
@Override @Override
public void beforeStop() { public void beforeStop() {
AlertsLifeCycleService.this.alertsService.stop(); stop(false);
} }
}); });
manuallyStopped = !settings.getAsBoolean("alerts.start_immediately", true); manuallyStopped = !settings.getAsBoolean("alerts.start_immediately", true);
} }
public synchronized void start() { public void start() {
manuallyStopped = false; start(clusterService.state());
alertsService.start(clusterService.state());
} }
public synchronized void stop() { public void stop() {
manuallyStopped = true; stop(true);
}
private synchronized void start(ClusterState state) {
alertsService.start(state);
}
private synchronized void stop(boolean manual) {
manuallyStopped = manual;
alertsService.stop(); alertsService.stop();
} }
@ -65,7 +73,7 @@ public class AlertsLifeCycleService extends AbstractComponent implements Cluster
threadPool.executor(ThreadPool.Names.GENERIC).execute(new Runnable() { threadPool.executor(ThreadPool.Names.GENERIC).execute(new Runnable() {
@Override @Override
public void run() { public void run() {
alertsService.stop(); stop(false);
} }
}); });
} else { } else {
@ -78,7 +86,7 @@ public class AlertsLifeCycleService extends AbstractComponent implements Cluster
threadPool.executor(ThreadPool.Names.GENERIC).execute(new Runnable() { threadPool.executor(ThreadPool.Names.GENERIC).execute(new Runnable() {
@Override @Override
public void run() { public void run() {
alertsService.start(event.state()); start(event.state());
} }
}); });
} }

View File

@ -9,7 +9,6 @@ import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus; import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
import org.elasticsearch.action.admin.indices.refresh.RefreshResponse; import org.elasticsearch.action.admin.indices.refresh.RefreshResponse;
import org.elasticsearch.action.index.IndexResponse; import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.alerts.AlertsService;
import org.elasticsearch.alerts.support.init.proxy.ClientProxy; import org.elasticsearch.alerts.support.init.proxy.ClientProxy;
import org.elasticsearch.alerts.support.init.proxy.ScriptServiceProxy; import org.elasticsearch.alerts.support.init.proxy.ScriptServiceProxy;
import org.elasticsearch.client.Requests; import org.elasticsearch.client.Requests;
@ -31,19 +30,7 @@ public abstract class AbstractAlertsSingleNodeTests extends ElasticsearchSingleN
@AfterClass @AfterClass
public static void cleanupSuite() throws Exception { public static void cleanupSuite() throws Exception {
assertBusy(new Runnable() {
@Override
public void run() {
assertThat(getInstanceFromNode(AlertsService.class).state(), equalTo(AlertsService.State.STARTED));
}
});
node().stop(); node().stop();
assertBusy(new Runnable() {
@Override
public void run() {
assertThat(getInstanceFromNode(AlertsService.class).state(), equalTo(AlertsService.State.STOPPED));
}
});
} }
@Override @Override