Skip to content

Commit

Permalink
v2.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
arnett, stu committed Jul 8, 2016
1 parent 3ba2362 commit 3533ed9
Show file tree
Hide file tree
Showing 31 changed files with 842 additions and 118 deletions.
27 changes: 27 additions & 0 deletions 3rd-party-licenses/LICENSE-slf4j-api.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Library: slf4j-api
Copyright 2004-2013 QOS.ch
License: MIT
Full License Text:
-----------------------------------------------------------------------------------------------------------------------

Copyright (c) 2004-2013 QOS.ch
All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 changes: 27 additions & 0 deletions 3rd-party-licenses/LICENSE-slf4j-log4j12.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Library: slf4j-log4j12
Copyright 2004-2013 QOS.ch
License: MIT
Full License Text:
-----------------------------------------------------------------------------------------------------------------------

Copyright (c) 2004-2013 QOS.ch
All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
11 changes: 7 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ description = 'EMC Object Client for Java - provides REST access to object data
ext.githubProjectName = 'ecs-object-client-java'

buildscript {
ext.commonBuildVersion = '1.4.1'
ext.commonBuildVersion = '1.5'
ext.commonBuildDir = "https://raw.githubusercontent.com/EMCECS/ecs-common-build/v$commonBuildVersion"
apply from: "$commonBuildDir/ecs-publish.buildscript.gradle", to: buildscript
}
Expand All @@ -39,8 +39,11 @@ allprojects {
}

dependencies {
compile 'com.emc.ecs:smart-client:2.0.7',
'com.emc.ecs:object-transform:1.0.2',
'org.jdom:jdom2:2.0.6'
compile 'com.emc.ecs:smart-client:2.1.0',
'com.emc.ecs:object-transform:1.1.0',
'commons-codec:commons-codec:1.10',
'org.jdom:jdom2:2.0.6',
'org.slf4j:slf4j-api:1.7.5'
runtime 'org.slf4j:slf4j-log4j12:1.7.5'
testCompile 'junit:junit:4.12'
}
14 changes: 8 additions & 6 deletions src/main/java/com/emc/object/AbstractJerseyClient.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, EMC Corporation.
* Copyright (c) 2015-2016, EMC Corporation.
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
Expand Down Expand Up @@ -33,14 +33,16 @@
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.config.ClientConfig;
import com.sun.jersey.client.apache4.config.ApacheHttpClient4Config;
import org.apache.log4j.LogMF;
import org.apache.log4j.Logger;

