Issue 440, 429: decoupled openstack swift from cloudfiles

This commit is contained in:
Adrian Cole 2011-01-09 11:49:59 -08:00
parent 17629960cd
commit e00b465c78
92 changed files with 240 additions and 48 deletions

View File

@ -43,7 +43,8 @@ our compute api supports: aws-ec2, gogrid, cloudservers (generic), cloudservers-
our blobstore api supports: aws-s3, cloudfiles (generic), cloudfiles-us, cloudfiles-uk,
azurestorage, atmosonline (generic), synaptic, peer1-storage,
s3 (generic), walrus(generic), googlestorage, scaleup-storage,
ecc-s3, transient (in-mem), filesystem (on-disk)
ecc-s3, swift (generic), transient (in-mem),
filesystem (on-disk)
* note * the pom dependency org.jclouds/jclouds-allblobstore gives you access to
to all of these providers

View File

@ -69,6 +69,11 @@
<artifactId>jclouds-atmos</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jclouds.api</groupId>
<artifactId>swift</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jclouds.api</groupId>
<artifactId>cloudfiles</artifactId>

View File

@ -44,13 +44,8 @@
<dependencies>
<dependency>
<groupId>org.jclouds.common</groupId>
<artifactId>rackspace-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-blobstore</artifactId>
<groupId>org.jclouds.api</groupId>
<artifactId>swift</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
@ -62,7 +57,7 @@
</dependency>
<dependency>
<groupId>org.jclouds.common</groupId>
<artifactId>rackspace-common</artifactId>
<artifactId>openstack-common</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
@ -74,6 +69,13 @@
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jclouds.api</groupId>
<artifactId>swift</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-log4j</artifactId>

View File

@ -36,12 +36,12 @@ import javax.ws.rs.core.MediaType;
import org.jclouds.blobstore.functions.ThrowContainerNotFoundOn404;
import org.jclouds.cloudfiles.domain.ContainerCDNMetadata;
import org.jclouds.cloudfiles.functions.ParseCdnUriFromHeaders;
import org.jclouds.cloudfiles.functions.ParseContainerCDNMetadataFromHeaders;
import org.jclouds.cloudfiles.options.ListCdnContainerOptions;
import org.jclouds.cloudfiles.reference.CloudFilesHeaders;
import org.jclouds.openstack.filters.AuthenticateRequest;
import org.jclouds.openstack.swift.CommonSwiftAsyncClient;
import org.jclouds.openstack.swift.Storage;
import org.jclouds.openstack.swift.functions.ParseContainerCDNMetadataFromHeaders;
import org.jclouds.rest.annotations.Endpoint;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.Headers;

View File

@ -17,7 +17,7 @@
* ====================================================================
*/
package org.jclouds.openstack.swift.functions;
package org.jclouds.cloudfiles.functions;
import static com.google.common.base.Preconditions.checkNotNull;

View File

@ -44,7 +44,7 @@
<dependencies>
<dependency>
<groupId>org.jclouds.common</groupId>
<artifactId>rackspace-common</artifactId>
<artifactId>openstack-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
@ -61,7 +61,7 @@
</dependency>
<dependency>
<groupId>org.jclouds.common</groupId>
<artifactId>rackspace-common</artifactId>
<artifactId>openstack-common</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>

View File

@ -39,6 +39,7 @@
<module>elb</module>
<module>walrus</module>
<module>eucalyptus</module>
<module>swift</module>
<module>cloudfiles</module>
<module>cloudservers</module>
</modules>

148
apis/swift/pom.xml Normal file
View File

