zhuzhurk commented on code in PR #24091:
URL: https://github.com/apache/flink/pull/24091#discussion_r1461756156
##########
flink-dist/src/main/flink-bin/bin/config.sh:
##########
@@ -243,25 +210,13 @@ export FLINK_LIB_DIR
# export /opt dir to access it for the SQL client
export FLINK_OPT_DIR
+YAML_CONF=$(getFlinkConfiguration "${FLINK_CONF_DIR}" "${FLINK_BIN_DIR}"
${FLINK_LIB_DIR} -flatten)
+
########################################################################################################################
# ENVIRONMENT VARIABLES
########################################################################################################################
# read JAVA_HOME from config with no default value
-MY_JAVA_HOME=$(readFromConfig ${KEY_ENV_JAVA_HOME} "" "${YAML_CONF}")
-# check if config specified JAVA_HOME
-if [ -z "${MY_JAVA_HOME}" ]; then
- # config did not specify JAVA_HOME. Use system JAVA_HOME
- MY_JAVA_HOME="${JAVA_HOME}"
-fi
-# check if we have a valid JAVA_HOME and if java is not available
-if [ -z "${MY_JAVA_HOME}" ] && ! type java > /dev/null 2> /dev/null; then
- echo "Please specify JAVA_HOME. Either in Flink config
./conf/flink-conf.yaml or as system-wide JAVA_HOME."
- exit 1
-else
- JAVA_HOME="${MY_JAVA_HOME}"
-fi
-
UNAME=$(uname -s)
if [ "${UNAME:0:6}" == "CYGWIN" ]; then
JAVA_RUN=java
Review Comment:
JAVA_RUN is already defined in `bash-java-utils.sh`. Seems this block is no
longer needed?
##########
flink-runtime/src/main/java/org/apache/flink/runtime/util/bash/FlinkConfigLoader.java:
##########
@@ -36,22 +37,27 @@
*/
public class FlinkConfigLoader {
- private static final Options CMD_OPTIONS =
ClusterConfigurationParserFactory.options();
-
public static Configuration loadConfiguration(String[] args) throws
FlinkException {
return ConfigurationParserUtils.loadCommonConfiguration(
- filterCmdArgs(args), BashJavaUtils.class.getSimpleName());
+ filterCmdArgs(args,
ClusterConfigurationParserFactory.options()),
+ BashJavaUtils.class.getSimpleName());
+ }
+
+ public static List<String> getConfigurationWritableData(String[] args)
throws FlinkException {
Review Comment:
getConfigurationWritableData -> loadAndModifyConfiguration
The same applies to the names of its UTs.
##########
flink-runtime/src/main/java/org/apache/flink/runtime/entrypoint/YamlConfigurationParserFactory.java:
##########
@@ -0,0 +1,97 @@
+/*
+ * 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.runtime.entrypoint;
+
+import org.apache.flink.api.java.tuple.Tuple3;
+import org.apache.flink.runtime.entrypoint.parser.ParserResultFactory;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Options;
+
+import javax.annotation.Nonnull;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Properties;
+
+import static
org.apache.flink.runtime.entrypoint.parser.CommandLineOptions.CONFIG_DIR_OPTION;
+import static
org.apache.flink.runtime.entrypoint.parser.CommandLineOptions.DYNAMIC_PROPERTY_OPTION;
+import static
org.apache.flink.runtime.entrypoint.parser.CommandLineOptions.FLATTEN_CONFIG_OPTION;
+import static
org.apache.flink.runtime.entrypoint.parser.CommandLineOptions.REMOVE_KEY_OPTION;
+import static
org.apache.flink.runtime.entrypoint.parser.CommandLineOptions.REMOVE_KEY_VALUE_OPTION;
+import static
org.apache.flink.runtime.entrypoint.parser.CommandLineOptions.REPLACE_KEY_VALUE_OPTION;
+
+/** A class can be used to extract the configuration from command line and
modify it. */
+public class YamlConfigurationParserFactory implements
ParserResultFactory<YamlConfiguration> {
Review Comment:
The differences from `ClusterConfigurationParserFactory` is that this class
additionally parses params of modifications, not **YAML**. Maybe name it as
`ModifiableClusterConfigurationParserFactory`? The same applies to
`YamlConfiguration`.
##########
flink-dist/src/main/flink-bin/bin/bash-java-utils.sh:
##########
@@ -0,0 +1,170 @@
+#!/usr/bin/env bash
+################################################################################
+# 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.
+################################################################################
+
+UNAME=$(uname -s)
+if [ "${UNAME:0:6}" == "CYGWIN" ]; then
+ JAVA_RUN=java
+else
+ if [[ -d "$JAVA_HOME" ]]; then
+ JAVA_RUN="$JAVA_HOME"/bin/java
+ else
+ JAVA_RUN=java
+ fi
+fi
+
+manglePathList() {
+ UNAME=$(uname -s)
+ # a path list, for example a java classpath
+ if [ "${UNAME:0:6}" == "CYGWIN" ]; then
+ echo `cygpath -wp "$1"`
+ else
+ echo $1
+ fi
+}
+
+findFlinkDistJar() {
+ local FLINK_DIST
+ local LIB_DIR
+ if [[ -n "$1" ]]; then
+ LIB_DIR="$1"
+ else
+ LIB_DIR="$FLINK_LIB_DIR"
+ fi
+ FLINK_DIST="$(find "$LIB_DIR" -name 'flink-dist*.jar')"
+ local FLINK_DIST_COUNT
+ FLINK_DIST_COUNT="$(echo "$FLINK_DIST" | wc -l)"
+
+ # If flink-dist*.jar cannot be resolved write error messages to stderr
since stdout is stored
+ # as the classpath and exit function with empty classpath to force process
failure
+ if [[ "$FLINK_DIST" == "" ]]; then
+ (>&2 echo "[ERROR] Flink distribution jar not found in
$FLINK_LIB_DIR.")
+ exit 1
+ elif [[ "$FLINK_DIST_COUNT" -gt 1 ]]; then
+ (>&2 echo "[ERROR] Multiple flink-dist*.jar found in $FLINK_LIB_DIR.
Please resolve.")
+ exit 1
+ fi
+
+ echo "$FLINK_DIST"
+}
+
+runBashJavaUtilsCmd() {
+ local cmd=$1
+ local conf_dir=$2
+ local class_path=$3
+ local dynamic_args=${@:4}
+ class_path=`manglePathList "${class_path}"`
+
+ local output=`"${JAVA_RUN}" -classpath "${class_path}"
org.apache.flink.runtime.util.bash.BashJavaUtils ${cmd} --configDir
"${conf_dir}" $dynamic_args 2>&1 | tail -n 1000`
+ if [[ $? -ne 0 ]]; then
+ echo "[ERROR] Cannot run BashJavaUtils to execute command ${cmd}." 1>&2
+ # Print the output in case the user redirect the log to console.
+ echo "$output" 1>&2
+ exit 1
+ fi
+
+ echo "$output"
+}
+
+getFlinkConfiguration() {
Review Comment:
Is the method also used for config updates?
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]