ferenc-csaky commented on code in PR #24303:
URL: https://github.com/apache/flink/pull/24303#discussion_r1487357451


##########
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:
   It has to be removed by hand to get the updated JAR, or rename the new file. 
Regarding this I was thinking about adding a config option flag to force 
override existing artifacts on the remote.
   
   The same thing might make sense for fetching the artifats as well, but I 
think the 2 things are different so probably would require 2 different flags.



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