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 ;
2326import org .elasticsearch .common .xcontent .XContentHelper ;
2427import org .elasticsearch .core .TimeValue ;
2528import org .elasticsearch .rest .RestStatus ;
29+ import org .elasticsearch .test .cluster .ElasticsearchCluster ;
2630import org .elasticsearch .xcontent .ObjectPath ;
2731import org .elasticsearch .xcontent .XContentBuilder ;
2832import org .elasticsearch .xcontent .XContentType ;
2933import org .elasticsearch .xcontent .json .JsonXContent ;
34+ import org .elasticsearch .xpack .ccr .AbstractCCRRestTestCase ;
3035import org .elasticsearch .xpack .core .ilm .LifecycleAction ;
3136import org .elasticsearch .xpack .core .ilm .LifecyclePolicy ;
3237import org .elasticsearch .xpack .core .ilm .Phase ;
3338import org .elasticsearch .xpack .core .ilm .UnfollowAction ;
3439import org .elasticsearch .xpack .core .ilm .WaitUntilTimeSeriesEndTimePassesStep ;
3540import org .elasticsearch .xpack .ilm .action .RestPutLifecycleAction ;
41+ import org .junit .ClassRule ;
42+ import org .junit .rules .RuleChain ;
43+ import org .junit .rules .TemporaryFolder ;
3644
3745import java .io .IOException ;
3846import java .io .InputStream ;
5260import static org .hamcrest .Matchers .notNullValue ;
5361import static org .hamcrest .Matchers .nullValue ;
5462
55- public class CCRIndexLifecycleIT extends ESCCRRestTestCase {
63+ public class CCRIndexLifecycleIT extends AbstractCCRRestTestCase {
5664
5765 private static final Logger LOGGER = LogManager .getLogger (CCRIndexLifecycleIT .class );
5866 private static final String TEST_PHASE = "hot" ;
@@ -88,18 +96,69 @@ public class CCRIndexLifecycleIT extends ESCCRRestTestCase {
8896 }
8997 }""" ;
9098
99+ public static TemporaryFolder repoDir = new TemporaryFolder ();
100+
101+ public static ElasticsearchCluster leaderCluster = ElasticsearchCluster .local ()
102+ .name ("leader" )
103+ .module ("x-pack-ilm" )
104+ .module ("x-pack-ccr" )
105+ .module ("searchable-snapshots" )
106+ .module ("data-streams" )
107+ .setting ("path.repo" , () -> repoDir .getRoot ().getAbsolutePath ())
108+ .setting ("xpack.ccr.enabled" , "true" )
109+ .setting ("xpack.security.enabled" , "false" )
110+ .setting ("xpack.license.self_generated.type" , "trial" )
111+ .setting ("indices.lifecycle.poll_interval" , "1000ms" )
112+ .build ();
113+
114+ public static ElasticsearchCluster followerCluster = ElasticsearchCluster .local ()
115+ .name ("follower" )
116+ .module ("x-pack-ilm" )
117+ .module ("x-pack-ccr" )
118+ .module ("searchable-snapshots" )
119+ .module ("data-streams" )
120+ .setting ("path.repo" , () -> repoDir .getRoot ().getAbsolutePath ())
121+ .setting ("xpack.ccr.enabled" , "true" )
122+ .setting ("xpack.security.enabled" , "false" )
123+ .setting ("xpack.license.self_generated.type" , "trial" )
124+ .setting ("indices.lifecycle.poll_interval" , "1000ms" )
125+ .setting ("cluster.remote.leader_cluster.seeds" , () -> "\" " + leaderCluster .getTransportEndpoints () + "\" " )
126+ .build ();
127+
128+ @ ClassRule
129+ public static RuleChain ruleChain = RuleChain .outerRule (repoDir ).around (leaderCluster ).around (followerCluster );
130+
131+ public CCRIndexLifecycleIT (@ Name ("targetCluster" ) TargetCluster targetCluster ) {
132+ super (targetCluster );
133+ }
134+
135+ @ ParametersFactory
136+ public static Iterable <Object []> parameters () throws Exception {
137+ return leaderFollower ();
138+ }
139+
140+ @ Override
141+ protected ElasticsearchCluster getFollowerCluster () {
142+ return followerCluster ;
143+ }
144+
145+ @ Override
146+ protected ElasticsearchCluster getLeaderCluster () {
147+ return leaderCluster ;
148+ }
149+
91150 public void testBasicCCRAndILMIntegration () throws Exception {
92151 String indexName = "logs-1" ;
93152
94153 String policyName = "basic-test" ;
95- if ("leader" . equals ( targetCluster ) ) {
154+ if (targetCluster == TargetCluster . LEADER ) {
96155 putILMPolicy (policyName , "50GB" , null , TimeValue .timeValueHours (7 * 24 ));
97156 Settings indexSettings = indexSettings (1 , 0 ).put ("index.lifecycle.name" , policyName )
98157 .put ("index.lifecycle.rollover_alias" , "logs" )
99158 .build ();
100159 createIndex (indexName , indexSettings , "" , "\" logs\" : { }" );
101160 ensureGreen (indexName );
102- } else if ("follow" . equals ( targetCluster ) ) {
161+ } else if (targetCluster == TargetCluster . FOLLOWER ) {
103162 // Policy with the same name must exist in follower cluster too:
104163 putILMPolicy (policyName , "50GB" , null , TimeValue .timeValueHours (7 * 24 ));
105164 followIndex (indexName , indexName );
@@ -136,7 +195,7 @@ public void testBasicCCRAndILMIntegration() throws Exception {
136195 // ILM should have unfollowed the follower index, so the following_index setting should have been removed:
137196 // (this controls whether the follow engine is used)
138197 assertThat (getIndexSetting (client (), indexName , "index.xpack.ccr.following_index" ), nullValue ());
139- });
198+ }, 30 , TimeUnit . SECONDS );
140199 }
141200 } else {
142201 fail ("unexpected target cluster [" + targetCluster + "]" );
@@ -145,10 +204,10 @@ public void testBasicCCRAndILMIntegration() throws Exception {
145204
146205 public void testCCRUnfollowDuringSnapshot () throws Exception {
147206 String indexName = "unfollow-test-index" ;
148- if ("leader" . equals ( targetCluster ) ) {
207+ if (targetCluster == TargetCluster . LEADER ) {
149208 createIndex (adminClient (), indexName , indexSettings (2 , 0 ).build ());
150209 ensureGreen (indexName );
151- } else if ("follow" . equals ( targetCluster ) ) {
210+ } else if (targetCluster == TargetCluster . FOLLOWER ) {
152211 createNewSingletonPolicy ("unfollow-only" , "hot" , UnfollowAction .INSTANCE , TimeValue .ZERO );
153212 followIndex (indexName , indexName );
154213 ensureGreen (indexName );
@@ -162,7 +221,7 @@ public void testCCRUnfollowDuringSnapshot() throws Exception {
162221 .field ("type" , "fs" )
163222 .startObject ("settings" )
164223 .field ("compress" , randomBoolean ())
165- .field ("location" , System . getProperty ( "tests.path.repo" ))
224+ .field ("location" , repoDir . getRoot (). getAbsolutePath ( ))
166225 .field ("max_snapshot_bytes_per_sec" , "256b" )
167226 .endObject ()
168227 .endObject ()
@@ -215,7 +274,7 @@ public void testCcrAndIlmWithRollover() throws Exception {
215274 String nextIndexName = "mymetrics-000002" ;
216275 String policyName = "rollover-test" ;
217276
218- if ("leader" . equals ( targetCluster ) ) {
277+ if (targetCluster == TargetCluster . LEADER ) {
219278 // Create a policy on the leader
220279 putILMPolicy (policyName , null , 1 , null );
221280 Request templateRequest = new Request ("PUT" , "/_index_template/my_template" );
@@ -226,7 +285,7 @@ public void testCcrAndIlmWithRollover() throws Exception {
226285 "{\" index_patterns\" : [\" mymetrics-*\" ], \" template\" :{\" settings\" : " + Strings .toString (indexSettings ) + "}}"
227286 );
228287 assertOK (client ().performRequest (templateRequest ));
229- } else if ("follow" . equals ( targetCluster ) ) {
288+ } else if (targetCluster == TargetCluster . FOLLOWER ) {
230289 // Policy with the same name must exist in follower cluster too:
231290 putILMPolicy (policyName , null , 1 , null );
232291
@@ -330,7 +389,7 @@ public void testAliasReplicatedOnShrink() throws Exception {
330389 final String policyName = "shrink-test-policy" ;
331390 final int numberOfAliases = randomIntBetween (0 , 4 );
332391
333- if ("leader" . equals ( targetCluster ) ) {
392+ if (targetCluster == TargetCluster . LEADER ) {
334393 // this policy won't exist on the leader, that's fine
335394 Settings indexSettings = indexSettings (3 , 0 ).put ("index.lifecycle.name" , policyName ).build ();
336395 final StringBuilder aliases = new StringBuilder ();
@@ -349,7 +408,7 @@ public void testAliasReplicatedOnShrink() throws Exception {
349408 }
350409 createIndex (indexName , indexSettings , "" , aliases .toString ());
351410 ensureGreen (indexName );
352- } else if ("follow" . equals ( targetCluster ) ) {
411+ } else if (targetCluster == TargetCluster . FOLLOWER ) {
353412 // Create a policy with just a Shrink action on the follower
354413 putShrinkOnlyPolicy (client (), policyName );
355414
@@ -391,12 +450,12 @@ public void testUnfollowInjectedBeforeShrink() throws Exception {
391450 final String indexName = "shrink-test" ;
392451 final String policyName = "shrink-test-policy" ;
393452
394- if ("leader" . equals ( targetCluster ) ) {
453+ if (targetCluster == TargetCluster . LEADER ) {
395454 // this policy won't exist on the leader, that's fine
396455 Settings indexSettings = indexSettings (3 , 0 ).put ("index.lifecycle.name" , policyName ).build ();
397456 createIndex (indexName , indexSettings , "" , "" );
398457 ensureGreen (indexName );
399- } else if ("follow" . equals ( targetCluster ) ) {
458+ } else if (targetCluster == TargetCluster . FOLLOWER ) {
400459 // Create a policy with just a Shrink action on the follower
401460 putShrinkOnlyPolicy (client (), policyName );
402461
@@ -433,14 +492,14 @@ public void testUnfollowInjectedBeforeShrink() throws Exception {
433492 public void testCannotShrinkLeaderIndex () throws Exception {
434493 String indexName = "shrink-leader-test" ;
435494 String policyName = "shrink-leader-test-policy" ;
436- if ("leader" . equals ( targetCluster ) ) {
495+ if (targetCluster == TargetCluster . LEADER ) {
437496 // Set up the policy and index, but don't attach the policy yet,
438497 // otherwise it'll proceed through shrink before we can set up the
439498 // follower
440499 putShrinkOnlyPolicy (client (), policyName );
441500 createIndex (indexName , indexSettings (2 , 0 ).build (), "" , "" );
442501 ensureGreen (indexName );
443- } else if ("follow" . equals ( targetCluster ) ) {
502+ } else if (targetCluster == TargetCluster . FOLLOWER ) {
444503
445504 try (RestClient leaderClient = buildLeaderClient ()) {
446505 // Policy with the same name must exist in follower cluster too:
@@ -505,16 +564,15 @@ public void testILMUnfollowFailsToRemoveRetentionLeases() throws Exception {
505564 final String followerIndex = "follower" ;
506565 final String policyName = "unfollow_only_policy" ;
507566
508- if ("leader" . equals ( targetCluster ) ) {
567+ if (targetCluster == TargetCluster . LEADER ) {
509568 Settings indexSettings = indexSettings (1 , 0 ).put ("index.lifecycle.name" , policyName ) // this policy won't exist on the leader,
510569 // that's fine
511570 .build ();
512571 createIndex (leaderIndex , indexSettings , "" , "" );
513572 ensureGreen (leaderIndex );
514- } else if ("follow" . equals ( targetCluster ) ) {
573+ } else if (targetCluster == TargetCluster . FOLLOWER ) {
515574 try (RestClient leaderClient = buildLeaderClient ()) {
516- String leaderRemoteClusterSeed = System .getProperty ("tests.leader_remote_cluster_seed" );
517- configureRemoteClusters ("other_remote" , leaderRemoteClusterSeed );
575+ configureRemoteClusters ("other_remote" , leaderCluster .getTransportEndpoints ());
518576 assertBusy (() -> {
519577 Map <?, ?> localConnection = (Map <?, ?>) toMap (client ().performRequest (new Request ("GET" , "/_remote/info" ))).get (
520578 "other_remote"
@@ -579,12 +637,12 @@ public void testTsdbLeaderIndexRolloverAndSyncAfterWaitUntilEndTime() throws Exc
579637 String dataStream = "tsdb-index-cpu" ;
580638 String policyName = "tsdb-policy" ;
581639
582- if ("leader" . equals ( targetCluster ) ) {
640+ if (targetCluster == TargetCluster . LEADER ) {
583641 putILMPolicy (policyName , null , 1 , null );
584642 Request templateRequest = new Request ("PUT" , "/_index_template/tsdb_template" );
585643 templateRequest .setJsonEntity (Strings .format (TSDB_INDEX_TEMPLATE , indexPattern , policyName ));
586644 assertOK (client ().performRequest (templateRequest ));
587- } else if ("follow" . equals ( targetCluster ) ) {
645+ } else if (targetCluster == TargetCluster . FOLLOWER ) {
588646 // Use unfollow-only policy for follower cluster instead of regular ILM policy
589647 // Follower clusters should not have their own rollover actions as they are meant
590648 // to follow the rollover behavior of the leader index, not initiate their own rollovers
0 commit comments