Remove start/stop in Exporter(s)
Original commit: elastic/x-pack-elasticsearch@9ddcb8119b
This commit is contained in:
parent
415f6eda79
commit
da4b259c48
|
@ -36,12 +36,8 @@ public abstract class Exporter {
|
|||
return false;
|
||||
}
|
||||
|
||||
public abstract void start();
|
||||
|
||||
public abstract void export(Collection<MarvelDoc> marvelDocs) throws Exception;
|
||||
|
||||
public abstract void stop();
|
||||
|
||||
public abstract void close();
|
||||
|
||||
protected String settingFQN(String setting) {
|
||||
|
|
|
@ -48,46 +48,10 @@ public class Exporters extends AbstractLifecycleComponent<Exporters> 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<Exporters> implements
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doClose() {
|
||||
}
|
||||
|
||||
public Exporter getExporter(String name) {
|
||||
return exporters.get(name);
|
||||
}
|
||||
|
@ -141,7 +109,6 @@ public class Exporters extends AbstractLifecycleComponent<Exporters> 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<Exporters> 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 {
|
||||
|
|
|
@ -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<MarvelDoc> marvelDocs) throws Exception {
|
||||
HttpURLConnection connection = openExportingConnection();
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<TestFactory.TestExporter> {
|
||||
|
@ -266,20 +264,10 @@ public class ExportersTests extends ESTestCase {
|
|||
super(type, config);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void export(Collection<MarvelDoc> marvelDocs) throws Exception {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue