tillrohrmann commented on a change in pull request #10532: 
[FLINK-15053][runtime] Escape all dynamical property values for taskmanager
URL: https://github.com/apache/flink/pull/10532#discussion_r360337061
 
 

 ##########
 File path: 
flink-tests/src/test/java/org/apache/flink/test/runtime/TaskManagerLoadingDynamicPropertiesITCase.java
 ##########
 @@ -0,0 +1,158 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.test.runtime;
+
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.runtime.clusterframework.BootstrapTools;
+import org.apache.flink.runtime.entrypoint.FlinkParseException;
+import org.apache.flink.runtime.taskexecutor.TaskManagerRunner;
+import org.apache.flink.runtime.testutils.CommonTestUtils;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+import static 
org.apache.flink.configuration.GlobalConfiguration.FLINK_CONF_FILENAME;
+import static 
org.apache.flink.runtime.testutils.CommonTestUtils.getCurrentClasspath;
+import static 
org.apache.flink.runtime.testutils.CommonTestUtils.getJavaCommandPath;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Tests for passing and loading dynamical properties of task manager.
+ * Usually(in Yarn, Kubernetes), the taskmanager java start commands are 
wrapped within bash. This test will generate a
+ * launch_container.sh script to validate the dynamical properties passing and 
loading.
+ */
+public class TaskManagerLoadingDynamicPropertiesITCase {
+
+       private static final String KEY_A = "key.a";
+       private static final String VALUE_A = "value-of-a";
+       private static final String KEY_B = "key.b";
+       private static final String VALUE_B = "#a,b&c^d*e%f(g!h";
+       private static final String KEY_C = "key.c";
+       private static final String VALUE_C = "my'value is 1";
+
+       @Rule
+       public TemporaryFolder folder = new TemporaryFolder();
+
+       @Test
+       public void testLoadingDynamicPropertiesInBash() throws Exception {
+               final Configuration clientConfiguration = new Configuration();
+               clientConfiguration.setString("client.key.a", "value");
+               final File root = folder.getRoot();
+               final File homeDir = new File(root, "home");
+               assertTrue(homeDir.mkdir());
+               BootstrapTools.writeConfiguration(clientConfiguration, new 
File(homeDir, FLINK_CONF_FILENAME));
+
+               final Configuration jmUpdatedConfiguration = new 
Configuration();
+               jmUpdatedConfiguration.setString(KEY_A, VALUE_A);
+               jmUpdatedConfiguration.setString(KEY_B, VALUE_B);
+               jmUpdatedConfiguration.setString(KEY_C, VALUE_C);
+               final String[] dynamicProperties = 
BootstrapTools.getDynamicProperties(clientConfiguration, 
jmUpdatedConfiguration);
+
+               UnixShellScriptBuilder shellScriptBuilder = new 
UnixShellScriptBuilder();
+               final List<String> commands = new ArrayList<>();
+               commands.add(getJavaCommandPath());
+               
commands.add(TestingTaskManagerRunner.class.getName().replace("$", "'$'"));
+               commands.add("--configDir");
+               commands.add(homeDir.getAbsolutePath());
+               commands.addAll(Arrays.asList(dynamicProperties));
+               shellScriptBuilder.env("CLASSPATH", getCurrentClasspath());
+               shellScriptBuilder.command(commands);
+               final File shellScriptFile = new File(homeDir, 
"launch_container.sh");
+               shellScriptBuilder.write(shellScriptFile);
 
 Review comment:
   I would factor this out into a smaller method with an expressive name.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to