XComp commented on a change in pull request #15020: URL: https://github.com/apache/flink/pull/15020#discussion_r616071812
########## File path: flink-clients/src/main/java/org/apache/flink/client/deployment/application/PythonBasedPackagedProgramRetriever.java ########## @@ -0,0 +1,56 @@ +/* + * 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.application; + +import org.apache.flink.annotation.Internal; +import org.apache.flink.client.program.PackagedProgram; +import org.apache.flink.client.program.PackagedProgramRetriever; +import org.apache.flink.client.program.PackagedProgramUtils; +import org.apache.flink.client.program.ProgramInvocationException; +import org.apache.flink.configuration.Configuration; + +import javax.annotation.Nullable; + +import java.io.File; +import java.io.IOException; + +/** + * A python based {@link PackagedProgramRetriever} which creates the {@link PackagedProgram} when + * program arguments contain "-py/--python" or "-pym/--pyModule". Review comment: The JavaDoc should only describe what the class is doing. The condition on when to use this class (i.e. "when program arguments contain [...]") is made outside of this class in what's currently called `PackagedProgramRetrieverAdapter.Builder`. ########## File path: flink-clients/src/main/java/org/apache/flink/client/deployment/application/AbstractPackagedProgramRetriever.java ########## @@ -0,0 +1,96 @@ +/* + * 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.application; + +import org.apache.flink.annotation.Internal; +import org.apache.flink.client.program.PackagedProgram; +import org.apache.flink.client.program.PackagedProgramRetriever; +import org.apache.flink.client.program.ProgramInvocationException; +import org.apache.flink.configuration.Configuration; +import org.apache.flink.util.FileUtils; +import org.apache.flink.util.FlinkException; +import org.apache.flink.util.Preconditions; +import org.apache.flink.util.function.FunctionUtils; + +import javax.annotation.Nullable; + +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.stream.Collectors; + +/** + * An abstract {@link PackagedProgramRetriever} which creates the {@link PackagedProgram} containing + * the user's {@code main()} from a class on the class path. + */ +@Internal +public abstract class AbstractPackagedProgramRetriever implements PackagedProgramRetriever { + + private final String[] programArguments; + + private final Configuration configuration; + + /** User class paths in relative form to the working directory. */ + protected final Collection<URL> userClasspaths; + + AbstractPackagedProgramRetriever( + String[] programArguments, Configuration configuration, @Nullable File userLibDirectory) + throws IOException { + this.programArguments = Preconditions.checkNotNull(programArguments); + this.configuration = Preconditions.checkNotNull(configuration); + this.userClasspaths = discoverUserClasspaths(userLibDirectory); + } + + private static Collection<URL> discoverUserClasspaths(@Nullable File jobDir) Review comment: ```suggestion private static List<URL> discoverUserClasspaths(@Nullable File jobDir) ``` This would enable us to not use the `ArrayList` copy constructor in `getPackagedProgram` ########## File path: flink-clients/src/main/java/org/apache/flink/client/deployment/application/PythonBasedPackagedProgramRetriever.java ########## @@ -0,0 +1,56 @@ +/* + * 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.application; + +import org.apache.flink.annotation.Internal; +import org.apache.flink.client.program.PackagedProgram; +import org.apache.flink.client.program.PackagedProgramRetriever; +import org.apache.flink.client.program.PackagedProgramUtils; +import org.apache.flink.client.program.ProgramInvocationException; +import org.apache.flink.configuration.Configuration; + +import javax.annotation.Nullable; + +import java.io.File; +import java.io.IOException; + +/** + * A python based {@link PackagedProgramRetriever} which creates the {@link PackagedProgram} when + * program arguments contain "-py/--python" or "-pym/--pyModule". + */ +@Internal +public class PythonBasedPackagedProgramRetriever extends AbstractPackagedProgramRetriever { + + PythonBasedPackagedProgramRetriever( + String[] programArguments, Configuration configuration, @Nullable File userLibDirectory) + throws IOException { + super(programArguments, configuration, userLibDirectory); + } + + @Override + public PackagedProgram buildPackagedProgram(PackagedProgram.Builder packagedProgramBuilder) + throws ProgramInvocationException { + // It is Python job if program arguments contain "-py/--python" or "-pym/--pyModule", + // set the fixed jobClassName and jarFile path. Review comment: Analogous to what I mentioned already for the JavaDoc of this class: We might not want to add comments for something that's happening outside of this class. ########## File path: flink-container/src/main/java/org/apache/flink/container/entrypoint/StandaloneApplicationClusterEntryPoint.java ########## @@ -62,16 +62,17 @@ public static void main(String[] args) { args, new StandaloneApplicationClusterConfigurationParserFactory(), StandaloneApplicationClusterEntryPoint.class); + final Configuration configuration = Review comment: A minor thing: Usually, it's best to separate the fix from the refactoring, i.e. providing one commit doing the refactoring and another commit fixing the actual issue. ########## File path: flink-clients/src/main/java/org/apache/flink/client/deployment/application/AbstractPackagedProgramRetriever.java ########## @@ -0,0 +1,96 @@ +/* + * 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.application; + +import org.apache.flink.annotation.Internal; +import org.apache.flink.client.program.PackagedProgram; +import org.apache.flink.client.program.PackagedProgramRetriever; +import org.apache.flink.client.program.ProgramInvocationException; +import org.apache.flink.configuration.Configuration; +import org.apache.flink.util.FileUtils; +import org.apache.flink.util.FlinkException; +import org.apache.flink.util.Preconditions; +import org.apache.flink.util.function.FunctionUtils; + +import javax.annotation.Nullable; + +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.stream.Collectors; + +/** + * An abstract {@link PackagedProgramRetriever} which creates the {@link PackagedProgram} containing + * the user's {@code main()} from a class on the class path. + */ +@Internal +public abstract class AbstractPackagedProgramRetriever implements PackagedProgramRetriever { + + private final String[] programArguments; + + private final Configuration configuration; + + /** User class paths in relative form to the working directory. */ + protected final Collection<URL> userClasspaths; + + AbstractPackagedProgramRetriever( + String[] programArguments, Configuration configuration, @Nullable File userLibDirectory) + throws IOException { + this.programArguments = Preconditions.checkNotNull(programArguments); + this.configuration = Preconditions.checkNotNull(configuration); + this.userClasspaths = discoverUserClasspaths(userLibDirectory); Review comment: It think, we could save the `userLibDirectory` as a member here. The actual `discoverUserClasspaths` call could happen in the `build` method later on. -- 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]
