Github user zentol commented on a diff in the pull request:

    https://github.com/apache/flink/pull/6199#discussion_r197377877
  
    --- Diff: 
flink-clients/src/main/java/org/apache/flink/client/program/rest/RestClusterClient.java
 ---
    @@ -323,17 +325,18 @@ public JobSubmissionResult submitJob(JobGraph 
jobGraph, ClassLoader classLoader)
                        (BlobServerPortResponseBody response, String 
dispatcherAddress) -> {
                                final int blobServerPort = response.port;
                                final InetSocketAddress address = new 
InetSocketAddress(dispatcherAddress, blobServerPort);
    -                           final List<PermanentBlobKey> keys;
    -                           try {
    -                                   log.info("Uploading jar files.");
    -                                   keys = BlobClient.uploadFiles(address, 
flinkConfig, jobGraph.getJobID(), jobGraph.getUserJars());
    -                                   jobGraph.uploadUserArtifacts(address, 
flinkConfig);
    -                           } catch (IOException ioe) {
    -                                   throw new CompletionException(new 
FlinkException("Could not upload job files.", ioe));
    -                           }
     
    -                           for (PermanentBlobKey key : keys) {
    -                                   jobGraph.addUserJarBlobKey(key);
    +                           List<Path> userJars = jobGraph.getUserJars();
    +                           Map<String, 
DistributedCache.DistributedCacheEntry> userArtifacts = 
jobGraph.getUserArtifacts();
    +                           if (!userJars.isEmpty() || 
!userArtifacts.isEmpty()) {
    +                                   try (BlobClient client = new 
BlobClient(address, flinkConfig)) {
    --- End diff --
    
    alternatively we could refactor the try-with-resource statement and 
exception handling into a method that accepts a function, which would be used 
like this:
    
    ```
    ClientUtils.withBlobClient(address, flinkConfig, () -> {
        log.info("Uploading jar files.");
        ClientUtils.uploadAndSetUserJars(jobGraph, client);
        log.info("Uploading jar artifacts.");
        ClientUtils.uploadAndSetUserArtifacts(jobGraph, client);
    }
    ```


---

Reply via email to