JCLOUDS-489 - Adds support to Cloud Files for the iOS Streaming URI

This commit is contained in:
Jeremy Daggett 2014-03-07 11:20:21 -08:00 committed by Everett Toews
parent a45a24d4a1
commit c3d341a680
7 changed files with 90 additions and 73 deletions

View File

@ -16,8 +16,15 @@
*/
package org.jclouds.cloudfiles.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties;
import java.net.URI;
import javax.inject.Named;
import org.jclouds.javax.annotation.Nullable;
/**
*
* @author James Murty
@ -26,23 +33,32 @@ import java.net.URI;
public class ContainerCDNMetadata implements Comparable<ContainerCDNMetadata> {
private String name;
private boolean cdn_enabled;
private boolean log_retention;
@Named("cdn_enabled")
private boolean cdnEnabled;
@Named("log_retention")
private boolean logRetention;
private long ttl;
private URI cdn_uri;
private URI cdn_ssl_uri;
private URI cdn_streaming_uri;
private String referrer_acl;
private String useragent_acl;
@Named("cdn_uri")
private URI cdnUri;
@Named("cdn_ssl_uri")
private URI cdnSslUri;
@Named("cdn_streaming_uri")
private URI cdnStreamingUri;
@Named("cdn_ios_uri")
private URI cdnIosUri;
public ContainerCDNMetadata(String name, boolean cdnEnabled, boolean logRetention, long ttl, URI cdnUri, URI cdnSslUri, URI cdnStreamingUri) {
this.name = name;
this.cdn_enabled = cdnEnabled;
this.log_retention = logRetention;
this.ttl = ttl;
this.cdn_uri = cdnUri;
this.cdn_ssl_uri = cdnSslUri;
this.cdn_streaming_uri = cdnStreamingUri;
@ConstructorProperties({ "name", "cdn_enabled", "log_retention", "ttl", "cdn_uri", "cdn_ssl_uri",
"cdn_streaming_uri", "cdn_ios_uri"})
public ContainerCDNMetadata(String name, boolean cdnEnabled, boolean logRetention, long ttl,
@Nullable URI cdnUri, @Nullable URI cdnSslUri, @Nullable URI cdnStreamingUri, @Nullable URI cdnIosUri) {
this.name = checkNotNull(name, "name");
this.cdnEnabled = checkNotNull(cdnEnabled);
this.logRetention = checkNotNull(logRetention);
this.ttl = checkNotNull(ttl);
this.cdnUri = cdnUri;
this.cdnSslUri = cdnSslUri;
this.cdnStreamingUri = cdnStreamingUri;
this.cdnIosUri = cdnIosUri;
}
public ContainerCDNMetadata() {
@ -57,11 +73,11 @@ public class ContainerCDNMetadata implements Comparable<ContainerCDNMetadata> {
}
public boolean isCDNEnabled() {
return cdn_enabled;
return cdnEnabled;
}
public boolean isLogRetention() {
return log_retention;
return logRetention;
}
public long getTTL() {
@ -69,23 +85,19 @@ public class ContainerCDNMetadata implements Comparable<ContainerCDNMetadata> {
}
public URI getCDNUri() {
return cdn_uri;
return cdnUri;
}
public URI getCDNSslUri() {
return cdn_ssl_uri;
return cdnSslUri;
}
public URI getCDNStreamingUri() {
return cdn_streaming_uri;
return cdnStreamingUri;
}
public String getReferrerACL() {
return referrer_acl;
}
public String getUseragentACL() {
return useragent_acl;
public URI getCDNIosUri() {
return cdnIosUri;
}
public int compareTo(ContainerCDNMetadata o) {
@ -98,7 +110,7 @@ public class ContainerCDNMetadata implements Comparable<ContainerCDNMetadata> {
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((cdn_uri == null) ? 0 : cdn_uri.hashCode());
result = prime * result + ((cdnUri == null) ? 0 : cdnUri.hashCode());
return result;
}
@ -112,10 +124,10 @@ public class ContainerCDNMetadata implements Comparable<ContainerCDNMetadata> {
return false;
ContainerCDNMetadata other = (ContainerCDNMetadata) obj;
if (cdn_uri == null) {
if (other.cdn_uri != null)
if (cdnUri == null) {
if (other.cdnUri != null)
return false;
} else if (!cdn_uri.equals(other.cdn_uri))
} else if (!cdnUri.equals(other.cdnUri))
return false;
return true;
@ -124,7 +136,7 @@ public class ContainerCDNMetadata implements Comparable<ContainerCDNMetadata> {
@Override
public String toString() {
return String.format(
"[name=%s, cdn_enabled=%s, log_retention=%s, ttl=%s, cdn_uri=%s, cdn_ssl_uri=%s, cdn_streaming_uri=%s, referrer_acl=%s, useragent_acl=%s]",
name, cdn_enabled, log_retention, ttl, cdn_uri, cdn_ssl_uri, cdn_streaming_uri, referrer_acl, useragent_acl);
"[name=%s, cdnEnabled=%s, logRetention=%s, ttl=%s, cdnUri=%s, cdnSslUri=%s, cdnStreamingUri=%s, cdnIosUri=%s]",
name, cdnEnabled, logRetention, ttl, cdnUri, cdnSslUri, cdnStreamingUri, cdnIosUri);
}
}

View File

@ -16,9 +16,12 @@
*/
package org.jclouds.cloudfiles.functions;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Lists.newArrayList;
import java.net.URI;
import java.util.List;
import org.jclouds.cloudfiles.domain.ContainerCDNMetadata;
import org.jclouds.cloudfiles.reference.CloudFilesHeaders;
@ -27,11 +30,14 @@ import org.jclouds.http.HttpResponse;
import org.jclouds.rest.InvocationContext;
import com.google.common.base.Function;
import com.google.common.base.Splitter;
import com.google.common.collect.Iterables;
/**
* This parses {@link AccountMetadata} from HTTP headers.
*
* @author James Murty
* @author Jeremy Daggett
*/
public class ParseContainerCDNMetadataFromHeaders implements
Function<HttpResponse, ContainerCDNMetadata>, InvocationContext<ParseContainerCDNMetadataFromHeaders> {
@ -48,21 +54,20 @@ public class ParseContainerCDNMetadataFromHeaders implements
String cdnUri = checkNotNull(from.getFirstHeaderOrNull(CloudFilesHeaders.CDN_URI), CloudFilesHeaders.CDN_URI);
String cdnSslUri = checkNotNull(from.getFirstHeaderOrNull(CloudFilesHeaders.CDN_SSL_URI), CloudFilesHeaders.CDN_SSL_URI);
String cdnStreamingUri = checkNotNull(from.getFirstHeaderOrNull(CloudFilesHeaders.CDN_STREAMING_URI), CloudFilesHeaders.CDN_STREAMING_URI);
String cdnIosUri = checkNotNull(from.getFirstHeaderOrNull(CloudFilesHeaders.CDN_IOS_URI), CloudFilesHeaders.CDN_IOS_URI);
if (cdnUri == null) {
// CDN is not, and has never, been enabled for this container.
return null;
}
else {
return new ContainerCDNMetadata(
request.getEndpoint().getPath(),
Boolean.parseBoolean(cdnEnabled),
Boolean.parseBoolean(cdnLogRetention),
Long.parseLong(cdnTTL),
URI.create(cdnUri),
URI.create(cdnSslUri),
URI.create(cdnStreamingUri));
}
List<String> parts = newArrayList(Splitter.on('/').split(request.getEndpoint().getPath()));
checkArgument(!parts.isEmpty(), "incorrect path: " + request.getEndpoint().getPath());
return new ContainerCDNMetadata(
Iterables.getLast(parts),
Boolean.parseBoolean(cdnEnabled),
Boolean.parseBoolean(cdnLogRetention),
Long.parseLong(cdnTTL),
URI.create(cdnUri),
URI.create(cdnSslUri),
URI.create(cdnStreamingUri),
URI.create(cdnIosUri));
}
@Override

View File

@ -34,8 +34,7 @@ public interface CloudFilesHeaders extends SwiftHeaders {
public static final String CDN_URI = "X-CDN-URI";
public static final String CDN_SSL_URI = "X-Cdn-Ssl-Uri";
public static final String CDN_STREAMING_URI = "X-Cdn-Streaming-Uri";
public static final String CDN_REFERRER_ACL = "X-Referrer-ACL ";
public static final String CDN_USER_AGENT_ACL = "X-User-Agent-ACL";
public static final String CDN_IOS_URI = "X-Cdn-Ios-Uri";
public static final String CDN_CONTAINER_PURGE_OBJECT_EMAIL = "X-Purge-Email";
public static final String CDN_WEBSITE_INDEX = "X-Container-Meta-Web-Index";

View File

@ -33,13 +33,13 @@ import org.testng.annotations.Test;
/**
*
* @author Adrian Cole
* @author Jeremy Daggett
*/
@Test(groups = "unit", testName = "CloudFilesClientExpectTest")
public class CloudFilesClientExpectTest extends BaseCloudFilesRestClientExpectTest {
@Test
public void testDeleteContainerReturnsTrueOn200And404() {
HttpRequest deleteContainer = HttpRequest
.builder()
.method("DELETE")
@ -62,7 +62,7 @@ public class CloudFilesClientExpectTest extends BaseCloudFilesRestClientExpectTe
@Test
public void testGetCDNMetadataWhenResponseIs2xxReturnsContainerCDNMetadata() {
HttpRequest cdnContainerRequest = HttpRequest.builder()
HttpRequest cdnContainerRequest = HttpRequest.builder()
.method("HEAD")
.endpoint("https://cdn3.clouddrive.com/v1/MossoCloudFS_83a9d536-2e25-4166-bd3b-a503a934f953/container")
.addHeader("X-Auth-Token", authToken)
@ -75,6 +75,7 @@ public class CloudFilesClientExpectTest extends BaseCloudFilesRestClientExpectTe
.addHeader(CloudFilesHeaders.CDN_URI, "http://546406d62bf471d7435d-36c33e76d676c80251b3c13ecb603b67.r19.cf1.rackcdn.com")
.addHeader(CloudFilesHeaders.CDN_SSL_URI, "https://e9f6fe92d217dc013369-36c33e76d676c80251b3c13ecb603b67.ssl.cf1.rackcdn.com")
.addHeader(CloudFilesHeaders.CDN_STREAMING_URI, "http://0e79346bc0a2564dcc5e-36c33e76d676c80251b3c13ecb603b67.r19.stream.cf1.rackcdn.com")
.addHeader(CloudFilesHeaders.CDN_IOS_URI, "http://552e06d62bf471d7435d-36c33e76d676c80251b3c13ecb603b67.r11.iosr.cf1.rackcdn.com")
.statusCode(204)
.build();
@ -88,11 +89,12 @@ public class CloudFilesClientExpectTest extends BaseCloudFilesRestClientExpectTe
assertEquals(containerCDNMetadata.getCDNUri().toString(), "http://546406d62bf471d7435d-36c33e76d676c80251b3c13ecb603b67.r19.cf1.rackcdn.com");
assertEquals(containerCDNMetadata.getCDNSslUri().toString(), "https://e9f6fe92d217dc013369-36c33e76d676c80251b3c13ecb603b67.ssl.cf1.rackcdn.com");
assertEquals(containerCDNMetadata.getCDNStreamingUri().toString(), "http://0e79346bc0a2564dcc5e-36c33e76d676c80251b3c13ecb603b67.r19.stream.cf1.rackcdn.com");
assertEquals(containerCDNMetadata.getCDNIosUri().toString(), "http://552e06d62bf471d7435d-36c33e76d676c80251b3c13ecb603b67.r11.iosr.cf1.rackcdn.com");
}
@Test
public void testGetCDNMetadataWhenResponseIs404ReturnsNull() {
HttpRequest cdnContainerRequest = HttpRequest.builder()
HttpRequest cdnContainerRequest = HttpRequest.builder()
.method("HEAD")
.endpoint("https://cdn3.clouddrive.com/v1/MossoCloudFS_83a9d536-2e25-4166-bd3b-a503a934f953/container")
.addHeader("X-Auth-Token", authToken)
@ -110,7 +112,7 @@ public class CloudFilesClientExpectTest extends BaseCloudFilesRestClientExpectTe
@Test
public void testUpdateCDNMetadataWhenResponseIs2xxReturnsURI() {
HttpRequest cdnContainerRequest = HttpRequest.builder()
HttpRequest cdnContainerRequest = HttpRequest.builder()
.method("POST")
.endpoint("https://cdn3.clouddrive.com/v1/MossoCloudFS_83a9d536-2e25-4166-bd3b-a503a934f953/container")
.addHeader(CloudFilesHeaders.CDN_TTL, "259200")
@ -125,6 +127,7 @@ public class CloudFilesClientExpectTest extends BaseCloudFilesRestClientExpectTe
.addHeader(CloudFilesHeaders.CDN_URI, "http://546406d62bf471d7435d-36c33e76d676c80251b3c13ecb603b67.r19.cf1.rackcdn.com")
.addHeader(CloudFilesHeaders.CDN_SSL_URI, "https://e9f6fe92d217dc013369-36c33e76d676c80251b3c13ecb603b67.ssl.cf1.rackcdn.com")
.addHeader(CloudFilesHeaders.CDN_STREAMING_URI, "http://0e79346bc0a2564dcc5e-36c33e76d676c80251b3c13ecb603b67.r19.stream.cf1.rackcdn.com")
.addHeader(CloudFilesHeaders.CDN_IOS_URI, "http://552e06d62bf471d7435d-36c33e76d676c80251b3c13ecb603b67.r11.iosr.cf1.rackcdn.com")
.statusCode(204)
.build();
@ -157,7 +160,7 @@ public class CloudFilesClientExpectTest extends BaseCloudFilesRestClientExpectTe
@Test
public void testPurgeCDNObjectWhenResponseIs2xxReturnsTrue() {
HttpRequest cdnContainerRequest = HttpRequest.builder()
HttpRequest cdnContainerRequest = HttpRequest.builder()
.method("DELETE")
.endpoint("https://cdn3.clouddrive.com/v1/MossoCloudFS_83a9d536-2e25-4166-bd3b-a503a934f953/container/foo.txt")
.addHeader("X-Auth-Token", authToken)
@ -175,7 +178,7 @@ public class CloudFilesClientExpectTest extends BaseCloudFilesRestClientExpectTe
@Test
public void testSetCDNStaticWebsiteIndexWhenResponseIs2xxReturnsTrue() {
HttpRequest cdnContainerRequest = HttpRequest.builder()
HttpRequest cdnContainerRequest = HttpRequest.builder()
.method("POST")
.endpoint("https://storage101.lon3.clouddrive.com/v1/MossoCloudFS_83a9d536-2e25-4166-bd3b-a503a934f953/container")
.addHeader(CloudFilesHeaders.CDN_WEBSITE_INDEX, "index.html")
@ -194,7 +197,7 @@ public class CloudFilesClientExpectTest extends BaseCloudFilesRestClientExpectTe
@Test(expectedExceptions = ContainerNotFoundException.class)
public void testSetCDNStaticWebsiteIndexWhenResponseIs404ThrowsException() {
HttpRequest cdnContainerRequest = HttpRequest.builder()
HttpRequest cdnContainerRequest = HttpRequest.builder()
.method("POST")
.endpoint("https://storage101.lon3.clouddrive.com/v1/MossoCloudFS_83a9d536-2e25-4166-bd3b-a503a934f953/container")
.addHeader(CloudFilesHeaders.CDN_WEBSITE_INDEX, "index.html")
@ -213,7 +216,7 @@ public class CloudFilesClientExpectTest extends BaseCloudFilesRestClientExpectTe
@Test
public void testSetCDNStaticWebsiteErrorWhenResponseIs2xxReturnsTrue() {
HttpRequest cdnContainerRequest = HttpRequest.builder()
HttpRequest cdnContainerRequest = HttpRequest.builder()
.method("POST")
.endpoint("https://storage101.lon3.clouddrive.com/v1/MossoCloudFS_83a9d536-2e25-4166-bd3b-a503a934f953/container")
.addHeader(CloudFilesHeaders.CDN_WEBSITE_ERROR, "error.html")
@ -232,7 +235,7 @@ public class CloudFilesClientExpectTest extends BaseCloudFilesRestClientExpectTe
@Test(expectedExceptions = ContainerNotFoundException.class)
public void testSetCDNStaticWebsiteErrorWhenResponseIs404ThrowsException() {
HttpRequest cdnContainerRequest = HttpRequest.builder()
HttpRequest cdnContainerRequest = HttpRequest.builder()
.method("POST")
.endpoint("https://storage101.lon3.clouddrive.com/v1/MossoCloudFS_83a9d536-2e25-4166-bd3b-a503a934f953/container")
.addHeader(CloudFilesHeaders.CDN_WEBSITE_ERROR, "error.html")

View File

@ -109,10 +109,9 @@ public class CloudFilesClientLiveTest extends CommonSwiftClientLiveTest<CloudFil
final long initialTTL = cdnMetadata.getTTL();
final URI cdnSslUri = cdnMetadata.getCDNSslUri();
final URI cdnStreamingUri = cdnMetadata.getCDNStreamingUri();
final URI cdnIosUri = cdnMetadata.getCDNIosUri();
assertTrue(cdnMetadataList.contains(new ContainerCDNMetadata(
containerNameWithCDN, cdnEnabled, logRetention, initialTTL, cdnUri, cdnSslUri, cdnStreamingUri)));
containerNameWithCDN, cdnEnabled, logRetention, initialTTL, cdnUri, cdnSslUri, cdnStreamingUri, cdnIosUri)));
// Test listing with options
cdnMetadataList = getApi().listCDNContainers(ListCdnContainerOptions.Builder.enabledOnly());

View File

@ -56,7 +56,8 @@ public class ParseContainerCDNMetadataListFromJsonResponseTest {
3600,
URI.create("http://c0354712.cdn.cloudfiles.rackspacecloud.com"),
URI.create("https://c0354712.cdn.ssl.cloudfiles.rackspacecloud.com"),
URI.create("http://c0354712.cdn.stream.cloudfiles.rackspacecloud.com")),
URI.create("http://c0354712.cdn.stream.cloudfiles.rackspacecloud.com"),
URI.create("http://c0354712.cdn.iosr.cloudfiles.rackspacecloud.com")),
new ContainerCDNMetadata(
"adriancole-blobstore5",
true,
@ -64,7 +65,8 @@ public class ParseContainerCDNMetadataListFromJsonResponseTest {
28800,
URI.create("http://c0404671.cdn.cloudfiles.rackspacecloud.com"),
URI.create("https://c0404671.cdn.ssl.cloudfiles.rackspacecloud.com"),
URI.create("http://c0404671.cdn.stream.cloudfiles.rackspacecloud.com")),
URI.create("http://c0404671.cdn.stream.cloudfiles.rackspacecloud.com"),
URI.create("http://c0404671.cdn.iosr.cloudfiles.rackspacecloud.com")),
new ContainerCDNMetadata(
"adriancole-cfcdnint.testCDNOperationsContainerWithCDN",
false,
@ -72,8 +74,8 @@ public class ParseContainerCDNMetadataListFromJsonResponseTest {
3600,
URI.create("http://c0320431.cdn.cloudfiles.rackspacecloud.com"),
URI.create("https://c0320431.cdn.ssl.cloudfiles.rackspacecloud.com"),
URI.create("http://c0320431.cdn.stream.cloudfiles.rackspacecloud.com"))
);
URI.create("http://c0320431.cdn.stream.cloudfiles.rackspacecloud.com"),
URI.create("http://c0320431.cdn.iosr.cloudfiles.rackspacecloud.com")));
ParseJson<SortedSet<ContainerCDNMetadata>> parser = i.getInstance(Key
.get(new TypeLiteral<ParseJson<SortedSet<ContainerCDNMetadata>>>() {

View File

@ -7,8 +7,7 @@
"cdn_uri":"http://c0354712.cdn.cloudfiles.rackspacecloud.com",
"cdn_ssl_uri":"https://c0354712.cdn.ssl.cloudfiles.rackspacecloud.com",
"cdn_streaming_uri":"http://c0354712.cdn.stream.cloudfiles.rackspacecloud.com",
"referrer_acl":"",
"useragent_acl":""
"cdn_ios_uri":"http://c0354712.cdn.iosr.cloudfiles.rackspacecloud.com"
},
{
"name":"adriancole-blobstore5",
@ -18,8 +17,7 @@
"cdn_uri":"http://c0404671.cdn.cloudfiles.rackspacecloud.com",
"cdn_ssl_uri":"https://c0404671.cdn.ssl.cloudfiles.rackspacecloud.com",
"cdn_streaming_uri":"http://c0404671.cdn.stream.cloudfiles.rackspacecloud.com",
"referrer_acl":"",
"useragent_acl":""
"cdn_ios_uri":"http://c0404671.cdn.iosr.cloudfiles.rackspacecloud.com"
},
{
"name":"adriancole-cfcdnint.testCDNOperationsContainerWithCDN",
@ -29,7 +27,6 @@
"cdn_uri":"http://c0320431.cdn.cloudfiles.rackspacecloud.com",
"cdn_ssl_uri":"https://c0320431.cdn.ssl.cloudfiles.rackspacecloud.com",
"cdn_streaming_uri":"http://c0320431.cdn.stream.cloudfiles.rackspacecloud.com",
"referrer_acl":"",
"useragent_acl":""
"cdn_ios_uri":"http://c0320431.cdn.iosr.cloudfiles.rackspacecloud.com"
}
]