From 4ae386e48d4c679eafb0eb046ec70fc6c16bb97f Mon Sep 17 00:00:00 2001 From: Bharath Kumarasubramanian Date: Wed, 22 Nov 2023 12:00:40 -0800 Subject: [PATCH] SAMZA-2798: Populate worker.opts in environment variable only if available --- .../main/java/org/apache/samza/job/ShellCommandBuilder.java | 3 ++- .../java/org/apache/samza/job/TestShellCommandBuilder.java | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/samza-core/src/main/java/org/apache/samza/job/ShellCommandBuilder.java b/samza-core/src/main/java/org/apache/samza/job/ShellCommandBuilder.java index 504d9a26f7..4262145eef 100644 --- a/samza-core/src/main/java/org/apache/samza/job/ShellCommandBuilder.java +++ b/samza-core/src/main/java/org/apache/samza/job/ShellCommandBuilder.java @@ -44,9 +44,10 @@ public Map buildEnvironment() { envBuilder.put(ShellCommandConfig.ENV_CONTAINER_ID, this.id); envBuilder.put(ShellCommandConfig.ENV_COORDINATOR_URL, this.url.toString()); envBuilder.put(ShellCommandConfig.ENV_JAVA_OPTS, shellCommandConfig.getTaskOpts().orElse("")); - envBuilder.put(ShellCommandConfig.WORKER_JVM_OPTS, shellCommandConfig.getWorkerOpts().orElse("")); envBuilder.put(ShellCommandConfig.ENV_ADDITIONAL_CLASSPATH_DIR, shellCommandConfig.getAdditionalClasspathDir().orElse("")); + shellCommandConfig.getWorkerOpts() + .ifPresent(workerOpts -> envBuilder.put(ShellCommandConfig.WORKER_JVM_OPTS, workerOpts)); shellCommandConfig.getJavaHome().ifPresent(javaHome -> envBuilder.put(ShellCommandConfig.ENV_JAVA_HOME, javaHome)); return envBuilder.build(); } diff --git a/samza-core/src/test/java/org/apache/samza/job/TestShellCommandBuilder.java b/samza-core/src/test/java/org/apache/samza/job/TestShellCommandBuilder.java index afb6bfeec5..4acba9487c 100644 --- a/samza-core/src/test/java/org/apache/samza/job/TestShellCommandBuilder.java +++ b/samza-core/src/test/java/org/apache/samza/job/TestShellCommandBuilder.java @@ -45,7 +45,6 @@ public void testBasicBuild() throws MalformedURLException { ShellCommandConfig.ENV_CONTAINER_ID, "1", ShellCommandConfig.ENV_COORDINATOR_URL, URL_STRING, ShellCommandConfig.ENV_JAVA_OPTS, "", - ShellCommandConfig.WORKER_JVM_OPTS, "", ShellCommandConfig.ENV_ADDITIONAL_CLASSPATH_DIR, ""); // assertions when command path is not set assertEquals("foo", shellCommandBuilder.buildCommand());