StandardTuner implements ICassandraTuner { @SuppressWarnings("unchecked") public void writeAllProperties(String yamlLocation, String hostname, String seedProvider) throws Exception { DumperOptions options = new DumperOptions(); options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); Yaml yaml = new Yaml(options); File yamlFile = new File(yamlLocation); Map map = yaml.load(new FileInputStream(yamlFile)); map.put("cluster_name", config.getAppName()); map.put("storage_port", config.getStoragePort()); map.put("ssl_storage_port", config.getSSLStoragePort()); map.put("start_rpc", config.isThriftEnabled()); map.put("rpc_port", config.getThriftPort()); map.put("start_native_transport", config.isNativeTransportEnabled()); map.put("native_transport_port", config.getNativeTransportPort()); map.put("listen_address", hostname); map.put("rpc_address", hostname); if (!Restore.isRestoreEnabled(config, instanceInfo)) { map.put("auto_bootstrap", config.getAutoBoostrap()); } else { map.put("auto_bootstrap", false); } map.put("saved_caches_directory", config.getCacheLocation()); map.put("commitlog_directory", config.getCommitLogLocation()); map.put("data_file_directories", Lists.newArrayList(config.getDataFileLocation())); boolean enableIncremental = IncrementalBackup.isEnabled(config, backupRestoreConfig); map.put("incremental_backups", enableIncremental); map.put("endpoint_snitch", config.getSnitch()); if (map.containsKey("in_memory_compaction_limit_in_mb")) { map.remove("in_memory_compaction_limit_in_mb"); } map.put("compaction_throughput_mb_per_sec", config.getCompactionThroughput()); map.put( "partitioner", derivePartitioner(map.get("partitioner").toString(), config.getPartitioner())); if (map.containsKey("memtable_total_space_in_mb")) { map.remove("memtable_total_space_in_mb"); } map.put("stream_throughput_outbound_megabits_per_sec", config.getStreamingThroughputMB()); if (map.containsKey("multithreaded_compaction")) { map.remove("multithreaded_compaction"); } map.put("max_hint_window_in_ms", config.getMaxHintWindowInMS()); map.put("hinted_handoff_throttle_in_kb", config.getHintedHandoffThrottleKb()); map.put("authenticator", config.getAuthenticator()); map.put("authorizer", config.getAuthorizer()); map.put("internode_compression", config.getInternodeCompression()); map.put("dynamic_snitch", config.isDynamicSnitchEnabled()); map.put("concurrent_reads", config.getConcurrentReadsCnt()); map.put("concurrent_writes", config.getConcurrentWritesCnt()); map.put("concurrent_compactors", config.getConcurrentCompactorsCnt()); map.put("rpc_server_type", config.getRpcServerType()); map.put("rpc_min_threads", config.getRpcMinThreads()); map.put("rpc_max_threads", config.getRpcMaxThreads()); map.put("broadcast_rpc_address", instanceInfo.getPrivateIP()); map.put("tombstone_warn_threshold", config.getTombstoneWarnThreshold()); map.put("tombstone_failure_threshold", config.getTombstoneFailureThreshold()); map.put("streaming_socket_timeout_in_ms", config.getStreamingSocketTimeoutInMS()); map.put("memtable_cleanup_threshold", config.getMemtableCleanupThreshold()); map.put( "compaction_large_partition_warning_threshold_mb", config.getCompactionLargePartitionWarnThresholdInMB()); List<?> seedp = (List) map.get("seed_provider"); Map<String, String> m = (Map<String, String>) seedp.get(0); m.put("class_name", seedProvider); configfureSecurity(map); configureGlobalCaches(config, map); map.put("num_tokens", 1); addExtraCassParams(map); addCustomCassParams(map); map.remove("flush_largest_memtables_at"); map.remove("reduce_cache_capacity_to"); logger.info(yaml.dump(map)); yaml.dump(map, new FileWriter(yamlFile)); configureCommitLogBackups(); PropertiesFileTuner propertyTuner = new PropertiesFileTuner(config); for (String propertyFile : config.getTunablePropertyFiles()) { propertyTuner.updateAndSaveProperties(propertyFile); } } @Inject  StandardTuner(
            IConfiguration config,
            IBackupRestoreConfig backupRestoreConfig,
            InstanceInfo instanceInfo); @SuppressWarnings("unchecked") void writeAllProperties(String yamlLocation, String hostname, String seedProvider); void updateAutoBootstrap(String yamlFile, boolean autobootstrap); @Override final void updateJVMOptions(); void addExtraCassParams(Map map);  }
