|
31 | 31 | import static org.elasticsearch.cluster.metadata.DataStream.getDefaultBackingIndexName; |
32 | 32 | import static org.elasticsearch.cluster.metadata.DataStream.getDefaultFailureStoreName; |
33 | 33 | import static org.hamcrest.Matchers.is; |
| 34 | +import static org.hamcrest.Matchers.notNullValue; |
34 | 35 | import static org.hamcrest.Matchers.nullValue; |
35 | 36 |
|
36 | 37 | public class GetDataStreamsResponseTests extends ESTestCase { |
@@ -136,16 +137,16 @@ public void testResponseIlmAndDataStreamLifecycleRepresentation() throws Excepti |
136 | 137 |
|
137 | 138 | if (DataStream.isFailureStoreFeatureFlagEnabled()) { |
138 | 139 | var failureStore = (Map<String, Object>) dataStreamMap.get(DataStream.FAILURE_STORE_FIELD.getPreferredName()); |
139 | | - List<Object> failureStoresRepresentation = (List<Object>) failureStore.get(DataStream.INDICES_FIELD.getPreferredName()); |
140 | | - Map<String, Object> failureStoreRepresentation = (Map<String, Object>) failureStoresRepresentation.get(0); |
141 | | - assertThat(failureStoreRepresentation.get("index_name"), is(failureStoreIndex.getName())); |
142 | | - assertThat(failureStoreRepresentation.get(Response.DataStreamInfo.PREFER_ILM.getPreferredName()), is(false)); |
| 140 | + List<Object> failureIndices = (List<Object>) failureStore.get(DataStream.INDICES_FIELD.getPreferredName()); |
| 141 | + Map<String, Object> failureIndexRepresentation = (Map<String, Object>) failureIndices.get(0); |
| 142 | + assertThat(failureIndexRepresentation.get("index_name"), is(failureStoreIndex.getName())); |
| 143 | + assertThat(failureIndexRepresentation.get(Response.DataStreamInfo.PREFER_ILM.getPreferredName()), nullValue()); |
143 | 144 | assertThat( |
144 | | - failureStoreRepresentation.get(Response.DataStreamInfo.ILM_POLICY_FIELD.getPreferredName()), |
| 145 | + failureIndexRepresentation.get(Response.DataStreamInfo.ILM_POLICY_FIELD.getPreferredName()), |
145 | 146 | is(nullValue()) |
146 | 147 | ); |
147 | 148 | assertThat( |
148 | | - failureStoreRepresentation.get(Response.DataStreamInfo.MANAGED_BY.getPreferredName()), |
| 149 | + failureIndexRepresentation.get(Response.DataStreamInfo.MANAGED_BY.getPreferredName()), |
149 | 150 | is(ManagedBy.LIFECYCLE.displayValue) |
150 | 151 | ); |
151 | 152 | } |
@@ -230,21 +231,86 @@ public void testResponseIlmAndDataStreamLifecycleRepresentation() throws Excepti |
230 | 231 |
|
231 | 232 | if (DataStream.isFailureStoreFeatureFlagEnabled()) { |
232 | 233 | var failureStore = (Map<String, Object>) dataStreamMap.get(DataStream.FAILURE_STORE_FIELD.getPreferredName()); |
233 | | - List<Object> failureStoresRepresentation = (List<Object>) failureStore.get(DataStream.INDICES_FIELD.getPreferredName()); |
234 | | - Map<String, Object> failureStoreRepresentation = (Map<String, Object>) failureStoresRepresentation.get(0); |
235 | | - assertThat(failureStoreRepresentation.get("index_name"), is(failureStoreIndex.getName())); |
236 | | - assertThat(failureStoreRepresentation.get(Response.DataStreamInfo.PREFER_ILM.getPreferredName()), is(false)); |
| 234 | + List<Object> failureIndices = (List<Object>) failureStore.get(DataStream.INDICES_FIELD.getPreferredName()); |
| 235 | + Map<String, Object> failureIndexRepresentation = (Map<String, Object>) failureIndices.get(0); |
| 236 | + assertThat(failureIndexRepresentation.get("index_name"), is(failureStoreIndex.getName())); |
| 237 | + assertThat(failureIndexRepresentation.get(Response.DataStreamInfo.PREFER_ILM.getPreferredName()), nullValue()); |
237 | 238 | assertThat( |
238 | | - failureStoreRepresentation.get(Response.DataStreamInfo.ILM_POLICY_FIELD.getPreferredName()), |
| 239 | + failureIndexRepresentation.get(Response.DataStreamInfo.ILM_POLICY_FIELD.getPreferredName()), |
239 | 240 | is(nullValue()) |
240 | 241 | ); |
241 | 242 | assertThat( |
242 | | - failureStoreRepresentation.get(Response.DataStreamInfo.MANAGED_BY.getPreferredName()), |
| 243 | + failureIndexRepresentation.get(Response.DataStreamInfo.MANAGED_BY.getPreferredName()), |
243 | 244 | is(ManagedBy.UNMANAGED.displayValue) |
244 | 245 | ); |
245 | 246 | } |
246 | 247 | } |
247 | 248 | } |
| 249 | + |
| 250 | + { |
| 251 | + // one failure index that have ILM policy |
| 252 | + DataStream logs = DataStream.builder("logs", indices) |
| 253 | + .setGeneration(3) |
| 254 | + .setAllowCustomRouting(true) |
| 255 | + .setIndexMode(IndexMode.STANDARD) |
| 256 | + .setLifecycle(DataStreamLifecycle.DEFAULT_DATA_LIFECYCLE) |
| 257 | + .setDataStreamOptions(DataStreamOptions.FAILURE_STORE_ENABLED) |
| 258 | + .setFailureIndices(DataStream.DataStreamIndices.failureIndicesBuilder(failureStores).build()) |
| 259 | + .build(); |
| 260 | + |
| 261 | + String ilmPolicyName = "rollover-30days"; |
| 262 | + Map<Index, Response.IndexProperties> indexSettingsValues = Map.of( |
| 263 | + firstGenerationIndex, |
| 264 | + new Response.IndexProperties(true, ilmPolicyName, ManagedBy.ILM, null), |
| 265 | + secondGenerationIndex, |
| 266 | + new Response.IndexProperties(false, ilmPolicyName, ManagedBy.LIFECYCLE, null), |
| 267 | + writeIndex, |
| 268 | + new Response.IndexProperties(true, null, ManagedBy.LIFECYCLE, null), |
| 269 | + failureStoreIndex, |
| 270 | + new Response.IndexProperties(randomBoolean(), ilmPolicyName, ManagedBy.LIFECYCLE, null) |
| 271 | + ); |
| 272 | + |
| 273 | + Response.DataStreamInfo dataStreamInfo = new Response.DataStreamInfo( |
| 274 | + logs, |
| 275 | + true, |
| 276 | + ClusterHealthStatus.GREEN, |
| 277 | + "index-template", |
| 278 | + null, |
| 279 | + null, |
| 280 | + indexSettingsValues, |
| 281 | + false, |
| 282 | + null, |
| 283 | + null |
| 284 | + ); |
| 285 | + Response response = new Response(List.of(dataStreamInfo)); |
| 286 | + XContentBuilder contentBuilder = XContentFactory.jsonBuilder(); |
| 287 | + response.toXContent(contentBuilder, ToXContent.EMPTY_PARAMS); |
| 288 | + |
| 289 | + BytesReference bytes = BytesReference.bytes(contentBuilder); |
| 290 | + try (XContentParser parser = createParser(JsonXContent.jsonXContent, bytes)) { |
| 291 | + Map<String, Object> map = parser.map(); |
| 292 | + List<Object> dataStreams = (List<Object>) map.get(Response.DATA_STREAMS_FIELD.getPreferredName()); |
| 293 | + assertThat(dataStreams.size(), is(1)); |
| 294 | + Map<String, Object> dataStreamMap = (Map<String, Object>) dataStreams.get(0); |
| 295 | + assertThat(dataStreamMap.get(DataStream.NAME_FIELD.getPreferredName()), is(dataStreamName)); |
| 296 | + |
| 297 | + if (DataStream.isFailureStoreFeatureFlagEnabled()) { |
| 298 | + var failureStore = (Map<String, Object>) dataStreamMap.get(DataStream.FAILURE_STORE_FIELD.getPreferredName()); |
| 299 | + List<Object> failureIndices = (List<Object>) failureStore.get(DataStream.INDICES_FIELD.getPreferredName()); |
| 300 | + Map<String, Object> failureIndexRepresentation = (Map<String, Object>) failureIndices.get(0); |
| 301 | + assertThat(failureIndexRepresentation.get("index_name"), is(failureStoreIndex.getName())); |
| 302 | + assertThat(failureIndexRepresentation.get(Response.DataStreamInfo.PREFER_ILM.getPreferredName()), notNullValue()); |
| 303 | + assertThat( |
| 304 | + failureIndexRepresentation.get(Response.DataStreamInfo.ILM_POLICY_FIELD.getPreferredName()), |
| 305 | + is(ilmPolicyName) |
| 306 | + ); |
| 307 | + assertThat( |
| 308 | + failureIndexRepresentation.get(Response.DataStreamInfo.MANAGED_BY.getPreferredName()), |
| 309 | + is(ManagedBy.LIFECYCLE.displayValue) |
| 310 | + ); |
| 311 | + } |
| 312 | + } |
| 313 | + } |
248 | 314 | } |
249 | 315 |
|
250 | 316 | public void testManagedByDisplayValuesDontAccidentalyChange() { |
|
0 commit comments