1717import java .io .IOException ;
1818import java .util .ArrayList ;
1919import java .util .List ;
20- import java .util .Objects ;
2120
2221/**
2322 * Remote Store based Shard snapshot metadata
@@ -40,7 +39,7 @@ public class RemoteStoreShardShallowCopySnapshot implements ToXContentFragment {
4039 private final String indexUUID ;
4140 private final List <String > fileNames ;
4241
43- private static final String DEFAULT_VERSION = "1" ;
42+ static final String DEFAULT_VERSION = "1" ;
4443 static final String NAME = "name" ;
4544 static final String VERSION = "version" ;
4645 static final String INDEX_VERSION = "index_version" ;
@@ -116,22 +115,69 @@ public RemoteStoreShardShallowCopySnapshot(
116115 String repositoryBasePath ,
117116 List <String > fileNames
118117 ) {
119- this .snapshot = Objects .requireNonNull (snapshot , "Invalid/Missing Snapshot Name" );
120- assert indexVersion > 0 : "Invalid Index Version" ;
121- assert primaryTerm > 0 : "Invalid Primary Term" ;
122- assert commitGeneration > 0 : "Invalid Commit Generation" ;
118+ this .version = DEFAULT_VERSION ;
119+ verifyParameters (
120+ version ,
121+ snapshot ,
122+ indexVersion ,
123+ primaryTerm ,
124+ commitGeneration ,
125+ indexUUID ,
126+ remoteStoreRepository ,
127+ repositoryBasePath
128+ );
129+ this .snapshot = snapshot ;
123130 this .indexVersion = indexVersion ;
124131 this .primaryTerm = primaryTerm ;
125132 this .commitGeneration = commitGeneration ;
126133 this .startTime = startTime ;
127134 this .time = time ;
128135 this .totalFileCount = totalFileCount ;
129136 this .totalSize = totalSize ;
130- this .indexUUID = Objects .requireNonNull (indexUUID , "Invalid/Missing Index UUID" );
131- this .remoteStoreRepository = Objects .requireNonNull (remoteStoreRepository , "Invalid/Missing Remote Store Repository" );
132- this .repositoryBasePath = Objects .requireNonNull (repositoryBasePath , "Invalid/Missing Repository Base Path" );
137+ this .indexUUID = indexUUID ;
138+ this .remoteStoreRepository = remoteStoreRepository ;
139+ this .repositoryBasePath = repositoryBasePath ;
140+ this .fileNames = fileNames ;
141+ }
142+
143+ private RemoteStoreShardShallowCopySnapshot (
144+ String version ,
145+ String snapshot ,
146+ long indexVersion ,
147+ long primaryTerm ,
148+ long commitGeneration ,
149+ long startTime ,
150+ long time ,
151+ int totalFileCount ,
152+ long totalSize ,
153+ String indexUUID ,
154+ String remoteStoreRepository ,
155+ String repositoryBasePath ,
156+ List <String > fileNames
157+ ) {
158+ verifyParameters (
159+ version ,
160+ snapshot ,
161+ indexVersion ,
162+ primaryTerm ,
163+ commitGeneration ,
164+ indexUUID ,
165+ remoteStoreRepository ,
166+ repositoryBasePath
167+ );
168+ this .version = version ;
169+ this .snapshot = snapshot ;
170+ this .indexVersion = indexVersion ;
171+ this .primaryTerm = primaryTerm ;
172+ this .commitGeneration = commitGeneration ;
173+ this .startTime = startTime ;
174+ this .time = time ;
175+ this .totalFileCount = totalFileCount ;
176+ this .totalSize = totalSize ;
177+ this .indexUUID = indexUUID ;
178+ this .remoteStoreRepository = remoteStoreRepository ;
179+ this .repositoryBasePath = repositoryBasePath ;
133180 this .fileNames = fileNames ;
134- this .version = DEFAULT_VERSION ;
135181 }
136182
137183 /**
@@ -142,7 +188,7 @@ public RemoteStoreShardShallowCopySnapshot(
142188 */
143189 public static RemoteStoreShardShallowCopySnapshot fromXContent (XContentParser parser ) throws IOException {
144190 String snapshot = null ;
145- String version = DEFAULT_VERSION ;
191+ String version = null ;
146192 long indexVersion = -1 ;
147193 long startTime = 0 ;
148194 long time = 0 ;
@@ -205,6 +251,7 @@ public static RemoteStoreShardShallowCopySnapshot fromXContent(XContentParser pa
205251 }
206252
207253 return new RemoteStoreShardShallowCopySnapshot (
254+ version ,
208255 snapshot ,
209256 indexVersion ,
210257 primaryTerm ,
@@ -308,4 +355,43 @@ public long totalSize() {
308355 return totalSize ;
309356 }
310357
358+ private void verifyParameters (
359+ String version ,
360+ String snapshot ,
361+ long indexVersion ,
362+ long primaryTerm ,
363+ long commitGeneration ,
364+ String indexUUID ,
365+ String remoteStoreRepository ,
366+ String repositoryBasePath
367+ ) {
368+ String exceptionStr = null ;
369+ if (version == null ) {
370+ exceptionStr = "Invalid Version Provided" ;
371+ }
372+ if (snapshot == null ) {
373+ exceptionStr = "Invalid/Missing Snapshot Name" ;
374+ }
375+ if (indexVersion < 0 ) {
376+ exceptionStr = "Invalid Index Version" ;
377+ }
378+ if (primaryTerm < 0 ) {
379+ exceptionStr = "Invalid Primary Term" ;
380+ }
381+ if (commitGeneration < 0 ) {
382+ exceptionStr = "Invalid Commit Generation" ;
383+ }
384+ if (indexUUID == null ) {
385+ exceptionStr = "Invalid/Missing Index UUID" ;
386+ }
387+ if (remoteStoreRepository == null ) {
388+ exceptionStr = "Invalid/Missing Remote Store Repository" ;
389+ }
390+ if (repositoryBasePath == null ) {
391+ exceptionStr = "Invalid/Missing Repository Base Path" ;
392+ }
393+ if (exceptionStr != null ) {
394+ throw new IllegalArgumentException (exceptionStr );
395+ }
396+ }
311397}
0 commit comments