28
28
29
29
package org .sirix .access ;
30
30
31
- import com .google .common .base .MoreObjects ;
32
- import com .google .gson .stream .JsonReader ;
33
- import com .google .gson .stream .JsonWriter ;
34
- import net .openhft .hashing .LongHashFunction ;
31
+ import static com .google .common .base .Preconditions .checkArgument ;
32
+ import static java .util .Objects .requireNonNull ;
33
+
34
+ import java .io .FileReader ;
35
+ import java .io .FileWriter ;
36
+ import java .io .IOException ;
37
+ import java .lang .reflect .Constructor ;
38
+ import java .lang .reflect .InvocationTargetException ;
39
+ import java .nio .file .Files ;
40
+ import java .nio .file .Path ;
41
+ import java .nio .file .Paths ;
42
+ import java .util .ArrayList ;
43
+ import java .util .List ;
44
+ import java .util .Objects ;
45
+
35
46
import org .checkerframework .checker .index .qual .NonNegative ;
47
+ import org .json .JSONObject ;
36
48
import org .sirix .BinaryEncodingVersion ;
37
49
import org .sirix .access .trx .node .HashType ;
38
50
import org .sirix .exception .SirixIOException ;
46
58
import org .sirix .settings .VersioningType ;
47
59
import org .sirix .utils .OS ;
48
60
49
- import java .io .FileReader ;
50
- import java .io .FileWriter ;
51
- import java .io .IOException ;
52
- import java .lang .reflect .Constructor ;
53
- import java .lang .reflect .InvocationTargetException ;
54
- import java .nio .file .Files ;
55
- import java .nio .file .Path ;
56
- import java .nio .file .Paths ;
57
- import java .util .ArrayList ;
58
- import java .util .List ;
59
- import java .util .Objects ;
61
+ import com .google .common .base .MoreObjects ;
62
+ import com .google .gson .stream .JsonReader ;
63
+ import com .google .gson .stream .JsonWriter ;
60
64
61
- import static com .google .common .base .Preconditions .checkArgument ;
62
- import static java .util .Objects .requireNonNull ;
65
+ import net .openhft .hashing .LongHashFunction ;
63
66
64
67
/**
65
68
* Holds the settings for a resource which acts as a base for session that can not change. This
@@ -165,6 +168,36 @@ public static int compareStructure(final Path file) {
165
168
}
166
169
}
167
170
171
+ public static final class AWSStorageInformation {
172
+ private final String awsProfile ;
173
+ private final String awsRegion ;
174
+ private final String bucketName ; //this should be same as the database name
175
+ private final boolean shouldCreateBucketIfNotExists ;
176
+
177
+ public AWSStorageInformation (String awsProfile , String awsRegion , String bucketName ,
178
+ boolean shouldCreateBucketIfNotExists ) {
179
+ this .awsProfile = awsProfile ;
180
+ this .awsRegion = awsRegion ;
181
+ this .bucketName = bucketName ;
182
+ this .shouldCreateBucketIfNotExists = shouldCreateBucketIfNotExists ;
183
+ }
184
+
185
+ public String getAwsProfile () {
186
+ return awsProfile ;
187
+ }
188
+
189
+ public String getAwsRegion () {
190
+ return awsRegion ;
191
+ }
192
+
193
+ public String getBucketName () {
194
+ return bucketName ;
195
+ }
196
+
197
+ public boolean shouldCreateBucketIfNotExists () {
198
+ return shouldCreateBucketIfNotExists ;
199
+ }
200
+ }
168
201
// FIXED STANDARD FIELDS
169
202
/**
170
203
* Standard storage.
@@ -297,6 +330,14 @@ public static int compareStructure(final Path file) {
297
330
298
331
// END MEMBERS FOR FIXED FIELDS
299
332
333
+ /*
334
+ * Optional AWS Credentials
335
+ * */
336
+ /*
337
+ * This could be improved in future to make it more sophisticated in terms setting the credentials
338
+ * for creating the cloud client connection
339
+ * */
340
+ public final AWSStorageInformation awsStoreInfo ;
300
341
/**
301
342
* Get a new builder instance.
302
343
*
@@ -330,6 +371,7 @@ private ResourceConfiguration(final ResourceConfiguration.Builder builder) {
330
371
customCommitTimestamps = builder .customCommitTimestamps ;
331
372
storeNodeHistory = builder .storeNodeHistory ;
332
373
binaryVersion = builder .binaryEncodingVersion ;
374
+ awsStoreInfo = builder .awsStoreInfo ;
333
375
}
334
376
335
377
public BinaryEncodingVersion getBinaryEncodingVersion () {
@@ -448,7 +490,7 @@ public boolean storeNodeHistory() {
448
490
private static final String [] JSONNAMES =
449
491
{ "binaryEncoding" , "revisioning" , "revisioningClass" , "numbersOfRevisiontoRestore" , "byteHandlerClasses" ,
450
492
"storageKind" , "hashKind" , "hashFunction" , "compression" , "pathSummary" , "resourceID" , "deweyIDsStored" ,
451
- "persistenter" , "storeDiffs" , "customCommitTimestamps" , "storeNodeHistory" , "storeChildCount" };
493
+ "persistenter" , "storeDiffs" , "customCommitTimestamps" , "storeNodeHistory" , "storeChildCount" , "awsStoreInfo" };
452
494
453
495
/**
454
496
* Serialize the configuration.
@@ -596,7 +638,21 @@ public static ResourceConfiguration deserialize(final Path file) throws SirixIOE
596
638
name = jsonReader .nextName ();
597
639
assert name .equals (JSONNAMES [16 ]);
598
640
final boolean storeChildCount = jsonReader .nextBoolean ();
599
-
641
+ name = jsonReader .nextName ();
642
+ assert name .equals (JSONNAMES [17 ]);
643
+ /*Begin object to read the nested json properties required aws connection*/
644
+ jsonReader .beginObject ();
645
+ AWSStorageInformation awsStoreInfo =null ;
646
+ if (jsonReader .hasNext ()) {
647
+ final String awsProfile =jsonReader .nextString ();
648
+ final String awsRegion =jsonReader .nextString ();
649
+ final String bucketName =jsonReader .nextString ();
650
+ final boolean shouldCreateBucketIfNotExists =jsonReader .nextBoolean ();
651
+ awsStoreInfo = new AWSStorageInformation (awsProfile ,
652
+ awsRegion , bucketName , shouldCreateBucketIfNotExists );
653
+ }
654
+ jsonReader .endObject ();
655
+ /*End object to end reading the nested json properties*/
600
656
jsonReader .endObject ();
601
657
jsonReader .close ();
602
658
fileReader .close ();
@@ -619,7 +675,8 @@ public static ResourceConfiguration deserialize(final Path file) throws SirixIOE
619
675
.storeDiffs (storeDiffs )
620
676
.storeChildCount (storeChildCount )
621
677
.customCommitTimestamps (customCommitTimestamps )
622
- .storeNodeHistory (storeNodeHistory );
678
+ .storeNodeHistory (storeNodeHistory )
679
+ .awsStoreInfo (awsStoreInfo );
623
680
624
681
// Deserialized instance.
625
682
final ResourceConfiguration config = new ResourceConfiguration (builder );
@@ -713,6 +770,8 @@ public static final class Builder {
713
770
714
771
private BinaryEncodingVersion binaryEncodingVersion = BINARY_ENCODING_VERSION ;
715
772
773
+ private AWSStorageInformation awsStoreInfo ;
774
+
716
775
/**
717
776
* Constructor, setting the mandatory fields.
718
777
*
@@ -880,6 +939,12 @@ public Builder binaryEncodingVersion(BinaryEncodingVersion binaryEncodingVersion
880
939
return this ;
881
940
}
882
941
942
+ /*Since this is an optional config parameter, null check is not needed*/
943
+ public Builder awsStoreInfo (final AWSStorageInformation awsStoreInfo ) {
944
+ this .awsStoreInfo = awsStoreInfo ;
945
+ return this ;
946
+ }
947
+
883
948
@ Override
884
949
public String toString () {
885
950
return MoreObjects .toStringHelper (this )
0 commit comments