mirror of https://github.com/apache/jclouds.git
Issue 61: initial implementation of Sun Cloud s3 emualation
git-svn-id: http://jclouds.googlecode.com/svn/trunk@1429 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
parent
09ba1d1360
commit
b8275fda10
|
@ -0,0 +1,49 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
$HeadURL$
|
||||||
|
$Revision$
|
||||||
|
$Date$
|
||||||
|
|
||||||
|
Copyright (C) 2009 Adrian Cole <adrian@jclouds.org>
|
||||||
|
|
||||||
|
====================================================================
|
||||||
|
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.html
|
||||||
|
|
||||||
|
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">
|
||||||
|
<parent>
|
||||||
|
<groupId>org.jclouds</groupId>
|
||||||
|
<artifactId>jclouds-s3-extensions-project</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<relativePath>../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>org.jclouds</groupId>
|
||||||
|
<artifactId>jclouds-s3-suncloud</artifactId>
|
||||||
|
<name>jclouds s3 Sun Cloud Storage Adapter</name>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
<description>jclouds s3 Sun Cloud Storage Adapter</description>
|
||||||
|
|
||||||
|
<scm>
|
||||||
|
<connection>scm:svn:http://jclouds.googlecode.com/svn/trunk/aws/s3/extensions/suncloud</connection>
|
||||||
|
<developerConnection>scm:svn:https://jclouds.googlecode.com/svn/trunk/aws/s3/extensions/suncloud</developerConnection>
|
||||||
|
<url>http://jclouds.googlecode.com/svn/trunk/aws/s3/extensions/suncloud</url>
|
||||||
|
</scm>
|
||||||
|
|
||||||
|
</project>
|
|
@ -0,0 +1,54 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* 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.aws.s3.suncloud.config;
|
||||||
|
|
||||||
|
import org.jclouds.aws.s3.config.LiveS3ConnectionModule;
|
||||||
|
import org.jclouds.aws.s3.config.S3ConnectionModule;
|
||||||
|
import org.jclouds.aws.s3.suncloud.handlers.ParseSunCloudS3ErrorFromXmlContent;
|
||||||
|
import org.jclouds.http.HttpResponseHandler;
|
||||||
|
import org.jclouds.http.annotation.ClientErrorHandler;
|
||||||
|
import org.jclouds.http.annotation.RedirectHandler;
|
||||||
|
import org.jclouds.http.annotation.ServerErrorHandler;
|
||||||
|
import org.jclouds.http.handlers.CloseContentAndSetExceptionHandler;
|
||||||
|
|
||||||
|
import com.google.inject.Scopes;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configures the Sun Cloud S3 connection, including logging and http transport.
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
@S3ConnectionModule
|
||||||
|
public class SunCloudS3ConnectionModule extends LiveS3ConnectionModule {
|
||||||
|
|
||||||
|
protected void bindResponseHandlers() {
|
||||||
|
bind(HttpResponseHandler.class).annotatedWith(RedirectHandler.class).to(
|
||||||
|
CloseContentAndSetExceptionHandler.class).in(Scopes.SINGLETON);
|
||||||
|
bind(HttpResponseHandler.class).annotatedWith(ClientErrorHandler.class).to(
|
||||||
|
ParseSunCloudS3ErrorFromXmlContent.class).in(Scopes.SINGLETON);
|
||||||
|
bind(HttpResponseHandler.class).annotatedWith(ServerErrorHandler.class).to(
|
||||||
|
ParseSunCloudS3ErrorFromXmlContent.class).in(Scopes.SINGLETON);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,33 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* 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.aws.s3.suncloud.domain;
|
||||||
|
|
||||||
|
import org.jclouds.aws.domain.AWSError;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Adrian Cole
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class SunCloudS3Error extends AWSError {
|
||||||
|
}
|
|
@ -0,0 +1,88 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* 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.aws.s3.suncloud.handlers;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.jclouds.aws.AWSResponseException;
|
||||||
|
import org.jclouds.aws.domain.AWSError;
|
||||||
|
import org.jclouds.aws.s3.filters.RequestAuthorizeSignature;
|
||||||
|
import org.jclouds.aws.s3.reference.S3Headers;
|
||||||
|
import org.jclouds.aws.s3.suncloud.domain.SunCloudS3Error;
|
||||||
|
import org.jclouds.aws.s3.xml.S3ParserFactory;
|
||||||
|
import org.jclouds.http.HttpFutureCommand;
|
||||||
|
import org.jclouds.http.HttpResponse;
|
||||||
|
import org.jclouds.http.HttpResponseHandler;
|
||||||
|
import org.jclouds.logging.Logger;
|
||||||
|
import org.jclouds.util.Utils;
|
||||||
|
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This will parse and set an appropriate exception on the command object.
|
||||||
|
*
|
||||||
|
* @see SunCloudS3Error
|
||||||
|
* @author Adrian Cole
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class ParseSunCloudS3ErrorFromXmlContent implements HttpResponseHandler {
|
||||||
|
@Resource
|
||||||
|
protected Logger logger = Logger.NULL;
|
||||||
|
|
||||||
|
private final S3ParserFactory parserFactory;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public ParseSunCloudS3ErrorFromXmlContent(S3ParserFactory parserFactory) {
|
||||||
|
this.parserFactory = parserFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handle(HttpFutureCommand<?> command, HttpResponse response) {
|
||||||
|
SunCloudS3Error error = new SunCloudS3Error();
|
||||||
|
error.setRequestId(response.getFirstHeaderOrNull(S3Headers.REQUEST_ID));
|
||||||
|
error.setRequestToken(response.getFirstHeaderOrNull(S3Headers.REQUEST_TOKEN));
|
||||||
|
InputStream errorStream = response.getContent();
|
||||||
|
try {
|
||||||
|
if (errorStream != null) {
|
||||||
|
error.setMessage(Utils.toStringAndClose(errorStream));
|
||||||
|
//TODO parse the Sun Cloud error.
|
||||||
|
|
||||||
|
// error = parserFactory.createErrorParser().parse(errorStream);
|
||||||
|
// if ("SignatureDoesNotMatch".equals(error.getCode()))
|
||||||
|
// error.setStringSigned(RequestAuthorizeSignature
|
||||||
|
// .createStringToSign(command.getRequest()));
|
||||||
|
// error.setRequestToken(response
|
||||||
|
// .getFirstHeaderOrNull(S3Headers.REQUEST_TOKEN));
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.warn(e, "error parsing XML reponse: %1$s", response);
|
||||||
|
} finally {
|
||||||
|
command.setException(new AWSResponseException(command, response, error));
|
||||||
|
IOUtils.closeQuietly(errorStream);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,35 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* 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.aws.s3.suncloud.reference;
|
||||||
|
|
||||||
|
import org.jclouds.aws.s3.reference.S3Constants;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configuration properties and constants used in S3 connections from Sun Cloud Storage
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
public interface SunCloudS3Constants extends S3Constants {
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,61 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* 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.aws.s3.suncloud.xml;
|
||||||
|
|
||||||
|
import org.jclouds.aws.domain.AWSError;
|
||||||
|
import org.jclouds.aws.s3.suncloud.domain.SunCloudS3Error;
|
||||||
|
import org.jclouds.http.commands.callables.xml.ParseSax;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses the error from the Sun Cloud S3 REST API.
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
public class SunCloudS3ErrorHandler extends ParseSax.HandlerWithResult<AWSError> {
|
||||||
|
|
||||||
|
private SunCloudS3Error error = new SunCloudS3Error();
|
||||||
|
private StringBuilder currentText = new StringBuilder();
|
||||||
|
|
||||||
|
public AWSError getResult() {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void endElement(String uri, String name, String qName) {
|
||||||
|
// TODO parse the actual error coming back from Sun Cloud
|
||||||
|
if (qName.equals("Code")) {
|
||||||
|
error.setCode(currentText.toString());
|
||||||
|
} else if (qName.equals("Message")) {
|
||||||
|
error.setMessage(currentText.toString());
|
||||||
|
} else if (qName.equalsIgnoreCase("RequestId")) {
|
||||||
|
error.setRequestId(currentText.toString());
|
||||||
|
} else if (!qName.equals("Error")) {
|
||||||
|
error.getDetails().put(qName, currentText.toString());
|
||||||
|
}
|
||||||
|
currentText = new StringBuilder();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void characters(char ch[], int start, int length) {
|
||||||
|
currentText.append(ch, start, length);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,50 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* 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.aws.s3.suncloud.xml.config;
|
||||||
|
|
||||||
|
import org.jclouds.aws.domain.AWSError;
|
||||||
|
import org.jclouds.aws.s3.suncloud.xml.SunCloudS3ErrorHandler;
|
||||||
|
import org.jclouds.aws.s3.xml.S3ParserFactory;
|
||||||
|
import org.jclouds.aws.s3.xml.config.S3ParserModule;
|
||||||
|
import org.jclouds.http.commands.callables.xml.ParseSax;
|
||||||
|
|
||||||
|
import com.google.inject.TypeLiteral;
|
||||||
|
import com.google.inject.assistedinject.FactoryProvider;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the factories needed to interpret S3 responses from Sun Cloud Storage Object Service
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
public class SunCloudS3ParserModule extends S3ParserModule {
|
||||||
|
protected void bindErrorHandler() {
|
||||||
|
TypeLiteral<S3ParserFactory.GenericParseFactory<AWSError>> errorTypeLiteral = new TypeLiteral<S3ParserFactory.GenericParseFactory<AWSError>>() {
|
||||||
|
};
|
||||||
|
bind(new TypeLiteral<ParseSax.HandlerWithResult<AWSError>>() {
|
||||||
|
}).to(SunCloudS3ErrorHandler.class);
|
||||||
|
bind(errorTypeLiteral).toProvider(
|
||||||
|
FactoryProvider.newFactory(errorTypeLiteral, new TypeLiteral<ParseSax<AWSError>>() {
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,54 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* 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.aws.s3.suncloud;
|
||||||
|
|
||||||
|
import org.jclouds.aws.s3.S3ConnectionIntegrationTest;
|
||||||
|
import org.jclouds.aws.s3.S3ContextFactory;
|
||||||
|
import org.jclouds.aws.s3.suncloud.config.SunCloudS3ConnectionModule;
|
||||||
|
import org.jclouds.aws.s3.suncloud.xml.config.SunCloudS3ParserModule;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This performs the same test as {@link S3ConnectionIntegrationTest}, except using Sun Cloud
|
||||||
|
* Storage.
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
@Test(enabled = false, groups = { "live" }, testName = "s3.suncloud.SunCloudS3ConnectionLiveTest")
|
||||||
|
public class SunCloudS3ConnectionLiveTest extends S3ConnectionIntegrationTest {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean debugEnabled() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected S3ContextFactory buildS3ContextFactory(String AWSAccessKeyId, String AWSSecretAccessKey) {
|
||||||
|
return S3ContextFactory.createContext(AWSAccessKeyId, AWSSecretAccessKey).withModules(
|
||||||
|
new SunCloudS3ConnectionModule(), new SunCloudS3ParserModule()).withHttpAddress(
|
||||||
|
"object.storage.network.com").withHttpSecure(false).withHttpPort(80);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue