From 620f163397de190ea0bbbfad1f8dfac580bcc418 Mon Sep 17 00:00:00 2001 From: Beryl Snyder Date: Fri, 17 Apr 2020 12:01:54 -0500 Subject: [PATCH 1/2] changed s3 artifact uploads to use parallelstream changed artifactUrls to use ConcurrentHashMap --- .../JCloudsArtifactManager.java | 33 +++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/main/java/io/jenkins/plugins/artifact_manager_jclouds/JCloudsArtifactManager.java b/src/main/java/io/jenkins/plugins/artifact_manager_jclouds/JCloudsArtifactManager.java index f6ee5e13..ff8f5ce9 100644 --- a/src/main/java/io/jenkins/plugins/artifact_manager_jclouds/JCloudsArtifactManager.java +++ b/src/main/java/io/jenkins/plugins/artifact_manager_jclouds/JCloudsArtifactManager.java @@ -55,6 +55,7 @@ import java.util.Collection; import java.util.HashMap; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; import java.util.logging.Level; import java.util.logging.Logger; import jenkins.MasterToSlaveFileCallable; @@ -121,19 +122,23 @@ public void archive(FilePath workspace, Launcher launcher, BuildListener listene LOGGER.log(Level.FINE, "Archiving from {0}: {1}", new Object[] { workspace, artifacts }); Map contentTypes = workspace.act(new ContentTypeGuesser(new ArrayList<>(artifacts.keySet()), listener)); LOGGER.fine(() -> "guessing content types: " + contentTypes); - Map artifactUrls = new HashMap<>(); + Map artifactUrls = new ConcurrentHashMap<>(); BlobStore blobStore = getContext().getBlobStore(); - - // Map artifacts to urls for upload - for (Map.Entry entry : artifacts.entrySet()) { + // Map artifacts to urls for upload + artifacts.entrySet().parallelStream().forEach(entry -> { + try{ String path = "artifacts/" + entry.getKey(); String blobPath = getBlobPath(path); Blob blob = blobStore.blobBuilder(blobPath).build(); blob.getMetadata().setContainer(provider.getContainer()); blob.getMetadata().getContentMetadata().setContentType(contentTypes.get(entry.getKey())); artifactUrls.put(entry.getValue(), provider.toExternalURL(blob, HttpMethod.PUT)); - } - + } + catch (Exception e) { + // at the very least you want to log the exception, otherwise debugging will be difficult + listener.getLogger().printf("ERROR in artifacts: %s artifact \n", e); + } + }); workspace.act(new UploadToBlobStorage(artifactUrls, contentTypes, listener)); listener.getLogger().printf("Uploaded %s artifact(s) to %s%n", artifactUrls.size(), provider.toURI(provider.getContainer(), getBlobPath("artifacts/"))); } @@ -185,13 +190,15 @@ private static class UploadToBlobStorage extends MasterToSlaveFileCallable @Override public Void invoke(File f, VirtualChannel channel) throws IOException, InterruptedException { - try { - for (Map.Entry entry : artifactUrls.entrySet()) { - client.uploadFile(new File(f, entry.getKey()), contentTypes.get(entry.getKey()), entry.getValue(), listener); - } - } finally { - listener.getLogger().flush(); - } + artifactUrls.entrySet().parallelStream().forEach(entry -> { // entry is a Map.Entry + try { + client.uploadFile(new File(f, entry.getKey()), contentTypes.get(entry.getKey()), entry.getValue(), listener); + } catch (Exception e) { + // at the very least you want to log the exception, otherwise debugging will be hard + listener.getLogger().printf("ERROR in invoke (upload): %s artifact \n", e); + } + }); + listener.getLogger().flush(); return null; } } From bd2e7caca15be7d7bff588e259efc3d8710b72d9 Mon Sep 17 00:00:00 2001 From: beryl-factset <61850204+beryl-factset@users.noreply.github.com> Date: Wed, 6 May 2020 15:35:38 -0500 Subject: [PATCH 2/2] Update JCloudsArtifactManager.java swapped /n to %n per error --- .../artifact_manager_jclouds/JCloudsArtifactManager.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/jenkins/plugins/artifact_manager_jclouds/JCloudsArtifactManager.java b/src/main/java/io/jenkins/plugins/artifact_manager_jclouds/JCloudsArtifactManager.java index ff8f5ce9..fe00508e 100644 --- a/src/main/java/io/jenkins/plugins/artifact_manager_jclouds/JCloudsArtifactManager.java +++ b/src/main/java/io/jenkins/plugins/artifact_manager_jclouds/JCloudsArtifactManager.java @@ -136,7 +136,7 @@ public void archive(FilePath workspace, Launcher launcher, BuildListener listene } catch (Exception e) { // at the very least you want to log the exception, otherwise debugging will be difficult - listener.getLogger().printf("ERROR in artifacts: %s artifact \n", e); + listener.getLogger().printf("ERROR in artifacts: %s artifact %n", e); } }); workspace.act(new UploadToBlobStorage(artifactUrls, contentTypes, listener)); @@ -195,7 +195,7 @@ public Void invoke(File f, VirtualChannel channel) throws IOException, Interrupt client.uploadFile(new File(f, entry.getKey()), contentTypes.get(entry.getKey()), entry.getValue(), listener); } catch (Exception e) { // at the very least you want to log the exception, otherwise debugging will be hard - listener.getLogger().printf("ERROR in invoke (upload): %s artifact \n", e); + listener.getLogger().printf("ERROR in invoke (upload): %s artifact %n", e); } }); listener.getLogger().flush();