Skip to content

Commit 4ed027b

Browse files
authored
Remove unused plugins dir var from server CLI (#88917)
Split out of #88443. Remove the now-unused plugins directory variable from the server CLI code.
1 parent b0aca91 commit 4ed027b

File tree

6 files changed

+32
-43
lines changed

6 files changed

+32
-43
lines changed

distribution/tools/server-cli/src/main/java/org/elasticsearch/server/cli/JvmOptionsParser.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,15 @@ SortedMap<Integer, String> invalidLines() {
6969
* variable.
7070
*
7171
* @param configDir the ES config dir
72-
* @param pluginsDir the ES plugins dir
7372
* @param tmpDir the directory that should be passed to {@code -Djava.io.tmpdir}
7473
* @param envOptions the options passed through the ES_JAVA_OPTS env var
7574
* @return the list of options to put on the Java command line
7675
* @throws InterruptedException if the java subprocess is interrupted
7776
* @throws IOException if there is a problem reading any of the files
78-
* @throws UserException if there is a problem parsing the jvm.options file or jvm.options.d files
77+
* @throws UserException if there is a problem parsing the `jvm.options` file or `jvm.options.d` files
7978
*/
80-
static List<String> determineJvmOptions(Path configDir, Path pluginsDir, Path tmpDir, String envOptions) throws InterruptedException,
81-
IOException, UserException {
79+
static List<String> determineJvmOptions(Path configDir, Path tmpDir, String envOptions) throws InterruptedException, IOException,
80+
UserException {
8281

8382
final JvmOptionsParser parser = new JvmOptionsParser();
8483

@@ -87,7 +86,7 @@ static List<String> determineJvmOptions(Path configDir, Path pluginsDir, Path tm
8786
substitutions.put("ES_PATH_CONF", configDir.toString());
8887

8988
try {
90-
return parser.jvmOptions(configDir, pluginsDir, envOptions, substitutions);
89+
return parser.jvmOptions(configDir, envOptions, substitutions);
9190
} catch (final JvmOptionsFileParserException e) {
9291
final String errorMessage = String.format(
9392
Locale.ROOT,
@@ -116,7 +115,7 @@ static List<String> determineJvmOptions(Path configDir, Path pluginsDir, Path tm
116115
}
117116
}
118117

119-
private List<String> jvmOptions(final Path config, Path plugins, final String esJavaOpts, final Map<String, String> substitutions)
118+
private List<String> jvmOptions(final Path config, final String esJavaOpts, final Map<String, String> substitutions)
120119
throws InterruptedException, IOException, JvmOptionsFileParserException {
121120

122121
final List<String> jvmOptions = readJvmOptionsFiles(config);

distribution/tools/server-cli/src/main/java/org/elasticsearch/server/cli/ServerCli.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
import joptsimple.OptionSpecBuilder;
1414
import joptsimple.util.PathConverter;
1515

16-
import org.apache.logging.log4j.LogManager;
17-
import org.apache.logging.log4j.Logger;
1816
import org.elasticsearch.Build;
1917
import org.elasticsearch.bootstrap.ServerArgs;
2018
import org.elasticsearch.cli.CliToolProvider;
@@ -40,8 +38,6 @@
4038
*/
4139
class ServerCli extends EnvironmentAwareCommand {
4240

43-
private static final Logger logger = LogManager.getLogger(ServerCli.class);
44-
4541
private final OptionSpecBuilder versionOption;
4642
private final OptionSpecBuilder daemonizeOption;
4743
private final OptionSpec<Path> pidfileOption;
@@ -52,7 +48,7 @@ class ServerCli extends EnvironmentAwareCommand {
5248

5349
// visible for testing
5450
ServerCli() {
55-
super("Starts Elasticsearch"); // we configure logging later so we override the base class from configuring logging
51+
super("Starts Elasticsearch"); // we configure logging later, so we override the base class from configuring logging
5652
versionOption = parser.acceptsAll(Arrays.asList("V", "version"), "Prints Elasticsearch version information and exits");
5753
daemonizeOption = parser.acceptsAll(Arrays.asList("d", "daemonize"), "Starts Elasticsearch in the background")
5854
.availableUnless(versionOption);
@@ -88,7 +84,7 @@ public void execute(Terminal terminal, OptionSet options, Environment env, Proce
8884
syncPlugins(terminal, env, processInfo);
8985

9086
ServerArgs args = createArgs(options, env, keystorePassword, processInfo);
91-
this.server = startServer(terminal, processInfo, args, env.pluginsFile());
87+
this.server = startServer(terminal, processInfo, args);
9288

9389
if (options.has(daemonizeOption)) {
9490
server.detach();
@@ -162,7 +158,7 @@ private Environment autoConfigureSecurity(
162158
} catch (UserException e) {
163159
boolean okCode = switch (e.exitCode) {
164160
// these exit codes cover the cases where auto-conf cannot run but the node should NOT be prevented from starting as usual
165-
// eg the node is restarted, is already configured in an incompatible way, or the file system permissions do not allow it
161+
// e.g. the node is restarted, is already configured in an incompatible way, or the file system permissions do not allow it
166162
case ExitCodes.CANT_CREATE, ExitCodes.CONFIG, ExitCodes.NOOP -> true;
167163
default -> false;
168164
};
@@ -230,7 +226,7 @@ protected Command loadTool(String toolname, String libs) {
230226
}
231227

232228
// protected to allow tests to override
233-
protected ServerProcess startServer(Terminal terminal, ProcessInfo processInfo, ServerArgs args, Path pluginsDir) throws UserException {
234-
return ServerProcess.start(terminal, processInfo, args, pluginsDir);
229+
protected ServerProcess startServer(Terminal terminal, ProcessInfo processInfo, ServerArgs args) throws UserException {
230+
return ServerProcess.start(terminal, processInfo, args);
235231
}
236232
}

distribution/tools/server-cli/src/main/java/org/elasticsearch/server/cli/ServerProcess.java

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
/**
3737
* A helper to control a {@link Process} running the main Elasticsearch server.
3838
*
39-
* <p> The process can be started by calling {@link #start(Terminal, ProcessInfo, ServerArgs, Path)}.
39+
* <p> The process can be started by calling {@link #start(Terminal, ProcessInfo, ServerArgs)}.
4040
* The process is controlled by internally sending arguments and control signals on stdin,
4141
* and receiving control signals on stderr. The start method does not return until the
4242
* server is ready to process requests and has exited the bootstrap thread.
@@ -66,8 +66,7 @@ public class ServerProcess {
6666

6767
// this allows mocking the process building by tests
6868
interface OptionsBuilder {
69-
List<String> getJvmOptions(Path configDir, Path pluginsDir, Path tmpDir, String envOptions) throws InterruptedException,
70-
IOException, UserException;
69+
List<String> getJvmOptions(Path configDir, Path tmpDir, String envOptions) throws InterruptedException, IOException, UserException;
7170
}
7271

7372
// this allows mocking the process building by tests
@@ -81,20 +80,18 @@ interface ProcessStarter {
8180
* @param terminal A terminal to connect the standard inputs and outputs to for the new process.
8281
* @param processInfo Info about the current process, for passing through to the subprocess.
8382
* @param args Arguments to the server process.
84-
* @param pluginsDir The directory in which plugins can be found
8583
* @return A running server process that is ready for requests
8684
* @throws UserException If the process failed during bootstrap
8785
*/
88-
public static ServerProcess start(Terminal terminal, ProcessInfo processInfo, ServerArgs args, Path pluginsDir) throws UserException {
89-
return start(terminal, processInfo, args, pluginsDir, JvmOptionsParser::determineJvmOptions, ProcessBuilder::start);
86+
public static ServerProcess start(Terminal terminal, ProcessInfo processInfo, ServerArgs args) throws UserException {
87+
return start(terminal, processInfo, args, JvmOptionsParser::determineJvmOptions, ProcessBuilder::start);
9088
}
9189

9290
// package private so tests can mock options building and process starting
9391
static ServerProcess start(
9492
Terminal terminal,
9593
ProcessInfo processInfo,
9694
ServerArgs args,
97-
Path pluginsDir,
9895
OptionsBuilder optionsBuilder,
9996
ProcessStarter processStarter
10097
) throws UserException {
@@ -103,7 +100,7 @@ static ServerProcess start(
103100

104101
boolean success = false;
105102
try {
106-
jvmProcess = createProcess(processInfo, args.configDir(), pluginsDir, optionsBuilder, processStarter);
103+
jvmProcess = createProcess(processInfo, args.configDir(), optionsBuilder, processStarter);
107104
errorPump = new ErrorPumpThread(terminal.getErrorWriter(), jvmProcess.getErrorStream());
108105
errorPump.start();
109106
sendArgs(args, jvmProcess.getOutputStream());
@@ -138,7 +135,7 @@ public long pid() {
138135
/**
139136
* Detaches the server process from the current process, enabling the current process to exit.
140137
*
141-
* @throws IOException If an I/O error occured while reading stderr or closing any of the standard streams
138+
* @throws IOException If an I/O error occurred while reading stderr or closing any of the standard streams
142139
*/
143140
public synchronized void detach() throws IOException {
144141
errorPump.drain();
@@ -178,7 +175,7 @@ private static void sendArgs(ServerArgs args, OutputStream processStdin) {
178175
args.writeTo(out);
179176
out.flush();
180177
} catch (IOException ignore) {
181-
// A failure to write here means the process has problems, and it will die anyways. We let this fall through
178+
// A failure to write here means the process has problems, and it will die anyway. We let this fall through
182179
// so the pump thread can complete, writing out the actual error. All we get here is the failure to write to
183180
// the process pipe, which isn't helpful to print.
184181
}
@@ -198,7 +195,6 @@ private void sendShutdownMarker() {
198195
private static Process createProcess(
199196
ProcessInfo processInfo,
200197
Path configDir,
201-
Path pluginsDir,
202198
OptionsBuilder optionsBuilder,
203199
ProcessStarter processStarter
204200
) throws InterruptedException, IOException, UserException {
@@ -208,7 +204,7 @@ private static Process createProcess(
208204
envVars.put("LIBFFI_TMPDIR", tempDir.toString());
209205
}
210206

211-
List<String> jvmOptions = optionsBuilder.getJvmOptions(configDir, pluginsDir, tempDir, envVars.remove("ES_JAVA_OPTS"));
207+
List<String> jvmOptions = optionsBuilder.getJvmOptions(configDir, tempDir, envVars.remove("ES_JAVA_OPTS"));
212208
// also pass through distribution type
213209
jvmOptions.add("-Des.distribution.type=" + processInfo.sysprops().get("es.distribution.type"));
214210

@@ -233,7 +229,7 @@ private static Process createProcess(
233229
/**
234230
* Returns the java.io.tmpdir Elasticsearch should use, creating it if necessary.
235231
*
236-
* <p> On non-Windows OS, this will be created as a sub-directory of the default temporary directory.
232+
* <p> On non-Windows OS, this will be created as a subdirectory of the default temporary directory.
237233
* Note that this causes the created temporary directory to be a private temporary directory.
238234
*/
239235
private static Path setupTempDir(ProcessInfo processInfo, String tmpDirOverride) throws UserException, IOException {

distribution/tools/server-cli/src/test/java/org/elasticsearch/server/cli/ServerCliTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ protected Command loadTool(String toolname, String libs) {
436436
}
437437

438438
@Override
439-
protected ServerProcess startServer(Terminal terminal, ProcessInfo processInfo, ServerArgs args, Path pluginsDir) {
439+
protected ServerProcess startServer(Terminal terminal, ProcessInfo processInfo, ServerArgs args) {
440440
if (argsValidator != null) {
441441
argsValidator.accept(args);
442442
}

distribution/tools/server-cli/src/test/java/org/elasticsearch/server/cli/ServerProcessTests.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public void resetEnv() {
9292
envVars.clear();
9393
esHomeDir = createTempDir();
9494
nodeSettings = Settings.builder();
95-
optionsBuilder = (configDir, pluginsDir, tmpDir, envOptions) -> new ArrayList<>();
95+
optionsBuilder = (configDir, tmpDir, envOptions) -> new ArrayList<>();
9696
processValidator = null;
9797
mainCallback = null;
9898
}
@@ -201,7 +201,7 @@ ServerProcess startProcess(boolean daemonize, boolean quiet, String keystorePass
201201
process = new MockElasticsearchProcess();
202202
return process;
203203
};
204-
return ServerProcess.start(terminal, pinfo, args, esHomeDir.resolve("plugins"), optionsBuilder, starter);
204+
return ServerProcess.start(terminal, pinfo, args, optionsBuilder, starter);
205205
}
206206

207207
public void testProcessBuilder() throws Exception {
@@ -253,9 +253,7 @@ public void testStartError() throws Exception {
253253
}
254254

255255
public void testOptionsBuildingInterrupted() throws Exception {
256-
optionsBuilder = (configDir, pluginsDir, tmpDir, envOptions) -> {
257-
throw new InterruptedException("interrupted while get jvm options");
258-
};
256+
optionsBuilder = (configDir, tmpDir, envOptions) -> { throw new InterruptedException("interrupted while get jvm options"); };
259257
var e = expectThrows(RuntimeException.class, () -> runForeground());
260258
assertThat(e.getCause().getMessage(), equalTo("interrupted while get jvm options"));
261259
}
@@ -279,7 +277,7 @@ public void testLibffiEnv() throws Exception {
279277
}
280278

281279
public void testTempDir() throws Exception {
282-
optionsBuilder = (configDir, pluginsDir, tmpDir, envOptions) -> {
280+
optionsBuilder = (configDir, tmpDir, envOptions) -> {
283281
assertThat(tmpDir.toString(), Files.exists(tmpDir), is(true));
284282
assertThat(tmpDir.getFileName().toString(), startsWith("elasticsearch-"));
285283
return new ArrayList<>();
@@ -291,7 +289,7 @@ public void testTempDirWindows() throws Exception {
291289
Path baseTmpDir = createTempDir();
292290
sysprops.put("os.name", "Windows 10");
293291
sysprops.put("java.io.tmpdir", baseTmpDir.toString());
294-
optionsBuilder = (configDir, pluginsDir, tmpDir, envOptions) -> {
292+
optionsBuilder = (configDir, tmpDir, envOptions) -> {
295293
assertThat(tmpDir.toString(), Files.exists(tmpDir), is(true));
296294
assertThat(tmpDir.getFileName().toString(), equalTo("elasticsearch"));
297295
assertThat(tmpDir.getParent().toString(), equalTo(baseTmpDir.toString()));
@@ -303,7 +301,7 @@ public void testTempDirWindows() throws Exception {
303301
public void testTempDirOverride() throws Exception {
304302
Path customTmpDir = createTempDir();
305303
envVars.put("ES_TMPDIR", customTmpDir.toString());
306-
optionsBuilder = (configDir, pluginsDir, tmpDir, envOptions) -> {
304+
optionsBuilder = (configDir, tmpDir, envOptions) -> {
307305
assertThat(tmpDir.toString(), equalTo(customTmpDir.toString()));
308306
return new ArrayList<>();
309307
};
@@ -329,7 +327,7 @@ public void testTempDirOverrideNotADirectory() throws Exception {
329327

330328
public void testCustomJvmOptions() throws Exception {
331329
envVars.put("ES_JAVA_OPTS", "-Dmyoption=foo");
332-
optionsBuilder = (configDir, pluginsDir, tmpDir, envOptions) -> {
330+
optionsBuilder = (configDir, tmpDir, envOptions) -> {
333331
assertThat(envOptions, equalTo("-Dmyoption=foo"));
334332
return new ArrayList<>();
335333
};
@@ -338,7 +336,7 @@ public void testCustomJvmOptions() throws Exception {
338336
}
339337

340338
public void testCommandLineSysprops() throws Exception {
341-
optionsBuilder = (configDir, pluginsDir, tmpDir, envOptions) -> List.of("-Dfoo1=bar", "-Dfoo2=baz");
339+
optionsBuilder = (configDir, tmpDir, envOptions) -> List.of("-Dfoo1=bar", "-Dfoo2=baz");
342340
processValidator = pb -> {
343341
assertThat(pb.command(), contains("-Dfoo1=bar"));
344342
assertThat(pb.command(), contains("-Dfoo2=bar"));

distribution/tools/windows-service-cli/src/main/java/org/elasticsearch/windows/service/WindowsServiceDaemon.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020

2121
/**
2222
* Starts an Elasticsearch process, but does not wait for it to exit.
23-
*
24-
* This class is expected to be run via Apache Procrun in a long lived JVM that will call close
25-
* when the server should shutdown.
23+
* <p>
24+
* This class is expected to be run via Apache Procrun in a long-lived JVM that will call close
25+
* when the server should shut down.
2626
*/
2727
class WindowsServiceDaemon extends EnvironmentAwareCommand {
2828

@@ -35,7 +35,7 @@ class WindowsServiceDaemon extends EnvironmentAwareCommand {
3535
@Override
3636
public void execute(Terminal terminal, OptionSet options, Environment env, ProcessInfo processInfo) throws Exception {
3737
var args = new ServerArgs(false, true, null, new SecureString(""), env.settings(), env.configFile());
38-
this.server = ServerProcess.start(terminal, processInfo, args, env.pluginsFile());
38+
this.server = ServerProcess.start(terminal, processInfo, args);
3939
// start does not return until the server is ready, and we do not wait for the process
4040
}
4141

0 commit comments

Comments
 (0)