8
8
9
9
package org .opensearch .snapshots ;
10
10
11
- import com .fasterxml .jackson .core .JsonParseException ;
12
-
13
- import org .opensearch .OpenSearchParseException ;
14
11
import org .opensearch .core .xcontent .ToXContent ;
15
12
import org .opensearch .core .xcontent .XContentBuilder ;
16
13
import org .opensearch .core .xcontent .XContentParser ;
14
+ import org .opensearch .index .remote .RemoteStoreEnums .PathHashAlgorithm ;
15
+ import org .opensearch .index .remote .RemoteStoreEnums .PathType ;
17
16
18
17
import java .io .IOException ;
19
- import java .util .ArrayList ;
20
- import java .util .Collections ;
21
18
import java .util .List ;
22
19
23
20
/**
@@ -34,19 +31,49 @@ public class SnapshotShardPaths implements ToXContent {
34
31
public static final String FILE_NAME_FORMAT = "%s" ;
35
32
36
33
private static final String PATHS_FIELD = "paths" ;
34
+ private static final String INDEX_ID_FIELD = "indexId" ;
35
+ private static final String INDEX_NAME_FIELD = "indexName" ;
36
+ private static final String NUMBER_OF_SHARDS_FIELD = "number_of_shards" ;
37
+ private static final String SHARD_PATH_TYPE_FIELD = "shard_path_type" ;
38
+ private static final String SHARD_PATH_HASH_ALGORITHM_FIELD = "shard_path_hash_algorithm" ;
37
39
38
40
private final List <String > paths ;
39
-
40
- public SnapshotShardPaths (List <String > paths ) {
41
- this .paths = Collections .unmodifiableList (paths );
42
- }
43
-
44
- public List <String > getPaths () {
45
- return paths ;
41
+ private final String indexId ;
42
+ private final String indexName ;
43
+ private final int numberOfShards ;
44
+ private final PathType shardPathType ;
45
+ private final PathHashAlgorithm shardPathHashAlgorithm ;
46
+
47
+ public SnapshotShardPaths (
48
+ List <String > paths ,
49
+ String indexId ,
50
+ String indexName ,
51
+ int numberOfShards ,
52
+ PathType shardPathType ,
53
+ PathHashAlgorithm shardPathHashAlgorithm
54
+ ) {
55
+ assert !paths .isEmpty () : "paths must not be empty" ;
56
+ assert indexId != null && !indexId .isEmpty () : "indexId must not be empty" ;
57
+ assert indexName != null && !indexName .isEmpty () : "indexName must not be empty" ;
58
+ assert numberOfShards > 0 : "numberOfShards must be > 0" ;
59
+ assert shardPathType != null : "shardPathType must not be null" ;
60
+ assert shardPathHashAlgorithm != null : "shardPathHashAlgorithm must not be null" ;
61
+
62
+ this .paths = paths ;
63
+ this .indexId = indexId ;
64
+ this .indexName = indexName ;
65
+ this .numberOfShards = numberOfShards ;
66
+ this .shardPathType = shardPathType ;
67
+ this .shardPathHashAlgorithm = shardPathHashAlgorithm ;
46
68
}
47
69
48
70
@ Override
49
71
public XContentBuilder toXContent (XContentBuilder builder , Params params ) throws IOException {
72
+ builder .field (INDEX_ID_FIELD , indexId );
73
+ builder .field (INDEX_NAME_FIELD , indexName );
74
+ builder .field (NUMBER_OF_SHARDS_FIELD , numberOfShards );
75
+ builder .field (SHARD_PATH_TYPE_FIELD , shardPathType .getCode ());
76
+ builder .field (SHARD_PATH_HASH_ALGORITHM_FIELD , shardPathHashAlgorithm .getCode ());
50
77
builder .startArray (PATHS_FIELD );
51
78
for (String path : paths ) {
52
79
builder .value (path );
@@ -55,41 +82,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
55
82
return builder ;
56
83
}
57
84
58
- public static SnapshotShardPaths fromXContent (XContentParser parser ) throws IOException {
59
- List <String > paths = new ArrayList <>();
60
-
61
- try {
62
- XContentParser .Token token = parser .currentToken ();
63
- if (token == null ) {
64
- token = parser .nextToken ();
65
- }
66
-
67
- if (token != XContentParser .Token .START_OBJECT ) {
68
- throw new OpenSearchParseException ("Expected a start object" );
69
- }
70
-
71
- token = parser .nextToken ();
72
- if (token == XContentParser .Token .END_OBJECT ) {
73
- throw new OpenSearchParseException ("Missing [" + PATHS_FIELD + "] field" );
74
- }
75
-
76
- while (token != XContentParser .Token .END_OBJECT ) {
77
- String fieldName = parser .currentName ();
78
- if (PATHS_FIELD .equals (fieldName )) {
79
- if (parser .nextToken () != XContentParser .Token .START_ARRAY ) {
80
- throw new OpenSearchParseException ("Expected an array for field [" + PATHS_FIELD + "]" );
81
- }
82
- while (parser .nextToken () != XContentParser .Token .END_ARRAY ) {
83
- paths .add (parser .text ());
84
- }
85
- } else {
86
- throw new OpenSearchParseException ("Unexpected field [" + fieldName + "]" );
87
- }
88
- token = parser .nextToken ();
89
- }
90
- } catch (JsonParseException e ) {
91
- throw new OpenSearchParseException ("Failed to parse SnapshotIndexIdPaths" , e );
92
- }
93
- return new SnapshotShardPaths (paths );
85
+ public static SnapshotShardPaths fromXContent (XContentParser ignored ) {
86
+ throw new UnsupportedOperationException ("SnapshotShardPaths.fromXContent() is not supported" );
94
87
}
95
88
}
0 commit comments