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..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 @@ -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; } }