66 */
77package org .elasticsearch .xpack .ilm ;
88
9+ import com .carrotsearch .randomizedtesting .annotations .Name ;
10+ import com .carrotsearch .randomizedtesting .annotations .ParametersFactory ;
11+
912import org .apache .http .entity .ContentType ;
1013import org .apache .http .entity .StringEntity ;
1114import org .apache .http .util .EntityUtils ;
2225import org .elasticsearch .common .xcontent .XContentHelper ;
2326import org .elasticsearch .core .TimeValue ;
2427import org .elasticsearch .rest .RestStatus ;
28+ import org .elasticsearch .test .cluster .ElasticsearchCluster ;
2529import org .elasticsearch .xcontent .ObjectPath ;
2630import org .elasticsearch .xcontent .XContentBuilder ;
2731import org .elasticsearch .xcontent .XContentType ;
2832import org .elasticsearch .xcontent .json .JsonXContent ;
33+ import org .elasticsearch .xpack .ccr .AbstractCCRRestTestCase ;
2934import org .elasticsearch .xpack .core .ilm .LifecycleAction ;
3035import org .elasticsearch .xpack .core .ilm .LifecyclePolicy ;
3136import org .elasticsearch .xpack .core .ilm .Phase ;
3237import org .elasticsearch .xpack .core .ilm .UnfollowAction ;
3338import org .elasticsearch .xpack .core .ilm .WaitUntilTimeSeriesEndTimePassesStep ;
39+ import org .junit .ClassRule ;
40+ import org .junit .rules .RuleChain ;
41+ import org .junit .rules .TemporaryFolder ;
3442
3543import java .io .IOException ;
3644import java .io .InputStream ;
5058import static org .hamcrest .Matchers .notNullValue ;
5159import static org .hamcrest .Matchers .nullValue ;
5260
53- public class CCRIndexLifecycleIT extends ESCCRRestTestCase {
61+ public class CCRIndexLifecycleIT extends AbstractCCRRestTestCase {
5462
5563 private static final Logger LOGGER = LogManager .getLogger (CCRIndexLifecycleIT .class );
5664 private static final String TSDB_INDEX_TEMPLATE = """
@@ -85,18 +93,69 @@ public class CCRIndexLifecycleIT extends ESCCRRestTestCase {
8593 }
8694 }""" ;
8795
96+ public static TemporaryFolder repoDir = new TemporaryFolder ();
97+
98+ public static ElasticsearchCluster leaderCluster = ElasticsearchCluster .local ()
99+ .name ("leader" )
100+ .module ("x-pack-ilm" )
101+ .module ("x-pack-ccr" )
102+ .module ("searchable-snapshots" )
103+ .module ("data-streams" )
104+ .setting ("path.repo" , () -> repoDir .getRoot ().getAbsolutePath ())
105+ .setting ("xpack.ccr.enabled" , "true" )
106+ .setting ("xpack.security.enabled" , "false" )
107+ .setting ("xpack.license.self_generated.type" , "trial" )
108+ .setting ("indices.lifecycle.poll_interval" , "1000ms" )
109+ .build ();
110+
111+ public static ElasticsearchCluster followerCluster = ElasticsearchCluster .local ()
112+ .name ("follower" )
113+ .module ("x-pack-ilm" )
114+ .module ("x-pack-ccr" )
115+ .module ("searchable-snapshots" )
116+ .module ("data-streams" )
117+ .setting ("path.repo" , () -> repoDir .getRoot ().getAbsolutePath ())
118+ .setting ("xpack.ccr.enabled" , "true" )
119+ .setting ("xpack.security.enabled" , "false" )
120+ .setting ("xpack.license.self_generated.type" , "trial" )
121+ .setting ("indices.lifecycle.poll_interval" , "1000ms" )
122+ .setting ("cluster.remote.leader_cluster.seeds" , () -> "\" " + leaderCluster .getTransportEndpoints () + "\" " )
123+ .build ();
124+
125+ @ ClassRule
126+ public static RuleChain ruleChain = RuleChain .outerRule (repoDir ).around (leaderCluster ).around (followerCluster );
127+
128+ public CCRIndexLifecycleIT (@ Name ("targetCluster" ) TargetCluster targetCluster ) {
129+ super (targetCluster );
130+ }
131+
132+ @ ParametersFactory
133+ public static Iterable <Object []> parameters () throws Exception {
134+ return leaderFollower ();
135+ }
136+
137+ @ Override
138+ protected ElasticsearchCluster getFollowerCluster () {
139+ return followerCluster ;
140+ }
141+
142+ @ Override
143+ protected ElasticsearchCluster getLeaderCluster () {
144+ return leaderCluster ;
145+ }
146+
88147 public void testBasicCCRAndILMIntegration () throws Exception {
89148 String indexName = "logs-1" ;
90149
91150 String policyName = "basic-test" ;
92- if ("leader" . equals ( targetCluster ) ) {
151+ if (targetCluster == TargetCluster . LEADER ) {
93152 putILMPolicy (policyName , "50GB" , null , TimeValue .timeValueHours (7 * 24 ));
94153 Settings indexSettings = indexSettings (1 , 0 ).put ("index.lifecycle.name" , policyName )
95154 .put ("index.lifecycle.rollover_alias" , "logs" )
96155 .build ();
97156 createIndex (indexName , indexSettings , "" , "\" logs\" : { }" );
98157 ensureGreen (indexName );
99- } else if ("follow" . equals ( targetCluster ) ) {
158+ } else if (targetCluster == TargetCluster . FOLLOWER ) {
100159 // Policy with the same name must exist in follower cluster too:
101160 putILMPolicy (policyName , "50GB" , null , TimeValue .timeValueHours (7 * 24 ));
102161 followIndex (indexName , indexName );
@@ -133,7 +192,7 @@ public void testBasicCCRAndILMIntegration() throws Exception {
133192 // ILM should have unfollowed the follower index, so the following_index setting should have been removed:
134193 // (this controls whether the follow engine is used)
135194 assertThat (getIndexSetting (client (), indexName , "index.xpack.ccr.following_index" ), nullValue ());
136- });
195+ }, 30 , TimeUnit . SECONDS );
137196 }
138197 } else {
139198 fail ("unexpected target cluster [" + targetCluster + "]" );
@@ -142,10 +201,10 @@ public void testBasicCCRAndILMIntegration() throws Exception {
142201
143202 public void testCCRUnfollowDuringSnapshot () throws Exception {
144203 String indexName = "unfollow-test-index" ;
145- if ("leader" . equals ( targetCluster ) ) {
204+ if (targetCluster == TargetCluster . LEADER ) {
146205 createIndex (adminClient (), indexName , indexSettings (2 , 0 ).build ());
147206 ensureGreen (indexName );
148- } else if ("follow" . equals ( targetCluster ) ) {
207+ } else if (targetCluster == TargetCluster . FOLLOWER ) {
149208 createNewSingletonPolicy ("unfollow-only" , "hot" , UnfollowAction .INSTANCE , TimeValue .ZERO );
150209 followIndex (indexName , indexName );
151210 ensureGreen (indexName );
@@ -159,7 +218,7 @@ public void testCCRUnfollowDuringSnapshot() throws Exception {
159218 .field ("type" , "fs" )
160219 .startObject ("settings" )
161220 .field ("compress" , randomBoolean ())
162- .field ("location" , System . getProperty ( "tests.path.repo" ))
221+ .field ("location" , repoDir . getRoot (). getAbsolutePath ( ))
163222 .field ("max_snapshot_bytes_per_sec" , "256b" )
164223 .endObject ()
165224 .endObject ()
@@ -212,7 +271,7 @@ public void testCcrAndIlmWithRollover() throws Exception {
212271 String nextIndexName = "mymetrics-000002" ;
213272 String policyName = "rollover-test" ;
214273
215- if ("leader" . equals ( targetCluster ) ) {
274+ if (targetCluster == TargetCluster . LEADER ) {
216275 // Create a policy on the leader
217276 putILMPolicy (policyName , null , 1 , null );
218277 Request templateRequest = new Request ("PUT" , "/_index_template/my_template" );
@@ -223,7 +282,7 @@ public void testCcrAndIlmWithRollover() throws Exception {
223282 "{\" index_patterns\" : [\" mymetrics-*\" ], \" template\" :{\" settings\" : " + Strings .toString (indexSettings ) + "}}"
224283 );
225284 assertOK (client ().performRequest (templateRequest ));
226- } else if ("follow" . equals ( targetCluster ) ) {
285+ } else if (targetCluster == TargetCluster . FOLLOWER ) {
227286 // Policy with the same name must exist in follower cluster too:
228287 putILMPolicy (policyName , null , 1 , null );
229288
@@ -327,7 +386,7 @@ public void testAliasReplicatedOnShrink() throws Exception {
327386 final String policyName = "shrink-test-policy" ;
328387 final int numberOfAliases = randomIntBetween (0 , 4 );
329388
330- if ("leader" . equals ( targetCluster ) ) {
389+ if (targetCluster == TargetCluster . LEADER ) {
331390 // this policy won't exist on the leader, that's fine
332391 Settings indexSettings = indexSettings (3 , 0 ).put ("index.lifecycle.name" , policyName ).build ();
333392 final StringBuilder aliases = new StringBuilder ();
@@ -346,7 +405,7 @@ public void testAliasReplicatedOnShrink() throws Exception {
346405 }
347406 createIndex (indexName , indexSettings , "" , aliases .toString ());
348407 ensureGreen (indexName );
349- } else if ("follow" . equals ( targetCluster ) ) {
408+ } else if (targetCluster == TargetCluster . FOLLOWER ) {
350409 // Create a policy with just a Shrink action on the follower
351410 putShrinkOnlyPolicy (client (), policyName );
352411
@@ -388,12 +447,12 @@ public void testUnfollowInjectedBeforeShrink() throws Exception {
388447 final String indexName = "shrink-test" ;
389448 final String policyName = "shrink-test-policy" ;
390449
391- if ("leader" . equals ( targetCluster ) ) {
450+ if (targetCluster == TargetCluster . LEADER ) {
392451 // this policy won't exist on the leader, that's fine
393452 Settings indexSettings = indexSettings (3 , 0 ).put ("index.lifecycle.name" , policyName ).build ();
394453 createIndex (indexName , indexSettings , "" , "" );
395454 ensureGreen (indexName );
396- } else if ("follow" . equals ( targetCluster ) ) {
455+ } else if (targetCluster == TargetCluster . FOLLOWER ) {
397456 // Create a policy with just a Shrink action on the follower
398457 putShrinkOnlyPolicy (client (), policyName );
399458
@@ -430,14 +489,14 @@ public void testUnfollowInjectedBeforeShrink() throws Exception {
430489 public void testCannotShrinkLeaderIndex () throws Exception {
431490 String indexName = "shrink-leader-test" ;
432491 String policyName = "shrink-leader-test-policy" ;
433- if ("leader" . equals ( targetCluster ) ) {
492+ if (targetCluster == TargetCluster . LEADER ) {
434493 // Set up the policy and index, but don't attach the policy yet,
435494 // otherwise it'll proceed through shrink before we can set up the
436495 // follower
437496 putShrinkOnlyPolicy (client (), policyName );
438497 createIndex (indexName , indexSettings (2 , 0 ).build (), "" , "" );
439498 ensureGreen (indexName );
440- } else if ("follow" . equals ( targetCluster ) ) {
499+ } else if (targetCluster == TargetCluster . FOLLOWER ) {
441500
442501 try (RestClient leaderClient = buildLeaderClient ()) {
443502 // Policy with the same name must exist in follower cluster too:
@@ -502,16 +561,15 @@ public void testILMUnfollowFailsToRemoveRetentionLeases() throws Exception {
502561 final String followerIndex = "follower" ;
503562 final String policyName = "unfollow_only_policy" ;
504563
505- if ("leader" . equals ( targetCluster ) ) {
564+ if (targetCluster == TargetCluster . LEADER ) {
506565 Settings indexSettings = indexSettings (1 , 0 ).put ("index.lifecycle.name" , policyName ) // this policy won't exist on the leader,
507566 // that's fine
508567 .build ();
509568 createIndex (leaderIndex , indexSettings , "" , "" );
510569 ensureGreen (leaderIndex );
511- } else if ("follow" . equals ( targetCluster ) ) {
570+ } else if (targetCluster == TargetCluster . FOLLOWER ) {
512571 try (RestClient leaderClient = buildLeaderClient ()) {
513- String leaderRemoteClusterSeed = System .getProperty ("tests.leader_remote_cluster_seed" );
514- configureRemoteClusters ("other_remote" , leaderRemoteClusterSeed );
572+ configureRemoteClusters ("other_remote" , leaderCluster .getTransportEndpoints ());
515573 assertBusy (() -> {
516574 Map <?, ?> localConnection = (Map <?, ?>) toMap (client ().performRequest (new Request ("GET" , "/_remote/info" ))).get (
517575 "other_remote"
@@ -576,12 +634,12 @@ public void testTsdbLeaderIndexRolloverAndSyncAfterWaitUntilEndTime() throws Exc
576634 String dataStream = "tsdb-index-cpu" ;
577635 String policyName = "tsdb-policy" ;
578636
579- if ("leader" . equals ( targetCluster ) ) {
637+ if (targetCluster == TargetCluster . LEADER ) {
580638 putILMPolicy (policyName , null , 1 , null );
581639 Request templateRequest = new Request ("PUT" , "/_index_template/tsdb_template" );
582640 templateRequest .setJsonEntity (Strings .format (TSDB_INDEX_TEMPLATE , indexPattern , policyName ));
583641 assertOK (client ().performRequest (templateRequest ));
584- } else if ("follow" . equals ( targetCluster ) ) {
642+ } else if (targetCluster == TargetCluster . FOLLOWER ) {
585643 // Use unfollow-only policy for follower cluster instead of regular ILM policy
586644 // Follower clusters should not have their own rollover actions as they are meant
587645 // to follow the rollover behavior of the leader index, not initiate their own rollovers
0 commit comments