From da4b259c488766ffad618c3b69adeed544a40a62 Mon Sep 17 00:00:00 2001 From: Tanguy Leroux Date: Thu, 24 Sep 2015 00:03:49 +0200 Subject: [PATCH] Remove start/stop in Exporter(s) Original commit: elastic/x-pack-elasticsearch@9ddcb8119b1dffd0a2d5db90b703b4e973738151 --- .../marvel/agent/exporter/Exporter.java | 4 -- .../marvel/agent/exporter/Exporters.java | 51 ++----------------- .../agent/exporter/http/HttpExporter.java | 10 ---- .../agent/exporter/local/LocalExporter.java | 22 +++----- .../marvel/agent/exporter/ExportersTests.java | 12 ----- 5 files changed, 12 insertions(+), 87 deletions(-) diff --git a/marvel/src/main/java/org/elasticsearch/marvel/agent/exporter/Exporter.java b/marvel/src/main/java/org/elasticsearch/marvel/agent/exporter/Exporter.java index b5aefc1aa68..46d111e8f38 100644 --- a/marvel/src/main/java/org/elasticsearch/marvel/agent/exporter/Exporter.java +++ b/marvel/src/main/java/org/elasticsearch/marvel/agent/exporter/Exporter.java @@ -36,12 +36,8 @@ public abstract class Exporter { return false; } - public abstract void start(); - public abstract void export(Collection marvelDocs) throws Exception; - public abstract void stop(); - public abstract void close(); protected String settingFQN(String setting) { diff --git a/marvel/src/main/java/org/elasticsearch/marvel/agent/exporter/Exporters.java b/marvel/src/main/java/org/elasticsearch/marvel/agent/exporter/Exporters.java index dc1dedc7d31..667b940a0ee 100644 --- a/marvel/src/main/java/org/elasticsearch/marvel/agent/exporter/Exporters.java +++ b/marvel/src/main/java/org/elasticsearch/marvel/agent/exporter/Exporters.java @@ -48,46 +48,10 @@ public class Exporters extends AbstractLifecycleComponent implements @Override protected void doStart() { exporters = initExporters(settings.getAsSettings(EXPORTERS_SETTING)); - - ElasticsearchException exception = null; - for (Exporter exporter : exporters) { - try { - exporter.start(); - } catch (Exception e) { - logger.error("exporter [{}] failed to start", e, exporter.name()); - if (exception == null) { - exception = new ElasticsearchException("failed to start exporters"); - } - exception.addSuppressed(e); - } - } - if (exception != null) { - throw exception; - } } @Override protected void doStop() { - ElasticsearchException exception = null; - for (Exporter exporter : exporters) { - try { - exporter.stop(); - } catch (Exception e) { - logger.error("exporter [{}] failed to stop", e, exporter.name()); - if (exception == null) { - exception = new ElasticsearchException("failed to stop exporters"); - } - exception.addSuppressed(e); - } - } - if (exception != null) { - throw exception; - } - } - - - @Override - protected void doClose() { ElasticsearchException exception = null; for (Exporter exporter : exporters) { try { @@ -105,6 +69,10 @@ public class Exporters extends AbstractLifecycleComponent implements } } + @Override + protected void doClose() { + } + public Exporter getExporter(String name) { return exporters.get(name); } @@ -141,7 +109,6 @@ public class Exporters extends AbstractLifecycleComponent implements .put(updatedSettings) .build()); existing.close(logger); - exporters.start(logger); } // TODO only rebuild the exporters that need to be updated according to settings @@ -218,16 +185,6 @@ public class Exporters extends AbstractLifecycleComponent implements return exporters.get(name); } - void start(ESLogger logger) { - for (Exporter exporter : exporters.values()) { - try { - exporter.start(); - } catch (Exception e) { - logger.error("failed to start exporter [{}]", e, exporter.name()); - } - } - } - void close(ESLogger logger) { for (Exporter exporter : exporters.values()) { try { diff --git a/marvel/src/main/java/org/elasticsearch/marvel/agent/exporter/http/HttpExporter.java b/marvel/src/main/java/org/elasticsearch/marvel/agent/exporter/http/HttpExporter.java index ca9096c7476..f347589673a 100644 --- a/marvel/src/main/java/org/elasticsearch/marvel/agent/exporter/http/HttpExporter.java +++ b/marvel/src/main/java/org/elasticsearch/marvel/agent/exporter/http/HttpExporter.java @@ -153,16 +153,6 @@ public class HttpExporter extends Exporter { MarvelSettings.MARVEL_INDICES_PREFIX, indexTimeFormat, templateVersion); } - @Override - public void start() { - - } - - @Override - public void stop() { - - } - @Override public void export(Collection marvelDocs) throws Exception { HttpURLConnection connection = openExportingConnection(); diff --git a/marvel/src/main/java/org/elasticsearch/marvel/agent/exporter/local/LocalExporter.java b/marvel/src/main/java/org/elasticsearch/marvel/agent/exporter/local/LocalExporter.java index 5cbfc484708..69bdee24afa 100644 --- a/marvel/src/main/java/org/elasticsearch/marvel/agent/exporter/local/LocalExporter.java +++ b/marvel/src/main/java/org/elasticsearch/marvel/agent/exporter/local/LocalExporter.java @@ -45,6 +45,7 @@ import java.util.concurrent.atomic.AtomicReference; import static org.elasticsearch.marvel.agent.exporter.http.HttpExporter.MIN_SUPPORTED_CLUSTER_VERSION; import static org.elasticsearch.marvel.agent.exporter.http.HttpExporter.MIN_SUPPORTED_TEMPLATE_VERSION; +import static org.elasticsearch.marvel.agent.exporter.http.HttpExporterUtils.MARVEL_VERSION_FIELD; /** * @@ -106,18 +107,11 @@ public class LocalExporter extends Exporter { if (builtInTemplateVersion == null) { throw new IllegalStateException("unable to find built-in template version"); } - } - - @Override - public void start() { - if (state.compareAndSet(State.INITIALIZED, State.STARTING)) { - queueConsumer.start(); - state.set(State.STARTED); - } + state.set(State.STARTING); } public void stop() { - if (state.compareAndSet(State.STARTED, State.STOPPING) || state.compareAndSet(State.EXPORTING, State.STOPPING)) { + if (state.compareAndSet(State.STARTED, State.STOPPING) || state.compareAndSet(State.STARTING, State.STOPPING)) { try { queueConsumer.interrupt(); } finally { @@ -134,11 +128,11 @@ public class LocalExporter extends Exporter { } private boolean canExport() { - if (state.get() == State.EXPORTING) { + if (state.get() == State.STARTED) { return true; } - if (state.get() != State.STARTED) { + if (state.get() != State.STARTING) { return false; } @@ -172,7 +166,8 @@ public class LocalExporter extends Exporter { } logger.debug("exporter [{}] can now export marvel data", name()); - state.set(State.EXPORTING); + queueConsumer.start(); + state.set(State.STARTED); return true; } @@ -187,7 +182,7 @@ public class LocalExporter extends Exporter { Version templateVersion() { for (IndexTemplateMetaData template : client.admin().indices().prepareGetTemplates(INDEX_TEMPLATE_NAME).get().getIndexTemplates()) { if (template.getName().equals(INDEX_TEMPLATE_NAME)) { - String version = template.settings().get("index." + HttpExporterUtils.MARVEL_VERSION_FIELD); + String version = template.settings().get("index." + MARVEL_VERSION_FIELD); if (Strings.hasLength(version)) { return Version.fromString(version); } @@ -397,7 +392,6 @@ public class LocalExporter extends Exporter { INITIALIZED, STARTING, STARTED, - EXPORTING, STOPPING, STOPPED, FAILED diff --git a/marvel/src/test/java/org/elasticsearch/marvel/agent/exporter/ExportersTests.java b/marvel/src/test/java/org/elasticsearch/marvel/agent/exporter/ExportersTests.java index e9aa519fc84..6851dcd2f3a 100644 --- a/marvel/src/test/java/org/elasticsearch/marvel/agent/exporter/ExportersTests.java +++ b/marvel/src/test/java/org/elasticsearch/marvel/agent/exporter/ExportersTests.java @@ -243,10 +243,8 @@ public class ExportersTests extends ESTestCase { exporters.export(docsList); verify(exporters.getExporter("_name0"), times(1)).masterOnly(); - verify(exporters.getExporter("_name0"), times(1)).start(); verify(exporters.getExporter("_name0"), times(1)).export(docsList); verify(exporters.getExporter("_name1"), times(1)).masterOnly(); - verify(exporters.getExporter("_name1"), times(1)).start(); } static class TestFactory extends Exporter.Factory { @@ -266,20 +264,10 @@ public class ExportersTests extends ESTestCase { super(type, config); } - @Override - public void start() { - - } - @Override public void export(Collection marvelDocs) throws Exception { } - @Override - public void stop() { - - } - @Override public void close() { }