Skip to content

Commit

Permalink
fix guice and plugin initialization after split (elastic#3677)
Browse files Browse the repository at this point in the history
the x-pack-split required updating the IndexLifecycle plugin to
be a proper plugin with the Plugin API methods instead of the XPackPlugin API
methods.
  • Loading branch information
talevy committed May 14, 2018
1 parent 22331d4 commit 21ce214
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 16 deletions.
Expand Up @@ -109,7 +109,7 @@ public Request(String policyName) {
this.policyName = policyName;
}

Request() {
public Request() {
}

public String getPolicyName() {
Expand Down
Expand Up @@ -53,7 +53,7 @@ public static class Response extends ActionResponse implements ToXContentObject

private LifecyclePolicy policy;

Response() {
public Response() {
}

public Response(LifecyclePolicy policy) {
Expand Down Expand Up @@ -114,7 +114,7 @@ public Request(String policyName) {
this.policyName = policyName;
}

Request() {
public Request() {
}

public String getPolicyName() {
Expand Down
Expand Up @@ -116,7 +116,7 @@ public Request(LifecyclePolicy policy) {
this.policy = policy;
}

Request() {
public Request() {
}

public LifecyclePolicy getPolicy() {
Expand Down
Expand Up @@ -24,11 +24,15 @@
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.settings.SettingsFilter;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.plugins.ActionPlugin.ActionHandler;
import org.elasticsearch.env.Environment;
import org.elasticsearch.env.NodeEnvironment;
import org.elasticsearch.plugins.ActionPlugin;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestHandler;
import org.elasticsearch.script.ScriptService;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.watcher.ResourceWatcherService;
import org.elasticsearch.xpack.XPackPlugin;
import org.elasticsearch.xpack.XPackSettings;
import org.elasticsearch.xpack.indexlifecycle.action.DeleteLifecycleAction;
Expand All @@ -41,7 +45,6 @@
import org.elasticsearch.xpack.indexlifecycle.action.TransportGetLifecycleAction;
import org.elasticsearch.xpack.indexlifecycle.action.TransportDeleteLifcycleAction;

import java.io.IOException;
import java.time.Clock;
import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -52,7 +55,7 @@

import static java.util.Collections.emptyList;

public class IndexLifecycle extends Plugin {
public class IndexLifecycle extends Plugin implements ActionPlugin {
public static final String NAME = "index_lifecycle";
public static final String BASE_PATH = "/_xpack/index_lifecycle/";
private final SetOnce<IndexLifecycleService> indexLifecycleInitialisationService = new SetOnce<>();
Expand All @@ -66,7 +69,12 @@ public IndexLifecycle(Settings settings) {
this.transportClientMode = XPackPlugin.transportClientMode(settings);
}

public Collection<Module> nodeModules() {
// overridable by tests
protected Clock getClock() {
return Clock.systemUTC();
}

public Collection<Module> createGuiceModules() {
List<Module> modules = new ArrayList<>();

if (transportClientMode) {
Expand All @@ -88,21 +96,19 @@ public List<Setting<?>> getSettings() {
LifecycleSettings.LIFECYCLE_ACTION_SETTING);
}

public Collection<Object> createComponents(Client client, ClusterService clusterService, Clock clock,
ThreadPool threadPool) {
@Override
public Collection<Object> createComponents(Client client, ClusterService clusterService, ThreadPool threadPool,
ResourceWatcherService resourceWatcherService, ScriptService scriptService,
NamedXContentRegistry xContentRegistry, Environment environment,
NodeEnvironment nodeEnvironment, NamedWriteableRegistry namedWriteableRegistry) {
if (enabled == false || transportClientMode) {
return emptyList();
}
indexLifecycleInitialisationService
.set(new IndexLifecycleService(settings, client, clusterService, clock, threadPool, System::currentTimeMillis));
.set(new IndexLifecycleService(settings, client, clusterService, getClock(), threadPool, System::currentTimeMillis));
return Collections.singletonList(indexLifecycleInitialisationService.get());
}

@Override
public void close() throws IOException {
indexLifecycleInitialisationService.get().close();
}

@Override
public List<Entry> getNamedWriteables() {
return Arrays.asList(
Expand Down Expand Up @@ -142,6 +148,7 @@ public List<org.elasticsearch.common.xcontent.NamedXContentRegistry.Entry> getNa
new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(DeleteAction.NAME), DeleteAction::parse));
}

@Override
public List<RestHandler> getRestHandlers(Settings settings, RestController restController, ClusterSettings clusterSettings,
IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter, IndexNameExpressionResolver indexNameExpressionResolver,
Supplier<DiscoveryNodes> nodesInCluster) {
Expand All @@ -151,11 +158,16 @@ public List<RestHandler> getRestHandlers(Settings settings, RestController restC
new RestDeleteLifecycleAction(settings, restController));
}

@Override
public List<ActionHandler<? extends ActionRequest, ? extends ActionResponse>> getActions() {
return Arrays.asList(
new ActionHandler<>(PutLifecycleAction.INSTANCE, TransportPutLifecycleAction.class),
new ActionHandler<>(GetLifecycleAction.INSTANCE, TransportGetLifecycleAction.class),
new ActionHandler<>(DeleteLifecycleAction.INSTANCE, TransportDeleteLifcycleAction.class));
}

@Override
public void close() {
indexLifecycleInitialisationService.get().close();
}
}

0 comments on commit 21ce214

Please sign in to comment.