Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,38 @@
package org.elasticsearch.xpack.core.template;

import org.elasticsearch.xcontent.NamedXContentRegistry;
import org.elasticsearch.xcontent.ParseField;
import org.elasticsearch.xpack.core.ilm.DeleteAction;
import org.elasticsearch.xpack.core.ilm.ForceMergeAction;
import org.elasticsearch.xpack.core.ilm.LifecycleAction;
import org.elasticsearch.xpack.core.ilm.LifecyclePolicy;
import org.elasticsearch.xpack.core.ilm.LifecyclePolicyUtils;
import org.elasticsearch.xpack.core.ilm.LifecycleType;
import org.elasticsearch.xpack.core.ilm.RolloverAction;
import org.elasticsearch.xpack.core.ilm.ShrinkAction;
import org.elasticsearch.xpack.core.ilm.TimeseriesLifecycleType;

import java.util.List;

/**
* Describes an index lifecycle policy to be loaded from a resource file for use with an {@link IndexTemplateRegistry}.
*/
public class LifecyclePolicyConfig {

public static final NamedXContentRegistry DEFAULT_X_CONTENT_REGISTRY = new NamedXContentRegistry(
List.of(
new NamedXContentRegistry.Entry(
LifecycleType.class,
new ParseField(TimeseriesLifecycleType.TYPE),
(p) -> TimeseriesLifecycleType.INSTANCE
),
new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(RolloverAction.NAME), RolloverAction::parse),
new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(ForceMergeAction.NAME), ForceMergeAction::parse),
new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(ShrinkAction.NAME), ShrinkAction::parse),
new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(DeleteAction.NAME), DeleteAction::parse)
)
);

private final String policyName;
private final String fileName;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,23 @@
package org.elasticsearch.xpack.deprecation.logging;

import org.elasticsearch.client.Client;
import org.elasticsearch.cluster.metadata.ComponentTemplate;
import org.elasticsearch.cluster.metadata.ComposableIndexTemplate;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.xcontent.NamedXContentRegistry;
import org.elasticsearch.xcontent.XContentParserConfiguration;
import org.elasticsearch.xcontent.json.JsonXContent;
import org.elasticsearch.xpack.core.ilm.LifecyclePolicy;
import org.elasticsearch.xpack.core.template.IndexTemplateConfig;
import org.elasticsearch.xpack.core.template.IndexTemplateRegistry;
import org.elasticsearch.xpack.core.template.LifecyclePolicyConfig;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static org.elasticsearch.xpack.core.ClientHelper.DEPRECATION_ORIGIN;

