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) {
|
||||
|
||||
@@ -1,88 +0,0 @@
|
||||
# ======================== OpenSearch Configuration =========================
|
||||
#
|
||||
# NOTE: OpenSearch comes with reasonable defaults for most settings.
|
||||
# Before you set out to tweak and tune the configuration, make sure you
|
||||
# understand what are you trying to accomplish and the consequences.
|
||||
#
|
||||
# The primary way of configuring a node is via this file. This template lists
|
||||
# the most important settings you may want to configure for a production cluster.
|
||||
#
|
||||
# Please consult the documentation for further information on configuration options:
|
||||
# https://www.opensearch.org
|
||||
#
|
||||
# ---------------------------------- Cluster -----------------------------------
|
||||
#
|
||||
# Use a descriptive name for your cluster:
|
||||
#
|
||||
#cluster.name: my-application
|
||||
#
|
||||
# ------------------------------------ Node ------------------------------------
|
||||
#
|
||||
# Use a descriptive name for the node:
|
||||
#
|
||||
#node.name: node-1
|
||||
#
|
||||
# Add custom attributes to the node:
|
||||
#
|
||||
#node.attr.rack: r1
|
||||
#
|
||||
# ----------------------------------- Paths ------------------------------------
|
||||
#
|
||||
# Path to directory where to store the data (separate multiple locations by comma):
|
||||
#
|
||||
#path.data: /path/to/data
|
||||
#
|
||||
# Path to log files:
|
||||
#
|
||||
#path.logs: /path/to/logs
|
||||
#
|
||||
# ----------------------------------- Memory -----------------------------------
|
||||
#
|
||||
# Lock the memory on startup:
|
||||
#
|
||||
#bootstrap.memory_lock: true
|
||||
#
|
||||
# Make sure that the heap size is set to about half the memory available
|
||||
# on the system and that the owner of the process is allowed to use this
|
||||
# limit.
|
||||
#
|
||||
# OpenSearch performs poorly when the system is swapping the memory.
|
||||
#
|
||||
# ---------------------------------- Network -----------------------------------
|
||||
#
|
||||
# Set the bind address to a specific IP (IPv4 or IPv6):
|
||||
#
|
||||
#network.host: 192.168.0.1
|
||||
#
|
||||
# Set a custom port for HTTP:
|
||||
#
|
||||
#http.port: 9200
|
||||
#
|
||||
# For more information, consult the network module documentation.
|
||||
#
|
||||
# --------------------------------- Discovery ----------------------------------
|
||||
#
|
||||
# Pass an initial list of hosts to perform discovery when this node is started:
|
||||
# The default list of hosts is ["127.0.0.1", "[::1]"]
|
||||
#
|
||||
#discovery.seed_hosts: ["host1", "host2"]
|
||||
#
|
||||
# Bootstrap the cluster using an initial set of cluster-manager-eligible nodes:
|
||||
#
|
||||
#cluster.initial_cluster_manager_nodes: ["node-1", "node-2"]
|
||||
#
|
||||
# For more information, consult the discovery and cluster formation module documentation.
|
||||
#
|
||||
# ---------------------------------- Gateway -----------------------------------
|
||||
#
|
||||
# Block initial recovery after a full cluster restart until N nodes are started:
|
||||
#
|
||||
#gateway.recover_after_nodes: 3
|
||||
#
|
||||
# For more information, consult the gateway module documentation.
|
||||
#
|
||||
# ---------------------------------- Various -----------------------------------
|
||||
#
|
||||
# Require explicit names when deleting indices:
|
||||
#
|
||||
#action.destructive_requires_name: true
|
||||
Reference in New Issue
Block a user