Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modified S3 uploads to be done in parallel #114

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String, String> contentTypes = workspace.act(new ContentTypeGuesser(new ArrayList<>(artifacts.keySet()), listener));
LOGGER.fine(() -> "guessing content types: " + contentTypes);
Map<String, URL> artifactUrls = new HashMap<>();
Map<String, URL> artifactUrls = new ConcurrentHashMap<>();
BlobStore blobStore = getContext().getBlobStore();

// Map artifacts to urls for upload
for (Map.Entry<String, String> entry : artifacts.entrySet()) {
// Map artifacts to urls for upload
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spacing issue here.

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/")));
}
Expand Down Expand Up @@ -185,13 +190,15 @@ private static class UploadToBlobStorage extends MasterToSlaveFileCallable<Void>

@Override
public Void invoke(File f, VirtualChannel channel) throws IOException, InterruptedException {
try {
for (Map.Entry<String, URL> 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<String, URL>
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;
}
}
Expand Down