Skip to content

Commit

Permalink
CloudStorage for S3 and EMCECSStorage not thread-safe fix #1717
Browse files Browse the repository at this point in the history
  • Loading branch information
gunterze committed Dec 3, 2018
1 parent ef444cf commit d438ad2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
public class CloudStorage extends AbstractStorage {

private static final String DEFAULT_CONTAINER = "org.dcm4chee.arc";
private static final Uploader DEFAULT_UPLOADER = new Uploader() {
private static final Uploader STREAMING_UPLOADER = new Uploader() {
@Override
public void upload(BlobStoreContext context, InputStream in, BlobStore blobStore, String container,
String storagePath) throws IOException {
Expand All @@ -87,7 +87,7 @@ public void upload(BlobStoreContext context, InputStream in, BlobStore blobStore
private final AttributesFormat pathFormat;
private final String container;
private final BlobStoreContext context;
private final Uploader uploader;
private final boolean streamingUpload;
private int count;

@Override
Expand All @@ -108,7 +108,7 @@ protected CloudStorage(StorageDescriptor descriptor, Device device) {
endpoint = api.substring(endApi + 1);
api = api.substring(0, endApi);
}
this.uploader = api.endsWith("s3") ? new S3Uploader() : DEFAULT_UPLOADER;
this.streamingUpload = Boolean.parseBoolean(descriptor.getProperty("streamingUpload", null));
ContextBuilder ctxBuilder = ContextBuilder.newBuilder(api);
String identity = descriptor.getProperty("identity", null);
if (identity != null)
Expand Down Expand Up @@ -185,6 +185,7 @@ private void upload(InputStream in, WriteContext ctx) throws IOException {
storagePath = storagePath.substring(0, storagePath.lastIndexOf('/') + 1)
.concat(String.format("%08X", ThreadLocalRandom.current().nextInt()));
}
Uploader uploader = streamingUpload ? STREAMING_UPLOADER : new S3Uploader();
uploader.upload(context, in, blobStore, container, storagePath);
ctx.setStoragePath(storagePath);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
*/
public class EMCECSStorage extends AbstractStorage {

public static final String PROPERTY_STREAMING = "emc-ecs-s3.streaming";
public static final String PROPERTY_URL_CONNECTION_CLIENT_HANDLER = "emc-ecs-s3.URLConnectionClientHandler";

private static final String DEFAULT_CONTAINER = "org.dcm4chee.arc";
Expand All @@ -83,7 +82,7 @@ public void upload(S3Client s3, InputStream in, String container, String storag
private final AttributesFormat pathFormat;
private final String container;
private final S3Client s3;
private final Uploader uploader;
private final boolean streamingUpload;
private int count;

public EMCECSStorage(StorageDescriptor descriptor, Device device) {
Expand All @@ -97,9 +96,7 @@ public EMCECSStorage(StorageDescriptor descriptor, Device device) {
String identity = descriptor.getProperty("identity", null);
if (identity != null)
config.withIdentity(identity).withSecretKey(descriptor.getProperty("credential", null));
this.uploader = Boolean.parseBoolean(descriptor.getProperty(PROPERTY_STREAMING, null))
? STREAMING_UPLOADER
: new S3Uploader();
this.streamingUpload = Boolean.parseBoolean(descriptor.getProperty("streamingUpload", null));
s3 = new S3JerseyClient(config,
Boolean.parseBoolean(descriptor.getProperty(PROPERTY_URL_CONNECTION_CLIENT_HANDLER, null))
? new URLConnectionClientHandler()
Expand Down Expand Up @@ -162,6 +159,7 @@ else while (exists(storagePath)) {
storagePath = storagePath.substring(0, storagePath.lastIndexOf('/') + 1)
.concat(String.format("%08X", ThreadLocalRandom.current().nextInt()));
}
Uploader uploader = streamingUpload ? STREAMING_UPLOADER : new S3Uploader();
uploader.upload(s3, in, container, storagePath);
ctx.setStoragePath(storagePath);
}
Expand Down

0 comments on commit d438ad2

Please sign in to comment.