@Test public void dump() throws Exception { Files.copy(new File("src/main/resources/incr-restore-cassandra.yaml"), target); tuner.writeAllProperties(target.getAbsolutePath(), "your_host", "YourSeedProvider"); }
@Test public void addExtraParams() throws Exception { String cassParamName1 = "client_encryption_options.optional"; String priamKeyName1 = "Priam.client_encryption.optional"; String cassParamName2 = "client_encryption_options.keystore_password"; String priamKeyName2 = "Priam.client_encryption.keystore_password"; String cassParamName3 = "randomKey"; String priamKeyName3 = "Priam.randomKey"; String cassParamName4 = "randomGroup.randomKey"; String priamKeyName4 = "Priam.randomGroup.randomKey"; String extraConfigParam = String.format( "%s=%s,%s=%s,%s=%s,%s=%s", priamKeyName1, cassParamName1, priamKeyName2, cassParamName2, priamKeyName3, cassParamName3, priamKeyName4, cassParamName4); Map extraParamValues = new HashMap(); extraParamValues.put(priamKeyName1, true); extraParamValues.put(priamKeyName2, "test"); extraParamValues.put(priamKeyName3, "randomKeyValue"); extraParamValues.put(priamKeyName4, "randomGroupValue"); StandardTuner tuner = new StandardTuner( new TunerConfiguration(extraConfigParam, extraParamValues), backupRestoreConfig, instanceInfo); Files.copy(new File("src/main/resources/incr-restore-cassandra.yaml"), target); tuner.writeAllProperties(target.getAbsolutePath(), "your_host", "YourSeedProvider"); DumperOptions options = new DumperOptions(); options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); Yaml yaml = new Yaml(options); Map map = yaml.load(new FileInputStream(target)); Assert.assertEquals("your_host", map.get("listen_address")); Assert.assertEquals("true", ((Map) map.get("client_encryption_options")).get("optional")); Assert.assertEquals( "test", ((Map) map.get("client_encryption_options")).get("keystore_password")); Assert.assertEquals("randomKeyValue", map.get("randomKey")); Assert.assertEquals("randomGroupValue", ((Map) map.get("randomGroup")).get("randomKey")); }
@Test public void testPropertiesFiles() throws Exception { FakeConfiguration fake = (FakeConfiguration) config; File testRackDcFile = new File("src/test/resources/conf/cassandra-rackdc.properties"); File testYamlFile = new File("src/main/resources/incr-restore-cassandra.yaml"); String propertiesPath = new File(config.getYamlLocation()).getParentFile().getPath(); File rackDcFile = new File( Paths.get(propertiesPath, "cassandra-rackdc.properties") .normalize() .toString()); File configFile = new File(Paths.get(propertiesPath, "properties_test.yaml").normalize().toString()); System.out.println(testRackDcFile); System.out.println(rackDcFile); Files.copy(testRackDcFile, rackDcFile); Files.copy(testYamlFile, configFile); try { fake.fakeProperties.put( "propertyOverrides.cassandra-rackdc", "dc=${dc},rack=${rac},ec2_naming_scheme=legacy,dc_suffix=testsuffix"); tuner.writeAllProperties(configFile.getPath(), "your_host", "YourSeedProvider"); Properties prop = new Properties(); prop.load(new FileReader(rackDcFile)); assertEquals("us-east-1", prop.getProperty("dc")); assertEquals("my_zone", prop.getProperty("rack")); assertEquals("legacy", prop.getProperty("ec2_naming_scheme")); assertEquals("testsuffix", prop.getProperty("dc_suffix")); assertEquals(4, prop.stringPropertyNames().size()); } finally { fake.fakeProperties.clear(); for (String line : Files.readLines(rackDcFile, Charset.defaultCharset())) { System.out.println(line); } Files.copy(testRackDcFile, rackDcFile); Files.copy(testYamlFile, configFile); } }