Skip to content

Commit d3c5f99

Browse files
committed
1. Use specific ccr FeatureAction instead of XPackInfoAction
2. Add test dependency ccr for ilm 3. Add InternalClusterTests for CCR disabled
1 parent 391e8cf commit d3c5f99

File tree

6 files changed

+158
-24
lines changed

6 files changed

+158
-24
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/WaitForNoFollowersStep.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import org.elasticsearch.index.Index;
2020
import org.elasticsearch.protocol.xpack.XPackInfoRequest;
2121
import org.elasticsearch.protocol.xpack.XPackInfoResponse;
22-
import org.elasticsearch.xpack.core.action.XPackInfoAction;
22+
import org.elasticsearch.xpack.core.action.XPackInfoFeatureAction;
2323
import org.elasticsearch.xpack.core.ilm.step.info.SingleMessageFieldInfo;
2424

2525
import java.util.Arrays;
@@ -55,14 +55,11 @@ public boolean isRetryable() {
5555
public void evaluateCondition(Metadata metadata, Index index, Listener listener, TimeValue masterTimeout) {
5656
XPackInfoRequest xPackInfoRequest = new XPackInfoRequest();
5757
xPackInfoRequest.setCategories(EnumSet.of(XPackInfoRequest.Category.FEATURES));
58-
getClient().execute(XPackInfoAction.INSTANCE, xPackInfoRequest, ActionListener.wrap((xPackInfoResponse) -> {
59-
XPackInfoResponse.FeatureSetsInfo featureSetsInfo = xPackInfoResponse.getFeatureSetsInfo();
60-
if (featureSetsInfo != null) {
61-
XPackInfoResponse.FeatureSetsInfo.FeatureSet featureSet = featureSetsInfo.getFeatureSets().get(CCR_LEASE_KEY);
62-
if (featureSet != null && featureSet.enabled() == false) {
63-
listener.onResponse(true, null);
64-
return;
65-
}
58+
getClient().execute(XPackInfoFeatureAction.CCR, xPackInfoRequest, ActionListener.wrap((xPackInfoResponse) -> {
59+
XPackInfoResponse.FeatureSetsInfo.FeatureSet featureSet = xPackInfoResponse.getInfo();
60+
if (featureSet != null && featureSet.enabled() == false) {
61+
listener.onResponse(true, null);
62+
return;
6663
}
6764
leaderIndexCheck(metadata, index, listener, masterTimeout);
6865
}, listener::onFailure));

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitForNoFollowersStepTests.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,12 @@
2525
import org.elasticsearch.index.shard.ShardPath;
2626
import org.elasticsearch.protocol.xpack.XPackInfoResponse;
2727
import org.elasticsearch.xcontent.ToXContentObject;
28-
import org.elasticsearch.xpack.core.action.XPackInfoAction;
28+
import org.elasticsearch.xpack.core.action.XPackInfoFeatureAction;
29+
import org.elasticsearch.xpack.core.action.XPackInfoFeatureResponse;
2930
import org.mockito.Mockito;
3031

3132
import java.nio.file.Path;
3233
import java.util.ArrayList;
33-
import java.util.HashSet;
34-
import java.util.Set;
3534

3635
import static org.elasticsearch.xpack.core.ilm.WaitForNoFollowersStep.CCR_LEASE_KEY;
3736
import static org.hamcrest.Matchers.containsString;
@@ -258,16 +257,13 @@ private void mockXPackInfo(boolean available, boolean enabled) {
258257
Mockito.doAnswer(invocationOnMock -> {
259258

260259
@SuppressWarnings("unchecked")
261-
ActionListener<XPackInfoResponse> listener = (ActionListener<XPackInfoResponse>) invocationOnMock.getArguments()[2];
262-
263-
Set<XPackInfoResponse.FeatureSetsInfo.FeatureSet> featureSets = new HashSet<>();
264-
featureSets.add(new XPackInfoResponse.FeatureSetsInfo.FeatureSet("ccr", available, enabled));
265-
XPackInfoResponse.FeatureSetsInfo featureInfos = new XPackInfoResponse.FeatureSetsInfo(featureSets);
266-
XPackInfoResponse xpackInfo = new XPackInfoResponse(null, null, featureInfos);
267-
268-
listener.onResponse(xpackInfo);
260+
ActionListener<XPackInfoFeatureResponse> listener = (ActionListener<XPackInfoFeatureResponse>) invocationOnMock
261+
.getArguments()[2];
262+
var featureSet = new XPackInfoResponse.FeatureSetsInfo.FeatureSet("ccr", available, enabled);
263+
XPackInfoFeatureResponse xPackInfoFeatureResponse = new XPackInfoFeatureResponse(featureSet);
264+
listener.onResponse(xPackInfoFeatureResponse);
269265
return null;
270-
}).when(client).execute(Mockito.same(XPackInfoAction.INSTANCE), Mockito.any(), Mockito.any());
266+
}).when(client).execute(Mockito.same(XPackInfoFeatureAction.CCR), Mockito.any(), Mockito.any());
271267
}
272268

273269
private void mockIndexStatsCall(String expectedIndexName, IndexStats indexStats) {

x-pack/plugin/ilm/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ archivesBaseName = 'x-pack-ilm'
1616
dependencies {
1717
compileOnly project(path: xpackModule('core'))
1818
testImplementation(testArtifact(project(xpackModule('core'))))
19+
testImplementation project(xpackModule('ccr'))
1920
testImplementation project(':modules:data-streams')
2021
testImplementation project(':modules:dlm')
2122
}

x-pack/plugin/ilm/src/internalClusterTest/java/org/elasticsearch/xpack/ilm/ClusterStateWaitThresholdBreachTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.elasticsearch.core.TimeValue;
1717
import org.elasticsearch.plugins.Plugin;
1818
import org.elasticsearch.test.ESIntegTestCase;
19+
import org.elasticsearch.xpack.ccr.Ccr;
1920
import org.elasticsearch.xpack.core.LocalStateCompositeXPackPlugin;
2021
import org.elasticsearch.xpack.core.XPackSettings;
2122
import org.elasticsearch.xpack.core.ilm.ExplainLifecycleRequest;
@@ -68,7 +69,7 @@ protected boolean ignoreExternalCluster() {
6869

6970
@Override
7071
protected Collection<Class<? extends Plugin>> nodePlugins() {
71-
return Arrays.asList(LocalStateCompositeXPackPlugin.class, IndexLifecycle.class);
72+
return Arrays.asList(LocalStateCompositeXPackPlugin.class, IndexLifecycle.class, Ccr.class);
7273
}
7374

7475
@Override
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.xpack.ilm;
9+
10+
import org.elasticsearch.action.admin.indices.template.put.PutComposableIndexTemplateAction;
11+
import org.elasticsearch.cluster.metadata.ComposableIndexTemplate;
12+
import org.elasticsearch.cluster.metadata.DataStream;
13+
import org.elasticsearch.cluster.metadata.IndexMetadata;
14+
import org.elasticsearch.cluster.metadata.Template;
15+
import org.elasticsearch.common.Strings;
16+
import org.elasticsearch.common.settings.Settings;
17+
import org.elasticsearch.core.TimeValue;
18+
import org.elasticsearch.datastreams.DataStreamsPlugin;
19+
import org.elasticsearch.plugins.Plugin;
20+
import org.elasticsearch.test.ESIntegTestCase;
21+
import org.elasticsearch.xpack.ccr.Ccr;
22+
import org.elasticsearch.xpack.core.LocalStateCompositeXPackPlugin;
23+
import org.elasticsearch.xpack.core.XPackSettings;
24+
import org.elasticsearch.xpack.core.ilm.ExplainLifecycleRequest;
25+
import org.elasticsearch.xpack.core.ilm.ExplainLifecycleResponse;
26+
import org.elasticsearch.xpack.core.ilm.IndexLifecycleExplainResponse;
27+
import org.elasticsearch.xpack.core.ilm.LifecyclePolicy;
28+
import org.elasticsearch.xpack.core.ilm.LifecycleSettings;
29+
import org.elasticsearch.xpack.core.ilm.Phase;
30+
import org.elasticsearch.xpack.core.ilm.RolloverAction;
31+
import org.elasticsearch.xpack.core.ilm.ShrinkAction;
32+
import org.elasticsearch.xpack.core.ilm.action.ExplainLifecycleAction;
33+
import org.elasticsearch.xpack.core.ilm.action.PutLifecycleAction;
34+
35+
import java.util.Arrays;
36+
import java.util.Collection;
37+
import java.util.Collections;
38+
import java.util.HashMap;
39+
import java.util.Map;
40+
import java.util.concurrent.TimeUnit;
41+
42+
import static org.elasticsearch.xpack.core.ilm.ShrinkIndexNameSupplier.SHRUNKEN_INDEX_PREFIX;
43+
import static org.hamcrest.Matchers.equalTo;
44+
45+
@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 0, numClientNodes = 0)
46+
public class ILMMultiNodeWithCCRDisabledIT extends ESIntegTestCase {
47+
private static final String index = "myindex";
48+
49+
@Override
50+
protected Collection<Class<? extends Plugin>> nodePlugins() {
51+
return Arrays.asList(LocalStateCompositeXPackPlugin.class, DataStreamsPlugin.class, IndexLifecycle.class, Ccr.class);
52+
}
53+
54+
@Override
55+
protected Settings nodeSettings(int nodeOrdinal, Settings otherSettings) {
56+
return Settings.builder()
57+
.put(super.nodeSettings(nodeOrdinal, otherSettings))
58+
.put(LifecycleSettings.LIFECYCLE_POLL_INTERVAL, "1s")
59+
// This just generates less churn and makes it easier to read the log file if needed
60+
.put(LifecycleSettings.LIFECYCLE_HISTORY_INDEX_ENABLED, false)
61+
.put(XPackSettings.CCR_ENABLED_SETTING.getKey(), false)
62+
.build();
63+
}
64+
65+
public void testShrinkOnTiers() throws Exception {
66+
startHotOnlyNode();
67+
startWarmOnlyNode();
68+
ensureGreen();
69+
70+
RolloverAction rolloverAction = new RolloverAction(null, null, null, 1L, null, null, null, null, null, null);
71+
Phase hotPhase = new Phase("hot", TimeValue.ZERO, Collections.singletonMap(rolloverAction.getWriteableName(), rolloverAction));
72+
ShrinkAction shrinkAction = new ShrinkAction(1, null);
73+
Phase warmPhase = new Phase("warm", TimeValue.ZERO, Collections.singletonMap(shrinkAction.getWriteableName(), shrinkAction));
74+
Map<String, Phase> phases = new HashMap<>();
75+
phases.put(hotPhase.getName(), hotPhase);
76+
phases.put(warmPhase.getName(), warmPhase);
77+
LifecyclePolicy lifecyclePolicy = new LifecyclePolicy("shrink-policy", phases);
78+
client().execute(PutLifecycleAction.INSTANCE, new PutLifecycleAction.Request(lifecyclePolicy)).get();
79+
80+
Template t = new Template(
81+
Settings.builder()
82+
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 2)
83+
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0)
84+
.put(LifecycleSettings.LIFECYCLE_NAME, "shrink-policy")
85+
.build(),
86+
null,
87+
null
88+
);
89+
90+
ComposableIndexTemplate template = new ComposableIndexTemplate(
91+
Collections.singletonList(index),
92+
t,
93+
null,
94+
null,
95+
null,
96+
null,
97+
new ComposableIndexTemplate.DataStreamTemplate(),
98+
null
99+
);
100+
client().execute(
101+
PutComposableIndexTemplateAction.INSTANCE,
102+
new PutComposableIndexTemplateAction.Request("template").indexTemplate(template)
103+
).actionGet();
104+
client().prepareIndex(index).setCreate(true).setId("1").setSource("@timestamp", "2020-09-09").get();
105+
106+
assertBusy(() -> {
107+
ExplainLifecycleResponse explain = client().execute(ExplainLifecycleAction.INSTANCE, new ExplainLifecycleRequest().indices("*"))
108+
.get();
109+
logger.info("--> explain: {}", Strings.toString(explain));
110+
111+
String backingIndexName = DataStream.getDefaultBackingIndexName(index, 1);
112+
IndexLifecycleExplainResponse indexResp = null;
113+
for (Map.Entry<String, IndexLifecycleExplainResponse> indexNameAndResp : explain.getIndexResponses().entrySet()) {
114+
if (indexNameAndResp.getKey().startsWith(SHRUNKEN_INDEX_PREFIX) && indexNameAndResp.getKey().contains(backingIndexName)) {
115+
indexResp = indexNameAndResp.getValue();
116+
assertNotNull(indexResp);
117+
assertThat(indexResp.getPhase(), equalTo("warm"));
118+
assertThat(indexResp.getStep(), equalTo("complete"));
119+
break;
120+
}
121+
}
122+
123+
assertNotNull("Unable to find an ilm explain output for the shrunk index of " + index, indexResp);
124+
}, 30, TimeUnit.SECONDS);
125+
}
126+
127+
public void startHotOnlyNode() {
128+
Settings nodeSettings = Settings.builder().putList("node.roles", Arrays.asList("master", "data_hot", "ingest")).build();
129+
internalCluster().startNode(nodeSettings);
130+
}
131+
132+
public void startWarmOnlyNode() {
133+
Settings nodeSettings = Settings.builder().putList("node.roles", Arrays.asList("master", "data_warm", "ingest")).build();
134+
internalCluster().startNode(nodeSettings);
135+
}
136+
}

x-pack/plugin/ilm/src/internalClusterTest/java/org/elasticsearch/xpack/ilm/ILMMultiNodeIT.java renamed to x-pack/plugin/ilm/src/internalClusterTest/java/org/elasticsearch/xpack/ilm/ILMMultiNodeWithCCREnabledIT.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
import org.elasticsearch.datastreams.DataStreamsPlugin;
1919
import org.elasticsearch.plugins.Plugin;
2020
import org.elasticsearch.test.ESIntegTestCase;
21+
import org.elasticsearch.xpack.ccr.Ccr;
2122
import org.elasticsearch.xpack.core.LocalStateCompositeXPackPlugin;
23+
import org.elasticsearch.xpack.core.XPackSettings;
2224
import org.elasticsearch.xpack.core.ilm.ExplainLifecycleRequest;
2325
import org.elasticsearch.xpack.core.ilm.ExplainLifecycleResponse;
2426
import org.elasticsearch.xpack.core.ilm.IndexLifecycleExplainResponse;
@@ -41,12 +43,12 @@
4143
import static org.hamcrest.Matchers.equalTo;
4244

4345
@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 0, numClientNodes = 0)
44-
public class ILMMultiNodeIT extends ESIntegTestCase {
46+
public class ILMMultiNodeWithCCREnabledIT extends ESIntegTestCase {
4547
private static final String index = "myindex";
4648

4749
@Override
4850
protected Collection<Class<? extends Plugin>> nodePlugins() {
49-
return Arrays.asList(LocalStateCompositeXPackPlugin.class, DataStreamsPlugin.class, IndexLifecycle.class);
51+
return Arrays.asList(LocalStateCompositeXPackPlugin.class, DataStreamsPlugin.class, IndexLifecycle.class, Ccr.class);
5052
}
5153

5254
@Override
@@ -56,6 +58,7 @@ protected Settings nodeSettings(int nodeOrdinal, Settings otherSettings) {
5658
.put(LifecycleSettings.LIFECYCLE_POLL_INTERVAL, "1s")
5759
// This just generates less churn and makes it easier to read the log file if needed
5860
.put(LifecycleSettings.LIFECYCLE_HISTORY_INDEX_ENABLED, false)
61+
.put(XPackSettings.CCR_ENABLED_SETTING.getKey(), true)
5962
.build();
6063
}
6164

0 commit comments

Comments
 (0)