TisonKun commented on a change in pull request #9881: [FLINK-14377] Parse 
Executor-relevant ProgramOptions to ConfigOptions
URL: https://github.com/apache/flink/pull/9881#discussion_r334236287
 
 

 ##########
 File path: 
flink-clients/src/main/java/org/apache/flink/client/cli/ExecutionParameterProviderBuilder.java
 ##########
 @@ -0,0 +1,161 @@
+/*
+ * 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.client.cli;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.api.common.ExecutionConfig;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.ExecutorOptions;
+import org.apache.flink.configuration.PipelineOptions;
+import org.apache.flink.runtime.jobgraph.SavepointRestoreSettings;
+
+import org.apache.commons.cli.CommandLine;
+
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import static org.apache.flink.client.cli.CliFrontendParser.ARGS_OPTION;
+import static org.apache.flink.client.cli.CliFrontendParser.CLASSPATH_OPTION;
+import static org.apache.flink.client.cli.CliFrontendParser.CLASS_OPTION;
+import static org.apache.flink.client.cli.CliFrontendParser.DETACHED_OPTION;
+import static org.apache.flink.client.cli.CliFrontendParser.JAR_OPTION;
+import static org.apache.flink.client.cli.CliFrontendParser.PARALLELISM_OPTION;
+import static org.apache.flink.client.cli.CliFrontendParser.PYMODULE_OPTION;
+import static org.apache.flink.client.cli.CliFrontendParser.PY_OPTION;
+import static 
org.apache.flink.client.cli.CliFrontendParser.SAVEPOINT_ALLOW_NON_RESTORED_OPTION;
+import static 
org.apache.flink.client.cli.CliFrontendParser.SAVEPOINT_PATH_OPTION;
+import static 
org.apache.flink.client.cli.CliFrontendParser.SHUTDOWN_IF_ATTACHED_OPTION;
+import static 
org.apache.flink.client.cli.CliFrontendParser.YARN_DETACHED_OPTION;
+import static org.apache.flink.util.Preconditions.checkNotNull;
+
+/**
+ * Creates a {@link ExecutionParameterProvider} based either on a {@link 
Configuration}, or a {@link CommandLine command-line options}.
+ */
+@Internal
+public class ExecutionParameterProviderBuilder {
+
+       /**
+        * Creates a {@link ExecutionParameterProvider} based on the provided 
{@link Configuration}.
+        */
+       public static ExecutionParameterProvider fromConfiguration(final 
Configuration configuration) {
+               return new 
ExecutionParameterProvider(checkNotNull(configuration));
+       }
+
+       /**
+        * Creates a {@link ExecutionParameterProvider} based on the provided 
user-provided {@link CommandLine command-line options}.
+        */
+       public static ExecutionParameterProvider fromCommandLine(final 
CommandLine commandLine) throws CliArgsException {
+               final Configuration configuration = new Configuration();
+
+               final String[] args = 
commandLine.hasOption(ARGS_OPTION.getOpt()) ?
+                               
commandLine.getOptionValues(ARGS_OPTION.getOpt()) :
+                               commandLine.getArgs();
+
+               final String entryPointClass = 
commandLine.hasOption(CLASS_OPTION.getOpt())
+                               ? 
commandLine.getOptionValue(CLASS_OPTION.getOpt())
+                               : null;
+
+               final boolean isPython = 
commandLine.hasOption(PY_OPTION.getOpt())
+                               | 
commandLine.hasOption(PYMODULE_OPTION.getOpt())
+                               | 
"org.apache.flink.client.python.PythonGatewayServer".equals(entryPointClass);
+
+               if (commandLine.hasOption(JAR_OPTION.getOpt())) {
+                       
parseJarURLToConfig(commandLine.getOptionValue(JAR_OPTION.getOpt()), 
configuration);
+               } else if (!isPython && args.length > 0) {
+                       parseJarURLToConfig(args[0], configuration);
+               }
+
+               parseClasspathURLsToConfig(commandLine, configuration);
+               parseParallelismToConfig(commandLine, configuration);
+               parseDetachedModeToConfig(commandLine, configuration);
+               parseShutdownOnExitToConfig(commandLine, configuration);
+               parseSavepointRestoreSettingsToConfig(commandLine, 
configuration);
+
+               return new ExecutionParameterProvider(configuration);
+       }
+
+       private static boolean parseShutdownOnExitToConfig(final CommandLine 
commandLine, final Configuration configuration) {
 
 Review comment:
   Anywhere we need return values of these `parse` functions? According to 
`parse` prefix I would assume it is action only.

----------------------------------------------------------------
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