DataNode: writing opensearch.yml instead of env vars (#17021)

* writing opensearch.yml instead of env vars

* appending to an existing original config file to be able to check in default config options in git

* remove original config file, always create/write config

* removed unnecessary imports
This commit is contained in:
Jan Heise
2023-10-20 12:09:36 +02:00
committed by GitHub
parent 392ed658bb
commit 2a8139135e
2 changed files with 17 additions and 93 deletions

View File

@@ -16,6 +16,8 @@
*/
package org.graylog.datanode.management;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import org.apache.commons.exec.OS;
import org.graylog.datanode.process.OpensearchConfiguration;
import org.graylog.datanode.process.ProcessInformation;
@@ -32,7 +34,6 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
public class OpensearchCommandLineProcess implements Closeable {
@@ -40,6 +41,8 @@ public class OpensearchCommandLineProcess implements Closeable {
private final CommandLineProcess commandLineProcess;
private final CommandLineProcessListener resultHandler;
private final ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
private static final String CONFIG = "opensearch.yml";
/**
* as long as OpenSearch is not supported on macOS, we have to fix the jdk path if we want to
@@ -74,13 +77,22 @@ public class OpensearchCommandLineProcess implements Closeable {
}
}
private void writeOpenSearchConfig(final OpensearchConfiguration config) {
try {
final var configFile = config.datanodeDirectories().getOpensearchProcessConfigurationDir().resolve(CONFIG);
Files.deleteIfExists(configFile);
mapper.writeValue(configFile.toFile(), getOpensearchConfigurationArguments(config));
} catch (IOException e) {
throw new RuntimeException("Could not generate OpenSearch config: " + e.getMessage(), e);
}
}
public OpensearchCommandLineProcess(OpensearchConfiguration config, ProcessListener listener) {
fixJdkOnMac(config);
final Path executable = config.opensearchDistribution().getOpensearchExecutable();;
final List<String> arguments = getOpensearchConfigurationArguments(config).entrySet().stream()
.map(it -> String.format(Locale.ROOT, "-E%s=%s", it.getKey(), it.getValue())).toList();
final Path executable = config.opensearchDistribution().getOpensearchExecutable();
writeOpenSearchConfig(config);
resultHandler = new CommandLineProcessListener(listener);
commandLineProcess = new CommandLineProcess(executable, arguments, resultHandler, config.getEnv());
commandLineProcess = new CommandLineProcess(executable, List.of(), resultHandler, config.getEnv());
}
private static Map<String, String> getOpensearchConfigurationArguments(OpensearchConfiguration config) {