Skip to content

Commit

Permalink
Artifacts.loadViaParser(..) should also (automatically) accept files …
Browse files Browse the repository at this point in the history
…with '.txt' suffixes
  • Loading branch information
michaelsembwever committed Aug 23, 2024
1 parent 30d71ae commit 26e7189
Showing 1 changed file with 23 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<String> = 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.
Expand Down Expand Up @@ -483,7 +488,11 @@ class Artifacts(
}

private fun <T> loadViaParser(parentFolder: File, fileNames: List<String>, parser: IFileParser<T>, hostname: String, loadErrors: MutableList<LoadError>, 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())
Expand Down

0 comments on commit 26e7189

Please sign in to comment.