Creates a new X-Pack feature for index lifecycle

Feature consists of a shell of a persistant task which will later be used to inspect the index settings and apply curator like changes to the index (move from hot to warm, rollover, shrink etc.)
This commit is contained in:
Colin Goodheart-Smithe 2017-09-11 13:36:56 +01:00
commit 4aaec2ef81
3 changed files with 249 additions and 0 deletions

View File

@ -0,0 +1,154 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.xpack.indexlifecycle;
import org.elasticsearch.action.ActionRequest;
import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
import org.elasticsearch.cluster.node.DiscoveryNodes;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.inject.Module;
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
import org.elasticsearch.common.settings.ClusterSettings;
import org.elasticsearch.common.settings.IndexScopedSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.settings.SettingsFilter;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.plugins.ActionPlugin;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestHandler;
import org.elasticsearch.threadpool.ExecutorBuilder;
import org.elasticsearch.threadpool.FixedExecutorBuilder;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.xpack.XPackPlugin;
import org.elasticsearch.xpack.XPackSettings;
import org.elasticsearch.xpack.security.InternalClient;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.function.Supplier;
public class IndexLifecycle implements ActionPlugin {
public static final String NAME = "index_lifecycle";
public static final String BASE_PATH = "/_xpack/index_lifecycle/";
public static final String THREAD_POOL_NAME = NAME;
private Settings settings;
private boolean enabled;
private boolean transportClientMode;
private boolean tribeNode;
private boolean tribeNodeClient;
public IndexLifecycle(Settings settings) {
this.settings = settings;
this.enabled = XPackSettings.INDEX_LIFECYCLE_ENABLED.get(settings);
this.transportClientMode = XPackPlugin.transportClientMode(settings);
this.tribeNode = XPackPlugin.isTribeNode(settings);
this.tribeNodeClient = XPackPlugin.isTribeClientNode(settings);
}
public Collection<Module> nodeModules() {
List<Module> modules = new ArrayList<>();
if (transportClientMode) {
return modules;
}
modules.add(b -> XPackPlugin.bindFeatureSet(b, IndexLifecycleFeatureSet.class));
return modules;
}
public Collection<Object> createComponents(InternalClient internalClient, ClusterService clusterService, ThreadPool threadPool) {
return Collections.singletonList(new IndexLifecycleInitialisationService(settings, clusterService));
}
@Override
public List<RestHandler> getRestHandlers(Settings settings, RestController restController, ClusterSettings clusterSettings,
IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter,
IndexNameExpressionResolver indexNameExpressionResolver,
Supplier<DiscoveryNodes> nodesInCluster) {
if (!enabled || tribeNodeClient) {
return Collections.emptyList();
}
return Arrays.asList(
// new RestRollupSearchAction(settings, restController),
// new RestPutRollupJobAction(settings, restController),
// new RestStartRollupJobAction(settings, restController),
// new RestStopRollupJobAction(settings, restController),
// new RestDeleteRollupJobAction(settings, restController)
);
}
@Override
public List<ActionHandler<? extends ActionRequest, ? extends ActionResponse>> getActions() {
if (!enabled) {
return Collections.emptyList();
}
return Arrays.asList(
// new ActionHandler<>(RollupSearchAction.INSTANCE, RollupSearchAction.TransportAction.class),
// new ActionHandler<>(PutRollupJobAction.INSTANCE, PutRollupJobAction.TransportAction.class),
// new ActionHandler<>(StartRollupJobAction.INSTANCE, StartRollupJobAction.TransportAction.class),
// new ActionHandler<>(StopRollupJobAction.INSTANCE, StopRollupJobAction.TransportAction.class),
// new ActionHandler<>(DeleteRollupJobAction.INSTANCE, DeleteRollupJobAction.TransportAction.class)
);
}
public List<ExecutorBuilder<?>> getExecutorBuilders(Settings settings) {
if (false == enabled || tribeNode || tribeNodeClient || transportClientMode) {
return Collections.emptyList();
}
FixedExecutorBuilder indexing = new FixedExecutorBuilder(settings, IndexLifecycle.THREAD_POOL_NAME, 4, 4,
"xpack.index_lifecycle.thread_pool");
return Collections.singletonList(indexing);
}
// public Collection<PersistentTasksExecutor<?>> getPersistentTasksExecutors(InternalClient client,
// ClusterService clusterService,
// SchedulerEngine schedulerEngine) {
// return Collections.singletonList(
// new IndexLifecycleTask.IndexLifecycleJobPersistentTasksExecutor(settings, client, clusterService, schedulerEngine));
// }
public List<NamedWriteableRegistry.Entry> getNamedWriteables() {
return Arrays.asList(
// // Metadata
// new NamedWriteableRegistry.Entry(MetaData.Custom.class, "rollup", RollupMetadata::new),
// new NamedWriteableRegistry.Entry(NamedDiff.class, "rollup", RollupMetadata.RollupMetadataDiff::new),
//
// // Persistent action requests
// new NamedWriteableRegistry.Entry(PersistentTaskParams.class, RollupJobTask.TASK_NAME,
// RollupJob::new),
//
// // Task statuses
// new NamedWriteableRegistry.Entry(Task.Status.class, RollupJobStatus.NAME, RollupJobStatus::new)
);
}
public List<NamedXContentRegistry.Entry> getNamedXContent() {
return Arrays.asList(
// // Custom metadata
// new NamedXContentRegistry.Entry(MetaData.Custom.class, new ParseField("rollup"),
// parser -> RollupMetadata.METADATA_PARSER.parse(parser, null).build()),
//
// // Persistent action requests
// new NamedXContentRegistry.Entry(PersistentTaskParams.class, new ParseField(RollupJobTask.TASK_NAME),
// parser -> RollupJob.Builder.fromXContent(parser).build())
//
// // Task statuses
// //new NamedXContentRegistry.Entry(Task.Status.class, new ParseField(RollupJobStatus.NAME), RollupJobStatus::fromXContent)
);
}
}

