mirror of https://github.com/apache/jclouds.git
Added HP CDN support back
This commit is contained in:
parent
5d9d03ed7e
commit
96ff7d137a
|
@ -0,0 +1,40 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds 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.hpcloud.objectstorage.lvs;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import javax.inject.Qualifier;
|
||||
|
||||
/**
|
||||
* Represents a component related to HP Cloud Services Content Delivery Network.
|
||||
*
|
||||
* @see <a href="https://manage.hpcloud.com/pages/build/docs/object-storage/api">HP Cloud Object Storage API</a>
|
||||
* @author Jeremy Daggett
|
||||
*
|
||||
*/
|
||||
@Retention(value = RetentionPolicy.RUNTIME)
|
||||
@Target(value = { ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
|
||||
@Qualifier
|
||||
public @interface CDNManagement {
|
||||
|
||||
}
|
|
@ -18,22 +18,36 @@
|
|||
*/
|
||||
package org.jclouds.hpcloud.objectstorage.lvs;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.HEAD;
|
||||
import javax.ws.rs.HeaderParam;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.PUT;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.jclouds.blobstore.functions.ReturnNullOnContainerNotFound;
|
||||
import org.jclouds.hpcloud.objectstorage.lvs.domain.ContainerCDNMetadata;
|
||||
import org.jclouds.hpcloud.objectstorage.lvs.functions.ParseCDNUriFromHeaders;
|
||||
import org.jclouds.hpcloud.objectstorage.lvs.functions.ParseContainerCDNMetadataFromHeaders;
|
||||
import org.jclouds.hpcloud.objectstorage.lvs.functions.ParseContainerMetadataFromHeaders;
|
||||
import org.jclouds.hpcloud.objectstorage.lvs.options.CreateContainerOptions;
|
||||
import org.jclouds.hpcloud.objectstorage.lvs.options.ListCDNContainerOptions;
|
||||
import org.jclouds.hpcloud.objectstorage.lvs.reference.HPCloudObjectStorageLasVegasHeaders;
|
||||
import org.jclouds.openstack.filters.AuthenticateRequest;
|
||||
import org.jclouds.openstack.swift.CommonSwiftAsyncClient;
|
||||
import org.jclouds.openstack.swift.Storage;
|
||||
import org.jclouds.openstack.swift.domain.ContainerMetadata;
|
||||
import org.jclouds.rest.annotations.Endpoint;
|
||||
import org.jclouds.rest.annotations.ExceptionParser;
|
||||
import org.jclouds.rest.annotations.Headers;
|
||||
import org.jclouds.rest.annotations.QueryParams;
|
||||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.annotations.ResponseParser;
|
||||
import org.jclouds.rest.annotations.SkipEncoding;
|
||||
|
@ -75,5 +89,70 @@ public interface HPCloudObjectStorageLasVegasAsyncClient extends CommonSwiftAsyn
|
|||
ListenableFuture<Boolean> createContainer(@PathParam("container") String container,
|
||||
CreateContainerOptions... options);
|
||||
|
||||
/**
|
||||
* @see HPCloudObjectStorageClient#listCDNContainers(ListCDNContainerOptions)
|
||||
*/
|
||||
@Beta
|
||||
@GET
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@QueryParams(keys = "format", values = "json")
|
||||
@Path("/")
|
||||
@Endpoint(CDNManagement.class)
|
||||
ListenableFuture<? extends Set<ContainerCDNMetadata>> listCDNContainers(ListCDNContainerOptions... options);
|
||||
|
||||
/**
|
||||
* @see HPCloudObjectStorageClient#getCDNMetadata(String)
|
||||
*/
|
||||
@Beta
|
||||
@HEAD
|
||||
@ResponseParser(ParseContainerCDNMetadataFromHeaders.class)
|
||||
@ExceptionParser(ReturnNullOnContainerNotFound.class)
|
||||
@Path("/{container}")
|
||||
@Endpoint(CDNManagement.class)
|
||||
ListenableFuture<ContainerCDNMetadata> getCDNMetadata(@PathParam("container") String container);
|
||||
|
||||
/**
|
||||
* @see HPCloudObjectStorageClient#enableCDN(String, long)
|
||||
*/
|
||||
@Beta
|
||||
@PUT
|
||||
@Path("/{container}")
|
||||
@Headers(keys = HPCloudObjectStorageLasVegasHeaders.CDN_ENABLED, values = "True")
|
||||
@ResponseParser(ParseCDNUriFromHeaders.class)
|
||||
@Endpoint(CDNManagement.class)
|
||||
ListenableFuture<URI> enableCDN(@PathParam("container") String container,
|
||||
@HeaderParam(HPCloudObjectStorageLasVegasHeaders.CDN_TTL) long ttl);
|
||||
|
||||
/**
|
||||
* @see HPCloudObjectStorageClient#enableCDN(String)
|
||||
*/
|
||||
@Beta
|
||||
@PUT
|
||||
@Path("/{container}")
|
||||
@Headers(keys = HPCloudObjectStorageLasVegasHeaders.CDN_ENABLED, values = "True")
|
||||
@ResponseParser(ParseCDNUriFromHeaders.class)
|
||||
@Endpoint(CDNManagement.class)
|
||||
ListenableFuture<URI> enableCDN(@PathParam("container") String container);
|
||||
|
||||
/**
|
||||
* @see HPCloudObjectStorageClient#updateCDN(String, long)
|
||||
*/
|
||||
@Beta
|
||||
@POST
|
||||
@Path("/{container}")
|
||||
@ResponseParser(ParseCDNUriFromHeaders.class)
|
||||
@Endpoint(CDNManagement.class)
|
||||
ListenableFuture<URI> updateCDN(@PathParam("container") String container,
|
||||
@HeaderParam(HPCloudObjectStorageLasVegasHeaders.CDN_TTL) long ttl);
|
||||
|
||||
/**
|
||||
* @see HPCloudObjectStorageClient#disableCDN(String)
|
||||
*/
|
||||
@Beta
|
||||
@PUT
|
||||
@Path("/{container}")
|
||||
@Headers(keys = HPCloudObjectStorageLasVegasHeaders.CDN_ENABLED, values = "False")
|
||||
@Endpoint(CDNManagement.class)
|
||||
ListenableFuture<Boolean> disableCDN(@PathParam("container") String container);
|
||||
|
||||
}
|
||||
|
|
|
@ -18,14 +18,19 @@
|
|||
*/
|
||||
package org.jclouds.hpcloud.objectstorage.lvs;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
import org.jclouds.hpcloud.objectstorage.lvs.domain.ContainerCDNMetadata;
|
||||
import org.jclouds.hpcloud.objectstorage.lvs.options.CreateContainerOptions;
|
||||
import org.jclouds.hpcloud.objectstorage.lvs.options.ListCDNContainerOptions;
|
||||
import org.jclouds.openstack.swift.CommonSwiftClient;
|
||||
import org.jclouds.openstack.swift.domain.ContainerMetadata;
|
||||
|
||||
import com.google.common.annotations.Beta;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
||||
/**
|
||||
|
@ -47,4 +52,22 @@ public interface HPCloudObjectStorageLasVegasClient extends CommonSwiftClient {
|
|||
|
||||
ContainerMetadata getContainerMetadata(String container);
|
||||
|
||||
@Beta
|
||||
Set<ContainerCDNMetadata> listCDNContainers(ListCDNContainerOptions... options);
|
||||
|
||||
@Beta
|
||||
ContainerCDNMetadata getCDNMetadata(String container);
|
||||
|
||||
@Beta
|
||||
URI enableCDN(String container, long ttl);
|
||||
|
||||
@Beta
|
||||
URI enableCDN(String container);
|
||||
|
||||
@Beta
|
||||
URI updateCDN(String container, long ttl);
|
||||
|
||||
@Beta
|
||||
boolean disableCDN(String container);
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds 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.hpcloud.objectstorage.lvs.blobstore.functions;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.hpcloud.objectstorage.lvs.HPCloudObjectStorageLasVegasClient;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class EnableCDNAndCache implements Function<String, URI> {
|
||||
private final LoadingCache<String, URI> cdnContainer;
|
||||
private final HPCloudObjectStorageLasVegasClient sync;
|
||||
|
||||
@Inject
|
||||
public EnableCDNAndCache(HPCloudObjectStorageLasVegasClient sync, LoadingCache<String, URI> cdnContainer) {
|
||||
this.sync = sync;
|
||||
this.cdnContainer = cdnContainer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public URI apply(String input) {
|
||||
URI uri = sync.enableCDN(input);
|
||||
cdnContainer.put(input, uri);
|
||||
return uri;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds 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.hpcloud.objectstorage.lvs.blobstore.functions;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Provider;
|
||||
import javax.inject.Singleton;
|
||||
import javax.ws.rs.core.UriBuilder;
|
||||
|
||||
import org.jclouds.openstack.swift.domain.ObjectInfo;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class PublicUriForObjectInfo implements Function<ObjectInfo, URI> {
|
||||
private final LoadingCache<String, URI> cdnContainer;
|
||||
private final Provider<UriBuilder> uriBuilders;
|
||||
|
||||
@Inject
|
||||
public PublicUriForObjectInfo(LoadingCache<String, URI> cdnContainer, Provider<UriBuilder> uriBuilders) {
|
||||
this.cdnContainer = cdnContainer;
|
||||
this.uriBuilders = uriBuilders;
|
||||
}
|
||||
|
||||
public URI apply(ObjectInfo from) {
|
||||
if (from == null)
|
||||
return null;
|
||||
try {
|
||||
return uriBuilders.get().uri(cdnContainer.getUnchecked(from.getContainer())).path(from.getName()).replaceQuery("")
|
||||
.build();
|
||||
} catch (CacheLoader.InvalidCacheLoadException e) {
|
||||
// nulls not permitted from cache loader
|
||||
return null;
|
||||
} catch (NullPointerException e) {
|
||||
// nulls not permitted from cache loader
|
||||
// TODO this shouldn't occur when the above exception is reliably presented
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds 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.hpcloud.objectstorage.lvs.functions;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.jclouds.hpcloud.objectstorage.lvs.reference.HPCloudObjectStorageLasVegasHeaders;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.openstack.swift.domain.AccountMetadata;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
/**
|
||||
* This parses {@link AccountMetadata} from HTTP headers.
|
||||
*
|
||||
* @author James Murty
|
||||
*/
|
||||
public class ParseCDNUriFromHeaders implements Function<HttpResponse, URI> {
|
||||
|
||||
/**
|
||||
* parses the http response headers to provide the CDN URI string.
|
||||
*/
|
||||
public URI apply(final HttpResponse from) {
|
||||
String cdnUri = checkNotNull(from.getFirstHeaderOrNull(HPCloudObjectStorageLasVegasHeaders.CDN_URI),
|
||||
HPCloudObjectStorageLasVegasHeaders.CDN_URI);
|
||||
return URI.create(cdnUri);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds 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.hpcloud.objectstorage.lvs.functions;
|
||||
|
||||
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.hpcloud.objectstorage.lvs.domain.ContainerCDNMetadata;
|
||||
import org.jclouds.hpcloud.objectstorage.lvs.reference.HPCloudObjectStorageLasVegasHeaders;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.openstack.swift.domain.AccountMetadata;
|
||||
import org.jclouds.rest.InvocationContext;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Splitter;
|
||||
|
||||
/**
|
||||
* This parses {@link AccountMetadata} from HTTP headers.
|
||||
*
|
||||
* @author James Murty
|
||||
*/
|
||||
public class ParseContainerCDNMetadataFromHeaders implements
|
||||
Function<HttpResponse, ContainerCDNMetadata>, InvocationContext<ParseContainerCDNMetadataFromHeaders> {
|
||||
|
||||
private HttpRequest request;
|
||||
|
||||
/**
|
||||
* parses the http response headers to create a new {@link ContainerCDNMetadata} object.
|
||||
*/
|
||||
public ContainerCDNMetadata apply(final HttpResponse from) {
|
||||
String cdnUri = checkNotNull(from.getFirstHeaderOrNull(HPCloudObjectStorageLasVegasHeaders.CDN_URI),
|
||||
HPCloudObjectStorageLasVegasHeaders.CDN_URI);
|
||||
String cdnTTL = checkNotNull(from.getFirstHeaderOrNull(HPCloudObjectStorageLasVegasHeaders.CDN_TTL),
|
||||
HPCloudObjectStorageLasVegasHeaders.CDN_TTL);
|
||||
String cdnEnabled = checkNotNull(from.getFirstHeaderOrNull(HPCloudObjectStorageLasVegasHeaders.CDN_ENABLED),
|
||||
HPCloudObjectStorageLasVegasHeaders.CDN_ENABLED);
|
||||
if (cdnUri == null) {
|
||||
// CDN is not enabled for this container.
|
||||
return null;
|
||||
} else {
|
||||
// just need the name from the path
|
||||
List<String> parts = newArrayList(Splitter.on('/').split(request.getEndpoint().getPath()));
|
||||
|
||||
return new ContainerCDNMetadata(parts.get(parts.size()-1), Boolean
|
||||
.parseBoolean(cdnEnabled), Long.parseLong(cdnTTL), URI.create(cdnUri));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParseContainerCDNMetadataFromHeaders setContext(HttpRequest request) {
|
||||
this.request = request;
|
||||
return this;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue