[GitHub] [flink] kl0u commented on a change in pull request #10346: [FLINK-14972] Make Remote(Stream)Environment use Executors.
kl0u commented on a change in pull request #10346: [FLINK-14972] Make Remote(Stream)Environment use Executors. URL: https://github.com/apache/flink/pull/10346#discussion_r352164760 ## File path: flink-java/src/main/java/org/apache/flink/api/java/RemoteEnvironment.java ## @@ -111,58 +93,59 @@ public RemoteEnvironment(String host, int port, Configuration clientConfig, Stri * protocol (e.g. file://) and be accessible on all nodes (e.g. by means of a NFS share). * The protocol must be supported by the {@link java.net.URLClassLoader}. */ - public RemoteEnvironment(String host, int port, Configuration clientConfig, - String[] jarFiles, URL[] globalClasspaths) { - if (!ExecutionEnvironment.areExplicitEnvironmentsAllowed()) { - throw new InvalidProgramException( - "The RemoteEnvironment cannot be instantiated when running in a pre-defined context " + - "(such as Command Line Client, Scala Shell, or TestEnvironment)"); - } - if (host == null) { - throw new NullPointerException("Host must not be null."); - } - if (port < 1 || port >= 0x) { - throw new IllegalArgumentException("Port out of range"); - } - - this.host = host; - this.port = port; - this.clientConfiguration = clientConfig == null ? new Configuration() : clientConfig; - if (jarFiles != null) { - this.jarFiles = new ArrayList<>(jarFiles.length); - for (String jarFile : jarFiles) { - try { - this.jarFiles.add(new File(jarFile).getAbsoluteFile().toURI().toURL()); - } catch (MalformedURLException e) { - throw new IllegalArgumentException("JAR file path invalid", e); - } - } - } - else { - this.jarFiles = Collections.emptyList(); - } - - if (globalClasspaths == null) { - this.globalClasspaths = Collections.emptyList(); - } else { - this.globalClasspaths = Arrays.asList(globalClasspaths); - } + public RemoteEnvironment(String host, int port, Configuration clientConfig, String[] jarFiles, URL[] globalClasspaths) { + super(validateAndGetEffectiveConfiguration(clientConfig, host, port, jarFiles, globalClasspaths)); } - // + private static Configuration validateAndGetEffectiveConfiguration( + final Configuration configuration, + final String host, + final int port, + final String[] jarFiles, + final URL[] globalClasspaths) { + RemoteEnvironmentConfigUtils.validate(host, port); + return getEffectiveConfiguration( + getClientConfiguration(configuration), + host, + port, + jarFiles, + getClasspathURLs(globalClasspaths)); + } - @Override - public JobExecutionResult execute(String jobName) throws Exception { - final Plan p = createProgramPlan(jobName); + private static Configuration getClientConfiguration(final Configuration configuration) { + return configuration == null ? new Configuration() : configuration; + } - final PlanExecutor executor = PlanExecutor.createRemoteExecutor(host, port, clientConfiguration); - lastJobExecutionResult = executor.executePlan(p, jarFiles, globalClasspaths); - return lastJobExecutionResult; + private static List getClasspathURLs(final URL[] classpaths) { + return classpaths == null ? Collections.emptyList() : Arrays.asList(classpaths); + } + + private static Configuration getEffectiveConfiguration( + final Configuration baseConfiguration, + final String host, + final int port, + final String[] jars, + final List classpaths) { + + final Configuration effectiveConfiguration = new Configuration(baseConfiguration); + + RemoteEnvironmentConfigUtils.setJobManagerAddressToConfig(host, port, effectiveConfiguration); +
[GitHub] [flink] kl0u commented on a change in pull request #10346: [FLINK-14972] Make Remote(Stream)Environment use Executors.
kl0u commented on a change in pull request #10346: [FLINK-14972] Make Remote(Stream)Environment use Executors. URL: https://github.com/apache/flink/pull/10346#discussion_r352009886 ## File path: flink-clients/src/main/java/org/apache/flink/client/deployment/executors/RemoteExecutor.java ## @@ -0,0 +1,31 @@ +/* + * 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.deployment.executors; + +import org.apache.flink.annotation.Internal; +import org.apache.flink.core.execution.Executor; + +/** + * The {@link Executor} to be used when executing a job on an already running cluster. + */ +@Internal +public class RemoteExecutor extends StandaloneSessionClusterExecutor { Review comment: Good point @TisonKun ! Thanks for spotting this. I will address that. 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: us...@infra.apache.org With regards, Apache Git Services
[GitHub] [flink] kl0u commented on a change in pull request #10346: [FLINK-14972] Make Remote(Stream)Environment use Executors.
kl0u commented on a change in pull request #10346: [FLINK-14972] Make Remote(Stream)Environment use Executors. URL: https://github.com/apache/flink/pull/10346#discussion_r351718421 ## File path: flink-java/src/main/java/org/apache/flink/api/java/RemoteEnvironment.java ## @@ -111,58 +93,59 @@ public RemoteEnvironment(String host, int port, Configuration clientConfig, Stri * protocol (e.g. file://) and be accessible on all nodes (e.g. by means of a NFS share). * The protocol must be supported by the {@link java.net.URLClassLoader}. */ - public RemoteEnvironment(String host, int port, Configuration clientConfig, - String[] jarFiles, URL[] globalClasspaths) { - if (!ExecutionEnvironment.areExplicitEnvironmentsAllowed()) { - throw new InvalidProgramException( - "The RemoteEnvironment cannot be instantiated when running in a pre-defined context " + - "(such as Command Line Client, Scala Shell, or TestEnvironment)"); - } - if (host == null) { - throw new NullPointerException("Host must not be null."); - } - if (port < 1 || port >= 0x) { - throw new IllegalArgumentException("Port out of range"); - } - - this.host = host; - this.port = port; - this.clientConfiguration = clientConfig == null ? new Configuration() : clientConfig; - if (jarFiles != null) { - this.jarFiles = new ArrayList<>(jarFiles.length); - for (String jarFile : jarFiles) { - try { - this.jarFiles.add(new File(jarFile).getAbsoluteFile().toURI().toURL()); - } catch (MalformedURLException e) { - throw new IllegalArgumentException("JAR file path invalid", e); - } - } - } - else { - this.jarFiles = Collections.emptyList(); - } - - if (globalClasspaths == null) { - this.globalClasspaths = Collections.emptyList(); - } else { - this.globalClasspaths = Arrays.asList(globalClasspaths); - } + public RemoteEnvironment(String host, int port, Configuration clientConfig, String[] jarFiles, URL[] globalClasspaths) { + super(validateAndGetEffectiveConfiguration(clientConfig, host, port, jarFiles, globalClasspaths)); } - // + private static Configuration validateAndGetEffectiveConfiguration( + final Configuration configuration, + final String host, + final int port, + final String[] jarFiles, + final URL[] globalClasspaths) { + RemoteEnvironmentConfigUtils.validate(host, port); + return getEffectiveConfiguration( + getClientConfiguration(configuration), + host, + port, + jarFiles, + getClasspathURLs(globalClasspaths)); + } - @Override - public JobExecutionResult execute(String jobName) throws Exception { - final Plan p = createProgramPlan(jobName); + private static Configuration getClientConfiguration(final Configuration configuration) { + return configuration == null ? new Configuration() : configuration; + } - final PlanExecutor executor = PlanExecutor.createRemoteExecutor(host, port, clientConfiguration); - lastJobExecutionResult = executor.executePlan(p, jarFiles, globalClasspaths); - return lastJobExecutionResult; + private static List getClasspathURLs(final URL[] classpaths) { + return classpaths == null ? Collections.emptyList() : Arrays.asList(classpaths); + } + + private static Configuration getEffectiveConfiguration( + final Configuration baseConfiguration, + final String host, + final int port, + final String[] jars, + final List classpaths) { + + final Configuration effectiveConfiguration = new Configuration(baseConfiguration); + + RemoteEnvironmentConfigUtils.setJobManagerAddressToConfig(host, port, effectiveConfiguration); +