schevalley2 commented on code in PR #24303:
URL: https://github.com/apache/flink/pull/24303#discussion_r1487538828


##########
flink-kubernetes/src/main/java/org/apache/flink/kubernetes/artifact/DefaultKubernetesArtifactUploader.java:
##########
@@ -0,0 +1,122 @@
+/*
+ * 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.kubernetes.artifact;
+
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.flink.client.cli.ArtifactFetchOptions;
+import org.apache.flink.client.program.PackagedProgramUtils;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.PipelineOptions;
+import org.apache.flink.core.fs.FSDataOutputStream;
+import org.apache.flink.core.fs.FileSystem;
+import org.apache.flink.core.fs.Path;
+import org.apache.flink.kubernetes.configuration.KubernetesConfigOptions;
+import org.apache.flink.util.StringUtils;
+import org.apache.flink.util.function.FunctionUtils;
+
+import org.apache.commons.io.FileUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Collections;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import static org.apache.flink.util.Preconditions.checkArgument;
+
+/** Default {@link KubernetesArtifactUploader} implementation. */
+public class DefaultKubernetesArtifactUploader implements 
KubernetesArtifactUploader {
+
+    private static final Logger LOG =
+            LoggerFactory.getLogger(DefaultKubernetesArtifactUploader.class);
+
+    @Override
+    public void uploadAll(Configuration config) throws Exception {
+        if (!config.get(KubernetesConfigOptions.LOCAL_UPLOAD_ENABLED)) {
+            LOG.info(
+                    "Local artifact uploading is disabled. Set '{}' to 
enable.",
+                    KubernetesConfigOptions.LOCAL_UPLOAD_ENABLED.key());
+            return;
+        }
+
+        final String jobUri = upload(config, getJobUri(config));
+        config.set(PipelineOptions.JARS, Collections.singletonList(jobUri));
+
+        final List<String> additionalUris =
+                config.getOptional(ArtifactFetchOptions.ARTIFACT_LIST)
+                        .orElse(Collections.emptyList());
+
+        final List<String> uploadedAdditionalUris =
+                additionalUris.stream()
+                        .map(
+                                FunctionUtils.uncheckedFunction(
+                                        artifactUri -> upload(config, 
artifactUri)))
+                        .collect(Collectors.toList());
+
+        config.set(ArtifactFetchOptions.ARTIFACT_LIST, uploadedAdditionalUris);
+    }
+
+    @VisibleForTesting
+    String upload(Configuration config, String artifactUriStr)
+            throws IOException, URISyntaxException {
+        URI artifactUri = PackagedProgramUtils.resolveURI(artifactUriStr);
+        if (!"local".equals(artifactUri.getScheme())) {
+            return artifactUriStr;
+        }
+
+        final String targetDir = 
config.get(KubernetesConfigOptions.LOCAL_UPLOAD_TARGET);
+        checkArgument(
+                !StringUtils.isNullOrWhitespaceOnly(targetDir),
+                String.format(
+                        "Setting '%s' to a valid remote path is required.",
+                        KubernetesConfigOptions.LOCAL_UPLOAD_TARGET.key()));
+
+        final File src = new File(artifactUri.getPath());
+        final Path target = new Path(targetDir, src.getName());
+        if (target.getFileSystem().exists(target)) {
+            LOG.debug("Skipping artifact '{}', as it already exists.", target);

Review Comment:
   For uploading, actually, it's executed as part of the CLI, no? Maybe it 
could be logged back to the user right on the spot i.e. "we did not send 
udf.jar because it was already there, use --owerwrite to reupload existing 
artifacts".
   
   > but I think the 2 things are different
   
   I agree, here is how I understand it: for fetching, since it's for 
Kubernetes, my assumption is that the artifacts are going to be stored on 
temporary storage. So most of the time artifacts will need to be downloaded 
again and that would work to ship new versions of the jars. The exceptions I 
could think of are:
   
   * the job is interrupted but the task manager is still running and does not 
have to fetch the artifacts again, which is a nice behavior
   * deployment of the job includes a cache, but that means the people managing 
wanted that behavior and know they have to take care of how invalidation works
   



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

Reply via email to