@ -0,0 +1,148 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
====================================================================
Licensed 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.
====================================================================
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4.0.0.xsd" >
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-project</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../../project/pom.xml</relativePath>
</parent>
<groupId>org.jclouds.api</groupId>
<artifactId>swift</artifactId>
<name>jcloud swift api</name>
<description>jclouds components to access an implementation of OpenStack Swift</description>
<properties>
<test.initializer>org.jclouds.openstack.swift.blobstore.integration.SwiftTestInitializer</test.initializer>
<test.swift.endpoint>http://localhost:11000</test.swift.endpoint>
<test.swift.apiversion>1.0</test.swift.apiversion>
<test.swift.identity>test:tester</test.swift.identity>
<test.swift.credential>testing</test.swift.credential>
</properties>
<dependencies>
<dependency>
<groupId>org.jclouds.common</groupId>
<artifactId>openstack-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-blobstore</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-core</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jclouds.common</groupId>
<artifactId>openstack-common</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-blobstore</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-log4j</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
<scope>test</scope>
</dependency>
</dependencies>
<profiles>
<profile>
<id>live</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<id>integration</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<systemProperties>
<property>
<name>test.swift.endpoint</name>
<value>${test.swift.endpoint}</value>
</property>
<property>
<name>test.swift.apiversion</name>
<value>${test.swift.apiversion}</value>
</property>
<property>
<name>test.swift.identity</name>
<value>${test.swift.identity}</value>
</property>
<property>
<name>test.swift.credential</name>
<value>${test.swift.credential}</value>
</property>
<property>
<name>test.initializer</name>
<value>${test.initializer}</value>
</property>
<property>
<name>jclouds.blobstore.httpstream.url</name>
<value>${jclouds.blobstore.httpstream.url}</value>
</property>
<property>
<name>jclouds.blobstore.httpstream.md5</name>
<value>${jclouds.blobstore.httpstream.md5}</value>
</property>
</systemProperties>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

View File

@ -20,6 +20,7 @@
package org.jclouds.openstack.swift;
import static org.jclouds.blobstore.reference.BlobStoreConstants.PROPERTY_USER_METADATA_PREFIX;
import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS;
import java.util.Properties;
@ -34,6 +35,7 @@ public class SwiftPropertiesBuilder extends PropertiesBuilder {
@Override
protected Properties defaultProperties() {
Properties properties = super.defaultProperties();
properties.setProperty(PROPERTY_REGIONS, "DEFAULT");
properties.setProperty(PROPERTY_USER_METADATA_PREFIX, "X-Object-Meta-");
return properties;
}

View File

@ -23,7 +23,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
import org.jclouds.http.HttpResponse;
import org.jclouds.openstack.swift.domain.AccountMetadata;
import org.jclouds.cloudfiles.reference.CloudFilesHeaders;
import org.jclouds.openstack.swift.reference.SwiftHeaders;
import com.google.common.base.Function;
@ -32,21 +32,16 @@ import com.google.common.base.Function;
*
* @author James Murty
*/
public class ParseAccountMetadataResponseFromHeaders implements
Function<HttpResponse, AccountMetadata> {
public class ParseAccountMetadataResponseFromHeaders implements Function<HttpResponse, AccountMetadata> {
/**
* parses the http response headers to create a new {@link AccountMetadata} object.
*/
public AccountMetadata apply(final HttpResponse from) {
String bytesString = checkNotNull(
from.getFirstHeaderOrNull(CloudFilesHeaders.ACCOUNT_BYTES_USED),
CloudFilesHeaders.ACCOUNT_BYTES_USED);
String containersCountString = checkNotNull(
from.getFirstHeaderOrNull(CloudFilesHeaders.ACCOUNT_CONTAINER_COUNT),
CloudFilesHeaders.ACCOUNT_CONTAINER_COUNT);
return new AccountMetadata(
Long.parseLong(containersCountString),
Long.parseLong(bytesString));
String bytesString = checkNotNull(from.getFirstHeaderOrNull(SwiftHeaders.ACCOUNT_BYTES_USED),
SwiftHeaders.ACCOUNT_BYTES_USED);
String containersCountString = checkNotNull(from.getFirstHeaderOrNull(SwiftHeaders.ACCOUNT_CONTAINER_COUNT),
SwiftHeaders.ACCOUNT_CONTAINER_COUNT);
return new AccountMetadata(Long.parseLong(containersCountString), Long.parseLong(bytesString));
}
}

View File

@ -17,7 +17,7 @@
* ====================================================================
*/
package org.jclouds.openstack.swift.functions;
package org.jclouds.openstack.functions;
import static org.testng.Assert.assertEquals;
@ -29,7 +29,6 @@ import org.jclouds.Constants;
import org.jclouds.blobstore.reference.BlobStoreConstants;
import org.jclouds.http.HttpResponse;
import org.jclouds.openstack.OpenStackAuthAsyncClient.AuthenticationResponse;
import org.jclouds.openstack.functions.ParseAuthenticationResponseFromHeaders;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
@ -61,12 +60,13 @@ public class ParseAuthenticationResponseFromHeadersTest {
public void testReplaceLocalhost() {
ParseAuthenticationResponseFromHeaders parser = i.getInstance(ParseAuthenticationResponseFromHeaders.class);
parser = parser.setHostToReplace("fooman");
HttpResponse response = new HttpResponse(204, "No Content", null, ImmutableMultimap.<String, String> of(
"X-Auth-Token", "token", "X-Storage-Token", "token", "X-Storage-Url", "http://127.0.0.1:8080/v1/token"));
AuthenticationResponse md = parser.apply(response);
assertEquals(md, new AuthenticationResponse("token", ImmutableMap.<String, URI> of("X-Storage-Url", URI
.create("http://127.0.0.1:8080/v1/token"))));
.create("http://fooman:8080/v1/token"))));
}
}