import java.net.URI;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public abstract class AbstractJerseyClient {
private static final Logger l4j = Logger.getLogger(AbstractJerseyClient.class);

private static final Logger log = LoggerFactory.getLogger(AbstractJerseyClient.class);

protected ObjectConfig objectConfig;

Expand Down Expand Up @@ -69,13 +71,13 @@ protected ClientResponse executeRequest(Client client, ObjectRequest request) {

// if content-length is set (perhaps by user), force jersey to use it
if (entityRequest.getContentLength() != null) {
LogMF.debug(l4j, "enabling content-length override ({0})", entityRequest.getContentLength());
log.debug("enabling content-length override ({})", entityRequest.getContentLength().toString());
SizeOverrideWriter.setEntitySize(entityRequest.getContentLength());

// otherwise chunked encoding will be used. if the request does not support it, try to ensure
// that the entity is buffered (will set content length from buffered write)
} else if (!entityRequest.isChunkable()) {
l4j.debug("no content-length and request is not chunkable, attempting to enable buffering");
log.debug("no content-length and request is not chunkable, attempting to enable buffering");
request.property(ApacheHttpClient4Config.PROPERTY_ENABLE_BUFFERING, Boolean.TRUE);
request.property(ClientConfig.PROPERTY_CHUNKED_ENCODING_SIZE, null);
}
Expand Down
13 changes: 8 additions & 5 deletions src/main/java/com/emc/object/ObjectConfig.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, EMC Corporation.
* Copyright (c) 2015-2016, EMC Corporation.
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
Expand Down Expand Up @@ -30,14 +30,17 @@
import com.emc.rest.smart.Host;
import com.emc.rest.smart.SmartConfig;
import com.emc.rest.smart.ecs.Vdc;
import org.apache.log4j.Logger;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.*;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public abstract class ObjectConfig<T extends ObjectConfig<T>> {
private static final Logger l4j = Logger.getLogger(ObjectConfig.class);

private static final Logger log = LoggerFactory.getLogger(ObjectConfig.class);

public static final String PROPERTY_POLL_PROTOCOL = "com.emc.object.pollProtocol";
public static final String PROPERTY_POLL_PORT = "com.emc.object.pollPort";
Expand Down Expand Up @@ -142,8 +145,8 @@ public URI resolvePath(String relativePath, String rawQuery) {
try {
URI uri = RestUtil.buildUri(protocol.toString().toLowerCase(), resolveHost().getName(), port, path, rawQuery, null);

l4j.debug("raw path & query: " + path + "?" + rawQuery);
l4j.debug("resolved URI: " + uri);
log.debug("raw path & query: " + path + "?" + rawQuery);
log.debug("resolved URI: " + uri);

return uri;
} catch (URISyntaxException e) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/emc/object/ObjectRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class ObjectRequest {
* dynamic path properties such as bucket or namespace. Since this is context-relative, also exclude
* the base context of the service (i.e. /rest for Atmos).
* @param subresource the subresource of the request. This will be the first parameter in the querystring and will
* not have an associated value (i.e. "acl" => ?acl).
* not have an associated value (i.e. "acl" =&gt; ?acl).
*/
public ObjectRequest(Method method, String path, String subresource) {
this.method = method;
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/com/emc/object/s3/LargeFileDownloader.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, EMC Corporation.
* Copyright (c) 2015-2016, EMC Corporation.
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
Expand Down Expand Up @@ -28,7 +28,6 @@

import com.emc.object.Range;
import com.emc.object.s3.request.GetObjectRequest;
import org.apache.log4j.Logger;

import java.io.File;
import java.io.RandomAccessFile;
Expand All @@ -41,12 +40,16 @@
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Convenience class to facilitate multi-threaded download for large objects. This class will split the object
* and download it in parts, transferring several parts simultaneously to maximize efficiency.
*/
public class LargeFileDownloader implements Runnable {
public static final Logger l4j = Logger.getLogger(LargeFileDownloader.class);

private static final Logger log = LoggerFactory.getLogger(LargeFileDownloader.class);

public static final int MIN_PART_SIZE = 2 * 1024 * 1024; // 2MB
public static final int DEFAULT_PART_SIZE = 4 * 1024 * 1024; // 4MB
Expand Down Expand Up @@ -79,7 +82,7 @@ public void run() {
throw new IllegalArgumentException("cannot write to file: " + file.getPath());

if (partSize < MIN_PART_SIZE) {
l4j.warn(String.format("%,dk is below the minimum part size (%,dk). the minimum will be used instead",
log.warn(String.format("%,dk is below the minimum part size (%,dk). the minimum will be used instead",
partSize / 1024, MIN_PART_SIZE / 1024));
partSize = MIN_PART_SIZE;
}
Expand Down
21 changes: 12 additions & 9 deletions src/main/java/com/emc/object/s3/LargeFileUploader.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, EMC Corporation.
* Copyright (c) 2015-2016, EMC Corporation.
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
Expand Down Expand Up @@ -36,7 +36,6 @@
import com.emc.object.util.ProgressInputStream;
import com.emc.object.util.ProgressListener;
import com.emc.rest.util.SizedInputStream;
import org.apache.log4j.Logger;

import java.io.File;
import java.io.FileInputStream;
Expand All @@ -51,12 +50,16 @@
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicLong;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Convenience class to facilitate multipart upload for large files. This class will split the file
* and upload it in parts, transferring several parts simultaneously to maximize efficiency.
*/
public class LargeFileUploader implements Runnable {
private static final Logger l4j = Logger.getLogger(LargeFileUploader.class);

private static final Logger log = LoggerFactory.getLogger(LargeFileUploader.class);

public static final int DEFAULT_THREADS = 8;

Expand Down Expand Up @@ -146,7 +149,7 @@ public void doMultipartUpload() {
try {
s3Client.abortMultipartUpload(new AbortMultipartUploadRequest(bucket, key, uploadId));
} catch (Throwable t) {
l4j.warn("could not abort upload after failure", t);
log.warn("could not abort upload after failure", t);
}
if (e instanceof RuntimeException) throw (RuntimeException) e;
throw new RuntimeException("error during upload", e);
Expand All @@ -159,7 +162,7 @@ public void doMultipartUpload() {
try {
stream.close();
} catch (Throwable t) {
l4j.warn("could not close stream", t);
log.warn("could not close stream", t);
}
}
}
Expand Down Expand Up @@ -197,7 +200,7 @@ public void doByteRangeUpload() {
try {
s3Client.deleteObject(bucket, key);
} catch (Throwable t) {
l4j.warn("could not delete object after failure", t);
log.warn("could not delete object after failure", t);
}
if (e instanceof RuntimeException) throw (RuntimeException) e;
throw new RuntimeException("error during upload", e);
Expand All @@ -210,7 +213,7 @@ public void doByteRangeUpload() {
try {
stream.close();
} catch (Throwable t) {
l4j.warn("could not close stream", t);
log.warn("could not close stream", t);
}
}
}
Expand Down Expand Up @@ -241,11 +244,11 @@ protected void configure() {
if (objectMetadata != null) objectMetadata.setContentLength(null);

long minPartSize = Math.max(MIN_PART_SIZE, fullSize / MAX_PARTS + 1);
l4j.debug(String.format("minimum part size calculated as %,dk", minPartSize / 1024));
log.debug(String.format("minimum part size calculated as %,dk", minPartSize / 1024));

if (partSize == null) partSize = minPartSize;
if (partSize < minPartSize) {
l4j.warn(String.format("%,dk is below the minimum part size (%,dk). the minimum will be used instead",
log.warn(String.format("%,dk is below the minimum part size (%,dk). the minimum will be used instead",
partSize / 1024, minPartSize / 1024));
partSize = minPartSize;
}
Expand Down
14 changes: 8 additions & 6 deletions src/main/java/com/emc/object/s3/S3AuthUtil.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, EMC Corporation.
* Copyright (c) 2015-2016, EMC Corporation.
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
Expand Down Expand Up @@ -31,7 +31,8 @@
import com.emc.object.s3.request.PresignedUrlRequest;
import com.emc.object.util.RestUtil;
import org.apache.commons.codec.binary.Base64;
import org.apache.log4j.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
Expand All @@ -44,7 +45,8 @@
import java.util.*;

public final class S3AuthUtil {
private static final Logger l4j = Logger.getLogger(S3AuthUtil.class);

private static final Logger log = LoggerFactory.getLogger(S3AuthUtil.class);

public static SortedSet<String> SIGNED_PARAMETERS;

Expand Down Expand Up @@ -86,7 +88,7 @@ public static URL generatePresignedUrl(PresignedUrlRequest request, S3Config s3C
resource = "/" + namespace + resource; // prepend to resource path for signing
} else {
// issue warning if namespace is specified and vhost is disabled because we can't put the namespace in the URL
l4j.warn("vHost namespace is disabled, so there is no way to specify a namespace in a pre-signed URL");
log.warn("vHost namespace is disabled, so there is no way to specify a namespace in a pre-signed URL");
}
}

Expand Down Expand Up @@ -170,7 +172,7 @@ public static String getStringToSign(String method, String resource, Map<String,
}

String stringToSignStr = stringToSign.toString();
l4j.debug("stringToSign:\n" + stringToSignStr);
log.debug("stringToSign:\n" + stringToSignStr);
return stringToSignStr;
}

Expand Down Expand Up @@ -212,7 +214,7 @@ public static String getSignature(String stringToSign, String secretKey) {
Mac mac = Mac.getInstance("HmacSHA1");
mac.init(new SecretKeySpec(secretKey.getBytes("UTF-8"), "HmacSHA1")); // AWS does not B64-decode the secret key!
String signature = new String(Base64.encodeBase64(mac.doFinal(stringToSign.getBytes("UTF-8"))));
l4j.debug("signature:\n" + signature);
log.debug("signature:\n" + signature);
return signature;
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException("HmacSHA1 algorithm is not supported on this platform", e);
Expand Down
15 changes: 10 additions & 5 deletions src/main/java/com/emc/object/s3/S3Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -292,30 +292,35 @@ public interface S3Client {

/**
* Reads object <code>key</code> in bucket <code>bucketName</code> and converts it to <code>objectType</code>,
* provided the conversion is supported by the implementation
* provided the conversion is supported by the implementation.
* Note: this method will return <code>null</code> for 304 and 412 responses (failed preconditions)
*/
<T> T readObject(String bucketName, String key, Class<T> objectType);

/**
* Reads version <code>versionId</code> of object <code>key</code> in bucket <code>bucketName</code> and converts
* it to <code>objectType</code>, provided the conversion is supported by the implementation
* it to <code>objectType</code>, provided the conversion is supported by the implementation.
* Note: this method will return <code>null</code> for 304 and 412 responses (failed preconditions)
*/
<T> T readObject(String bucketName, String key, String versionId, Class<T> objectType);

/**
* Reads <code>range</code> bytes of object <code>key</code> in bucket <code>bucketName</code> as a stream
* Reads <code>range</code> bytes of object <code>key</code> in bucket <code>bucketName</code> as a stream.
* Note: this method will return <code>null</code> for 304 and 412 responses (failed preconditions)
*/
InputStream readObjectStream(String bucketName, String key, Range range);

/**
* Gets object <code>key</code> in bucket <code>bucketName</code>. Object details as well as the data stream
* (obtained from {@link GetObjectResult#getObject()} are contained in the {@link GetObjectResult} instance
* (obtained from {@link GetObjectResult#getObject()} are contained in the {@link GetObjectResult} instance.
* Note: this method will return <code>null</code> for 304 and 412 responses (failed preconditions)
*/
GetObjectResult<InputStream> getObject(String bucketName, String key);

/**
* Gets an object using the parameters specified in <code>request</code>. Object details as well as the translated
* data (converted to <code>objectType</code>) are contained in the {@link GetObjectResult} instance
* data (converted to <code>objectType</code>) are contained in the {@link GetObjectResult} instance.
* Note: this method will return <code>null</code> for 304 and 412 responses (failed preconditions)
*/
<T> GetObjectResult<T> getObject(GetObjectRequest request, Class<T> objectType);

Expand Down
Loading

0 comments on commit 3533ed9

Please sign in to comment.