Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Artifacts.loadViaParser(..) should also (automatically) accept files with '.txt' suffixes #8

Merged
merged 1 commit into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 all jvm(.*-server)?.options files combined and MUST be manually validated"))
jvmSettings = JVMSettingsParser.parse(settingsFromOptions)
}
else {
Expand Down Expand Up @@ -372,33 +372,37 @@ class Artifacts(
}

private fun getJvmSettingsFromOptions(searchDirectory: String): String {
logger.info("Attempting to reconstruct JVM settings from jvm-server.options...")
var jvmSettingsList: List<String> = listOf()
val jvmFiles = FileHelpers.getFilesWithName(searchDirectory, "jvm(-server)?.options")
logger.info("Attempting to reconstruct JVM settings from jvm(.*-server)?.options...")
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(" ")
}
if (!jvmSettingsList.contains("-Xmx")) {
val maxHeapSize =
FileHelpers.getFilesWithName(searchDirectory, "cassandra-env.sh").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 jvmServerFiles = jvmFiles.filter { it.endsWith("-server.options") }

// XXX flags from different jvm*-server.options files are appended. half of these are not actually used.
var jvmFlags = if (jvmServerFiles.isNotEmpty()) {
jvmServerFiles.flatMap { it.readLines() }.filter { !it.startsWith("#") && it.contains("-X") }.joinToString(" ")
} else {
jvmFiles.flatMap { it.readLines() }.filter { !it.startsWith("#") && it.contains("-X") }.joinToString(" ")
}

if (!jvmFlags.contains("-Xmx")) {
logger.info("Attempting to reconstruct JVM settings from cassandra-env.sh...")
val envFiles = FileHelpers.getFilesWithName(searchDirectory, "cassandra-env.sh")
if (envFiles.isNotEmpty()) {

jvmFlags += envFiles.first().readLines().filter {
it.startsWith("MAX_HEAP_SIZE=")
}.joinToString(" ") { " -Xmx${it.replace("MAX_HEAP_SIZE=\"", "").replace("\"", "")}" }

jvmFlags += envFiles.first().readLines().filter {
it.startsWith("HEAP_NEWSIZE=")
}.joinToString(" ") { " -Xmn${it.replace("HEAP_NEWSIZE=\"", "").replace("\"", "")}" }
}
}
return jvmFlags
} else {
// no jvm.options.
// no jvm(.*-server)?.options.
return ""
}
return jvmSettingsList.first()
}

private fun getVersionFileContents(nodeFilePath: String): List<String> {
Expand Down Expand Up @@ -483,7 +487,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
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ package com.datastax.montecristo.model.os
data class PsAux(val data : List<String>, val path : String) {

fun getNodeProcessLine() : String? {
return data.firstOrNull{ it.contains("CassandraDaemon") ||
it.contains("DseModule") ||
it.contains("/usr/share/cassandra") ||
it.contains("/usr/local/cassandra") ||
it.contains("/usr/share/dse/cassandra") ||
it.contains("/opt/dse/") }
return data.firstOrNull{ it.contains("CassandraDaemon") }
?: data.firstOrNull{ it.contains("DseModule") }
?: data.firstOrNull{ it.contains("/usr/share/cassandra") ||
it.contains("/usr/local/cassandra") ||
it.contains("/usr/share/dse/cassandra") ||
it.contains("/opt/dse/") }
}

fun getCassandraRunningUser() : String {
Expand Down
Loading