Issue 112: first vcloud express functionality

git-svn-id: http://jclouds.googlecode.com/svn/trunk@1979 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
adrian.f.cole 2009-10-14 01:19:18 +00:00
parent ae1ad7498b
commit b4a4bedcc3
38 changed files with 2614 additions and 0 deletions

View File

@ -47,6 +47,7 @@
<module>rackspace</module>
<module>mezeo</module>
<module>nirvanix</module>
<module>vcloudx</module>
</modules>
<build>
<plugins>

53
vcloudx/core/pom.xml Executable file
View File

@ -0,0 +1,53 @@
<?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-vcloudx-project</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-vcloudx-core</artifactId>
<name>jclouds vcloudx Components Core</name>
<packaging>jar</packaging>
<description>jclouds Core components to access vcloudx</description>
<properties>
<jclouds.test.user>${jclouds.vcloudx.user}</jclouds.test.user>
<jclouds.test.key>${jclouds.vcloudx.password}</jclouds.test.key>
<jclouds.test.endpoint>${jclouds.vcloudx.endpoint}</jclouds.test.endpoint>
</properties>
<scm>
<connection>scm:svn:http://jclouds.googlecode.com/svn/trunk/vcloudx/core</connection>
<developerConnection>scm:svn:https://jclouds.googlecode.com/svn/trunk/vcloudx/core</developerConnection>
<url>http://jclouds.googlecode.com/svn/trunk/vcloudx/core</url>
</scm>
</project>

View File

@ -0,0 +1,74 @@
/**
*
* 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.vcloudx;
import java.net.URI;
import java.util.List;
import java.util.Properties;
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
import org.jclouds.logging.jdk.config.JDKLoggingModule;
import org.jclouds.vcloudx.config.BaseRestVCloudXConnectionModule;
import org.jclouds.vcloudx.config.BaseVCloudXContextModule;
import com.google.inject.Injector;
import com.google.inject.Module;
import com.google.inject.TypeLiteral;
/**
* Creates {@link VCloudXContext} or {@link Injector} instances based on the most commonly
* requested arguments.
* <p/>
* Note that Threadsafe objects will be bound as singletons to the Injector or Context provided.
* <p/>
* <p/>
* If no <code>Module</code>s are specified, the default {@link JDKLoggingModule logging} and
* {@link JavaUrlHttpCommandExecutorServiceModule http transports} will be installed.
*
* @author Adrian Cole
* @see CloudFilesContext
*/
public class BaseVCloudXContextBuilder extends VCloudXContextBuilder<VCloudXConnection> {
public BaseVCloudXContextBuilder(URI endpoint, String id, String secret) {
super(new TypeLiteral<VCloudXConnection>(){}, endpoint, id, secret);
}
public BaseVCloudXContextBuilder(Properties props) {
super(new TypeLiteral<VCloudXConnection>(){}, props);
}
@Override
protected void addConnectionModule(List<Module> modules) {
addAuthenticationModule(this);
modules.add(new BaseRestVCloudXConnectionModule());
}
@Override
protected void addContextModule(List<Module> modules) {
modules.add(new BaseVCloudXContextModule());
}
}

View File

