forked from trinodb/trino
/
HiveS3Config.java
496 lines (427 loc) · 13.2 KB
/
HiveS3Config.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.trino.plugin.hive.s3;
import com.google.common.base.StandardSystemProperty;
import io.airlift.configuration.Config;
import io.airlift.configuration.ConfigDescription;
import io.airlift.configuration.ConfigSecuritySensitive;
import io.airlift.configuration.DefunctConfig;
import io.airlift.configuration.validation.FileExists;
import io.airlift.units.DataSize;
import io.airlift.units.Duration;
import io.airlift.units.MaxDataSize;
import io.airlift.units.MinDataSize;
import io.airlift.units.MinDuration;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.io.File;
import java.util.concurrent.TimeUnit;
import static io.airlift.units.DataSize.Unit.MEGABYTE;
@DefunctConfig("hive.s3.use-instance-credentials")
public class HiveS3Config
{
private String s3AwsAccessKey;
private String s3AwsSecretKey;
private String s3Endpoint;
private TrinoS3StorageClass s3StorageClass = TrinoS3StorageClass.STANDARD;
private TrinoS3SignerType s3SignerType;
private String s3SignerClass;
private boolean s3PathStyleAccess;
private String s3IamRole;
private String s3ExternalId;
private boolean s3SslEnabled = true;
private boolean s3SseEnabled;
private TrinoS3SseType s3SseType = TrinoS3SseType.S3;
private String s3EncryptionMaterialsProvider;
private String s3KmsKeyId;
private String s3SseKmsKeyId;
private int s3MaxClientRetries = 5;
private int s3MaxErrorRetries = 10;
private Duration s3MaxBackoffTime = new Duration(10, TimeUnit.MINUTES);
private Duration s3MaxRetryTime = new Duration(10, TimeUnit.MINUTES);
private Duration s3ConnectTimeout = new Duration(5, TimeUnit.SECONDS);
private Duration s3SocketTimeout = new Duration(5, TimeUnit.SECONDS);
private int s3MaxConnections = 500;
private File s3StagingDirectory = new File(StandardSystemProperty.JAVA_IO_TMPDIR.value());
private DataSize s3MultipartMinFileSize = DataSize.of(16, MEGABYTE);
private DataSize s3MultipartMinPartSize = DataSize.of(5, MEGABYTE);
private boolean pinS3ClientToCurrentRegion;
private String s3UserAgentPrefix = "";
private TrinoS3AclType s3AclType = TrinoS3AclType.PRIVATE;
private boolean skipGlacierObjects;
private boolean requesterPaysEnabled;
private boolean s3StreamingUploadEnabled = true;
private DataSize s3StreamingPartSize = DataSize.of(16, MEGABYTE);
public String getS3AwsAccessKey()
{
return s3AwsAccessKey;
}
@Config("hive.s3.aws-access-key")
public HiveS3Config setS3AwsAccessKey(String s3AwsAccessKey)
{
this.s3AwsAccessKey = s3AwsAccessKey;
return this;
}
public String getS3AwsSecretKey()
{
return s3AwsSecretKey;
}
@Config("hive.s3.aws-secret-key")
@ConfigSecuritySensitive
public HiveS3Config setS3AwsSecretKey(String s3AwsSecretKey)
{
this.s3AwsSecretKey = s3AwsSecretKey;
return this;
}
public String getS3Endpoint()
{
return s3Endpoint;
}
@Config("hive.s3.endpoint")
public HiveS3Config setS3Endpoint(String s3Endpoint)
{
this.s3Endpoint = s3Endpoint;
return this;
}
@NotNull
public TrinoS3StorageClass getS3StorageClass()
{
return s3StorageClass;
}
@Config("hive.s3.storage-class")
@ConfigDescription("AWS S3 storage class to use when writing the data")
public HiveS3Config setS3StorageClass(TrinoS3StorageClass s3StorageClass)
{
this.s3StorageClass = s3StorageClass;
return this;
}
public TrinoS3SignerType getS3SignerType()
{
return s3SignerType;
}
@Config("hive.s3.signer-type")
public HiveS3Config setS3SignerType(TrinoS3SignerType s3SignerType)
{
this.s3SignerType = s3SignerType;
return this;
}
public String getS3SignerClass()
{
return s3SignerClass;
}
@Config("hive.s3.signer-class")
public HiveS3Config setS3SignerClass(String s3SignerClass)
{
this.s3SignerClass = s3SignerClass;
return this;
}
public boolean isS3PathStyleAccess()
{
return s3PathStyleAccess;
}
@Config("hive.s3.path-style-access")
@ConfigDescription("Use path-style access for all request to S3")
public HiveS3Config setS3PathStyleAccess(boolean s3PathStyleAccess)
{
this.s3PathStyleAccess = s3PathStyleAccess;
return this;
}
public String getS3IamRole()
{
return s3IamRole;
}
@Config("hive.s3.iam-role")
@ConfigDescription("ARN of an IAM role to assume when connecting to S3")
public HiveS3Config setS3IamRole(String s3IamRole)
{
this.s3IamRole = s3IamRole;
return this;
}
public String getS3ExternalId()
{
return s3ExternalId;
}
@Config("hive.s3.external-id")
@ConfigDescription("External ID for the IAM role trust policy when connecting to S3")
public HiveS3Config setS3ExternalId(String s3ExternalId)
{
this.s3ExternalId = s3ExternalId;
return this;
}
public boolean isS3SslEnabled()
{
return s3SslEnabled;
}
@Config("hive.s3.ssl.enabled")
public HiveS3Config setS3SslEnabled(boolean s3SslEnabled)
{
this.s3SslEnabled = s3SslEnabled;
return this;
}
public String getS3EncryptionMaterialsProvider()
{
return s3EncryptionMaterialsProvider;
}
@Config("hive.s3.encryption-materials-provider")
@ConfigDescription("Use a custom encryption materials provider for S3 data encryption")
public HiveS3Config setS3EncryptionMaterialsProvider(String s3EncryptionMaterialsProvider)
{
this.s3EncryptionMaterialsProvider = s3EncryptionMaterialsProvider;
return this;
}
public String getS3KmsKeyId()
{
return s3KmsKeyId;
}
@Config("hive.s3.kms-key-id")
@ConfigDescription("Use an AWS KMS key for S3 data encryption")
public HiveS3Config setS3KmsKeyId(String s3KmsKeyId)
{
this.s3KmsKeyId = s3KmsKeyId;
return this;
}
public String getS3SseKmsKeyId()
{
return s3SseKmsKeyId;
}
@Config("hive.s3.sse.kms-key-id")
@ConfigDescription("KMS Key ID to use for S3 server-side encryption with KMS-managed key")
public HiveS3Config setS3SseKmsKeyId(String s3SseKmsKeyId)
{
this.s3SseKmsKeyId = s3SseKmsKeyId;
return this;
}
public boolean isS3SseEnabled()
{
return s3SseEnabled;
}
@Config("hive.s3.sse.enabled")
@ConfigDescription("Enable S3 server side encryption")
public HiveS3Config setS3SseEnabled(boolean s3SseEnabled)
{
this.s3SseEnabled = s3SseEnabled;
return this;
}
@NotNull
public TrinoS3SseType getS3SseType()
{
return s3SseType;
}
@Config("hive.s3.sse.type")
@ConfigDescription("Key management type for S3 server-side encryption (S3 or KMS)")
public HiveS3Config setS3SseType(TrinoS3SseType s3SseType)
{
this.s3SseType = s3SseType;
return this;
}
@Min(0)
public int getS3MaxClientRetries()
{
return s3MaxClientRetries;
}
@Config("hive.s3.max-client-retries")
public HiveS3Config setS3MaxClientRetries(int s3MaxClientRetries)
{
this.s3MaxClientRetries = s3MaxClientRetries;
return this;
}
@Min(0)
public int getS3MaxErrorRetries()
{
return s3MaxErrorRetries;
}
@Config("hive.s3.max-error-retries")
public HiveS3Config setS3MaxErrorRetries(int s3MaxErrorRetries)
{
this.s3MaxErrorRetries = s3MaxErrorRetries;
return this;
}
@MinDuration("1s")
@NotNull
public Duration getS3MaxBackoffTime()
{
return s3MaxBackoffTime;
}
@Config("hive.s3.max-backoff-time")
public HiveS3Config setS3MaxBackoffTime(Duration s3MaxBackoffTime)
{
this.s3MaxBackoffTime = s3MaxBackoffTime;
return this;
}
@MinDuration("1ms")
@NotNull
public Duration getS3MaxRetryTime()
{
return s3MaxRetryTime;
}
@Config("hive.s3.max-retry-time")
public HiveS3Config setS3MaxRetryTime(Duration s3MaxRetryTime)
{
this.s3MaxRetryTime = s3MaxRetryTime;
return this;
}
@MinDuration("1ms")
@NotNull
public Duration getS3ConnectTimeout()
{
return s3ConnectTimeout;
}
@Config("hive.s3.connect-timeout")
public HiveS3Config setS3ConnectTimeout(Duration s3ConnectTimeout)
{
this.s3ConnectTimeout = s3ConnectTimeout;
return this;
}
@MinDuration("1ms")
@NotNull
public Duration getS3SocketTimeout()
{
return s3SocketTimeout;
}
@Config("hive.s3.socket-timeout")
public HiveS3Config setS3SocketTimeout(Duration s3SocketTimeout)
{
this.s3SocketTimeout = s3SocketTimeout;
return this;
}
@Min(1)
public int getS3MaxConnections()
{
return s3MaxConnections;
}
@Config("hive.s3.max-connections")
public HiveS3Config setS3MaxConnections(int s3MaxConnections)
{
this.s3MaxConnections = s3MaxConnections;
return this;
}
@NotNull
@FileExists
public File getS3StagingDirectory()
{
return s3StagingDirectory;
}
@Config("hive.s3.staging-directory")
@ConfigDescription("Temporary directory for staging files before uploading to S3")
public HiveS3Config setS3StagingDirectory(File s3StagingDirectory)
{
this.s3StagingDirectory = s3StagingDirectory;
return this;
}
@NotNull
@MinDataSize("16MB")
public DataSize getS3MultipartMinFileSize()
{
return s3MultipartMinFileSize;
}
@Config("hive.s3.multipart.min-file-size")
@ConfigDescription("Minimum file size for an S3 multipart upload")
public HiveS3Config setS3MultipartMinFileSize(DataSize size)
{
this.s3MultipartMinFileSize = size;
return this;
}
@NotNull
@MinDataSize("5MB")
public DataSize getS3MultipartMinPartSize()
{
return s3MultipartMinPartSize;
}
@Config("hive.s3.multipart.min-part-size")
@ConfigDescription("Minimum part size for an S3 multipart upload")
public HiveS3Config setS3MultipartMinPartSize(DataSize size)
{
this.s3MultipartMinPartSize = size;
return this;
}
public boolean isPinS3ClientToCurrentRegion()
{
return pinS3ClientToCurrentRegion;
}
@Config("hive.s3.pin-client-to-current-region")
@ConfigDescription("Should the S3 client be pinned to the current EC2 region")
public HiveS3Config setPinS3ClientToCurrentRegion(boolean pinS3ClientToCurrentRegion)
{
this.pinS3ClientToCurrentRegion = pinS3ClientToCurrentRegion;
return this;
}
@NotNull
public String getS3UserAgentPrefix()
{
return s3UserAgentPrefix;
}
@Config("hive.s3.user-agent-prefix")
@ConfigDescription("The user agent prefix to use for S3 calls")
public HiveS3Config setS3UserAgentPrefix(String s3UserAgentPrefix)
{
this.s3UserAgentPrefix = s3UserAgentPrefix;
return this;
}
@NotNull
public TrinoS3AclType getS3AclType()
{
return s3AclType;
}
@Config("hive.s3.upload-acl-type")
@ConfigDescription("Canned ACL type for S3 uploads")
public HiveS3Config setS3AclType(TrinoS3AclType s3AclType)
{
this.s3AclType = s3AclType;
return this;
}
public boolean isSkipGlacierObjects()
{
return skipGlacierObjects;
}
@Config("hive.s3.skip-glacier-objects")
public HiveS3Config setSkipGlacierObjects(boolean skipGlacierObjects)
{
this.skipGlacierObjects = skipGlacierObjects;
return this;
}
public boolean isRequesterPaysEnabled()
{
return requesterPaysEnabled;
}
@Config("hive.s3.requester-pays.enabled")
public HiveS3Config setRequesterPaysEnabled(boolean requesterPaysEnabled)
{
this.requesterPaysEnabled = requesterPaysEnabled;
return this;
}
public boolean isS3StreamingUploadEnabled()
{
return s3StreamingUploadEnabled;
}
@Config("hive.s3.streaming.enabled")
public HiveS3Config setS3StreamingUploadEnabled(boolean s3StreamingUploadEnabled)
{
this.s3StreamingUploadEnabled = s3StreamingUploadEnabled;
return this;
}
@NotNull
@MinDataSize("5MB")
@MaxDataSize("256MB")
public DataSize getS3StreamingPartSize()
{
return s3StreamingPartSize;
}
@Config("hive.s3.streaming.part-size")
@ConfigDescription("Part size for S3 streaming upload")
public HiveS3Config setS3StreamingPartSize(DataSize s3StreamingPartSize)
{
this.s3StreamingPartSize = s3StreamingPartSize;
return this;
}
}