Skip to content

Commit

Permalink
v2.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
arnett, stu committed Aug 12, 2015
1 parent 45a9f74 commit fd4ec5a
Show file tree
Hide file tree
Showing 26 changed files with 601 additions and 171 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ buildscript {
apply from: "$commonBuildDir/ecs-publish.gradle"

dependencies {
compile 'com.emc.ecs:smart-client:2.0.2',
compile 'com.emc.ecs:smart-client:2.0.3',
'com.emc.ecs:object-transform:1.0.2',
'org.jdom:jdom2:2.0.6'
testCompile 'junit:junit:4.12'
Expand Down
17 changes: 12 additions & 5 deletions src/main/java/com/emc/object/ObjectConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ public abstract class ObjectConfig<T extends ObjectConfig<T>> {
private String secretKey;
private long serverClockSkew;
private String userAgent = DEFAULT_USER_AGENT;
private EncryptionConfig encryptionConfig;
private boolean geoPinningEnabled = false;

private Map<String, Object> properties = new HashMap<String, Object>();
Expand Down Expand Up @@ -111,7 +110,6 @@ public ObjectConfig(ObjectConfig<T> other) {
this.secretKey = other.secretKey;
this.serverClockSkew = other.serverClockSkew;
this.userAgent = other.userAgent;
if (other.encryptionConfig != null) this.encryptionConfig = new EncryptionConfig(other.encryptionConfig);
this.geoPinningEnabled = other.geoPinningEnabled;
}

Expand Down Expand Up @@ -266,12 +264,18 @@ public void setUserAgent(String userAgent) {
this.userAgent = userAgent;
}

/**
* @deprecated (2.0.3) always returns null (see {@link #setEncryptionConfig(EncryptionConfig)})
*/
public EncryptionConfig getEncryptionConfig() {
return encryptionConfig;
return null;
}

/**
* @deprecated (2.0.3) this method does nothing. EncryptionConfig instance should be passed to the constructor of
* an encryption client
*/
public void setEncryptionConfig(EncryptionConfig encryptionConfig) {
this.encryptionConfig = encryptionConfig;
}

public boolean isGeoPinningEnabled() {
Expand Down Expand Up @@ -344,6 +348,10 @@ public T withUserAgent(String userAgent) {
return (T) this;
}

/**
* @deprecated (2.0.3) this method does nothing. EncryptionConfig instance should be passed to the constructor of
* an encryption client
*/
@SuppressWarnings("unchecked")
public T withEncryptionConfig(EncryptionConfig encryptionConfig) {
setEncryptionConfig(encryptionConfig);
Expand Down Expand Up @@ -375,7 +383,6 @@ public String toString() {
", secretKey='" + secretKey + '\'' +
", serverClockSkew=" + serverClockSkew +
", userAgent='" + userAgent + '\'' +
", encryptionConfig=" + encryptionConfig +
", geoPinningEnabled=" + geoPinningEnabled +
", properties=" + properties +
'}';
Expand Down
15 changes: 11 additions & 4 deletions src/main/java/com/emc/object/s3/S3Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,13 @@
*/
public interface S3Client {
/**
* Always call .shutdown() when finished with a client to ensure that any attached resources and background processes
* are released/terminated (i.e. polling threads for host list providers)
* Always call .destroy() when finished with a client to ensure that any attached resources and background processes
* are released/terminated (i.e. polling threads, host list providers and connection pools)
*/
void destroy();

/**
* @deprecated (2.0.3) use destroy() instead
*/
void shutdown();

Expand Down Expand Up @@ -125,7 +130,8 @@ public interface S3Client {
void setBucketCors(String bucketName, CorsConfiguration corsConfiguration);

/**
* Retrieves the CORS configuration for <code>bucketName</code>
* Retrieves the CORS configuration for <code>bucketName</code>. If no CORS configuration exists for the specified
* bucket, <code>null</code> is returned
*
* @see CorsConfiguration
*/
Expand All @@ -144,7 +150,8 @@ public interface S3Client {
void setBucketLifecycle(String bucketName, LifecycleConfiguration lifecycleConfiguration);

/**
* Retrieves the lifecycle configuration for <code>bucketName</code>
* Retrieves the lifecycle configuration for <code>bucketName</code>. If no lifecycle exists for the specified
* bucket, <code>null</code> is returned
*
* @see LifecycleConfiguration
*/
Expand Down
63 changes: 63 additions & 0 deletions src/main/java/com/emc/object/s3/S3Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@
public class S3Config extends ObjectConfig<S3Config> {
public static final int DEFAULT_HTTP_PORT = 9020;
public static final int DEFAULT_HTTPS_PORT = 9021;
public static final int DEFAULT_INITIAL_RETRY_DELAY = 1000; // ms
public static final int DEFAULT_RETRY_LIMIT = 3;
public static final int DEFAULT_RETRY_BUFFER_SIZE = 2 * 1024 * 1024;

protected static int defaultPort(Protocol protocol) {
if (protocol == Protocol.HTTP) return DEFAULT_HTTP_PORT;
Expand All @@ -72,6 +75,10 @@ protected static int defaultPort(Protocol protocol) {
protected boolean useVHost = false;
protected boolean signNamespace = true;
protected boolean checksumEnabled = true;
protected boolean retryEnabled = true;
protected int initialRetryDelay = DEFAULT_INITIAL_RETRY_DELAY;
protected int retryLimit = DEFAULT_RETRY_LIMIT;
protected int retryBufferSize = DEFAULT_RETRY_BUFFER_SIZE;

/**
* External load balancer constructor (no smart-client).
Expand Down Expand Up @@ -105,6 +112,7 @@ public S3Config(S3Config other) {
this.useVHost = other.useVHost;
this.signNamespace = other.signNamespace;
this.checksumEnabled = other.checksumEnabled;
this.retryEnabled = other.retryEnabled;
}

@Override
Expand Down Expand Up @@ -153,6 +161,41 @@ public void setChecksumEnabled(boolean checksumEnabled) {
this.checksumEnabled = checksumEnabled;
}

public boolean isRetryEnabled() {
return retryEnabled;
}

/**
* Set to false to disable automatic retry of (retriable) requests
*/
public void setRetryEnabled(boolean retryEnabled) {
this.retryEnabled = retryEnabled;
}

public int getInitialRetryDelay() {
return initialRetryDelay;
}

public void setInitialRetryDelay(int initialRetryDelay) {
this.initialRetryDelay = initialRetryDelay;
}

public int getRetryLimit() {
return retryLimit;
}

public void setRetryLimit(int retryLimit) {
this.retryLimit = retryLimit;
}

public int getRetryBufferSize() {
return retryBufferSize;
}

public void setRetryBufferSize(int retryBufferSize) {
this.retryBufferSize = retryBufferSize;
}

public S3Config withUseVHost(boolean useVHost) {
setUseVHost(useVHost);
return this;
Expand All @@ -168,6 +211,26 @@ public S3Config withChecksumEnabled(boolean checksumEnabled) {
return this;
}

public S3Config withRetryEnabled(boolean retryEnabled) {
setRetryEnabled(retryEnabled);
return this;
}

public S3Config withInitialRetryDelay(int initialRetryDelay) {
setInitialRetryDelay(initialRetryDelay);
return this;
}

public S3Config withRetryLimit(int retryLimit) {
setRetryLimit(retryLimit);
return this;
}

public S3Config withRetryBufferSize(int retryBufferSize) {
setRetryBufferSize(retryBufferSize);
return this;
}

@Override
public String toString() {
return "S3Config{" +
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/com/emc/object/s3/bean/CorsRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,35 @@ public CorsRule withAllowedHeaders(List<String> allowedHeaders) {
public CorsRule withAllowedHeaders(String... allowedHeaders) {
return withAllowedHeaders(Arrays.asList(allowedHeaders));
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof CorsRule)) return false;

CorsRule corsRule = (CorsRule) o;

if (id != null ? !id.equals(corsRule.id) : corsRule.id != null) return false;
if (allowedMethods != null ? !allowedMethods.equals(corsRule.allowedMethods) : corsRule.allowedMethods != null)
return false;
if (allowedOrigins != null ? !allowedOrigins.equals(corsRule.allowedOrigins) : corsRule.allowedOrigins != null)
return false;
if (maxAgeSeconds != null ? !maxAgeSeconds.equals(corsRule.maxAgeSeconds) : corsRule.maxAgeSeconds != null)
return false;
if (exposeHeaders != null ? !exposeHeaders.equals(corsRule.exposeHeaders) : corsRule.exposeHeaders != null)
return false;
return !(allowedHeaders != null ? !allowedHeaders.equals(corsRule.allowedHeaders) : corsRule.allowedHeaders != null);

}

@Override
public int hashCode() {
int result = id != null ? id.hashCode() : 0;
result = 31 * result + (allowedMethods != null ? allowedMethods.hashCode() : 0);
result = 31 * result + (allowedOrigins != null ? allowedOrigins.hashCode() : 0);
result = 31 * result + (maxAgeSeconds != null ? maxAgeSeconds.hashCode() : 0);
result = 31 * result + (exposeHeaders != null ? exposeHeaders.hashCode() : 0);
result = 31 * result + (allowedHeaders != null ? allowedHeaders.hashCode() : 0);
return result;
}
}
11 changes: 11 additions & 0 deletions src/main/java/com/emc/object/s3/bean/LifecycleConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@XmlRootElement(name = "LifecycleConfiguration")
Expand All @@ -43,4 +44,14 @@ public List<LifecycleRule> getRules() {
public void setRules(List<LifecycleRule> rules) {
this.rules = rules;
}

public LifecycleConfiguration withRules(List<LifecycleRule> rules) {
setRules(rules);
return this;
}

public LifecycleConfiguration withRules(LifecycleRule... rules) {
setRules(Arrays.asList(rules));
return this;
}
}
16 changes: 14 additions & 2 deletions src/main/java/com/emc/object/s3/jersey/CodecFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import com.emc.rest.smart.SizeOverrideWriter;
import com.sun.jersey.api.client.*;
import com.sun.jersey.api.client.filter.ClientFilter;
import org.apache.log4j.LogMF;
import org.apache.log4j.Logger;

import javax.ws.rs.core.MultivaluedMap;
import java.io.IOException;
Expand All @@ -41,6 +43,8 @@
import java.util.Set;

public class CodecFilter extends ClientFilter {
private static final Logger l4j = Logger.getLogger(CodecFilter.class);

private CodecChain encodeChain;
private Map<String, Object> codecProperties;

Expand All @@ -56,8 +60,16 @@ public ClientResponse handle(ClientRequest request) throws ClientHandlerExceptio
Boolean encode = (Boolean) request.getProperties().get(RestUtil.PROPERTY_ENCODE_ENTITY);
if (encode != null && encode) {

// we don't know what the size will be; this will turn on chunked encoding in the apache client
SizeOverrideWriter.setEntitySize(-1L);
// if encoded size is predictable and we know the original size, we can set a content-length and avoid chunked encoding
Long originalSize = SizeOverrideWriter.getEntitySize();
if (encodeChain.isSizePredictable() && originalSize != null) {
long encodedSize = encodeChain.getEncodedSize(originalSize);
LogMF.debug(l4j, "updating content-length for encoded data (original: {0}, encoded: {1})", originalSize, encodedSize);
SizeOverrideWriter.setEntitySize(encodedSize);
} else {
// we don't know what the size will be; this will turn on chunked encoding in the apache client
SizeOverrideWriter.setEntitySize(-1L);
}

// wrap output stream with encryptor
request.setAdapter(new EncryptAdapter(request.getAdapter(), userMeta));
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/com/emc/object/s3/jersey/GeoPinningFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.filter.ClientFilter;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.log4j.Logger;

import java.nio.ByteBuffer;
import java.util.ArrayList;
Expand All @@ -44,6 +45,8 @@
* the path to extract the object key)
*/
public class GeoPinningFilter extends ClientFilter {
private static final Logger l4j = Logger.getLogger(GeoPinningFilter.class);

private ObjectConfig<?> objectConfig;

public GeoPinningFilter(ObjectConfig<?> objectConfig) {
Expand Down Expand Up @@ -83,9 +86,13 @@ public ClientResponse handle(ClientRequest request) throws ClientHandlerExceptio
if (vdc.isHealthy()) healthyVdcs.add(vdc);
}

int geoPinIndex = getGeoPinIndex(getGeoId(request, bucketName), healthyVdcs.size());
if (healthyVdcs.isEmpty()) {
l4j.warn("there are no healthy VDCs!");
} else {
int geoPinIndex = getGeoPinIndex(getGeoId(request, bucketName), healthyVdcs.size());

request.getProperties().put(GeoPinningRule.PROP_GEO_PINNED_VDC, healthyVdcs.get(geoPinIndex));
request.getProperties().put(GeoPinningRule.PROP_GEO_PINNED_VDC, healthyVdcs.get(geoPinIndex));
}
}

return getNext().handle(request);
Expand Down
Loading

0 comments on commit fd4ec5a

Please sign in to comment.