XComp commented on a change in pull request #16286: URL: https://github.com/apache/flink/pull/16286#discussion_r663822386
########## File path: flink-clients/src/main/java/org/apache/flink/client/deployment/application/FromJarEntryClassInformationProvider.java ########## @@ -0,0 +1,102 @@ +/* + * 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.client.program.PackagedProgramUtils; +import org.apache.flink.util.Preconditions; + +import javax.annotation.Nullable; + +import java.io.File; +import java.util.Optional; + +/** + * {@code FromJarEntryClassInformationProvider} is used for cases where the Jar archive is + * explicitly specified. + */ +public class FromJarEntryClassInformationProvider implements EntryClassInformationProvider { + + private final File jarFile; + private final String jobClassName; + + /** + * Creates a {@code FromJarEntryClassInformationProvider} for a custom Jar archive. At least the + * {@code jarFile} or the {@code jobClassName} has to be set. + * + * @param jarFile The Jar archive. + * @param jobClassName The name of the job class. + * @return The {@code FromJarEntryClassInformationProvider} referring to the passed information. + */ + public static FromJarEntryClassInformationProvider createFromCustomJar( + @Nullable File jarFile, @Nullable String jobClassName) { + return new FromJarEntryClassInformationProvider(jarFile, jobClassName); + } + + /** + * Creates a {@code FromJarEntryClassInformationProvider} for a job implemented in Python. + * + * @return A {@code FromJarEntryClassInformationProvider} for a job implemented in Python + */ + public static FromJarEntryClassInformationProvider createFromPythonJar() { + return new FromJarEntryClassInformationProvider( + new File(PackagedProgramUtils.getPythonJar().getPath()), + PackagedProgramUtils.getPythonDriverClassName()); + } + + private FromJarEntryClassInformationProvider( + @Nullable File jarFile, @Nullable String jobClassName) { + Preconditions.checkArgument( + jarFile != null || jobClassName != null, + "Either the jar file or the job class name, or both need to be set."); + this.jarFile = jarFile; + this.jobClassName = jobClassName; + } + + /** + * Returns the specified {@code jarFile}. If no {@code jarFile} was specified it can only return + * an empty {@code Optional} if the {@code jobClassName} is specified instead. In that case, the + * caller should assume that the passed job class can be found on the system classpath. + * + * @return The specified {@code jarFile}. If returning an empty {@code Optional} the caller + * should assume to find the job class on the system classpath. + * @see #getJobClassName() + */ + @Override + public Optional<File> getJarFile() { + return Optional.ofNullable(jarFile); + } + + /** + * Returns the specified job class name that is either available in the corresponding {@code + * jarFile} or, if the {@code jarFile} is not set, should be assumed to be contained in the + * system classpath. It can return an emtpy {@code Optional} if the respective {@code jarFile} + * is set. In that case one should assume the job class being the entry class of the respective Review comment: I agree, but that would not reflect the original code. That's why I didn't add it. We also have to consider the fact that the entry class is not specified in the jar archive. In that case setting the job class name explicitly makes sense -- 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: issues-unsubscr...@flink.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org