View File

@ -39,8 +39,6 @@ import org.jclouds.blobstore.domain.BlobMetadata;
import org.jclouds.blobstore.domain.PageSet;
import org.jclouds.blobstore.functions.HttpGetOptionsListToGetOptions;
import org.jclouds.blobstore.options.ListContainerOptions;
import org.jclouds.cloudfiles.domain.ContainerCDNMetadata;
import org.jclouds.cloudfiles.options.ListCdnContainerOptions;
import org.jclouds.concurrent.Futures;
import org.jclouds.http.options.GetOptions;
import org.jclouds.openstack.swift.CommonSwiftAsyncClient;
@ -126,10 +124,6 @@ public class StubSwiftAsyncClient implements CommonSwiftAsyncClient {
throw new UnsupportedOperationException();
}
public ListenableFuture<ContainerCDNMetadata> getCDNMetadata(String container) {
throw new UnsupportedOperationException();
}
public ListenableFuture<SwiftObject> getObject(String container, String key, GetOptions... options) {
org.jclouds.blobstore.options.GetOptions getOptions = httpGetOptionsConverter.apply(options);
return Futures.compose(blobStore.getBlob(container, key, getOptions), blob2Object, service);
@ -148,10 +142,6 @@ public class StubSwiftAsyncClient implements CommonSwiftAsyncClient {
}, service);
}
public ListenableFuture<? extends Set<ContainerCDNMetadata>> listCDNContainers(ListCdnContainerOptions... options) {
throw new UnsupportedOperationException();
}
public ListenableFuture<? extends Set<ContainerMetadata>> listContainers(
org.jclouds.openstack.swift.options.ListContainerOptions... options) {
return immediateFuture(Sets.newHashSet(Iterables.transform(blobStore.getContainerToBlobs().keySet(),

View File

@ -23,7 +23,7 @@
Current supported services are:
[transient, filesystem, s3, azureblob, atmos, cloudfiles, walrus,
googlestorage, synaptic, peer1-storage, aws-s3, ecc-s3, cloudfiles-us,
cloufiles-uk]
cloudfiles-uki, swift]
Here's a quick example of how to viewresources in rackspace

View File

@ -29,7 +29,7 @@
<relativePath>../../project/pom.xml</relativePath>
</parent>
<groupId>org.jclouds.common</groupId>
<artifactId>rackspace-common</artifactId>
<artifactId>openstack-common</artifactId>
<name>jclouds Rackspace Components Core</name>
<description>jclouds Core components to access Rackspace apis</description>
<dependencies>

View File

@ -28,12 +28,17 @@ import java.net.URI;
import java.util.Map.Entry;
import javax.annotation.Resource;
import javax.inject.Singleton;
import javax.inject.Inject;
import javax.inject.Provider;
import javax.ws.rs.core.UriBuilder;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.logging.Logger;
import org.jclouds.openstack.OpenStackAuthAsyncClient.AuthenticationResponse;
import org.jclouds.rest.InvocationContext;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMap.Builder;
@ -43,12 +48,20 @@ import com.google.common.collect.ImmutableMap.Builder;
*
* @author Adrian Cole
*/
@Singleton
public class ParseAuthenticationResponseFromHeaders implements Function<HttpResponse, AuthenticationResponse> {
public class ParseAuthenticationResponseFromHeaders implements Function<HttpResponse, AuthenticationResponse>,
InvocationContext<ParseAuthenticationResponseFromHeaders> {
@Resource
protected Logger logger = Logger.NULL;
private final Provider<UriBuilder> uriBuilderProvider;
private String hostToReplace;
@Inject
public ParseAuthenticationResponseFromHeaders(Provider<UriBuilder> uriBuilderProvider) {
this.uriBuilderProvider = uriBuilderProvider;
}
/**
* parses the http response headers to create a new {@link AuthenticationResponse} object.
*/
@ -57,11 +70,32 @@ public class ParseAuthenticationResponseFromHeaders implements Function<HttpResp
Builder<String, URI> builder = ImmutableMap.<String, URI> builder();
for (Entry<String, String> entry : from.getHeaders().entries()) {
if (entry.getKey().endsWith(URL_SUFFIX))
builder.put(entry.getKey(), URI.create(entry.getValue()));
builder.put(entry.getKey(), getURI(entry.getValue()));
}
AuthenticationResponse response = new AuthenticationResponse(checkNotNull(from.getFirstHeaderOrNull(AUTH_TOKEN),
AUTH_TOKEN), builder.build());
logger.debug("will connect to: ", response);
return response;
}
// TODO: find the swift configuration or bug related to returning localhost
protected URI getURI(String headerValue) {
if (headerValue == null)
return null;
URI toReturn = URI.create(headerValue);
if (!"127.0.0.1".equals(toReturn.getHost()))
return toReturn;
return uriBuilderProvider.get().uri(toReturn).host(hostToReplace).build();
}
@Override
public ParseAuthenticationResponseFromHeaders setContext(HttpRequest request) {
return setHostToReplace(request.getEndpoint().getHost());
}
@VisibleForTesting
ParseAuthenticationResponseFromHeaders setHostToReplace(String hostToReplace) {
this.hostToReplace = hostToReplace;
return this;
}
}

View File

@ -34,6 +34,6 @@
<name>jclouds commons project</name>
<modules>
<module>aws</module>
<module>rackspace</module>
<module>openstack</module>
</modules>
</project>

View File

@ -49,6 +49,13 @@
<version>${project.version}</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.jclouds.api</groupId>
<artifactId>swift</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jclouds.api</groupId>
<artifactId>cloudfiles</artifactId>

View File

@ -49,6 +49,13 @@
<version>${project.version}</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.jclouds.api</groupId>
<artifactId>swift</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jclouds.api</groupId>
<artifactId>cloudfiles</artifactId>

View File

@ -44,7 +44,7 @@
<dependencies>
<dependency>
<groupId>org.jclouds.common</groupId>
<artifactId>rackspace-common</artifactId>
<artifactId>openstack-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>

View File

@ -44,7 +44,7 @@
<dependencies>
<dependency>
<groupId>org.jclouds.common</groupId>
<artifactId>rackspace-common</artifactId>
<artifactId>openstack-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>