ShellCommandConfig extends MapConfig { public Optional<String> getTaskOpts() { Optional<String> jvmOpts = Optional.ofNullable(get(ShellCommandConfig.TASK_JVM_OPTS)); Optional<String> maxHeapMbOptional = Optional.ofNullable(get(JobConfig.JOB_AUTOSIZING_CONTAINER_MAX_HEAP_MB)); if (new JobConfig(this).getAutosizingEnabled() && maxHeapMbOptional.isPresent()) { String maxHeapMb = maxHeapMbOptional.get(); String xmxSetting = "-Xmx" + maxHeapMb + "m"; if (jvmOpts.isPresent() && jvmOpts.get().contains("-Xmx")) { jvmOpts = Optional.of(jvmOpts.get().replaceAll("-Xmx\\S+", xmxSetting)); } else if (jvmOpts.isPresent()) { jvmOpts = Optional.of(jvmOpts.get().concat(" " + xmxSetting)); } else { jvmOpts = Optional.of(xmxSetting); } } return jvmOpts; } ShellCommandConfig(Config config); String getCommand(); Optional<String> getTaskOpts(); Optional<String> getJavaHome(); Optional<String> getAdditionalClasspathDir(); static final String ENV_COORDINATOR_SYSTEM_CONFIG; static final String ENV_SUBMISSION_CONFIG; static final String ENV_CONTAINER_ID; static final String ENV_COORDINATOR_URL; static final String ENV_JAVA_OPTS; static final String ENV_JAVA_HOME; static final String ENV_EXECUTION_ENV_CONTAINER_ID; static final String ENV_SPLIT_DEPLOYMENT_ENABLED; static final String ENV_APPLICATION_LIB_DIR; static final String ENV_LOGGED_STORE_BASE_DIR; static final String EXECUTION_PLAN_DIR; static final String ENV_ADDITIONAL_CLASSPATH_DIR; static final String COMMAND_SHELL_EXECUTE; static final String TASK_JVM_OPTS; static final String TASK_JAVA_HOME; static final String ADDITIONAL_CLASSPATH_DIR; }
@Test public void testGetTaskOptsAutosizingDisabled() { ShellCommandConfig shellCommandConfig = new ShellCommandConfig(new MapConfig(ImmutableMap.of(JobConfig.JOB_AUTOSIZING_ENABLED, "false"))); assertEquals(Optional.empty(), shellCommandConfig.getTaskOpts()); String taskOpts = "-Dproperty=value"; shellCommandConfig = new ShellCommandConfig(new MapConfig( ImmutableMap.of(ShellCommandConfig.TASK_JVM_OPTS, taskOpts, JobConfig.JOB_AUTOSIZING_ENABLED, "false"))); assertEquals(Optional.of(taskOpts), shellCommandConfig.getTaskOpts()); }
@Test public void testGetTaskOptsAutosizingEnabled() { ShellCommandConfig shellCommandConfig = new ShellCommandConfig(new MapConfig(ImmutableMap.of(JobConfig.JOB_AUTOSIZING_ENABLED, "true"))); assertEquals(Optional.empty(), shellCommandConfig.getTaskOpts()); String taskOpts = "-Dproperty=value"; shellCommandConfig = new ShellCommandConfig(new MapConfig( ImmutableMap.of(ShellCommandConfig.TASK_JVM_OPTS, taskOpts, JobConfig.JOB_AUTOSIZING_ENABLED, "true"))); assertEquals(Optional.of(taskOpts), shellCommandConfig.getTaskOpts()); shellCommandConfig = new ShellCommandConfig(new MapConfig( ImmutableMap.of(JobConfig.JOB_AUTOSIZING_ENABLED, "true", JobConfig.JOB_AUTOSIZING_CONTAINER_MAX_HEAP_MB, "1024"))); assertEquals(Optional.of("-Xmx1024m"), shellCommandConfig.getTaskOpts()); shellCommandConfig = new ShellCommandConfig(new MapConfig( ImmutableMap.of(JobConfig.JOB_AUTOSIZING_ENABLED, "true", JobConfig.JOB_AUTOSIZING_CONTAINER_MAX_HEAP_MB, "1024", "task.opts", "-Xmx10m -Dproperty=value"))); assertEquals(Optional.of("-Xmx1024m -Dproperty=value"), shellCommandConfig.getTaskOpts()); shellCommandConfig = new ShellCommandConfig(new MapConfig( ImmutableMap.of(JobConfig.JOB_AUTOSIZING_ENABLED, "true", JobConfig.JOB_AUTOSIZING_CONTAINER_MAX_HEAP_MB, "1024", "task.opts", "-Dproperty=value"))); assertEquals(Optional.of("-Dproperty=value -Xmx1024m"), shellCommandConfig.getTaskOpts()); }