From 26e71890d3317e7cdf837947d83b0471143ed3f2 Mon Sep 17 00:00:00 2001 From: mck Date: Fri, 23 Aug 2024 16:13:06 +0200 Subject: [PATCH] Artifacts.loadViaParser(..) should also (automatically) accept files with '.txt' suffixes --- .../montecristo/fileLoaders/Artifacts.kt | 37 ++++++++++++------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/montecristo/src/main/kotlin/com/datastax/montecristo/fileLoaders/Artifacts.kt b/montecristo/src/main/kotlin/com/datastax/montecristo/fileLoaders/Artifacts.kt index a219957..7cc163d 100644 --- a/montecristo/src/main/kotlin/com/datastax/montecristo/fileLoaders/Artifacts.kt +++ b/montecristo/src/main/kotlin/com/datastax/montecristo/fileLoaders/Artifacts.kt @@ -181,7 +181,7 @@ class Artifacts( if (jvmSettings.gcAlgorithm == GCAlgorithm.UNKNOWN) { val settingsFromOptions = getJvmSettingsFromOptions(fp.absolutePath) if (settingsFromOptions.isNotEmpty()) { - loadErrors.add(LoadError(hostname, "GC settings have been estimated from jvm-server.options and should be manually validated")) + loadErrors.add(LoadError(hostname, "GC settings have been estimated from jvm(-server)?.options and should be manually validated")) jvmSettings = JVMSettingsParser.parse(settingsFromOptions) } else { @@ -372,27 +372,32 @@ class Artifacts( } private fun getJvmSettingsFromOptions(searchDirectory: String): String { - logger.info("Attempting to reconstruct JVM settings from jvm-server.options...") + logger.info("Attempting to reconstruct JVM settings from jvm(-server)?.options...") var jvmSettingsList: List = listOf() val jvmFiles = FileHelpers.getFilesWithName(searchDirectory, "jvm(-server)?.options") if (jvmFiles.isNotEmpty()) { val jvmServerFiles = jvmFiles.filter { it.endsWith("jvm-server.options") } + val jvmFlags = if (jvmServerFiles.isNotEmpty()) { - jvmServerFiles.first().readLines().filter { !it.startsWith("#") && it.contains("-X") }.joinToString(" ") - } else { - jvmFiles.first().readLines().filter { !it.startsWith("#") && it.contains("-X") }.joinToString(" ") - } + jvmServerFiles.first().readLines().filter { !it.startsWith("#") && it.contains("-X") }.joinToString(" ") + } else { + jvmFiles.first().readLines().filter { !it.startsWith("#") && it.contains("-X") }.joinToString(" ") + } + if (!jvmSettingsList.contains("-Xmx")) { - val maxHeapSize = - FileHelpers.getFilesWithName(searchDirectory, "cassandra-env.sh").first().readLines().filter { + val envFiles = FileHelpers.getFilesWithName(searchDirectory, "cassandra-env.sh") + if (envFiles.isNotEmpty()) { + val maxHeapSize = envFiles.first().readLines().filter { it.startsWith("MAX_HEAP_SIZE=") }.joinToString(" ") { " -Xmx${it.replace("MAX_HEAP_SIZE=\"", "").replace("\"", "")}" } - val newGenSize = - FileHelpers.getFilesWithName(searchDirectory, "cassandra-env.sh").first().readLines().filter { - it.startsWith("HEAP_NEWSIZE=") - }.joinToString(" ") { " -Xmn${it.replace("HEAP_NEWSIZE=\"", "").replace("\"", "")}" } - jvmSettingsList = listOf("$jvmFlags $maxHeapSize $newGenSize") + val newGenSize = + envFiles.first().readLines().filter { + it.startsWith("HEAP_NEWSIZE=") + }.joinToString(" ") { " -Xmn${it.replace("HEAP_NEWSIZE=\"", "").replace("\"", "")}" } + + jvmSettingsList = listOf("$jvmFlags $maxHeapSize $newGenSize") + } } } else { // no jvm.options. @@ -483,7 +488,11 @@ class Artifacts( } private fun loadViaParser(parentFolder: File, fileNames: List, parser: IFileParser, hostname: String, loadErrors: MutableList, noFileReturn: T): T { - val dataFile = FileHelpers.getFile(parentFolder, fileNames) + + val dataFile = FileHelpers.getFile( + parentFolder, + fileNames.flatMap { if (it.endsWith(".txt")) listOf(it) else listOf(it, "$it.txt") }) + return if (dataFile.exists()) { try { parser.parse(dataFile.readLines())