Issue 112: created vcloud tester, converted to lookup api version dynamically

git-svn-id: http://jclouds.googlecode.com/svn/trunk@2295 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
adrian.f.cole 2009-11-17 02:53:10 +00:00
parent df95eb10bb
commit 09adeebe3d
57 changed files with 1295 additions and 370 deletions

View File

@ -84,70 +84,70 @@ public interface VCloudAsyncClient {
@POST @POST
@Consumes(TASK_XML) @Consumes(TASK_XML)
@Endpoint(org.jclouds.vcloud.endpoints.VCloud.class) @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
@Path("/vapp/{vAppId}/action/deploy") @Path("/vapp/{vAppId}/action/deploy")
@XMLResponseParser(TaskHandler.class) @XMLResponseParser(TaskHandler.class)
Future<? extends Task> deployVApp(@PathParam("vAppId") int vAppId); Future<? extends Task> deployVApp(@PathParam("vAppId") String vAppId);
@DELETE @DELETE
@Endpoint(org.jclouds.vcloud.endpoints.VCloud.class) @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
@Path("/vapp/{vAppId}") @Path("/vapp/{vAppId}")
Future<Void> deleteVApp(@PathParam("vAppId") int vAppId); Future<Void> deleteVApp(@PathParam("vAppId") String vAppId);
@POST @POST
@Consumes(TASK_XML) @Consumes(TASK_XML)
@Endpoint(org.jclouds.vcloud.endpoints.VCloud.class) @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
@Path("/vapp/{vAppId}/action/undeploy") @Path("/vapp/{vAppId}/action/undeploy")
@XMLResponseParser(TaskHandler.class) @XMLResponseParser(TaskHandler.class)
Future<? extends Task> undeployVApp(@PathParam("vAppId") int vAppId); Future<? extends Task> undeployVApp(@PathParam("vAppId") String vAppId);
/** /**
* This call powers on the vApp, as specified in the vApp's ovf:Startup element. * This call powers on the vApp, as specified in the vApp's ovf:Startup element.
*/ */
@POST @POST
@Consumes(TASK_XML) @Consumes(TASK_XML)
@Endpoint(org.jclouds.vcloud.endpoints.VCloud.class) @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
@Path("/vapp/{vAppId}/power/action/powerOn") @Path("/vapp/{vAppId}/power/action/powerOn")
@XMLResponseParser(TaskHandler.class) @XMLResponseParser(TaskHandler.class)
Future<? extends Task> powerOnVApp(@PathParam("vAppId") int vAppId); Future<? extends Task> powerOnVApp(@PathParam("vAppId") String vAppId);
/** /**
* This call powers off the vApp, as specified in the vApp's ovf:Startup element. * This call powers off the vApp, as specified in the vApp's ovf:Startup element.
*/ */
@POST @POST
@Consumes(TASK_XML) @Consumes(TASK_XML)
@Endpoint(org.jclouds.vcloud.endpoints.VCloud.class) @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
@Path("/vapp/{vAppId}/power/action/powerOff") @Path("/vapp/{vAppId}/power/action/powerOff")
@XMLResponseParser(TaskHandler.class) @XMLResponseParser(TaskHandler.class)
Future<? extends Task> powerOffVApp(@PathParam("vAppId") int vAppId); Future<? extends Task> powerOffVApp(@PathParam("vAppId") String vAppId);
/** /**
* This call shuts down the vApp. * This call shuts down the vApp.
*/ */
@POST @POST
@Endpoint(org.jclouds.vcloud.endpoints.VCloud.class) @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
@Path("/vapp/{vAppId}/power/action/shutdown") @Path("/vapp/{vAppId}/power/action/shutdown")
Future<Void> shutdownVApp(@PathParam("vAppId") int vAppId); Future<Void> shutdownVApp(@PathParam("vAppId") String vAppId);
/** /**
* This call resets the vApp. * This call resets the vApp.
*/ */
@POST @POST
@Consumes(TASK_XML) @Consumes(TASK_XML)
@Endpoint(org.jclouds.vcloud.endpoints.VCloud.class) @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
@Path("/vapp/{vAppId}/power/action/reset") @Path("/vapp/{vAppId}/power/action/reset")
@XMLResponseParser(TaskHandler.class) @XMLResponseParser(TaskHandler.class)
Future<? extends Task> resetVApp(@PathParam("vAppId") int vAppId); Future<? extends Task> resetVApp(@PathParam("vAppId") String vAppId);
/** /**
* This call suspends the vApp. * This call suspends the vApp.
*/ */
@POST @POST
@Consumes(TASK_XML) @Consumes(TASK_XML)
@Endpoint(org.jclouds.vcloud.endpoints.VCloud.class) @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
@Path("/vapp/{vAppId}/power/action/suspend") @Path("/vapp/{vAppId}/power/action/suspend")
@XMLResponseParser(TaskHandler.class) @XMLResponseParser(TaskHandler.class)
Future<? extends Task> suspendVApp(@PathParam("vAppId") int vAppId); Future<? extends Task> suspendVApp(@PathParam("vAppId") String vAppId);
@GET @GET
@Consumes(TASK_XML) @Consumes(TASK_XML)
@ -160,7 +160,7 @@ public interface VCloudAsyncClient {
@GET @GET
@Consumes(VAPP_XML) @Consumes(VAPP_XML)
@Endpoint(org.jclouds.vcloud.endpoints.VCloud.class) @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
@Path("/vapp/{vAppId}") @Path("/vapp/{vAppId}")
Future<String> getVAppString(@PathParam("vAppId") String appId); Future<String> getVAppString(@PathParam("vAppId") String appId);
} }

View File