@ -0,0 +1,44 @@
/**
*
* 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.vcloudx;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.inject.Qualifier;
/**
* A VCloud Session Token
*
* @author Adrian Cole
*
*/
@Retention(value = RetentionPolicy.RUNTIME)
@Target(value = { ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
@Qualifier
public @interface VCloudToken {
}

View File

@ -0,0 +1,57 @@
/**
*
* 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.vcloudx;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.core.MediaType;
import org.jclouds.rest.annotations.Endpoint;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.XMLResponseParser;
import org.jclouds.vcloudx.domain.OrgLinks;
import org.jclouds.vcloudx.endpoints.Org;
import org.jclouds.vcloudx.filters.SetVCloudTokenCookie;
import org.jclouds.vcloudx.xml.OrgLinksHandler;
/**
* Provides access to VCloudX resources via their REST API.
* <p/>
*
* @see <a href="https://community.vcloudexpress.terremark.com/en-us/discussion_forums/f/60.aspx" />
* @author Adrian Cole
*/
@RequestFilters(SetVCloudTokenCookie.class)
public interface VCloudXConnection {
/**
* This call returns a list of all vCloud Data Centers (vDCs), catalogs, and task lists within
* the organization.
*/
@GET
@Endpoint(Org.class)
@Consumes(MediaType.APPLICATION_XML)
@XMLResponseParser(OrgLinksHandler.class)
OrgLinks getOrganization();
}

View File

@ -0,0 +1,39 @@
/**
*
* 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.vcloudx;
import org.jclouds.cloud.CloudContext;
/**
* Represents an authenticated context to VCloud Express
*
* @see <a href="https://community.vcloudexpress.terremark.com/en-us/discussion_forums/f/60.aspx" />
* @see VCloudXConnection
* @see CloudContext
* @author Adrian Cole
*
*/
public interface VCloudXContext<C extends VCloudXConnection> extends CloudContext<C> {
}

View File

@ -0,0 +1,116 @@
/**
*
* 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.vcloudx;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.vcloudx.reference.VCloudXConstants.PROPERTY_VCLOUDX_ENDPOINT;
import static org.jclouds.vcloudx.reference.VCloudXConstants.PROPERTY_VCLOUDX_KEY;
import static org.jclouds.vcloudx.reference.VCloudXConstants.PROPERTY_VCLOUDX_SESSIONINTERVAL;
import static org.jclouds.vcloudx.reference.VCloudXConstants.PROPERTY_VCLOUDX_USER;
import java.net.URI;
import java.util.Properties;
import org.jclouds.cloud.CloudContextBuilder;
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
import org.jclouds.logging.jdk.config.JDKLoggingModule;
import org.jclouds.vcloudx.config.RestVCloudXAuthenticationModule;
import org.jclouds.vcloudx.reference.VCloudXConstants;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.TypeLiteral;
import com.google.inject.util.Types;
/**
* Creates {@link VCloudXContext} or {@link Injector} instances based on the most commonly requested
* arguments.
* <p/>
* Note that Threadsafe objects will be bound as singletons to the Injector or Context provided.
* <p/>
* <p/>
* If no <code>Module</code>s are specified, the default {@link JDKLoggingModule logging} and
* {@link JavaUrlHttpCommandExecutorServiceModule http transports} will be installed.
*
* @author Adrian Cole
* @see CloudFilesContext
*/
public abstract class VCloudXContextBuilder<C extends VCloudXConnection> extends
CloudContextBuilder<C> {
public VCloudXContextBuilder(TypeLiteral<C> literal, URI endpoint, String id, String secret) {
this(literal, addEndpointTo(endpoint, new Properties()));
authenticate(this, id, secret);
withTokenExpiration(9 * 60);
}
private static Properties addEndpointTo(URI endpoint, Properties properties) {
properties.setProperty(VCloudXConstants.PROPERTY_VCLOUDX_ENDPOINT, checkNotNull(endpoint,
"endpoint").toString());
return properties;
}
public VCloudXContextBuilder(TypeLiteral<C> literal, Properties props) {
super(literal, props);
checkNotNull(properties.getProperty(VCloudXConstants.PROPERTY_VCLOUDX_ENDPOINT),
VCloudXConstants.PROPERTY_VCLOUDX_ENDPOINT);
}
public static <C extends VCloudXConnection> void authenticate(VCloudXContextBuilder<C> builder,
String id, String secret) {
builder.getProperties().setProperty(PROPERTY_VCLOUDX_USER, checkNotNull(id, "user"));
builder.getProperties().setProperty(PROPERTY_VCLOUDX_KEY, checkNotNull(secret, "key"));
}
public static <C extends VCloudXConnection> void addAuthenticationModule(
VCloudXContextBuilder<C> builder) {
builder.withModule(new RestVCloudXAuthenticationModule());
}
public static <C extends VCloudXConnection> VCloudXContextBuilder<C> withEndpoint(
VCloudXContextBuilder<C> builder, URI endpoint) {
builder.getProperties().setProperty(PROPERTY_VCLOUDX_ENDPOINT,
checkNotNull(endpoint, "endpoint").toString());
return builder;
}
public VCloudXContextBuilder<C> withTokenExpiration(long seconds) {
getProperties().setProperty(PROPERTY_VCLOUDX_SESSIONINTERVAL, seconds + "");
return this;
}
@Override
public VCloudXContextBuilder<C> withEndpoint(URI endpoint) {
return (VCloudXContextBuilder<C>) withEndpoint(this, endpoint);
}
@Override
@SuppressWarnings("unchecked")
public VCloudXContext<C> buildContext() {
Injector injector = buildInjector();
return (VCloudXContext<C>) injector.getInstance(Key.get(Types.newParameterizedType(
VCloudXContext.class, connectionType.getType())));
}
}

View File

@ -0,0 +1,69 @@
/**
*
* 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.vcloudx;
import java.net.URI;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.core.MediaType;
import org.jclouds.http.filters.BasicAuthentication;
import org.jclouds.rest.annotations.Endpoint;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.ResponseParser;
import org.jclouds.vcloudx.endpoints.Org;
import org.jclouds.vcloudx.endpoints.VCloudX;
import org.jclouds.vcloudx.functions.ParseLoginResponseFromHeaders;
/**
* Establishes a context with a VCloudX endpoint.
* <p/>
*
* @see <a href="https://community.vcloudexpress.terremark.com/en-us/discussion_forums/f/60.aspx" />
* @author Adrian Cole
*/
@Endpoint(VCloudX.class)
@RequestFilters(BasicAuthentication.class)
public interface VCloudXLogin {
public interface VCloudXSession {
@VCloudToken
String getVCloudToken();
@Org
URI getOrg();
}
/**
* This request returns a token to use in subsequent requests. After ten minutes of inactivity,
* the token expires and you have to request a new token with this call.
*/
@POST
@ResponseParser(ParseLoginResponseFromHeaders.class)
@Path("/login")
@Consumes(MediaType.APPLICATION_XML)
VCloudXSession login();
}

View File

@ -0,0 +1,76 @@
/**
*
* 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.vcloudx;
import javax.ws.rs.core.MediaType;
/**
* Resource Types used in VCloud express
*
* @see MediaType
*/
public class VCloudXMediaType {
/**
* "application/vnd.vmware.vcloud.org+xml"
*/
public final static String ORG_XML = "application/vnd.vmware.vcloud.org+xml";
/**
* "application/vnd.vmware.vcloud.org+xml"
*/
public final static MediaType ORG_XML_TYPE = new MediaType("application",
"vnd.vmware.vcloud.org+xml");
/**
* "application/vnd.vmware.vcloud.vdc+xml"
*/
public final static String VDC_XML = "application/vnd.vmware.vcloud.vdc+xml";
/**
* "application/vnd.vmware.vcloud.vdc+xml"
*/
public final static MediaType VDC_XML_TYPE = new MediaType("application",
"vnd.vmware.vcloud.vdc+xml");
/**
* "application/vnd.vmware.vcloud.catalog+xml"
*/
public final static String CATALOG_XML = "application/vnd.vmware.vcloud.catalog+xml";
/**
* "application/vnd.vmware.vcloud.catalog+xml"
*/
public final static MediaType CATALOG_XML_TYPE = new MediaType("application",
"vnd.vmware.vcloud.catalog+xml");
/**
* "application/vnd.vmware.vcloud.tasksList+xml"
*/
public final static String TASKSLIST_XML = "application/vnd.vmware.vcloud.tasksList+xml";
/**
* "application/vnd.vmware.vcloud.tasksList+xml"
*/
public final static MediaType TASKSLIST_XML_TYPE = new MediaType("application",
"vnd.vmware.vcloud.tasksList+xml");
}

View File

@ -0,0 +1,57 @@
/**
*
* 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.vcloudx.config;
import javax.inject.Singleton;
import org.jclouds.cloud.ConfiguresCloudConnection;
import org.jclouds.http.RequiresHttp;
import org.jclouds.rest.RestClientFactory;
import org.jclouds.vcloudx.VCloudXConnection;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
/**
* Configures the VCloudX authentication service connection, including logging and http
* transport.
*
* @author Adrian Cole
*/
@RequiresHttp
@ConfiguresCloudConnection
public class BaseRestVCloudXConnectionModule extends AbstractModule {
@Override
protected void configure() {
}
@Provides
@Singleton
protected VCloudXConnection provideVCloudXConnection(RestClientFactory factory) {
return factory.create(VCloudXConnection.class);
}
}

View File

@ -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.vcloudx.config;
import java.net.URI;
import javax.inject.Inject;
import javax.inject.Named;
import org.jclouds.cloud.internal.CloudContextImpl;
import org.jclouds.lifecycle.Closer;
import org.jclouds.vcloudx.VCloudXConnection;
import org.jclouds.vcloudx.VCloudXContext;
import org.jclouds.vcloudx.endpoints.Org;
import org.jclouds.vcloudx.reference.VCloudXConstants;
import com.google.inject.AbstractModule;
import com.google.inject.Scopes;
import com.google.inject.TypeLiteral;
/**
* @author Adrian Cole
*/
public class BaseVCloudXContextModule extends AbstractModule {
@Override
protected void configure() {
bind(new TypeLiteral<VCloudXContext<VCloudXConnection>>() {
}).to(VCloudXContextImpl.class).in(Scopes.SINGLETON);
}
public static class VCloudXContextImpl extends CloudContextImpl<VCloudXConnection> implements
VCloudXContext<VCloudXConnection> {
@Inject
public VCloudXContextImpl(Closer closer, VCloudXConnection defaultApi, @Org URI endPoint,
@Named(VCloudXConstants.PROPERTY_VCLOUDX_USER) String account) {
super(closer, defaultApi, endPoint, account);
}
}
}

View File

@ -0,0 +1,112 @@
/**
*
* 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.vcloudx.config;
import static org.jclouds.vcloudx.reference.VCloudXConstants.PROPERTY_VCLOUDX_ENDPOINT;
import static org.jclouds.vcloudx.reference.VCloudXConstants.PROPERTY_VCLOUDX_KEY;
import static org.jclouds.vcloudx.reference.VCloudXConstants.PROPERTY_VCLOUDX_SESSIONINTERVAL;
import static org.jclouds.vcloudx.reference.VCloudXConstants.PROPERTY_VCLOUDX_USER;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.TimeUnit;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.http.RequiresHttp;
import org.jclouds.http.filters.BasicAuthentication;
import org.jclouds.rest.RestClientFactory;
import org.jclouds.vcloudx.VCloudXLogin;
import org.jclouds.vcloudx.VCloudToken;
import org.jclouds.vcloudx.VCloudXLogin.VCloudXSession;
import org.jclouds.vcloudx.endpoints.Org;
import org.jclouds.vcloudx.endpoints.VCloudX;
import com.google.common.base.Function;
import com.google.common.collect.MapMaker;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
/**
* Configures the VCloudX authentication service connection, including logging and http
* transport.
*
* @author Adrian Cole
*/
@RequiresHttp
public class RestVCloudXAuthenticationModule extends AbstractModule {
@Override
protected void configure() {
}
@VCloudToken
@Provides
String provideVCloudToken(ConcurrentMap<String, VCloudXSession> cache) {
return cache.get("doesn't matter").getVCloudToken();
}
@Provides
@Org
protected URI provideOrg(ConcurrentMap<String, VCloudXSession> cache) {
return cache.get("doesn't matter").getOrg();
}
/**
* borrowing concurrency code to ensure that caching takes place properly
*/
@Provides
ConcurrentMap<String, VCloudXSession> provideVCloudTokenCache(
@Named(PROPERTY_VCLOUDX_SESSIONINTERVAL) long seconds, final VCloudXLogin login) {
return new MapMaker().expiration(seconds, TimeUnit.SECONDS).makeComputingMap(
new Function<String, VCloudXSession>() {
public VCloudXSession apply(String key) {
return login.login();
}
});
}
@Provides
@Singleton
@VCloudX
protected URI provideAuthenticationURI(@Named(PROPERTY_VCLOUDX_ENDPOINT) String endpoint) {
return URI.create(endpoint);
}
@Provides
@Singleton
protected VCloudXLogin provideVCloudXLogin(RestClientFactory factory) {
return factory.create(VCloudXLogin.class);
}
@Provides
@Singleton
public BasicAuthentication provideBasicAuthentication(@Named(PROPERTY_VCLOUDX_USER) String user,
@Named(PROPERTY_VCLOUDX_KEY) String key) throws UnsupportedEncodingException {
return new BasicAuthentication(user, key);
}
}

View File

@ -0,0 +1,123 @@
/**
*
* 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.vcloudx.domain;
import java.net.URI;
import java.util.Set;
import javax.inject.Singleton;
/**
* Locations of resources in VCloud Express
*
* @author Adrian Cole
*
*/
@Singleton
public class OrgLinks {
private final String name;
private final URI org;
private final URI catalog;
private final Set<URI> vDCs;
private final Set<URI> taskLists;
public OrgLinks(String name, URI org, URI catalog, Set<URI> vDCs, Set<URI> tasksLists) {
this.name = name;
this.org = org;
this.catalog = catalog;
this.vDCs = vDCs;
this.taskLists = tasksLists;
}
public String getName() {
return name;
}
public URI getOrg() {
return org;
}
public URI getCatalog() {
return catalog;
}
public Set<URI> getVDCs() {
return vDCs;
}
public Set<URI> getTaskLists() {
return taskLists;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((catalog == null) ? 0 : catalog.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((org == null) ? 0 : org.hashCode());
result = prime * result + ((taskLists == null) ? 0 : taskLists.hashCode());
result = prime * result + ((vDCs == null) ? 0 : vDCs.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
OrgLinks other = (OrgLinks) obj;
if (catalog == null) {
if (other.catalog != null)
return false;
} else if (!catalog.equals(other.catalog))
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
if (org == null) {
if (other.org != null)
return false;
} else if (!org.equals(other.org))
return false;
if (taskLists == null) {
if (other.taskLists != null)
return false;
} else if (!taskLists.equals(other.taskLists))
return false;
if (vDCs == null) {
if (other.vDCs != null)
return false;
} else if (!vDCs.equals(other.vDCs))
return false;
return true;
}
}

View File

@ -0,0 +1,44 @@
/**
*
* 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.vcloudx.endpoints;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.inject.Qualifier;
/**
* Related to a VCloud express vDC.
*
* @author Adrian Cole
*
*/
@Retention(value = RetentionPolicy.RUNTIME)
@Target(value = { ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
@Qualifier
public @interface Catalog {
}

View File

@ -0,0 +1,44 @@
/**
*
* 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.vcloudx.endpoints;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.inject.Qualifier;
/**
* Related to a VCloud express Org.
*
* @author Adrian Cole
*
*/
@Retention(value = RetentionPolicy.RUNTIME)
@Target(value = { ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
@Qualifier
public @interface Org {
}

View File

@ -0,0 +1,44 @@
/**
*
* 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.vcloudx.endpoints;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.inject.Qualifier;
/**
* Related to a VCloud express Task List.
*
* @author Adrian Cole
*
*/
@Retention(value = RetentionPolicy.RUNTIME)
@Target(value = { ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
@Qualifier
public @interface TaskList {
}

View File

@ -0,0 +1,45 @@
/**
*
* 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.vcloudx.endpoints;
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 VCloud Express.
*
* @see <a href="https://community.vcloudexpress.terremark.com/en-us/discussion_forums/f/60.aspx" />
* @author Adrian Cole
*
*/
@Retention(value = RetentionPolicy.RUNTIME)
@Target(value = { ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
@Qualifier
public @interface VCloudX {
}

View File

@ -0,0 +1,44 @@
/**
*
* 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.vcloudx.endpoints;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.inject.Qualifier;
/**
* Related to a VCloud express Catalog.
*
* @author Adrian Cole
*
*/
@Retention(value = RetentionPolicy.RUNTIME)
@Target(value = { ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
@Qualifier
public @interface VDC {
}

View File

@ -0,0 +1,57 @@
/**
*
* 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.vcloudx.filters;
import java.util.Collections;
import javax.inject.Inject;
import javax.inject.Provider;
import javax.inject.Singleton;
import org.jclouds.http.HttpException;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpRequestFilter;
import org.jclouds.vcloudx.VCloudToken;
/**
* Adds the VCloud Token to the request as a cookie
*
* @author Adrian Cole
*
*/
@Singleton
public class SetVCloudTokenCookie implements HttpRequestFilter {
private Provider<String> vcloudTokenProvider;
@Inject
public SetVCloudTokenCookie(@VCloudToken Provider<String> authTokenProvider) {
this.vcloudTokenProvider = authTokenProvider;
}
public void filter(HttpRequest request) throws HttpException {
request.getHeaders().replaceValues("Cookie",
Collections.singletonList("vcloud-token=" + vcloudTokenProvider.get()));
}
}

View File

@ -0,0 +1,95 @@
/**
*
* 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.vcloudx.functions;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.inject.Inject;
import javax.inject.Provider;
import javax.ws.rs.core.HttpHeaders;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.HttpResponseException;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ParseSax.Factory;
import org.jclouds.vcloudx.VCloudToken;
import org.jclouds.vcloudx.VCloudXLogin.VCloudXSession;
import org.jclouds.vcloudx.endpoints.Org;
import org.jclouds.vcloudx.xml.OrgListToOrgUriHandler;
import com.google.common.base.Function;
/**
* This parses {@link VCloudXSession} from HTTP headers.
*
* @author Adrian Cole
*/
public class ParseLoginResponseFromHeaders implements Function<HttpResponse, VCloudXSession> {
static final Pattern pattern = Pattern.compile("vcloud-token=(.*); path=.*");
private final ParseSax.Factory factory;
private final Provider<OrgListToOrgUriHandler> orgHandlerProvider;
@Inject
private ParseLoginResponseFromHeaders(Factory factory,
Provider<OrgListToOrgUriHandler> orgHandlerProvider) {
super();
this.factory = factory;
this.orgHandlerProvider = orgHandlerProvider;
}
/**
* parses the http response headers to create a new {@link VCloudXSession} object.
*/
public VCloudXSession apply(HttpResponse from) {
String cookieHeader = checkNotNull(from.getFirstHeaderOrNull(HttpHeaders.SET_COOKIE),
HttpHeaders.SET_COOKIE);
final Matcher matcher = pattern.matcher(cookieHeader);
boolean matchFound = matcher.find();
if (matchFound) {
final URI org = (URI) factory.create(orgHandlerProvider.get()).parse(from.getContent());
return new VCloudXSession() {
@VCloudToken
public String getVCloudToken() {
return matcher.group(1);
}
@Org
public URI getOrg() {
return org;
}
};
} else {
throw new HttpResponseException("vcloud token not found in response ", null, from);
}
}
}

View File

@ -0,0 +1,39 @@
/**
*
* 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.vcloudx.reference;
/**
* Configuration properties and constants used in VCloudX connections.
*
* @author Adrian Cole
*/
public interface VCloudXConstants {
public static final String PROPERTY_VCLOUDX_ENDPOINT = "jclouds.vcloudx.endpoint";
public static final String PROPERTY_VCLOUDX_USER = "jclouds.vcloudx.user";
public static final String PROPERTY_VCLOUDX_KEY = "jclouds.vcloudx.key";
/**
* automatically renew vcloud token before this interval expires.
*/
public static final String PROPERTY_VCLOUDX_SESSIONINTERVAL = "jclouds.vcloudx.sessioninterval";
}

View File

@ -0,0 +1,28 @@
/**
*
* 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.
* ====================================================================
*/
/**
* This package contains properties and reference data used in VCloud Express.
* @author Adrian Cole
*/
package org.jclouds.vcloudx.reference;

View File

@ -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.vcloudx.xml;
import static org.jclouds.vcloudx.VCloudXMediaType.CATALOG_XML;
import static org.jclouds.vcloudx.VCloudXMediaType.TASKSLIST_XML;
import static org.jclouds.vcloudx.VCloudXMediaType.VDC_XML;
import java.net.URI;
import java.util.Set;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.vcloudx.domain.OrgLinks;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import com.google.common.collect.Sets;
/**
* @author Adrian Cole
*/
public class OrgLinksHandler extends ParseSax.HandlerWithResult<OrgLinks> {
private String name;
private URI org;
private Set<URI> vdcs = Sets.newHashSet();
private Set<URI> tasksLists = Sets.newHashSet();
private URI catalog;
public OrgLinks getResult() {
return new OrgLinks(name, org, catalog, vdcs, tasksLists);
}
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes)
throws SAXException {
if (qName.equals("Org")) {
int index = attributes.getIndex("href");
if (index != -1) {
org = URI.create(attributes.getValue(index));
}
index = attributes.getIndex("name");
if (index != -1) {
name = attributes.getValue(index);
}
} else if (qName.equals("Link")) {
int typeIndex = attributes.getIndex("type");
if (typeIndex != -1) {
if (attributes.getValue(typeIndex).equals(VDC_XML)) {
int index = attributes.getIndex("href");
if (index != -1) {
vdcs.add(URI.create(attributes.getValue(index)));
}
} else if (attributes.getValue(typeIndex).equals(CATALOG_XML)) {
int index = attributes.getIndex("href");
if (index != -1) {
catalog = URI.create(attributes.getValue(index));
}
} else if (attributes.getValue(typeIndex).equals(TASKSLIST_XML)) {
int index = attributes.getIndex("href");
if (index != -1) {
tasksLists.add(URI.create(attributes.getValue(index)));
}
}
}
}
}
}

View File

@ -0,0 +1,58 @@
/**
*
* 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.vcloudx.xml;
import java.net.URI;
import static org.jclouds.vcloudx.VCloudXMediaType.*;
import org.jclouds.http.functions.ParseSax;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
/**
* @author Adrian Cole
*/
public class OrgListToOrgUriHandler extends ParseSax.HandlerWithResult<URI> {
private URI org;
public URI getResult() {
return org;
}
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes)
throws SAXException {
if (qName.equals("Org")) {
int typeIndex = attributes.getIndex("type");
if (typeIndex != -1) {
if (attributes.getValue(typeIndex).equals(ORG_XML)) {
int index = attributes.getIndex("href");
if (index != -1) {
org = URI.create(attributes.getValue(index));
}
}
}
}
}
}

View File

@ -0,0 +1,119 @@
/**
*
* 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.vcloudx;
import static org.easymock.classextension.EasyMock.createMock;
import static org.testng.Assert.assertEquals;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import org.jclouds.cloud.CloudContext;
import org.jclouds.cloud.CloudContextBuilder;
import org.jclouds.cloud.ConfiguresCloudConnection;
import org.jclouds.vcloudx.config.BaseRestVCloudXConnectionModule;
import org.jclouds.vcloudx.config.BaseVCloudXContextModule;
import org.jclouds.vcloudx.config.BaseVCloudXContextModule.VCloudXContextImpl;
import org.jclouds.vcloudx.endpoints.Org;
import org.jclouds.vcloudx.reference.VCloudXConstants;
import org.testng.annotations.Test;
import com.google.inject.AbstractModule;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.Module;
import com.google.inject.TypeLiteral;
/**
* Tests behavior of modules configured in BaseVCloudXContextBuilder
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "vcloudx.BaseVCloudXContextBuilderTest")
public class BaseVCloudXContextBuilderTest {
VCloudXConnection connection = createMock(VCloudXConnection.class);
@ConfiguresCloudConnection
private final class StubConnectionModule extends AbstractModule {
@Override
protected void configure() {
bind(URI.class).annotatedWith(Org.class).toInstance(URI.create("http://org"));
bind(VCloudXConnection.class).toInstance(connection);
}
}
public void testNewBuilder() {
CloudContextBuilder<VCloudXConnection> builder = builder();
assertEquals(builder.getProperties().getProperty(VCloudXConstants.PROPERTY_VCLOUDX_ENDPOINT),
"http://localhost");
assertEquals(builder.getProperties().getProperty(VCloudXConstants.PROPERTY_VCLOUDX_USER),
"id");
assertEquals(builder.getProperties().getProperty(VCloudXConstants.PROPERTY_VCLOUDX_KEY),
"secret");
assertEquals(builder.getProperties().getProperty(
VCloudXConstants.PROPERTY_VCLOUDX_SESSIONINTERVAL), "540");
}
public void testBuildContext() {
CloudContextBuilder<VCloudXConnection> builder = builder();
CloudContext<VCloudXConnection> context = builder.buildContext();
assertEquals(context.getClass(), VCloudXContextImpl.class);
assertEquals(context.getApi(), connection);
assertEquals(context.getAccount(), "id");
assertEquals(context.getEndPoint(), URI.create("http://org"));
}
public CloudContextBuilder<VCloudXConnection> builder() {
return new BaseVCloudXContextBuilder(URI.create("http://localhost"), "id", "secret")
.withModule(new StubConnectionModule());
}
public void testBuildInjector() {
CloudContextBuilder<VCloudXConnection> builder = builder();
Injector i = builder.buildInjector();
assert i.getInstance(Key.get(new TypeLiteral<VCloudXContext<VCloudXConnection>>() {
})) != null;
}
protected void testAddContextModule() {
List<Module> modules = new ArrayList<Module>();
BaseVCloudXContextBuilder builder = new BaseVCloudXContextBuilder(URI
.create("http://localhost"), "id", "secret");
builder.addContextModule(modules);
assertEquals(modules.size(), 1);
assertEquals(modules.get(0).getClass(), BaseVCloudXContextModule.class);
}
protected void addConnectionModule() {
List<Module> modules = new ArrayList<Module>();
BaseVCloudXContextBuilder builder = new BaseVCloudXContextBuilder(URI
.create("http://localhost"), "id", "secret");
builder.addConnectionModule(modules);
assertEquals(modules.size(), 1);
assertEquals(modules.get(0).getClass(), BaseRestVCloudXConnectionModule.class);
}
}

View File

@ -0,0 +1,69 @@
/**
*
* 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.vcloudx;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import java.net.URI;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.vcloudx.domain.OrgLinks;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
/**
* Tests behavior of {@code VCloudXConnection}
*
* @author Adrian Cole
*/
@Test(groups = "live", testName = "vcloudx.VCloudXConnectionLiveTest")
public class VCloudXConnectionLiveTest {
private VCloudXConnection connection;
private String account;
@Test
public void testOrganization() throws Exception {
OrgLinks response = connection.getOrganization();
assertNotNull(response);
assertEquals(response.getName(), account);
assertNotNull(response.getOrg());
assertNotNull(response.getCatalog());
assertEquals(response.getTaskLists().size(), 1);
assertEquals(response.getVDCs().size(), 1);
}
@BeforeGroups(groups = { "live" })
public void setupConnection() {
String endpoint = checkNotNull(System.getProperty("jclouds.test.endpoint"),
"jclouds.test.endpoint");
account = checkNotNull(System.getProperty("jclouds.test.user"), "jclouds.test.user");
String key = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key");
connection = new BaseVCloudXContextBuilder(URI.create(endpoint), account, key).withModules(
new Log4JLoggingModule()).buildContext().getApi();
}
}

View File

@ -0,0 +1,104 @@
/**
*
* 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.vcloudx;
import static org.testng.Assert.assertEquals;
import java.lang.reflect.Method;
import java.net.URI;
import javax.inject.Provider;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import org.jclouds.concurrent.WithinThreadExecutorService;
import org.jclouds.concurrent.config.ExecutorServiceModule;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
import org.jclouds.logging.Logger;
import org.jclouds.logging.Logger.LoggerFactory;
import org.jclouds.rest.config.RestModule;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.vcloudx.endpoints.Org;
import org.jclouds.vcloudx.filters.SetVCloudTokenCookie;
import org.jclouds.vcloudx.xml.OrgLinksHandler;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.TypeLiteral;
/**
* Tests behavior of {@code VCloudXConnection}
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "vcloudx.VCloudXConnection")
public class VCloudXConnectionTest {
private RestAnnotationProcessor<VCloudXConnection> processor;
public void testOrganization() throws SecurityException, NoSuchMethodException {
Method method = VCloudXConnection.class.getMethod("getOrganization");
HttpRequest httpMethod = processor.createRequest(method);
assertEquals(httpMethod.getRequestLine(), "GET http://org HTTP/1.1");
assertEquals(httpMethod.getHeaders().size(), 1);
assertEquals(httpMethod.getFirstHeaderOrNull(HttpHeaders.ACCEPT), MediaType.APPLICATION_XML);
assertEquals(RestAnnotationProcessor.getXMLTransformerOrNull(method),OrgLinksHandler.class);
assertEquals(httpMethod.getFilters().size(), 1);
assertEquals(httpMethod.getFilters().get(0).getClass(), SetVCloudTokenCookie.class);
}
@BeforeClass
void setupFactory() {
Injector injector = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
bind(URI.class).annotatedWith(Org.class).toInstance(URI.create("http://org"));
bind(SetVCloudTokenCookie.class).toInstance(
new SetVCloudTokenCookie(new Provider<String>() {
public String get() {
return "token";
}
}));
bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() {
public Logger getLogger(String category) {
return Logger.NULL;
}
});
}
}, new RestModule(), new ExecutorServiceModule(new WithinThreadExecutorService()),
new JavaUrlHttpCommandExecutorServiceModule());
processor = injector.getInstance(Key
.get(new TypeLiteral<RestAnnotationProcessor<VCloudXConnection>>() {
}));
}
}

View File

@ -0,0 +1,128 @@
/**
*
* 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.vcloudx;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.vcloudx.reference.VCloudXConstants.PROPERTY_VCLOUDX_KEY;
import static org.jclouds.vcloudx.reference.VCloudXConstants.PROPERTY_VCLOUDX_SESSIONINTERVAL;
import static org.jclouds.vcloudx.reference.VCloudXConstants.PROPERTY_VCLOUDX_USER;
import static org.testng.Assert.assertNotNull;
import java.net.URI;
import java.util.List;
import java.util.Properties;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.cloud.CloudContext;
import org.jclouds.cloud.CloudContextBuilder;
import org.jclouds.cloud.internal.CloudContextImpl;
import org.jclouds.concurrent.WithinThreadExecutorService;
import org.jclouds.concurrent.config.ExecutorServiceModule;
import org.jclouds.lifecycle.Closer;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.vcloudx.VCloudXLogin.VCloudXSession;
import org.jclouds.vcloudx.config.RestVCloudXAuthenticationModule;
import org.jclouds.vcloudx.endpoints.VCloudX;
import org.jclouds.vcloudx.reference.VCloudXConstants;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import com.google.inject.AbstractModule;
import com.google.inject.Module;
import com.google.inject.Provides;
import com.google.inject.TypeLiteral;
/**
* Tests behavior of {@code VCloudXLogin}
*
* @author Adrian Cole
*/
@Test(groups = "live", testName = "vcloudx.VCloudXLoginLiveTest")
public class VCloudXLoginLiveTest {
private final class VCloudXLoginContextModule extends AbstractModule {
@SuppressWarnings( { "unused" })
@Provides
@Singleton
CloudContext<VCloudXLogin> provideContext(Closer closer, VCloudXLogin api,
@VCloudX URI endPoint,
@Named(VCloudXConstants.PROPERTY_VCLOUDX_USER) String account) {
return new CloudContextImpl<VCloudXLogin>(closer, api, endPoint, account);
}
@Override
protected void configure() {
}
}
String endpoint = checkNotNull(System.getProperty("jclouds.test.endpoint"),
"jclouds.test.endpoint");
String account = checkNotNull(System.getProperty("jclouds.test.user"), "jclouds.test.user");
String key = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key");
private CloudContext<VCloudXLogin> context;
@Test
public void testLogin() throws Exception {
VCloudXLogin authentication = context.getApi();
for (int i = 0; i < 5; i++) {
VCloudXSession response = authentication.login();
assertNotNull(response);
assertNotNull(response.getVCloudToken());
assertNotNull(response.getOrg());
}
}
@BeforeClass
void setupFactory() {
context = new CloudContextBuilder<VCloudXLogin>(new TypeLiteral<VCloudXLogin>() {
}, new Properties()) {
public void addContextModule(List<Module> modules) {
modules.add(new VCloudXLoginContextModule());
}
@Override
protected void addConnectionModule(List<Module> modules) {
properties.setProperty(VCloudXConstants.PROPERTY_VCLOUDX_ENDPOINT, checkNotNull(
endpoint, "endpoint").toString());
properties.setProperty(PROPERTY_VCLOUDX_USER, checkNotNull(account, "user"));
properties.setProperty(PROPERTY_VCLOUDX_KEY, checkNotNull(key, "key"));
properties.setProperty(PROPERTY_VCLOUDX_SESSIONINTERVAL, "4");
modules.add(new RestVCloudXAuthenticationModule());
}
@Override
public CloudContextBuilder<VCloudXLogin> withEndpoint(URI endpoint) {
return this;
}
}.withModules(new Log4JLoggingModule(),
new ExecutorServiceModule(new WithinThreadExecutorService())).buildContext();
}
}

View File

@ -0,0 +1,102 @@
/**
*
* 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.vcloudx;
import static org.testng.Assert.assertEquals;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Method;
import java.net.URI;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import org.jclouds.concurrent.WithinThreadExecutorService;
import org.jclouds.concurrent.config.ExecutorServiceModule;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
import org.jclouds.http.filters.BasicAuthentication;
import org.jclouds.logging.Logger;
import org.jclouds.logging.Logger.LoggerFactory;
import org.jclouds.rest.config.RestModule;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.vcloudx.endpoints.VCloudX;
import org.jclouds.vcloudx.functions.ParseLoginResponseFromHeaders;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.TypeLiteral;
/**
* Tests behavior of {@code VCloudXLogin}
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "vcloudx.VCloudXLogin")
public class VCloudXLoginTest {
private RestAnnotationProcessor<VCloudXLogin> processor;
public void testAuthenticate() throws SecurityException, NoSuchMethodException {
Method method = VCloudXLogin.class.getMethod("login");
HttpRequest httpMethod = processor.createRequest(method);
assertEquals(httpMethod.getRequestLine(), "POST http://localhost:8080/login HTTP/1.1");
assertEquals(httpMethod.getHeaders().size(), 1);
assertEquals(httpMethod.getFirstHeaderOrNull(HttpHeaders.ACCEPT), MediaType.APPLICATION_XML);
assertEquals(RestAnnotationProcessor.getParserOrThrowException(method),
ParseLoginResponseFromHeaders.class);
assertEquals(httpMethod.getFilters().size(), 1);
assertEquals(httpMethod.getFilters().get(0).getClass(), BasicAuthentication.class);
}
@BeforeClass
void setupFactory() {
Injector injector = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
bind(URI.class).annotatedWith(VCloudX.class).toInstance(
URI.create("http://localhost:8080"));
try {
bind(BasicAuthentication.class).toInstance(new BasicAuthentication("user", "pass"));
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() {
public Logger getLogger(String category) {
return Logger.NULL;
}
});
}
}, new RestModule(), new ExecutorServiceModule(new WithinThreadExecutorService()),
new JavaUrlHttpCommandExecutorServiceModule());
processor = injector.getInstance(Key
.get(new TypeLiteral<RestAnnotationProcessor<VCloudXLogin>>() {
}));
}
}

View File

@ -0,0 +1,128 @@
/**
*
* 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.vcloudx.config;
import static org.jclouds.vcloudx.reference.VCloudXConstants.PROPERTY_VCLOUDX_ENDPOINT;
import static org.jclouds.vcloudx.reference.VCloudXConstants.PROPERTY_VCLOUDX_KEY;
import static org.jclouds.vcloudx.reference.VCloudXConstants.PROPERTY_VCLOUDX_SESSIONINTERVAL;
import static org.jclouds.vcloudx.reference.VCloudXConstants.PROPERTY_VCLOUDX_USER;
import static org.testng.Assert.assertEquals;
import java.net.URI;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicInteger;
import org.jclouds.http.HttpRetryHandler;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.http.handlers.CloseContentAndSetExceptionErrorHandler;
import org.jclouds.http.handlers.DelegatingErrorHandler;
import org.jclouds.http.handlers.DelegatingRetryHandler;
import org.jclouds.http.handlers.RedirectionRetryHandler;
import org.jclouds.util.Jsr330;
import org.jclouds.vcloudx.VCloudXLogin;
import org.jclouds.vcloudx.VCloudXLogin.VCloudXSession;
import org.testng.annotations.Test;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
/**
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "vcloudx.RestVCloudXAuthenticationModuleTest")
public class RestVCloudXAuthenticationModuleTest {
Injector createInjector() {
return Guice.createInjector(new RestVCloudXAuthenticationModule(), new ParserModule(),
new AbstractModule() {
@Override
protected void configure() {
bindConstant().annotatedWith(Jsr330.named(PROPERTY_VCLOUDX_USER)).to("user");
bindConstant().annotatedWith(Jsr330.named(PROPERTY_VCLOUDX_KEY)).to("secret");
bindConstant().annotatedWith(Jsr330.named(PROPERTY_VCLOUDX_ENDPOINT)).to(
"http://localhost");
bindConstant().annotatedWith(Jsr330.named(PROPERTY_VCLOUDX_SESSIONINTERVAL))
.to("2");
}
});
}
@Test
void testUpdatesOnlyOncePerSecond() throws NoSuchMethodException, InterruptedException {
RestVCloudXAuthenticationModule module = new RestVCloudXAuthenticationModule();
VCloudXLogin login = new VCloudXLogin() {
private final AtomicInteger token = new AtomicInteger();
public VCloudXSession login() {
return new VCloudXSession() {
public URI getOrg() {
return null;
}
public String getVCloudToken() {
return token.incrementAndGet() + "";
}
};
}
};
ConcurrentMap<String, VCloudXSession> map = module.provideVCloudTokenCache(1, login);
for (int i = 0; i < 10; i++)
map.get("foo");
assert "1".equals(map.get("foo").getVCloudToken());
Thread.sleep(1001);
assert "2".equals(map.get("foo").getVCloudToken());
}
@Test
void testServerErrorHandler() {
DelegatingErrorHandler handler = createInjector().getInstance(DelegatingErrorHandler.class);
assertEquals(handler.getServerErrorHandler().getClass(),
CloseContentAndSetExceptionErrorHandler.class);
}
@Test
void testClientErrorHandler() {
DelegatingErrorHandler handler = createInjector().getInstance(DelegatingErrorHandler.class);
assertEquals(handler.getClientErrorHandler().getClass(),
CloseContentAndSetExceptionErrorHandler.class);
}
@Test
void testClientRetryHandler() {
DelegatingRetryHandler handler = createInjector().getInstance(DelegatingRetryHandler.class);
assertEquals(handler.getClientErrorRetryHandler(), HttpRetryHandler.NEVER_RETRY);
}
@Test
void testRedirectionRetryHandler() {
DelegatingRetryHandler handler = createInjector().getInstance(DelegatingRetryHandler.class);
assertEquals(handler.getRedirectionRetryHandler().getClass(), RedirectionRetryHandler.class);
}
}

View File

@ -0,0 +1,64 @@
/**
*
* 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.vcloudx.filters;
import static org.testng.Assert.assertEquals;
import java.net.URI;
import javax.inject.Provider;
import javax.ws.rs.core.HttpHeaders;
import org.jclouds.http.HttpRequest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
/**
* @author Adrian Cole
*/
@Test
public class SetVCloudTokenCookieTest {
private SetVCloudTokenCookie filter;
@BeforeTest
void setUp() {
filter = new SetVCloudTokenCookie(new Provider<String>() {
public String get() {
return "token";
}
});
}
@Test
public void testApply() {
HttpRequest request = new HttpRequest("GET", URI.create("http://localhost"));
filter.filter(request);
assertEquals(request.getHeaders().size(), 1);
assertEquals(request.getFirstHeaderOrNull(HttpHeaders.COOKIE), "vcloud-token=token");
}
}

View File

@ -0,0 +1,67 @@
/**
*
* 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.vcloudx.functions;
import static org.testng.Assert.assertEquals;
import java.net.URI;
import javax.ws.rs.core.HttpHeaders;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.BaseHandlerTest;
import org.jclouds.vcloudx.VCloudXLogin.VCloudXSession;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
/**
* @author Adrian Cole
*/
public class ParseLoginResponseFromHeadersTest extends BaseHandlerTest {
private ParseLoginResponseFromHeaders parser;
@BeforeTest
void setUp() {
parser = injector.getInstance(ParseLoginResponseFromHeaders.class);
}
@Test
public void testApply() {
HttpResponse response = new HttpResponse();
response.setMessage("OK");
response.setStatusCode(200);
response.setContent(getClass().getResourceAsStream("/orglist.xml"));
response.getHeaders().put(HttpHeaders.SET_COOKIE,
"vcloud-token=9er4d061-4bff-48fa-84b1-5da7166764d2; path=/");
response.getHeaders().put(HttpHeaders.CONTENT_LENGTH, "307");
response.getHeaders().put(HttpHeaders.CONTENT_TYPE,
"Content-Type: application/xml; charset=utf-8");
VCloudXSession reply = parser.apply(response);
assertEquals(reply.getVCloudToken(), "9er4d061-4bff-48fa-84b1-5da7166764d2");
assertEquals(reply.getOrg(), URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/org/48"));
}
}

View File

@ -0,0 +1,67 @@
/**
*
* 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.vcloudx.xml;
import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import java.net.URI;
import org.jclouds.http.functions.BaseHandlerTest;
import org.jclouds.vcloudx.domain.OrgLinks;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import com.google.common.collect.Sets;
/**
* Tests behavior of {@code OrgLinksHandler}
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "vcloudx.OrgLinksHandlerTest")
public class OrgLinksHandlerTest extends BaseHandlerTest {
@BeforeTest
@Override
protected void setUpInjector() {
super.setUpInjector();
}
public void testApplyInputStream() {
InputStream is = getClass().getResourceAsStream("/org.xml");
OrgLinks result = (OrgLinks) factory.create(injector.getInstance(OrgLinksHandler.class))
.parse(is);
assertEquals(result.getName(), "adrian@jclouds.org");
assertEquals(result.getOrg(), URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/org/48"));
assertEquals(result.getCatalog(), URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32/catalog"));
assertEquals(result.getVDCs(), Sets.newHashSet(URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32")));
assertEquals(result.getTaskLists(), Sets.newHashSet(URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/tasksList/32")));
}
}

View File

@ -0,0 +1,57 @@
/**
*
* 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.vcloudx.xml;
import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import java.net.URI;
import org.jclouds.http.functions.BaseHandlerTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
/**
* Tests behavior of {@code OrgListToOrgUriHandler}
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "vcloudx.OrgListToOrgUriHandlerTest")
public class OrgListToOrgUriHandlerTest extends BaseHandlerTest {
@BeforeTest
@Override
protected void setUpInjector() {
super.setUpInjector();
}
public void testApplyInputStream() {
InputStream is = getClass().getResourceAsStream("/orglist.xml");
URI result = (URI) factory.create(injector.getInstance(OrgListToOrgUriHandler.class)).parse(
is);
assertEquals(result, URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/org/48"));
}
}

View File

@ -0,0 +1,115 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
====================================================================
-->
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<!--
For more configuration infromation and examples see the Apache Log4j
website: http://logging.apache.org/log4j/
-->
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"
debug="false">
<!-- A time/date based rolling appender -->
<appender name="WIREFILE" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="target/test-data/jclouds-wire.log" />
<param name="Append" value="true" />
<!-- Rollover at midnight each day -->
<param name="DatePattern" value="'.'yyyy-MM-dd" />
<param name="Threshold" value="TRACE" />
<layout class="org.apache.log4j.PatternLayout">
<!-- The default pattern: Date Priority [Category] Message\n -->
<param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />
<!--
The full pattern: Date MS Priority [Category] (Thread:NDC) Message\n
<param name="ConversionPattern" value="%d %-5r %-5p [%c] (%t:%x)
%m%n"/>
-->
</layout>
</appender>
<!-- A time/date based rolling appender -->
<appender name="FILE" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="target/test-data/jclouds.log" />
<param name="Append" value="true" />
<!-- Rollover at midnight each day -->
<param name="DatePattern" value="'.'yyyy-MM-dd" />
<param name="Threshold" value="TRACE" />
<layout class="org.apache.log4j.PatternLayout">
<!-- The default pattern: Date Priority [Category] Message\n -->
<param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />
<!--
The full pattern: Date MS Priority [Category] (Thread:NDC) Message\n
<param name="ConversionPattern" value="%d %-5r %-5p [%c] (%t:%x)
%m%n"/>
-->
</layout>
</appender>
<appender name="ASYNC" class="org.apache.log4j.AsyncAppender">
<appender-ref ref="FILE" />
</appender>
<appender name="ASYNCWIRE" class="org.apache.log4j.AsyncAppender">
<appender-ref ref="WIREFILE" />
</appender>
<!-- ================ -->
<!-- Limit categories -->
<!-- ================ -->
<category name="org.jclouds">
<priority value="DEBUG" />
<appender-ref ref="ASYNC" />
</category>
<category name="jclouds.http.headers">
<priority value="DEBUG" />
<appender-ref ref="ASYNCWIRE" />
</category>
<category name="jclouds.http.wire">
<priority value="DEBUG" />
<appender-ref ref="ASYNCWIRE" />
</category>
<!-- ======================= -->
<!-- Setup the Root category -->
<!-- ======================= -->
<root>
<priority value="WARN" />
</root>
</log4j:configuration>

View File

@ -0,0 +1,30 @@
<!--
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.
====================================================================
-->
<Org href="https://services.vcloudexpress.terremark.com/api/v0.8/org/48" name="adrian@jclouds.org" xmlns="http://www.vmware.com/vcloud/v1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Link rel="down" href="https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32" type="application/vnd.vmware.vcloud.vdc+xml" name="Miami Environment 1"/>
<Link rel="down" href="https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32/catalog" type="application/vnd.vmware.vcloud.catalog+xml" name="Miami Environment 1 Catalog"/>
<Link rel="down" href="https://services.vcloudexpress.terremark.com/api/v0.8/tasksList/32" type="application/vnd.vmware.vcloud.tasksList+xml" name="Miami Environment 1 Tasks List"/>
</Org>

View File

@ -0,0 +1,28 @@
<!--
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.
====================================================================
-->
<OrgList xmlns="http://www.vmware.com/vcloud/v1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Org href="https://services.vcloudexpress.terremark.com/api/v0.8/org/48" type="application/vnd.vmware.vcloud.org+xml" name="adrian@jclouds.org"/>
</OrgList>

68
vcloudx/pom.xml Executable file
View File

@ -0,0 +1,68 @@
<?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>
<artifactId>jclouds-project</artifactId>
<groupId>org.jclouds</groupId>
<version>1.0-SNAPSHOT</version>
<relativePath>../project/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>jclouds-vcloudx-project</artifactId>
<packaging>pom</packaging>
<name>jclouds vcloudx project</name>
<modules>
<module>core</module>
</modules>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jclouds-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jclouds-core</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jclouds-log4j</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>