77
88package  org .elasticsearch .xpack .deprecation ;
99
10+ import  org .elasticsearch .cluster .ClusterState ;
11+ import  org .elasticsearch .cluster .metadata .DataStream ;
12+ import  org .elasticsearch .cluster .metadata .DataStreamMetadata ;
13+ import  org .elasticsearch .cluster .metadata .DataStreamOptions ;
1014import  org .elasticsearch .cluster .metadata .IndexMetadata ;
15+ import  org .elasticsearch .cluster .metadata .Metadata ;
16+ import  org .elasticsearch .common .collect .ImmutableOpenMap ;
1117import  org .elasticsearch .common .settings .Settings ;
18+ import  org .elasticsearch .index .IndexMode ;
1219import  org .elasticsearch .index .IndexModule ;
1320import  org .elasticsearch .index .IndexSettings ;
1421import  org .elasticsearch .index .IndexVersion ;
1926
2027import  java .io .IOException ;
2128import  java .util .List ;
29+ import  java .util .Map ;
2230
2331import  static  java .util .Collections .singletonList ;
2432import  static  org .elasticsearch .xpack .deprecation .DeprecationChecks .INDEX_SETTINGS_CHECKS ;
2533import  static  org .hamcrest .Matchers .empty ;
34+ import  static  org .hamcrest .Matchers .equalTo ;
2635import  static  org .hamcrest .Matchers .hasItem ;
2736import  static  org .hamcrest .collection .IsIterableContainingInOrder .contains ;
2837
2938public  class  IndexDeprecationChecksTests  extends  ESTestCase  {
3039    public  void  testOldIndicesCheck () {
31-         IndexVersion  createdWith  = IndexVersion .fromId (1000099 );
40+         IndexVersion  createdWith  = IndexVersion .fromId (7170099 );
3241        IndexMetadata  indexMetadata  = IndexMetadata .builder ("test" )
3342            .settings (settings (createdWith ))
3443            .numberOfShards (1 )
3544            .numberOfReplicas (0 )
3645            .build ();
46+         ClusterState  clusterState  = ClusterState .builder (ClusterState .EMPTY_STATE )
47+             .metadata (Metadata .builder ().put (indexMetadata , true ))
48+             .build ();
3749        DeprecationIssue  expected  = new  DeprecationIssue (
3850            DeprecationIssue .Level .CRITICAL ,
39-             "Old index with a compatibility version < 7 .0" ,
40-             "https://www.elastic.co/guide/en/elasticsearch/reference/master/"   +  " breaking-changes-8 .0.html" ,
51+             "Old index with a compatibility version < 8 .0" ,
52+             "https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking-changes-9 .0.html" ,
4153            "This index has version: "  + createdWith .toReleaseVersion (),
4254            false ,
4355            null 
4456        );
45-         List <DeprecationIssue > issues  = DeprecationChecks .filterChecks (INDEX_SETTINGS_CHECKS , c  -> c .apply (indexMetadata ));
57+         List <DeprecationIssue > issues  = DeprecationChecks .filterChecks (INDEX_SETTINGS_CHECKS , c  -> c .apply (indexMetadata ,  clusterState ));
4658        assertEquals (singletonList (expected ), issues );
4759    }
4860
61+     public  void  testOldIndicesCheckDataStreamIndex () {
62+         IndexVersion  createdWith  = IndexVersion .fromId (7170099 );
63+         IndexMetadata  indexMetadata  = IndexMetadata .builder (".ds-test" )
64+             .settings (settings (createdWith ).put ("index.hidden" , true ))
65+             .numberOfShards (1 )
66+             .numberOfReplicas (0 )
67+             .build ();
68+         DataStream  dataStream  = new  DataStream (
69+             randomAlphaOfLength (10 ),
70+             List .of (indexMetadata .getIndex ()),
71+             randomNegativeLong (),
72+             Map .of (),
73+             randomBoolean (),
74+             false ,
75+             false ,
76+             randomBoolean (),
77+             randomFrom (IndexMode .values ()),
78+             null ,
79+             randomFrom (DataStreamOptions .EMPTY , DataStreamOptions .FAILURE_STORE_DISABLED , DataStreamOptions .FAILURE_STORE_ENABLED , null ),
80+             List .of (),
81+             randomBoolean (),
82+             null 
83+         );
84+         ClusterState  clusterState  = ClusterState .builder (ClusterState .EMPTY_STATE )
85+             .metadata (
86+                 Metadata .builder ()
87+                     .put (indexMetadata , true )
88+                     .customs (
89+                         Map .of (
90+                             DataStreamMetadata .TYPE ,
91+                             new  DataStreamMetadata (
92+                                 ImmutableOpenMap .builder (Map .of ("my-data-stream" , dataStream )).build (),
93+                                 ImmutableOpenMap .of ()
94+                             )
95+                         )
96+                     )
97+             )
98+             .build ();
99+         List <DeprecationIssue > issues  = DeprecationChecks .filterChecks (INDEX_SETTINGS_CHECKS , c  -> c .apply (indexMetadata , clusterState ));
100+         assertThat (issues .size (), equalTo (0 ));
101+     }
102+ 
49103    public  void  testTranslogRetentionSettings () {
50104        Settings .Builder  settings  = settings (IndexVersion .current ());
51105        settings .put (IndexSettings .INDEX_TRANSLOG_RETENTION_AGE_SETTING .getKey (), randomPositiveTimeValue ());
52106        settings .put (IndexSettings .INDEX_TRANSLOG_RETENTION_SIZE_SETTING .getKey (), between (1 , 1024 ) + "b" );
53107        IndexMetadata  indexMetadata  = IndexMetadata .builder ("test" ).settings (settings ).numberOfShards (1 ).numberOfReplicas (0 ).build ();
54-         List <DeprecationIssue > issues  = DeprecationChecks .filterChecks (INDEX_SETTINGS_CHECKS , c  -> c .apply (indexMetadata ));
108+         List <DeprecationIssue > issues  = DeprecationChecks .filterChecks (
109+             INDEX_SETTINGS_CHECKS ,
110+             c  -> c .apply (indexMetadata , ClusterState .EMPTY_STATE )
111+         );
55112        assertThat (
56113            issues ,
57114            contains (
@@ -81,15 +138,21 @@ public void testDefaultTranslogRetentionSettings() {
81138            settings .put (IndexSettings .INDEX_SOFT_DELETES_SETTING .getKey (), false );
82139        }
83140        IndexMetadata  indexMetadata  = IndexMetadata .builder ("test" ).settings (settings ).numberOfShards (1 ).numberOfReplicas (0 ).build ();
84-         List <DeprecationIssue > issues  = DeprecationChecks .filterChecks (INDEX_SETTINGS_CHECKS , c  -> c .apply (indexMetadata ));
141+         List <DeprecationIssue > issues  = DeprecationChecks .filterChecks (
142+             INDEX_SETTINGS_CHECKS ,
143+             c  -> c .apply (indexMetadata , ClusterState .EMPTY_STATE )
144+         );
85145        assertThat (issues , empty ());
86146    }
87147
88148    public  void  testIndexDataPathSetting () {
89149        Settings .Builder  settings  = settings (IndexVersion .current ());
90150        settings .put (IndexMetadata .INDEX_DATA_PATH_SETTING .getKey (), createTempDir ());
91151        IndexMetadata  indexMetadata  = IndexMetadata .builder ("test" ).settings (settings ).numberOfShards (1 ).numberOfReplicas (0 ).build ();
92-         List <DeprecationIssue > issues  = DeprecationChecks .filterChecks (INDEX_SETTINGS_CHECKS , c  -> c .apply (indexMetadata ));
152+         List <DeprecationIssue > issues  = DeprecationChecks .filterChecks (
153+             INDEX_SETTINGS_CHECKS ,
154+             c  -> c .apply (indexMetadata , ClusterState .EMPTY_STATE )
155+         );
93156        final  String  expectedUrl  =
94157            "https://www.elastic.co/guide/en/elasticsearch/reference/7.13/breaking-changes-7.13.html#deprecate-shared-data-path-setting" ;
95158        assertThat (
@@ -111,7 +174,10 @@ public void testSimpleFSSetting() {
111174        Settings .Builder  settings  = settings (IndexVersion .current ());
112175        settings .put (IndexModule .INDEX_STORE_TYPE_SETTING .getKey (), "simplefs" );
113176        IndexMetadata  indexMetadata  = IndexMetadata .builder ("test" ).settings (settings ).numberOfShards (1 ).numberOfReplicas (0 ).build ();
114-         List <DeprecationIssue > issues  = DeprecationChecks .filterChecks (INDEX_SETTINGS_CHECKS , c  -> c .apply (indexMetadata ));
177+         List <DeprecationIssue > issues  = DeprecationChecks .filterChecks (
178+             INDEX_SETTINGS_CHECKS ,
179+             c  -> c .apply (indexMetadata , ClusterState .EMPTY_STATE )
180+         );
115181        assertThat (
116182            issues ,
117183            contains (
@@ -133,7 +199,10 @@ public void testFrozenIndex() {
133199        Settings .Builder  settings  = settings (IndexVersion .current ());
134200        settings .put (FrozenEngine .INDEX_FROZEN .getKey (), true );
135201        IndexMetadata  indexMetadata  = IndexMetadata .builder ("test" ).settings (settings ).numberOfShards (1 ).numberOfReplicas (0 ).build ();
136-         List <DeprecationIssue > issues  = DeprecationChecks .filterChecks (INDEX_SETTINGS_CHECKS , c  -> c .apply (indexMetadata ));
202+         List <DeprecationIssue > issues  = DeprecationChecks .filterChecks (
203+             INDEX_SETTINGS_CHECKS ,
204+             c  -> c .apply (indexMetadata , ClusterState .EMPTY_STATE )
205+         );
137206        assertThat (
138207            issues ,
139208            contains (
@@ -175,7 +244,10 @@ public void testCamelCaseDeprecation() throws IOException {
175244            false ,
176245            null 
177246        );
178-         List <DeprecationIssue > issues  = DeprecationChecks .filterChecks (INDEX_SETTINGS_CHECKS , c  -> c .apply (simpleIndex ));
247+         List <DeprecationIssue > issues  = DeprecationChecks .filterChecks (
248+             INDEX_SETTINGS_CHECKS ,
249+             c  -> c .apply (simpleIndex , ClusterState .EMPTY_STATE )
250+         );
179251        assertThat (issues , hasItem (expected ));
180252    }
181253}
0 commit comments