9
9
package org .opensearch .action .pagination ;
10
10
11
11
import org .opensearch .OpenSearchParseException ;
12
+ import org .opensearch .action .support .IndicesOptions ;
12
13
import org .opensearch .cluster .ClusterState ;
13
14
import org .opensearch .cluster .metadata .IndexMetadata ;
14
15
import org .opensearch .cluster .routing .IndexRoutingTable ;
@@ -37,14 +38,23 @@ public class ShardPaginationStrategy implements PaginationStrategy<ShardRouting>
37
38
private PageData pageData ;
38
39
39
40
public ShardPaginationStrategy (PageParams pageParams , ClusterState clusterState ) {
41
+ this (pageParams , clusterState , null );
42
+ }
43
+
44
+ public ShardPaginationStrategy (PageParams pageParams , ClusterState clusterState , IndicesOptions indicesOptions ) {
40
45
ShardStrategyToken shardStrategyToken = getShardStrategyToken (pageParams .getRequestedToken ());
41
46
// Get list of indices metadata sorted by their creation time and filtered by the last sent index
42
- List <IndexMetadata > filteredIndices = getEligibleIndices (
47
+ List <IndexMetadata > filteredIndices = PaginationStrategy . getSortedIndexMetadata (
43
48
clusterState ,
44
- pageParams .getSort (),
45
- Objects .isNull (shardStrategyToken ) ? null : shardStrategyToken .lastIndexName ,
46
- Objects .isNull (shardStrategyToken ) ? null : shardStrategyToken .lastIndexCreationTime
49
+ getMetadataFilter (
50
+ pageParams .getSort (),
51
+ Objects .isNull (shardStrategyToken ) ? null : shardStrategyToken .lastIndexName ,
52
+ Objects .isNull (shardStrategyToken ) ? null : shardStrategyToken .lastIndexCreationTime ,
53
+ indicesOptions
54
+ ),
55
+ PageParams .PARAM_ASC_SORT_VALUE .equals (pageParams .getSort ()) ? ASC_COMPARATOR : DESC_COMPARATOR
47
56
);
57
+
48
58
// Get the list of shards and indices belonging to current page.
49
59
this .pageData = getPageData (
50
60
filteredIndices ,
@@ -54,39 +64,31 @@ public ShardPaginationStrategy(PageParams pageParams, ClusterState clusterState)
54
64
);
55
65
}
56
66
57
- private static List <IndexMetadata > getEligibleIndices (
58
- ClusterState clusterState ,
67
+ private static Predicate <IndexMetadata > getMetadataFilter (
59
68
String sortOrder ,
60
69
String lastIndexName ,
61
- Long lastIndexCreationTime
70
+ Long lastIndexCreationTime ,
71
+ IndicesOptions indicesOptions
62
72
) {
63
73
if (Objects .isNull (lastIndexName ) || Objects .isNull (lastIndexCreationTime )) {
64
- return PaginationStrategy .getSortedIndexMetadata (
65
- clusterState ,
66
- PageParams .PARAM_ASC_SORT_VALUE .equals (sortOrder ) ? ASC_COMPARATOR : DESC_COMPARATOR
67
- );
68
- } else {
69
- return PaginationStrategy .getSortedIndexMetadata (
70
- clusterState ,
71
- getMetadataFilter (sortOrder , lastIndexName , lastIndexCreationTime ),
72
- PageParams .PARAM_ASC_SORT_VALUE .equals (sortOrder ) ? ASC_COMPARATOR : DESC_COMPARATOR
73
- );
74
- }
75
- }
76
-
77
- private static Predicate <IndexMetadata > getMetadataFilter (String sortOrder , String lastIndexName , Long lastIndexCreationTime ) {
78
- if (Objects .isNull (lastIndexName ) || Objects .isNull (lastIndexCreationTime )) {
79
- return indexMetadata -> true ;
74
+ return indexStateFilter (indicesOptions );
80
75
}
81
76
return indexNameFilter (lastIndexName ).or (
82
77
IndexPaginationStrategy .getIndexCreateTimeFilter (sortOrder , lastIndexName , lastIndexCreationTime )
83
- );
78
+ ). and ( indexStateFilter ( indicesOptions )) ;
84
79
}
85
80
86
81
private static Predicate <IndexMetadata > indexNameFilter (String lastIndexName ) {
87
82
return metadata -> metadata .getIndex ().getName ().equals (lastIndexName );
88
83
}
89
84
85
+ private static Predicate <IndexMetadata > indexStateFilter (IndicesOptions indicesOptions ) {
86
+ if (Objects .isNull (indicesOptions ) || !indicesOptions .forbidClosedIndices ()) {
87
+ return metadata -> true ;
88
+ }
89
+ return metadata -> metadata .getState ().equals (IndexMetadata .State .OPEN );
90
+ }
91
+
90
92
/**
91
93
* Will be used to get the list of shards and respective indices to which they belong,
92
94
* which are to be displayed in a page.
0 commit comments