mirror of https://github.com/apache/jclouds.git
JCLOUDS-547: Improved header and option support for Swift/Cloud Files
This commit is contained in:
parent
0c22936ab2
commit
46867d1353
|
@ -48,4 +48,17 @@ public interface CloudFilesApi extends SwiftApi {
|
|||
*/
|
||||
@Delegate
|
||||
CDNApi getCDNApiForRegion(@EndpointParam(parser = RegionToCDNEndpoint.class) @Nullable String region);
|
||||
|
||||
/**
|
||||
* Provides access to Cloud Files CDN features.
|
||||
*
|
||||
* @param region the region to access the CDN API.
|
||||
*
|
||||
* @return the {@link CDNApi} for the specified region.
|
||||
*
|
||||
* @deprecated Please use {@link #getCDNApiForRegion(String)}. This method will be removed in jclouds 1.8.
|
||||
*/
|
||||
@Deprecated
|
||||
@Delegate
|
||||
CDNApi cdnApiInRegion(@EndpointParam(parser = RegionToCDNEndpoint.class) @Nullable String region);
|
||||
}
|
||||
|
|
|
@ -39,12 +39,12 @@ import org.jclouds.Fallbacks.FalseOnNotFoundOr404;
|
|||
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest;
|
||||
import org.jclouds.openstack.swift.v1.options.ListContainerOptions;
|
||||
import org.jclouds.rackspace.cloudfiles.v1.CloudFilesApi;
|
||||
import org.jclouds.rackspace.cloudfiles.v1.binders.BindCDNPurgeEmailAddressesToHeaders;
|
||||
import org.jclouds.rackspace.cloudfiles.v1.domain.CDNContainer;
|
||||
import org.jclouds.rackspace.cloudfiles.v1.functions.ParseCDNContainerFromHeaders;
|
||||
import org.jclouds.rackspace.cloudfiles.v1.functions.ParseCDNContainerURIFromHeaders;
|
||||
import org.jclouds.rackspace.cloudfiles.v1.options.ListCDNContainerOptions;
|
||||
import org.jclouds.rackspace.cloudfiles.v1.options.UpdateCDNContainerOptions;
|
||||
import org.jclouds.rackspace.cloudfiles.v1.reference.CloudFilesHeaders;
|
||||
import org.jclouds.rest.annotations.BinderParam;
|
||||
|
@ -97,7 +97,7 @@ public interface CDNApi extends Closeable {
|
|||
@QueryParams(keys = {"format", "enabled_only"}, values = {"json", "true"})
|
||||
@Fallback(EmptyFluentIterableOnNotFoundOr404.class)
|
||||
@Path("/")
|
||||
FluentIterable<CDNContainer> list(ListContainerOptions options);
|
||||
FluentIterable<CDNContainer> list(ListCDNContainerOptions options);
|
||||
|
||||
/**
|
||||
* Gets the specified CDN Container.
|
||||
|
|
|
@ -0,0 +1,86 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.rackspace.cloudfiles.v1.options;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
import org.jclouds.http.options.BaseHttpRequestOptions;
|
||||
|
||||
/**
|
||||
* Options for listing containers.
|
||||
*
|
||||
* @see {@link org.jclouds.rackspace.cloudfiles.v1.features.CDNAp#list(ListCDNContainerOptions) CDNApi.list(ListCDNContainerOptions)}
|
||||
*/
|
||||
public class ListCDNContainerOptions extends BaseHttpRequestOptions {
|
||||
|
||||
/**
|
||||
* For an integer value <i>n</i>, limits the number of results to <i>n</n>.
|
||||
*/
|
||||
public ListCDNContainerOptions limit(int limit) {
|
||||
checkState(limit >= 0, "limit must be >= 0");
|
||||
checkState(limit <= 10000, "limit must be <= 10000");
|
||||
queryParameters.put("limit", Integer.toString(limit));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a string value <i>x</i>, returns container names greater in value than the specified
|
||||
* {@code marker}. Only strings using UTF-8 encoding are valid. Using {@code marker} provides
|
||||
* a mechanism for iterating through the entire list of containers.
|
||||
*/
|
||||
public ListCDNContainerOptions marker(String marker) {
|
||||
queryParameters.put("marker", checkNotNull(marker, "marker"));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a string value <i>x</i>, returns container names lesser in value than the specified
|
||||
* end marker. Only strings using UTF-8 encoding are valid.
|
||||
*/
|
||||
public ListCDNContainerOptions endMarker(String endMarker) {
|
||||
queryParameters.put("end_marker", checkNotNull(endMarker, "endMarker"));
|
||||
return this;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
/**
|
||||
* @see ListCDNContainerOptions#limit
|
||||
*/
|
||||
public static ListCDNContainerOptions limit(int limit) {
|
||||
ListCDNContainerOptions options = new ListCDNContainerOptions();
|
||||
return options.limit(limit);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ListCDNContainerOptions#marker
|
||||
*/
|
||||
public static ListCDNContainerOptions marker(String marker) {
|
||||
ListCDNContainerOptions options = new ListCDNContainerOptions();
|
||||
return options.marker(marker);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ListCDNContainerOptions#endMarker
|
||||
*/
|
||||
public static ListCDNContainerOptions endMarker(String endMarker) {
|
||||
ListCDNContainerOptions options = new ListCDNContainerOptions();
|
||||
return options.endMarker(endMarker);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -23,11 +23,11 @@ import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.STATIC_WEB_E
|
|||
import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.STATIC_WEB_INDEX;
|
||||
import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.STATIC_WEB_LISTINGS;
|
||||
import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.STATIC_WEB_LISTINGS_CSS;
|
||||
import static org.jclouds.rackspace.cloudfiles.v1.reference.CloudFilesConstants.CDN_TTL_MAX;
|
||||
import static org.jclouds.rackspace.cloudfiles.v1.reference.CloudFilesConstants.CDN_TTL_MIN;
|
||||
import static org.jclouds.rackspace.cloudfiles.v1.reference.CloudFilesHeaders.CDN_ENABLED;
|
||||
import static org.jclouds.rackspace.cloudfiles.v1.reference.CloudFilesHeaders.CDN_LOG_RETENTION;
|
||||
import static org.jclouds.rackspace.cloudfiles.v1.reference.CloudFilesHeaders.CDN_TTL;
|
||||
import static org.jclouds.rackspace.cloudfiles.v1.reference.CloudFilesHeaders.CDN_TTL_MAX;
|
||||
import static org.jclouds.rackspace.cloudfiles.v1.reference.CloudFilesHeaders.CDN_TTL_MIN;
|
||||
|
||||
import org.jclouds.http.options.BaseHttpRequestOptions;
|
||||
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jclouds.rackspace.cloudfiles.v1.reference;
|
||||
|
||||
|
||||
/**
|
||||
* Constants specified by Rackspace Cloud Files.
|
||||
*/
|
||||
public interface CloudFilesConstants {
|
||||
int CDN_TTL_MIN = 900;
|
||||
int CDN_TTL_MAX = 31536000;
|
||||
int CDN_TTL_DEFAULT = 259200;
|
||||
}
|
|
@ -19,13 +19,8 @@ package org.jclouds.rackspace.cloudfiles.v1.reference;
|
|||
import org.jclouds.openstack.swift.v1.reference.SwiftHeaders;
|
||||
|
||||
/**
|
||||
* Additional headers specified by Rackspace Cloud Files CDN.
|
||||
* Additional headers specified by Rackspace Cloud Files.
|
||||
*
|
||||
* @see <a
|
||||
* href="http://docs.rackspace.com/files/api/v1/cf-devguide/content/index.html">
|
||||
* Cloud Files API</a>
|
||||
*
|
||||
* @author Jeremy Daggett
|
||||
*/
|
||||
public interface CloudFilesHeaders extends SwiftHeaders {
|
||||
// Access logs
|
||||
|
@ -40,11 +35,6 @@ public interface CloudFilesHeaders extends SwiftHeaders {
|
|||
String CDN_STREAMING_URI = "X-Cdn-Streaming-Uri";
|
||||
String CDN_IOS_URI = "X-Cdn-Ios-Uri";
|
||||
|
||||
// CDN TTL Limits
|
||||
int CDN_TTL_MIN = 900;
|
||||
int CDN_TTL_MAX = 31536000;
|
||||
int CDN_TTL_DEFAULT = 259200;
|
||||
|
||||
// CDN Purge
|
||||
String CDN_PURGE_OBJECT_EMAIL = "X-Purge-Email";
|
||||
String CDN_PURGE_OBJECT_FAILED = "X-Purge-Failed-Reason";
|
||||
|
|
|
@ -28,17 +28,15 @@ import org.jclouds.http.options.GetOptions;
|
|||
import org.jclouds.io.Payload;
|
||||
import org.jclouds.io.Payloads;
|
||||
import org.jclouds.openstack.swift.v1.features.ObjectApi;
|
||||
import org.jclouds.openstack.swift.v1.options.CreateContainerOptions;
|
||||
import org.jclouds.openstack.swift.v1.options.ListContainerOptions;
|
||||
import org.jclouds.rackspace.cloudfiles.v1.domain.CDNContainer;
|
||||
import org.jclouds.rackspace.cloudfiles.v1.internal.BaseCloudFilesApiLiveTest;
|
||||
import org.jclouds.rackspace.cloudfiles.v1.options.ListCDNContainerOptions;
|
||||
import org.jclouds.rackspace.cloudfiles.v1.options.UpdateCDNContainerOptions;
|
||||
import org.testng.annotations.AfterClass;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.io.ByteSource;
|
||||
|
||||
|
||||
|
@ -101,7 +99,7 @@ public class CloudFilesCDNApiLiveTest extends BaseCloudFilesApiLiveTest {
|
|||
public void testListWithOptions() throws Exception {
|
||||
String lexicographicallyBeforeName = name.substring(0, name.length() - 1);
|
||||
for (String regionId : regions) {
|
||||
ListContainerOptions options = ListContainerOptions.Builder.marker(lexicographicallyBeforeName);
|
||||
ListCDNContainerOptions options = new ListCDNContainerOptions().marker(lexicographicallyBeforeName);
|
||||
|
||||
CDNContainer cdnContainer = api.getCDNApiForRegion(regionId).list(options).get(0);
|
||||
assertCDNContainerNotNull(cdnContainer);
|
||||
|
|
|
@ -35,10 +35,10 @@ import static org.testng.Assert.assertTrue;
|
|||
import java.net.URI;
|
||||
import java.util.List;
|
||||
|
||||
import org.jclouds.openstack.swift.v1.options.ListContainerOptions;
|
||||
import org.jclouds.openstack.v2_0.internal.BaseOpenStackMockTest;
|
||||
import org.jclouds.rackspace.cloudfiles.v1.CloudFilesApi;
|
||||
import org.jclouds.rackspace.cloudfiles.v1.domain.CDNContainer;
|
||||
import org.jclouds.rackspace.cloudfiles.v1.options.ListCDNContainerOptions;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.FluentIterable;
|
||||
|
@ -105,7 +105,7 @@ public class CloudFilesCDNApiMockTest extends BaseOpenStackMockTest<CloudFilesAp
|
|||
|
||||
try {
|
||||
CloudFilesApi api = api(server.getUrl("/").toString(), "rackspace-cloudfiles");
|
||||
ListContainerOptions options = ListContainerOptions.Builder.marker("cdn-container-3");
|
||||
ListCDNContainerOptions options = new ListCDNContainerOptions().marker("cdn-container-3");
|
||||
ImmutableList<CDNContainer> containers = api.getCDNApiForRegion("DFW").list(options).toList();
|
||||
|
||||
for (CDNContainer container : containers) {
|
||||
|
@ -129,7 +129,7 @@ public class CloudFilesCDNApiMockTest extends BaseOpenStackMockTest<CloudFilesAp
|
|||
|
||||
try {
|
||||
CloudFilesApi api = api(server.getUrl("/").toString(), "rackspace-cloudfiles");
|
||||
ListContainerOptions options = ListContainerOptions.Builder.marker("cdn-container-3");
|
||||
ListCDNContainerOptions options = ListCDNContainerOptions.Builder.marker("cdn-container-3");
|
||||
FluentIterable<CDNContainer> containers = api.getCDNApiForRegion("DFW").list(options);
|
||||
|
||||
assertEquals(server.getRequestCount(), 2);
|
||||
|
|
|
@ -21,10 +21,10 @@ import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.STATIC_WEB_E
|
|||
import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.STATIC_WEB_INDEX;
|
||||
import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.STATIC_WEB_LISTINGS;
|
||||
import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.STATIC_WEB_LISTINGS_CSS;
|
||||
import static org.jclouds.rackspace.cloudfiles.v1.reference.CloudFilesConstants.CDN_TTL_MAX;
|
||||
import static org.jclouds.rackspace.cloudfiles.v1.reference.CloudFilesConstants.CDN_TTL_MIN;
|
||||
import static org.jclouds.rackspace.cloudfiles.v1.reference.CloudFilesHeaders.CDN_LOG_RETENTION;
|
||||
import static org.jclouds.rackspace.cloudfiles.v1.reference.CloudFilesHeaders.CDN_TTL;
|
||||
import static org.jclouds.rackspace.cloudfiles.v1.reference.CloudFilesHeaders.CDN_TTL_MAX;
|
||||
import static org.jclouds.rackspace.cloudfiles.v1.reference.CloudFilesHeaders.CDN_TTL_MIN;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
|
Loading…
Reference in New Issue