Remove start/stop in Exporter(s)

Original commit: elastic/x-pack-elasticsearch@9ddcb8119b
This commit is contained in:
Tanguy Leroux 2015-09-24 00:03:49 +02:00 committed by uboness
parent 415f6eda79
commit da4b259c48
5 changed files with 12 additions and 87 deletions

View File

@ -36,12 +36,8 @@ public abstract class Exporter {
return false; return false;
} }
public abstract void start();
public abstract void export(Collection<MarvelDoc> marvelDocs) throws Exception; public abstract void export(Collection<MarvelDoc> marvelDocs) throws Exception;
public abstract void stop();
public abstract void close(); public abstract void close();
protected String settingFQN(String setting) { protected String settingFQN(String setting) {

View File

@ -48,46 +48,10 @@ public class Exporters extends AbstractLifecycleComponent<Exporters> implements
@Override @Override
protected void doStart() { protected void doStart() {
exporters = initExporters(settings.getAsSettings(EXPORTERS_SETTING)); 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 @Override
protected void doStop() { 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; ElasticsearchException exception = null;
for (Exporter exporter : exporters) { for (Exporter exporter : exporters) {
try { try {
@ -105,6 +69,10 @@ public class Exporters extends AbstractLifecycleComponent<Exporters> implements
} }
} }
@Override
protected void doClose() {
}
public Exporter getExporter(String name) { public Exporter getExporter(String name) {
return exporters.get(name); return exporters.get(name);
} }
@ -141,7 +109,6 @@ public class Exporters extends AbstractLifecycleComponent<Exporters> implements
.put(updatedSettings) .put(updatedSettings)
.build()); .build());
existing.close(logger); existing.close(logger);
exporters.start(logger);
} }
// TODO only rebuild the exporters that need to be updated according to settings // TODO only rebuild the exporters that need to be updated according to settings
@ -218,16 +185,6 @@ public class Exporters extends AbstractLifecycleComponent<Exporters> implements
return exporters.get(name); 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) { void close(ESLogger logger) {
for (Exporter exporter : exporters.values()) { for (Exporter exporter : exporters.values()) {
try { try {

View File

@ -153,16 +153,6 @@ public class HttpExporter extends Exporter {
MarvelSettings.MARVEL_INDICES_PREFIX, indexTimeFormat, templateVersion); MarvelSettings.MARVEL_INDICES_PREFIX, indexTimeFormat, templateVersion);
} }
@Override
public void start() {
}
@Override
public void stop() {
}
@Override @Override
public void export(Collection<MarvelDoc> marvelDocs) throws Exception { public void export(Collection<MarvelDoc> marvelDocs) throws Exception {
HttpURLConnection connection = openExportingConnection(); HttpURLConnection connection = openExportingConnection();

View File

@ -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_CLUSTER_VERSION;
import static org.elasticsearch.marvel.agent.exporter.http.HttpExporter.MIN_SUPPORTED_TEMPLATE_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) { if (builtInTemplateVersion == null) {
throw new IllegalStateException("unable to find built-in template version"); throw new IllegalStateException("unable to find built-in template version");
} }
} state.set(State.STARTING);
@Override
public void start() {
if (state.compareAndSet(State.INITIALIZED, State.STARTING)) {
queueConsumer.start();
state.set(State.STARTED);
}
} }
public void stop() { 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 { try {
queueConsumer.interrupt(); queueConsumer.interrupt();
} finally { } finally {
@ -134,11 +128,11 @@ public class LocalExporter extends Exporter {
} }
private boolean canExport() { private boolean canExport() {
if (state.get() == State.EXPORTING) { if (state.get() == State.STARTED) {
return true; return true;
} }
if (state.get() != State.STARTED) { if (state.get() != State.STARTING) {
return false; return false;
} }
@ -172,7 +166,8 @@ public class LocalExporter extends Exporter {
} }
logger.debug("exporter [{}] can now export marvel data", name()); logger.debug("exporter [{}] can now export marvel data", name());
state.set(State.EXPORTING); queueConsumer.start();
state.set(State.STARTED);
return true; return true;
} }
@ -187,7 +182,7 @@ public class LocalExporter extends Exporter {
Version templateVersion() { Version templateVersion() {
for (IndexTemplateMetaData template : client.admin().indices().prepareGetTemplates(INDEX_TEMPLATE_NAME).get().getIndexTemplates()) { for (IndexTemplateMetaData template : client.admin().indices().prepareGetTemplates(INDEX_TEMPLATE_NAME).get().getIndexTemplates()) {
if (template.getName().equals(INDEX_TEMPLATE_NAME)) { 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)) { if (Strings.hasLength(version)) {
return Version.fromString(version); return Version.fromString(version);
} }
@ -397,7 +392,6 @@ public class LocalExporter extends Exporter {
INITIALIZED, INITIALIZED,
STARTING, STARTING,
STARTED, STARTED,
EXPORTING,
STOPPING, STOPPING,
STOPPED, STOPPED,
FAILED FAILED

View File

@ -243,10 +243,8 @@ public class ExportersTests extends ESTestCase {
exporters.export(docsList); exporters.export(docsList);
verify(exporters.getExporter("_name0"), times(1)).masterOnly(); 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("_name0"), times(1)).export(docsList);
verify(exporters.getExporter("_name1"), times(1)).masterOnly(); verify(exporters.getExporter("_name1"), times(1)).masterOnly();
verify(exporters.getExporter("_name1"), times(1)).start();
} }
static class TestFactory extends Exporter.Factory<TestFactory.TestExporter> { static class TestFactory extends Exporter.Factory<TestFactory.TestExporter> {
@ -266,20 +264,10 @@ public class ExportersTests extends ESTestCase {
super(type, config); super(type, config);
} }
@Override
public void start() {
}
@Override @Override
public void export(Collection<MarvelDoc> marvelDocs) throws Exception { public void export(Collection<MarvelDoc> marvelDocs) throws Exception {
} }
@Override
public void stop() {
}
@Override @Override
public void close() { public void close() {
} }