From 6dcd505b216ee11ed1804c8469a61c650b2df8b9 Mon Sep 17 00:00:00 2001 From: Bharath Kumarasubramanian Date: Wed, 22 Nov 2023 13:49:33 -0800 Subject: [PATCH] SAMZA-2798: Populate worker.opts in environment variable only if available (#1693) Description Populate worker.opts in the environment variable only if available in the configs. Changes Check if worker.opts is present and then add it to environment variable Tests Updated unit tests --- .../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());