Expand All @@ -35,32 +43,6 @@ public class DeprecationIndexingTemplateRegistry extends IndexTemplateRegistry {
public static final String DEPRECATION_INDEXING_TEMPLATE_NAME = ".deprecation-indexing-template";
public static final String DEPRECATION_INDEXING_POLICY_NAME = ".deprecation-indexing-ilm-policy";

public static final IndexTemplateConfig DEPRECATION_INDEXING_MAPPINGS = new IndexTemplateConfig(
DEPRECATION_INDEXING_MAPPINGS_NAME,
"/org/elasticsearch/xpack/deprecation/deprecation-indexing-mappings.json",
INDEX_TEMPLATE_VERSION,
DEPRECATION_INDEXING_TEMPLATE_VERSION_VARIABLE
);

public static final IndexTemplateConfig DEPRECATION_INDEXING_SETTINGS = new IndexTemplateConfig(
DEPRECATION_INDEXING_SETTINGS_NAME,
"/org/elasticsearch/xpack/deprecation/deprecation-indexing-settings.json",
INDEX_TEMPLATE_VERSION,
DEPRECATION_INDEXING_TEMPLATE_VERSION_VARIABLE
);

public static final IndexTemplateConfig DEPRECATION_INDEXING_INDEX_TEMPLATE = new IndexTemplateConfig(
DEPRECATION_INDEXING_TEMPLATE_NAME,
"/org/elasticsearch/xpack/deprecation/deprecation-indexing-template.json",
INDEX_TEMPLATE_VERSION,
DEPRECATION_INDEXING_TEMPLATE_VERSION_VARIABLE
);

public static final LifecyclePolicyConfig DEPRECATION_INDEXING_HISTORY_POLICY = new LifecyclePolicyConfig(
DEPRECATION_INDEXING_POLICY_NAME,
"/org/elasticsearch/xpack/deprecation/deprecation-indexing-ilm-policy.json"
);

public DeprecationIndexingTemplateRegistry(
Settings nodeSettings,
ClusterService clusterService,
Expand All @@ -71,19 +53,65 @@ public DeprecationIndexingTemplateRegistry(
super(nodeSettings, clusterService, threadPool, client, xContentRegistry);
}

private static final Map<String, ComponentTemplate> COMPONENT_TEMPLATE_CONFIGS;

static {
final Map<String, ComponentTemplate> componentTemplates = new HashMap<>();
for (IndexTemplateConfig config : List.of(
new IndexTemplateConfig(
DEPRECATION_INDEXING_MAPPINGS_NAME,
"/org/elasticsearch/xpack/deprecation/deprecation-indexing-mappings.json",
INDEX_TEMPLATE_VERSION,
DEPRECATION_INDEXING_TEMPLATE_VERSION_VARIABLE
),
new IndexTemplateConfig(
DEPRECATION_INDEXING_SETTINGS_NAME,
"/org/elasticsearch/xpack/deprecation/deprecation-indexing-settings.json",
INDEX_TEMPLATE_VERSION,
DEPRECATION_INDEXING_TEMPLATE_VERSION_VARIABLE
)
)) {
try {
componentTemplates.put(
config.getTemplateName(),
ComponentTemplate.parse(JsonXContent.jsonXContent.createParser(XContentParserConfiguration.EMPTY, config.loadBytes()))
);
} catch (IOException e) {
throw new AssertionError(e);
}
}
COMPONENT_TEMPLATE_CONFIGS = Map.copyOf(componentTemplates);
}

@Override
protected List<IndexTemplateConfig> getComponentTemplateConfigs() {
return List.of(DEPRECATION_INDEXING_MAPPINGS, DEPRECATION_INDEXING_SETTINGS);
protected Map<String, ComponentTemplate> getComponentTemplateConfigs() {
return COMPONENT_TEMPLATE_CONFIGS;
}

private static final Map<String, ComposableIndexTemplate> COMPOSABLE_INDEX_TEMPLATE_CONFIGS = parseComposableTemplates(
new IndexTemplateConfig(
DEPRECATION_INDEXING_TEMPLATE_NAME,
"/org/elasticsearch/xpack/deprecation/deprecation-indexing-template.json",
INDEX_TEMPLATE_VERSION,
DEPRECATION_INDEXING_TEMPLATE_VERSION_VARIABLE
)
);

@Override
protected List<IndexTemplateConfig> getComposableTemplateConfigs() {
return List.of(DEPRECATION_INDEXING_INDEX_TEMPLATE);
protected Map<String, ComposableIndexTemplate> getComposableTemplateConfigs() {
return COMPOSABLE_INDEX_TEMPLATE_CONFIGS;
}

private static final List<LifecyclePolicy> LIFECYCLE_POLICIES = List.of(
new LifecyclePolicyConfig(
DEPRECATION_INDEXING_POLICY_NAME,
"/org/elasticsearch/xpack/deprecation/deprecation-indexing-ilm-policy.json"
).load(LifecyclePolicyConfig.DEFAULT_X_CONTENT_REGISTRY)
);

@Override
protected List<LifecyclePolicyConfig> getPolicyConfigs() {
return List.of(DEPRECATION_INDEXING_HISTORY_POLICY);
protected List<LifecyclePolicy> getPolicyConfigs() {
return LIFECYCLE_POLICIES;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,18 @@
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.xcontent.NamedXContentRegistry;
import org.elasticsearch.xpack.core.ClientHelper;
import org.elasticsearch.xpack.core.ilm.LifecyclePolicy;
import org.elasticsearch.xpack.core.template.IndexTemplateRegistry;
import org.elasticsearch.xpack.core.template.LifecyclePolicyConfig;

import java.util.List;

public class FleetTemplateRegistry extends IndexTemplateRegistry {

public static final LifecyclePolicyConfig FLEET_ACTIONS_RESULTS_POLICY = new LifecyclePolicyConfig(
".fleet-actions-results-ilm-policy",
"/fleet-actions-results-ilm-policy.json"
private static final List<LifecyclePolicy> LIFECYCLE_POLICIES = List.of(
new LifecyclePolicyConfig(".fleet-actions-results-ilm-policy", "/fleet-actions-results-ilm-policy.json").load(
LifecyclePolicyConfig.DEFAULT_X_CONTENT_REGISTRY
)
);

public FleetTemplateRegistry(
Expand All @@ -41,7 +43,7 @@ protected String getOrigin() {
}

@Override
protected List<LifecyclePolicyConfig> getPolicyConfigs() {
return List.of(FLEET_ACTIONS_RESULTS_POLICY);
protected List<LifecyclePolicy> getPolicyConfigs() {
return LIFECYCLE_POLICIES;
}
}
1 change: 1 addition & 0 deletions x-pack/plugin/ilm/qa/multi-node/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ apply plugin: 'elasticsearch.internal-java-rest-test'

dependencies {
javaRestTestImplementation(testArtifact(project(xpackModule('core'))))
javaRestTestImplementation project(xpackModule('ilm'))
javaRestTestImplementation project(":client:rest-high-level")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@
import static org.elasticsearch.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.xpack.TimeSeriesRestDriver.createComposableTemplate;
import static org.elasticsearch.xpack.TimeSeriesRestDriver.getStepKeyForIndex;
import static org.elasticsearch.xpack.core.slm.history.SnapshotHistoryItem.CREATE_OPERATION;
import static org.elasticsearch.xpack.core.slm.history.SnapshotHistoryItem.DELETE_OPERATION;
import static org.elasticsearch.xpack.core.slm.history.SnapshotHistoryStore.SLM_HISTORY_DATA_STREAM;
import static org.elasticsearch.xpack.slm.history.SnapshotHistoryItem.CREATE_OPERATION;
import static org.elasticsearch.xpack.slm.history.SnapshotHistoryItem.DELETE_OPERATION;
import static org.elasticsearch.xpack.slm.history.SnapshotHistoryStore.SLM_HISTORY_DATA_STREAM;
import static org.hamcrest.Matchers.anyOf;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.empty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
import java.util.concurrent.atomic.AtomicReference;

import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.elasticsearch.xpack.core.slm.history.SnapshotHistoryStore.SLM_HISTORY_DATA_STREAM;
import static org.elasticsearch.xpack.slm.history.SnapshotHistoryStore.SLM_HISTORY_DATA_STREAM;
import static org.hamcrest.Matchers.anyOf;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.equalTo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@
import org.elasticsearch.xpack.core.slm.action.PutSnapshotLifecycleAction;
import org.elasticsearch.xpack.core.slm.action.StartSLMAction;
import org.elasticsearch.xpack.core.slm.action.StopSLMAction;
import org.elasticsearch.xpack.core.slm.history.SnapshotHistoryStore;
import org.elasticsearch.xpack.core.slm.history.SnapshotLifecycleTemplateRegistry;
import org.elasticsearch.xpack.ilm.action.RestDeleteLifecycleAction;
import org.elasticsearch.xpack.ilm.action.RestExplainLifecycleAction;
import org.elasticsearch.xpack.ilm.action.RestGetLifecycleAction;
Expand Down Expand Up @@ -131,6 +129,8 @@
import org.elasticsearch.xpack.slm.action.TransportPutSnapshotLifecycleAction;
import org.elasticsearch.xpack.slm.action.TransportStartSLMAction;
import org.elasticsearch.xpack.slm.action.TransportStopSLMAction;
import org.elasticsearch.xpack.slm.history.SnapshotHistoryStore;
import org.elasticsearch.xpack.slm.history.SnapshotLifecycleTemplateRegistry;

import java.io.IOException;
import java.time.Clock;
Expand All @@ -145,6 +145,9 @@
import static org.elasticsearch.xpack.core.ClientHelper.INDEX_LIFECYCLE_ORIGIN;

public class IndexLifecycle extends Plugin implements ActionPlugin {

public static final List<NamedXContentRegistry.Entry> NAMED_X_CONTENT_ENTRIES = xContentEntries();

private final SetOnce<IndexLifecycleService> indexLifecycleInitialisationService = new SetOnce<>();
private final SetOnce<ILMHistoryStore> ilmHistoryStore = new SetOnce<>();
private final SetOnce<SnapshotLifecycleService> snapshotLifecycleService = new SetOnce<>();
Expand Down Expand Up @@ -272,6 +275,10 @@ public List<Entry> getNamedWriteables() {

@Override
public List<NamedXContentRegistry.Entry> getNamedXContent() {
return NAMED_X_CONTENT_ENTRIES;
}

private static List<NamedXContentRegistry.Entry> xContentEntries() {
List<NamedXContentRegistry.Entry> entries = new ArrayList<>(
Arrays.asList(
// Custom Metadata
Expand Down Expand Up @@ -320,8 +327,7 @@ public List<NamedXContentRegistry.Entry> getNamedXContent() {
new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(RollupILMAction.NAME), RollupILMAction::parse)
);
}

return entries;
return List.copyOf(entries);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,22 @@
package org.elasticsearch.xpack.ilm.history;

import org.elasticsearch.client.Client;
import org.elasticsearch.cluster.metadata.ComposableIndexTemplate;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.xcontent.NamedXContentRegistry;
import org.elasticsearch.xpack.core.ClientHelper;
import org.elasticsearch.xpack.core.ilm.LifecyclePolicy;
import org.elasticsearch.xpack.core.ilm.LifecycleSettings;
import org.elasticsearch.xpack.core.template.IndexTemplateConfig;
import org.elasticsearch.xpack.core.template.IndexTemplateRegistry;
import org.elasticsearch.xpack.core.template.LifecyclePolicyConfig;
import org.elasticsearch.xpack.ilm.IndexLifecycle;

import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
* The {@link ILMHistoryTemplateRegistry} class sets up and configures an ILM policy and index
Expand All @@ -44,18 +48,6 @@ protected boolean requiresMasterNode() {
return true;
}

public static final IndexTemplateConfig TEMPLATE_ILM_HISTORY = new IndexTemplateConfig(
ILM_TEMPLATE_NAME,
"/ilm-history.json",
INDEX_TEMPLATE_VERSION,
ILM_TEMPLATE_VERSION_VARIABLE
);

public static final LifecyclePolicyConfig ILM_HISTORY_POLICY = new LifecyclePolicyConfig(
ILM_POLICY_NAME,
"/ilm-history-ilm-policy.json"
);

private final boolean ilmHistoryEnabled;

public ILMHistoryTemplateRegistry(
Expand All @@ -69,22 +61,28 @@ public ILMHistoryTemplateRegistry(
this.ilmHistoryEnabled = LifecycleSettings.LIFECYCLE_HISTORY_INDEX_ENABLED_SETTING.get(nodeSettings);
}

private static final Map<String, ComposableIndexTemplate> COMPOSABLE_INDEX_TEMPLATE_CONFIGS = parseComposableTemplates(
new IndexTemplateConfig(ILM_TEMPLATE_NAME, "/ilm-history.json", INDEX_TEMPLATE_VERSION, ILM_TEMPLATE_VERSION_VARIABLE)
);

@Override
protected List<IndexTemplateConfig> getComposableTemplateConfigs() {
protected Map<String, ComposableIndexTemplate> getComposableTemplateConfigs() {
if (this.ilmHistoryEnabled) {
return Collections.singletonList(TEMPLATE_ILM_HISTORY);
return COMPOSABLE_INDEX_TEMPLATE_CONFIGS;
} else {
return Collections.emptyList();
return Map.of();
}
}

private static final List<LifecyclePolicy> LIFECYCLE_POLICIES = List.of(
new LifecyclePolicyConfig(ILM_POLICY_NAME, "/ilm-history-ilm-policy.json").load(
new NamedXContentRegistry(IndexLifecycle.NAMED_X_CONTENT_ENTRIES)
)
);

@Override
protected List<LifecyclePolicyConfig> getPolicyConfigs() {
if (this.ilmHistoryEnabled) {
return Collections.singletonList(ILM_HISTORY_POLICY);
} else {
return Collections.emptyList();
}
protected List<LifecyclePolicy> getPolicyConfigs() {
return this.ilmHistoryEnabled ? LIFECYCLE_POLICIES : Collections.emptyList();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
import org.elasticsearch.xpack.core.slm.SnapshotLifecycleMetadata;
import org.elasticsearch.xpack.core.slm.SnapshotLifecyclePolicyMetadata;
import org.elasticsearch.xpack.core.slm.SnapshotLifecycleStats;
import org.elasticsearch.xpack.core.slm.history.SnapshotHistoryItem;
import org.elasticsearch.xpack.core.slm.history.SnapshotHistoryStore;
import org.elasticsearch.xpack.ilm.LifecyclePolicySecurityClient;
import org.elasticsearch.xpack.slm.history.SnapshotHistoryItem;
import org.elasticsearch.xpack.slm.history.SnapshotHistoryStore;

import java.io.IOException;
import java.time.Instant;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
import org.elasticsearch.xpack.core.slm.SnapshotLifecyclePolicy;
import org.elasticsearch.xpack.core.slm.SnapshotLifecycleStats;
import org.elasticsearch.xpack.core.slm.SnapshotRetentionConfiguration;
import org.elasticsearch.xpack.core.slm.history.SnapshotHistoryItem;
import org.elasticsearch.xpack.core.slm.history.SnapshotHistoryStore;
import org.elasticsearch.xpack.slm.history.SnapshotHistoryItem;
import org.elasticsearch.xpack.slm.history.SnapshotHistoryStore;

import java.io.IOException;
import java.time.Instant;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
import org.elasticsearch.xpack.core.slm.SnapshotLifecycleMetadata;
import org.elasticsearch.xpack.core.slm.SnapshotLifecyclePolicyMetadata;
import org.elasticsearch.xpack.core.slm.action.ExecuteSnapshotLifecycleAction;
import org.elasticsearch.xpack.core.slm.history.SnapshotHistoryStore;
import org.elasticsearch.xpack.slm.SnapshotLifecycleService;
import org.elasticsearch.xpack.slm.SnapshotLifecycleTask;
import org.elasticsearch.xpack.slm.history.SnapshotHistoryStore;

import java.util.Optional;

Expand Down
Loading