View File

@ -0,0 +1,61 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.xpack.indexlifecycle;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.license.XPackLicenseState;
import org.elasticsearch.xpack.XPackFeatureSet;
import org.elasticsearch.xpack.XPackPlugin;
import org.elasticsearch.xpack.XPackSettings;
import java.util.Map;
public class IndexLifecycleFeatureSet implements XPackFeatureSet {
private final boolean enabled;
private final XPackLicenseState licenseState;
@Inject
public IndexLifecycleFeatureSet(Settings settings, @Nullable XPackLicenseState licenseState) {
this.enabled = XPackSettings.INDEX_LIFECYCLE_ENABLED.get(settings);
this.licenseState = licenseState;
}
@Override
public String name() {
return XPackPlugin.INDEX_LIFECYCLE;
}
@Override
public String description() {
return "Index lifecycle management for the Elastic Stack";
}
@Override
public boolean available() {
return licenseState != null && licenseState.isIndexLifecycleAllowed();
}
@Override
public boolean enabled() {
return enabled;
}
@Override
public Map<String, Object> nativeCodeInfo() {
return null;
}
@Override
public void usage(ActionListener<XPackFeatureSet.Usage> listener) {
listener.onResponse(new Usage(name(), available(), enabled()) {
});
}
}

View File

@ -0,0 +1,34 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.xpack.indexlifecycle;
import org.elasticsearch.cluster.ClusterChangedEvent;
import org.elasticsearch.cluster.ClusterStateListener;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.component.AbstractComponent;
import org.elasticsearch.common.component.LifecycleListener;
import org.elasticsearch.common.logging.ESLoggerFactory;
import org.elasticsearch.common.settings.Settings;
public class IndexLifecycleInitialisationService extends AbstractComponent implements ClusterStateListener {
public IndexLifecycleInitialisationService(Settings settings, ClusterService clusterService) {
super(settings);
clusterService.addListener(this);
clusterService.addLifecycleListener(new LifecycleListener() {
@Override
public void beforeStop() {
super.beforeStop();
}
});
}
@Override
public void clusterChanged(ClusterChangedEvent event) {
ESLoggerFactory.getLogger("INDEX-LIFECYCLE-PLUGIN").error("cluster state changed: " + event.source());
}
}