mirror of
https://github.com/Graylog2/graylog2-server.git
synced 2026-03-13 09:32:21 +08:00
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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user