@ -51,36 +51,36 @@ public interface VCloudClient {
@Timeout(duration = 90, timeUnit = TimeUnit.SECONDS) @Timeout(duration = 90, timeUnit = TimeUnit.SECONDS)
TasksList getDefaultTasksList(); TasksList getDefaultTasksList();
Task deployVApp(int vAppId); Task deployVApp(String vAppId);
void deleteVApp(int vAppId); void deleteVApp(String vAppId);
Task undeployVApp(int vAppId); Task undeployVApp(String vAppId);
/** /**
* This call powers on the vApp, as specified in the vApp's ovf:Startup element. * This call powers on the vApp, as specified in the vApp's ovf:Startup element.
*/ */
Task powerOnVApp(int vAppId); Task powerOnVApp(String vAppId);
/** /**
* This call powers off the vApp, as specified in the vApp's ovf:Startup element. * This call powers off the vApp, as specified in the vApp's ovf:Startup element.
*/ */
Task powerOffVApp(int vAppId); Task powerOffVApp(String vAppId);
/** /**
* This call shuts down the vApp. * This call shuts down the vApp.
*/ */
void shutdownVApp(int vAppId); void shutdownVApp(String vAppId);
/** /**
* This call resets the vApp. * This call resets the vApp.
*/ */
Task resetVApp(int vAppId); Task resetVApp(String vAppId);
/** /**
* This call suspends the vApp. * This call suspends the vApp.
*/ */
Task suspendVApp(int vAppId); Task suspendVApp(String vAppId);
Task getTask(URI task); Task getTask(URI task);

View File

@ -28,7 +28,6 @@ import java.util.concurrent.Future;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
import javax.ws.rs.POST; import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import org.jclouds.http.filters.BasicAuthentication; import org.jclouds.http.filters.BasicAuthentication;
@ -37,7 +36,6 @@ import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.ResponseParser; import org.jclouds.rest.annotations.ResponseParser;
import org.jclouds.rest.domain.NamedLink; import org.jclouds.rest.domain.NamedLink;
import org.jclouds.vcloud.endpoints.Org; import org.jclouds.vcloud.endpoints.Org;
import org.jclouds.vcloud.endpoints.VCloud;
import org.jclouds.vcloud.functions.ParseLoginResponseFromHeaders; import org.jclouds.vcloud.functions.ParseLoginResponseFromHeaders;
/** /**
@ -47,7 +45,7 @@ import org.jclouds.vcloud.functions.ParseLoginResponseFromHeaders;
* @see <a href="https://community.vcloudexpress.terremark.com/en-us/discussion_forums/f/60.aspx" /> * @see <a href="https://community.vcloudexpress.terremark.com/en-us/discussion_forums/f/60.aspx" />
* @author Adrian Cole * @author Adrian Cole
*/ */
@Endpoint(VCloud.class) @Endpoint(org.jclouds.vcloud.endpoints.VCloudLogin.class)
@RequestFilters(BasicAuthentication.class) @RequestFilters(BasicAuthentication.class)
public interface VCloudLogin { public interface VCloudLogin {
@ -65,7 +63,6 @@ public interface VCloudLogin {
*/ */
@POST @POST
@ResponseParser(ParseLoginResponseFromHeaders.class) @ResponseParser(ParseLoginResponseFromHeaders.class)
@Path("/login")
@Consumes(MediaType.APPLICATION_XML) @Consumes(MediaType.APPLICATION_XML)
Future<VCloudSession> login(); Future<VCloudSession> login();
} }

View File

@ -28,6 +28,7 @@ import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_ENDPO
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_KEY; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_KEY;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_SESSIONINTERVAL; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_SESSIONINTERVAL;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_USER; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_USER;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_VERSION;
import java.net.URI; import java.net.URI;
import java.util.Properties; import java.util.Properties;
@ -43,6 +44,7 @@ public class VCloudPropertiesBuilder extends HttpPropertiesBuilder {
@Override @Override
protected Properties defaultProperties() { protected Properties defaultProperties() {
Properties properties = super.defaultProperties(); Properties properties = super.defaultProperties();
properties.setProperty(PROPERTY_VCLOUD_VERSION, "0.8");
properties.setProperty(PROPERTY_VCLOUD_SESSIONINTERVAL, 9 * 60 + ""); properties.setProperty(PROPERTY_VCLOUD_SESSIONINTERVAL, 9 * 60 + "");
return properties; return properties;
} }

View File

@ -0,0 +1,58 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.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.vcloud;
import java.net.URI;
import java.util.SortedMap;
import java.util.concurrent.Future;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.core.MediaType;
import org.jclouds.rest.annotations.Endpoint;
import org.jclouds.rest.annotations.XMLResponseParser;
import org.jclouds.vcloud.endpoints.VCloud;
import org.jclouds.vcloud.xml.SupportedVersionsHandler;
/**
* Establishes a context with a VCloud endpoint.
* <p/>
*
* @see <a href="https://community.vcloudexpress.terremark.com/en-us/discussion_forums/f/60.aspx" />
* @author Adrian Cole
*/
@Endpoint(VCloud.class)
public interface VCloudVersions {
/**
* Retrieve information for supported versions
*/
@GET
@XMLResponseParser(SupportedVersionsHandler.class)
@Path("/versions")
@Consumes(MediaType.APPLICATION_XML)
Future<SortedMap<String, URI>> getSupportedVersions();
}

View File

@ -27,10 +27,13 @@ import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_ENDPO
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_KEY; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_KEY;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_SESSIONINTERVAL; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_SESSIONINTERVAL;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_USER; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_USER;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_VERSION;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.URI; import java.net.URI;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import javax.inject.Named; import javax.inject.Named;
import javax.inject.Singleton; import javax.inject.Singleton;
@ -38,14 +41,17 @@ import javax.inject.Singleton;
import org.jclouds.concurrent.ExpirableSupplier; import org.jclouds.concurrent.ExpirableSupplier;
import org.jclouds.http.RequiresHttp; import org.jclouds.http.RequiresHttp;
import org.jclouds.http.filters.BasicAuthentication; import org.jclouds.http.filters.BasicAuthentication;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.RestClientFactory; import org.jclouds.rest.RestClientFactory;
import org.jclouds.util.Utils; import org.jclouds.util.Utils;
import org.jclouds.vcloud.VCloudDiscovery; import org.jclouds.vcloud.VCloudDiscovery;
import org.jclouds.vcloud.VCloudLogin; import org.jclouds.vcloud.VCloudLogin;
import org.jclouds.vcloud.VCloudToken; import org.jclouds.vcloud.VCloudToken;
import org.jclouds.vcloud.VCloudVersions;
import org.jclouds.vcloud.VCloudLogin.VCloudSession; import org.jclouds.vcloud.VCloudLogin.VCloudSession;
import org.jclouds.vcloud.endpoints.Org; import org.jclouds.vcloud.endpoints.Org;
import org.jclouds.vcloud.endpoints.VCloud; import org.jclouds.vcloud.endpoints.VCloud;
import org.jclouds.vcloud.endpoints.VCloudApi;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
@ -58,6 +64,7 @@ import com.google.inject.Provides;
* @author Adrian Cole * @author Adrian Cole
*/ */
@RequiresHttp @RequiresHttp
@ConfiguresRestClient
public class VCloudDiscoveryRestClientModule extends AbstractModule { public class VCloudDiscoveryRestClientModule extends AbstractModule {
@Override @Override
@ -77,6 +84,13 @@ public class VCloudDiscoveryRestClientModule extends AbstractModule {
return Iterables.getLast(cache.get().getOrgs().values()).getLocation(); return Iterables.getLast(cache.get().getOrgs().values()).getLocation();
} }
@Provides
@VCloudApi
@Singleton
URI provideVCloudApi(@org.jclouds.vcloud.endpoints.VCloudLogin URI vcloudUri) {
return URI.create(vcloudUri.toASCIIString().replace("/login", ""));
}
/** /**
* borrowing concurrency code to ensure that caching takes place properly * borrowing concurrency code to ensure that caching takes place properly
*/ */
@ -99,10 +113,19 @@ public class VCloudDiscoveryRestClientModule extends AbstractModule {
@Provides @Provides
@Singleton @Singleton
@VCloud @VCloud
protected URI provideAuthenticationURI(@Named(PROPERTY_VCLOUD_ENDPOINT) String endpoint) { protected URI provideBaseURI(@Named(PROPERTY_VCLOUD_ENDPOINT) String endpoint) {
return URI.create(endpoint); return URI.create(endpoint);
} }
@Provides
@Singleton
@org.jclouds.vcloud.endpoints.VCloudLogin
protected URI provideAuthenticationURI(VCloudVersions versionService,
@Named(PROPERTY_VCLOUD_VERSION) String version) throws InterruptedException,
ExecutionException, TimeoutException {
return versionService.getSupportedVersions().get(30, TimeUnit.SECONDS).get(version);
}
@Provides @Provides
@Singleton @Singleton
protected VCloudLogin provideVCloudLogin(RestClientFactory factory) { protected VCloudLogin provideVCloudLogin(RestClientFactory factory) {
@ -115,6 +138,12 @@ public class VCloudDiscoveryRestClientModule extends AbstractModule {
return factory.create(VCloudDiscovery.class); return factory.create(VCloudDiscovery.class);
} }
@Provides
@Singleton
protected VCloudVersions provideVCloudVersions(RestClientFactory factory) {
return factory.create(VCloudVersions.class);
}
@Provides @Provides
@Singleton @Singleton
public BasicAuthentication provideBasicAuthentication(@Named(PROPERTY_VCLOUD_USER) String user, public BasicAuthentication provideBasicAuthentication(@Named(PROPERTY_VCLOUD_USER) String user,

View File

@ -41,7 +41,7 @@ import org.jclouds.vcloud.domain.Organization;
import org.jclouds.vcloud.endpoints.Catalog; import org.jclouds.vcloud.endpoints.Catalog;
import org.jclouds.vcloud.endpoints.Network; import org.jclouds.vcloud.endpoints.Network;
import org.jclouds.vcloud.endpoints.TasksList; import org.jclouds.vcloud.endpoints.TasksList;
import org.jclouds.vcloud.endpoints.VCloud; import org.jclouds.vcloud.endpoints.VCloudLogin;
import org.jclouds.vcloud.endpoints.VDC; import org.jclouds.vcloud.endpoints.VDC;
import org.jclouds.vcloud.endpoints.internal.CatalogItemRoot; import org.jclouds.vcloud.endpoints.internal.CatalogItemRoot;
import org.jclouds.vcloud.endpoints.internal.VAppRoot; import org.jclouds.vcloud.endpoints.internal.VAppRoot;
@ -78,15 +78,15 @@ public class VCloudRestClientModule extends AbstractModule {
@Provides @Provides
@CatalogItemRoot @CatalogItemRoot
@Singleton @Singleton
String provideCatalogItemRoot(@VCloud URI vcloudUri) { String provideCatalogItemRoot(@VCloudLogin URI vcloudUri) {
return vcloudUri.toASCIIString() + "/catalogItem"; return vcloudUri.toASCIIString().replace("/login", "/catalogItem");
} }
@Provides @Provides
@VAppRoot @VAppRoot
@Singleton @Singleton
String provideVAppRoot(@VCloud URI vcloudUri) { String provideVAppRoot(@VCloudLogin URI vcloudUri) {
return vcloudUri.toASCIIString() + "/vapp"; return vcloudUri.toASCIIString().replace("/login", "/vapp");
} }
@Provides @Provides

View File

@ -13,5 +13,5 @@ import com.google.inject.ImplementedBy;
*/ */
@ImplementedBy(NamedResourceImpl.class) @ImplementedBy(NamedResourceImpl.class)
public interface NamedResource extends NamedLink, Comparable<NamedResource> { public interface NamedResource extends NamedLink, Comparable<NamedResource> {
int getId(); String getId();
} }

View File

@ -44,7 +44,7 @@ import com.google.inject.ImplementedBy;
public interface Organization { public interface Organization {
String getName(); String getName();
int getId(); String getId();
URI getLocation(); URI getLocation();

View File

@ -40,7 +40,7 @@ public interface VDC {
String getName(); String getName();
int getId(); String getId();
URI getLocation(); URI getLocation();

View File

@ -12,37 +12,26 @@ import org.jclouds.vcloud.domain.NamedResource;
* *
*/ */
public class NamedResourceImpl extends NamedLinkImpl implements NamedResource { public class NamedResourceImpl extends NamedLinkImpl implements NamedResource {
private final int id; private final String id;
public NamedResourceImpl(int id, String name, String type, URI location) { public NamedResourceImpl(String id, String name, String type, URI location) {
super(name, type, location); super(name, type, location);
this.id = id; this.id = id;
} }
public int getId() { public String getId() {
return id; return id;
} }
public int compareTo(NamedResource that) { public int compareTo(NamedResource that) {
final int BEFORE = -1; return (this == that) ? 0 : this.id.compareTo(that.getId());
final int EQUAL = 0;
final int AFTER = 1;
if (this == that)
return EQUAL;
if (this.id < that.getId())
return BEFORE;
if (this.id > that.getId())
return AFTER;
return EQUAL;
} }
@Override @Override
public int hashCode() { public int hashCode() {
final int prime = 31; final int prime = 31;
int result = super.hashCode(); int result = super.hashCode();
result = prime * result + id; result = prime * result + ((id == null) ? 0 : id.hashCode());
return result; return result;
} }
@ -55,9 +44,17 @@ public class NamedResourceImpl extends NamedLinkImpl implements NamedResource {
if (getClass() != obj.getClass()) if (getClass() != obj.getClass())
return false; return false;
NamedResourceImpl other = (NamedResourceImpl) obj; NamedResourceImpl other = (NamedResourceImpl) obj;
if (id != other.id) if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false; return false;
return true; return true;
} }
@Override
public String toString() {
return "NamedResourceImpl [id=" + id + ", name=" + getName() + ", location="
+ getLocation() + ", type=" + getType() + "]";
}
} }

View File

@ -39,14 +39,14 @@ import org.jclouds.vcloud.endpoints.VDC;
* *
*/ */
public class OrganizationImpl implements Organization { public class OrganizationImpl implements Organization {
private final int id; private final String id;
private final String name; private final String name;
private final URI location; private final URI location;
private final NamedLink catalog; private final NamedLink catalog;
private final Map<String, NamedLink> vdcs; private final Map<String, NamedLink> vdcs;
private final Map<String, NamedLink> tasksLists; private final Map<String, NamedLink> tasksLists;
public OrganizationImpl(int id, String name, URI location, NamedLink catalog, public OrganizationImpl(String id, String name, URI location, NamedLink catalog,
Map<String, NamedLink> vdcs, Map<String, NamedLink> tasksLists) { Map<String, NamedLink> vdcs, Map<String, NamedLink> tasksLists) {
this.id = id; this.id = id;
this.name = name; this.name = name;
@ -56,7 +56,7 @@ public class OrganizationImpl implements Organization {
this.tasksLists = tasksLists; this.tasksLists = tasksLists;
} }
public int getId() { public String getId() {
return id; return id;
} }
@ -88,7 +88,7 @@ public class OrganizationImpl implements Organization {
final int prime = 31; final int prime = 31;
int result = 1; int result = 1;
result = prime * result + ((catalog == null) ? 0 : catalog.hashCode()); result = prime * result + ((catalog == null) ? 0 : catalog.hashCode());
result = prime * result + id; result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result + ((location == null) ? 0 : location.hashCode()); result = prime * result + ((location == null) ? 0 : location.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((tasksLists == null) ? 0 : tasksLists.hashCode()); result = prime * result + ((tasksLists == null) ? 0 : tasksLists.hashCode());
@ -110,7 +110,10 @@ public class OrganizationImpl implements Organization {
return false; return false;
} else if (!catalog.equals(other.catalog)) } else if (!catalog.equals(other.catalog))
return false; return false;
if (id != other.id) if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false; return false;
if (location == null) { if (location == null) {
if (other.location != null) if (other.location != null)

View File

@ -41,7 +41,7 @@ import org.jclouds.vcloud.domain.VDC;
*/ */
public class VDCImpl implements VDC { public class VDCImpl implements VDC {
private final int id; private final String id;
private final String name; private final String name;
private final URI location; private final URI location;
private final String description; private final String description;
@ -53,15 +53,13 @@ public class VDCImpl implements VDC {
private final Map<String, NamedLink> availableNetworks; private final Map<String, NamedLink> availableNetworks;
private final Map<String, NamedLink> resourceEntities; private final Map<String, NamedLink> resourceEntities;
public VDCImpl(int id, String name, URI location, String description, Capacity storageCapacity, public VDCImpl(String id, String name, URI location, String description, Capacity storageCapacity,
Capacity cpuCapacity, Capacity memoryCapacity, Quota instantiatedVmsQuota, Capacity cpuCapacity, Capacity memoryCapacity, Quota instantiatedVmsQuota,
Quota deployedVmsQuota, Map<String, NamedLink> resourceEntities, Quota deployedVmsQuota, Map<String, NamedLink> resourceEntities,
Map<String, NamedLink> availableNetworks) { Map<String, NamedLink> availableNetworks) {
this.id = id; this.id = id;
this.name = checkNotNull(name, "name"); this.name = checkNotNull(name, "name");
;
this.location = checkNotNull(location, "location"); this.location = checkNotNull(location, "location");
;
this.description = description; this.description = description;
this.storageCapacity = storageCapacity; this.storageCapacity = storageCapacity;
this.cpuCapacity = cpuCapacity; this.cpuCapacity = cpuCapacity;
@ -69,15 +67,13 @@ public class VDCImpl implements VDC {
this.instantiatedVmsQuota = instantiatedVmsQuota; this.instantiatedVmsQuota = instantiatedVmsQuota;
this.deployedVmsQuota = deployedVmsQuota; this.deployedVmsQuota = deployedVmsQuota;
this.availableNetworks = checkNotNull(availableNetworks, "availableNetworks"); this.availableNetworks = checkNotNull(availableNetworks, "availableNetworks");
;
this.resourceEntities = checkNotNull(resourceEntities, "resourceEntities"); this.resourceEntities = checkNotNull(resourceEntities, "resourceEntities");
;
} }
/** The serialVersionUID */ /** The serialVersionUID */
private static final long serialVersionUID = 8464716396538298809L; private static final long serialVersionUID = 8464716396538298809L;
public int getId() { public String getId() {
return id; return id;
} }
@ -105,7 +101,7 @@ public class VDCImpl implements VDC {
result = prime * result + ((cpuCapacity == null) ? 0 : cpuCapacity.hashCode()); result = prime * result + ((cpuCapacity == null) ? 0 : cpuCapacity.hashCode());
result = prime * result + ((deployedVmsQuota == null) ? 0 : deployedVmsQuota.hashCode()); result = prime * result + ((deployedVmsQuota == null) ? 0 : deployedVmsQuota.hashCode());
result = prime * result + ((description == null) ? 0 : description.hashCode()); result = prime * result + ((description == null) ? 0 : description.hashCode());
result = prime * result + id; result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result result = prime * result
+ ((instantiatedVmsQuota == null) ? 0 : instantiatedVmsQuota.hashCode()); + ((instantiatedVmsQuota == null) ? 0 : instantiatedVmsQuota.hashCode());
result = prime * result + ((location == null) ? 0 : location.hashCode()); result = prime * result + ((location == null) ? 0 : location.hashCode());
@ -145,7 +141,10 @@ public class VDCImpl implements VDC {
return false; return false;
} else if (!description.equals(other.description)) } else if (!description.equals(other.description))
return false; return false;
if (id != other.id) if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false; return false;
if (instantiatedVmsQuota == null) { if (instantiatedVmsQuota == null) {
if (other.instantiatedVmsQuota != null) if (other.instantiatedVmsQuota != null)

View File

@ -0,0 +1,45 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.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.vcloud.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.
*
* @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 VCloudApi {
}

View File

@ -0,0 +1,45 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.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.vcloud.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.
*
* @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 VCloudLogin {
}

View File

@ -20,9 +20,9 @@ public class CatalogIdToUri implements Function<Object, String> {
private String catalogItemRoot; private String catalogItemRoot;
public String apply(Object from) { public String apply(Object from) {
checkArgument(checkNotNull(from, "from") instanceof Integer, checkArgument(checkNotNull(from, "from") instanceof String,
"this binder is only valid for Integers!"); "this binder is only valid for String!");
return String.format("%s/%d", catalogItemRoot, from); return String.format("%s/%s", catalogItemRoot, from);
} }
} }

View File

@ -20,9 +20,9 @@ public class VAppIdToUri implements Function<Object, String> {
private String vAppRoot; private String vAppRoot;
public String apply(Object from) { public String apply(Object from) {
checkArgument(checkNotNull(from, "from") instanceof Integer, checkArgument(checkNotNull(from, "from") instanceof String,
"this binder is only valid for Integers!"); "this binder is only valid for Strings!");
return String.format("%s/%d", vAppRoot, from); return String.format("%s/%s", vAppRoot, from);
} }
} }

View File

@ -29,6 +29,7 @@ package org.jclouds.vcloud.reference;
* @author Adrian Cole * @author Adrian Cole
*/ */
public interface VCloudConstants { public interface VCloudConstants {
public static final String PROPERTY_VCLOUD_VERSION = "jclouds.vcloud.version";
public static final String PROPERTY_VCLOUD_ENDPOINT = "jclouds.vcloud.endpoint"; public static final String PROPERTY_VCLOUD_ENDPOINT = "jclouds.vcloud.endpoint";
public static final String PROPERTY_VCLOUD_USER = "jclouds.vcloud.user"; public static final String PROPERTY_VCLOUD_USER = "jclouds.vcloud.user";
public static final String PROPERTY_VCLOUD_KEY = "jclouds.vcloud.key"; public static final String PROPERTY_VCLOUD_KEY = "jclouds.vcloud.key";

View File

@ -84,11 +84,12 @@ public class CatalogHandler extends ParseSax.HandlerWithResult<Catalog> {
} }
public NamedResource newNamedResource(Attributes attributes) { public NamedResource newNamedResource(Attributes attributes) {
return new NamedResourceImpl(Integer.parseInt(attributes String href = attributes.getValue(attributes.getIndex("href"));
.getValue(attributes.getIndex("href")).replace(catalogItemRoot + "/", "")), String id = href.replace(catalogItemRoot + "/", "");
attributes.getValue(attributes.getIndex("name")), attributes.getValue(attributes assert !id.contains("https://") : String.format(
.getIndex("type")), URI.create(attributes.getValue(attributes "parse of %s should have stripped, but didn't %s", href, id);
.getIndex("href")))); return new NamedResourceImpl(id, attributes.getValue(attributes.getIndex("name")), attributes
.getValue(attributes.getIndex("type")), URI.create(href));
} }
public void putNamedResource(Map<String, NamedResource> map, Attributes attributes) { public void putNamedResource(Map<String, NamedResource> map, Attributes attributes) {

View File

@ -40,7 +40,7 @@ import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.Organization; import org.jclouds.vcloud.domain.Organization;
import org.jclouds.vcloud.domain.internal.NamedResourceImpl; import org.jclouds.vcloud.domain.internal.NamedResourceImpl;
import org.jclouds.vcloud.domain.internal.OrganizationImpl; import org.jclouds.vcloud.domain.internal.OrganizationImpl;
import org.jclouds.vcloud.endpoints.VCloud; import org.jclouds.vcloud.endpoints.VCloudApi;
import org.xml.sax.Attributes; import org.xml.sax.Attributes;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
@ -55,7 +55,7 @@ public class OrgHandler extends ParseSax.HandlerWithResult<Organization> {
private Map<String, NamedLink> tasksLists = Maps.newHashMap(); private Map<String, NamedLink> tasksLists = Maps.newHashMap();
private NamedLink catalog; private NamedLink catalog;
@Inject @Inject
@VCloud @VCloudApi
URI vcloudUri; URI vcloudUri;
public Organization getResult() { public Organization getResult() {
@ -83,9 +83,8 @@ public class OrgHandler extends ParseSax.HandlerWithResult<Organization> {
} }
public NamedResource newNamedResource(Attributes attributes) { public NamedResource newNamedResource(Attributes attributes) {
return new NamedResourceImpl( return new NamedResourceImpl(attributes.getValue(attributes.getIndex("href")).replace(
Integer.parseInt(attributes.getValue(attributes.getIndex("href")).replace( vcloudUri.toASCIIString() + "/org/", ""), attributes.getValue(attributes
vcloudUri.toASCIIString() + "/org/", "")), attributes.getValue(attributes
.getIndex("name")), attributes.getValue(attributes.getIndex("type")), URI .getIndex("name")), attributes.getValue(attributes.getIndex("type")), URI
.create(attributes.getValue(attributes.getIndex("href")))); .create(attributes.getValue(attributes.getIndex("href"))));
} }

View File

@ -0,0 +1,66 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.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.vcloud.xml;
import java.net.URI;
import java.util.SortedMap;
import org.jclouds.http.functions.ParseSax;
import com.google.common.collect.Maps;
/**
* @author Adrian Cole
*/
public class SupportedVersionsHandler extends ParseSax.HandlerWithResult<SortedMap<String, URI>> {
private StringBuilder currentText = new StringBuilder();
private SortedMap<String, URI> contents = Maps.newTreeMap();
private String version;
private URI location;
public SortedMap<String, URI> getResult() {
return contents;
}
public void endElement(String uri, String name, String qName) {
if (qName.equals("Version")) {
version = currentOrNull();
} else if (qName.equals("LoginUrl")) {
location = URI.create(currentOrNull());
} else if (qName.equals("VersionInfo")) {
contents.put(version, location);
}
currentText = new StringBuilder();
}
public void characters(char ch[], int start, int length) {
currentText.append(ch, start, length);
}
protected String currentOrNull() {
String returnVal = currentText.toString().trim();
return returnVal.equals("") ? null : returnVal;
}
}

View File

@ -38,7 +38,7 @@ import org.jclouds.vcloud.domain.Quota;
import org.jclouds.vcloud.domain.VDC; import org.jclouds.vcloud.domain.VDC;
import org.jclouds.vcloud.domain.internal.NamedResourceImpl; import org.jclouds.vcloud.domain.internal.NamedResourceImpl;
import org.jclouds.vcloud.domain.internal.VDCImpl; import org.jclouds.vcloud.domain.internal.VDCImpl;
import org.jclouds.vcloud.endpoints.VCloud; import org.jclouds.vcloud.endpoints.VCloudApi;
import org.xml.sax.Attributes; import org.xml.sax.Attributes;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
@ -54,7 +54,7 @@ public class VDCHandler extends ParseSax.HandlerWithResult<VDC> {
private Map<String, NamedLink> resourceEntities = Maps.newHashMap(); private Map<String, NamedLink> resourceEntities = Maps.newHashMap();
private Map<String, NamedLink> availableNetworks = Maps.newHashMap(); private Map<String, NamedLink> availableNetworks = Maps.newHashMap();
@Inject @Inject
@VCloud @VCloudApi
URI vcloudUri; URI vcloudUri;
private String description; private String description;
@ -125,11 +125,10 @@ public class VDCHandler extends ParseSax.HandlerWithResult<VDC> {
} }
public NamedResource newNamedResource(Attributes attributes) { public NamedResource newNamedResource(Attributes attributes) {
return new NamedResourceImpl(Integer.parseInt(attributes return new NamedResourceImpl(attributes.getValue(attributes.getIndex("href")).replace(
.getValue(attributes.getIndex("href")).replace(vcloudUri.toASCIIString() + "/vdc/", vcloudUri.toASCIIString() + "/vdc/", ""), attributes.getValue(attributes
"")), attributes.getValue(attributes.getIndex("name")), attributes .getIndex("name")), attributes.getValue(attributes.getIndex("type")), URI
.getValue(attributes.getIndex("type")), URI.create(attributes.getValue(attributes .create(attributes.getValue(attributes.getIndex("href"))));
.getIndex("href"))));
} }
protected String currentOrNull() { protected String currentOrNull() {

View File

@ -40,7 +40,7 @@ import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.vcloud.endpoints.Catalog; import org.jclouds.vcloud.endpoints.Catalog;
import org.jclouds.vcloud.endpoints.TasksList; import org.jclouds.vcloud.endpoints.TasksList;
import org.jclouds.vcloud.endpoints.VCloud; import org.jclouds.vcloud.endpoints.VCloudApi;
import org.jclouds.vcloud.endpoints.VDC; import org.jclouds.vcloud.endpoints.VDC;
import org.jclouds.vcloud.endpoints.internal.CatalogItemRoot; import org.jclouds.vcloud.endpoints.internal.CatalogItemRoot;
import org.jclouds.vcloud.endpoints.internal.VAppRoot; import org.jclouds.vcloud.endpoints.internal.VAppRoot;
@ -112,7 +112,7 @@ public class VCloudClientTest extends RestClientTest<VCloudAsyncClient> {
} }
public void testDeployVApp() throws SecurityException, NoSuchMethodException, IOException { public void testDeployVApp() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("deployVApp", int.class); Method method = VCloudAsyncClient.class.getMethod("deployVApp", String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, 1); GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, 1);
assertRequestLineEquals(httpMethod, "POST http://vcloud/vapp/1/action/deploy HTTP/1.1"); assertRequestLineEquals(httpMethod, "POST http://vcloud/vapp/1/action/deploy HTTP/1.1");
@ -127,7 +127,7 @@ public class VCloudClientTest extends RestClientTest<VCloudAsyncClient> {
} }
public void testUndeployVApp() throws SecurityException, NoSuchMethodException, IOException { public void testUndeployVApp() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("undeployVApp", int.class); Method method = VCloudAsyncClient.class.getMethod("undeployVApp", String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, 1); GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, 1);
assertRequestLineEquals(httpMethod, "POST http://vcloud/vapp/1/action/undeploy HTTP/1.1"); assertRequestLineEquals(httpMethod, "POST http://vcloud/vapp/1/action/undeploy HTTP/1.1");
@ -142,7 +142,7 @@ public class VCloudClientTest extends RestClientTest<VCloudAsyncClient> {
} }
public void testDeleteVApp() throws SecurityException, NoSuchMethodException, IOException { public void testDeleteVApp() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("deleteVApp", int.class); Method method = VCloudAsyncClient.class.getMethod("deleteVApp", String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, 1); GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, 1);
assertRequestLineEquals(httpMethod, "DELETE http://vcloud/vapp/1 HTTP/1.1"); assertRequestLineEquals(httpMethod, "DELETE http://vcloud/vapp/1 HTTP/1.1");
@ -157,7 +157,7 @@ public class VCloudClientTest extends RestClientTest<VCloudAsyncClient> {
} }
public void testPowerOn() throws SecurityException, NoSuchMethodException, IOException { public void testPowerOn() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("powerOnVApp", int.class); Method method = VCloudAsyncClient.class.getMethod("powerOnVApp", String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, 1); GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, 1);
assertRequestLineEquals(httpMethod, "POST http://vcloud/vapp/1/power/action/powerOn HTTP/1.1"); assertRequestLineEquals(httpMethod, "POST http://vcloud/vapp/1/power/action/powerOn HTTP/1.1");
@ -172,7 +172,7 @@ public class VCloudClientTest extends RestClientTest<VCloudAsyncClient> {
} }
public void testPowerOff() throws SecurityException, NoSuchMethodException, IOException { public void testPowerOff() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("powerOffVApp", int.class); Method method = VCloudAsyncClient.class.getMethod("powerOffVApp", String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, 1); GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, 1);
assertRequestLineEquals(httpMethod, assertRequestLineEquals(httpMethod,
@ -188,7 +188,7 @@ public class VCloudClientTest extends RestClientTest<VCloudAsyncClient> {
} }
public void testReset() throws SecurityException, NoSuchMethodException, IOException { public void testReset() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("resetVApp", int.class); Method method = VCloudAsyncClient.class.getMethod("resetVApp", String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, 1); GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, 1);
assertRequestLineEquals(httpMethod, "POST http://vcloud/vapp/1/power/action/reset HTTP/1.1"); assertRequestLineEquals(httpMethod, "POST http://vcloud/vapp/1/power/action/reset HTTP/1.1");
@ -203,7 +203,7 @@ public class VCloudClientTest extends RestClientTest<VCloudAsyncClient> {
} }
public void testSuspend() throws SecurityException, NoSuchMethodException, IOException { public void testSuspend() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("suspendVApp", int.class); Method method = VCloudAsyncClient.class.getMethod("suspendVApp", String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, 1); GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, 1);
assertRequestLineEquals(httpMethod, "POST http://vcloud/vapp/1/power/action/suspend HTTP/1.1"); assertRequestLineEquals(httpMethod, "POST http://vcloud/vapp/1/power/action/suspend HTTP/1.1");
@ -218,7 +218,7 @@ public class VCloudClientTest extends RestClientTest<VCloudAsyncClient> {
} }
public void testShutdown() throws SecurityException, NoSuchMethodException, IOException { public void testShutdown() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("shutdownVApp", int.class); Method method = VCloudAsyncClient.class.getMethod("shutdownVApp", String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, 1); GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, 1);
assertRequestLineEquals(httpMethod, assertRequestLineEquals(httpMethod,
@ -289,7 +289,7 @@ public class VCloudClientTest extends RestClientTest<VCloudAsyncClient> {
bind(URI.class).annotatedWith(VDC.class).toInstance(URI.create("http://vdc")); bind(URI.class).annotatedWith(VDC.class).toInstance(URI.create("http://vdc"));
bind(URI.class).annotatedWith(TasksList.class).toInstance( bind(URI.class).annotatedWith(TasksList.class).toInstance(
URI.create("http://tasksList")); URI.create("http://tasksList"));
bind(URI.class).annotatedWith(VCloud.class).toInstance(URI.create("http://vcloud")); bind(URI.class).annotatedWith(VCloudApi.class).toInstance(URI.create("http://vcloud"));
bind(SetVCloudTokenCookie.class).toInstance( bind(SetVCloudTokenCookie.class).toInstance(
new SetVCloudTokenCookie(new Provider<String>() { new SetVCloudTokenCookie(new Provider<String>() {

View File

@ -27,6 +27,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_KEY; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_KEY;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_SESSIONINTERVAL; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_SESSIONINTERVAL;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_USER; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_USER;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_VERSION;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNotNull;
@ -116,6 +117,7 @@ public class VCloudDiscoveryLiveTest {
protected void addClientModule(List<Module> modules) { protected void addClientModule(List<Module> modules) {
properties.setProperty(VCloudConstants.PROPERTY_VCLOUD_ENDPOINT, checkNotNull(endpoint, properties.setProperty(VCloudConstants.PROPERTY_VCLOUD_ENDPOINT, checkNotNull(endpoint,
"endpoint").toString()); "endpoint").toString());
properties.setProperty(PROPERTY_VCLOUD_VERSION, "0.8");
properties.setProperty(PROPERTY_VCLOUD_USER, checkNotNull(account, "user")); properties.setProperty(PROPERTY_VCLOUD_USER, checkNotNull(account, "user"));
properties.setProperty(PROPERTY_VCLOUD_KEY, checkNotNull(key, "key")); properties.setProperty(PROPERTY_VCLOUD_KEY, checkNotNull(key, "key"));
properties.setProperty(PROPERTY_VCLOUD_SESSIONINTERVAL, "4"); properties.setProperty(PROPERTY_VCLOUD_SESSIONINTERVAL, "4");

View File

@ -38,7 +38,7 @@ import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.vcloud.endpoints.Org; import org.jclouds.vcloud.endpoints.Org;
import org.jclouds.vcloud.endpoints.VCloud; import org.jclouds.vcloud.endpoints.VCloudApi;
import org.jclouds.vcloud.filters.SetVCloudTokenCookie; import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
import org.jclouds.vcloud.xml.OrgHandler; import org.jclouds.vcloud.xml.OrgHandler;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -106,7 +106,7 @@ public class VCloudDiscoveryTest extends RestClientTest<VCloudDiscovery> {
} }
@SuppressWarnings("unused") @SuppressWarnings("unused")
@Provides @Provides
@VCloud @VCloudApi
URI provide() { URI provide() {
return URI.create("https://services.vcloudexpress.terremark.com/api/v0.8"); return URI.create("https://services.vcloudexpress.terremark.com/api/v0.8");
} }

View File

@ -27,6 +27,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_KEY; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_KEY;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_SESSIONINTERVAL; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_SESSIONINTERVAL;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_USER; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_USER;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_VERSION;
import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNotNull;
import java.net.URI; import java.net.URI;
@ -113,6 +114,7 @@ public class VCloudLoginLiveTest {
protected void addClientModule(List<Module> modules) { protected void addClientModule(List<Module> modules) {
properties.setProperty(VCloudConstants.PROPERTY_VCLOUD_ENDPOINT, checkNotNull(endpoint, properties.setProperty(VCloudConstants.PROPERTY_VCLOUD_ENDPOINT, checkNotNull(endpoint,
"endpoint").toString()); "endpoint").toString());
properties.setProperty(PROPERTY_VCLOUD_VERSION, "0.8");
properties.setProperty(PROPERTY_VCLOUD_USER, checkNotNull(account, "user")); properties.setProperty(PROPERTY_VCLOUD_USER, checkNotNull(account, "user"));
properties.setProperty(PROPERTY_VCLOUD_KEY, checkNotNull(key, "key")); properties.setProperty(PROPERTY_VCLOUD_KEY, checkNotNull(key, "key"));
properties.setProperty(PROPERTY_VCLOUD_SESSIONINTERVAL, "4"); properties.setProperty(PROPERTY_VCLOUD_SESSIONINTERVAL, "4");

View File

@ -39,7 +39,6 @@ import org.jclouds.logging.Logger.LoggerFactory;
import org.jclouds.rest.RestClientTest; import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.vcloud.endpoints.VCloud;
import org.jclouds.vcloud.functions.ParseLoginResponseFromHeaders; import org.jclouds.vcloud.functions.ParseLoginResponseFromHeaders;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -87,8 +86,8 @@ public class VCloudLoginTest extends RestClientTest<VCloudLogin> {
return new AbstractModule() { return new AbstractModule() {
@Override @Override
protected void configure() { protected void configure() {
bind(URI.class).annotatedWith(VCloud.class).toInstance( bind(URI.class).annotatedWith(org.jclouds.vcloud.endpoints.VCloudLogin.class)
URI.create("http://localhost:8080")); .toInstance(URI.create("http://localhost:8080/login"));
try { try {
bind(BasicAuthentication.class).toInstance(new BasicAuthentication("user", "pass")); bind(BasicAuthentication.class).toInstance(new BasicAuthentication("user", "pass"));
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {

View File

@ -0,0 +1,132 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.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.vcloud;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.testng.Assert.assertNotNull;
import java.net.URI;
import java.util.List;
import java.util.Properties;
import java.util.SortedMap;
import java.util.concurrent.TimeUnit;
import javax.inject.Singleton;
import org.jclouds.concurrent.WithinThreadExecutorService;
import org.jclouds.concurrent.config.ExecutorServiceModule;
import org.jclouds.http.RequiresHttp;
import org.jclouds.lifecycle.Closer;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.RestClientFactory;
import org.jclouds.rest.RestContext;
import org.jclouds.rest.RestContextBuilder;
import org.jclouds.rest.internal.RestContextImpl;
import org.jclouds.vcloud.endpoints.VCloud;
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 VCloudVersions}
*
* @author Adrian Cole
*/
@Test(groups = "live", testName = "vcloud.VCloudVersionsLiveTest")
public class VCloudVersionsLiveTest {
@RequiresHttp
@ConfiguresRestClient
private static final class VCloudVersionsRestClientModule extends AbstractModule {
@SuppressWarnings("unused")
@Provides
@Singleton
protected VCloudVersions provideVCloudVersions(RestClientFactory factory) {
return factory.create(VCloudVersions.class);
}
@Override
protected void configure() {
bind(URI.class).annotatedWith(VCloud.class).toInstance(URI.create(endpoint));
}
}
private final class VCloudVersionsContextModule extends AbstractModule {
@SuppressWarnings( { "unused" })
@Provides
@Singleton
RestContext<VCloudVersions, VCloudVersions> provideContext(Closer closer, VCloudVersions api,
@VCloud URI endPoint) {
return new RestContextImpl<VCloudVersions, VCloudVersions>(closer, api, api, endPoint, "");
}
@Override
protected void configure() {
}
}
static String endpoint = checkNotNull(System.getProperty("jclouds.test.endpoint"),
"jclouds.test.endpoint");
private RestContext<VCloudVersions, VCloudVersions> context;
@Test
public void testGetSupportedVersions() throws Exception {
VCloudVersions authentication = context.getAsyncApi();
for (int i = 0; i < 5; i++) {
SortedMap<String, URI> response = authentication.getSupportedVersions().get(45,
TimeUnit.SECONDS);
assertNotNull(response);
assertNotNull(response.containsKey("0.8"));
}
}
@BeforeClass
void setupFactory() {
context = new RestContextBuilder<VCloudVersions, VCloudVersions>(
new TypeLiteral<VCloudVersions>() {
}, new TypeLiteral<VCloudVersions>() {
}, new Properties()) {
public void addContextModule(List<Module> modules) {
modules.add(new VCloudVersionsContextModule());
}
@Override
protected void addClientModule(List<Module> modules) {
modules.add(new VCloudVersionsRestClientModule());
}
}.withModules(new Log4JLoggingModule(),
new ExecutorServiceModule(new WithinThreadExecutorService())).buildContext();
}
}

View File

@ -0,0 +1,100 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.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.vcloud;
import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.lang.reflect.Method;
import java.net.URI;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.logging.Logger;
import org.jclouds.logging.Logger.LoggerFactory;
import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.vcloud.endpoints.VCloud;
import org.jclouds.vcloud.xml.SupportedVersionsHandler;
import org.testng.annotations.Test;
import com.google.inject.AbstractModule;
import com.google.inject.Module;
import com.google.inject.TypeLiteral;
/**
* Tests behavior of {@code VCloudVersions}
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "vcloud.VCloudVersionsTest")
public class VCloudVersionsTest extends RestClientTest<VCloudVersions> {
public void testLogin() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudVersions.class.getMethod("getSupportedVersions");
GeneratedHttpRequest<VCloudVersions> httpMethod = processor.createRequest(method);
assertEquals(httpMethod.getRequestLine(), "GET http://localhost:8080/versions HTTP/1.1");
assertHeadersEqual(httpMethod, HttpHeaders.ACCEPT + ": " + MediaType.APPLICATION_XML + "\n");
assertEntityEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
assertSaxResponseParserClassEquals(method, SupportedVersionsHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod);
}
@Override
protected void checkFilters(GeneratedHttpRequest<VCloudVersions> httpMethod) {
assertEquals(httpMethod.getFilters().size(), 0);
}
@Override
protected TypeLiteral<RestAnnotationProcessor<VCloudVersions>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<VCloudVersions>>() {
};
}
@Override
protected Module createModule() {
return new AbstractModule() {
@Override
protected void configure() {
bind(URI.class).annotatedWith(VCloud.class).toInstance(
URI.create("http://localhost:8080"));
bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() {
public Logger getLogger(String category) {
return Logger.NULL;
}
});
}
};
}
}

View File

@ -27,6 +27,7 @@ import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_ENDPO
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_KEY; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_KEY;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_SESSIONINTERVAL; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_SESSIONINTERVAL;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_USER; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_USER;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_VERSION;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import java.util.Map; import java.util.Map;
@ -42,6 +43,7 @@ import org.jclouds.http.handlers.CloseContentAndSetExceptionErrorHandler;
import org.jclouds.http.handlers.DelegatingErrorHandler; import org.jclouds.http.handlers.DelegatingErrorHandler;
import org.jclouds.http.handlers.DelegatingRetryHandler; import org.jclouds.http.handlers.DelegatingRetryHandler;
import org.jclouds.http.handlers.RedirectionRetryHandler; import org.jclouds.http.handlers.RedirectionRetryHandler;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.rest.domain.NamedLink; import org.jclouds.rest.domain.NamedLink;
import org.jclouds.util.Jsr330; import org.jclouds.util.Jsr330;
import org.jclouds.vcloud.VCloudLogin; import org.jclouds.vcloud.VCloudLogin;
@ -60,10 +62,11 @@ import com.google.inject.Injector;
public class VCloudDiscoveryRestClientModuleTest { public class VCloudDiscoveryRestClientModuleTest {
Injector createInjector() { Injector createInjector() {
return Guice.createInjector(new VCloudDiscoveryRestClientModule(), new ParserModule(), return Guice.createInjector(new VCloudDiscoveryRestClientModule(), new Log4JLoggingModule(),
new AbstractModule() { new ParserModule(), new AbstractModule() {
@Override @Override
protected void configure() { protected void configure() {
bindConstant().annotatedWith(Jsr330.named(PROPERTY_VCLOUD_VERSION)).to("0.8");
bindConstant().annotatedWith(Jsr330.named(PROPERTY_VCLOUD_USER)).to("user"); bindConstant().annotatedWith(Jsr330.named(PROPERTY_VCLOUD_USER)).to("user");
bindConstant().annotatedWith(Jsr330.named(PROPERTY_VCLOUD_KEY)).to("secret"); bindConstant().annotatedWith(Jsr330.named(PROPERTY_VCLOUD_KEY)).to("secret");
bindConstant().annotatedWith(Jsr330.named(PROPERTY_VCLOUD_ENDPOINT)).to( bindConstant().annotatedWith(Jsr330.named(PROPERTY_VCLOUD_ENDPOINT)).to(

View File

@ -1,72 +0,0 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.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.vcloud.config;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_ENDPOINT;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_KEY;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_SESSIONINTERVAL;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_USER;
import static org.testng.Assert.assertEquals;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.util.Jsr330;
import org.jclouds.vcloud.endpoints.internal.CatalogItemRoot;
import org.jclouds.vcloud.endpoints.internal.VAppRoot;
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;
/**
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "vcloud.VCloudRestClientModuleTest")
public class VCloudRestClientModuleTest extends VCloudDiscoveryRestClientModuleTest {
protected Injector createInjector() {
return Guice.createInjector(new VCloudRestClientModule(),
new VCloudDiscoveryRestClientModule(), new ParserModule(), new AbstractModule() {
@Override
protected void configure() {
bindConstant().annotatedWith(Jsr330.named(PROPERTY_VCLOUD_USER)).to("user");
bindConstant().annotatedWith(Jsr330.named(PROPERTY_VCLOUD_KEY)).to("secret");
bindConstant().annotatedWith(Jsr330.named(PROPERTY_VCLOUD_ENDPOINT)).to(
"http://localhost");
bindConstant().annotatedWith(Jsr330.named(PROPERTY_VCLOUD_SESSIONINTERVAL))
.to("2");
}
});
}
@Test
void testCatalogItemRoot() {
assertEquals(createInjector().getInstance(Key.get(String.class, CatalogItemRoot.class)),
"http://localhost/catalogItem");
assertEquals(createInjector().getInstance(Key.get(String.class, VAppRoot.class)),
"http://localhost/vapp");
}
}

View File

@ -79,84 +79,84 @@ public class CatalogHandlerTest {
assertEquals(result.getLocation(), URI assertEquals(result.getLocation(), URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32/catalog")); .create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32/catalog"));
assertEquals(result.get("CentOS 5.3 (32-bit)"), new NamedResourceImpl(5, assertEquals(result.get("CentOS 5.3 (32-bit)"), new NamedResourceImpl(5 + "",
"CentOS 5.3 (32-bit)", CATALOGITEM_XML, "CentOS 5.3 (32-bit)", CATALOGITEM_XML,
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/5"))); URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/5")));
assertEquals(result.get("CentOS 5.3 (64-bit)"), new NamedResourceImpl(6, assertEquals(result.get("CentOS 5.3 (64-bit)"), new NamedResourceImpl(6 + "",
"CentOS 5.3 (64-bit)", CATALOGITEM_XML, "CentOS 5.3 (64-bit)", CATALOGITEM_XML,
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/6"))); URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/6")));
assertEquals(result.get("RHEL 5.3 (32-bit)"), new NamedResourceImpl(7, "RHEL 5.3 (32-bit)", assertEquals(result.get("RHEL 5.3 (32-bit)"), new NamedResourceImpl(7 + "",
CATALOGITEM_XML, "RHEL 5.3 (32-bit)", CATALOGITEM_XML,
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/7"))); URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/7")));
assertEquals(result.get("RHEL 5.3 (64-bit)"), new NamedResourceImpl(8, "RHEL 5.3 (64-bit)", assertEquals(result.get("RHEL 5.3 (64-bit)"), new NamedResourceImpl(8 + "",
CATALOGITEM_XML, "RHEL 5.3 (64-bit)", CATALOGITEM_XML,
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/8"))); URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/8")));
assertEquals(result.get("Ubuntu JeOS 9.04 (32-bit)"), new NamedResourceImpl(11, assertEquals(result.get("Ubuntu JeOS 9.04 (32-bit)"), new NamedResourceImpl(11 + "",
"Ubuntu JeOS 9.04 (32-bit)", CATALOGITEM_XML, "Ubuntu JeOS 9.04 (32-bit)", CATALOGITEM_XML,
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/11"))); URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/11")));
assertEquals(result.get("Ubuntu JeOS 9.04 (64-bit)"), new NamedResourceImpl(12, assertEquals(result.get("Ubuntu JeOS 9.04 (64-bit)"), new NamedResourceImpl(12 + "",
"Ubuntu JeOS 9.04 (64-bit)", CATALOGITEM_XML, "Ubuntu JeOS 9.04 (64-bit)", CATALOGITEM_XML,
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/12"))); URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/12")));
assertEquals(result.get("Ubuntu Server 9.04 (32-bit)"), new NamedResourceImpl(9, assertEquals(result.get("Ubuntu Server 9.04 (32-bit)"), new NamedResourceImpl(9 + "",
"Ubuntu Server 9.04 (32-bit)", CATALOGITEM_XML, "Ubuntu Server 9.04 (32-bit)", CATALOGITEM_XML,
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/9"))); URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/9")));
assertEquals(result.get("Ubuntu Server 9.04 (64-bit)"), new NamedResourceImpl(10, assertEquals(result.get("Ubuntu Server 9.04 (64-bit)"), new NamedResourceImpl(10 + "",
"Ubuntu Server 9.04 (64-bit)", CATALOGITEM_XML, "Ubuntu Server 9.04 (64-bit)", CATALOGITEM_XML,
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/10"))); URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/10")));
assertEquals(result.get("Windows 2003 Enterprise R2 (32-bit)"), new NamedResourceImpl(1, assertEquals(result.get("Windows 2003 Enterprise R2 (32-bit)"), new NamedResourceImpl(1 + "",
"Windows 2003 Enterprise R2 (32-bit)", CATALOGITEM_XML, "Windows 2003 Enterprise R2 (32-bit)", CATALOGITEM_XML,
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/1"))); URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/1")));
assertEquals(result.get("Windows 2003 Enterprise R2 (64-bit)"), new NamedResourceImpl(2, assertEquals(result.get("Windows 2003 Enterprise R2 (64-bit)"), new NamedResourceImpl(2 + "",
"Windows 2003 Enterprise R2 (64-bit)", CATALOGITEM_XML, "Windows 2003 Enterprise R2 (64-bit)", CATALOGITEM_XML,
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/2"))); URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/2")));
assertEquals(result.get("Windows 2003 Standard R2 (32-bit)"), new NamedResourceImpl(3, assertEquals(result.get("Windows 2003 Standard R2 (32-bit)"), new NamedResourceImpl(3 + "",
"Windows 2003 Standard R2 (32-bit)", CATALOGITEM_XML, "Windows 2003 Standard R2 (32-bit)", CATALOGITEM_XML,
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/3"))); URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/3")));
assertEquals(result.get("Windows 2003 Standard R2 (64-bit)"), new NamedResourceImpl(4, assertEquals(result.get("Windows 2003 Standard R2 (64-bit)"), new NamedResourceImpl(4 + "",
"Windows 2003 Standard R2 (64-bit)", CATALOGITEM_XML, "Windows 2003 Standard R2 (64-bit)", CATALOGITEM_XML,
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/4"))); URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/4")));
assertEquals( assertEquals(
result.get("Windows 2003 Standard R2 w.SQL 2008 Web (64-bit)"), result.get("Windows 2003 Standard R2 w.SQL 2008 Web (64-bit)"),
new NamedResourceImpl( new NamedResourceImpl(
23, 23 + "",
"Windows 2003 Standard R2 w.SQL 2008 Web (64-bit)", "Windows 2003 Standard R2 w.SQL 2008 Web (64-bit)",
CATALOGITEM_XML, CATALOGITEM_XML,
URI URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/23"))); .create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/23")));
assertEquals(result.get("Windows Server 2008 Enterprise (32-bit)"), new NamedResourceImpl(13, assertEquals(result.get("Windows Server 2008 Enterprise (32-bit)"), new NamedResourceImpl(
"Windows Server 2008 Enterprise (32-bit)", CATALOGITEM_XML, 13 + "", "Windows Server 2008 Enterprise (32-bit)", CATALOGITEM_XML,
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/13"))); URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/13")));
assertEquals(result.get("Windows Server 2008 Enterprise (64-bit)"), new NamedResourceImpl(15, assertEquals(result.get("Windows Server 2008 Enterprise (64-bit)"), new NamedResourceImpl(
"Windows Server 2008 Enterprise (64-bit)", CATALOGITEM_XML, 15 + "", "Windows Server 2008 Enterprise (64-bit)", CATALOGITEM_XML,
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/15"))); URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/15")));
assertEquals(result.get("Windows Server 2008 Enterprise R2 (64-bit)"), new NamedResourceImpl( assertEquals(result.get("Windows Server 2008 Enterprise R2 (64-bit)"), new NamedResourceImpl(
16, "Windows Server 2008 Enterprise R2 (64-bit)", CATALOGITEM_XML, 16 + "", "Windows Server 2008 Enterprise R2 (64-bit)", CATALOGITEM_XML,
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/16"))); URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/16")));
assertEquals(result.get("Windows Server 2008 Standard (32-bit)"), new NamedResourceImpl(17, assertEquals(result.get("Windows Server 2008 Standard (32-bit)"), new NamedResourceImpl(
"Windows Server 2008 Standard (32-bit)", CATALOGITEM_XML, 17 + "", "Windows Server 2008 Standard (32-bit)", CATALOGITEM_XML,
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/17"))); URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/17")));
assertEquals(result.get("Windows Server 2008 Standard (64-bit)"), new NamedResourceImpl(18, assertEquals(result.get("Windows Server 2008 Standard (64-bit)"), new NamedResourceImpl(
"Windows Server 2008 Standard (64-bit)", CATALOGITEM_XML, 18 + "", "Windows Server 2008 Standard (64-bit)", CATALOGITEM_XML,
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/18"))); URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/18")));
assertEquals(result.get("Windows Server 2008 Standard R2 (64-bit)"), new NamedResourceImpl( assertEquals(result.get("Windows Server 2008 Standard R2 (64-bit)"), new NamedResourceImpl(
19, "Windows Server 2008 Standard R2 (64-bit)", CATALOGITEM_XML, 19 + "", "Windows Server 2008 Standard R2 (64-bit)", CATALOGITEM_XML,
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/19"))); URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/19")));
assertEquals( assertEquals(
result.get("Windows Server 2008 Standard w.SQL 2008 Web (64-bit)"), result.get("Windows Server 2008 Standard w.SQL 2008 Web (64-bit)"),
new NamedResourceImpl( new NamedResourceImpl(
14, 14 + "",
"Windows Server 2008 Standard w.SQL 2008 Web (64-bit)", "Windows Server 2008 Standard w.SQL 2008 Web (64-bit)",
CATALOGITEM_XML, CATALOGITEM_XML,
URI URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/14"))); .create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/14")));
assertEquals(result.get("Windows Web Server 2008 (32-bit)"), new NamedResourceImpl(20, assertEquals(result.get("Windows Web Server 2008 (32-bit)"), new NamedResourceImpl(20 + "",
"Windows Web Server 2008 (32-bit)", CATALOGITEM_XML, "Windows Web Server 2008 (32-bit)", CATALOGITEM_XML,
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/20"))); URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/20")));
assertEquals(result.get("Windows Web Server 2008 (64-bit)"), new NamedResourceImpl(21, assertEquals(result.get("Windows Web Server 2008 (64-bit)"), new NamedResourceImpl(21 + "",
"Windows Web Server 2008 (64-bit)", CATALOGITEM_XML, "Windows Web Server 2008 (64-bit)", CATALOGITEM_XML,
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/21"))); URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/21")));
assertEquals(result.get("Windows Web Server 2008 R2 (64-bit)"), new NamedResourceImpl(22, assertEquals(result.get("Windows Web Server 2008 R2 (64-bit)"), new NamedResourceImpl(
"Windows Web Server 2008 R2 (64-bit)", CATALOGITEM_XML, 22 + "", "Windows Web Server 2008 R2 (64-bit)", CATALOGITEM_XML,
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/22"))); URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/22")));
} }
@ -185,19 +185,19 @@ public class CatalogHandlerTest {
assertEquals(result.getLocation(), URI assertEquals(result.getLocation(), URI
.create("https://vcloud.safesecureweb.com/api/v0.8/catalog/1")); .create("https://vcloud.safesecureweb.com/api/v0.8/catalog/1"));
assertEquals(result.get("Plesk (Linux) 64-bit Template"), new NamedResourceImpl(1, assertEquals(result.get("Plesk (Linux) 64-bit Template"), new NamedResourceImpl(1 + "",
"Plesk (Linux) 64-bit Template", CATALOGITEM_XML, URI "Plesk (Linux) 64-bit Template", CATALOGITEM_XML, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/1"))); .create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/1")));
assertEquals(result.get("Windows 2008 Datacenter 64 Bit Template"), new NamedResourceImpl(2, assertEquals(result.get("Windows 2008 Datacenter 64 Bit Template"), new NamedResourceImpl(
"Windows 2008 Datacenter 64 Bit Template", CATALOGITEM_XML, URI 2 + "", "Windows 2008 Datacenter 64 Bit Template", CATALOGITEM_XML, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/2"))); .create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/2")));
assertEquals(result.get("Cent OS 64 Bit Template"), new NamedResourceImpl(3, assertEquals(result.get("Cent OS 64 Bit Template"), new NamedResourceImpl(3 + "",
"Cent OS 64 Bit Template", CATALOGITEM_XML, URI "Cent OS 64 Bit Template", CATALOGITEM_XML, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/3"))); .create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/3")));
assertEquals(result.get("cPanel (Linux) 64 Bit Template"), new NamedResourceImpl(4, assertEquals(result.get("cPanel (Linux) 64 Bit Template"), new NamedResourceImpl(4 + "",
"cPanel (Linux) 64 Bit Template", CATALOGITEM_XML, URI "cPanel (Linux) 64 Bit Template", CATALOGITEM_XML, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/4"))); .create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/4")));
} }

View File

@ -38,7 +38,7 @@ import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.rest.domain.internal.NamedLinkImpl; import org.jclouds.rest.domain.internal.NamedLinkImpl;
import org.jclouds.vcloud.VCloudMediaType; import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.domain.Organization; import org.jclouds.vcloud.domain.Organization;
import org.jclouds.vcloud.endpoints.VCloud; import org.jclouds.vcloud.endpoints.VCloudApi;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
@ -68,7 +68,7 @@ public class OrgHandlerTest {
@SuppressWarnings("unused") @SuppressWarnings("unused")
@Provides @Provides
@Singleton @Singleton
@VCloud @VCloudApi
URI provide(){ URI provide(){
return URI.create("https://services.vcloudexpress.terremark.com/api/v0.8"); return URI.create("https://services.vcloudexpress.terremark.com/api/v0.8");
} }
@ -79,7 +79,7 @@ public class OrgHandlerTest {
Organization result = (Organization) factory.create(injector.getInstance(OrgHandler.class)) Organization result = (Organization) factory.create(injector.getInstance(OrgHandler.class))
.parse(is); .parse(is);
assertEquals(result.getName(), "adrian@jclouds.org"); assertEquals(result.getName(), "adrian@jclouds.org");
assertEquals(result.getId(), 48); assertEquals(result.getId(), 48+"");
assertEquals(result.getLocation(), URI assertEquals(result.getLocation(), URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/org/48")); .create("https://services.vcloudexpress.terremark.com/api/v0.8/org/48"));
assertEquals(result.getCatalog(), new NamedLinkImpl("Miami Environment 1 Catalog", assertEquals(result.getCatalog(), new NamedLinkImpl("Miami Environment 1 Catalog",
@ -111,7 +111,7 @@ public class OrgHandlerTest {
@SuppressWarnings("unused") @SuppressWarnings("unused")
@Provides @Provides
@Singleton @Singleton
@VCloud @VCloudApi
URI provide(){ URI provide(){
return URI.create("https://vcloud.safesecureweb.com/api/v0.8"); return URI.create("https://vcloud.safesecureweb.com/api/v0.8");
} }
@ -121,7 +121,7 @@ public class OrgHandlerTest {
Organization result = (Organization) factory.create(injector.getInstance(OrgHandler.class)) Organization result = (Organization) factory.create(injector.getInstance(OrgHandler.class))
.parse(is); .parse(is);
assertEquals(result.getName(), "Customer 188849"); assertEquals(result.getName(), "Customer 188849");
assertEquals(result.getId(), 188849); assertEquals(result.getId(), 188849+"");
assertEquals(result.getLocation(), URI assertEquals(result.getLocation(), URI
.create("https://vcloud.safesecureweb.com/api/v0.8/org/188849")); .create("https://vcloud.safesecureweb.com/api/v0.8/org/188849"));
assertEquals(result.getCatalog(), new NamedLinkImpl("HMS Shared Catalog", CATALOG_XML, URI assertEquals(result.getCatalog(), new NamedLinkImpl("HMS Shared Catalog", CATALOG_XML, URI

View File

@ -0,0 +1,60 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.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.vcloud.xml;
import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import java.net.URI;
import java.util.SortedMap;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ParseSax.Factory;
import org.jclouds.http.functions.config.ParserModule;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSortedMap;
import com.google.inject.Guice;
import com.google.inject.Injector;
/**
* Tests behavior of {@code SupportedVersionsHandler}
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "vcloud.SupportedVersionsHandlerTest")
public class SupportedVersionsHandlerTest {
public void testApplyInputStream() {
InputStream is = getClass().getResourceAsStream("/versions.xml");
Injector injector = Guice.createInjector(new ParserModule());
Factory factory = injector.getInstance(ParseSax.Factory.class);
SortedMap<String, URI> result = factory.create(
injector.getInstance(SupportedVersionsHandler.class)).parse(is);
assertEquals(result, ImmutableSortedMap.of("0.8", URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/login")));
}
}

View File

@ -36,7 +36,7 @@ import org.jclouds.rest.domain.internal.NamedLinkImpl;
import org.jclouds.vcloud.domain.Capacity; import org.jclouds.vcloud.domain.Capacity;
import org.jclouds.vcloud.domain.Quota; import org.jclouds.vcloud.domain.Quota;
import org.jclouds.vcloud.domain.VDC; import org.jclouds.vcloud.domain.VDC;
import org.jclouds.vcloud.endpoints.VCloud; import org.jclouds.vcloud.endpoints.VCloudApi;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
@ -63,7 +63,7 @@ public class VDCHandlerTest {
@SuppressWarnings("unused") @SuppressWarnings("unused")
@Provides @Provides
@VCloud @VCloudApi
URI provide() { URI provide() {
return URI.create("https://services.vcloudexpress.terremark.com/api/v0.8"); return URI.create("https://services.vcloudexpress.terremark.com/api/v0.8");
} }
@ -103,7 +103,7 @@ public class VDCHandlerTest {
@SuppressWarnings("unused") @SuppressWarnings("unused")
@Provides @Provides
@VCloud @VCloudApi
URI provide() { URI provide() {
return URI.create("https://vcloud.safesecureweb.com/api/v0.8"); return URI.create("https://vcloud.safesecureweb.com/api/v0.8");
} }

View File

@ -77,6 +77,31 @@
</layout> </layout>
</appender> </appender>
<!-- A time/date based rolling appender -->
<appender name="VCLOUDFILE" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="target/test-data/jclouds-vcloud.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 name="ASYNC" class="org.apache.log4j.AsyncAppender">
<appender-ref ref="FILE" /> <appender-ref ref="FILE" />
</appender> </appender>
@ -85,6 +110,10 @@
<appender-ref ref="WIREFILE" /> <appender-ref ref="WIREFILE" />
</appender> </appender>
<appender name="ASYNCVCLOUD" class="org.apache.log4j.AsyncAppender">
<appender-ref ref="VCLOUDFILE" />
</appender>
<!-- ================ --> <!-- ================ -->
<!-- Limit categories --> <!-- Limit categories -->
<!-- ================ --> <!-- ================ -->
@ -100,6 +129,13 @@
</category> </category>
<category name="org.jclouds.vcloud.terremark.VCloudComputeClient">
<priority value="TRACE" />
<appender-ref ref="ASYNCVCLOUD" />
</category>
<category name="org.jclouds.predicates.SocketOpen"> <category name="org.jclouds.predicates.SocketOpen">
<priority value="TRACE" /> <priority value="TRACE" />
<appender-ref ref="ASYNCWIRE" /> <appender-ref ref="ASYNCWIRE" />

View File

@ -0,0 +1,7 @@
<SupportedVersions xmlns="http://www.vmware.com/vcloud/versions"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<VersionInfo>
<Version>0.8</Version>
<LoginUrl>https://services.vcloudexpress.terremark.com/api/v0.8/login</LoginUrl>
</VersionInfo>
</SupportedVersions>

View File

@ -83,7 +83,7 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient {
@XMLResponseParser(TerremarkVAppHandler.class) @XMLResponseParser(TerremarkVAppHandler.class)
@MapBinder(InstantiateVAppTemplateOptions.class) @MapBinder(InstantiateVAppTemplateOptions.class)
Future<? extends VApp> instantiateVAppTemplate(@MapEntityParam("name") String appName, Future<? extends VApp> instantiateVAppTemplate(@MapEntityParam("name") String appName,
@MapEntityParam("template") @ParamParser(CatalogIdToUri.class) int templateId, @MapEntityParam("template") @ParamParser(CatalogIdToUri.class) String templateId,
InstantiateVAppTemplateOptions... options); InstantiateVAppTemplateOptions... options);
@POST @POST
@ -97,61 +97,61 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient {
AddInternetServiceOptions... options); AddInternetServiceOptions... options);
@POST @POST
@Endpoint(org.jclouds.vcloud.endpoints.VCloud.class) @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
@Path("/publicIps/{ipId}/InternetServices") @Path("/publicIps/{ipId}/InternetServices")
@Produces(MediaType.APPLICATION_XML) @Produces(MediaType.APPLICATION_XML)
@XMLResponseParser(InternetServiceHandler.class) @XMLResponseParser(InternetServiceHandler.class)
@MapBinder(AddInternetServiceOptions.class) @MapBinder(AddInternetServiceOptions.class)
Future<? extends InternetService> addInternetServiceToExistingIp( Future<? extends InternetService> addInternetServiceToExistingIp(
@PathParam("ipId") int existingIpId, @MapEntityParam("name") String serviceName, @PathParam("ipId") String existingIpId, @MapEntityParam("name") String serviceName,
@MapEntityParam("protocol") String protocol, @MapEntityParam("port") int port, @MapEntityParam("protocol") String protocol, @MapEntityParam("port") int port,
AddInternetServiceOptions... options); AddInternetServiceOptions... options);
@DELETE @DELETE
@Endpoint(org.jclouds.vcloud.endpoints.VCloud.class) @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
@Path("/internetServices/{internetServiceId}") @Path("/internetServices/{internetServiceId}")
Future<Void> deleteInternetService(@PathParam("internetServiceId") int internetServiceId); Future<Void> deleteInternetService(@PathParam("internetServiceId") String internetServiceId);
@GET @GET
@Endpoint(org.jclouds.vcloud.endpoints.VCloud.class) @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
@Path("/internetServices/{internetServiceId}") @Path("/internetServices/{internetServiceId}")
@XMLResponseParser(InternetServiceHandler.class) @XMLResponseParser(InternetServiceHandler.class)
Future<? extends InternetService> getInternetService( Future<? extends InternetService> getInternetService(
@PathParam("internetServiceId") int internetServiceId); @PathParam("internetServiceId") String internetServiceId);
@POST @POST
@Endpoint(org.jclouds.vcloud.endpoints.VCloud.class) @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
@Path("/internetServices/{internetServiceId}/nodes") @Path("/internetServices/{internetServiceId}/nodes")
@Produces(MediaType.APPLICATION_XML) @Produces(MediaType.APPLICATION_XML)
@XMLResponseParser(NodeHandler.class) @XMLResponseParser(NodeHandler.class)
@MapBinder(AddNodeOptions.class) @MapBinder(AddNodeOptions.class)
Future<? extends Node> addNode( Future<? extends Node> addNode(
@PathParam("internetServiceId") int internetServiceId, @PathParam("internetServiceId") String internetServiceId,
@MapEntityParam("ipAddress") @ParamParser(InetAddressToHostAddress.class) InetAddress ipAddress, @MapEntityParam("ipAddress") @ParamParser(InetAddressToHostAddress.class) InetAddress ipAddress,
@MapEntityParam("name") String name, @MapEntityParam("port") int port, @MapEntityParam("name") String name, @MapEntityParam("port") int port,
AddNodeOptions... options); AddNodeOptions... options);
@GET @GET
@Endpoint(org.jclouds.vcloud.endpoints.VCloud.class) @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
@Path("/nodeServices/{nodeId}") @Path("/nodeServices/{nodeId}")
@XMLResponseParser(NodeHandler.class) @XMLResponseParser(NodeHandler.class)
Future<? extends Node> getNode(@PathParam("nodeId") int nodeId); Future<? extends Node> getNode(@PathParam("nodeId") String nodeId);
@DELETE @DELETE
@Endpoint(org.jclouds.vcloud.endpoints.VCloud.class) @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
@Path("/nodeServices/{nodeId}") @Path("/nodeServices/{nodeId}")
Future<Void> deleteNode(@PathParam("nodeId") int nodeId); Future<Void> deleteNode(@PathParam("nodeId") String nodeId);
@GET @GET
@Consumes(VAPP_XML) @Consumes(VAPP_XML)
@Endpoint(org.jclouds.vcloud.endpoints.VCloud.class) @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
@Path("/vapp/{vAppId}") @Path("/vapp/{vAppId}")
@XMLResponseParser(TerremarkVAppHandler.class) @XMLResponseParser(TerremarkVAppHandler.class)
Future<? extends VApp> getVApp(@PathParam("vAppId") int vAppId); Future<? extends VApp> getVApp(@PathParam("vAppId") String vAppId);
@GET @GET
@Consumes(VAPP_XML) @Consumes(VAPP_XML)
@Endpoint(org.jclouds.vcloud.endpoints.VCloud.class) @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
@Path("/vapp/{vAppId}") @Path("/vapp/{vAppId}")
Future<String> getVAppString(@PathParam("vAppId") int vAppId); Future<String> getVAppString(@PathParam("vAppId") String vAppId);
} }

View File

@ -45,26 +45,26 @@ import org.jclouds.vcloud.terremark.options.InstantiateVAppTemplateOptions;
@Timeout(duration = 45, timeUnit = TimeUnit.SECONDS) @Timeout(duration = 45, timeUnit = TimeUnit.SECONDS)
public interface TerremarkVCloudClient extends VCloudClient { public interface TerremarkVCloudClient extends VCloudClient {
VApp instantiateVAppTemplate(String appName, int templateId, VApp instantiateVAppTemplate(String appName, String templateId,
InstantiateVAppTemplateOptions... options); InstantiateVAppTemplateOptions... options);
InternetService addInternetService(String serviceName, String protocol, int port, InternetService addInternetService(String serviceName, String protocol, int port,
AddInternetServiceOptions... options); AddInternetServiceOptions... options);
InternetService addInternetServiceToExistingIp(int existingIpId, String serviceName, InternetService addInternetServiceToExistingIp(String existingIpId, String serviceName,
String protocol, int port, AddInternetServiceOptions... options); String protocol, int port, AddInternetServiceOptions... options);
void deleteInternetService(int internetServiceId); void deleteInternetService(String internetServiceId);
InternetService getInternetService(int internetServiceId); InternetService getInternetService(String internetServiceId);
Node addNode(int internetServiceId, InetAddress ipAddress, String name, int port, Node addNode(String internetServiceId, InetAddress ipAddress, String name, int port,
AddNodeOptions... options); AddNodeOptions... options);
Node getNode(int nodeId); Node getNode(String nodeId);
void deleteNode(int nodeId); void deleteNode(String nodeId);
VApp getVApp(int vAppId); VApp getVApp(String vAppId);
} }

View File

@ -40,7 +40,7 @@ public class TerremarkVCloudPropertiesBuilder extends VCloudPropertiesBuilder {
protected Properties defaultProperties() { protected Properties defaultProperties() {
Properties properties = super.defaultProperties(); Properties properties = super.defaultProperties();
properties.setProperty(PROPERTY_VCLOUD_ENDPOINT, properties.setProperty(PROPERTY_VCLOUD_ENDPOINT,
"https://services.vcloudexpress.terremark.com/api/v0.8"); "https://services.vcloudexpress.terremark.com/api");
return properties; return properties;
} }
@ -49,6 +49,6 @@ public class TerremarkVCloudPropertiesBuilder extends VCloudPropertiesBuilder {
} }
public TerremarkVCloudPropertiesBuilder(String id, String secret) { public TerremarkVCloudPropertiesBuilder(String id, String secret) {
super(URI.create("https://services.vcloudexpress.terremark.com/api/v0.8"), id, secret); super(URI.create("https://services.vcloudexpress.terremark.com/api"), id, secret);
} }
} }

View File

@ -29,7 +29,7 @@ import java.net.URI;
* @author Adrian Cole * @author Adrian Cole
*/ */
public class InternetService implements Comparable<InternetService> { public class InternetService implements Comparable<InternetService> {
private final int id; private final String id;
private final String name; private final String name;
private final URI location; private final URI location;
private final PublicIpAddress publicIpAddress; private final PublicIpAddress publicIpAddress;
@ -39,7 +39,7 @@ public class InternetService implements Comparable<InternetService> {
private final int timeout; private final int timeout;
private final String description; private final String description;
public InternetService(int id, String name, URI location, PublicIpAddress publicIpAddress, public InternetService(String id, String name, URI location, PublicIpAddress publicIpAddress,
int port, String protocol, boolean enabled, int timeout, String description) { int port, String protocol, boolean enabled, int timeout, String description) {
this.id = id; this.id = id;
this.name = name; this.name = name;
@ -82,7 +82,7 @@ public class InternetService implements Comparable<InternetService> {
int result = 1; int result = 1;
result = prime * result + ((description == null) ? 0 : description.hashCode()); result = prime * result + ((description == null) ? 0 : description.hashCode());
result = prime * result + (enabled ? 1231 : 1237); result = prime * result + (enabled ? 1231 : 1237);
result = prime * result + id; result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result + ((location == null) ? 0 : location.hashCode()); result = prime * result + ((location == null) ? 0 : location.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + port; result = prime * result + port;
@ -108,7 +108,10 @@ public class InternetService implements Comparable<InternetService> {
return false; return false;
if (enabled != other.enabled) if (enabled != other.enabled)
return false; return false;
if (id != other.id) if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false; return false;
if (location == null) { if (location == null) {
if (other.location != null) if (other.location != null)
@ -138,21 +141,10 @@ public class InternetService implements Comparable<InternetService> {
} }
public int compareTo(InternetService that) { public int compareTo(InternetService that) {
final int BEFORE = -1; return (this == that) ? 0 : this.getId().compareTo(that.getId());
final int EQUAL = 0;
final int AFTER = 1;
if (this == that)
return EQUAL;
if (this.getId() < that.getId())
return BEFORE;
if (this.getId() > that.getId())
return AFTER;
return EQUAL;
} }
public int getId() { public String getId() {
return id; return id;
} }

View File

@ -30,7 +30,7 @@ import java.net.URI;
* @author Adrian Cole * @author Adrian Cole
*/ */
public class Node implements Comparable<Node> { public class Node implements Comparable<Node> {
private final int id; private final String id;
private final String name; private final String name;
private final URI location; private final URI location;
private final InetAddress ipAddress; private final InetAddress ipAddress;
@ -38,7 +38,7 @@ public class Node implements Comparable<Node> {
private final boolean enabled; private final boolean enabled;
private final String description; private final String description;
public Node(int id, String name, URI location, InetAddress ipAddress, int port, public Node(String id, String name, URI location, InetAddress ipAddress, int port,
boolean enabled, String description) { boolean enabled, String description) {
this.id = id; this.id = id;
this.name = name; this.name = name;
@ -61,7 +61,7 @@ public class Node implements Comparable<Node> {
return description; return description;
} }
public int getId() { public String getId() {
return id; return id;
} }
@ -74,18 +74,7 @@ public class Node implements Comparable<Node> {
} }
public int compareTo(Node that) { public int compareTo(Node that) {
final int BEFORE = -1; return (this == that) ? 0 : this.getId().compareTo(that.getId());
final int EQUAL = 0;
final int AFTER = 1;
if (this == that)
return EQUAL;
if (this.getId() < that.getId())
return BEFORE;
if (this.getId() > that.getId())
return AFTER;
return EQUAL;
} }
public InetAddress getIpAddress() { public InetAddress getIpAddress() {
@ -98,7 +87,7 @@ public class Node implements Comparable<Node> {
int result = 1; int result = 1;
result = prime * result + ((description == null) ? 0 : description.hashCode()); result = prime * result + ((description == null) ? 0 : description.hashCode());
result = prime * result + (enabled ? 1231 : 1237); result = prime * result + (enabled ? 1231 : 1237);
result = prime * result + id; result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result + ((ipAddress == null) ? 0 : ipAddress.hashCode()); result = prime * result + ((ipAddress == null) ? 0 : ipAddress.hashCode());
result = prime * result + ((location == null) ? 0 : location.hashCode()); result = prime * result + ((location == null) ? 0 : location.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + ((name == null) ? 0 : name.hashCode());
@ -122,7 +111,10 @@ public class Node implements Comparable<Node> {
return false; return false;
if (enabled != other.enabled) if (enabled != other.enabled)
return false; return false;
if (id != other.id) if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false; return false;
if (ipAddress == null) { if (ipAddress == null) {
if (other.ipAddress != null) if (other.ipAddress != null)

View File

@ -9,8 +9,6 @@ import org.jclouds.vcloud.VCloudAsyncClient;
* VirtualResource such as disks or CPU * VirtualResource such as disks or CPU
* *
* @author Adrian Cole * @author Adrian Cole
* @see VCloudAsyncClient#getVApp
*
* *
*/ */
public enum ResourceType { public enum ResourceType {

View File

@ -49,7 +49,7 @@ public class TerremarkVDCImpl extends VDCImpl implements TerremarkVDC {
/** The serialVersionUID */ /** The serialVersionUID */
private static final long serialVersionUID = 8464716396538298809L; private static final long serialVersionUID = 8464716396538298809L;
public TerremarkVDCImpl(int id, String name, URI location, String description, public TerremarkVDCImpl(String id, String name, URI location, String description,
Capacity storageCapacity, Capacity cpuCapacity, Capacity memoryCapacity, Capacity storageCapacity, Capacity cpuCapacity, Capacity memoryCapacity,
Quota instantiatedVmsQuota, Quota deployedVmsQuota, Quota instantiatedVmsQuota, Quota deployedVmsQuota,
Map<String, NamedLink> availableNetworks, Map<String, NamedLink> resourceEntities, Map<String, NamedLink> availableNetworks, Map<String, NamedLink> resourceEntities,

View File

@ -62,7 +62,7 @@ public class VAppImpl extends NamedResourceImpl implements VApp {
/** The serialVersionUID */ /** The serialVersionUID */
private static final long serialVersionUID = 8464716396538298809L; private static final long serialVersionUID = 8464716396538298809L;
public VAppImpl(int id, String name, String type, URI location, VAppStatus status, long size, public VAppImpl(String id, String name, String type, URI location, VAppStatus status, long size,
Link vDC, Link computeOptions, Link customizationOptions, Link vDC, Link computeOptions, Link customizationOptions,
ListMultimap<String, InetAddress> networkToAddresses, ListMultimap<String, InetAddress> networkToAddresses,
String operatingSystemDescription, VirtualSystem system, String operatingSystemDescription, VirtualSystem system,

View File

@ -47,7 +47,7 @@ public class InternetServiceHandler extends HandlerWithResult<InternetService> {
private boolean inPublicIpAddress; private boolean inPublicIpAddress;
private int addressId; private int addressId;
private int id; private String id;
private URI location; private URI location;
private URI addressLocation; private URI addressLocation;
private String serviceName; private String serviceName;
@ -83,7 +83,7 @@ public class InternetServiceHandler extends HandlerWithResult<InternetService> {
if (inPublicIpAddress) if (inPublicIpAddress)
addressId = Integer.parseInt(currentOrNull()); addressId = Integer.parseInt(currentOrNull());
else else
id = Integer.parseInt(currentOrNull()); id = currentOrNull();
} else if (qName.equals("Href") && currentOrNull() != null) { } else if (qName.equals("Href") && currentOrNull() != null) {
if (inPublicIpAddress) if (inPublicIpAddress)
addressLocation = URI.create(currentOrNull()); addressLocation = URI.create(currentOrNull());

View File

@ -42,7 +42,7 @@ public class NodeHandler extends HandlerWithResult<Node> {
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
private StringBuilder currentText = new StringBuilder(); private StringBuilder currentText = new StringBuilder();
private int id; private String id;
private URI location; private URI location;
private String serviceName; private String serviceName;
private InetAddress address; private InetAddress address;
@ -62,7 +62,7 @@ public class NodeHandler extends HandlerWithResult<Node> {
public void endElement(String uri, String name, String qName) { public void endElement(String uri, String name, String qName) {
if (qName.equals("Id")) { if (qName.equals("Id")) {
id = Integer.parseInt(currentOrNull()); id = currentOrNull();
} else if (qName.equals("Href") && currentOrNull() != null) { } else if (qName.equals("Href") && currentOrNull() != null) {
location = URI.create(currentOrNull()); location = URI.create(currentOrNull());
} else if (qName.equals("Name")) { } else if (qName.equals("Name")) {

View File

@ -168,10 +168,10 @@ public class TerremarkVAppHandler extends ParseSax.HandlerWithResult<VApp> {
} }
public NamedResource newNamedResource(Attributes attributes) { public NamedResource newNamedResource(Attributes attributes) {
return new NamedResourceImpl(Integer.parseInt(attributes return new NamedResourceImpl(attributes.getValue(attributes.getIndex("href")).replace(
.getValue(attributes.getIndex("href")).replace(vAppRoot + "/", "")), attributes vAppRoot + "/", ""), attributes.getValue(attributes.getIndex("name")), attributes
.getValue(attributes.getIndex("name")), attributes.getValue(attributes .getValue(attributes.getIndex("type")), URI.create(attributes.getValue(attributes
.getIndex("type")), URI.create(attributes.getValue(attributes.getIndex("href")))); .getIndex("href"))));
} }
public void putNamedResource(Map<String, NamedResource> map, Attributes attributes) { public void putNamedResource(Map<String, NamedResource> map, Attributes attributes) {

View File

@ -46,7 +46,6 @@ import org.jclouds.ssh.jsch.config.JschSshClientModule;
import org.jclouds.util.Utils; import org.jclouds.util.Utils;
import org.jclouds.vcloud.VCloudClientLiveTest; import org.jclouds.vcloud.VCloudClientLiveTest;
import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.TaskStatus;
import org.jclouds.vcloud.domain.VAppStatus; import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.predicates.TaskSuccess; import org.jclouds.vcloud.predicates.TaskSuccess;
import org.jclouds.vcloud.terremark.domain.InternetService; import org.jclouds.vcloud.terremark.domain.InternetService;
@ -58,7 +57,6 @@ import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeGroups; import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.Iterables;
import com.google.inject.Injector; import com.google.inject.Injector;
/** /**
@ -106,24 +104,20 @@ public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest {
String catalogOs = "CentOS 5.3 (32-bit)"; String catalogOs = "CentOS 5.3 (32-bit)";
String expectedOs = "Red Hat Enterprise Linux 5 (32-bit)"; String expectedOs = "Red Hat Enterprise Linux 5 (32-bit)";
int templateId = tmClient.getCatalog().get(catalogOs).getId(); String templateId = tmClient.getCatalog().get(catalogOs).getId();
System.out.printf("%d: instantiating vApp%n", System.currentTimeMillis()); System.out.printf("%d: instantiating vApp%n", System.currentTimeMillis());
vApp = tmClient.instantiateVAppTemplate(serverName, templateId); vApp = tmClient.instantiateVAppTemplate(serverName, templateId);
assertEquals(vApp.getStatus(), VAppStatus.CREATING); assertEquals(vApp.getStatus(), VAppStatus.CREATING);
Task instantiateTask = getLastTaskFor(vApp.getVDC().getLocation());
assertEquals(instantiateTask.getStatus(), TaskStatus.QUEUED);
// in terremark, this should be a no-op, as it should simply return the above task, which is // in terremark, this should be a no-op, as it should simply return the above task, which is
// already deploying // already deploying
Task deployTask = tmClient.deployVApp(vApp.getId()); Task deployTask = tmClient.deployVApp(vApp.getId());
assertEquals(deployTask.getLocation(), instantiateTask.getLocation());
// check to see the result of calling deploy twice // check to see the result of calling deploy twice
deployTask = tmClient.deployVApp(vApp.getId()); deployTask = tmClient.deployVApp(vApp.getId());
assertEquals(deployTask.getLocation(), instantiateTask.getLocation()); assertEquals(deployTask.getLocation(), deployTask.getLocation());
vApp = tmClient.getVApp(vApp.getId()); vApp = tmClient.getVApp(vApp.getId());
assertEquals(vApp.getStatus(), VAppStatus.CREATING); assertEquals(vApp.getStatus(), VAppStatus.CREATING);
@ -141,8 +135,7 @@ public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest {
verifyConfigurationOfVApp(vApp, serverName, expectedOs, processorCount, memory, hardDisk); verifyConfigurationOfVApp(vApp, serverName, expectedOs, processorCount, memory, hardDisk);
assertEquals(vApp.getStatus(), VAppStatus.OFF); assertEquals(vApp.getStatus(), VAppStatus.OFF);
assert successTester.apply(tmClient.powerOnVApp(vApp.getId()) assert successTester.apply(tmClient.powerOnVApp(vApp.getId()).getLocation());
.getLocation());
System.out.printf("%d: done powering on vApp%n", System.currentTimeMillis()); System.out.printf("%d: done powering on vApp%n", System.currentTimeMillis());
vApp = tmClient.getVApp(vApp.getId()); vApp = tmClient.getVApp(vApp.getId());
@ -181,8 +174,7 @@ public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest {
assertEquals(e.getResponse().getStatusCode(), 501); assertEquals(e.getResponse().getStatusCode(), 501);
} }
assert successTester.apply(tmClient.resetVApp(vApp.getId()) assert successTester.apply(tmClient.resetVApp(vApp.getId()).getLocation());
.getLocation());
vApp = tmClient.getVApp(vApp.getId()); vApp = tmClient.getVApp(vApp.getId());
assertEquals(vApp.getStatus(), VAppStatus.ON); assertEquals(vApp.getStatus(), VAppStatus.ON);
@ -192,8 +184,7 @@ public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest {
// vApp = tmClient.getVApp(vApp.getId()); // vApp = tmClient.getVApp(vApp.getId());
// assertEquals(vApp.getStatus(), VAppStatus.ON); // assertEquals(vApp.getStatus(), VAppStatus.ON);
assert successTester.apply(tmClient.powerOffVApp(vApp.getId()) assert successTester.apply(tmClient.powerOffVApp(vApp.getId()).getLocation());
.getLocation());
vApp = tmClient.getVApp(vApp.getId()); vApp = tmClient.getVApp(vApp.getId());
assertEquals(vApp.getStatus(), VAppStatus.OFF); assertEquals(vApp.getStatus(), VAppStatus.OFF);
@ -216,12 +207,6 @@ public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest {
.get(ResourceType.VIRTUAL_DISK).getVirtualQuantity()); .get(ResourceType.VIRTUAL_DISK).getVirtualQuantity());
} }
private Task getLastTaskFor(URI owner) throws InterruptedException, ExecutionException,
TimeoutException {
return Iterables.getLast(tmClient.getDefaultTasksList()
.getTasksByOwner().get(owner));
}
private void doCheckPass(InetAddress address) throws IOException { private void doCheckPass(InetAddress address) throws IOException {
InetSocketAddress socket = new InetSocketAddress(address, 22); InetSocketAddress socket = new InetSocketAddress(address, 22);
@ -250,8 +235,7 @@ public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest {
tmClient.deleteInternetService(is.getId()); tmClient.deleteInternetService(is.getId());
if (vApp != null) { if (vApp != null) {
try { try {
successTester.apply(tmClient.powerOffVApp(vApp.getId()) successTester.apply(tmClient.powerOffVApp(vApp.getId()).getLocation());
.getLocation());
} catch (Exception e) { } catch (Exception e) {
} }
@ -265,7 +249,7 @@ public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest {
account = checkNotNull(System.getProperty("jclouds.test.user"), "jclouds.test.user"); account = checkNotNull(System.getProperty("jclouds.test.user"), "jclouds.test.user");
String key = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key"); String key = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key");
Injector injector = new TerremarkVCloudContextBuilder(new TerremarkVCloudPropertiesBuilder( Injector injector = new TerremarkVCloudContextBuilder(new TerremarkVCloudPropertiesBuilder(
account, key).build()).withModules(new Log4JLoggingModule(), account, key).relaxSSLHostname().build()).withModules(new Log4JLoggingModule(),
new JschSshClientModule()).buildInjector(); new JschSshClientModule()).buildInjector();
connection = tmClient = injector.getInstance(TerremarkVCloudClient.class); connection = tmClient = injector.getInstance(TerremarkVCloudClient.class);

View File

@ -48,7 +48,7 @@ import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.util.Utils; import org.jclouds.util.Utils;
import org.jclouds.vcloud.endpoints.Catalog; import org.jclouds.vcloud.endpoints.Catalog;
import org.jclouds.vcloud.endpoints.Network; import org.jclouds.vcloud.endpoints.Network;
import org.jclouds.vcloud.endpoints.VCloud; import org.jclouds.vcloud.endpoints.VCloudApi;
import org.jclouds.vcloud.endpoints.VDC; import org.jclouds.vcloud.endpoints.VDC;
import org.jclouds.vcloud.endpoints.internal.CatalogItemRoot; import org.jclouds.vcloud.endpoints.internal.CatalogItemRoot;
import org.jclouds.vcloud.endpoints.internal.VAppRoot; import org.jclouds.vcloud.endpoints.internal.VAppRoot;
@ -93,10 +93,10 @@ public class TerremarkVCloudClientTest extends RestClientTest<TerremarkVCloudAsy
public void testInstantiateVAppTemplate() throws SecurityException, NoSuchMethodException, public void testInstantiateVAppTemplate() throws SecurityException, NoSuchMethodException,
IOException { IOException {
Method method = TerremarkVCloudAsyncClient.class.getMethod("instantiateVAppTemplate", Method method = TerremarkVCloudAsyncClient.class.getMethod("instantiateVAppTemplate",
String.class, int.class, Array.newInstance(InstantiateVAppTemplateOptions.class, 0) String.class, String.class, Array.newInstance(InstantiateVAppTemplateOptions.class,
.getClass()); 0).getClass());
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method, GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method,
"name", 3); "name", 3 + "");
assertRequestLineEquals(httpMethod, "POST http://vdc/action/instantiatevAppTemplate HTTP/1.1"); assertRequestLineEquals(httpMethod, "POST http://vdc/action/instantiatevAppTemplate HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
@ -115,10 +115,10 @@ public class TerremarkVCloudClientTest extends RestClientTest<TerremarkVCloudAsy
public void testInstantiateVAppTemplateOptions() throws SecurityException, public void testInstantiateVAppTemplateOptions() throws SecurityException,
NoSuchMethodException, IOException { NoSuchMethodException, IOException {
Method method = TerremarkVCloudAsyncClient.class.getMethod("instantiateVAppTemplate", Method method = TerremarkVCloudAsyncClient.class.getMethod("instantiateVAppTemplate",
String.class, int.class, Array.newInstance(InstantiateVAppTemplateOptions.class, 0) String.class, String.class, Array.newInstance(InstantiateVAppTemplateOptions.class,
.getClass()); 0).getClass());
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method, GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method,
"name", 3, cpuCount(4).megabytes(1024).inNetwork(URI.create("http://newnet"))); "name", 3 + "", cpuCount(4).megabytes(1024).inNetwork(URI.create("http://newnet")));
assertRequestLineEquals(httpMethod, "POST http://vdc/action/instantiatevAppTemplate HTTP/1.1"); assertRequestLineEquals(httpMethod, "POST http://vdc/action/instantiatevAppTemplate HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
@ -136,9 +136,9 @@ public class TerremarkVCloudClientTest extends RestClientTest<TerremarkVCloudAsy
public void testAddInternetService() throws SecurityException, NoSuchMethodException, public void testAddInternetService() throws SecurityException, NoSuchMethodException,
IOException { IOException {
Method method = TerremarkVCloudAsyncClient.class.getMethod("addInternetService", String.class, Method method = TerremarkVCloudAsyncClient.class.getMethod("addInternetService",
String.class, int.class, Array.newInstance(AddInternetServiceOptions.class, 0) String.class, String.class, int.class, Array.newInstance(
.getClass()); AddInternetServiceOptions.class, 0).getClass());
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method, GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method,
"name", "tcp", 22); "name", "tcp", 22);
@ -156,9 +156,9 @@ public class TerremarkVCloudClientTest extends RestClientTest<TerremarkVCloudAsy
public void testAddInternetServiceOptions() throws SecurityException, NoSuchMethodException, public void testAddInternetServiceOptions() throws SecurityException, NoSuchMethodException,
IOException { IOException {
Method method = TerremarkVCloudAsyncClient.class.getMethod("addInternetService", String.class, Method method = TerremarkVCloudAsyncClient.class.getMethod("addInternetService",
String.class, int.class, Array.newInstance(AddInternetServiceOptions.class, 0) String.class, String.class, int.class, Array.newInstance(
.getClass()); AddInternetServiceOptions.class, 0).getClass());
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method, GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method,
"name", "tcp", 22, disabled().withDescription("yahoo")); "name", "tcp", 22, disabled().withDescription("yahoo"));
@ -175,8 +175,10 @@ public class TerremarkVCloudClientTest extends RestClientTest<TerremarkVCloudAsy
public void testGetInternetService() throws SecurityException, NoSuchMethodException, public void testGetInternetService() throws SecurityException, NoSuchMethodException,
IOException { IOException {
Method method = TerremarkVCloudAsyncClient.class.getMethod("getInternetService", int.class); Method method = TerremarkVCloudAsyncClient.class
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method, 12); .getMethod("getInternetService", String.class);
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method,
12);
assertRequestLineEquals(httpMethod, "GET http://vcloud/internetServices/12 HTTP/1.1"); assertRequestLineEquals(httpMethod, "GET http://vcloud/internetServices/12 HTTP/1.1");
assertHeadersEqual(httpMethod, ""); assertHeadersEqual(httpMethod, "");
@ -191,8 +193,10 @@ public class TerremarkVCloudClientTest extends RestClientTest<TerremarkVCloudAsy
public void testDeleteInternetService() throws SecurityException, NoSuchMethodException, public void testDeleteInternetService() throws SecurityException, NoSuchMethodException,
IOException { IOException {
Method method = TerremarkVCloudAsyncClient.class.getMethod("deleteInternetService", int.class); Method method = TerremarkVCloudAsyncClient.class.getMethod("deleteInternetService",
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method, 12); String.class);
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method,
12);
assertRequestLineEquals(httpMethod, "DELETE http://vcloud/internetServices/12 HTTP/1.1"); assertRequestLineEquals(httpMethod, "DELETE http://vcloud/internetServices/12 HTTP/1.1");
assertHeadersEqual(httpMethod, ""); assertHeadersEqual(httpMethod, "");
@ -208,10 +212,10 @@ public class TerremarkVCloudClientTest extends RestClientTest<TerremarkVCloudAsy
public void testAddInternetServiceToExistingIp() throws SecurityException, public void testAddInternetServiceToExistingIp() throws SecurityException,
NoSuchMethodException, IOException { NoSuchMethodException, IOException {
Method method = TerremarkVCloudAsyncClient.class.getMethod("addInternetServiceToExistingIp", Method method = TerremarkVCloudAsyncClient.class.getMethod("addInternetServiceToExistingIp",
int.class, String.class, String.class, int.class, Array.newInstance( String.class, String.class, String.class, int.class, Array.newInstance(
AddInternetServiceOptions.class, 0).getClass()); AddInternetServiceOptions.class, 0).getClass());
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method, 12, GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method,
"name", "tcp", 22); 12, "name", "tcp", 22);
assertRequestLineEquals(httpMethod, assertRequestLineEquals(httpMethod,
"POST http://vcloud/publicIps/12/InternetServices HTTP/1.1"); "POST http://vcloud/publicIps/12/InternetServices HTTP/1.1");
@ -229,10 +233,10 @@ public class TerremarkVCloudClientTest extends RestClientTest<TerremarkVCloudAsy
public void testAddInternetServiceToExistingIpOptions() throws SecurityException, public void testAddInternetServiceToExistingIpOptions() throws SecurityException,
NoSuchMethodException, IOException { NoSuchMethodException, IOException {
Method method = TerremarkVCloudAsyncClient.class.getMethod("addInternetServiceToExistingIp", Method method = TerremarkVCloudAsyncClient.class.getMethod("addInternetServiceToExistingIp",
int.class, String.class, String.class, int.class, Array.newInstance( String.class, String.class, String.class, int.class, Array.newInstance(
AddInternetServiceOptions.class, 0).getClass()); AddInternetServiceOptions.class, 0).getClass());
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method, 12, GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method,
"name", "tcp", 22, disabled().withDescription("yahoo")); 12, "name", "tcp", 22, disabled().withDescription("yahoo"));
assertRequestLineEquals(httpMethod, assertRequestLineEquals(httpMethod,
"POST http://vcloud/publicIps/12/InternetServices HTTP/1.1"); "POST http://vcloud/publicIps/12/InternetServices HTTP/1.1");
@ -247,11 +251,11 @@ public class TerremarkVCloudClientTest extends RestClientTest<TerremarkVCloudAsy
} }
public void testAddNode() throws SecurityException, NoSuchMethodException, IOException { public void testAddNode() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkVCloudAsyncClient.class.getMethod("addNode", int.class, Method method = TerremarkVCloudAsyncClient.class.getMethod("addNode", String.class,
InetAddress.class, String.class, int.class, Array.newInstance(AddNodeOptions.class, InetAddress.class, String.class, int.class, Array.newInstance(AddNodeOptions.class,
0).getClass()); 0).getClass());
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method, 12, GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method,
InetAddress.getByName("10.2.2.2"), "name", 22); 12, InetAddress.getByName("10.2.2.2"), "name", 22);
assertRequestLineEquals(httpMethod, "POST http://vcloud/internetServices/12/nodes HTTP/1.1"); assertRequestLineEquals(httpMethod, "POST http://vcloud/internetServices/12/nodes HTTP/1.1");
assertHeadersEqual(httpMethod, "Content-Length: 298\nContent-Type: application/xml\n"); assertHeadersEqual(httpMethod, "Content-Length: 298\nContent-Type: application/xml\n");
@ -266,11 +270,11 @@ public class TerremarkVCloudClientTest extends RestClientTest<TerremarkVCloudAsy
} }
public void testAddNodeOptions() throws SecurityException, NoSuchMethodException, IOException { public void testAddNodeOptions() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkVCloudAsyncClient.class.getMethod("addNode", int.class, Method method = TerremarkVCloudAsyncClient.class.getMethod("addNode", String.class,
InetAddress.class, String.class, int.class, Array.newInstance(AddNodeOptions.class, InetAddress.class, String.class, int.class, Array.newInstance(AddNodeOptions.class,
0).getClass()); 0).getClass());
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method, 12, GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method,
InetAddress.getByName("10.2.2.2"), "name", 22, AddNodeOptions.Builder.disabled() 12, InetAddress.getByName("10.2.2.2"), "name", 22, AddNodeOptions.Builder.disabled()
.withDescription("yahoo")); .withDescription("yahoo"));
assertRequestLineEquals(httpMethod, "POST http://vcloud/internetServices/12/nodes HTTP/1.1"); assertRequestLineEquals(httpMethod, "POST http://vcloud/internetServices/12/nodes HTTP/1.1");
@ -285,8 +289,9 @@ public class TerremarkVCloudClientTest extends RestClientTest<TerremarkVCloudAsy
} }
public void testGetNode() throws SecurityException, NoSuchMethodException, IOException { public void testGetNode() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkVCloudAsyncClient.class.getMethod("getNode", int.class); Method method = TerremarkVCloudAsyncClient.class.getMethod("getNode", String.class);
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method, 12); GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method,
12);
assertRequestLineEquals(httpMethod, "GET http://vcloud/nodeServices/12 HTTP/1.1"); assertRequestLineEquals(httpMethod, "GET http://vcloud/nodeServices/12 HTTP/1.1");
assertHeadersEqual(httpMethod, ""); assertHeadersEqual(httpMethod, "");
@ -300,8 +305,9 @@ public class TerremarkVCloudClientTest extends RestClientTest<TerremarkVCloudAsy
} }
public void testDeleteNode() throws SecurityException, NoSuchMethodException, IOException { public void testDeleteNode() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkVCloudAsyncClient.class.getMethod("deleteNode", int.class); Method method = TerremarkVCloudAsyncClient.class.getMethod("deleteNode", String.class);
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method, 12); GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method,
12);
assertRequestLineEquals(httpMethod, "DELETE http://vcloud/nodeServices/12 HTTP/1.1"); assertRequestLineEquals(httpMethod, "DELETE http://vcloud/nodeServices/12 HTTP/1.1");
assertHeadersEqual(httpMethod, ""); assertHeadersEqual(httpMethod, "");
@ -334,7 +340,7 @@ public class TerremarkVCloudClientTest extends RestClientTest<TerremarkVCloudAsy
bind(URI.class).annotatedWith(Catalog.class).toInstance(URI.create("http://catalog")); bind(URI.class).annotatedWith(Catalog.class).toInstance(URI.create("http://catalog"));
bind(String.class).annotatedWith(CatalogItemRoot.class) bind(String.class).annotatedWith(CatalogItemRoot.class)
.toInstance("http://catalogItem"); .toInstance("http://catalogItem");
bind(URI.class).annotatedWith(VCloud.class).toInstance(URI.create("http://vcloud")); bind(URI.class).annotatedWith(VCloudApi.class).toInstance(URI.create("http://vcloud"));
bind(String.class).annotatedWith(VAppRoot.class).toInstance("http://vapp"); bind(String.class).annotatedWith(VAppRoot.class).toInstance("http://vapp");
bind(URI.class).annotatedWith(VDC.class).toInstance(URI.create("http://vdc")); bind(URI.class).annotatedWith(VDC.class).toInstance(URI.create("http://vdc"));
bind(URI.class).annotatedWith(Network.class).toInstance(URI.create("http://network")); bind(URI.class).annotatedWith(Network.class).toInstance(URI.create("http://network"));

View File

@ -0,0 +1,212 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.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.vcloud.terremark;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.URI;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.predicates.AddressReachable;
import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.predicates.SocketOpen;
import org.jclouds.ssh.jsch.config.JschSshClientModule;
import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.predicates.TaskSuccess;
import org.jclouds.vcloud.terremark.VCloudComputeClient.Image;
import org.jclouds.vcloud.terremark.domain.InternetService;
import org.jclouds.vcloud.terremark.domain.Node;
import org.jclouds.vcloud.terremark.domain.ResourceType;
import org.jclouds.vcloud.terremark.domain.VApp;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
import com.google.common.base.Predicate;
import com.google.inject.AbstractModule;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.Provides;
import com.google.inject.TypeLiteral;
import com.google.inject.internal.ImmutableMap;
/**
* Tests behavior of {@code TerremarkVCloudClient}
*
* @author Adrian Cole
*/
@Test(groups = "live", sequential = true, testName = "vcloud.TerremarkVCloudClientLiveTest")
public class TerremarkVCloudComputeClientLiveTest {
VCloudComputeClient client;
TerremarkVCloudClient tmClient;
private String id;
private InetAddress privateAddress;
public static final String PREFIX = System.getProperty("user.name") + "-terremark";
private static class Expectation {
final long hardDisk;
final String os;
public Expectation(long hardDisk, String os) {
this.hardDisk = hardDisk;
this.os = os;
}
}
private Map<Image, Expectation> expectationMap = ImmutableMap.<Image, Expectation> builder()
.put(Image.CENTOS_53,
new Expectation(4194304 / 4 * 10, "Red Hat Enterprise Linux 5 (32-bit)")).put(
Image.RHEL_53,
new Expectation(4194304 / 4 * 10, "Red Hat Enterprise Linux 5 (32-bit)")).put(
Image.UMBUNTU_SERVER_90, new Expectation(4194304, "Ubuntu Linux (32-bit)"))
.put(Image.UMBUNTU_JEOS_90, new Expectation(4194304, "Ubuntu Linux (32-bit)")).put(
Image.CENTOS_53_64,
new Expectation(4194304 / 4 * 10, "Red Hat Enterprise Linux 5 (64-bit)")).put(
Image.RHEL_53_64,
new Expectation(4194304 / 4 * 10, "Red Hat Enterprise Linux 5 (64-bit)")).put(
Image.UMBUNTU_SERVER_90_64, new Expectation(4194304, "Ubuntu Linux (64-bit)"))
.put(Image.UMBUNTU_JEOS_90_64, new Expectation(4194304, "Ubuntu Linux (64-bit)"))
.build();
private InternetService is;
private Node node;
private InetAddress publicIp;
private Predicate<InetAddress> addressTester;
@Test
public void testPowerOn() throws InterruptedException, ExecutionException, TimeoutException,
IOException {
Image toTest = Image.CENTOS_53;
String serverName = getCompatibleServerName(toTest);
int processorCount = 1;
int memory = 512;
id = client.start(serverName, processorCount, memory, toTest);
Expectation expectation = expectationMap.get(toTest);
VApp vApp = tmClient.getVApp(id);
verifyConfigurationOfVApp(vApp, serverName, expectation.os, processorCount, memory,
expectation.hardDisk);
assertEquals(vApp.getStatus(), VAppStatus.ON);
}
private String getCompatibleServerName(Image toTest) {
String serverName = toTest.toString().toLowerCase().replaceAll("_", "-").substring(0,
toTest.toString().length() <= 15 ? toTest.toString().length() : 14);
return serverName;
}
@Test(dependsOnMethods = "testPowerOn")
public void testGetAnyPrivateAddress() {
privateAddress = client.getAnyPrivateAddress(id);
assert !addressTester.apply(privateAddress);
}
@Test(dependsOnMethods = "testGetAnyPrivateAddress")
public void testSshLoadBalanceIp() {
is = tmClient.addInternetService("SSH", "TCP", 22);
node = tmClient.addNode(is.getId(), privateAddress, id + "-SSH", 22);
publicIp = is.getPublicIpAddress().getAddress();
assert addressTester.apply(publicIp);
client.testSsh(publicIp);
}
private void verifyConfigurationOfVApp(VApp vApp, String serverName, String expectedOs,
int processorCount, int memory, long hardDisk) {
assertEquals(vApp.getName(), serverName);
assertEquals(vApp.getOperatingSystemDescription(), expectedOs);
assertEquals(vApp.getResourceAllocationByType().get(ResourceType.VIRTUAL_CPU)
.getVirtualQuantity(), processorCount);
assertEquals(vApp.getResourceAllocationByType().get(ResourceType.SCSI_CONTROLLER)
.getVirtualQuantity(), 1);
assertEquals(
vApp.getResourceAllocationByType().get(ResourceType.MEMORY).getVirtualQuantity(),
memory);
assertEquals(vApp.getResourceAllocationByType().get(ResourceType.VIRTUAL_DISK)
.getVirtualQuantity(), hardDisk);
assertEquals(vApp.getSize(), vApp.getResourceAllocationByType()
.get(ResourceType.VIRTUAL_DISK).getVirtualQuantity());
}
@AfterTest
void cleanup() throws InterruptedException, ExecutionException, TimeoutException {
if (node != null)
tmClient.deleteNode(node.getId());
if (is != null)
tmClient.deleteInternetService(is.getId());
if (id != null)
client.stop(id);
}
@BeforeGroups(groups = { "live" })
public void setupClient() {
String account = checkNotNull(System.getProperty("jclouds.test.user"), "jclouds.test.user");
String key = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key");
Injector injector = new TerremarkVCloudContextBuilder(new TerremarkVCloudPropertiesBuilder(
account, key).relaxSSLHostname().build()).withModules(new Log4JLoggingModule(),
new JschSshClientModule(), new AbstractModule() {
@Override
protected void configure() {
}
@SuppressWarnings("unused")
@Provides
private Predicate<InetSocketAddress> socketTester(SocketOpen open) {
return new RetryablePredicate<InetSocketAddress>(open, 130, 10,
TimeUnit.SECONDS);// make it longer then
// default internet
}
@SuppressWarnings("unused")
@Provides
private Predicate<InetAddress> addressTester(AddressReachable open) {
return open;
}
@SuppressWarnings("unused")
@Provides
private Predicate<URI> successTester(TaskSuccess success) {
return new RetryablePredicate<URI>(success, 300, 10, TimeUnit.SECONDS);
}
}).buildInjector();
client = injector.getInstance(VCloudComputeClient.class);
tmClient = injector.getInstance(TerremarkVCloudClient.class);
addressTester = injector.getInstance(Key.get(new TypeLiteral<Predicate<InetAddress>>() {
}));
}
}

View File

@ -0,0 +1,232 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.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.vcloud.terremark;
import static com.google.common.base.Preconditions.checkArgument;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.URI;
import java.util.Map;
import javax.annotation.Resource;
import javax.inject.Inject;
import org.jclouds.logging.Logger;
import org.jclouds.ssh.SshClient;
import org.jclouds.ssh.SshClient.Factory;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.terremark.domain.VApp;
import org.jclouds.vcloud.terremark.options.InstantiateVAppTemplateOptions;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import com.google.common.collect.MapMaker;
/**
*
* @author Adrian Cole
*/
public class VCloudComputeClient {
@Resource
protected Logger logger = Logger.NULL;
private final Predicate<InetSocketAddress> socketTester;
private final Predicate<URI> taskTester;
private final TerremarkVCloudClient tmClient;
@Inject
public VCloudComputeClient(TerremarkVCloudClient tmClient, Factory sshFactory,
Predicate<InetSocketAddress> socketTester, Predicate<URI> successTester) {
this.tmClient = tmClient;
this.sshFactory = sshFactory;
this.socketTester = socketTester;
this.taskTester = successTester;
}
private final Factory sshFactory;
public enum Image {
CENTOS_53, CENTOS_53_64, RHEL_53, RHEL_53_64, UMBUNTU_JEOS_90, UMBUNTU_JEOS_90_64, UMBUNTU_SERVER_90, UMBUNTU_SERVER_90_64
}
private Map<Image, String> imageCatalogNameMap = ImmutableMap.<Image, String> builder().put(
Image.CENTOS_53, "CentOS 5.3 (32-bit)").put(Image.RHEL_53, "RHEL 5.3 (32-bit)").put(
Image.UMBUNTU_JEOS_90, "Ubuntu JeOS 9.04 (32-bit)").put(Image.UMBUNTU_SERVER_90,
"Ubuntu Server 9.04 (64-bit)").put(Image.CENTOS_53_64, "CentOS 5.3 (64-bit)").put(
Image.RHEL_53_64, "RHEL 5.3 (64-bit)").put(Image.UMBUNTU_JEOS_90_64,
"Ubuntu JeOS 9.04 (64-bit)").put(Image.UMBUNTU_SERVER_90_64,
"Ubuntu Server 9.04 (64-bit)").build();
private Map<String, String> catalogNameTemplateIdMap = new MapMaker()
.makeComputingMap(new Function<String, String>() {
@Override
public String apply(String from) {
return tmClient.getCatalog().get(from).getId();
}
});
public String start(String name, int minCores, int minMegs, Image image) {
checkArgument(imageCatalogNameMap.containsKey(image), "image not configured: " + image);
String templateId = catalogNameTemplateIdMap.get(imageCatalogNameMap.get(image));
logger.debug(">> instantiating vApp name(%s) minCores(%d) minMegs(%d) image(%s)", name,
minCores, minMegs, image);
VApp vApp = tmClient.instantiateVAppTemplate(name, templateId,
InstantiateVAppTemplateOptions.Builder.cpuCount(minCores).megabytes(minMegs));
logger.debug("<< instantiated VApp(%s)", vApp.getId());
logger.debug(">> deploying vApp(%s)", vApp.getId());
vApp = blockUntilVAppStatusOrThrowException(vApp, tmClient.deployVApp(vApp.getId()),
"deploy", VAppStatus.OFF);
logger.debug("<< deployed vApp(%s)", vApp.getId());
logger.debug(">> powering vApp(%s)", vApp.getId());
vApp = blockUntilVAppStatusOrThrowException(vApp, tmClient.powerOnVApp(vApp.getId()),
"powerOn", VAppStatus.ON);
logger.debug("<< on vApp(%s)", vApp.getId());
return vApp.getId();
}
/**
*
* @throws ElementNotFoundException
* if no address is configured
*/
public InetAddress getAnyPrivateAddress(String id) {
VApp vApp = tmClient.getVApp(id);
return Iterables.getLast(vApp.getNetworkToAddresses().values());
}
public void testSsh(InetAddress address) {
InetSocketAddress sshSocket = new InetSocketAddress(address, 22);
logger.debug(">> sshConnect socket(%s)", sshSocket);
checkSsh(sshSocket, "vcloud", "p4ssw0rd");
logger.debug("<< sshOk socket(%s)", sshSocket);
}
public void reboot(String id) {
VApp vApp = tmClient.getVApp(id);
logger.debug(">> rebooting vApp(%s)", vApp.getId());
blockUntilVAppStatusOrThrowException(vApp, tmClient.resetVApp(vApp.getId()), "reset",
VAppStatus.ON);
logger.debug("<< on vApp(%s)", vApp.getId());
}
public void stop(String id) {
VApp vApp = tmClient.getVApp(id);
if (vApp.getStatus() != VAppStatus.OFF) {
logger.debug(">> powering off vApp(%s)", vApp.getId());
blockUntilVAppStatusOrThrowException(vApp, tmClient.powerOffVApp(vApp.getId()),
"powerOff", VAppStatus.OFF);
logger.debug("<< off vApp(%s)", vApp.getId());
}
logger.debug(">> deleting vApp(%s)", vApp.getId());
tmClient.deleteVApp(id);
logger.debug("<< deleted vApp(%s)", vApp.getId());
}
private void checkSsh(InetSocketAddress socket, String username, String password) {
if (!socketTester.apply(socket)) {
throw new SocketNotOpenException(socket);
}
SshClient connection = sshFactory.create(socket, username, password);
try {
connection.connect();
} finally {
if (connection != null)
connection.disconnect();
}
}
private VApp blockUntilVAppStatusOrThrowException(VApp vApp, Task deployTask, String taskType,
VAppStatus expectedStatus) {
if (!taskTester.apply(deployTask.getLocation())) {
throw new TaskException(taskType, vApp, deployTask);
}
vApp = tmClient.getVApp(vApp.getId());
if (vApp.getStatus() != expectedStatus) {
throw new VAppException(String.format("vApp %s status %s should be %s after %s", vApp
.getId(), vApp.getStatus(), expectedStatus, taskType), vApp);
}
return vApp;
}
public static class TaskException extends VAppException {
private final Task task;
/** The serialVersionUID */
private static final long serialVersionUID = 251801929573211256L;
public TaskException(String type, VApp vApp, Task task) {
super(String.format("failed to %s vApp %s status %s;task %s status %s", type,
vApp.getId(), vApp.getStatus(), task.getLocation(), task.getStatus()), vApp);
this.task = task;
}
public Task getTask() {
return task;
}
}
public static class SocketNotOpenException extends RuntimeException {
private final InetSocketAddress socket;
/** The serialVersionUID */
private static final long serialVersionUID = 251801929573211256L;
public SocketNotOpenException(InetSocketAddress socket) {
super("socket not open: " + socket);
this.socket = socket;
}
public InetSocketAddress getSocket() {
return socket;
}
}
public static class VAppException extends RuntimeException {
private final VApp vApp;
/** The serialVersionUID */
private static final long serialVersionUID = 251801929573211256L;
public VAppException(String message, VApp vApp) {
super(message);
this.vApp = vApp;
}
public VApp getvApp() {
return vApp;
}
}
}

View File

@ -27,6 +27,7 @@ import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_ENDPO
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_KEY; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_KEY;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_SESSIONINTERVAL; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_SESSIONINTERVAL;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_USER; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_USER;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_VERSION;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import java.io.IOException; import java.io.IOException;
@ -35,7 +36,6 @@ import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.util.Jsr330; import org.jclouds.util.Jsr330;
import org.jclouds.util.Utils; import org.jclouds.util.Utils;
import org.jclouds.vcloud.config.VCloudDiscoveryRestClientModule; import org.jclouds.vcloud.config.VCloudDiscoveryRestClientModule;
import org.jclouds.vcloud.config.VCloudRestClientModuleTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.inject.AbstractModule; import com.google.inject.AbstractModule;
@ -47,14 +47,14 @@ import com.google.inject.Key;
* @author Adrian Cole * @author Adrian Cole
*/ */
@Test(groups = "unit", testName = "vcloud.TerremarkVCloudRestClientModuleTest") @Test(groups = "unit", testName = "vcloud.TerremarkVCloudRestClientModuleTest")
public class TerremarkVCloudRestClientModuleTest extends VCloudRestClientModuleTest { public class TerremarkVCloudRestClientModuleTest {
@Override
protected Injector createInjector() { protected Injector createInjector() {
return Guice.createInjector(new TerremarkVCloudRestClientModule(), return Guice.createInjector(new TerremarkVCloudRestClientModule(),
new VCloudDiscoveryRestClientModule(), new ParserModule(), new AbstractModule() { new VCloudDiscoveryRestClientModule(), new ParserModule(), new AbstractModule() {
@Override @Override
protected void configure() { protected void configure() {
bindConstant().annotatedWith(Jsr330.named(PROPERTY_VCLOUD_VERSION)).to("0.8");
bindConstant().annotatedWith(Jsr330.named(PROPERTY_VCLOUD_USER)).to("user"); bindConstant().annotatedWith(Jsr330.named(PROPERTY_VCLOUD_USER)).to("user");
bindConstant().annotatedWith(Jsr330.named(PROPERTY_VCLOUD_KEY)).to("secret"); bindConstant().annotatedWith(Jsr330.named(PROPERTY_VCLOUD_KEY)).to("secret");
bindConstant().annotatedWith(Jsr330.named(PROPERTY_VCLOUD_ENDPOINT)).to( bindConstant().annotatedWith(Jsr330.named(PROPERTY_VCLOUD_ENDPOINT)).to(

View File

@ -55,8 +55,8 @@ public class InternetServiceHandlerTest extends BaseHandlerTest {
InternetService result = (InternetService) factory.create( InternetService result = (InternetService) factory.create(
injector.getInstance(InternetServiceHandler.class)).parse(is); injector.getInstance(InternetServiceHandler.class)).parse(is);
assertEquals(result, new InternetService(523, "IS_for_Jim", null, new PublicIpAddress(4208, assertEquals(result, new InternetService(523 + "", "IS_for_Jim", null, new PublicIpAddress(
InetAddress.getByName("10.1.22.159"), null), 80, "HTTP", false, 1, 4208, InetAddress.getByName("10.1.22.159"), null), 80, "HTTP", false, 1,
"Some test service")); "Some test service"));
} }
@ -68,7 +68,7 @@ public class InternetServiceHandlerTest extends BaseHandlerTest {
assertEquals( assertEquals(
result, result,
new InternetService( new InternetService(
524, 524 + "",
"IS_for_Jim2", "IS_for_Jim2",
URI URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/InternetServices/524"), .create("https://services.vcloudexpress.terremark.com/api/v0.8/InternetServices/524"),

View File

@ -45,9 +45,8 @@ public class NodeHandlerTest extends BaseHandlerTest {
public void test1() throws UnknownHostException { public void test1() throws UnknownHostException {
InputStream is = getClass().getResourceAsStream("/terremark/NodeService.xml"); InputStream is = getClass().getResourceAsStream("/terremark/NodeService.xml");
Node result = (Node) factory.create( Node result = (Node) factory.create(injector.getInstance(NodeHandler.class)).parse(is);
injector.getInstance(NodeHandler.class)).parse(is); assertEquals(result, new Node(242 + "", "Node for Jim", URI
assertEquals(result, new Node(242, "Node for Jim", URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/NodeServices/242"), .create("https://services.vcloudexpress.terremark.com/api/v0.8/NodeServices/242"),
InetAddress.getByName("172.16.20.3"), 80, false, "Some test node")); InetAddress.getByName("172.16.20.3"), 80, false, "Some test node"));
} }

View File

@ -85,7 +85,7 @@ public class TerremarkVAppHandlerTest extends BaseHandlerTest {
VApp result = (VApp) factory.create(injector.getInstance(TerremarkVAppHandler.class)).parse( VApp result = (VApp) factory.create(injector.getInstance(TerremarkVAppHandler.class)).parse(
is); is);
assertEquals(result.getId(), 13775); assertEquals(result.getId(), 13775+"");
assertEquals(result.getName(), "adriantest"); assertEquals(result.getName(), "adriantest");
assertEquals(result.getStatus(), VAppStatus.CREATING); assertEquals(result.getStatus(), VAppStatus.CREATING);
@ -105,7 +105,7 @@ public class TerremarkVAppHandlerTest extends BaseHandlerTest {
VApp result = (VApp) factory.create(injector.getInstance(TerremarkVAppHandler.class)).parse( VApp result = (VApp) factory.create(injector.getInstance(TerremarkVAppHandler.class)).parse(
is); is);
assertEquals(result.getId(), 13850); assertEquals(result.getId(), 13850+"");
assertEquals(result.getName(), "adriantest1"); assertEquals(result.getName(), "adriantest1");
assertEquals(result.getStatus(), VAppStatus.OFF); assertEquals(result.getStatus(), VAppStatus.OFF);

View File

@ -34,7 +34,7 @@ import org.jclouds.http.functions.ParseSax.Factory;
import org.jclouds.http.functions.config.ParserModule; import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.rest.domain.NamedLink; import org.jclouds.rest.domain.NamedLink;
import org.jclouds.rest.domain.internal.NamedLinkImpl; import org.jclouds.rest.domain.internal.NamedLinkImpl;
import org.jclouds.vcloud.endpoints.VCloud; import org.jclouds.vcloud.endpoints.VCloudApi;
import org.jclouds.vcloud.terremark.domain.TerremarkVDC; import org.jclouds.vcloud.terremark.domain.TerremarkVDC;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -62,7 +62,7 @@ public class TerremarkVDCHandlerTest {
@SuppressWarnings("unused") @SuppressWarnings("unused")
@Provides @Provides
@VCloud @VCloudApi
URI provide() { URI provide() {
return URI.create("https://services.vcloudexpress.terremark.com/api/v0.8"); return URI.create("https://services.vcloudexpress.terremark.com/api/v0.8");
} }