/
PriamConfiguration.java
744 lines (604 loc) · 21.3 KB
/
PriamConfiguration.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
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
/*
* Copyright 2018 Netflix, Inc.
*
* 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 com.netflix.priam.config;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.netflix.priam.configSource.IConfigSource;
import com.netflix.priam.identity.config.InstanceInfo;
import com.netflix.priam.scheduler.UnsupportedTypeException;
import com.netflix.priam.tuner.GCType;
import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Singleton
public class PriamConfiguration implements IConfiguration {
public static final String PRIAM_PRE = "priam";
private final IConfigSource config;
private static final Logger logger = LoggerFactory.getLogger(PriamConfiguration.class);
@JsonIgnore private InstanceInfo instanceInfo;
@Inject
public PriamConfiguration(IConfigSource config, InstanceInfo instanceInfo) {
this.config = config;
this.instanceInfo = instanceInfo;
}
@Override
public void initialize() {
this.config.initialize(instanceInfo.getAutoScalingGroup(), instanceInfo.getRegion());
}
@Override
public String getCassStartupScript() {
return config.get(PRIAM_PRE + ".cass.startscript", "/etc/init.d/cassandra start");
}
@Override
public String getCassStopScript() {
return config.get(PRIAM_PRE + ".cass.stopscript", "/etc/init.d/cassandra stop");
}
@Override
public int getGracefulDrainHealthWaitSeconds() {
return -1;
}
@Override
public int getRemediateDeadCassandraRate() {
return config.get(
PRIAM_PRE + ".remediate.dead.cassandra.rate", 3600); // Default to once per hour
}
@Override
public String getCassHome() {
return config.get(PRIAM_PRE + ".cass.home", "/etc/cassandra");
}
@Override
public String getBackupLocation() {
return config.get(PRIAM_PRE + ".s3.base_dir", "backup");
}
@Override
public String getBackupPrefix() {
return config.get(PRIAM_PRE + ".s3.bucket", "cassandra-archive");
}
@Override
public int getBackupRetentionDays() {
return config.get(PRIAM_PRE + ".backup.retention", 0);
}
@Override
public List<String> getBackupRacs() {
return config.getList(PRIAM_PRE + ".backup.racs");
}
@Override
public String getRestorePrefix() {
return config.get(PRIAM_PRE + ".restore.prefix");
}
@Override
public String getDataFileLocation() {
return config.get(PRIAM_PRE + ".data.location", getCassandraBaseDirectory() + "/data");
}
@Override
public String getLogDirLocation() {
return config.get(PRIAM_PRE + ".logs.location", getCassandraBaseDirectory() + "/logs");
}
@Override
public String getHintsLocation() {
return config.get(PRIAM_PRE + ".hints.location", getCassandraBaseDirectory() + "/hints");
}
@Override
public String getCacheLocation() {
return config.get(
PRIAM_PRE + ".cache.location", getCassandraBaseDirectory() + "/saved_caches");
}
@Override
public String getCommitLogLocation() {
return config.get(
PRIAM_PRE + ".commitlog.location", getCassandraBaseDirectory() + "/commitlog");
}
@Override
public String getBackupCommitLogLocation() {
return config.get(PRIAM_PRE + ".backup.commitlog.location", "");
}
@Override
public long getBackupChunkSize() {
long size = config.get(PRIAM_PRE + ".backup.chunksizemb", 10);
return size * 1024 * 1024L;
}
@Override
public int getJmxPort() {
return config.get(PRIAM_PRE + ".jmx.port", 7199);
}
@Override
public String getJmxUsername() {
return config.get(PRIAM_PRE + ".jmx.username", "");
}
@Override
public String getJmxPassword() {
return config.get(PRIAM_PRE + ".jmx.password", "");
}
/** @return Enables Remote JMX connections n C* */
@Override
public boolean enableRemoteJMX() {
return config.get(PRIAM_PRE + ".jmx.remote.enable", false);
}
public int getNativeTransportPort() {
return config.get(PRIAM_PRE + ".nativeTransport.port", 9042);
}
@Override
public int getStoragePort() {
return config.get(PRIAM_PRE + ".storage.port", 7000);
}
@Override
public int getSSLStoragePort() {
return config.get(PRIAM_PRE + ".ssl.storage.port", 7001);
}
@Override
public String getSnitch() {
return config.get(PRIAM_PRE + ".endpoint_snitch", "org.apache.cassandra.locator.Ec2Snitch");
}
@Override
public String getAppName() {
return config.get(PRIAM_PRE + ".clustername", "cass_cluster");
}
@Override
public List<String> getRacs() {
return config.getList(PRIAM_PRE + ".zones.available", instanceInfo.getDefaultRacks());
}
@Override
public String getHeapSize() {
return config.get((PRIAM_PRE + ".heap.size.") + instanceInfo.getInstanceType(), "8G");
}
@Override
public String getHeapNewSize() {
return config.get(
(PRIAM_PRE + ".heap.newgen.size.") + instanceInfo.getInstanceType(), "2G");
}
@Override
public String getMaxDirectMemory() {
return config.get(
(PRIAM_PRE + ".direct.memory.size.") + instanceInfo.getInstanceType(), "50G");
}
@Override
public GCType getGCType() throws UnsupportedTypeException {
String gcType = config.get(PRIAM_PRE + ".gc.type", GCType.CMS.getGcType());
return GCType.lookup(gcType);
}
@Override
public String getJVMExcludeSet() {
return config.get(PRIAM_PRE + ".jvm.options.exclude");
}
@Override
public String getJVMUpsertSet() {
return config.get(PRIAM_PRE + ".jvm.options.upsert");
}
@Override
public String getJVMInjectSet() {
return config.get(PRIAM_PRE + ".jvm.options.inject");
}
@Override
public String getFlushCronExpression() {
return config.get(PRIAM_PRE + ".flush.cron", "-1");
}
@Override
public String getCompactionCronExpression() {
return config.get(PRIAM_PRE + ".compaction.cron", "-1");
}
@Override
public String getCompactionIncludeCFList() {
return config.get(PRIAM_PRE + ".compaction.cf.include");
}
@Override
public String getCompactionExcludeCFList() {
return config.get(PRIAM_PRE + ".compaction.cf.exclude");
}
@Override
public String getSnapshotIncludeCFList() {
return config.get(PRIAM_PRE + ".snapshot.cf.include");
}
@Override
public String getSnapshotExcludeCFList() {
return config.get(PRIAM_PRE + ".snapshot.cf.exclude");
}
@Override
public String getIncrementalIncludeCFList() {
return config.get(PRIAM_PRE + ".incremental.cf.include");
}
@Override
public String getIncrementalExcludeCFList() {
return config.get(PRIAM_PRE + ".incremental.cf.exclude");
}
@Override
public String getRestoreIncludeCFList() {
return config.get(PRIAM_PRE + ".restore.cf.include");
}
@Override
public String getRestoreExcludeCFList() {
return config.get(PRIAM_PRE + ".restore.cf.exclude");
}
@Override
public String getRestoreSnapshot() {
return config.get(PRIAM_PRE + ".restore.snapshot", "");
}
@Override
public boolean isRestoreEncrypted() {
return config.get(PRIAM_PRE + ".encrypted.restore.enabled", false);
}
@Override
public String getSDBInstanceIdentityRegion() {
return config.get(PRIAM_PRE + ".sdb.instanceIdentity.region", "us-east-1");
}
@Override
public boolean isMultiDC() {
return config.get(PRIAM_PRE + ".multiregion.enable", false);
}
@Override
public int getBackupThreads() {
return config.get(PRIAM_PRE + ".backup.threads", 2);
}
@Override
public int getRestoreThreads() {
return config.get(PRIAM_PRE + ".restore.threads", 8);
}
@Override
public boolean isRestoreClosestToken() {
return config.get(PRIAM_PRE + ".restore.closesttoken", false);
}
@Override
public String getSiblingASGNames() {
return config.get(PRIAM_PRE + ".az.sibling.asgnames", ",");
}
@Override
public String getACLGroupName() {
return config.get(PRIAM_PRE + ".acl.groupname", this.getAppName());
}
@Override
public boolean isIncrementalBackupEnabled() {
return config.get(PRIAM_PRE + ".backup.incremental.enable", true);
}
@Override
public int getUploadThrottle() {
return config.get(PRIAM_PRE + ".upload.throttle", -1);
}
@Override
public int getRemoteFileSystemObjectExistsThrottle() {
return config.get(PRIAM_PRE + ".remoteFileSystemObjectExistThrottle", -1);
}
@Override
public boolean isLocalBootstrapEnabled() {
return config.get(PRIAM_PRE + ".localbootstrap.enable", false);
}
@Override
public int getCompactionThroughput() {
return config.get(PRIAM_PRE + ".compaction.throughput", 8);
}
@Override
public int getMaxHintWindowInMS() {
return config.get(PRIAM_PRE + ".hint.window", 10800000);
}
public int getHintedHandoffThrottleKb() {
return config.get(PRIAM_PRE + ".hints.throttleKb", 1024);
}
@Override
public String getBootClusterName() {
return config.get(PRIAM_PRE + ".bootcluster", "");
}
@Override
public String getSeedProviderName() {
return config.get(
PRIAM_PRE + ".seed.provider",
"com.netflix.priam.cassandra.extensions.NFSeedProvider");
}
public double getMemtableCleanupThreshold() {
return config.get(PRIAM_PRE + ".memtable.cleanup.threshold", 0.11);
}
@Override
public int getStreamingThroughputMB() {
return config.get(PRIAM_PRE + ".streaming.throughput.mb", 400);
}
public String getPartitioner() {
return config.get(PRIAM_PRE + ".partitioner", "org.apache.cassandra.dht.RandomPartitioner");
}
public String getKeyCacheSizeInMB() {
return config.get(PRIAM_PRE + ".keyCache.size");
}
public String getKeyCacheKeysToSave() {
return config.get(PRIAM_PRE + ".keyCache.count");
}
public String getRowCacheSizeInMB() {
return config.get(PRIAM_PRE + ".rowCache.size");
}
public String getRowCacheKeysToSave() {
return config.get(PRIAM_PRE + ".rowCache.count");
}
@Override
public String getCassProcessName() {
return config.get(PRIAM_PRE + ".cass.process", "CassandraDaemon");
}
public String getYamlLocation() {
return config.get(PRIAM_PRE + ".yamlLocation", getCassHome() + "/conf/cassandra.yaml");
}
@Override
public String getJVMOptionsFileLocation() {
return config.get(
PRIAM_PRE + ".jvm.options.location", getCassHome() + "/conf/jvm-server.options");
}
public String getAuthenticator() {
return config.get(
PRIAM_PRE + ".authenticator", "org.apache.cassandra.auth.AllowAllAuthenticator");
}
public String getAuthorizer() {
return config.get(
PRIAM_PRE + ".authorizer", "org.apache.cassandra.auth.AllowAllAuthorizer");
}
public String getRoleManager() {
return config.get(
PRIAM_PRE + ".roleManager", "org.apache.cassandra.auth.CassandraRoleManager");
}
@Override
public boolean doesCassandraStartManually() {
return config.get(PRIAM_PRE + ".cass.manual.start.enable", false);
}
public String getInternodeCompression() {
return config.get(PRIAM_PRE + ".internodeCompression", "all");
}
public boolean isClientSslEnabled() {
return config.get(PRIAM_PRE + ".client.sslEnabled", false);
}
public String getInternodeEncryption() {
return config.get(PRIAM_PRE + ".internodeEncryption", "none");
}
public boolean isDynamicSnitchEnabled() {
return config.get(PRIAM_PRE + ".dsnitchEnabled", true);
}
public boolean isNativeTransportEnabled() {
return config.get(PRIAM_PRE + ".nativeTransport.enabled", false);
}
public int getConcurrentReadsCnt() {
return config.get(PRIAM_PRE + ".concurrentReads", 32);
}
public int getConcurrentWritesCnt() {
return config.get(PRIAM_PRE + ".concurrentWrites", 32);
}
public int getConcurrentCompactorsCnt() {
int cpus = Runtime.getRuntime().availableProcessors();
return config.get(PRIAM_PRE + ".concurrentCompactors", cpus);
}
@Override
public int getCompactionLargePartitionWarnThresholdInMB() {
return config.get(PRIAM_PRE + ".compaction.large.partition.warn.threshold", 100);
}
public String getExtraConfigParams() {
return config.get(PRIAM_PRE + ".extra.params");
}
@Override
public Map<String, String> getExtraEnvParams() {
String envParams = config.get(PRIAM_PRE + ".extra.env.params");
if (envParams == null) {
logger.info("getExtraEnvParams: No extra env params");
return null;
}
Map<String, String> extraEnvParamsMap = new HashMap<>();
String[] pairs = envParams.split(",");
logger.info("getExtraEnvParams: Extra cass params. From config :{}", envParams);
for (String pair1 : pairs) {
String[] pair = pair1.split("=");
if (pair.length > 1) {
String priamKey = pair[0];
String cassKey = pair[1];
String cassVal = config.get(priamKey);
logger.info(
"getExtraEnvParams: Start-up/ env params: Priamkey[{}], CassStartupKey[{}], Val[{}]",
priamKey,
cassKey,
cassVal);
if (!StringUtils.isBlank(cassKey) && !StringUtils.isBlank(cassVal)) {
extraEnvParamsMap.put(cassKey, cassVal);
}
}
}
return extraEnvParamsMap;
}
public String getCassYamlVal(String priamKey) {
return config.get(priamKey);
}
public boolean getAutoBoostrap() {
return config.get(PRIAM_PRE + ".auto.bootstrap", true);
}
@Override
public boolean isCreateNewTokenEnable() {
return config.get(PRIAM_PRE + ".create.new.token.enable", true);
}
@Override
public String getPrivateKeyLocation() {
return config.get(PRIAM_PRE + ".private.key.location");
}
@Override
public String getRestoreSourceType() {
return config.get(PRIAM_PRE + ".restore.source.type");
}
@Override
public boolean isEncryptBackupEnabled() {
return config.get(PRIAM_PRE + ".encrypted.backup.enabled", false);
}
@Override
public String getAWSRoleAssumptionArn() {
return config.get(PRIAM_PRE + ".roleassumption.arn");
}
@Override
public String getClassicEC2RoleAssumptionArn() {
return config.get(PRIAM_PRE + ".ec2.roleassumption.arn");
}
@Override
public String getVpcEC2RoleAssumptionArn() {
return config.get(PRIAM_PRE + ".vpc.roleassumption.arn");
}
@Override
public boolean isDualAccount() {
return config.get(PRIAM_PRE + ".roleassumption.dualaccount", false);
}
@Override
public String getGcsServiceAccountId() {
return config.get(PRIAM_PRE + ".gcs.service.acct.id");
}
@Override
public String getGcsServiceAccountPrivateKeyLoc() {
return config.get(
PRIAM_PRE + ".gcs.service.acct.private.key",
"/apps/tomcat/conf/gcsentryptedkey.p12");
}
@Override
public String getPgpPasswordPhrase() {
return config.get(PRIAM_PRE + ".pgp.password.phrase");
}
@Override
public String getPgpPublicKeyLoc() {
return config.get(PRIAM_PRE + ".pgp.pubkey.file.location");
}
@Override
public boolean enableAsyncIncremental() {
return config.get(PRIAM_PRE + ".async.incremental", false);
}
@Override
public boolean enableAsyncSnapshot() {
return config.get(PRIAM_PRE + ".async.snapshot", false);
}
@Override
public int getBackupQueueSize() {
return config.get(PRIAM_PRE + ".backup.queue.size", 100000);
}
@Override
public int getDownloadQueueSize() {
return config.get(PRIAM_PRE + ".download.queue.size", 100000);
}
@Override
public long getUploadTimeout() {
return config.get(PRIAM_PRE + ".upload.timeout", (2 * 60 * 60 * 1000L));
}
public long getDownloadTimeout() {
return config.get(PRIAM_PRE + ".download.timeout", (10 * 60 * 60 * 1000L));
}
@Override
public int getTombstoneWarnThreshold() {
return config.get(PRIAM_PRE + ".tombstone.warning.threshold", 1000);
}
@Override
public int getTombstoneFailureThreshold() {
return config.get(PRIAM_PRE + ".tombstone.failure.threshold", 100000);
}
@Override
public int getStreamingKeepAlivePeriod() {
return config.get(PRIAM_PRE + ".streaming.socket.keepalive.s", 300);
}
@Override
public String getFlushKeyspaces() {
return config.get(PRIAM_PRE + ".flush.keyspaces");
}
@Override
public String getBackupStatusFileLoc() {
return config.get(
PRIAM_PRE + ".backup.status.location",
getDataFileLocation() + File.separator + "backup.status");
}
@Override
public boolean useSudo() {
return config.get(PRIAM_PRE + ".cass.usesudo", true);
}
@Override
public boolean enableBackupNotification() {
return config.get(PRIAM_PRE + ".enableBackupNotification", true);
}
@Override
public String getBackupNotificationTopicArn() {
return config.get(PRIAM_PRE + ".backup.notification.topic.arn", "");
}
@Override
public boolean isPostRestoreHookEnabled() {
return config.get(PRIAM_PRE + ".postrestorehook.enabled", false);
}
@Override
public String getPostRestoreHook() {
return config.get(PRIAM_PRE + ".postrestorehook");
}
@Override
public String getPostRestoreHookHeartbeatFileName() {
return config.get(
PRIAM_PRE + ".postrestorehook.heartbeat.filename",
getDataFileLocation() + File.separator + "postrestorehook_heartbeat");
}
@Override
public String getPostRestoreHookDoneFileName() {
return config.get(
PRIAM_PRE + ".postrestorehook.done.filename",
getDataFileLocation() + File.separator + "postrestorehook_done");
}
@Override
public int getPostRestoreHookTimeOutInDays() {
return config.get(PRIAM_PRE + ".postrestorehook.timeout.in.days", 2);
}
@Override
public int getPostRestoreHookHeartBeatTimeoutInMs() {
return config.get(PRIAM_PRE + ".postrestorehook.heartbeat.timeout", 120000);
}
@Override
public int getPostRestoreHookHeartbeatCheckFrequencyInMs() {
return config.get(PRIAM_PRE + ".postrestorehook.heartbeat.check.frequency", 120000);
}
@Override
public String getProperty(String key, String defaultValue) {
return config.get(key, defaultValue);
}
@Override
public String getMergedConfigurationCronExpression() {
// Every minute on the top of the minute.
return config.get(PRIAM_PRE + ".configMerge.cron", "0 * * * * ? *");
}
@Override
public int getGracePeriodDaysForCompaction() {
return config.get(PRIAM_PRE + ".gracePeriodDaysForCompaction", 5);
}
@Override
public int getForgottenFileGracePeriodDaysForRead() {
return config.get(PRIAM_PRE + ".forgottenFileGracePeriodDaysForRead", 3);
}
@Override
public boolean isForgottenFileMoveEnabled() {
return config.get(PRIAM_PRE + ".forgottenFileMoveEnabled", false);
}
@Override
public BackupsToCompress getBackupsToCompress() {
return BackupsToCompress.valueOf(
config.get("priam.backupsToCompress", BackupsToCompress.ALL.name()));
}
@Override
public String getDiskAccessMode() {
return config.get(PRIAM_PRE + ".diskAccessMode", "auto");
}
@Override
public boolean permitDirectTokenAssignmentWithGossipMismatch() {
return config.get(PRIAM_PRE + ".permitDirectTokenAssignmentWithGossipMismatch", false);
}
@Override
public int getTargetMinutesToCompleteSnaphotUpload() {
return config.get(PRIAM_PRE + ".snapshotUploadDuration", 0);
}
@Override
public double getRateLimitChangeThreshold() {
return config.get(PRIAM_PRE + ".rateLimitChangeThreshold", 0.1);
}
@Override
public boolean getAutoSnapshot() {
return config.get(PRIAM_PRE + ".autoSnapshot", false);
}
}