Merge remote branch 'origin'

This commit is contained in:
Andrew Phillips 2010-08-23 17:19:32 +02:00
commit 6b7cb6a166
268 changed files with 10324 additions and 5077 deletions

View File

@ -26,8 +26,9 @@ freedom to use portable abstractions or cloud-specific features.
our current version is 1.0-beta-6
our dev version is 1.0-SNAPSHOT
our compute api supports: ec2, gogrid, rackspace, rimuhosting, vcloud, terremark,
eucalyptus, hosting.com, bluelock, ibmdev, slicehost
our compute api supports: ec2, gogrid, rackspace, rimuhosting, vcloud, trmk-ecloud,
trmk-vcloudexpress, eucalyptus, bluelock-vclouddirector,
bluelock-vcloudexpress, ibmdev, slicehost
* note * the pom dependency org.jclouds/jclouds-allcompute gives you access to
to all of these providers

View File

@ -243,33 +243,6 @@
<outputDirectory>providers/azure</outputDirectory>
</fileSet>
<!-- providers: hostingdotcom -->
<fileSet>
<directory>vcloud/hostingdotcom/target</directory>
<includes>
<include>jclouds-hostingdotcom-${project.version}.jar</include>
</includes>
<outputDirectory>providers/hostingdotcom/lib</outputDirectory>
</fileSet>
<fileSet>
<directory>vcloud/hostingdotcom/target</directory>
<includes>
<include>jclouds-hostingdotcom-${project.version}-sources.jar</include>
</includes>
<outputDirectory>providers/hostingdotcom/src</outputDirectory>
</fileSet>
<fileSet>
<directory>vcloud/hostingdotcom/target/apidocs</directory>
<outputDirectory>providers/hostingdotcom/docs</outputDirectory>
</fileSet>
<fileSet>
<directory>vcloud/hostingdotcom</directory>
<includes>
<include>README.txt</include>
</includes>
<outputDirectory>providers/hostingdotcom</outputDirectory>
</fileSet>
<!-- providers: mezeo -->
<fileSet>
<directory>mezeo/pcs2/target</directory>

View File

@ -114,7 +114,6 @@ public interface ELBAsyncClient {
@XMLResponseParser(DescribeLoadBalancersResponseHandler.class)
@FormParams(keys = ACTION, values = "DescribeLoadBalancers")
ListenableFuture<? extends Set<LoadBalancer>> describeLoadBalancersInRegion(
@EndpointParam(parser = RegionToEndpoint.class) @Nullable String region,
@FormParam("LoadBalancerName") @Nullable String name);
@EndpointParam(parser = RegionToEndpoint.class) @Nullable String region);
}

View File

@ -94,6 +94,11 @@ public interface ELBClient {
void deregisterInstancesWithLoadBalancerInRegion(@Nullable String region, String name,
String... instanceIds);
Set<LoadBalancer> describeLoadBalancersInRegion(@Nullable String region, @Nullable String name);
/**
* Returns a set of elastic load balancers
* @param region
* @return
*/
Set<LoadBalancer> describeLoadBalancersInRegion(@Nullable String region);
}

View File

@ -84,10 +84,12 @@ public class EC2LoadBalancerServiceLiveTest extends BaseLoadBalancerServiceLiveT
for (NodeMetadata node : nodes) {
instanceIds.add(node.getProviderId());
}
Set<LoadBalancer> elbs = elbClient.describeLoadBalancersInRegion(Region.US_EAST_1, tag);
Set<LoadBalancer> elbs = elbClient.describeLoadBalancersInRegion(Region.US_EAST_1);
assertNotNull(elbs);
LoadBalancer elb = elbs.iterator().next();
assertEquals(elb.getInstanceIds(), instanceIds);
for(LoadBalancer elb:elbs)
{
if(elb.getName().equals(tag))
assertEquals(elb.getInstanceIds(), instanceIds);
}
}
}

View File

@ -78,10 +78,9 @@ public class ELBClientLiveTest {
@Test(dependsOnMethods = "testCreateLoadBalancer")
void testDescribeLoadBalancers() {
String name = "TestDescribeLoadBalancer";
for (String region : Lists.newArrayList(null, Region.EU_WEST_1, Region.US_EAST_1,
Region.US_WEST_1, Region.AP_SOUTHEAST_1)) {
Set<LoadBalancer> allResults = client.describeLoadBalancersInRegion(region, name);
Set<LoadBalancer> allResults = client.describeLoadBalancersInRegion(region);
assertNotNull(allResults);
assert (allResults.size() >= 1);
}

View File

@ -22,7 +22,7 @@
Current supported services are:
[ec2, rimuhosting, cloudservers, trmk-ecloud, trmk-vcloudexpress, vcloud, bluelock,
ibmdev, eucalyptus, hostingdotcom, slicehost]
ibmdev, eucalyptus, slicehost]
Here's an example of getting some compute configuration from rackspace:

View File

@ -68,5 +68,8 @@ public interface LoadBalancerService {
@Beta
void destroyLoadBalancer(String handle);
@Beta
Set<String> listLoadBalancers();
}

View File

@ -38,171 +38,171 @@ public class CIMOperatingSystem extends OperatingSystem {
/**
* Other
*/
OTHER(0, "Other", OsFamily.UNKNOWN, false),
OTHER(1, "Other", OsFamily.UNKNOWN, false),
/**
* MACOS
*/
MACOS(1, "MACOS", OsFamily.DARWIN, false),
MACOS(2, "MACOS", OsFamily.DARWIN, false),
/**
* Solaris
*/
SOLARIS(28, "Solaris", OsFamily.SOLARIS, false),
SOLARIS(29, "Solaris", OsFamily.SOLARIS, false),
/**
* LINUX
*/
LINUX(35, "LINUX", OsFamily.LINUX, false),
LINUX(36, "LINUX", OsFamily.LINUX, false),
/**
* FreeBSD
*/
FREEBSD(41, "FreeBSD", OsFamily.FREEBSD, false),
FREEBSD(42, "FreeBSD", OsFamily.FREEBSD, false),
/**
* NetBSD
*/
NETBSD(42, "NetBSD", OsFamily.NETBSD, false),
NETBSD(43, "NetBSD", OsFamily.NETBSD, false),
/**
* OpenBSD
*/
OPENBSD(64, "OpenBSD", OsFamily.OPENBSD, false),
OPENBSD(65, "OpenBSD", OsFamily.OPENBSD, false),
/**
* Not Applicable
*/
NOT_APPLICABLE(65, "Not Applicable", OsFamily.UNKNOWN, false),
NOT_APPLICABLE(66, "Not Applicable", OsFamily.UNKNOWN, false),
/**
* Microsoft Windows Server 2003
*/
WINDOWS_SERVER_2003(68, "Microsoft Windows Server 2003", OsFamily.WINDOWS, false),
WINDOWS_SERVER_2003(69, "Microsoft Windows Server 2003", OsFamily.WINDOWS, false),
/**
* Microsoft Windows Server 2003 64-Bit
*/
WINDOWS_SERVER_2003_64(69, "Microsoft Windows Server 2003 64-Bit", OsFamily.WINDOWS, true),
WINDOWS_SERVER_2003_64(70, "Microsoft Windows Server 2003 64-Bit", OsFamily.WINDOWS, true),
/**
* Microsoft Windows Server 2008
*/
WINDOWS_SERVER_2008(75, "Microsoft Windows Server 2008", OsFamily.WINDOWS, false),
WINDOWS_SERVER_2008(76, "Microsoft Windows Server 2008", OsFamily.WINDOWS, false),
/**
* Microsoft Windows Server 2008 64-Bit
*/
WINDOWS_SERVER_2008_64(76, "Microsoft Windows Server 2008 64-Bit", OsFamily.WINDOWS, true),
WINDOWS_SERVER_2008_64(77, "Microsoft Windows Server 2008 64-Bit", OsFamily.WINDOWS, true),
/**
* FreeBSD 64-Bit
*/
FREEBSD_64(77, "FreeBSD 64-Bit", OsFamily.FREEBSD, true),
FREEBSD_64(78, "FreeBSD 64-Bit", OsFamily.FREEBSD, true),
/**
* RedHat Enterprise Linux
*/
RHEL(78, "RedHat Enterprise Linux", OsFamily.RHEL, false),
RHEL(79, "RedHat Enterprise Linux", OsFamily.RHEL, false),
/**
* RedHat Enterprise Linux 64-Bit
*/
RHEL_64(79, "RedHat Enterprise Linux 64-Bit", OsFamily.RHEL, true),
RHEL_64(80, "RedHat Enterprise Linux 64-Bit", OsFamily.RHEL, true),
/**
* Solaris 64-Bit
*/
SOLARIS_64(80, "Solaris 64-Bit", OsFamily.SOLARIS, true),
SOLARIS_64(81, "Solaris 64-Bit", OsFamily.SOLARIS, true),
/**
* SUSE
*/
SUSE(81, "SUSE", OsFamily.SUSE, false),
SUSE(82, "SUSE", OsFamily.SUSE, false),
/**
* SUSE 64-Bit
*/
SUSE_64(82, "SUSE 64-Bit", OsFamily.SUSE, true),
SUSE_64(83, "SUSE 64-Bit", OsFamily.SUSE, true),
/**
* SLES
*/
SLES(83, "SLES", OsFamily.SUSE, false),
SLES(84, "SLES", OsFamily.SUSE, false),
/**
* SLES 64-Bit
*/
SLES_64(84, "SLES 64-Bit", OsFamily.SUSE, true),
SLES_64(85, "SLES 64-Bit", OsFamily.SUSE, true),
/**
* Novell OES
*/
NOVELL_OES(85, "Novell OES", OsFamily.SUSE, true),
NOVELL_OES(86, "Novell OES", OsFamily.SUSE, true),
/**
* Mandriva
*/
MANDRIVA(88, "Mandriva", OsFamily.MANDRIVA, false),
MANDRIVA(89, "Mandriva", OsFamily.MANDRIVA, false),
/**
* Mandriva 64-Bit
*/
MANDRIVA_64(89, "Mandriva 64-Bit", OsFamily.MANDRIVA, true),
MANDRIVA_64(90, "Mandriva 64-Bit", OsFamily.MANDRIVA, true),
/**
* TurboLinux
*/
TURBOLINUX(90, "TurboLinux", OsFamily.TURBOLINUX, false),
TURBOLINUX(91, "TurboLinux", OsFamily.TURBOLINUX, false),
/**
* TurboLinux 64-Bit
*/
TURBOLINUX_64(91, "TurboLinux 64-Bit", OsFamily.TURBOLINUX, true),
TURBOLINUX_64(92, "TurboLinux 64-Bit", OsFamily.TURBOLINUX, true),
/**
* Ubuntu
*/
UBUNTU(92, "Ubuntu", OsFamily.UBUNTU, false),
UBUNTU(93, "Ubuntu", OsFamily.UBUNTU, false),
/**
* Ubuntu 64-Bit
*/
UBUNTU_64(93, "Ubuntu 64-Bit", OsFamily.UBUNTU, true),
UBUNTU_64(94, "Ubuntu 64-Bit", OsFamily.UBUNTU, true),
/**
* Debian
*/
DEBIAN(94, "Debian", OsFamily.DEBIAN, false),
DEBIAN(95, "Debian", OsFamily.DEBIAN, false),
/**
* Debian 64-Bit
*/
DEBIAN_64(95, "Debian 64-Bit", OsFamily.DEBIAN, false),
DEBIAN_64(96, "Debian 64-Bit", OsFamily.DEBIAN, false),
/**
* Linux 2.4.x
*/
LINUX_2_4(96, "Linux 2.4.x", OsFamily.LINUX, false),
LINUX_2_4(97, "Linux 2.4.x", OsFamily.LINUX, false),
/**
* Linux 2.4.x 64-Bi
*/
LINUX_2_4_64(97, "Linux 2.4.x 64-Bit", OsFamily.LINUX, true),
LINUX_2_4_64(98, "Linux 2.4.x 64-Bit", OsFamily.LINUX, true),
/**
* Linux 2.6.x
*/
LINUX_2_6(98, "Linux 2.6.x", OsFamily.LINUX, false),
LINUX_2_6(99, "Linux 2.6.x", OsFamily.LINUX, false),
/**
* Linux 2.6.x 64-Bit
*/
LINUX_2_6_64(99, "Linux 2.6.x 64-Bit", OsFamily.LINUX, true),
LINUX_2_6_64(100, "Linux 2.6.x 64-Bit", OsFamily.LINUX, true),
/**
* Linux 64-Bit
*/
LINUX_64(100, "Linux 64-Bit", OsFamily.LINUX, true),
LINUX_64(101, "Linux 64-Bit", OsFamily.LINUX, true),
/**
* Other 64-Bit
*/
OTHER_64(101, "Other 64-Bit", OsFamily.UNKNOWN, true),
OTHER_64(102, "Other 64-Bit", OsFamily.UNKNOWN, true),
/**
* Microsoft Windows Server 2008 R2
*/
WINDOWS_SERVER_2008_R2(102, "Microsoft Windows Server 2008 R2", OsFamily.WINDOWS, true),
WINDOWS_SERVER_2008_R2(103, "Microsoft Windows Server 2008 R2", OsFamily.WINDOWS, true),
/**
* VMware ESXi
*/
ESXI(103, "VMware ESXi", OsFamily.ESX, true),
ESXI(104, "VMware ESXi", OsFamily.ESX, true),
/**
* Microsoft Windows 7
*/
WINDOWS_7(104, "Microsoft Windows 7", OsFamily.WINDOWS, false),
WINDOWS_7(105, "Microsoft Windows 7", OsFamily.WINDOWS, false),
/**
* CentOS 32-bit
*/
CENTOS(105, "CentOS 32-bit", OsFamily.CENTOS, false),
CENTOS(106, "CentOS 32-bit", OsFamily.CENTOS, false),
/**
* CentOS 64-bit
*/
CENTOS_64(106, "CentOS 64-bit", OsFamily.CENTOS, true),
CENTOS_64(107, "CentOS 64-bit", OsFamily.CENTOS, true),
/**
* Oracle Enterprise Linux 32-bit
*/
ORACLE_ENTERPRISE_LINUX(107, "Oracle Enterprise Linux 32-bit", OsFamily.OEL, false),
ORACLE_ENTERPRISE_LINUX(108, "Oracle Enterprise Linux 32-bit", OsFamily.OEL, false),
/**
* Oracle Enterprise Linux 64-bit
*/
ORACLE_ENTERPRISE_LINUX_64(108, "Oracle Enterprise Linux 64-bit", OsFamily.OEL, true);
ORACLE_ENTERPRISE_LINUX_64(109, "Oracle Enterprise Linux 64-bit", OsFamily.OEL, true);
private final int code;

View File

@ -43,6 +43,7 @@ import org.jclouds.logging.Logger;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
@ -68,19 +69,20 @@ public class BaseLoadBalancerService implements LoadBalancerService {
protected final ComputeServiceContext context;
protected final LoadBalanceNodesStrategy loadBalancerStrategy;
protected final DestroyLoadBalancerStrategy destroyLoadBalancerStrategy;
// protected final ListLoadBalancersStrategy listLoadBalancersStrategy;
protected final BackoffLimitedRetryHandler backoffLimitedRetryHandler;
@Inject
protected BaseLoadBalancerService(ComputeServiceContext context,
LoadBalanceNodesStrategy loadBalancerStrategy,
protected BaseLoadBalancerService(ComputeServiceContext context, LoadBalanceNodesStrategy loadBalancerStrategy,
DestroyLoadBalancerStrategy destroyLoadBalancerStrategy,
// ListLoadBalancersStrategy listLoadBalancersStrategy,
BackoffLimitedRetryHandler backoffLimitedRetryHandler) {
this.context = checkNotNull(context, "context");
this.loadBalancerStrategy = checkNotNull(loadBalancerStrategy, "loadBalancerStrategy");
this.destroyLoadBalancerStrategy = checkNotNull(destroyLoadBalancerStrategy,
"destroyLoadBalancerStrategy");
this.backoffLimitedRetryHandler = checkNotNull(backoffLimitedRetryHandler,
"backoffLimitedRetryHandler");
this.destroyLoadBalancerStrategy = checkNotNull(destroyLoadBalancerStrategy, "destroyLoadBalancerStrategy");
// this.listLoadBalancersStrategy = checkNotNull(listLoadBalancersStrategy,
// "listLoadBalancersStrategy");
this.backoffLimitedRetryHandler = checkNotNull(backoffLimitedRetryHandler, "backoffLimitedRetryHandler");
}
/**
@ -92,17 +94,16 @@ public class BaseLoadBalancerService implements LoadBalancerService {
}
@Override
public Set<String> loadBalanceNodesMatching(Predicate<NodeMetadata> filter,
String loadBalancerName, String protocol, int loadBalancerPort, int instancePort) {
public Set<String> loadBalanceNodesMatching(Predicate<NodeMetadata> filter, String loadBalancerName,
String protocol, int loadBalancerPort, int instancePort) {
checkNotNull(loadBalancerName, "loadBalancerName");
checkNotNull(protocol, "protocol");
checkArgument(protocol.toUpperCase().equals("HTTP") || protocol.toUpperCase().equals("TCP"),
"Acceptable values for protocol are HTTP or TCP");
Map<Location, Set<String>> locationMap = Maps.newHashMap();
for (NodeMetadata node : Iterables.filter(context.getComputeService()
.listNodesDetailsMatching(NodePredicates.all()), Predicates.and(filter, Predicates
.not(NodePredicates.TERMINATED)))) {
for (NodeMetadata node : Iterables.filter(context.getComputeService().listNodesDetailsMatching(
NodePredicates.all()), Predicates.and(filter, Predicates.not(NodePredicates.TERMINATED)))) {
Set<String> ids = locationMap.get(node.getLocation());
if (ids == null)
ids = Sets.newHashSet();
@ -112,8 +113,8 @@ public class BaseLoadBalancerService implements LoadBalancerService {
Set<String> dnsNames = Sets.newHashSet();
for (Location location : locationMap.keySet()) {
logger.debug(">> creating load balancer (%s)", loadBalancerName);
String dnsName = loadBalancerStrategy.execute(location, loadBalancerName, protocol,
loadBalancerPort, instancePort, locationMap.get(location));
String dnsName = loadBalancerStrategy.execute(location, loadBalancerName, protocol, loadBalancerPort,
instancePort, locationMap.get(location));
dnsNames.add(dnsName);
logger.debug("<< created load balancer (%s) DNS (%s)", loadBalancerName, dnsName);
}
@ -131,4 +132,11 @@ public class BaseLoadBalancerService implements LoadBalancerService {
logger.debug("<< destroyed load balancer(%s) success(%s)", loadBalancer, successful);
}
public Set<String> listLoadBalancers() {
return ImmutableSet.of();
// TODO
// Set<String> loadBalancerSet = listLoadBalancersStrategy.execute();
// return loadBalancerSet;
}
}

View File

@ -64,7 +64,6 @@ import org.jclouds.compute.predicates.OperatingSystemPredicates;
import org.jclouds.domain.Credentials;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationScope;
import org.jclouds.http.HttpResponseException;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.net.IPSocket;
import org.jclouds.predicates.RetryablePredicate;
@ -266,8 +265,6 @@ public abstract class BaseComputeServiceLiveTest {
public void testCreateTwoNodesWithRunScript() throws Exception {
try {
client.destroyNodesMatching(withTag(tag));
} catch (HttpResponseException e) {
// TODO hosting.com throws 400 when we try to delete a vApp
} catch (NoSuchElementException e) {
}

View File

@ -30,21 +30,21 @@ public interface Constants {
* <p/>
* Amount of threads servicing the user requests and transformations
*/
public static final String PROPERTY_USER_THREADS = "jclouds.user_threads";
public static final String PROPERTY_USER_THREADS = "jclouds.user-threads";
/**
* Integer property. default (20)
* <p/>
* Amount of threads servicing the I/O of http connections.
*/
public static final String PROPERTY_IO_WORKER_THREADS = "jclouds.io_worker_threads";
public static final String PROPERTY_IO_WORKER_THREADS = "jclouds.io-worker-threads";
/**
* Integer property. default (20)
* <p/>
* Limits the amount of connections per context.
*/
public static final String PROPERTY_MAX_CONNECTIONS_PER_CONTEXT = "jclouds.max_connections_per_context";
public static final String PROPERTY_MAX_CONNECTIONS_PER_CONTEXT = "jclouds.max-connections-per_context";
/**
* Integer property. default (0)
@ -52,73 +52,73 @@ public interface Constants {
* Limits the amount of connections per host. 0 means indirectly limited by
* {@link #PROPERTY_MAX_CONNECTIONS_PER_CONTEXT}.
*/
public static final String PROPERTY_MAX_CONNECTIONS_PER_HOST = "jclouds.max_connections_per_host";
public static final String PROPERTY_MAX_CONNECTIONS_PER_HOST = "jclouds.max-connections-per-host";
/**
* Integer property. default (2)
* <p/>
* Maximum amount of http session failures before a pool is disabled.
*/
public static final String PROPERTY_MAX_SESSION_FAILURES = "jclouds.max_session_failures";
public static final String PROPERTY_MAX_SESSION_FAILURES = "jclouds.max-session-failures";
/**
* Integer property. default (75)
* <p/>
* Maximum amount of times to re_use an http connection. Services like Amazon S3 throw errors if
* connections are reused too many times.
*/
public static final String PROPERTY_MAX_CONNECTION_REUSE = "jclouds.max_connection_reuse";
public static final String PROPERTY_MAX_CONNECTION_REUSE = "jclouds.max-connection-reuse";
/**
* int property. default (60000)
* <p/>
* How many milliseconds to wait before a socket connection times out. 0 means infinity.
*/
public static final String PROPERTY_SO_TIMEOUT = "jclouds.so_timeout";
public static final String PROPERTY_SO_TIMEOUT = "jclouds.so-timeout";
/**
* Long property. default (60000)
* <p/>
* How many milliseconds to wait before a connection times out. 0 means infinity.
*/
public static final String PROPERTY_CONNECTION_TIMEOUT = "jclouds.connection_timeout";
public static final String PROPERTY_CONNECTION_TIMEOUT = "jclouds.connection-timeout";
/**
* Long property. default (60)
* <p/>
* How many seconds to wait before creating a new session
*/
public static final String PROPERTY_SESSION_INTERVAL = "jclouds.session_interval";
public static final String PROPERTY_SESSION_INTERVAL = "jclouds.session-interval";
/**
* Boolean property.
* <p/>
* Whether or not to use the proxy setup from the underlying operating system.
*/
public static final String PROPERTY_PROXY_SYSTEM = "jclouds.use_system_proxy";
public static final String PROPERTY_PROXY_SYSTEM = "jclouds.use-system-proxy";
/**
* String property.
* <p/>
*Explicitly sets the host name of a HTTP proxy server.
*/
public static final String PROPERTY_PROXY_HOST = "jclouds.proxy_host";
public static final String PROPERTY_PROXY_HOST = "jclouds.proxy-host";
/**
* Integer property.
* <p/>
* Explicitly sets the port number of a HTTP proxy server.
*/
public static final String PROPERTY_PROXY_PORT = "jclouds.proxy_port";
public static final String PROPERTY_PROXY_PORT = "jclouds.proxy-port";
/**
* String property.
* <p/>
* Explicitly sets the user name credential for proxy authentication.
*/
public static final String PROPERTY_PROXY_USER = "jclouds.proxy_user";
public static final String PROPERTY_PROXY_USER = "jclouds.proxy-user";
/**
* String property.
* <p/>
* Explicitly sets the password credential for proxy authentication.
*/
public static final String PROPERTY_PROXY_PASSWORD = "jclouds.proxy_password";
public static final String PROPERTY_PROXY_PASSWORD = "jclouds.proxy-password";
/**
* Integer property.
@ -126,26 +126,32 @@ public interface Constants {
* Commands are retried, if the problem on the server side was a resolvable conflict. However,
* the maximum tries of a single command is bounded.
*/
public static final String PROPERTY_MAX_RETRIES = "jclouds.max_retries";
public static final String PROPERTY_MAX_RETRIES = "jclouds.max-retries";
/**
* Integer property.
* <p/>
* Commands are limited to only a certain amount of redirects.
*/
public static final String PROPERTY_MAX_REDIRECTS = "jclouds.max_redirects";
public static final String PROPERTY_MAX_REDIRECTS = "jclouds.max-redirects";
/**
* Long property.
* <p/>
* longest time a single request can take before throwing an exception.
*/
public static final String PROPERTY_REQUEST_TIMEOUT = "jclouds.request_timeout";
public static final String PROPERTY_REQUEST_TIMEOUT = "jclouds.request-timeout";
/**
* Boolean property.
* <p/>
* allow mismatch between hostname and ssl cerificate. Set to true in DNS_based services like
* Amazon S3.
*/
public static final String PROPERTY_RELAX_HOSTNAME = "jclouds.relax_hostname";
public static final String PROPERTY_RELAX_HOSTNAME = "jclouds.relax-hostname";
/**
* Boolean property.
* <p/>
* trust self-signed certs
*/
public static final String PROPERTY_TRUST_ALL_CERTS = "jclouds.trust-all-certs";
/**
* Name of the logger that records all http headers from the client and the server.
*/
@ -161,7 +167,7 @@ public interface Constants {
/**
* Name of the custom adapter bindings map for Json
*/
public static final String PROPERTY_GSON_ADAPTERS = "jclouds.gson_adapters";
public static final String PROPERTY_GSON_ADAPTERS = "jclouds.gson-adapters";
/**
* String property.
@ -182,7 +188,7 @@ public interface Constants {
* <p/>
* Explicitly identifies the version of an api.
*/
public static final String PROPERTY_API_VERSION = "jclouds.api_version";
public static final String PROPERTY_API_VERSION = "jclouds.api-version";
/**
* String property.

View File

@ -23,6 +23,7 @@ import static org.jclouds.Constants.PROPERTY_API_VERSION;
import static org.jclouds.Constants.PROPERTY_CONNECTION_TIMEOUT;
import static org.jclouds.Constants.PROPERTY_CREDENTIAL;
import static org.jclouds.Constants.PROPERTY_ENDPOINT;
import static org.jclouds.Constants.PROPERTY_IDENTITY;
import static org.jclouds.Constants.PROPERTY_IO_WORKER_THREADS;
import static org.jclouds.Constants.PROPERTY_MAX_CONNECTIONS_PER_CONTEXT;
import static org.jclouds.Constants.PROPERTY_MAX_CONNECTIONS_PER_HOST;
@ -30,7 +31,6 @@ import static org.jclouds.Constants.PROPERTY_MAX_CONNECTION_REUSE;
import static org.jclouds.Constants.PROPERTY_MAX_REDIRECTS;
import static org.jclouds.Constants.PROPERTY_MAX_RETRIES;
import static org.jclouds.Constants.PROPERTY_MAX_SESSION_FAILURES;
import static org.jclouds.Constants.PROPERTY_IDENTITY;
import static org.jclouds.Constants.PROPERTY_PROVIDER;
import static org.jclouds.Constants.PROPERTY_PROXY_HOST;
import static org.jclouds.Constants.PROPERTY_PROXY_PASSWORD;
@ -40,6 +40,7 @@ import static org.jclouds.Constants.PROPERTY_PROXY_USER;
import static org.jclouds.Constants.PROPERTY_RELAX_HOSTNAME;
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
import static org.jclouds.Constants.PROPERTY_SO_TIMEOUT;
import static org.jclouds.Constants.PROPERTY_TRUST_ALL_CERTS;
import static org.jclouds.Constants.PROPERTY_USER_THREADS;
import java.util.Properties;
@ -63,6 +64,14 @@ public class PropertiesBuilder {
return this;
}
/**
* @see org.jclouds.Constants.PROPERTY_TRUST_ALL_CERTS
*/
public PropertiesBuilder trustAllCerts(boolean trust) {
properties.setProperty(PROPERTY_TRUST_ALL_CERTS, trust + "");
return this;
}
/**
* @see org.jclouds.Constants.PROPERTY_PROXY_SYSTEM
*/
@ -147,8 +156,7 @@ public class PropertiesBuilder {
* @see org.jclouds.Constants.PROPERTY_MAX_SESSION_FAILURES
*/
public PropertiesBuilder withMaxSessionFailures(int poolMaxSessionFailures) {
properties.setProperty(PROPERTY_MAX_SESSION_FAILURES, Integer
.toString(poolMaxSessionFailures));
properties.setProperty(PROPERTY_MAX_SESSION_FAILURES, Integer.toString(poolMaxSessionFailures));
return this;
}
@ -173,8 +181,7 @@ public class PropertiesBuilder {
* @see org.jclouds.Constants.PROPERTY_MAX_CONNECTIONS_PER_CONTEXT
*/
public PropertiesBuilder limitConnectionsTo(int connectionLimit) {
properties.setProperty(PROPERTY_MAX_CONNECTIONS_PER_CONTEXT, Integer
.toString(connectionLimit));
properties.setProperty(PROPERTY_MAX_CONNECTIONS_PER_CONTEXT, Integer.toString(connectionLimit));
return this;
}

View File

@ -117,6 +117,9 @@ public class HttpUtils {
@Inject(optional = true)
@Named(Constants.PROPERTY_PROXY_PASSWORD)
private String proxyPassword;
@Inject(optional = true)
@Named(Constants.PROPERTY_TRUST_ALL_CERTS)
private boolean trustAllCerts;
@Inject
public HttpUtils(@Named(Constants.PROPERTY_CONNECTION_TIMEOUT) int connectionTimeout,
@ -169,6 +172,10 @@ public class HttpUtils {
return relaxHostname;
}
public boolean trustAllCerts() {
return trustAllCerts;
}
public boolean useSystemProxies() {
return systemProxies;
}

View File

@ -19,12 +19,18 @@
package org.jclouds.http.config;
import java.security.SecureRandom;
import java.security.cert.X509Certificate;
import java.util.Map;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Singleton;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import org.jclouds.http.HttpCommandExecutorService;
import org.jclouds.http.TransformingHttpCommandExecutorService;
@ -32,9 +38,13 @@ import org.jclouds.http.TransformingHttpCommandExecutorServiceImpl;
import org.jclouds.http.internal.JavaUrlHttpCommandExecutorService;
import org.jclouds.logging.Logger;
import com.google.common.base.Supplier;
import com.google.common.base.Throwables;
import com.google.common.collect.Maps;
import com.google.inject.AbstractModule;
import com.google.inject.Scopes;
import com.google.inject.TypeLiteral;
import com.google.inject.name.Names;
/**
* Configures {@link JavaUrlHttpCommandExecutorService}.
@ -52,11 +62,13 @@ public class JavaUrlHttpCommandExecutorServiceModule extends AbstractModule {
}
protected void bindClient() {
bind(HttpCommandExecutorService.class).to(JavaUrlHttpCommandExecutorService.class).in(
Scopes.SINGLETON);
bind(HttpCommandExecutorService.class).to(JavaUrlHttpCommandExecutorService.class).in(Scopes.SINGLETON);
bind(HostnameVerifier.class).to(LogToMapHostnameVerifier.class);
bind(TransformingHttpCommandExecutorService.class).to(
TransformingHttpCommandExecutorServiceImpl.class).in(Scopes.SINGLETON);
bind(TransformingHttpCommandExecutorService.class).to(TransformingHttpCommandExecutorServiceImpl.class).in(
Scopes.SINGLETON);
bind(new TypeLiteral<Supplier<SSLContext>>() {
}).annotatedWith(Names.named("untrusted")).to(new TypeLiteral<UntrustedSSLContextSupplier>() {
});
}
/**
@ -77,4 +89,49 @@ public class JavaUrlHttpCommandExecutorServiceModule extends AbstractModule {
return true;
}
}
@Singleton
public static class UntrustedSSLContextSupplier implements Supplier<SSLContext> {
private final TrustAllCerts trustAllCerts;
@Inject
UntrustedSSLContextSupplier(TrustAllCerts trustAllCerts) {
this.trustAllCerts = trustAllCerts;
}
@Override
public SSLContext get() {
try {
SSLContext sc;
sc = SSLContext.getInstance("SSL");
sc.init(null, new TrustManager[] { trustAllCerts }, new SecureRandom());
return sc;
} catch (Exception e) {
Throwables.propagate(e);
return null;
}
}
}
/**
*
* Used to trust all certs
*
* @author Adrian Cole
*/
@Singleton
static class TrustAllCerts implements X509TrustManager {
public X509Certificate[] getAcceptedIssuers() {
return null;
}
public void checkClientTrusted(X509Certificate[] certs, String authType) {
return;
}
public void checkServerTrusted(X509Certificate[] certs, String authType) {
return;
}
}
}

View File

@ -47,6 +47,7 @@ import javax.inject.Named;
import javax.inject.Singleton;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.ws.rs.core.HttpHeaders;
import org.jclouds.Constants;
@ -62,6 +63,7 @@ import org.jclouds.io.Payload;
import org.jclouds.io.Payloads;
import org.jclouds.logging.Logger;
import com.google.common.base.Supplier;
import com.google.common.base.Throwables;
import com.google.common.collect.LinkedHashMultimap;
import com.google.common.collect.Multimap;
@ -77,6 +79,7 @@ public class JavaUrlHttpCommandExecutorService extends BaseHttpCommandExecutorSe
public static final String USER_AGENT = "jclouds/1.0 java/" + System.getProperty("java.version");
@Resource
protected Logger logger = Logger.NULL;
private final Supplier<SSLContext> untrustedSSLContextProvider;
private final HostnameVerifier verifier;
private final Field methodField;
@ -84,11 +87,13 @@ public class JavaUrlHttpCommandExecutorService extends BaseHttpCommandExecutorSe
public JavaUrlHttpCommandExecutorService(HttpUtils utils,
@Named(Constants.PROPERTY_IO_WORKER_THREADS) ExecutorService ioWorkerExecutor,
DelegatingRetryHandler retryHandler, IOExceptionRetryHandler ioRetryHandler,
DelegatingErrorHandler errorHandler, HttpWire wire, HostnameVerifier verifier) throws SecurityException,
DelegatingErrorHandler errorHandler, HttpWire wire, HostnameVerifier verifier,
@Named("untrusted") Supplier<SSLContext> untrustedSSLContextProvider) throws SecurityException,
NoSuchFieldException {
super(utils, ioWorkerExecutor, retryHandler, ioRetryHandler, errorHandler, wire);
if (utils.getMaxConnections() > 0)
System.setProperty("http.maxConnections", String.valueOf(checkNotNull(utils, "utils").getMaxConnections()));
this.untrustedSSLContextProvider = checkNotNull(untrustedSSLContextProvider, "untrustedSSLContextProvider");
this.verifier = checkNotNull(verifier, "verifier");
this.methodField = HttpURLConnection.class.getDeclaredField("method");
methodField.setAccessible(true);
@ -160,9 +165,12 @@ public class JavaUrlHttpCommandExecutorService extends BaseHttpCommandExecutorSe
} else {
connection = (HttpURLConnection) url.openConnection();
}
if (utils.relaxHostname() && connection instanceof HttpsURLConnection) {
if (connection instanceof HttpsURLConnection) {
HttpsURLConnection sslCon = (HttpsURLConnection) connection;
sslCon.setHostnameVerifier(verifier);
if (utils.relaxHostname())
sslCon.setHostnameVerifier(verifier);
if (utils.trustAllCerts())
sslCon.setSSLSocketFactory(untrustedSSLContextProvider.get().getSocketFactory());
}
connection.setDoOutput(true);
connection.setAllowUserInteraction(false);

View File

@ -59,9 +59,6 @@ trmk-vcloudexpress.propertiesbuilder=org.jclouds.vcloud.terremark.TerremarkVClou
trmk-ecloud.contextbuilder=org.jclouds.vcloud.terremark.TerremarkECloudContextBuilder
trmk-ecloud.propertiesbuilder=org.jclouds.vcloud.terremark.TerremarkECloudPropertiesBuilder
hostingdotcom.contextbuilder=org.jclouds.vcloud.hostingdotcom.HostingDotComVCloudContextBuilder
hostingdotcom.propertiesbuilder=org.jclouds.vcloud.hostingdotcom.HostingDotComVCloudPropertiesBuilder
chef.contextbuilder=org.jclouds.chef.ChefContextBuilder
chef.propertiesbuilder=org.jclouds.chef.ChefPropertiesBuilder
@ -74,14 +71,20 @@ opscodeplatform.propertiesbuilder=org.jclouds.opscodeplatform.OpscodePlatformPro
vcloud.contextbuilder=org.jclouds.vcloud.VCloudContextBuilder
vcloud.propertiesbuilder=org.jclouds.vcloud.VCloudPropertiesBuilder
vcloudexpress.contextbuilder=org.jclouds.vcloud.VCloudExpressContextBuilder
vcloudexpress.propertiesbuilder=org.jclouds.vcloud.VCloudExpressPropertiesBuilder
eucalyptus.contextbuilder=org.jclouds.aws.ec2.EC2ContextBuilder
eucalyptus.propertiesbuilder=org.jclouds.aws.ec2.EucalyptusPropertiesBuilder
cloudservers.contextbuilder=org.jclouds.rackspace.cloudservers.CloudServersContextBuilder
cloudservers.propertiesbuilder=org.jclouds.rackspace.RackspacePropertiesBuilder
bluelock.contextbuilder=org.jclouds.vcloud.bluelock.BlueLockVCloudContextBuilder
bluelock.propertiesbuilder=org.jclouds.vcloud.bluelock.BlueLockVCloudPropertiesBuilder
bluelock-vclouddirector.contextbuilder=org.jclouds.vcloud.bluelock.BlueLockVCloudDirectorContextBuilder
bluelock-vclouddirector.propertiesbuilder=org.jclouds.vcloud.bluelock.BlueLockVCloudDirectorPropertiesBuilder
bluelock-vcloudexpress.contextbuilder=org.jclouds.vcloud.bluelock.BlueLockVCloudExpressContextBuilder
bluelock-vcloudexpress.propertiesbuilder=org.jclouds.vcloud.bluelock.BlueLockVCloudExpressPropertiesBuilder
gogrid.propertiesbuilder=org.jclouds.gogrid.GoGridPropertiesBuilder
gogrid.contextbuilder=org.jclouds.gogrid.GoGridContextBuilder

View File

@ -45,7 +45,7 @@ public class CredentialsTest {
assertEquals(creds.credential, "Base64==");
}
public void testHosting() {
public void testDollar() {
Credentials creds = Credentials.parse(URI
.create("compute://user%40domain:pa%24sword@hostingdotcom"));
assertEquals(creds.identity, "user@domain");

View File

@ -31,6 +31,7 @@ import java.util.concurrent.Executors;
import javax.inject.Provider;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.ws.rs.core.UriBuilder;
@ -50,6 +51,7 @@ import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import com.google.common.base.Supplier;
import com.google.inject.Key;
import com.google.inject.TypeLiteral;
@ -112,12 +114,20 @@ public class BackoffLimitedRetryHandlerTest {
RedirectionRetryHandler retry = new RedirectionRetryHandler(uriBuilderProvider, backoff);
JavaUrlHttpCommandExecutorService httpService = new JavaUrlHttpCommandExecutorService(utils, execService,
new DelegatingRetryHandler(backoff, retry), new BackoffLimitedRetryHandler(),
new DelegatingErrorHandler(), new HttpWire(), new HostnameVerifier(){
new DelegatingErrorHandler(), new HttpWire(), new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return false;
}});
}
}, new Supplier<SSLContext>() {
@Override
public SSLContext get() {
return null;
}
});
executorService = new TransformingHttpCommandExecutorServiceImpl(httpService, execService);
}

View File

@ -136,10 +136,10 @@ public class HttpUtilsTest extends PerformanceTest {
assertEquals(creds, URI.create("compute://identity:Base64==@azureblob/container-hyphen/prefix"));
}
public void testHosting() {
URI creds = HttpUtils.createUri("compute://user@domain:pa$sword@hostingdotcom");
public void testDollar() {
URI creds = HttpUtils.createUri("compute://user@domain:pa$sword@host");
assertEquals(creds.getUserInfo(), "user@domain:pa$sword");
assertEquals(creds, URI.create("compute://user%40domain:pa%24sword@hostingdotcom"));
assertEquals(creds, URI.create("compute://user%40domain:pa%24sword@host"));
}
public void testTerremark() {

View File

@ -39,14 +39,14 @@
-->
<input
message="Which service would you like to use (ec2, cloudservers, vcloud, terremark, rimuhosting, hostingdotcom)?"
validargs="ec2,cloudservers,vcloud,terremark,rimuhosting,hostingdotcom"
message="Which service would you like to use (ec2, cloudservers, vcloud, terremark, rimuhosting)?"
validargs="ec2,cloudservers,vcloud,terremark,rimuhosting"
addproperty="service"
/>
<input
message="Which driver does ${service} use?"
validargs="aws,rackspace,vcloud,terremark,rimuhosting,hostingdotcom"
validargs="aws,rackspace,vcloud,terremark,rimuhosting"
addproperty="driver"
/>

View File

@ -30,14 +30,14 @@
<get src="http://apache.imghat.com/maven/binaries/maven-ant-tasks-2.1.0.jar" dest="build/maven-ant-tasks-2.1.0.jar"/>
<input
message="Which service would you like to use (ec2, cloudservers, vcloud, terremark, rimuhosting, hostingdotcom)?"
validargs="ec2,cloudservers,vcloud,terremark,rimuhosting,hostingdotcom"
message="Which service would you like to use (ec2, cloudservers, vcloud, terremark, rimuhosting)?"
validargs="ec2,cloudservers,vcloud,terremark,rimuhosting"
addproperty="service"
/>
<input
message="Which driver does ${service} use?"
validargs="aws,rackspace,vcloud,bluelock,gogrid,terremark,rimuhosting,hostingdotcom"
validargs="aws,rackspace,vcloud,bluelock,gogrid,terremark,rimuhosting"
addproperty="driver"
/>

View File

@ -31,9 +31,18 @@
<artifactId>jclouds-bluelock</artifactId>
<name>jclouds bluelock Components Core</name>
<description>jclouds core components to access bluelock</description>
<properties>
<jclouds.test.identity>${jclouds.bluelock.user}</jclouds.test.identity>
<jclouds.test.credential>${jclouds.bluelock.password}</jclouds.test.credential>
<!-- when instances are hung, open a ticket and add their names here -->
<jclouds.compute.blacklist.nodes></jclouds.compute.blacklist.nodes>
<bluelock-vcloudexpress.endpoint>https://express.bluelock.com/api</bluelock-vcloudexpress.endpoint>
<bluelock-vcloudexpress.apiversion>0.8</bluelock-vcloudexpress.apiversion>
<bluelock-vcloudexpress.identity>FIXME</bluelock-vcloudexpress.identity>
<bluelock-vcloudexpress.credential>FIXME</bluelock-vcloudexpress.credential>
<bluelock-vclouddirector.endpoint>https://vcenterprise.bluelock.com/api</bluelock-vclouddirector.endpoint>
<bluelock-vclouddirector.apiversion>1.0</bluelock-vclouddirector.apiversion>
<bluelock-vclouddirector.identity>FIXME</bluelock-vclouddirector.identity>
<bluelock-vclouddirector.credential>FIXME</bluelock-vclouddirector.credential>
</properties>
<scm>
@ -56,5 +65,66 @@
<scope>test</scope>
</dependency>
</dependencies>
<profiles>
<profile>
<id>live</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<id>integration</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<systemProperties>
<property>
<name>bluelock-vcloudexpress.endpoint</name>
<value>${bluelock-vcloudexpress.endpoint}</value>
</property>
<property>
<name>bluelock-vcloudexpress.apiversion</name>
<value>${bluelock-vcloudexpress.apiversion}</value>
</property>
<property>
<name>bluelock-vcloudexpress.identity</name>
<value>${bluelock-vcloudexpress.identity}</value>
</property>
<property>
<name>bluelock-vcloudexpress.credential</name>
<value>${bluelock-vcloudexpress.credential}</value>
</property>
<property>
<name>bluelock-vclouddirector.endpoint</name>
<value>${bluelock-vclouddirector.endpoint}</value>
</property>
<property>
<name>bluelock-vclouddirector.apiversion</name>
<value>${bluelock-vclouddirector.apiversion}</value>
</property>
<property>
<name>bluelock-vclouddirector.identity</name>
<value>${bluelock-vclouddirector.identity}</value>
</property>
<property>
<name>bluelock-vclouddirector.credential</name>
<value>${bluelock-vclouddirector.credential}</value>
</property>
<property>
<name>jclouds.compute.blacklist.nodes</name>
<value>${jclouds.compute.blacklist.nodes}</value>
</property>
</systemProperties>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

View File

@ -25,8 +25,8 @@ import java.util.Properties;
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
import org.jclouds.logging.jdk.config.JDKLoggingModule;
import org.jclouds.vcloud.VCloudContextBuilder;
import org.jclouds.vcloud.bluelock.compute.config.BlueLockVCloudComputeServiceContextModule;
import org.jclouds.vcloud.bluelock.config.BlueLockVCloudRestClientModule;
import org.jclouds.vcloud.bluelock.compute.config.BlueLockVCloudDirectorComputeServiceContextModule;
import org.jclouds.vcloud.bluelock.config.BlueLockVCloudDirectorRestClientModule;
import com.google.inject.Injector;
import com.google.inject.Module;
@ -44,20 +44,20 @@ import com.google.inject.Module;
* @author Adrian Cole
* @see BlueLockVCloudComputeServiceContext
*/
public class BlueLockVCloudContextBuilder extends VCloudContextBuilder {
public class BlueLockVCloudDirectorContextBuilder extends VCloudContextBuilder {
public BlueLockVCloudContextBuilder(Properties props) {
public BlueLockVCloudDirectorContextBuilder(Properties props) {
super(props);
}
@Override
protected void addContextModule(List<Module> modules) {
modules.add(new BlueLockVCloudComputeServiceContextModule());
modules.add(new BlueLockVCloudDirectorComputeServiceContextModule());
}
@Override
protected void addClientModule(List<Module> modules) {
modules.add(new BlueLockVCloudRestClientModule());
modules.add(new BlueLockVCloudDirectorRestClientModule());
}
}

View File

@ -17,31 +17,28 @@
* ====================================================================
*/
package org.jclouds.vcloud.hostingdotcom;
package org.jclouds.vcloud.bluelock;
import static org.jclouds.Constants.PROPERTY_ENDPOINT;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED;
import java.util.Properties;
import org.jclouds.vcloud.VCloudPropertiesBuilder;
/**
* Builds properties used in hosting.com VCloud Clients
* Builds properties used in bluelock VCloud Clients
*
* @author Adrian Cole
*/
public class HostingDotComVCloudPropertiesBuilder extends VCloudPropertiesBuilder {
public class BlueLockVCloudDirectorPropertiesBuilder extends VCloudPropertiesBuilder {
@Override
protected Properties defaultProperties() {
Properties properties = super.defaultProperties();
properties.setProperty(PROPERTY_ENDPOINT, "https://vcloud.safesecureweb.com/api");
properties.setProperty(PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED, 45 * 60 * 1000l + "");
properties.setProperty(PROPERTY_ENDPOINT, "https://vcenterprise.bluelock.com/api");
return properties;
}
public HostingDotComVCloudPropertiesBuilder(Properties properties) {
public BlueLockVCloudDirectorPropertiesBuilder(Properties properties) {
super(properties);
}
}

View File

@ -17,23 +17,23 @@
* ====================================================================
*/
package org.jclouds.vcloud.hostingdotcom;
package org.jclouds.vcloud.bluelock;
import java.util.List;
import java.util.Properties;
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
import org.jclouds.logging.jdk.config.JDKLoggingModule;
import org.jclouds.vcloud.VCloudContextBuilder;
import org.jclouds.vcloud.hostingdotcom.compute.config.HostingDotComVCloudComputeServiceContextModule;
import org.jclouds.vcloud.hostingdotcom.config.HostingDotComVCloudRestClientModule;
import org.jclouds.vcloud.VCloudExpressContextBuilder;
import org.jclouds.vcloud.bluelock.compute.config.BlueLockVCloudExpressComputeServiceContextModule;
import org.jclouds.vcloud.bluelock.config.BlueLockVCloudExpressRestClientModule;
import com.google.inject.Injector;
import com.google.inject.Module;
/**
* Creates {@link HostingDotComVCloudComputeServiceContext} or {@link Injector} instances based on
* the most commonly requested arguments.
* Creates {@link BlueLockVCloudComputeServiceContext} or {@link Injector} instances based on the
* most commonly requested arguments.
* <p/>
* Note that Threadsafe objects will be bound as singletons to the Injector or Context provided.
* <p/>
@ -42,22 +42,22 @@ import com.google.inject.Module;
* {@link JavaUrlHttpCommandExecutorServiceModule http transports} will be installed.
*
* @author Adrian Cole
* @see HostingDotComVCloudComputeServiceContext
* @see BlueLockVCloudComputeServiceContext
*/
public class HostingDotComVCloudContextBuilder extends VCloudContextBuilder {
public class BlueLockVCloudExpressContextBuilder extends VCloudExpressContextBuilder {
public HostingDotComVCloudContextBuilder(Properties props) {
public BlueLockVCloudExpressContextBuilder(Properties props) {
super(props);
}
@Override
protected void addContextModule(List<Module> modules) {
modules.add(new HostingDotComVCloudComputeServiceContextModule());
modules.add(new BlueLockVCloudExpressComputeServiceContextModule());
}
@Override
protected void addClientModule(List<Module> modules) {
modules.add(new HostingDotComVCloudRestClientModule());
modules.add(new BlueLockVCloudExpressRestClientModule());
}
}

View File

@ -23,14 +23,14 @@ import static org.jclouds.Constants.PROPERTY_ENDPOINT;
import java.util.Properties;
import org.jclouds.vcloud.VCloudPropertiesBuilder;
import org.jclouds.vcloud.VCloudExpressPropertiesBuilder;
/**
* Builds properties used in bluelock VCloud Clients
*
* @author Adrian Cole
*/
public class BlueLockVCloudPropertiesBuilder extends VCloudPropertiesBuilder {
public class BlueLockVCloudExpressPropertiesBuilder extends VCloudExpressPropertiesBuilder {
@Override
protected Properties defaultProperties() {
Properties properties = super.defaultProperties();
@ -38,7 +38,7 @@ public class BlueLockVCloudPropertiesBuilder extends VCloudPropertiesBuilder {
return properties;
}
public BlueLockVCloudPropertiesBuilder(Properties properties) {
public BlueLockVCloudExpressPropertiesBuilder(Properties properties) {
super(properties);
}
}

View File

@ -29,9 +29,9 @@ import org.jclouds.compute.domain.NodeState;
import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy;
import org.jclouds.domain.Credentials;
import org.jclouds.vcloud.VCloudClient;
import org.jclouds.vcloud.compute.BaseVCloudComputeClient;
import org.jclouds.vcloud.compute.internal.VCloudComputeClientImpl;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.domain.Status;
import org.jclouds.vcloud.domain.VAppTemplate;
import com.google.common.base.Predicate;
@ -40,12 +40,12 @@ import com.google.common.base.Predicate;
* @author Adrian Cole
*/
@Singleton
public class BlueLockVCloudComputeClient extends BaseVCloudComputeClient {
public class BlueLockVCloudDirectorComputeClient extends VCloudComputeClientImpl {
private final PopulateDefaultLoginCredentialsForImageStrategy credentialsProvider;
@Inject
protected BlueLockVCloudComputeClient(PopulateDefaultLoginCredentialsForImageStrategy credentialsProvider,
VCloudClient client, Predicate<URI> successTester, Map<VAppStatus, NodeState> vAppStatusToNodeState) {
protected BlueLockVCloudDirectorComputeClient(PopulateDefaultLoginCredentialsForImageStrategy credentialsProvider,
VCloudClient client, Predicate<URI> successTester, Map<Status, NodeState> vAppStatusToNodeState) {
super(client, successTester, vAppStatusToNodeState);
this.credentialsProvider = credentialsProvider;
}

View File

@ -0,0 +1,62 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.bluelock.compute;
import java.net.URI;
import java.util.Map;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.compute.domain.NodeState;
import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy;
import org.jclouds.domain.Credentials;
import org.jclouds.vcloud.VCloudExpressClient;
import org.jclouds.vcloud.compute.internal.VCloudExpressComputeClientImpl;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.Status;
import org.jclouds.vcloud.domain.VAppTemplate;
import com.google.common.base.Predicate;
/**
* @author Adrian Cole
*/
@Singleton
public class BlueLockVCloudExpressComputeClient extends VCloudExpressComputeClientImpl {
private final PopulateDefaultLoginCredentialsForImageStrategy credentialsProvider;
@Inject
protected BlueLockVCloudExpressComputeClient(PopulateDefaultLoginCredentialsForImageStrategy credentialsProvider,
VCloudExpressClient client, Predicate<URI> successTester, Map<Status, NodeState> vAppStatusToNodeState) {
super(client, successTester, vAppStatusToNodeState);
this.credentialsProvider = credentialsProvider;
}
@Override
protected Map<String, String> parseAndValidateResponse(VAppTemplate template, VApp vAppResponse) {
Credentials credentials = credentialsProvider.execute(template);
Map<String, String> toReturn = super.parseResponse(template, vAppResponse);
toReturn.put("username", credentials.identity);
toReturn.put("password", credentials.credential);
return toReturn;
}
}

View File

@ -23,9 +23,9 @@ import java.util.Set;
import org.jclouds.compute.domain.Size;
import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy;
import org.jclouds.vcloud.bluelock.compute.BlueLockVCloudComputeClient;
import org.jclouds.vcloud.bluelock.compute.BlueLockVCloudDirectorComputeClient;
import org.jclouds.vcloud.bluelock.compute.config.suppliers.ParseSizeFromImageSupplier;
import org.jclouds.vcloud.bluelock.compute.functions.BlueLockImageForVAppTemplate;
import org.jclouds.vcloud.bluelock.compute.functions.BlueLockVCloudImageForVAppTemplate;
import org.jclouds.vcloud.bluelock.compute.strategy.DefaultLoginCredentialsFromBlueLockFAQ;
import org.jclouds.vcloud.compute.VCloudComputeClient;
import org.jclouds.vcloud.compute.config.VCloudComputeServiceContextModule;
@ -40,13 +40,13 @@ import com.google.inject.Injector;
*
* @author Adrian Cole
*/
public class BlueLockVCloudComputeServiceContextModule extends VCloudComputeServiceContextModule {
public class BlueLockVCloudDirectorComputeServiceContextModule extends VCloudComputeServiceContextModule {
@Override
protected void configure() {
super.configure();
bind(ImageForVAppTemplate.class).to(BlueLockImageForVAppTemplate.class);
bind(VCloudComputeClient.class).to(BlueLockVCloudComputeClient.class);
bind(ImageForVAppTemplate.class).to(BlueLockVCloudImageForVAppTemplate.class);
bind(VCloudComputeClient.class).to(BlueLockVCloudDirectorComputeClient.class);
bind(PopulateDefaultLoginCredentialsForImageStrategy.class).to(DefaultLoginCredentialsFromBlueLockFAQ.class);
}

View File

@ -0,0 +1,57 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.bluelock.compute.config;
import java.util.Set;
import org.jclouds.compute.domain.Size;
import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy;
import org.jclouds.vcloud.bluelock.compute.BlueLockVCloudExpressComputeClient;
import org.jclouds.vcloud.bluelock.compute.config.suppliers.ParseSizeFromImageSupplier;
import org.jclouds.vcloud.bluelock.compute.functions.BlueLockVCloudImageForVAppTemplate;
import org.jclouds.vcloud.bluelock.compute.strategy.DefaultLoginCredentialsFromBlueLockFAQ;
import org.jclouds.vcloud.compute.VCloudExpressComputeClient;
import org.jclouds.vcloud.compute.config.VCloudExpressComputeServiceContextModule;
import org.jclouds.vcloud.compute.functions.ImageForVAppTemplate;
import com.google.common.base.Supplier;
import com.google.inject.Injector;
/**
* Configures the {@link BlueLockVCloudComputeServiceContext}; requires
* {@link BlueLockVCloudExpressComputeClient} bound.
*
* @author Adrian Cole
*/
public class BlueLockVCloudExpressComputeServiceContextModule extends VCloudExpressComputeServiceContextModule {
@Override
protected void configure() {
super.configure();
bind(ImageForVAppTemplate.class).to(BlueLockVCloudImageForVAppTemplate.class);
bind(VCloudExpressComputeClient.class).to(BlueLockVCloudExpressComputeClient.class);
bind(PopulateDefaultLoginCredentialsForImageStrategy.class).to(DefaultLoginCredentialsFromBlueLockFAQ.class);
}
@Override
protected Supplier<Set<? extends Size>> getSourceSizeSupplier(Injector injector) {
return injector.getInstance(ParseSizeFromImageSupplier.class);
}
}

View File

@ -31,10 +31,10 @@ import org.jclouds.vcloud.compute.functions.ImageForVAppTemplate;
* @author Adrian Cole
*/
@Singleton
public class BlueLockImageForVAppTemplate extends ImageForVAppTemplate {
public class BlueLockVCloudImageForVAppTemplate extends ImageForVAppTemplate {
@Inject
protected BlueLockImageForVAppTemplate(FindLocationForResource findLocationForResource,
protected BlueLockVCloudImageForVAppTemplate(FindLocationForResource findLocationForResource,
PopulateDefaultLoginCredentialsForImageStrategy credentialsProvider) {
super(findLocationForResource, credentialsProvider);
}

View File

@ -17,32 +17,19 @@
* ====================================================================
*/
package org.jclouds.vcloud.domain;
package org.jclouds.vcloud.bluelock.config;
import java.util.Map;
import org.jclouds.vcloud.domain.internal.OrganizationImpl;
import org.jclouds.vcloud.endpoints.Catalog;
import org.jclouds.vcloud.endpoints.Org;
import org.jclouds.vcloud.endpoints.TasksList;
import org.jclouds.vcloud.endpoints.VDC;
import com.google.inject.ImplementedBy;
import org.jclouds.http.RequiresHttp;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.vcloud.config.VCloudRestClientModule;
/**
* Configures the VCloud authentication service connection, including logging and http transport.
*
* @author Adrian Cole
*/
@Org
@ImplementedBy(OrganizationImpl.class)
public interface Organization extends NamedResource {
@RequiresHttp
@ConfiguresRestClient
public class BlueLockVCloudDirectorRestClientModule extends VCloudRestClientModule {
@Catalog
Map<String, NamedResource> getCatalogs();
@VDC
Map<String, NamedResource> getVDCs();
@TasksList
Map<String, NamedResource> getTasksLists();
}
}

View File

@ -24,34 +24,30 @@ import static org.jclouds.Constants.PROPERTY_IDENTITY;
import java.net.URI;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
import javax.inject.Named;
import org.jclouds.http.RequiresHttp;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.vcloud.VCloudClient;
import org.jclouds.vcloud.config.VCloudRestClientModule;
import org.jclouds.vcloud.CommonVCloudClient;
import org.jclouds.vcloud.config.VCloudExpressRestClientModule;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.Organization;
import org.jclouds.vcloud.domain.Org;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
/**
* Configures the VCloud authentication service connection, including logging
* and http transport.
* Configures the VCloud authentication service connection, including logging and http transport.
*
* @author Adrian Cole
*/
@RequiresHttp
@ConfiguresRestClient
public class BlueLockVCloudRestClientModule extends VCloudRestClientModule {
public class BlueLockVCloudExpressRestClientModule extends VCloudExpressRestClientModule {
@Override
protected URI provideDefaultNetwork(VCloudClient client) throws InterruptedException, ExecutionException,
TimeoutException {
protected URI provideDefaultNetwork(CommonVCloudClient client) {
org.jclouds.vcloud.domain.VDC vDC = client.findVDCInOrgNamed(null, null);
Map<String, NamedResource> networks = vDC.getAvailableNetworks();
checkState(networks.size() > 0, "No networks present in vDC: " + vDC.getName());
@ -66,7 +62,7 @@ public class BlueLockVCloudRestClientModule extends VCloudRestClientModule {
}
@Override
protected URI provideCatalog(Organization org, @Named(PROPERTY_IDENTITY) final String user) {
protected URI provideCatalog(Org org, @Named(PROPERTY_IDENTITY) final String user) {
checkState(org.getCatalogs().size() > 0, "No catalogs present in org: " + org.getName());
return Iterables.getOnlyElement(Iterables.filter(org.getCatalogs().values(), new Predicate<NamedResource>() {

View File

@ -11,20 +11,20 @@
*
* 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.
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either director or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.hostingdotcom;
package org.jclouds.vcloud.bluelock;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Properties;
import org.jclouds.compute.ComputeServiceContextFactory;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.rest.RestContextFactory;
import org.jclouds.vcloud.VCloudClientLiveTest;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
@ -33,21 +33,22 @@ import com.google.common.collect.ImmutableSet;
import com.google.inject.Module;
/**
* Tests behavior of {@code HostingDotComVCloudClient}
* Tests behavior of {@code BlueLockVCloudClient}
*
* @author Adrian Cole
*/
@Test(groups = "live", sequential = true, testName = "vcloud.HostingDotComVCloudClientLiveTest")
public class HostingDotComVCloudClientLiveTest extends VCloudClientLiveTest {
@Test(groups = "live", sequential = true, testName = "bluelock.BlueLockVCloudDirectorClientLiveTest")
public class BlueLockVCloudDirectorClientLiveTest extends VCloudClientLiveTest {
@BeforeGroups(groups = { "live" })
@Override
public void setupClient() {
identity = checkNotNull(System.getProperty("jclouds.test.identity"), "jclouds.test.identity");
String credential = checkNotNull(System.getProperty("jclouds.test.credential"), "jclouds.test.credential");
context = new RestContextFactory().createContext("hostingdotcom", identity, credential, ImmutableSet
.<Module> of(new Log4JLoggingModule()), new Properties());
identity = checkNotNull(System.getProperty("bluelock-vclouddirector.identity"),
"bluelock-vclouddirector.identity");
String credential = checkNotNull(System.getProperty("bluelock-vclouddirector.credential"),
"bluelock-vclouddirector.credential");
context = new ComputeServiceContextFactory().createContext("bluelock-vclouddirector", identity, credential, ImmutableSet
.<Module> of(new Log4JLoggingModule()), new Properties()).getProviderSpecificContext();
connection = context.getApi();
}

View File

@ -23,9 +23,9 @@ import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Properties;
import org.jclouds.compute.ComputeServiceContextFactory;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.rest.RestContextFactory;
import org.jclouds.vcloud.VCloudClientLiveTest;
import org.jclouds.vcloud.VCloudExpressClientLiveTest;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
@ -38,15 +38,16 @@ import com.google.inject.Module;
* @author Adrian Cole
*/
@Test(groups = "live", sequential = true, testName = "vcloud.BlueLockVCloudClientLiveTest")
public class BlueLockVCloudClientLiveTest extends VCloudClientLiveTest {
public class BlueLockVCloudExpressClientLiveTest extends VCloudExpressClientLiveTest {
@BeforeGroups(groups = { "live" })
@Override
public void setupClient() {
identity = checkNotNull(System.getProperty("jclouds.test.identity"), "jclouds.test.identity");
String credential = checkNotNull(System.getProperty("jclouds.test.credential"), "jclouds.test.credential");
context = new RestContextFactory().createContext("bluelock", identity, credential, ImmutableSet
.<Module> of(new Log4JLoggingModule()), new Properties());
identity = checkNotNull(System.getProperty("bluelock-vcloudexpress.identity"), "bluelock-vcloudexpress.identity");
String credential = checkNotNull(System.getProperty("bluelock-vcloudexpress.credential"),
"bluelock-vcloudexpress.credential");
context = new ComputeServiceContextFactory().createContext("bluelock-vcloudexpress", identity, credential,
ImmutableSet.<Module> of(new Log4JLoggingModule()), new Properties()).getProviderSpecificContext();
connection = context.getApi();
}

View File

@ -36,13 +36,16 @@ public class ProvidersInPropertiesTest {
@Test
public void testSupportedProviders() {
Iterable<String> providers = Utils.getSupportedProviders();
assert Iterables.contains(providers, "bluelock") : providers;
assert Iterables.contains(providers, "bluelock-vcloudexpress") : providers;
assert Iterables.contains(providers, "bluelock-vclouddirector") : providers;
}
@Test
public void testSupportedComputeServiceProviders() {
Iterable<String> providers = ComputeServiceUtils.getSupportedProviders();
assert Iterables.contains(providers, "bluelock") : providers;
assert Iterables.contains(providers, "bluelock-vcloudexpress") : providers;
assert Iterables.contains(providers, "bluelock-vclouddirector") : providers;
}
}

View File

@ -53,21 +53,22 @@ public class VCloudSessionRefreshLiveTest {
@Test
public void testSessionRefresh() throws Exception {
connection.findOrganizationNamed(null);
connection.findOrgNamed(null);
Thread.sleep(timeOut * 1000);
connection.findOrganizationNamed(null);
connection.findOrgNamed(null);
}
@BeforeGroups(groups = { "live" })
public void setupClient() throws IOException {
identity = checkNotNull(System.getProperty("jclouds.test.identity"), "jclouds.test.identity");
String credential = checkNotNull(System.getProperty("jclouds.test.credential"), "jclouds.test.credential");
identity = checkNotNull(System.getProperty("bluelock-vclouddirector.identity"), "bluelock-vclouddirector.identity");
String credential = checkNotNull(System.getProperty("bluelock-vclouddirector.credential"),
"bluelock-vclouddirector.credential");
Properties props = new Properties();
props.setProperty(PROPERTY_SESSION_INTERVAL, 40 + "");
context = new ComputeServiceContextFactory().createContext("bluelock", identity, credential, ImmutableSet
.<Module> of(new Log4JLoggingModule()), props);
context = new ComputeServiceContextFactory().createContext("bluelock-vclouddirector", identity, credential,
ImmutableSet.<Module> of(new Log4JLoggingModule()), props);
connection = VCloudClient.class.cast(context.getProviderSpecificContext().getApi());
}

View File

@ -11,20 +11,22 @@
*
* 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.
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either director or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.hostingdotcom.compute;
package org.jclouds.vcloud.bluelock.compute;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.testng.Assert.assertEquals;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.domain.Template;
import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.vcloud.compute.VCloudComputeServiceLiveTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
/**
@ -32,21 +34,38 @@ import org.testng.annotations.Test;
*
* @author Adrian Cole
*/
@Test(groups = "live", enabled = true, sequential = true, testName = "compute.HostingDotComVCloudComputeServiceLiveTest")
public class HostingDotComVCloudComputeServiceLiveTest extends VCloudComputeServiceLiveTest {
@BeforeClass
@Test(groups = "live", enabled = true, sequential = true, testName = "bluelock.BlueLockVCloudComputeServiceLiveTest")
public class BlueLockVCloudDirectorComputeServiceLiveTest extends VCloudComputeServiceLiveTest {
@Override
public void setServiceDefaults() {
provider = "hostingdotcom";
provider = "bluelock-vclouddirector";
tag = "director";
}
@Override
protected void setupCredentials() {
identity = checkNotNull(System.getProperty("bluelock-vclouddirector.identity"),
"bluelock-vclouddirector.identity");
credential = checkNotNull(System.getProperty("bluelock-vclouddirector.credential"),
"bluelock-vclouddirector.credential");
}
@Test
public void testTemplateBuilder() {
Template defaultTemplate = client.templateBuilder().build();
assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true);
assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.CENTOS);
assertEquals(defaultTemplate.getLocation().getId(), "188849");
assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU);
assert defaultTemplate.getLocation().getId() != null : defaultTemplate.getLocation();
assertEquals(defaultTemplate.getSize().getCores(), 1.0d);
}
}
@Override
protected Template buildTemplate(TemplateBuilder templateBuilder) {
Template template = super.buildTemplate(templateBuilder);
Image image = template.getImage();
assert image.getDefaultCredentials().identity != null : image;
assert image.getDefaultCredentials().credential != null : image;
return template;
}
}

View File

@ -19,14 +19,14 @@
package org.jclouds.vcloud.bluelock.compute;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.testng.Assert.assertEquals;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.domain.Template;
import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.vcloud.compute.VCloudComputeServiceLiveTest;
import org.testng.annotations.BeforeClass;
import org.jclouds.vcloud.compute.VCloudExpressComputeServiceLiveTest;
import org.testng.annotations.Test;
/**
@ -34,12 +34,19 @@ import org.testng.annotations.Test;
*
* @author Adrian Cole
*/
@Test(groups = "live", enabled = true, sequential = true, testName = "compute.BlueLockVCloudComputeServiceLiveTest")
public class BlueLockVCloudComputeServiceLiveTest extends VCloudComputeServiceLiveTest {
@BeforeClass
@Test(groups = "live", enabled = true, sequential = true, testName = "bluelock.BlueLockVCloudExpressComputeServiceLiveTest")
public class BlueLockVCloudExpressComputeServiceLiveTest extends VCloudExpressComputeServiceLiveTest {
@Override
public void setServiceDefaults() {
provider = "bluelock";
provider = "bluelock-vcloudexpress";
tag = "vcx";
}
@Override
protected void setupCredentials() {
identity = checkNotNull(System.getProperty("bluelock-vcloudexpress.identity"), "bluelock-vcloudexpress.identity");
credential = checkNotNull(System.getProperty("bluelock-vcloudexpress.credential"),
"bluelock-vcloudexpress.credential");
}
@Test

View File

@ -0,0 +1,55 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package domain;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import org.jclouds.http.filters.BasicAuthentication;
import org.jclouds.rest.annotations.Endpoint;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.ResponseParser;
import org.jclouds.vcloud.VCloudExpressMediaType;
import org.jclouds.vcloud.domain.VCloudSession;
import org.jclouds.vcloud.functions.ParseLoginResponseFromHeaders;
import com.google.common.util.concurrent.ListenableFuture;
/**
* 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(org.jclouds.vcloud.endpoints.VCloudLogin.class)
@RequestFilters(BasicAuthentication.class)
public interface VCloudExpressLoginAsyncClient {
/**
* This request returns a token to use in subsequent requests. After ten minutes of inactivity,
* the token expires and you have to request a new token with this call.
*/
@POST
@ResponseParser(ParseLoginResponseFromHeaders.class)
@Consumes(VCloudExpressMediaType.ORGLIST_XML)
ListenableFuture<VCloudSession> login();
}

View File

@ -17,9 +17,7 @@
* ====================================================================
*/
package org.jclouds.vcloud.internal;
import java.util.Map;
package domain;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
@ -29,9 +27,7 @@ import org.jclouds.rest.annotations.Endpoint;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.ResponseParser;
import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.VCloudToken;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.endpoints.Org;
import org.jclouds.vcloud.domain.VCloudSession;
import org.jclouds.vcloud.functions.ParseLoginResponseFromHeaders;
import com.google.common.util.concurrent.ListenableFuture;
@ -47,14 +43,6 @@ import com.google.common.util.concurrent.ListenableFuture;
@RequestFilters(BasicAuthentication.class)
public interface VCloudLoginAsyncClient {
public interface VCloudSession {
@VCloudToken
String getVCloudToken();
@Org
Map<String, NamedResource> getOrgs();
}
/**
* This request returns a token to use in subsequent requests. After ten minutes of inactivity,
* the token expires and you have to request a new token with this call.

View File

@ -17,7 +17,7 @@
* ====================================================================
*/
package org.jclouds.vcloud.internal;
package domain;
import java.net.URI;
import java.util.SortedMap;

View File

@ -0,0 +1,332 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud;
import static org.jclouds.vcloud.VCloudMediaType.CATALOGITEM_XML;
import static org.jclouds.vcloud.VCloudMediaType.CATALOG_XML;
import static org.jclouds.vcloud.VCloudMediaType.NETWORK_XML;
import static org.jclouds.vcloud.VCloudMediaType.ORG_XML;
import static org.jclouds.vcloud.VCloudMediaType.TASKSLIST_XML;
import static org.jclouds.vcloud.VCloudMediaType.TASK_XML;
import static org.jclouds.vcloud.VCloudMediaType.VAPPTEMPLATE_XML;
import static org.jclouds.vcloud.VCloudMediaType.VAPP_XML;
import static org.jclouds.vcloud.VCloudMediaType.VDC_XML;
import java.net.URI;
import javax.annotation.Nullable;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import org.jclouds.rest.annotations.EndpointParam;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.XMLResponseParser;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.domain.CatalogItem;
import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.TasksList;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VAppTemplate;
import org.jclouds.vcloud.domain.VDC;
import org.jclouds.vcloud.domain.network.OrgNetwork;
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
import org.jclouds.vcloud.functions.OrgNameAndCatalogNameToEndpoint;
import org.jclouds.vcloud.functions.OrgNameAndVDCNameToEndpoint;
import org.jclouds.vcloud.functions.OrgNameCatalogNameItemNameToEndpoint;
import org.jclouds.vcloud.functions.OrgNameCatalogNameVAppTemplateNameToEndpoint;
import org.jclouds.vcloud.functions.OrgNameToEndpoint;
import org.jclouds.vcloud.functions.OrgNameToTasksListEndpoint;
import org.jclouds.vcloud.functions.OrgNameVDCNameResourceEntityNameToEndpoint;
import org.jclouds.vcloud.xml.CatalogHandler;
import org.jclouds.vcloud.xml.CatalogItemHandler;
import org.jclouds.vcloud.xml.OrgHandler;
import org.jclouds.vcloud.xml.OrgNetworkHandler;
import org.jclouds.vcloud.xml.TaskHandler;
import org.jclouds.vcloud.xml.TasksListHandler;
import org.jclouds.vcloud.xml.VAppHandler;
import org.jclouds.vcloud.xml.VAppTemplateHandler;
import org.jclouds.vcloud.xml.VDCHandler;
import com.google.common.util.concurrent.ListenableFuture;
/**
* Provides access to VCloud resources via their REST API.
* <p/>
*
* @see <a href="https://community.vcloudexpress.terremark.com/en-us/discussion_forums/f/60.aspx" />
* @author Adrian Cole
*/
@RequestFilters(SetVCloudTokenCookie.class)
public interface CommonVCloudAsyncClient {
/**
* @see VCloudClient#getOrg
*/
@GET
@XMLResponseParser(OrgHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@Consumes(ORG_XML)
ListenableFuture<? extends Org> getOrg(@EndpointParam URI orgId);
/**
* @see VCloudClient#getOrgNamed
*/
@GET
@XMLResponseParser(OrgHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@Consumes(ORG_XML)
ListenableFuture<? extends Org> findOrgNamed(
@Nullable @EndpointParam(parser = OrgNameToEndpoint.class) String orgName);
/**
* @see VCloudClient#getCatalog
*/
@GET
@XMLResponseParser(CatalogHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@Consumes(CATALOG_XML)
ListenableFuture<? extends Catalog> getCatalog(@EndpointParam URI catalogId);
/**
* @see VCloudClient#findCatalogInOrgNamed
*/
@GET
@XMLResponseParser(CatalogHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@Consumes(CATALOG_XML)
ListenableFuture<? extends Catalog> findCatalogInOrgNamed(
@Nullable @EndpointParam(parser = OrgNameAndCatalogNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrgNameAndCatalogNameToEndpoint.class) String catalogName);
/**
* @see VCloudClient#getVAppTemplate
*/
@GET
@Consumes(VAPPTEMPLATE_XML)
@XMLResponseParser(VAppTemplateHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends VAppTemplate> getVAppTemplate(@EndpointParam URI vAppTemplate);
/**
* @see VCloudClient#findVAppTemplateInOrgCatalogNameds
*/
@GET
@Consumes(VAPPTEMPLATE_XML)
@XMLResponseParser(VAppTemplateHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends VAppTemplate> findVAppTemplateInOrgCatalogNamed(
@Nullable @EndpointParam(parser = OrgNameCatalogNameVAppTemplateNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrgNameCatalogNameVAppTemplateNameToEndpoint.class) String catalogName,
@EndpointParam(parser = OrgNameCatalogNameVAppTemplateNameToEndpoint.class) String itemName);
/**
* @see VCloudClient#getCatalogItem
*/
@GET
@Consumes(CATALOGITEM_XML)
@XMLResponseParser(CatalogItemHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends CatalogItem> getCatalogItem(@EndpointParam URI catalogItem);
/**
* @see VCloudClient#getCatalogItemInOrg
*/
@GET
@Consumes(CATALOGITEM_XML)
@XMLResponseParser(CatalogItemHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends CatalogItem> findCatalogItemInOrgCatalogNamed(
@Nullable @EndpointParam(parser = OrgNameCatalogNameItemNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrgNameCatalogNameItemNameToEndpoint.class) String catalogName,
@EndpointParam(parser = OrgNameCatalogNameItemNameToEndpoint.class) String itemName);
/**
* @see VCloudClient#findNetworkInOrgVDCNamed
*/
@GET
@Consumes(NETWORK_XML)
@XMLResponseParser(OrgNetworkHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends OrgNetwork> findNetworkInOrgVDCNamed(
@Nullable @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String catalogName,
@EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String networkName);
/**
* @see VCloudClient#getNetwork
*/
@GET
@Consumes(NETWORK_XML)
@XMLResponseParser(OrgNetworkHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends OrgNetwork> getNetwork(@EndpointParam URI network);
/**
* @see VCloudClient#getVDC(URI)
*/
@GET
@XMLResponseParser(VDCHandler.class)
@Consumes(VDC_XML)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends VDC> getVDC(@EndpointParam URI vdc);
/**
* @see VCloudClient#findVDCInOrgNamed(String, String)
*/
@GET
@XMLResponseParser(VDCHandler.class)
@Consumes(VDC_XML)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends VDC> findVDCInOrgNamed(
@Nullable @EndpointParam(parser = OrgNameAndVDCNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrgNameAndVDCNameToEndpoint.class) String vdcName);
/**
* @see VCloudClient#getTasksList
*/
@GET
@Consumes(TASKSLIST_XML)
@XMLResponseParser(TasksListHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends TasksList> getTasksList(@EndpointParam URI tasksListId);
/**
* @see VCloudClient#findTasksListInOrgNamed
*/
@GET
@Consumes(TASKSLIST_XML)
@XMLResponseParser(TasksListHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends TasksList> findTasksListInOrgNamed(
@Nullable @EndpointParam(parser = OrgNameToTasksListEndpoint.class) String orgName);
/**
* @see VCloudClient#deployVApp
*/
@POST
@Consumes(TASK_XML)
@Path("/action/deploy")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> deployVApp(@EndpointParam URI vAppId);
/**
* @see VCloudClient#deleteVApp
*/
@DELETE
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
ListenableFuture<Void> deleteVApp(@EndpointParam URI vAppId);
/**
* @see VCloudClient#undeployVApp
*/
@POST
@Consumes(TASK_XML)
@Path("/action/undeploy")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> undeployVApp(@EndpointParam URI vAppId);
/**
* @see VCloudClient#powerOnVApp
*/
@POST
@Consumes(TASK_XML)
@Path("/power/action/powerOn")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> powerOnVApp(@EndpointParam URI vAppId);
/**
* @see VCloudClient#powerOffVApp
*/
@POST
@Consumes(TASK_XML)
@Path("/power/action/powerOff")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> powerOffVApp(@EndpointParam URI vAppId);
/**
* @see VCloudClient#shutdownVApp
*/
@POST
@Path("/power/action/shutdown")
ListenableFuture<Void> shutdownVApp(@EndpointParam URI vAppId);
/**
* @see VCloudClient#resetVApp
*/
@POST
@Consumes(TASK_XML)
@Path("/power/action/reset")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> resetVApp(@EndpointParam URI vAppId);
/**
* @see VCloudClient#suspendVApp
*/
@POST
@Consumes(TASK_XML)
@Path("/power/action/suspend")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> suspendVApp(@EndpointParam URI vAppId);
/**
* @see VCloudClient#getTask
*/
@GET
@Consumes(TASK_XML)
@XMLResponseParser(TaskHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends Task> getTask(@EndpointParam URI taskId);
/**
* @see VCloudClient#cancelTask
*/
@POST
@Path("/action/cancel")
ListenableFuture<Void> cancelTask(@EndpointParam URI taskId);
/**
* @see VCloudClient#findVAppInOrgVDCNamed
*/
@GET
@Consumes(VAPP_XML)
@XMLResponseParser(VAppHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends VApp> findVAppInOrgVDCNamed(
@Nullable @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String catalogName,
@EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String vAppName);
/**
* @see VCloudClient#getVApp
*/
@GET
@Consumes(VAPP_XML)
@XMLResponseParser(VAppHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends VApp> getVApp(@EndpointParam URI vApp);
}

View File

@ -0,0 +1,176 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud;
import java.net.URI;
import java.util.NoSuchElementException;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;
import org.jclouds.concurrent.Timeout;
import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.domain.CatalogItem;
import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.TasksList;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VAppTemplate;
import org.jclouds.vcloud.domain.VDC;
import org.jclouds.vcloud.domain.network.OrgNetwork;
/**
* Provides access to VCloud resources via their REST API.
* <p/>
*
* @see <a href="http://communities.vmware.com/community/developer/forums/vcloudapi" />
* @author Adrian Cole
*/
@Timeout(duration = 300, timeUnit = TimeUnit.SECONDS)
public interface CommonVCloudClient {
Org getOrg(URI orgId);
/**
* This call returns a list of all vCloud Data Centers (vdcs), catalogs, and task lists within
* the organization.
*
* @param name
* organization name, or null for the default
* @throws NoSuchElementException
* if you specified an org name that isn't present
*/
Org findOrgNamed(@Nullable String name);
Catalog getCatalog(URI catalogId);
/**
* returns the catalog in the organization associated with the specified name. Note that both
* parameters can be null to choose default.
*
* @param orgName
* organization name, or null for the default
* @param catalogName
* catalog name, or null for the default
* @throws NoSuchElementException
* if you specified an org or catalog name that isn't present
*/
Catalog findCatalogInOrgNamed(@Nullable String orgName, @Nullable String catalogName);
CatalogItem getCatalogItem(URI catalogItem);
/**
* returns the catalog item in the catalog associated with the specified name. Note that the org
* and catalog parameters can be null to choose default.
*
* @param orgName
* organization name, or null for the default
* @param catalogName
* catalog name, or null for the default
* @param itemName
* item you wish to lookup
*
* @throws NoSuchElementException
* if you specified an org, catalog, or catalog item name that isn't present
*/
CatalogItem findCatalogItemInOrgCatalogNamed(@Nullable String orgName, @Nullable String catalogName, String itemName);
VAppTemplate getVAppTemplate(URI vAppTemplate);
/**
* returns the vapp template corresponding to a catalog item in the catalog associated with the
* specified name. Note that the org and catalog parameters can be null to choose default.
*
* @param orgName
* organization name, or null for the default
* @param catalogName
* catalog name, or null for the default
* @param itemName
* item you wish to lookup
*
* @throws NoSuchElementException
* if you specified an org, catalog, or catalog item name that isn't present
*/
VAppTemplate findVAppTemplateInOrgCatalogNamed(@Nullable String orgName, @Nullable String catalogName,
String itemName);
OrgNetwork findNetworkInOrgVDCNamed(@Nullable String orgName, @Nullable String catalogName, String networkName);
OrgNetwork getNetwork(URI network);
VDC getVDC(URI vdc);
/**
* returns the VDC in the organization associated with the specified name. Note that both
* parameters can be null to choose default.
*
* @param orgName
* organization name, or null for the default
* @param vdcName
* catalog name, or null for the default
* @throws NoSuchElementException
* if you specified an org or vdc name that isn't present
*/
VDC findVDCInOrgNamed(String orgName, String vdcName);
TasksList getTasksList(URI tasksListId);
TasksList findTasksListInOrgNamed(String orgName);
Task deployVApp(URI vAppId);
void deleteVApp(URI vAppId);
Task undeployVApp(URI vAppId);
/**
* This call powers on the vApp, as specified in the vApp's ovf:Startup element.
*/
Task powerOnVApp(URI vAppId);
/**
* This call powers off the vApp, as specified in the vApp's ovf:Startup element.
*/
Task powerOffVApp(URI vAppId);
/**
* This call shuts down the vApp.
*/
void shutdownVApp(URI vAppId);
/**
* This call resets the vApp.
*/
Task resetVApp(URI vAppId);
/**
* This call suspends the vApp.
*/
Task suspendVApp(URI vAppId);
Task getTask(URI taskId);
void cancelTask(URI taskId);
VApp findVAppInOrgVDCNamed(@Nullable String orgName, @Nullable String catalogName, String vAppName);
VApp getVApp(URI vApp);
}

View File

@ -19,68 +19,32 @@
package org.jclouds.vcloud;
import static org.jclouds.vcloud.VCloudMediaType.CATALOGITEM_XML;
import static org.jclouds.vcloud.VCloudMediaType.CATALOG_XML;
import static org.jclouds.vcloud.VCloudMediaType.NETWORK_XML;
import static org.jclouds.vcloud.VCloudMediaType.ORG_XML;
import static org.jclouds.vcloud.VCloudMediaType.TASKSLIST_XML;
import static org.jclouds.vcloud.VCloudMediaType.TASK_XML;
import static org.jclouds.vcloud.VCloudMediaType.VAPPTEMPLATE_XML;
import static org.jclouds.vcloud.VCloudMediaType.VAPP_XML;
import static org.jclouds.vcloud.VCloudMediaType.VDC_XML;
import java.net.URI;
import javax.annotation.Nullable;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import org.jclouds.predicates.validators.DnsNameValidator;
import org.jclouds.rest.annotations.Endpoint;
import org.jclouds.rest.annotations.EndpointParam;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.MapBinder;
import org.jclouds.rest.annotations.MapPayloadParam;
import org.jclouds.rest.annotations.ParamValidators;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.XMLResponseParser;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import org.jclouds.vcloud.binders.BindCloneVAppParamsToXmlPayload;
import org.jclouds.vcloud.binders.BindInstantiateVAppTemplateParamsToXmlPayload;
import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.domain.CatalogItem;
import org.jclouds.vcloud.domain.Network;
import org.jclouds.vcloud.domain.Organization;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.TasksList;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VAppTemplate;
import org.jclouds.vcloud.domain.VDC;
import org.jclouds.vcloud.endpoints.Org;
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
import org.jclouds.vcloud.functions.OrgNameAndCatalogNameToEndpoint;
import org.jclouds.vcloud.functions.OrgNameAndTasksListNameToEndpoint;
import org.jclouds.vcloud.functions.OrgNameAndVDCNameToEndpoint;
import org.jclouds.vcloud.functions.OrgNameCatalogNameItemNameToEndpoint;
import org.jclouds.vcloud.functions.OrgNameCatalogNameVAppTemplateNameToEndpoint;
import org.jclouds.vcloud.functions.OrgNameToEndpoint;
import org.jclouds.vcloud.functions.OrgNameVDCNameResourceEntityNameToEndpoint;
import org.jclouds.vcloud.options.CloneVAppOptions;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import org.jclouds.vcloud.xml.CatalogHandler;
import org.jclouds.vcloud.xml.CatalogItemHandler;
import org.jclouds.vcloud.xml.NetworkHandler;
import org.jclouds.vcloud.xml.OrgHandler;
import org.jclouds.vcloud.xml.TaskHandler;
import org.jclouds.vcloud.xml.TasksListHandler;
import org.jclouds.vcloud.xml.VAppHandler;
import org.jclouds.vcloud.xml.VAppTemplateHandler;
import org.jclouds.vcloud.xml.VDCHandler;
import com.google.common.util.concurrent.ListenableFuture;
@ -88,298 +52,11 @@ import com.google.common.util.concurrent.ListenableFuture;
* Provides access to VCloud resources via their REST API.
* <p/>
*
* @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
*/
@RequestFilters(SetVCloudTokenCookie.class)
public interface VCloudAsyncClient {
/**
* @see VCloudClient#getDefaultOrganization
*/
@Deprecated
@GET
@Endpoint(Org.class)
@Consumes(ORG_XML)
@XMLResponseParser(OrgHandler.class)
ListenableFuture<? extends Organization> getDefaultOrganization();
/**
* @see VCloudClient#getOrganization
*/
@GET
@XMLResponseParser(OrgHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@Consumes(ORG_XML)
ListenableFuture<? extends Organization> getOrganization(@EndpointParam URI orgId);
/**
* @see VCloudClient#getOrganizationNamed
*/
@GET
@XMLResponseParser(OrgHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@Consumes(ORG_XML)
ListenableFuture<? extends Organization> findOrganizationNamed(
@Nullable @EndpointParam(parser = OrgNameToEndpoint.class) String orgName);
/**
* @see VCloudClient#getDefaultCatalog
*/
@Deprecated
@GET
@Endpoint(org.jclouds.vcloud.endpoints.Catalog.class)
@Consumes(CATALOG_XML)
@XMLResponseParser(CatalogHandler.class)
ListenableFuture<? extends Catalog> getDefaultCatalog();
/**
* @see VCloudClient#getCatalog
*/
@GET
@XMLResponseParser(CatalogHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@Consumes(CATALOG_XML)
ListenableFuture<? extends Catalog> getCatalog(@EndpointParam URI catalogId);
/**
* @see VCloudClient#findCatalogInOrgNamed
*/
@GET
@XMLResponseParser(CatalogHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@Consumes(CATALOG_XML)
ListenableFuture<? extends Catalog> findCatalogInOrgNamed(
@Nullable @EndpointParam(parser = OrgNameAndCatalogNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrgNameAndCatalogNameToEndpoint.class) String catalogName);
/**
* @see VCloudClient#getVAppTemplate
*/
@GET
@Consumes(VAPPTEMPLATE_XML)
@XMLResponseParser(VAppTemplateHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends VAppTemplate> getVAppTemplate(@EndpointParam URI vAppTemplate);
/**
* @see VCloudClient#findVAppTemplateInOrgCatalogNameds
*/
@GET
@Consumes(VAPPTEMPLATE_XML)
@XMLResponseParser(VAppTemplateHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends VAppTemplate> findVAppTemplateInOrgCatalogNamed(
@Nullable @EndpointParam(parser = OrgNameCatalogNameVAppTemplateNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrgNameCatalogNameVAppTemplateNameToEndpoint.class) String catalogName,
@EndpointParam(parser = OrgNameCatalogNameVAppTemplateNameToEndpoint.class) String itemName);
/**
* @see VCloudClient#getCatalogItem
*/
@GET
@Consumes(CATALOGITEM_XML)
@XMLResponseParser(CatalogItemHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends CatalogItem> getCatalogItem(@EndpointParam URI catalogItem);
/**
* @see VCloudClient#getCatalogItemInOrg
*/
@GET
@Consumes(CATALOGITEM_XML)
@XMLResponseParser(CatalogItemHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends CatalogItem> findCatalogItemInOrgCatalogNamed(
@Nullable @EndpointParam(parser = OrgNameCatalogNameItemNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrgNameCatalogNameItemNameToEndpoint.class) String catalogName,
@EndpointParam(parser = OrgNameCatalogNameItemNameToEndpoint.class) String itemName);
/**
* @see VCloudClient#findNetworkInOrgVDCNamed
*/
@GET
@Consumes(NETWORK_XML)
@XMLResponseParser(NetworkHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends Network> findNetworkInOrgVDCNamed(
@Nullable @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String catalogName,
@EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String networkName);
/**
* @see VCloudClient#getNetwork
*/
@GET
@Consumes(NETWORK_XML)
@XMLResponseParser(NetworkHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends Network> getNetwork(@EndpointParam URI network);
/**
* @see VCloudClient#getDefaultVDC
*/
@Deprecated
@GET
@Endpoint(org.jclouds.vcloud.endpoints.VDC.class)
@XMLResponseParser(VDCHandler.class)
@Consumes(VDC_XML)
ListenableFuture<? extends VDC> getDefaultVDC();
/**
* @see VCloudClient#getVDC(URI)
*/
@GET
@XMLResponseParser(VDCHandler.class)
@Consumes(VDC_XML)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends VDC> getVDC(@EndpointParam URI vdc);
/**
* @see VCloudClient#findVDCInOrgNamed(String, String)
*/
@GET
@XMLResponseParser(VDCHandler.class)
@Consumes(VDC_XML)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends VDC> findVDCInOrgNamed(
@Nullable @EndpointParam(parser = OrgNameAndVDCNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrgNameAndVDCNameToEndpoint.class) String vdcName);
/**
* @see VCloudClient#getTasksList
*/
@GET
@Consumes(TASKSLIST_XML)
@XMLResponseParser(TasksListHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends TasksList> getTasksList(@EndpointParam URI tasksListId);
/**
* @see VCloudClient#getTasksListInOrg
*/
@GET
@Consumes(TASKSLIST_XML)
@XMLResponseParser(TasksListHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends TasksList> findTasksListInOrgNamed(
@Nullable @EndpointParam(parser = OrgNameAndTasksListNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrgNameAndTasksListNameToEndpoint.class) String tasksListName);
/**
* @see VCloudClient#getDefaultTasksList
*/
@Deprecated
@GET
@Endpoint(org.jclouds.vcloud.endpoints.TasksList.class)
@Consumes(TASKSLIST_XML)
@XMLResponseParser(TasksListHandler.class)
ListenableFuture<? extends TasksList> getDefaultTasksList();
/**
* @see VCloudClient#deployVApp
*/
@POST
@Consumes(TASK_XML)
@Path("/action/deploy")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> deployVApp(@EndpointParam URI vAppId);
/**
* @see VCloudClient#deleteVApp
*/
@DELETE
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
ListenableFuture<Void> deleteVApp(@EndpointParam URI vAppId);
/**
* @see VCloudClient#undeployVApp
*/
@POST
@Consumes(TASK_XML)
@Path("/action/undeploy")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> undeployVApp(@EndpointParam URI vAppId);
/**
* @see VCloudClient#powerOnVApp
*/
@POST
@Consumes(TASK_XML)
@Path("/power/action/powerOn")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> powerOnVApp(@EndpointParam URI vAppId);
/**
* @see VCloudClient#powerOffVApp
*/
@POST
@Consumes(TASK_XML)
@Path("/power/action/powerOff")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> powerOffVApp(@EndpointParam URI vAppId);
/**
* @see VCloudClient#shutdownVApp
*/
@POST
@Path("/power/action/shutdown")
ListenableFuture<Void> shutdownVApp(@EndpointParam URI vAppId);
/**
* @see VCloudClient#resetVApp
*/
@POST
@Consumes(TASK_XML)
@Path("/power/action/reset")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> resetVApp(@EndpointParam URI vAppId);
/**
* @see VCloudClient#suspendVApp
*/
@POST
@Consumes(TASK_XML)
@Path("/power/action/suspend")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> suspendVApp(@EndpointParam URI vAppId);
/**
* @see VCloudClient#getTask
*/
@GET
@Consumes(TASK_XML)
@XMLResponseParser(TaskHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends Task> getTask(@EndpointParam URI taskId);
/**
* @see VCloudClient#cancelTask
*/
@POST
@Path("/action/cancel")
ListenableFuture<Void> cancelTask(@EndpointParam URI taskId);
/**
* @see VCloudClient#findVAppInOrgVDCNamed
*/
@GET
@Consumes(VAPP_XML)
@XMLResponseParser(VAppHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends VApp> findVAppInOrgVDCNamed(
@Nullable @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String catalogName,
@EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String vAppName);
/**
* @see VCloudClient#getVApp
*/
@GET
@Consumes(VAPP_XML)
@XMLResponseParser(VAppHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends VApp> getVApp(@EndpointParam URI vApp);
public interface VCloudAsyncClient extends CommonVCloudAsyncClient {
/**
* @see VCloudClient#instantiateVAppTemplateInVDC
@ -391,9 +68,9 @@ public interface VCloudAsyncClient {
@XMLResponseParser(VAppHandler.class)
@MapBinder(BindInstantiateVAppTemplateParamsToXmlPayload.class)
ListenableFuture<? extends VApp> instantiateVAppTemplateInVDC(@EndpointParam URI vdc,
@MapPayloadParam("template") URI template,
@MapPayloadParam("name") @ParamValidators(DnsNameValidator.class) String appName,
InstantiateVAppTemplateOptions... options);
@MapPayloadParam("template") URI template,
@MapPayloadParam("name") @ParamValidators(DnsNameValidator.class) String appName,
InstantiateVAppTemplateOptions... options);
/**
* @see VCloudClient#cloneVAppInVDC
@ -405,7 +82,7 @@ public interface VCloudAsyncClient {
@XMLResponseParser(TaskHandler.class)
@MapBinder(BindCloneVAppParamsToXmlPayload.class)
ListenableFuture<? extends Task> cloneVAppInVDC(@EndpointParam URI vdc, @MapPayloadParam("vApp") URI toClone,
@MapPayloadParam("newName") @ParamValidators(DnsNameValidator.class) String newName,
CloneVAppOptions... options);
@MapPayloadParam("newName") @ParamValidators(DnsNameValidator.class) String newName,
CloneVAppOptions... options);
}

View File

@ -20,21 +20,11 @@
package org.jclouds.vcloud;
import java.net.URI;
import java.util.NoSuchElementException;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;
import org.jclouds.concurrent.Timeout;
import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.domain.CatalogItem;
import org.jclouds.vcloud.domain.Network;
import org.jclouds.vcloud.domain.Organization;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.TasksList;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VAppTemplate;
import org.jclouds.vcloud.domain.VDC;
import org.jclouds.vcloud.options.CloneVAppOptions;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
@ -42,169 +32,14 @@ import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
* Provides access to VCloud resources via their REST API.
* <p/>
*
* @see <a href="https://community.vcloudexpress.terremark.com/en-us/discussion_forums/f/60.aspx"
* @see <a
* href="http://communities.vmware.com/community/developer/forums/vcloudapi"
* />
* @author Adrian Cole
*/
@Timeout(duration = 300, timeUnit = TimeUnit.SECONDS)
public interface VCloudClient {
public interface VCloudClient extends CommonVCloudClient {
/**
* Please use {@link #findOrganizationNamed(String)} passing null
*/
@Deprecated
Organization getDefaultOrganization();
Organization getOrganization(URI orgId);
/**
* This call returns a list of all vCloud Data Centers (vdcs), catalogs, and
* task lists within the organization.
*
* @param name
* organization name, or null for the default
* @throws NoSuchElementException
* if you specified an org name that isn't present
*/
Organization findOrganizationNamed(@Nullable String name);
/**
* Please use #findCatalogInOrgNamed(null, null)
*/
@Deprecated
Catalog getDefaultCatalog();
Catalog getCatalog(URI catalogId);
/**
* returns the catalog in the organization associated with the specified
* name. Note that both parameters can be null to choose default.
*
* @param orgName
* organization name, or null for the default
* @param catalogName
* catalog name, or null for the default
* @throws NoSuchElementException
* if you specified an org or catalog name that isn't present
*/
Catalog findCatalogInOrgNamed(@Nullable String orgName, @Nullable String catalogName);
CatalogItem getCatalogItem(URI catalogItem);
/**
* returns the catalog item in the catalog associated with the specified
* name. Note that the org and catalog parameters can be null to choose
* default.
*
* @param orgName
* organization name, or null for the default
* @param catalogName
* catalog name, or null for the default
* @param itemName
* item you wish to lookup
*
* @throws NoSuchElementException
* if you specified an org, catalog, or catalog item name that
* isn't present
*/
CatalogItem findCatalogItemInOrgCatalogNamed(@Nullable String orgName, @Nullable String catalogName, String itemName);
VAppTemplate getVAppTemplate(URI vAppTemplate);
/**
* returns the vapp template corresponding to a catalog item in the catalog
* associated with the specified name. Note that the org and catalog
* parameters can be null to choose default.
*
* @param orgName
* organization name, or null for the default
* @param catalogName
* catalog name, or null for the default
* @param itemName
* item you wish to lookup
*
* @throws NoSuchElementException
* if you specified an org, catalog, or catalog item name that
* isn't present
*/
VAppTemplate findVAppTemplateInOrgCatalogNamed(@Nullable String orgName, @Nullable String catalogName,
String itemName);
Network findNetworkInOrgVDCNamed(@Nullable String orgName, @Nullable String catalogName, String networkName);
Network getNetwork(URI network);
VDC getVDC(URI vdc);
/**
* returns the VDC in the organization associated with the specified name.
* Note that both parameters can be null to choose default.
*
* @param orgName
* organization name, or null for the default
* @param vdcName
* catalog name, or null for the default
* @throws NoSuchElementException
* if you specified an org or vdc name that isn't present
*/
VDC findVDCInOrgNamed(String orgName, String vdcName);
/**
* Please use #findVDCInOrgNamed
*/
@Deprecated
VDC getDefaultVDC();
TasksList getTasksList(URI tasksListId);
TasksList findTasksListInOrgNamed(String orgName, String tasksListName);
/**
* Please use #getTasksListInOrg(null, null)
*/
@Deprecated
TasksList getDefaultTasksList();
Task deployVApp(URI vAppId);
void deleteVApp(URI vAppId);
Task undeployVApp(URI vAppId);
/**
* This call powers on the vApp, as specified in the vApp's ovf:Startup
* element.
*/
Task powerOnVApp(URI vAppId);
/**
* This call powers off the vApp, as specified in the vApp's ovf:Startup
* element.
*/
Task powerOffVApp(URI vAppId);
/**
* This call shuts down the vApp.
*/
void shutdownVApp(URI vAppId);
/**
* This call resets the vApp.
*/
Task resetVApp(URI vAppId);
/**
* This call suspends the vApp.
*/
Task suspendVApp(URI vAppId);
Task getTask(URI taskId);
void cancelTask(URI taskId);
VApp findVAppInOrgVDCNamed(@Nullable String orgName, @Nullable String catalogName, String vAppName);
VApp getVApp(URI vApp);
VApp instantiateVAppTemplateInVDC(URI vDC, URI template, String appName, InstantiateVAppTemplateOptions... options);

View File

@ -48,8 +48,7 @@ import com.google.inject.TypeLiteral;
* @author Adrian Cole
* @see VCloudComputeServiceContext
*/
public class VCloudContextBuilder extends
ComputeServiceContextBuilder<VCloudClient, VCloudAsyncClient> {
public class VCloudContextBuilder extends ComputeServiceContextBuilder<VCloudClient, VCloudAsyncClient> {
public VCloudContextBuilder(Properties props) {
super(VCloudClient.class, VCloudAsyncClient.class, props);
@ -68,11 +67,8 @@ public class VCloudContextBuilder extends
@Override
public ComputeServiceContext buildComputeServiceContext() {
// need the generic type information
return (ComputeServiceContext) this
.buildInjector()
.getInstance(
Key
.get(new TypeLiteral<ComputeServiceContextImpl<VCloudClient, VCloudAsyncClient>>() {
}));
return (ComputeServiceContext) this.buildInjector().getInstance(
Key.get(new TypeLiteral<ComputeServiceContextImpl<VCloudClient, VCloudAsyncClient>>() {
}));
}
}

View File

@ -0,0 +1,118 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud;
import static org.jclouds.vcloud.VCloudMediaType.NETWORK_XML;
import static org.jclouds.vcloud.VCloudMediaType.TASK_XML;
import static org.jclouds.vcloud.VCloudMediaType.VAPP_XML;
import java.net.URI;
import javax.annotation.Nullable;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import org.jclouds.predicates.validators.DnsNameValidator;
import org.jclouds.rest.annotations.EndpointParam;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.MapBinder;
import org.jclouds.rest.annotations.MapPayloadParam;
import org.jclouds.rest.annotations.ParamValidators;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.XMLResponseParser;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.vcloud.binders.BindCloneVAppParamsToXmlPayload;
import org.jclouds.vcloud.binders.BindInstantiateVAppTemplateParamsToXmlPayload;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.network.OrgNetwork;
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
import org.jclouds.vcloud.functions.OrgNameVDCNameResourceEntityNameToEndpoint;
import org.jclouds.vcloud.options.CloneVAppOptions;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import org.jclouds.vcloud.xml.OrgNetworkFromVCloudExpressNetworkHandler;
import org.jclouds.vcloud.xml.TaskHandler;
import org.jclouds.vcloud.xml.VAppHandler;
import com.google.common.util.concurrent.ListenableFuture;
/**
* Provides access to VCloud resources via their REST API.
* <p/>
*
* @see <a href="https://community.vcloudexpress.terremark.com/en-us/discussion_forums/f/60.aspx" />
* @author Adrian Cole
*/
@RequestFilters(SetVCloudTokenCookie.class)
public interface VCloudExpressAsyncClient extends CommonVCloudAsyncClient {
/**
* @see VCloudClient#findNetworkInOrgVDCNamed
*/
@Override
@GET
@Consumes(NETWORK_XML)
@XMLResponseParser(OrgNetworkFromVCloudExpressNetworkHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends OrgNetwork> findNetworkInOrgVDCNamed(
@Nullable @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String catalogName,
@EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String networkName);
/**
* @see VCloudClient#getNetwork
*/
@Override
@GET
@Consumes(NETWORK_XML)
@XMLResponseParser(OrgNetworkFromVCloudExpressNetworkHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends OrgNetwork> getNetwork(@EndpointParam URI network);
/**
* @see VCloudExpressClient#instantiateVAppTemplateInVDC
*/
@POST
@Path("action/instantiateVAppTemplate")
@Produces("application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml")
@Consumes(VAPP_XML)
@XMLResponseParser(VAppHandler.class)
@MapBinder(BindInstantiateVAppTemplateParamsToXmlPayload.class)
ListenableFuture<? extends VApp> instantiateVAppTemplateInVDC(@EndpointParam URI vdc,
@MapPayloadParam("template") URI template,
@MapPayloadParam("name") @ParamValidators(DnsNameValidator.class) String appName,
InstantiateVAppTemplateOptions... options);
/**
* @see VCloudExpressClient#cloneVAppInVDC
*/
@POST
@Path("/action/cloneVApp")
@Produces("application/vnd.vmware.vcloud.cloneVAppParams+xml")
@Consumes(TASK_XML)
@XMLResponseParser(TaskHandler.class)
@MapBinder(BindCloneVAppParamsToXmlPayload.class)
ListenableFuture<? extends Task> cloneVAppInVDC(@EndpointParam URI vdc, @MapPayloadParam("vApp") URI toClone,
@MapPayloadParam("newName") @ParamValidators(DnsNameValidator.class) String newName,
CloneVAppOptions... options);
}

View File

@ -17,34 +17,29 @@
* ====================================================================
*/
package org.jclouds.vcloud.hostingdotcom;
package org.jclouds.vcloud;
import java.net.URI;
import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout;
import org.jclouds.vcloud.VCloudClient;
import org.jclouds.vcloud.hostingdotcom.domain.HostingDotComVApp;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.options.CloneVAppOptions;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
/**
* Provides access to VCloud resources via their REST API.
* <p/>
*
* @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
*/
@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS)
public interface HostingDotComVCloudClient extends VCloudClient {
@Timeout(duration = 300, timeUnit = TimeUnit.SECONDS)
public interface VCloudExpressClient extends CommonVCloudClient {
@Override
@Timeout(duration = 600, timeUnit = TimeUnit.SECONDS)
HostingDotComVApp instantiateVAppTemplateInVDC(URI vDC, URI template, String appName,
InstantiateVAppTemplateOptions... options);
VApp instantiateVAppTemplateInVDC(URI vDC, URI template, String appName, InstantiateVAppTemplateOptions... options);
@Override
@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS)
HostingDotComVApp getVApp(URI vAppId);
Task cloneVAppInVDC(URI vDC, URI toClone, String newName, CloneVAppOptions... options);
}

View File

@ -0,0 +1,74 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud;
import java.util.List;
import java.util.Properties;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.ComputeServiceContextBuilder;
import org.jclouds.compute.internal.ComputeServiceContextImpl;
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
import org.jclouds.logging.jdk.config.JDKLoggingModule;
import org.jclouds.vcloud.compute.config.VCloudExpressComputeServiceContextModule;
import org.jclouds.vcloud.config.VCloudExpressRestClientModule;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.Module;
import com.google.inject.TypeLiteral;
/**
* Creates {@link VCloudComputeServiceContext} or {@link Injector} instances based on the most
* commonly requested arguments.
* <p/>
* Note that Threadsafe objects will be bound as singletons to the Injector or Context provided.
* <p/>
* <p/>
* If no <code>Module</code>s are specified, the default {@link JDKLoggingModule logging} and
* {@link JavaUrlHttpCommandExecutorServiceModule http transports} will be installed.
*
* @author Adrian Cole
* @see VCloudComputeServiceContext
*/
public class VCloudExpressContextBuilder extends ComputeServiceContextBuilder<VCloudExpressClient, VCloudExpressAsyncClient> {
public VCloudExpressContextBuilder(Properties props) {
super(VCloudExpressClient.class, VCloudExpressAsyncClient.class, props);
}
@Override
protected void addContextModule(List<Module> modules) {
modules.add(new VCloudExpressComputeServiceContextModule());
}
@Override
protected void addClientModule(List<Module> modules) {
modules.add(new VCloudExpressRestClientModule());
}
@Override
public ComputeServiceContext buildComputeServiceContext() {
// need the generic type information
return (ComputeServiceContext) this.buildInjector().getInstance(
Key.get(new TypeLiteral<ComputeServiceContextImpl<VCloudExpressClient, VCloudExpressAsyncClient>>() {
}));
}
}

View File

@ -0,0 +1,42 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud;
import javax.ws.rs.core.MediaType;
/**
* Resource Types used in VCloud express
*
* @see MediaType
*/
public interface VCloudExpressMediaType extends VCloudMediaType {
/**
* "application/vnd.vmware.vcloud.organizationList+xml"
*/
public final static String ORGLIST_XML = "application/vnd.vmware.vcloud.organizationList+xml";
/**
* "application/vnd.vmware.vcloud.organizationList+xml"
*/
public final static MediaType ORGLIST_XML_TYPE = new MediaType("application",
"vnd.vmware.vcloud.organizationList+xml");
}

View File

@ -0,0 +1,90 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud;
import static org.jclouds.Constants.PROPERTY_API_VERSION;
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_FENCEMODE;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_VERSION_SCHEMA;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_SCHEMA;
import java.util.Properties;
import org.jclouds.PropertiesBuilder;
import org.jclouds.vcloud.domain.network.FenceMode;
/**
* Builds properties used in VCloud Clients
*
* @author Adrian Cole
*/
public class VCloudExpressPropertiesBuilder extends PropertiesBuilder {
@Override
protected Properties defaultProperties() {
Properties properties = super.defaultProperties();
properties.setProperty(PROPERTY_API_VERSION, "0.8");
properties.setProperty(PROPERTY_VCLOUD_VERSION_SCHEMA, "0.8");
properties.setProperty(PROPERTY_SESSION_INTERVAL, 8 * 60 + "");
properties.setProperty(PROPERTY_VCLOUD_XML_SCHEMA,
"http://vcloud.safesecureweb.com/ns/vcloud.xsd");
properties.setProperty("jclouds.dns_name_length_min", "1");
properties.setProperty("jclouds.dns_name_length_max", "80");
properties.setProperty(PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED, 180l * 1000l + "");
return properties;
}
public VCloudExpressPropertiesBuilder(Properties properties) {
super(properties);
}
protected void setNs() {
if (properties.getProperty(PROPERTY_VCLOUD_XML_NAMESPACE) == null)
properties.setProperty(PROPERTY_VCLOUD_XML_NAMESPACE, "http://www.vmware.com/vcloud/v"
+ properties.getProperty(PROPERTY_VCLOUD_VERSION_SCHEMA));
}
protected void setFenceMode() {
if (properties.getProperty(PROPERTY_VCLOUD_DEFAULT_FENCEMODE) == null) {
if (properties.getProperty(PROPERTY_VCLOUD_VERSION_SCHEMA).startsWith("0.8"))
properties.setProperty(PROPERTY_VCLOUD_DEFAULT_FENCEMODE, "allowInOut");
else
properties.setProperty(PROPERTY_VCLOUD_DEFAULT_FENCEMODE, FenceMode.BRIDGED.toString());
}
}
public VCloudExpressPropertiesBuilder withApiVersion(String version) {
properties.setProperty(PROPERTY_API_VERSION, "0.8");
return this;
}
public VCloudExpressPropertiesBuilder withSchemaVersion(String version) {
properties.setProperty(PROPERTY_VCLOUD_VERSION_SCHEMA, "0.8");
return this;
}
@Override
public Properties build() {
setNs();
setFenceMode();
return super.build();
}
}

View File

@ -22,31 +22,29 @@ package org.jclouds.vcloud;
import javax.ws.rs.core.MediaType;
/**
* Resource Types used in VCloud express
* Resource Types used in VCloud
*
* @see MediaType
*/
public interface VCloudMediaType {
/**
* "application/vnd.vmware.vcloud.organizationList+xml"
* "application/vnd.vmware.vcloud.vcloud+xml"
*/
public final static String VCLOUD_XML = "application/vnd.vmware.vcloud.vcloud+xml";
/**
* "application/vnd.vmware.vcloud.organizationList+xml"
* "application/vnd.vmware.vcloud.vcloud+xml"
*/
public final static MediaType VCLOUD_XML_TYPE = new MediaType("application",
"vnd.vmware.vcloud.vcloud+xml");
public final static MediaType VCLOUD_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.vcloud+xml");
/**
* "application/vnd.vmware.vcloud.organizationList+xml"
* "application/vnd.vmware.vcloud.orgList+xml"
*/
public final static String ORGLIST_XML = "application/vnd.vmware.vcloud.organizationList+xml";
public final static String ORGLIST_XML = "application/vnd.vmware.vcloud.orgList+xml";
/**
* "application/vnd.vmware.vcloud.organizationList+xml"
* "application/vnd.vmware.vcloud.orgList+xml"
*/
public final static MediaType ORGLIST_XML_TYPE = new MediaType("application",
"vnd.vmware.vcloud.organizationList+xml");
public final static MediaType ORGLIST_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.orgList+xml");
/**
* "application/vnd.vmware.vcloud.org+xml"
*/
@ -54,8 +52,7 @@ public interface VCloudMediaType {
/**
* "application/vnd.vmware.vcloud.org+xml"
*/
public final static MediaType ORG_XML_TYPE = new MediaType("application",
"vnd.vmware.vcloud.org+xml");
public final static MediaType ORG_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.org+xml");
/**
* "application/vnd.vmware.vcloud.vdc+xml"
@ -64,8 +61,7 @@ public interface VCloudMediaType {
/**
* "application/vnd.vmware.vcloud.vdc+xml"
*/
public final static MediaType VDC_XML_TYPE = new MediaType("application",
"vnd.vmware.vcloud.vdc+xml");
public final static MediaType VDC_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.vdc+xml");
/**
* "application/vnd.vmware.vcloud.catalog+xml"
@ -74,8 +70,7 @@ public interface VCloudMediaType {
/**
* "application/vnd.vmware.vcloud.catalog+xml"
*/
public final static MediaType CATALOG_XML_TYPE = new MediaType("application",
"vnd.vmware.vcloud.catalog+xml");
public final static MediaType CATALOG_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.catalog+xml");
/**
* "application/vnd.vmware.vcloud.tasksList+xml"
@ -84,8 +79,7 @@ public interface VCloudMediaType {
/**
* "application/vnd.vmware.vcloud.tasksList+xml"
*/
public final static MediaType TASKSLIST_XML_TYPE = new MediaType("application",
"vnd.vmware.vcloud.tasksList+xml");
public final static MediaType TASKSLIST_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.tasksList+xml");
/**
* "application/vnd.vmware.vcloud.catalogItem+xml"
@ -104,8 +98,7 @@ public interface VCloudMediaType {
/**
* "application/vnd.vmware.vcloud.task+xml"
*/
public final static MediaType TASK_XML_TYPE = new MediaType("application",
"vnd.vmware.vcloud.task+xml");
public final static MediaType TASK_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.task+xml");
/**
* "application/vnd.vmware.vcloud.vApp+xml"
@ -114,8 +107,7 @@ public interface VCloudMediaType {
/**
* "application/vnd.vmware.vcloud.vApp+xml"
*/
public final static MediaType VAPP_XML_TYPE = new MediaType("application",
"vnd.vmware.vcloud.vApp+xml");
public final static MediaType VAPP_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.vApp+xml");
/**
* "application/vnd.vmware.vcloud.vAppTemplate+xml"
@ -134,7 +126,6 @@ public interface VCloudMediaType {
/**
* "application/vnd.vmware.vcloud.network+xml"
*/
public final static MediaType NETWORK_XML_TYPE = new MediaType("application",
"vnd.vmware.vcloud.network+xml");
public final static MediaType NETWORK_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.network+xml");
}

View File

@ -30,7 +30,7 @@ import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_S
import java.util.Properties;
import org.jclouds.PropertiesBuilder;
import org.jclouds.vcloud.domain.FenceMode;
import org.jclouds.vcloud.domain.network.FenceMode;
/**
* Builds properties used in VCloud Clients
@ -41,13 +41,13 @@ public class VCloudPropertiesBuilder extends PropertiesBuilder {
@Override
protected Properties defaultProperties() {
Properties properties = super.defaultProperties();
properties.setProperty(PROPERTY_API_VERSION, "0.8");
properties.setProperty(PROPERTY_VCLOUD_VERSION_SCHEMA, "0.8");
properties.setProperty(PROPERTY_API_VERSION, "1.0");
properties.setProperty(PROPERTY_VCLOUD_VERSION_SCHEMA, "1.0");
properties.setProperty(PROPERTY_SESSION_INTERVAL, 8 * 60 + "");
properties.setProperty(PROPERTY_VCLOUD_XML_SCHEMA,
"http://vcloud.safesecureweb.com/ns/vcloud.xsd");
properties.setProperty(PROPERTY_VCLOUD_XML_SCHEMA, "http://vcloud.safesecureweb.com/ns/vcloud.xsd");
properties.setProperty("jclouds.dns_name_length_min", "1");
properties.setProperty("jclouds.dns_name_length_max", "80");
properties.setProperty(PROPERTY_VCLOUD_DEFAULT_FENCEMODE, FenceMode.BRIDGED.toString());
properties.setProperty(PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED, 180l * 1000l + "");
return properties;
}
@ -62,29 +62,19 @@ public class VCloudPropertiesBuilder extends PropertiesBuilder {
+ properties.getProperty(PROPERTY_VCLOUD_VERSION_SCHEMA));
}
protected void setFenceMode() {
if (properties.getProperty(PROPERTY_VCLOUD_DEFAULT_FENCEMODE) == null) {
if (properties.getProperty(PROPERTY_VCLOUD_VERSION_SCHEMA).startsWith("0.8"))
properties.setProperty(PROPERTY_VCLOUD_DEFAULT_FENCEMODE, "allowInOut");
else
properties.setProperty(PROPERTY_VCLOUD_DEFAULT_FENCEMODE, FenceMode.BRIDGED);
}
}
public VCloudPropertiesBuilder withApiVersion(String version) {
properties.setProperty(PROPERTY_API_VERSION, "0.8");
properties.setProperty(PROPERTY_API_VERSION, "1.0");
return this;
}
public VCloudPropertiesBuilder withSchemaVersion(String version) {
properties.setProperty(PROPERTY_VCLOUD_VERSION_SCHEMA, "0.8");
properties.setProperty(PROPERTY_VCLOUD_VERSION_SCHEMA, "1.0");
return this;
}
@Override
public Properties build() {
setNs();
setFenceMode();
return super.build();
}
}

View File

@ -38,7 +38,7 @@ import org.jclouds.http.HttpRequest;
import org.jclouds.rest.MapBinder;
import org.jclouds.rest.binders.BindToStringPayload;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.VCloudExpressMediaType;
import org.jclouds.vcloud.options.CloneVAppOptions;
import com.google.inject.Inject;
@ -95,7 +95,7 @@ public class BindCloneVAppParamsToXmlPayload implements MapBinder {
XMLBuilder rootBuilder = buildRoot(newName, options.isDeploy(), options.isPowerOn());
if (options.getDescription() != null)
rootBuilder.e("Description").text(options.getDescription());
rootBuilder.e("VApp").a("href", vApp).a("type", VCloudMediaType.VAPP_XML);
rootBuilder.e("VApp").a("href", vApp).a("type", VCloudExpressMediaType.VAPP_XML);
Properties outputProperties = new Properties();
outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
return rootBuilder.asString(outputProperties);

View File

@ -22,6 +22,7 @@ package org.jclouds.vcloud.binders;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static org.jclouds.Constants.PROPERTY_API_VERSION;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_FENCEMODE;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_NETWORK;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE;
@ -63,21 +64,19 @@ public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder
protected final String ns;
protected final String schema;
private final BindToStringPayload stringBinder;
protected final Map<ResourceType, String> virtualHardwareToInstanceId = ImmutableMap
.of(ResourceType.PROCESSOR, "1", ResourceType.MEMORY, "2",
ResourceType.DISK_DRIVE, "9");
protected final Map<ResourceType, String> virtualHardwareToInstanceId = ImmutableMap.of(ResourceType.PROCESSOR, "1",
ResourceType.MEMORY, "2", ResourceType.DISK_DRIVE, "9");
private final URI defaultNetwork;
private final String defaultFenceMode;
private final String apiVersion;
@Inject
public BindInstantiateVAppTemplateParamsToXmlPayload(
BindToStringPayload stringBinder,
@Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns,
@Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema,
@Named(PROPERTY_VCLOUD_DEFAULT_NETWORK) String network,
@Named(PROPERTY_VCLOUD_DEFAULT_FENCEMODE) String fenceMode
) {
public BindInstantiateVAppTemplateParamsToXmlPayload(BindToStringPayload stringBinder,
@Named(PROPERTY_API_VERSION) String apiVersion, @Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns,
@Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema, @Named(PROPERTY_VCLOUD_DEFAULT_NETWORK) String network,
@Named(PROPERTY_VCLOUD_DEFAULT_FENCEMODE) String fenceMode) {
this.ns = ns;
this.apiVersion = apiVersion;
this.schema = schema;
this.stringBinder = stringBinder;
this.defaultNetwork = URI.create(network);
@ -86,17 +85,14 @@ public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder
@SuppressWarnings("unchecked")
public void bindToRequest(HttpRequest request, Map<String, String> postParams) {
checkArgument(
checkNotNull(request, "request") instanceof GeneratedHttpRequest,
"this binder is only valid for GeneratedHttpRequests!");
checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest,
"this binder is only valid for GeneratedHttpRequests!");
GeneratedHttpRequest gRequest = (GeneratedHttpRequest) request;
checkState(gRequest.getArgs() != null,
"args should be initialized at this point");
checkState(gRequest.getArgs() != null, "args should be initialized at this point");
String name = checkNotNull(postParams.remove("name"), "name");
String template = checkNotNull(postParams.remove("template"), "template");
SortedMap<ResourceType, String> virtualHardwareQuantity = Maps
.newTreeMap();
SortedMap<ResourceType, String> virtualHardwareQuantity = Maps.newTreeMap();
InstantiateVAppTemplateOptions options = findOptionsInArgsOrNull(gRequest);
Map<String, String> properties = Maps.newTreeMap();
@ -106,14 +102,15 @@ public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder
if (options != null) {
network = ifNullDefaultTo(options.getNetwork(), network);
fenceMode = ifNullDefaultTo(options.getFenceMode(), defaultFenceMode);
if (apiVersion.indexOf("0.8") != -1 && fenceMode.equals("bridged"))
fenceMode = "allowInOut";
networkName = ifNullDefaultTo(options.getNetworkName(), networkName);
addQuantity(options, virtualHardwareQuantity);
properties.putAll(options.getProperties());
}
try {
stringBinder.bindToRequest(request, generateXml(name, template,
properties, virtualHardwareQuantity, networkName, fenceMode, URI
.create(network)));
stringBinder.bindToRequest(request, generateXml(name, template, properties, virtualHardwareQuantity,
networkName, fenceMode, URI.create(network)));
} catch (ParserConfigurationException e) {
throw new RuntimeException(e);
} catch (FactoryConfigurationError e) {
@ -124,99 +121,73 @@ public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder
}
protected String generateXml(String name, String template,
Map<String, String> properties,
SortedMap<ResourceType, String> virtualHardwareQuantity,
String networkName, @Nullable String fenceMode, URI network)
throws ParserConfigurationException, FactoryConfigurationError,
TransformerException {
protected String generateXml(String name, String template, Map<String, String> properties,
SortedMap<ResourceType, String> virtualHardwareQuantity, String networkName, @Nullable String fenceMode,
URI network) throws ParserConfigurationException, FactoryConfigurationError, TransformerException {
XMLBuilder rootBuilder = buildRoot(name);
rootBuilder.e("VAppTemplate").a("href", template);
XMLBuilder instantiationParamsBuilder = rootBuilder
.e("InstantiationParams");
XMLBuilder instantiationParamsBuilder = rootBuilder.e("InstantiationParams");
addPropertiesifPresent(instantiationParamsBuilder, properties);
addVirtualQuantityIfPresent(instantiationParamsBuilder,
virtualHardwareQuantity);
addNetworkConfig(instantiationParamsBuilder, networkName, fenceMode,
network);
addVirtualQuantityIfPresent(instantiationParamsBuilder, virtualHardwareQuantity);
addNetworkConfig(instantiationParamsBuilder, networkName, fenceMode, network);
Properties outputProperties = new Properties();
outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION,
"yes");
outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
return rootBuilder.asString(outputProperties);
}
protected void addPropertiesifPresent(XMLBuilder instantiationParamsBuilder,
Map<String, String> properties) {
protected void addPropertiesifPresent(XMLBuilder instantiationParamsBuilder, Map<String, String> properties) {
if (properties.size() > 0) {
XMLBuilder productSectionBuilder = instantiationParamsBuilder.e(
"ProductSection").a("xmlns:q1", ns).a("xmlns:ovf",
"http://schemas.dmtf.org/ovf/envelope/1");
XMLBuilder productSectionBuilder = instantiationParamsBuilder.e("ProductSection").a("xmlns:q1", ns).a(
"xmlns:ovf", "http://schemas.dmtf.org/ovf/envelope/1");
for (Entry<String, String> entry : properties.entrySet()) {
productSectionBuilder.e("Property").a("xmlns",
"http://schemas.dmtf.org/ovf/envelope/1").a("ovf:key",
entry.getKey()).a("ovf:value", entry.getValue());
productSectionBuilder.e("Property").a("xmlns", "http://schemas.dmtf.org/ovf/envelope/1").a("ovf:key",
entry.getKey()).a("ovf:value", entry.getValue());
}
}
}
protected void addNetworkConfig(XMLBuilder instantiationParamsBuilder,
String name, @Nullable String fenceMode, URI network) {
XMLBuilder networkConfigBuilder = instantiationParamsBuilder.e(
"NetworkConfigSection").e("NetworkConfig").a("name", name);
protected void addNetworkConfig(XMLBuilder instantiationParamsBuilder, String name, @Nullable String fenceMode,
URI network) {
XMLBuilder networkConfigBuilder = instantiationParamsBuilder.e("NetworkConfigSection").e("NetworkConfig").a(
"name", name);
if (fenceMode != null) {
XMLBuilder featuresBuilder = networkConfigBuilder.e("Features");
featuresBuilder.e("FenceMode").t(fenceMode);
}
networkConfigBuilder.e("NetworkAssociation").a("href",
network.toASCIIString());
networkConfigBuilder.e("NetworkAssociation").a("href", network.toASCIIString());
}
protected void addVirtualQuantityIfPresent(
XMLBuilder instantiationParamsBuilder,
SortedMap<ResourceType, String> virtualHardwareQuantity) {
protected void addVirtualQuantityIfPresent(XMLBuilder instantiationParamsBuilder,
SortedMap<ResourceType, String> virtualHardwareQuantity) {
if (virtualHardwareQuantity.size() > 0) {
XMLBuilder virtualHardwareSectionBuilder = instantiationParamsBuilder
.e("VirtualHardwareSection").a("xmlns:q1", ns);
for (Entry<ResourceType, String> entry : virtualHardwareQuantity
.entrySet()) {
XMLBuilder itemBuilder = virtualHardwareSectionBuilder.e("Item").a(
"xmlns", "http://schemas.dmtf.org/ovf/envelope/1");
itemBuilder
.e("InstanceID")
.a(
"xmlns",
"http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData")
.t(virtualHardwareToInstanceId.get(entry.getKey()));
itemBuilder
.e("ResourceType")
.a(
"xmlns",
"http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData")
.t(entry.getKey().value());
itemBuilder
.e("VirtualQuantity")
.a(
"xmlns",
"http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData")
.t(entry.getValue());
XMLBuilder virtualHardwareSectionBuilder = instantiationParamsBuilder.e("VirtualHardwareSection").a(
"xmlns:q1", ns);
for (Entry<ResourceType, String> entry : virtualHardwareQuantity.entrySet()) {
XMLBuilder itemBuilder = virtualHardwareSectionBuilder.e("Item").a("xmlns",
"http://schemas.dmtf.org/ovf/envelope/1");
itemBuilder.e("InstanceID").a("xmlns",
"http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData").t(
virtualHardwareToInstanceId.get(entry.getKey()));
itemBuilder.e("ResourceType").a("xmlns",
"http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData").t(
entry.getKey().value());
itemBuilder.e("VirtualQuantity").a("xmlns",
"http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData").t(
entry.getValue());
}
}
}
protected XMLBuilder buildRoot(String name)
throws ParserConfigurationException, FactoryConfigurationError {
XMLBuilder rootBuilder = XMLBuilder.create(
"InstantiateVAppTemplateParams").a("name", name).a("xmlns", ns).a(
"xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance").a(
"xsi:schemaLocation", ns + " " + schema).a("xmlns:ovf",
"http://schemas.dmtf.org/ovf/envelope/1");
protected XMLBuilder buildRoot(String name) throws ParserConfigurationException, FactoryConfigurationError {
XMLBuilder rootBuilder = XMLBuilder.create("InstantiateVAppTemplateParams").a("name", name).a("xmlns", ns).a(
"xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance").a("xsi:schemaLocation", ns + " " + schema).a(
"xmlns:ovf", "http://schemas.dmtf.org/ovf/envelope/1");
return rootBuilder;
}
protected InstantiateVAppTemplateOptions findOptionsInArgsOrNull(
GeneratedHttpRequest<?> gRequest) {
protected InstantiateVAppTemplateOptions findOptionsInArgsOrNull(GeneratedHttpRequest<?> gRequest) {
for (Object arg : gRequest.getArgs()) {
if (arg instanceof InstantiateVAppTemplateOptions) {
return (InstantiateVAppTemplateOptions) arg;
@ -228,28 +199,23 @@ public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder
return null;
}
private void addQuantity(InstantiateVAppTemplateOptions options,
Map<ResourceType, String> virtualHardwareQuantity) {
private void addQuantity(InstantiateVAppTemplateOptions options, Map<ResourceType, String> virtualHardwareQuantity) {
if (options.getCpuCount() != null) {
virtualHardwareQuantity.put(ResourceType.PROCESSOR, options
.getCpuCount());
virtualHardwareQuantity.put(ResourceType.PROCESSOR, options.getCpuCount());
}
if (options.getMemorySizeMegabytes() != null) {
virtualHardwareQuantity.put(ResourceType.MEMORY, options
.getMemorySizeMegabytes());
virtualHardwareQuantity.put(ResourceType.MEMORY, options.getMemorySizeMegabytes());
}
if (options.getDiskSizeKilobytes() != null) {
virtualHardwareQuantity.put(ResourceType.DISK_DRIVE, options
.getDiskSizeKilobytes());
virtualHardwareQuantity.put(ResourceType.DISK_DRIVE, options.getDiskSizeKilobytes());
}
}
public void bindToRequest(HttpRequest request, Object input) {
throw new IllegalStateException(
"InstantiateVAppTemplateParams is needs parameters");
throw new IllegalStateException("InstantiateVAppTemplateParams is needs parameters");
}
protected String ifNullDefaultTo(String value, String defaultValue) {
return value != null ? value : checkNotNull(defaultValue, "defaultValue");
protected String ifNullDefaultTo(Object value, String defaultValue) {
return value != null ? value.toString() : checkNotNull(defaultValue, "defaultValue");
}
}

View File

@ -0,0 +1,62 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.compute;
import java.net.URI;
import java.util.Set;
/**
*
* @author Adrian Cole
*/
public interface CommonVCloudComputeClient {
/**
* returns a set of addresses that are only visible to the private network.
*/
Set<String> getPrivateAddresses(URI vAppId);
/**
* returns a set of addresses that are publically visible
*/
Set<String> getPublicAddresses(URI vAppId);
/**
* reboots the vApp, blocking until the following state transition is complete:
* <p/>
* current -> {@code VAppStatus#OFF} -> {@code VAppStatus#ON}
*
* @param vAppId
* vApp to reboot
*/
void reboot(URI vAppId);
/**
* Destroys dependent resources, powers off and deletes the vApp, blocking until the following
* state transition is complete:
* <p/>
* current -> {@code VAppStatus#OFF} -> deleted
*
* @param vAppId
* vApp to stop
*/
void stop(URI vAppId);
}

View File

@ -21,10 +21,10 @@ package org.jclouds.vcloud.compute;
import java.net.URI;
import java.util.Map;
import java.util.Set;
import javax.annotation.Nullable;
import org.jclouds.vcloud.compute.internal.VCloudComputeClientImpl;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import com.google.inject.ImplementedBy;
@ -33,11 +33,11 @@ import com.google.inject.ImplementedBy;
*
* @author Adrian Cole
*/
@ImplementedBy(BaseVCloudComputeClient.class)
public interface VCloudComputeClient {
@ImplementedBy(VCloudComputeClientImpl.class)
public interface VCloudComputeClient extends CommonVCloudComputeClient {
/**
* Runs through all commands necessary to startup a vApp, opening at least
* one ip address to the public network. These are the steps:
* Runs through all commands necessary to startup a vApp, opening at least one ip address to the
* public network. These are the steps:
* <p/>
* instantiate -> deploy -> powerOn
* <p/>
@ -59,43 +59,11 @@ public interface VCloudComputeClient {
* opens the following ports on the public ip address
* @return map contains at least the following properties
* <ol>
* <li>id - vApp id</li> <li>username - console login user</li> <li>
* password - console login password</li>
* <li>id - vApp id</li> <li>username - console login user</li> <li> password - console
* login password</li>
* </ol>
*/
Map<String, String> start(@Nullable URI VDC, URI templateId, String name, InstantiateVAppTemplateOptions options,
int... portsToOpen);
/**
* returns a set of addresses that are only visible to the private network.
*/
Set<String> getPrivateAddresses(URI vAppId);
/**
* returns a set of addresses that are publically visible
*/
Set<String> getPublicAddresses(URI vAppId);
/**
* reboots the vApp, blocking until the following state transition is
* complete:
* <p/>
* current -> {@code VAppStatus#OFF} -> {@code VAppStatus#ON}
*
* @param vAppId
* vApp to reboot
*/
void reboot(URI vAppId);
/**
* Destroys dependent resources, powers off and deletes the vApp, blocking
* until the following state transition is complete:
* <p/>
* current -> {@code VAppStatus#OFF} -> deleted
*
* @param vAppId
* vApp to stop
*/
void stop(URI vAppId);
int... portsToOpen);
}

View File

@ -0,0 +1,69 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.compute;
import java.net.URI;
import java.util.Map;
import javax.annotation.Nullable;
import org.jclouds.vcloud.compute.internal.VCloudExpressComputeClientImpl;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import com.google.inject.ImplementedBy;
/**
*
* @author Adrian Cole
*/
@ImplementedBy(VCloudExpressComputeClientImpl.class)
public interface VCloudExpressComputeClient extends CommonVCloudComputeClient {
/**
* Runs through all commands necessary to startup a vApp, opening at least one ip address to the
* public network. These are the steps:
* <p/>
* instantiate -> deploy -> powerOn
* <p/>
* This command blocks until the vApp is in state {@code VAppStatus#ON}
*
* @param VDC
* id of the virtual datacenter {@code VCloudClient#getDefaultVDC}
* @param templateId
* id of the vAppTemplate you wish to instantiate
* @param name
* name of the vApp
* @param cores
* amount of virtual cpu cores
* @param megs
* amount of ram in megabytes
* @param options
* options for instantiating the vApp; null is ok
* @param portsToOpen
* opens the following ports on the public ip address
* @return map contains at least the following properties
* <ol>
* <li>id - vApp id</li> <li>username - console login user</li> <li> password - console
* login password</li>
* </ol>
*/
Map<String, String> start(@Nullable URI VDC, URI templateId, String name, InstantiateVAppTemplateOptions options,
int... portsToOpen);
}

View File

@ -0,0 +1,110 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.compute.config;
import java.util.Map;
import java.util.Set;
import javax.inject.Singleton;
import org.jclouds.compute.LoadBalancerService;
import org.jclouds.compute.config.BaseComputeServiceContextModule;
import org.jclouds.compute.config.ComputeServiceTimeoutsModule;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.NodeState;
import org.jclouds.compute.domain.Size;
import org.jclouds.compute.strategy.DestroyNodeStrategy;
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
import org.jclouds.compute.strategy.ListNodesStrategy;
import org.jclouds.compute.strategy.RebootNodeStrategy;
import org.jclouds.compute.strategy.RunNodesAndAddToSetStrategy;
import org.jclouds.compute.strategy.impl.EncodeTagIntoNameRunNodesAndAddToSetStrategy;
import org.jclouds.domain.Location;
import org.jclouds.vcloud.compute.internal.VCloudComputeClientImpl;
import org.jclouds.vcloud.compute.strategy.VCloudDestroyNodeStrategy;
import org.jclouds.vcloud.compute.strategy.VCloudGetNodeMetadataStrategy;
import org.jclouds.vcloud.compute.strategy.VCloudListNodesStrategy;
import org.jclouds.vcloud.compute.strategy.VCloudRebootNodeStrategy;
import org.jclouds.vcloud.compute.suppliers.OrgAndVDCToLocationSupplier;
import org.jclouds.vcloud.compute.suppliers.StaticSizeSupplier;
import org.jclouds.vcloud.compute.suppliers.VCloudImageSupplier;
import org.jclouds.vcloud.domain.Status;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableMap;
import com.google.inject.Injector;
import com.google.inject.Provides;
import com.google.inject.util.Providers;
/**
* Configures the {@link VCloudComputeServiceContext}; requires {@link VCloudComputeClientImpl}
* bound.
*
* @author Adrian Cole
*/
public abstract class CommonVCloudComputeServiceContextModule extends BaseComputeServiceContextModule {
@VisibleForTesting
static final Map<Status, NodeState> vAppStatusToNodeState = ImmutableMap.<Status, NodeState> builder().put(
Status.OFF, NodeState.SUSPENDED).put(Status.ON, NodeState.RUNNING).put(Status.RESOLVED, NodeState.PENDING)
.put(Status.ERROR, NodeState.ERROR).put(Status.UNRECOGNIZED, NodeState.UNKNOWN).put(Status.DEPLOYED,
NodeState.PENDING).put(Status.INCONSISTENT, NodeState.PENDING).put(Status.UNKNOWN,
NodeState.UNKNOWN).put(Status.MIXED, NodeState.PENDING).put(Status.WAITING_FOR_INPUT,
NodeState.PENDING).put(Status.SUSPENDED, NodeState.SUSPENDED).put(Status.UNRESOLVED,
NodeState.PENDING).build();
@Singleton
@Provides
Map<Status, NodeState> provideVAppStatusToNodeState() {
return vAppStatusToNodeState;
}
@Override
protected void configure() {
install(new ComputeServiceTimeoutsModule());
bind(DestroyNodeStrategy.class).to(VCloudDestroyNodeStrategy.class);
bind(RunNodesAndAddToSetStrategy.class).to(EncodeTagIntoNameRunNodesAndAddToSetStrategy.class);
bind(ListNodesStrategy.class).to(VCloudListNodesStrategy.class);
bind(GetNodeMetadataStrategy.class).to(VCloudGetNodeMetadataStrategy.class);
bind(RebootNodeStrategy.class).to(VCloudRebootNodeStrategy.class);
bindLoadBalancer();
}
protected void bindLoadBalancer() {
bind(LoadBalancerService.class).toProvider(Providers.<LoadBalancerService> of(null));
}
@Override
protected Supplier<Set<? extends Size>> getSourceSizeSupplier(Injector injector) {
return injector.getInstance(StaticSizeSupplier.class);
}
@Override
protected Supplier<Set<? extends Location>> getSourceLocationSupplier(Injector injector) {
return injector.getInstance(OrgAndVDCToLocationSupplier.class);
}
@Override
protected Supplier<Set<? extends Image>> getSourceImageSupplier(Injector injector) {
return injector.getInstance(VCloudImageSupplier.class);
}
}

View File

@ -19,106 +19,46 @@
package org.jclouds.vcloud.compute.config;
import java.util.Map;
import java.util.Set;
import javax.inject.Singleton;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.LoadBalancerService;
import org.jclouds.compute.config.BaseComputeServiceContextModule;
import org.jclouds.compute.config.ComputeServiceTimeoutsModule;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.NodeState;
import org.jclouds.compute.domain.Size;
import org.jclouds.compute.internal.ComputeServiceContextImpl;
import org.jclouds.compute.strategy.AddNodeWithTagStrategy;
import org.jclouds.compute.strategy.DestroyNodeStrategy;
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
import org.jclouds.compute.strategy.ListNodesStrategy;
import org.jclouds.compute.strategy.RebootNodeStrategy;
import org.jclouds.compute.strategy.RunNodesAndAddToSetStrategy;
import org.jclouds.compute.strategy.impl.EncodeTagIntoNameRunNodesAndAddToSetStrategy;
import org.jclouds.domain.Location;
import org.jclouds.rest.RestContext;
import org.jclouds.rest.internal.RestContextImpl;
import org.jclouds.vcloud.VCloudAsyncClient;
import org.jclouds.vcloud.VCloudClient;
import org.jclouds.vcloud.compute.BaseVCloudComputeClient;
import org.jclouds.vcloud.compute.CommonVCloudComputeClient;
import org.jclouds.vcloud.compute.VCloudComputeClient;
import org.jclouds.vcloud.compute.internal.VCloudComputeClientImpl;
import org.jclouds.vcloud.compute.strategy.VCloudAddNodeWithTagStrategy;
import org.jclouds.vcloud.compute.strategy.VCloudDestroyNodeStrategy;
import org.jclouds.vcloud.compute.strategy.VCloudGetNodeMetadataStrategy;
import org.jclouds.vcloud.compute.strategy.VCloudListNodesStrategy;
import org.jclouds.vcloud.compute.strategy.VCloudRebootNodeStrategy;
import org.jclouds.vcloud.compute.suppliers.OrgAndVDCToLocationSupplier;
import org.jclouds.vcloud.compute.suppliers.StaticSizeSupplier;
import org.jclouds.vcloud.compute.suppliers.VCloudImageSupplier;
import org.jclouds.vcloud.domain.VAppStatus;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableMap;
import com.google.inject.Injector;
import com.google.inject.Provides;
import com.google.inject.Scopes;
import com.google.inject.TypeLiteral;
import com.google.inject.util.Providers;
/**
* Configures the {@link VCloudComputeServiceContext}; requires {@link BaseVCloudComputeClient}
* Configures the {@link VCloudComputeServiceContext}; requires {@link VCloudComputeClientImpl}
* bound.
*
* @author Adrian Cole
*/
public class VCloudComputeServiceContextModule extends BaseComputeServiceContextModule {
@VisibleForTesting
static final Map<VAppStatus, NodeState> vAppStatusToNodeState = ImmutableMap.<VAppStatus, NodeState> builder().put(
VAppStatus.OFF, NodeState.SUSPENDED).put(VAppStatus.ON, NodeState.RUNNING).put(VAppStatus.RESOLVED,
NodeState.PENDING).put(VAppStatus.SUSPENDED, NodeState.SUSPENDED).put(VAppStatus.UNRESOLVED,
NodeState.PENDING).build();
@Singleton
@Provides
Map<VAppStatus, NodeState> provideVAppStatusToNodeState() {
return vAppStatusToNodeState;
}
public class VCloudComputeServiceContextModule extends CommonVCloudComputeServiceContextModule {
@Override
protected void configure() {
install(new ComputeServiceTimeoutsModule());
bind(AddNodeWithTagStrategy.class).to(VCloudAddNodeWithTagStrategy.class);
super.configure();
bind(new TypeLiteral<ComputeServiceContext>() {
}).to(new TypeLiteral<ComputeServiceContextImpl<VCloudClient, VCloudAsyncClient>>() {
}).to(new TypeLiteral<ComputeServiceContextImpl<VCloudClient, VCloudClient>>() {
}).in(Scopes.SINGLETON);
bind(new TypeLiteral<RestContext<VCloudClient, VCloudAsyncClient>>() {
}).to(new TypeLiteral<RestContextImpl<VCloudClient, VCloudAsyncClient>>() {
bind(new TypeLiteral<RestContext<VCloudClient, VCloudClient>>() {
}).to(new TypeLiteral<RestContextImpl<VCloudClient, VCloudClient>>() {
}).in(Scopes.SINGLETON);
bind(RunNodesAndAddToSetStrategy.class).to(EncodeTagIntoNameRunNodesAndAddToSetStrategy.class);
bind(ListNodesStrategy.class).to(VCloudListNodesStrategy.class);
bind(GetNodeMetadataStrategy.class).to(VCloudGetNodeMetadataStrategy.class);
bind(RebootNodeStrategy.class).to(VCloudRebootNodeStrategy.class);
bind(DestroyNodeStrategy.class).to(VCloudDestroyNodeStrategy.class);
bindLoadBalancer();
bind(AddNodeWithTagStrategy.class).to(VCloudAddNodeWithTagStrategy.class);
}
protected void bindLoadBalancer() {
bind(LoadBalancerService.class).toProvider(Providers.<LoadBalancerService> of(null));
@Provides
@Singleton
CommonVCloudComputeClient provideCommonVCloudComputeClient(VCloudComputeClient in) {
return in;
}
@Override
protected Supplier<Set<? extends Image>> getSourceImageSupplier(Injector injector) {
return injector.getInstance(VCloudImageSupplier.class);
}
@Override
protected Supplier<Set<? extends Location>> getSourceLocationSupplier(Injector injector) {
return injector.getInstance(OrgAndVDCToLocationSupplier.class);
}
@Override
protected Supplier<Set<? extends Size>> getSourceSizeSupplier(Injector injector) {
return injector.getInstance(StaticSizeSupplier.class);
}
}

View File

@ -0,0 +1,64 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.compute.config;
import javax.inject.Singleton;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.internal.ComputeServiceContextImpl;
import org.jclouds.compute.strategy.AddNodeWithTagStrategy;
import org.jclouds.rest.RestContext;
import org.jclouds.rest.internal.RestContextImpl;
import org.jclouds.vcloud.VCloudExpressClient;
import org.jclouds.vcloud.compute.CommonVCloudComputeClient;
import org.jclouds.vcloud.compute.VCloudExpressComputeClient;
import org.jclouds.vcloud.compute.internal.VCloudExpressComputeClientImpl;
import org.jclouds.vcloud.compute.strategy.VCloudExpressAddNodeWithTagStrategy;
import com.google.inject.Provides;
import com.google.inject.Scopes;
import com.google.inject.TypeLiteral;
/**
* Configures the {@link VCloudComputeServiceContext}; requires
* {@link VCloudExpressComputeClientImpl} bound.
*
* @author Adrian Cole
*/
public class VCloudExpressComputeServiceContextModule extends CommonVCloudComputeServiceContextModule {
@Override
protected void configure() {
super.configure();
bind(new TypeLiteral<ComputeServiceContext>() {
}).to(new TypeLiteral<ComputeServiceContextImpl<VCloudExpressClient, VCloudExpressClient>>() {
}).in(Scopes.SINGLETON);
bind(new TypeLiteral<RestContext<VCloudExpressClient, VCloudExpressClient>>() {
}).to(new TypeLiteral<RestContextImpl<VCloudExpressClient, VCloudExpressClient>>() {
}).in(Scopes.SINGLETON);
bind(AddNodeWithTagStrategy.class).to(VCloudExpressAddNodeWithTagStrategy.class);
}
@Provides
@Singleton
CommonVCloudComputeClient provideCommonVCloudComputeClient(VCloudExpressComputeClient in) {
return in;
}
}

View File

@ -31,7 +31,7 @@ import javax.annotation.Resource;
import javax.inject.Singleton;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.compute.BaseVCloudComputeClient;
import org.jclouds.vcloud.compute.internal.VCloudExpressComputeClientImpl;
import org.jclouds.vcloud.domain.ResourceAllocation;
import org.jclouds.vcloud.domain.ResourceType;
import org.jclouds.vcloud.domain.VApp;
@ -40,7 +40,7 @@ import com.google.common.base.Function;
/**
* Configures the {@link VCloudComputeServiceContext}; requires
* {@link BaseVCloudComputeClient} bound.
* {@link VCloudExpressComputeClientImpl} bound.
*
* @author Adrian Cole
*/

View File

@ -25,10 +25,9 @@ import javax.inject.Singleton;
import org.jclouds.compute.domain.Image;
import org.jclouds.vcloud.domain.CatalogItem;
import org.jclouds.vcloud.domain.Organization;
import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.domain.VAppTemplate;
import org.jclouds.vcloud.functions.AllCatalogItemsInOrganization;
import org.jclouds.vcloud.functions.VAppTemplatesForCatalogItems;
import org.jclouds.vcloud.functions.AllCatalogItemsInOrg;
import com.google.common.base.Function;
import com.google.common.collect.Iterables;
@ -37,24 +36,24 @@ import com.google.common.collect.Iterables;
* @author Adrian Cole
*/
@Singleton
public class ImagesInOrganization implements Function<Organization, Iterable<? extends Image>> {
public class ImagesInOrg implements Function<Org, Iterable<? extends Image>> {
private final AllCatalogItemsInOrganization allCatalogItemsInOrganization;
private final VAppTemplatesForCatalogItems vAppTemplatesForCatalogItems;
private final AllCatalogItemsInOrg allCatalogItemsInOrg;
private final Function<Iterable<? extends CatalogItem>, Iterable<? extends VAppTemplate>> vAppTemplatesForCatalogItems;
private final Provider<ImageForVAppTemplate> imageForVAppTemplateProvider;
@Inject
ImagesInOrganization(AllCatalogItemsInOrganization allCatalogItemsInOrganization,
ImagesInOrg(AllCatalogItemsInOrg allCatalogItemsInOrg,
Provider<ImageForVAppTemplate> imageForVAppTemplateProvider,
VAppTemplatesForCatalogItems vAppTemplatesForCatalogItems) {
Function<Iterable<? extends CatalogItem>, Iterable<? extends VAppTemplate>> vAppTemplatesForCatalogItems) {
this.imageForVAppTemplateProvider = imageForVAppTemplateProvider;
this.allCatalogItemsInOrganization = allCatalogItemsInOrganization;
this.allCatalogItemsInOrg = allCatalogItemsInOrg;
this.vAppTemplatesForCatalogItems = vAppTemplatesForCatalogItems;
}
@Override
public Iterable<? extends Image> apply(Organization from) {
Iterable<? extends CatalogItem> catalogs = allCatalogItemsInOrganization.apply(from);
public Iterable<? extends Image> apply(Org from) {
Iterable<? extends CatalogItem> catalogs = allCatalogItemsInOrg.apply(from);
Iterable<? extends VAppTemplate> vAppTemplates = vAppTemplatesForCatalogItems.apply(catalogs);
return Iterables.transform(vAppTemplates, imageForVAppTemplateProvider.get().withParent(from));
}

View File

@ -1,96 +0,0 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.compute.functions;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.compute.util.ComputeServiceUtils.parseTagFromName;
import java.net.URI;
import java.util.Map;
import java.util.Set;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.NodeState;
import org.jclouds.compute.domain.internal.NodeMetadataImpl;
import org.jclouds.compute.domain.os.CIMOperatingSystem;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.domain.Location;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.VCloudClient;
import org.jclouds.vcloud.compute.BaseVCloudComputeClient;
import org.jclouds.vcloud.compute.VCloudComputeClient;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VAppStatus;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableMap;
/**
* Configures the {@link VCloudComputeServiceContext}; requires {@link BaseVCloudComputeClient}
* bound.
*
* @author Adrian Cole
*/
@Singleton
public class VCloudGetNodeMetadata {
@Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
public Logger logger = Logger.NULL;
protected final VCloudClient client;
protected final VCloudComputeClient computeClient;
protected final Supplier<Set<? extends Image>> images;
protected final FindLocationForResource findLocationForResourceInVDC;
protected final GetExtra getExtra;
protected final Map<VAppStatus, NodeState> vAppStatusToNodeState;
@Inject
VCloudGetNodeMetadata(VCloudClient client, VCloudComputeClient computeClient,
Map<VAppStatus, NodeState> vAppStatusToNodeState, GetExtra getExtra,
FindLocationForResource findLocationForResourceInVDC, Supplier<Set<? extends Image>> images) {
this.client = checkNotNull(client, "client");
this.images = checkNotNull(images, "images");
this.getExtra = checkNotNull(getExtra, "getExtra");
this.findLocationForResourceInVDC = checkNotNull(findLocationForResourceInVDC, "findLocationForResourceInVDC");
this.computeClient = checkNotNull(computeClient, "computeClient");
this.vAppStatusToNodeState = checkNotNull(vAppStatusToNodeState, "vAppStatusToNodeState");
}
public NodeMetadata execute(String in) {
URI id = URI.create(in);
VApp from = client.getVApp(id);
if (from == null)
return null;
String tag = parseTagFromName(from.getName());
Location location = findLocationForResourceInVDC.apply(from.getVDC());
return new NodeMetadataImpl(in, from.getName(), in, location, from.getId(), ImmutableMap.<String, String> of(),
tag, null, from.getOsType() != null ? new CIMOperatingSystem(CIMOperatingSystem.OSType.fromValue(from
.getOsType()), null, null, from.getOperatingSystemDescription()) : null, vAppStatusToNodeState
.get(from.getStatus()), computeClient.getPublicAddresses(id), computeClient
.getPrivateAddresses(id), getExtra.apply(from), null);
}
}

View File

@ -17,30 +17,26 @@
* ====================================================================
*/
package org.jclouds.vcloud.compute;
package org.jclouds.vcloud.compute.internal;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import java.net.URI;
import java.util.Map;
import java.util.Set;
import javax.annotation.Nullable;
import javax.annotation.Resource;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.compute.domain.NodeState;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.VCloudClient;
import org.jclouds.vcloud.CommonVCloudClient;
import org.jclouds.vcloud.compute.CommonVCloudComputeClient;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.domain.Status;
import org.jclouds.vcloud.domain.VAppTemplate;
import org.jclouds.vcloud.domain.VDC;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableSet;
@ -52,52 +48,18 @@ import com.google.inject.Inject;
* @author Adrian Cole
*/
@Singleton
public class BaseVCloudComputeClient implements VCloudComputeClient {
public class CommonVCloudComputeClientImpl implements CommonVCloudComputeClient {
@Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
protected Logger logger = Logger.NULL;
protected final VCloudClient client;
protected final CommonVCloudClient client;
protected final Predicate<URI> taskTester;
protected final Map<VAppStatus, NodeState> vAppStatusToNodeState;
@Inject
public BaseVCloudComputeClient(VCloudClient client, Predicate<URI> successTester,
Map<VAppStatus, NodeState> vAppStatusToNodeState) {
public CommonVCloudComputeClientImpl(CommonVCloudClient client, Predicate<URI> successTester) {
this.client = client;
this.taskTester = successTester;
this.vAppStatusToNodeState = vAppStatusToNodeState;
}
@Override
public Map<String, String> start(@Nullable URI VDC, URI templateId, String name,
InstantiateVAppTemplateOptions options, int... portsToOpen) {
checkNotNull(options, "options");
logger.debug(">> instantiating vApp vDC(%s) template(%s) name(%s) options(%s) ", VDC, templateId, name, options);
VDC vdc = client.getVDC(VDC);
VAppTemplate template = client.getVAppTemplate(templateId);
VApp vAppResponse = client.instantiateVAppTemplateInVDC(vdc.getId(), template.getId(), name, options);
logger.debug("<< instantiated VApp(%s)", vAppResponse.getName());
logger.debug(">> deploying vApp(%s)", vAppResponse.getName());
Task task = client.deployVApp(vAppResponse.getId());
if (options.shouldBlockOnDeploy()) {
if (!taskTester.apply(task.getLocation())) {
throw new TaskException("deploy", vAppResponse, task);
}
logger.debug("<< deployed vApp(%s)", vAppResponse.getName());
logger.debug(">> powering vApp(%s)", vAppResponse.getName());
task = client.powerOnVApp(vAppResponse.getId());
if (!taskTester.apply(task.getLocation())) {
throw new TaskException("powerOn", vAppResponse, task);
}
logger.debug("<< on vApp(%s)", vAppResponse.getName());
}
return parseAndValidateResponse(template, vAppResponse);
}
protected Map<String, String> parseAndValidateResponse(VAppTemplate template, VApp vAppResponse) {
@ -142,7 +104,7 @@ public class BaseVCloudComputeClient implements VCloudComputeClient {
}
private VApp undeployVAppIfDeployed(VApp vApp) {
if (vApp.getStatus().compareTo(VAppStatus.RESOLVED) > 0) {
if (vApp.getStatus().compareTo(Status.RESOLVED) > 0) {
logger.debug(">> undeploying vApp(%s), current status: %s", vApp.getName(), vApp.getStatus());
Task task = client.undeployVApp(vApp.getId());
if (!taskTester.apply(task.getLocation())) {
@ -155,7 +117,7 @@ public class BaseVCloudComputeClient implements VCloudComputeClient {
}
private VApp powerOffVAppIfDeployed(VApp vApp) {
if (vApp.getStatus().compareTo(VAppStatus.OFF) > 0) {
if (vApp.getStatus().compareTo(Status.OFF) > 0) {
logger.debug(">> powering off vApp(%s), current status: %s", vApp.getName(), vApp.getStatus());
Task task = client.powerOffVApp(vApp.getId());
if (!taskTester.apply(task.getLocation())) {
@ -175,7 +137,7 @@ public class BaseVCloudComputeClient implements VCloudComputeClient {
public TaskException(String type, VApp vApp, Task task) {
super(String.format("failed to %s vApp %s status %s;task %s status %s", type, vApp.getName(),
vApp.getStatus(), task.getLocation(), task.getStatus()), vApp);
vApp.getStatus(), task.getLocation(), task.getStatus()), vApp);
this.task = task;
}

View File

@ -0,0 +1,89 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.compute.internal;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.Map;
import javax.annotation.Nullable;
import javax.inject.Singleton;
import org.jclouds.compute.domain.NodeState;
import org.jclouds.vcloud.VCloudClient;
import org.jclouds.vcloud.compute.VCloudComputeClient;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.Status;
import org.jclouds.vcloud.domain.VAppTemplate;
import org.jclouds.vcloud.domain.VDC;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import com.google.common.base.Predicate;
import com.google.inject.Inject;
/**
* @author Adrian Cole
*/
@Singleton
public class VCloudComputeClientImpl extends CommonVCloudComputeClientImpl implements VCloudComputeClient {
protected final Map<Status, NodeState> vAppStatusToNodeState;
@Inject
public VCloudComputeClientImpl(VCloudClient client, Predicate<URI> successTester,
Map<Status, NodeState> vAppStatusToNodeState) {
super(client, successTester);
this.vAppStatusToNodeState = vAppStatusToNodeState;
}
@Override
public Map<String, String> start(@Nullable URI VDC, URI templateId, String name,
InstantiateVAppTemplateOptions options, int... portsToOpen) {
checkNotNull(options, "options");
logger.debug(">> instantiating vApp vDC(%s) template(%s) name(%s) options(%s) ", VDC, templateId, name, options);
VDC vdc = client.getVDC(VDC);
VAppTemplate template = client.getVAppTemplate(templateId);
VApp vAppResponse = VCloudClient.class.cast(client).instantiateVAppTemplateInVDC(vdc.getId(), template.getId(),
name, options);
logger.debug("<< instantiated VApp(%s)", vAppResponse.getName());
logger.debug(">> deploying vApp(%s)", vAppResponse.getName());
Task task = client.deployVApp(vAppResponse.getId());
if (options.shouldBlockOnDeploy()) {
if (!taskTester.apply(task.getLocation())) {
throw new TaskException("deploy", vAppResponse, task);
}
logger.debug("<< deployed vApp(%s)", vAppResponse.getName());
logger.debug(">> powering vApp(%s)", vAppResponse.getName());
task = client.powerOnVApp(vAppResponse.getId());
if (!taskTester.apply(task.getLocation())) {
throw new TaskException("powerOn", vAppResponse, task);
}
logger.debug("<< on vApp(%s)", vAppResponse.getName());
}
return parseAndValidateResponse(template, vAppResponse);
}
}

View File

@ -0,0 +1,90 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.compute.internal;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.Map;
import javax.annotation.Nullable;
import javax.inject.Singleton;
import org.jclouds.compute.domain.NodeState;
import org.jclouds.vcloud.VCloudExpressClient;
import org.jclouds.vcloud.compute.VCloudExpressComputeClient;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.Status;
import org.jclouds.vcloud.domain.VAppTemplate;
import org.jclouds.vcloud.domain.VDC;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import com.google.common.base.Predicate;
import com.google.inject.Inject;
/**
* @author Adrian Cole
*/
@Singleton
public class VCloudExpressComputeClientImpl extends CommonVCloudComputeClientImpl implements VCloudExpressComputeClient {
protected final Map<Status, NodeState> vAppStatusToNodeState;
@Inject
public VCloudExpressComputeClientImpl(VCloudExpressClient client, Predicate<URI> successTester,
Map<Status, NodeState> vAppStatusToNodeState) {
super(client, successTester);
this.vAppStatusToNodeState = vAppStatusToNodeState;
}
@Override
public Map<String, String> start(@Nullable URI VDC, URI templateId, String name,
InstantiateVAppTemplateOptions options, int... portsToOpen) {
checkNotNull(options, "options");
logger.debug(">> instantiating vApp vDC(%s) template(%s) name(%s) options(%s) ", VDC, templateId, name, options);
VDC vdc = client.getVDC(VDC);
VAppTemplate template = client.getVAppTemplate(templateId);
VApp vAppResponse = VCloudExpressClient.class.cast(client).instantiateVAppTemplateInVDC(vdc.getId(),
template.getId(), name, options);
logger.debug("<< instantiated VApp(%s)", vAppResponse.getName());
logger.debug(">> deploying vApp(%s)", vAppResponse.getName());
Task task = client.deployVApp(vAppResponse.getId());
if (options.shouldBlockOnDeploy()) {
if (!taskTester.apply(task.getLocation())) {
throw new TaskException("deploy", vAppResponse, task);
}
logger.debug("<< deployed vApp(%s)", vAppResponse.getName());
logger.debug(">> powering vApp(%s)", vAppResponse.getName());
task = client.powerOnVApp(vAppResponse.getId());
if (!taskTester.apply(task.getLocation())) {
throw new TaskException("powerOn", vAppResponse, task);
}
logger.debug("<< on vApp(%s)", vAppResponse.getName());
}
return parseAndValidateResponse(template, vAppResponse);
}
}

View File

@ -38,7 +38,7 @@ import org.jclouds.domain.Credentials;
import org.jclouds.vcloud.VCloudClient;
import org.jclouds.vcloud.compute.VCloudComputeClient;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.domain.Status;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import com.google.common.collect.ImmutableMap;
@ -50,11 +50,11 @@ import com.google.common.collect.ImmutableMap;
public class VCloudAddNodeWithTagStrategy implements AddNodeWithTagStrategy {
protected final VCloudClient client;
protected final VCloudComputeClient computeClient;
protected final Map<VAppStatus, NodeState> vAppStatusToNodeState;
protected final Map<Status, NodeState> vAppStatusToNodeState;
@Inject
protected VCloudAddNodeWithTagStrategy(VCloudClient client, VCloudComputeClient computeClient,
Map<VAppStatus, NodeState> vAppStatusToNodeState) {
Map<Status, NodeState> vAppStatusToNodeState) {
this.client = client;
this.computeClient = computeClient;
this.vAppStatusToNodeState = vAppStatusToNodeState;

View File

@ -29,18 +29,18 @@ import javax.inject.Singleton;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.strategy.DestroyNodeStrategy;
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
import org.jclouds.vcloud.compute.VCloudComputeClient;
import org.jclouds.vcloud.compute.CommonVCloudComputeClient;
/**
* @author Adrian Cole
*/
@Singleton
public class VCloudDestroyNodeStrategy implements DestroyNodeStrategy {
protected final VCloudComputeClient computeClient;
protected final CommonVCloudComputeClient computeClient;
protected final GetNodeMetadataStrategy getNode;
@Inject
protected VCloudDestroyNodeStrategy(VCloudComputeClient computeClient, GetNodeMetadataStrategy getNode) {
protected VCloudDestroyNodeStrategy(CommonVCloudComputeClient computeClient, GetNodeMetadataStrategy getNode) {
this.computeClient = computeClient;
this.getNode = getNode;

View File

@ -0,0 +1,89 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.compute.strategy;
import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.processorCount;
import java.net.URI;
import java.util.Map;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.NodeState;
import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.compute.domain.Template;
import org.jclouds.compute.domain.internal.NodeMetadataImpl;
import org.jclouds.compute.domain.os.CIMOperatingSystem;
import org.jclouds.compute.strategy.AddNodeWithTagStrategy;
import org.jclouds.domain.Credentials;
import org.jclouds.vcloud.VCloudExpressClient;
import org.jclouds.vcloud.compute.VCloudExpressComputeClient;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.Status;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import com.google.common.collect.ImmutableMap;
/**
* @author Adrian Cole
*/
@Singleton
public class VCloudExpressAddNodeWithTagStrategy implements AddNodeWithTagStrategy {
protected final VCloudExpressClient client;
protected final VCloudExpressComputeClient computeClient;
protected final Map<Status, NodeState> vAppStatusToNodeState;
@Inject
protected VCloudExpressAddNodeWithTagStrategy(VCloudExpressClient client, VCloudExpressComputeClient computeClient,
Map<Status, NodeState> vAppStatusToNodeState) {
this.client = client;
this.computeClient = computeClient;
this.vAppStatusToNodeState = vAppStatusToNodeState;
}
@Override
public NodeMetadata execute(String tag, String name, Template template) {
InstantiateVAppTemplateOptions options = processorCount(Double.valueOf(template.getSize().getCores()).intValue())
.memory(template.getSize().getRam()).disk(template.getSize().getDisk() * 1024 * 1024l);
if (!template.getOptions().shouldBlockUntilRunning())
options.blockOnDeploy(false);
Map<String, String> metaMap = computeClient.start(URI.create(template.getLocation().getId()), URI.create(template
.getImage().getId()), name, options, template.getOptions().getInboundPorts());
VApp vApp = client.getVApp(URI.create(metaMap.get("id")));
return newCreateNodeResponse(tag, template, metaMap, vApp);
}
protected NodeMetadata newCreateNodeResponse(String tag, Template template, Map<String, String> metaMap, VApp vApp) {
return new NodeMetadataImpl(vApp.getId().toASCIIString(), vApp.getName(), vApp.getId().toASCIIString(), template
.getLocation(), vApp.getId(), ImmutableMap.<String, String> of(), tag, template.getImage().getId(),
getOperatingSystemForVAppOrDefaultTo(vApp, template.getImage().getOperatingSystem()),
vAppStatusToNodeState.get(vApp.getStatus()), computeClient.getPublicAddresses(vApp.getId()),
computeClient.getPrivateAddresses(vApp.getId()), ImmutableMap.<String, String> of(), new Credentials(
metaMap.get("username"), metaMap.get("password")));
}
private OperatingSystem getOperatingSystemForVAppOrDefaultTo(VApp vApp, OperatingSystem operatingSystem) {
return vApp.getOsType() != null ? new CIMOperatingSystem(CIMOperatingSystem.OSType.fromValue(vApp.getOsType()),
null, null, vApp.getOperatingSystemDescription()) : operatingSystem;
}
}

View File

@ -20,30 +20,75 @@
package org.jclouds.vcloud.compute.strategy;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.compute.util.ComputeServiceUtils.parseTagFromName;
import java.net.URI;
import java.util.Map;
import java.util.Set;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.NodeState;
import org.jclouds.compute.domain.internal.NodeMetadataImpl;
import org.jclouds.compute.domain.os.CIMOperatingSystem;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
import org.jclouds.vcloud.compute.functions.VCloudGetNodeMetadata;
import org.jclouds.domain.Location;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.CommonVCloudClient;
import org.jclouds.vcloud.compute.CommonVCloudComputeClient;
import org.jclouds.vcloud.compute.functions.FindLocationForResource;
import org.jclouds.vcloud.compute.functions.GetExtra;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.Status;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableMap;
/**
* @author Adrian Cole
*/
@Singleton
public class VCloudGetNodeMetadataStrategy implements GetNodeMetadataStrategy {
protected final VCloudGetNodeMetadata getNodeMetadata;
@Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
public Logger logger = Logger.NULL;
protected final CommonVCloudClient client;
protected final CommonVCloudComputeClient computeClient;
protected final Supplier<Set<? extends Image>> images;
protected final FindLocationForResource findLocationForResourceInVDC;
protected final GetExtra getExtra;
protected final Map<Status, NodeState> vAppStatusToNodeState;
@Inject
protected VCloudGetNodeMetadataStrategy(VCloudGetNodeMetadata getNodeMetadata) {
this.getNodeMetadata = getNodeMetadata;
protected VCloudGetNodeMetadataStrategy(CommonVCloudClient client, CommonVCloudComputeClient computeClient,
Map<Status, NodeState> vAppStatusToNodeState, GetExtra getExtra,
FindLocationForResource findLocationForResourceInVDC, Supplier<Set<? extends Image>> images) {
this.client = checkNotNull(client, "client");
this.images = checkNotNull(images, "images");
this.getExtra = checkNotNull(getExtra, "getExtra");
this.findLocationForResourceInVDC = checkNotNull(findLocationForResourceInVDC, "findLocationForResourceInVDC");
this.computeClient = checkNotNull(computeClient, "computeClient");
this.vAppStatusToNodeState = checkNotNull(vAppStatusToNodeState, "vAppStatusToNodeState");
}
@Override
public NodeMetadata execute(String id) {
return getNodeMetadata.execute(checkNotNull(id, "node.id"));
public NodeMetadata execute(String in) {
URI id = URI.create(in);
VApp from = client.getVApp(id);
if (from == null)
return null;
String tag = parseTagFromName(from.getName());
Location location = findLocationForResourceInVDC.apply(from.getVDC());
return new NodeMetadataImpl(in, from.getName(), in, location, from.getId(), ImmutableMap.<String, String> of(),
tag, null, from.getOsType() != null ? new CIMOperatingSystem(CIMOperatingSystem.OSType.fromValue(from
.getOsType()), null, null, from.getOperatingSystemDescription()) : null, vAppStatusToNodeState
.get(from.getStatus()), computeClient.getPublicAddresses(id), computeClient
.getPrivateAddresses(id), getExtra.apply(from), null);
}
}

View File

@ -36,10 +36,9 @@ import org.jclouds.compute.domain.internal.ComputeMetadataImpl;
import org.jclouds.compute.strategy.ListNodesStrategy;
import org.jclouds.domain.Location;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.VCloudClient;
import org.jclouds.vcloud.CommonVCloudClient;
import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.compute.functions.FindLocationForResource;
import org.jclouds.vcloud.compute.functions.VCloudGetNodeMetadata;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.endpoints.Org;
@ -55,14 +54,14 @@ import com.google.inject.internal.util.ImmutableSet;
/**
* @author Adrian Cole
*/
//TODO REFACTOR!!! needs to be parallel
// TODO REFACTOR!!! needs to be parallel
@Singleton
public class VCloudListNodesStrategy implements ListNodesStrategy {
@Resource
@Named(COMPUTE_LOGGER)
public Logger logger = Logger.NULL;
protected final VCloudGetNodeMetadata getNodeMetadata;
protected final VCloudClient client;
protected final VCloudGetNodeMetadataStrategy getNodeMetadata;
protected final CommonVCloudClient client;
protected final FindLocationForResource findLocationForResourceInVDC;
Set<String> blackListVAppNames = ImmutableSet.<String> of();
@ -75,8 +74,9 @@ public class VCloudListNodesStrategy implements ListNodesStrategy {
private final Supplier<Map<String, NamedResource>> orgNameToEndpoint;
@Inject
protected VCloudListNodesStrategy(VCloudClient client, @Org Supplier<Map<String, NamedResource>> orgNameToEndpoint,
VCloudGetNodeMetadata getNodeMetadata, FindLocationForResource findLocationForResourceInVDC) {
protected VCloudListNodesStrategy(CommonVCloudClient client,
@Org Supplier<Map<String, NamedResource>> orgNameToEndpoint, VCloudGetNodeMetadataStrategy getNodeMetadata,
FindLocationForResource findLocationForResourceInVDC) {
this.client = client;
this.orgNameToEndpoint = orgNameToEndpoint;
this.getNodeMetadata = getNodeMetadata;
@ -87,7 +87,7 @@ public class VCloudListNodesStrategy implements ListNodesStrategy {
public Iterable<ComputeMetadata> list() {
Set<ComputeMetadata> nodes = Sets.newHashSet();
for (String org : orgNameToEndpoint.get().keySet()) {
for (NamedResource vdc : client.findOrganizationNamed(org).getVDCs().values()) {
for (NamedResource vdc : client.findOrgNamed(org).getVDCs().values()) {
for (NamedResource resource : client.getVDC(vdc.getId()).getResourceEntities().values()) {
if (validVApp(resource)) {
nodes.add(convertVAppToComputeMetadata(vdc, resource));
@ -104,15 +104,15 @@ public class VCloudListNodesStrategy implements ListNodesStrategy {
private ComputeMetadata convertVAppToComputeMetadata(NamedResource vdc, NamedResource resource) {
Location location = findLocationForResourceInVDC.apply(vdc);
return new ComputeMetadataImpl(ComputeType.NODE, resource.getId().toASCIIString(), resource.getName(),
resource.getId().toASCIIString(), location, null, ImmutableMap.<String, String> of());
return new ComputeMetadataImpl(ComputeType.NODE, resource.getId().toASCIIString(), resource.getName(), resource
.getId().toASCIIString(), location, null, ImmutableMap.<String, String> of());
}
@Override
public Iterable<NodeMetadata> listDetailsOnNodesMatching(Predicate<ComputeMetadata> filter) {
Set<NodeMetadata> nodes = Sets.newHashSet();
for (String org : orgNameToEndpoint.get().keySet()) {
for (NamedResource vdc : client.findOrganizationNamed(org).getVDCs().values()) {
for (NamedResource vdc : client.findOrgNamed(org).getVDCs().values()) {
for (NamedResource resource : client.getVDC(vdc.getId()).getResourceEntities().values()) {
if (validVApp(resource) && filter.apply(convertVAppToComputeMetadata(vdc, resource))) {
addVAppToSetRetryingIfNotYetPresent(nodes, vdc, resource);

View File

@ -29,7 +29,7 @@ import javax.inject.Singleton;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
import org.jclouds.compute.strategy.RebootNodeStrategy;
import org.jclouds.vcloud.VCloudClient;
import org.jclouds.vcloud.CommonVCloudClient;
import org.jclouds.vcloud.domain.Task;
import com.google.common.base.Predicate;
@ -39,12 +39,13 @@ import com.google.common.base.Predicate;
*/
@Singleton
public class VCloudRebootNodeStrategy implements RebootNodeStrategy {
private final VCloudClient client;
private final CommonVCloudClient client;
protected final Predicate<URI> taskTester;
protected final GetNodeMetadataStrategy getNode;
@Inject
protected VCloudRebootNodeStrategy(VCloudClient client, Predicate<URI> taskTester, GetNodeMetadataStrategy getNode) {
protected VCloudRebootNodeStrategy(CommonVCloudClient client, Predicate<URI> taskTester,
GetNodeMetadataStrategy getNode) {
this.client = client;
this.taskTester = taskTester;
this.getNode = getNode;

View File

@ -30,8 +30,7 @@ import org.jclouds.domain.LocationScope;
import org.jclouds.domain.internal.LocationImpl;
import org.jclouds.vcloud.compute.domain.VCloudLocation;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.Organization;
import org.jclouds.vcloud.endpoints.Org;
import org.jclouds.vcloud.domain.Org;
import com.google.common.base.Supplier;
import com.google.common.collect.Sets;
@ -43,12 +42,12 @@ import com.google.common.collect.Sets;
public class OrgAndVDCToLocationSupplier implements Supplier<Set<? extends Location>> {
private final String providerName;
private final Supplier<Map<String, NamedResource>> orgNameToResource;
private final Supplier<Map<String, ? extends Organization>> orgNameToVDCResource;
private final Supplier<Map<String, ? extends Org>> orgNameToVDCResource;
@Inject
OrgAndVDCToLocationSupplier(@org.jclouds.rest.annotations.Provider String providerName,
@Org Supplier<Map<String, NamedResource>> orgNameToResource,
Supplier<Map<String, ? extends Organization>> orgNameToVDCResource) {
@org.jclouds.vcloud.endpoints.Org Supplier<Map<String, NamedResource>> orgNameToResource,
Supplier<Map<String, ? extends Org>> orgNameToVDCResource) {
this.providerName = providerName;
this.orgNameToResource = orgNameToResource;
this.orgNameToVDCResource = orgNameToVDCResource;

View File

@ -39,8 +39,7 @@ import org.jclouds.Constants;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.compute.functions.ImagesInOrganization;
import org.jclouds.vcloud.domain.Organization;
import org.jclouds.vcloud.domain.Org;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
@ -55,32 +54,33 @@ public class VCloudImageSupplier implements Supplier<Set<? extends Image>> {
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
public Logger logger = Logger.NULL;
private final Supplier<Map<String, ? extends Organization>> orgMap;
private final ImagesInOrganization imagesInOrganization;
private final Supplier<Map<String, ? extends Org>> orgMap;
private final Function<Org, Iterable<? extends Image>> imagesInOrg;
private final ExecutorService executor;
@Inject
VCloudImageSupplier(Supplier<Map<String, ? extends Organization>> orgMap, ImagesInOrganization imagesInOrganization,
VCloudImageSupplier(Supplier<Map<String, ? extends Org>> orgMap,
Function<Org, Iterable<? extends Image>> imagesInOrg,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
this.orgMap = checkNotNull(orgMap, "orgMap");
this.imagesInOrganization = checkNotNull(imagesInOrganization, "imagesInOrganization");
this.imagesInOrg = checkNotNull(imagesInOrg, "imagesInOrg");
this.executor = checkNotNull(executor, "executor");
}
@Override
public Set<? extends Image> get() {
Iterable<? extends Organization> orgs = checkNotNull(orgMap.get().values(), "orgs");
Iterable<? extends Org> orgs = checkNotNull(orgMap.get().values(), "orgs");
Iterable<Iterable<? extends Image>> images = transformParallel(orgs,
new Function<Organization, Future<Iterable<? extends Image>>>() {
new Function<Org, Future<Iterable<? extends Image>>>() {
@Override
public Future<Iterable<? extends Image>> apply(final Organization from) {
public Future<Iterable<? extends Image>> apply(final Org from) {
checkNotNull(from, "org");
return executor.submit(new Callable<Iterable<? extends Image>>() {
@Override
public Iterable<? extends Image> call() throws Exception {
return imagesInOrganization.apply(from);
return imagesInOrg.apply(from);
}
});

View File

@ -0,0 +1,84 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.config;
import static com.google.common.base.Throwables.propagate;
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
import java.util.concurrent.TimeUnit;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.http.RequiresHttp;
import org.jclouds.rest.AsyncClientFactory;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.suppliers.RetryOnTimeOutButNotOnAuthorizationExceptionSupplier;
import org.jclouds.vcloud.VCloudExpressAsyncClient;
import org.jclouds.vcloud.VCloudExpressClient;
import org.jclouds.vcloud.domain.VCloudSession;
import com.google.common.base.Supplier;
import com.google.inject.Provides;
import domain.VCloudExpressLoginAsyncClient;
/**
* Configures the VCloud authentication service connection, including logging and http transport.
*
* @author Adrian Cole
*/
@RequiresHttp
@ConfiguresRestClient
public abstract class BaseVCloudExpressRestClientModule<S extends VCloudExpressClient, A extends VCloudExpressAsyncClient>
extends CommonVCloudRestClientModule<S, A> {
public BaseVCloudExpressRestClientModule(Class<S> syncClientType, Class<A> asyncClientType) {
super(syncClientType, asyncClientType);
}
@Provides
@Singleton
protected VCloudExpressLoginAsyncClient provideVCloudLogin(AsyncClientFactory factory) {
return factory.create(VCloudExpressLoginAsyncClient.class);
}
@Provides
@Singleton
protected Supplier<VCloudSession> provideVCloudTokenCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
final VCloudExpressLoginAsyncClient login) {
return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<VCloudSession>(authException, seconds,
new Supplier<VCloudSession>() {
@Override
public VCloudSession get() {
try {
return login.login().get(10, TimeUnit.SECONDS);
} catch (Exception e) {
propagate(e);
assert false : e;
return null;
}
}
});
}
}

View File

@ -19,447 +19,41 @@
package org.jclouds.vcloud.config;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.base.Throwables.propagate;
import static com.google.common.collect.Iterables.concat;
import static com.google.common.collect.Iterables.get;
import static com.google.common.collect.Iterables.getLast;
import static com.google.common.collect.Iterables.transform;
import static com.google.common.collect.Maps.newLinkedHashMap;
import static com.google.common.collect.Maps.transformValues;
import static com.google.common.collect.Maps.uniqueIndex;
import static org.jclouds.Constants.PROPERTY_API_VERSION;
import static org.jclouds.Constants.PROPERTY_IDENTITY;
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_NETWORK;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED;
import java.net.URI;
import java.util.Map;
import java.util.SortedMap;
import java.util.Map.Entry;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicReference;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.http.HttpErrorHandler;
import org.jclouds.http.RequiresHttp;
import org.jclouds.http.annotation.ClientError;
import org.jclouds.http.annotation.Redirection;
import org.jclouds.http.annotation.ServerError;
import org.jclouds.logging.Logger;
import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.rest.AsyncClientFactory;
import org.jclouds.rest.AuthorizationException;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.config.RestClientModule;
import org.jclouds.rest.suppliers.RetryOnTimeOutButNotOnAuthorizationExceptionSupplier;
import org.jclouds.vcloud.VCloudAsyncClient;
import org.jclouds.vcloud.VCloudClient;
import org.jclouds.vcloud.VCloudToken;
import org.jclouds.vcloud.domain.CatalogItem;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.Organization;
import org.jclouds.vcloud.endpoints.Catalog;
import org.jclouds.vcloud.endpoints.Network;
import org.jclouds.vcloud.endpoints.Org;
import org.jclouds.vcloud.endpoints.TasksList;
import org.jclouds.vcloud.endpoints.VDC;
import org.jclouds.vcloud.functions.AllCatalogItemsInCatalog;
import org.jclouds.vcloud.functions.AllCatalogsInOrganization;
import org.jclouds.vcloud.functions.AllVDCsInOrganization;
import org.jclouds.vcloud.functions.OrganizationsForNames;
import org.jclouds.vcloud.handlers.ParseVCloudErrorFromHttpResponse;
import org.jclouds.vcloud.internal.VCloudLoginAsyncClient;
import org.jclouds.vcloud.internal.VCloudVersionsAsyncClient;
import org.jclouds.vcloud.internal.VCloudLoginAsyncClient.VCloudSession;
import org.jclouds.vcloud.predicates.TaskSuccess;
import org.jclouds.vcloud.domain.VCloudSession;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Supplier;
import com.google.inject.Provides;
import domain.VCloudLoginAsyncClient;
/**
* Configures the VCloud authentication service connection, including logging
* and http transport.
* Configures the VCloud authentication service connection, including logging and http transport.
*
* @author Adrian Cole
*/
@RequiresHttp
@ConfiguresRestClient
public abstract class BaseVCloudRestClientModule<S extends VCloudClient, A extends VCloudAsyncClient> extends
RestClientModule<S, A> {
CommonVCloudRestClientModule<S, A> {
public BaseVCloudRestClientModule(Class<S> syncClientType, Class<A> asyncClientType) {
super(syncClientType, asyncClientType);
}
@Override
protected void configure() {
requestInjection(this);
super.configure();
}
@Resource
protected Logger logger = Logger.NULL;
@Provides
@Singleton
protected Predicate<URI> successTester(TaskSuccess success,
@Named(PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED) long completed) {
return new RetryablePredicate<URI>(success, completed);
}
@VCloudToken
@Provides
String provideVCloudToken(Supplier<VCloudSession> cache) {
return checkNotNull(cache.get().getVCloudToken(), "No token present in session");
}
@Provides
@Org
@Singleton
protected URI provideOrg(@Org Iterable<NamedResource> orgs) {
return getLast(orgs).getId();
}
@Provides
@Org
@Singleton
protected String provideOrgName(@Org Iterable<NamedResource> orgs) {
return getLast(orgs).getName();
}
@Provides
@Org
@Singleton
protected Supplier<Map<String, NamedResource>> provideVDCtoORG(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
final OrgNameToOrgSupplier supplier) {
return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, NamedResource>>(authException,
seconds, new Supplier<Map<String, NamedResource>>() {
@Override
public Map<String, NamedResource> get() {
return supplier.get();
}
});
}
@Provides
@Singleton
protected Supplier<Map<URI, ? extends org.jclouds.vcloud.domain.VDC>> provideURIToVDC(
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final URItoVDC supplier) {
return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<URI, ? extends org.jclouds.vcloud.domain.VDC>>(
authException, seconds, new Supplier<Map<URI, ? extends org.jclouds.vcloud.domain.VDC>>() {
@Override
public Map<URI, ? extends org.jclouds.vcloud.domain.VDC> get() {
return supplier.get();
}
});
}
@Provides
@Singleton
@VDC
protected Supplier<Map<String, String>> provideVDCtoORG(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
final Supplier<Map<String, ? extends Organization>> orgToVDCSupplier) {
return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, String>>(authException, seconds,
new Supplier<Map<String, String>>() {
@Override
public Map<String, String> get() {
Map<String, String> returnVal = newLinkedHashMap();
for (Entry<String, ? extends Organization> orgr : orgToVDCSupplier.get().entrySet()) {
for (String vdc : orgr.getValue().getVDCs().keySet()) {
returnVal.put(vdc, orgr.getKey());
}
}
return returnVal;
}
});
}
@Singleton
public static class URItoVDC implements Supplier<Map<URI, ? extends org.jclouds.vcloud.domain.VDC>> {
private final Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> orgVDCMap;
@Inject
URItoVDC(Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> orgVDCMap) {
this.orgVDCMap = orgVDCMap;
}
@Override
public Map<URI, ? extends org.jclouds.vcloud.domain.VDC> get() {
return uniqueIndex(
concat(transform(
orgVDCMap.get().values(),
new Function<Map<String, ? extends org.jclouds.vcloud.domain.VDC>, Iterable<? extends org.jclouds.vcloud.domain.VDC>>() {
@Override
public Iterable<? extends org.jclouds.vcloud.domain.VDC> apply(
Map<String, ? extends org.jclouds.vcloud.domain.VDC> from) {
return from.values();
}
})), new Function<org.jclouds.vcloud.domain.VDC, URI>() {
@Override
public URI apply(org.jclouds.vcloud.domain.VDC from) {
return from.getId();
}
});
}
}
@Provides
@Org
@Singleton
protected Iterable<NamedResource> provideOrgs(Supplier<VCloudSession> cache, @Named(PROPERTY_IDENTITY) String user) {
VCloudSession discovery = cache.get();
checkState(discovery.getOrgs().size() > 0, "No orgs present for user: " + user);
return discovery.getOrgs().values();
}
protected AtomicReference<AuthorizationException> authException = new AtomicReference<AuthorizationException>();
@Provides
@Singleton
protected Supplier<VCloudSession> provideVCloudTokenCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
final VCloudLoginAsyncClient login) {
return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<VCloudSession>(authException, seconds,
new Supplier<VCloudSession>() {
@Override
public VCloudSession get() {
try {
return login.login().get(10, TimeUnit.SECONDS);
} catch (Exception e) {
propagate(e);
assert false : e;
return null;
}
}
});
}
@Provides
@Singleton
protected Supplier<Map<String, ? extends Organization>> provideOrgMapCache(
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrganizationMapSupplier supplier) {
return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, ? extends Organization>>(
authException, seconds, new Supplier<Map<String, ? extends Organization>>() {
@Override
public Map<String, ? extends Organization> get() {
return supplier.get();
}
});
}
private final static Function<NamedResource, String> name = new Function<NamedResource, String>() {
@Override
public String apply(NamedResource from) {
return from.getName();
}
};
@Singleton
public static class OrganizationMapSupplier implements Supplier<Map<String, ? extends Organization>> {
protected final Supplier<VCloudSession> sessionSupplier;
private final OrganizationsForNames organizationsForNames;
@Inject
protected OrganizationMapSupplier(Supplier<VCloudSession> sessionSupplier,
OrganizationsForNames organizationsForNames) {
this.sessionSupplier = sessionSupplier;
this.organizationsForNames = organizationsForNames;
}
@Override
public Map<String, ? extends Organization> get() {
return uniqueIndex(organizationsForNames.apply(sessionSupplier.get().getOrgs().keySet()), name);
}
}
@Singleton
public static class OrganizationCatalogSupplier implements
Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>> {
protected final Supplier<Map<String, ? extends Organization>> orgSupplier;
private final AllCatalogsInOrganization allCatalogsInOrganization;
@Inject
protected OrganizationCatalogSupplier(Supplier<Map<String, ? extends Organization>> orgSupplier,
AllCatalogsInOrganization allCatalogsInOrganization) {
this.orgSupplier = orgSupplier;
this.allCatalogsInOrganization = allCatalogsInOrganization;
}
@Override
public Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>> get() {
return transformValues(
transformValues(orgSupplier.get(), allCatalogsInOrganization),
new Function<Iterable<? extends org.jclouds.vcloud.domain.Catalog>, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>() {
@Override
public Map<String, ? extends org.jclouds.vcloud.domain.Catalog> apply(
Iterable<? extends org.jclouds.vcloud.domain.Catalog> from) {
return uniqueIndex(from, name);
}
});
}
}
@Provides
@Singleton
protected Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>> provideOrganizationCatalogItemMapSupplierCache(
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrganizationCatalogSupplier supplier) {
return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>>(
authException, seconds,
new Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>>() {
@Override
public Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>> get() {
return supplier.get();
}
});
}
@Provides
@Singleton
protected Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> provideOrganizationVDCSupplierCache(
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrganizationVDCSupplier supplier) {
return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>>(
authException, seconds, new Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>>() {
@Override
public Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>> get() {
return supplier.get();
}
});
}
@Singleton
public static class OrganizationVDCSupplier implements
Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> {
protected final Supplier<Map<String, ? extends Organization>> orgSupplier;
private final AllVDCsInOrganization allVDCsInOrganization;
@Inject
protected OrganizationVDCSupplier(Supplier<Map<String, ? extends Organization>> orgSupplier,
AllVDCsInOrganization allVDCsInOrganization) {
this.orgSupplier = orgSupplier;
this.allVDCsInOrganization = allVDCsInOrganization;
}
@Override
public Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>> get() {
return transformValues(
transformValues(orgSupplier.get(), allVDCsInOrganization),
new Function<Iterable<? extends org.jclouds.vcloud.domain.VDC>, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>() {
@Override
public Map<String, ? extends org.jclouds.vcloud.domain.VDC> apply(
Iterable<? extends org.jclouds.vcloud.domain.VDC> from) {
return uniqueIndex(from, name);
}
});
}
}
@Singleton
public static class OrganizationCatalogItemSupplier implements
Supplier<Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>>> {
protected final Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>> catalogSupplier;
private final AllCatalogItemsInCatalog allCatalogItemsInCatalog;
@Inject
protected OrganizationCatalogItemSupplier(
Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>> catalogSupplier,
AllCatalogItemsInCatalog allCatalogItemsInCatalog) {
this.catalogSupplier = catalogSupplier;
this.allCatalogItemsInCatalog = allCatalogItemsInCatalog;
}
@Override
public Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>> get() {
return transformValues(
catalogSupplier.get(),
new Function<Map<String, ? extends org.jclouds.vcloud.domain.Catalog>, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>>() {
@Override
public Map<String, Map<String, ? extends CatalogItem>> apply(
Map<String, ? extends org.jclouds.vcloud.domain.Catalog> from) {
return transformValues(
from,
new Function<org.jclouds.vcloud.domain.Catalog, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>() {
@Override
public Map<String, ? extends CatalogItem> apply(org.jclouds.vcloud.domain.Catalog from) {
return uniqueIndex(allCatalogItemsInCatalog.apply(from), name);
}
});
}
});
}
}
@Provides
@Singleton
protected Supplier<Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>>> provideOrganizationCatalogItemSupplierCache(
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrganizationCatalogItemSupplier supplier) {
return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>>>(
authException, seconds,
new Supplier<Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>>>() {
@Override
public Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>> get() {
return supplier.get();
}
});
}
@Provides
@Singleton
@org.jclouds.vcloud.endpoints.VCloudLogin
protected URI provideAuthenticationURI(VCloudVersionsAsyncClient versionService,
@Named(PROPERTY_API_VERSION) String version) throws InterruptedException, ExecutionException, TimeoutException {
SortedMap<String, URI> versions = versionService.getSupportedVersions().get(180, TimeUnit.SECONDS);
checkState(versions.size() > 0, "No versions present");
checkState(versions.containsKey(version), "version " + version + " not present in: " + versions);
return versions.get(version);
}
@Singleton
private static class OrgNameToOrgSupplier implements Supplier<Map<String, NamedResource>> {
private final Supplier<VCloudSession> sessionSupplier;
@SuppressWarnings("unused")
@Inject
OrgNameToOrgSupplier(Supplier<VCloudSession> sessionSupplier) {
this.sessionSupplier = sessionSupplier;
}
@Override
public Map<String, NamedResource> get() {
return sessionSupplier.get().getOrgs();
}
}
@Provides
@Singleton
protected VCloudLoginAsyncClient provideVCloudLogin(AsyncClientFactory factory) {
@ -468,85 +62,22 @@ public abstract class BaseVCloudRestClientModule<S extends VCloudClient, A exten
@Provides
@Singleton
protected VCloudVersionsAsyncClient provideVCloudVersions(AsyncClientFactory factory) {
return factory.create(VCloudVersionsAsyncClient.class);
}
protected Supplier<VCloudSession> provideVCloudTokenCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
final VCloudLoginAsyncClient login) {
return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<VCloudSession>(authException, seconds,
new Supplier<VCloudSession>() {
@Provides
@Singleton
protected Organization provideOrganization(VCloudClient discovery) throws ExecutionException, TimeoutException,
InterruptedException {
if (authException.get() != null)
throw authException.get();
try {
return discovery.findOrganizationNamed(null);
} catch (AuthorizationException e) {
authException.set(e);
throw e;
}
}
@Override
public VCloudSession get() {
try {
return login.login().get(10, TimeUnit.SECONDS);
} catch (Exception e) {
propagate(e);
assert false : e;
return null;
}
}
@Provides
@VDC
@Singleton
protected URI provideDefaultVDC(Organization org) {
checkState(org.getVDCs().size() > 0, "No vdcs present in org: " + org.getName());
return get(org.getVDCs().values(), 0).getId();
}
@Provides
@Catalog
@Singleton
protected URI provideCatalog(Organization org, @Named(PROPERTY_IDENTITY) String user) {
checkState(org.getCatalogs().size() > 0, "No catalogs present in org: " + org.getName());
return get(org.getCatalogs().values(), 0).getId();
}
@Provides
@Catalog
@Singleton
protected String provideCatalogName(
Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>> catalogs) {
return getLast(getLast(catalogs.get().values()).keySet());
}
@Provides
@Network
@Singleton
protected URI provideDefaultNetwork(VCloudClient client) throws InterruptedException, ExecutionException,
TimeoutException {
if (authException.get() != null)
throw authException.get();
try {
org.jclouds.vcloud.domain.VDC vDC = client.findVDCInOrgNamed(null, null);
Map<String, NamedResource> networks = vDC.getAvailableNetworks();
checkState(networks.size() > 0, "No networks present in vDC: " + vDC.getName());
return get(networks.values(), 0).getId();
} catch (AuthorizationException e) {
authException.set(e);
throw e;
}
}
@Provides
@Named(PROPERTY_VCLOUD_DEFAULT_NETWORK)
@Singleton
String provideDefaultNetworkString(@Network URI network) {
return network.toASCIIString();
}
@Override
protected void bindErrorHandlers() {
bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(ParseVCloudErrorFromHttpResponse.class);
bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(ParseVCloudErrorFromHttpResponse.class);
bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(ParseVCloudErrorFromHttpResponse.class);
}
@Provides
@TasksList
@Singleton
protected URI provideDefaultTasksList(Organization org) {
checkState(org.getTasksLists().size() > 0, "No tasks lists present in org: " + org.getName());
return get(org.getTasksLists().values(), 0).getId();
});
}
}

View File

@ -0,0 +1,563 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.config;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.collect.Iterables.concat;
import static com.google.common.collect.Iterables.get;
import static com.google.common.collect.Iterables.getLast;
import static com.google.common.collect.Iterables.transform;
import static com.google.common.collect.Maps.newLinkedHashMap;
import static com.google.common.collect.Maps.transformValues;
import static com.google.common.collect.Maps.uniqueIndex;
import static org.jclouds.Constants.PROPERTY_API_VERSION;
import static org.jclouds.Constants.PROPERTY_IDENTITY;
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_NETWORK;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED;
import java.net.URI;
import java.util.Map;
import java.util.SortedMap;
import java.util.Map.Entry;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicReference;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.compute.domain.Image;
import org.jclouds.domain.Location;
import org.jclouds.http.HttpErrorHandler;
import org.jclouds.http.RequiresHttp;
import org.jclouds.http.annotation.ClientError;
import org.jclouds.http.annotation.Redirection;
import org.jclouds.http.annotation.ServerError;
import org.jclouds.logging.Logger;
import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.rest.AsyncClientFactory;
import org.jclouds.rest.AuthorizationException;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.config.RestClientModule;
import org.jclouds.rest.suppliers.RetryOnTimeOutButNotOnAuthorizationExceptionSupplier;
import org.jclouds.vcloud.CommonVCloudAsyncClient;
import org.jclouds.vcloud.CommonVCloudClient;
import org.jclouds.vcloud.VCloudToken;
import org.jclouds.vcloud.compute.functions.ImagesInOrg;
import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.domain.CatalogItem;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.domain.VAppTemplate;
import org.jclouds.vcloud.domain.VCloudSession;
import org.jclouds.vcloud.domain.VDC;
import org.jclouds.vcloud.endpoints.Network;
import org.jclouds.vcloud.endpoints.TasksList;
import org.jclouds.vcloud.functions.AllCatalogItemsInCatalog;
import org.jclouds.vcloud.functions.AllCatalogsInOrg;
import org.jclouds.vcloud.functions.AllVDCsInOrg;
import org.jclouds.vcloud.functions.OrgsForLocations;
import org.jclouds.vcloud.functions.OrgsForNames;
import org.jclouds.vcloud.functions.VAppTemplatesForCatalogItems;
import org.jclouds.vcloud.handlers.ParseVCloudErrorFromHttpResponse;
import org.jclouds.vcloud.predicates.TaskSuccess;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Supplier;
import com.google.inject.Injector;
import com.google.inject.Provides;
import com.google.inject.TypeLiteral;
import domain.VCloudVersionsAsyncClient;
/**
* Configures the VCloud authentication service connection, including logging and http transport.
*
* @author Adrian Cole
*/
@RequiresHttp
@ConfiguresRestClient
public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extends CommonVCloudAsyncClient> extends
RestClientModule<S, A> {
public CommonVCloudRestClientModule(Class<S> syncClientType, Class<A> asyncClientType) {
super(syncClientType, asyncClientType);
}
@Override
protected void configure() {
requestInjection(this);
super.configure();
bind(new TypeLiteral<Function<Org, Iterable<? extends Catalog>>>() {
}).to(new TypeLiteral<AllCatalogsInOrg>() {
});
bind(new TypeLiteral<Function<Org, Iterable<? extends VDC>>>() {
}).to(new TypeLiteral<AllVDCsInOrg>() {
});
bind(new TypeLiteral<Function<Iterable<String>, Iterable<? extends Org>>>() {
}).to(new TypeLiteral<OrgsForNames>() {
});
bind(new TypeLiteral<Function<Iterable<? extends Location>, Iterable<? extends Org>>>() {
}).to(new TypeLiteral<OrgsForLocations>() {
});
bind(new TypeLiteral<Function<Org, Iterable<? extends Image>>>() {
}).to(new TypeLiteral<ImagesInOrg>() {
});
bind(new TypeLiteral<Function<Catalog, Iterable<? extends CatalogItem>>>() {
}).to(new TypeLiteral<AllCatalogItemsInCatalog>() {
});
bind(new TypeLiteral<Function<Iterable<? extends CatalogItem>, Iterable<? extends VAppTemplate>>>() {
}).to(new TypeLiteral<VAppTemplatesForCatalogItems>() {
});
}
@Singleton
@Provides
CommonVCloudAsyncClient provideCommonVCloudAsyncClient(A in){
return in;
}
@Singleton
@Provides
CommonVCloudClient provideCommonVCloudClient(S in){
return in;
}
@Provides
@Singleton
@org.jclouds.vcloud.endpoints.VDC
protected Supplier<Map<String, String>> provideVDCtoORG(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
final Supplier<Map<String, ? extends Org>> orgToVDCSupplier) {
return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, String>>(authException, seconds,
new Supplier<Map<String, String>>() {
@Override
public Map<String, String> get() {
Map<String, String> returnVal = newLinkedHashMap();
for (Entry<String, ? extends Org> orgr : orgToVDCSupplier.get().entrySet()) {
for (String vdc : orgr.getValue().getVDCs().keySet()) {
returnVal.put(vdc, orgr.getKey());
}
}
return returnVal;
}
});
}
@Provides
@org.jclouds.vcloud.endpoints.VDC
@Singleton
protected URI provideDefaultVDC(Org org) {
checkState(org.getVDCs().size() > 0, "No vdcs present in org: " + org.getName());
return get(org.getVDCs().values(), 0).getId();
}
@Provides
@org.jclouds.vcloud.endpoints.Catalog
@Singleton
protected URI provideCatalog(Org org, @Named(PROPERTY_IDENTITY) String user) {
checkState(org.getCatalogs().size() > 0, "No catalogs present in org: " + org.getName());
return get(org.getCatalogs().values(), 0).getId();
}
@Provides
@Singleton
protected Supplier<Map<String, ? extends Org>> provideOrgMapCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
final OrgMapSupplier supplier) {
return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, ? extends Org>>(authException,
seconds, new Supplier<Map<String, ? extends Org>>() {
@Override
public Map<String, ? extends Org> get() {
return supplier.get();
}
});
}
@Singleton
public static class OrgMapSupplier implements Supplier<Map<String, ? extends Org>> {
protected final Supplier<VCloudSession> sessionSupplier;
private final Function<Iterable<String>, Iterable<? extends Org>> organizationsForNames;
@Inject
protected OrgMapSupplier(Supplier<VCloudSession> sessionSupplier,
Function<Iterable<String>, Iterable<? extends Org>> organizationsForNames) {
this.sessionSupplier = sessionSupplier;
this.organizationsForNames = organizationsForNames;
}
@Override
public Map<String, ? extends Org> get() {
return uniqueIndex(organizationsForNames.apply(sessionSupplier.get().getOrgs().keySet()), name);
}
}
@Singleton
public static class OrgCatalogSupplier implements
Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>> {
protected final Supplier<Map<String, ? extends Org>> orgSupplier;
private final Function<Org, Iterable<? extends org.jclouds.vcloud.domain.Catalog>> allCatalogsInOrg;
@Inject
protected OrgCatalogSupplier(Supplier<Map<String, ? extends Org>> orgSupplier,
Function<Org, Iterable<? extends org.jclouds.vcloud.domain.Catalog>> allCatalogsInOrg) {
this.orgSupplier = orgSupplier;
this.allCatalogsInOrg = allCatalogsInOrg;
}
@Override
public Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>> get() {
return transformValues(
transformValues(orgSupplier.get(), allCatalogsInOrg),
new Function<Iterable<? extends org.jclouds.vcloud.domain.Catalog>, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>() {
@Override
public Map<String, ? extends org.jclouds.vcloud.domain.Catalog> apply(
Iterable<? extends org.jclouds.vcloud.domain.Catalog> from) {
return uniqueIndex(from, name);
}
});
}
}
@Resource
protected Logger logger = Logger.NULL;
@VCloudToken
@Provides
String provideVCloudToken(Supplier<VCloudSession> cache) {
return checkNotNull(cache.get().getVCloudToken(), "No token present in session");
}
@Provides
@org.jclouds.vcloud.endpoints.Org
@Singleton
protected URI provideOrg(@org.jclouds.vcloud.endpoints.Org Iterable<NamedResource> orgs) {
return getLast(orgs).getId();
}
@Provides
@org.jclouds.vcloud.endpoints.Org
@Singleton
protected String provideOrgName(@org.jclouds.vcloud.endpoints.Org Iterable<NamedResource> orgs) {
return getLast(orgs).getName();
}
@Provides
@org.jclouds.vcloud.endpoints.Org
@Singleton
protected Supplier<Map<String, NamedResource>> provideVDCtoORG(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
final OrgNameToOrgSupplier supplier) {
return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, NamedResource>>(authException,
seconds, new Supplier<Map<String, NamedResource>>() {
@Override
public Map<String, NamedResource> get() {
return supplier.get();
}
});
}
@Provides
@Singleton
protected Supplier<Map<URI, ? extends org.jclouds.vcloud.domain.VDC>> provideURIToVDC(
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final URItoVDC supplier) {
return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<URI, ? extends org.jclouds.vcloud.domain.VDC>>(
authException, seconds, new Supplier<Map<URI, ? extends org.jclouds.vcloud.domain.VDC>>() {
@Override
public Map<URI, ? extends org.jclouds.vcloud.domain.VDC> get() {
return supplier.get();
}
});
}
@Singleton
public static class URItoVDC implements Supplier<Map<URI, ? extends org.jclouds.vcloud.domain.VDC>> {
private final Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> orgVDCMap;
@Inject
URItoVDC(Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> orgVDCMap) {
this.orgVDCMap = orgVDCMap;
}
@Override
public Map<URI, ? extends org.jclouds.vcloud.domain.VDC> get() {
return uniqueIndex(
concat(transform(
orgVDCMap.get().values(),
new Function<Map<String, ? extends org.jclouds.vcloud.domain.VDC>, Iterable<? extends org.jclouds.vcloud.domain.VDC>>() {
@Override
public Iterable<? extends org.jclouds.vcloud.domain.VDC> apply(
Map<String, ? extends org.jclouds.vcloud.domain.VDC> from) {
return from.values();
}
})), new Function<org.jclouds.vcloud.domain.VDC, URI>() {
@Override
public URI apply(org.jclouds.vcloud.domain.VDC from) {
return from.getId();
}
});
}
}
@Provides
@org.jclouds.vcloud.endpoints.Org
@Singleton
protected Iterable<NamedResource> provideOrgs(Supplier<VCloudSession> cache, @Named(PROPERTY_IDENTITY) String user) {
VCloudSession discovery = cache.get();
checkState(discovery.getOrgs().size() > 0, "No orgs present for user: " + user);
return discovery.getOrgs().values();
}
protected AtomicReference<AuthorizationException> authException = new AtomicReference<AuthorizationException>();
final static Function<NamedResource, String> name = new Function<NamedResource, String>() {
@Override
public String apply(NamedResource from) {
return from.getName();
}
};
@Provides
@Singleton
@org.jclouds.vcloud.endpoints.VCloudLogin
protected URI provideAuthenticationURI(VCloudVersionsAsyncClient versionService,
@Named(PROPERTY_API_VERSION) String version) throws InterruptedException, ExecutionException,
TimeoutException {
SortedMap<String, URI> versions = versionService.getSupportedVersions().get(180, TimeUnit.SECONDS);
checkState(versions.size() > 0, "No versions present");
checkState(versions.containsKey(version), "version " + version + " not present in: " + versions);
return versions.get(version);
}
@Singleton
private static class OrgNameToOrgSupplier implements Supplier<Map<String, NamedResource>> {
private final Supplier<VCloudSession> sessionSupplier;
@SuppressWarnings("unused")
@Inject
OrgNameToOrgSupplier(Supplier<VCloudSession> sessionSupplier) {
this.sessionSupplier = sessionSupplier;
}
@Override
public Map<String, NamedResource> get() {
return sessionSupplier.get().getOrgs();
}
}
@Provides
@Singleton
protected VCloudVersionsAsyncClient provideVCloudVersions(AsyncClientFactory factory) {
return factory.create(VCloudVersionsAsyncClient.class);
}
@Provides
@org.jclouds.vcloud.endpoints.Catalog
@Singleton
protected String provideCatalogName(
Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>> catalogs) {
return getLast(getLast(catalogs.get().values()).keySet());
}
@Provides
@Named(PROPERTY_VCLOUD_DEFAULT_NETWORK)
@Singleton
String provideDefaultNetworkString(@Network URI network) {
return network.toASCIIString();
}
@Provides
@Network
@Singleton
protected URI provideDefaultNetwork(CommonVCloudClient client) {
if (authException.get() != null)
throw authException.get();
try {
org.jclouds.vcloud.domain.VDC vDC = client.findVDCInOrgNamed(null, null);
Map<String, NamedResource> networks = vDC.getAvailableNetworks();
checkState(networks.size() > 0, "No networks present in vDC: " + vDC.getName());
return get(networks.values(), 0).getId();
} catch (AuthorizationException e) {
authException.set(e);
throw e;
}
}
@Provides
@Singleton
protected Org provideOrg(CommonVCloudClient discovery) {
if (authException.get() != null)
throw authException.get();
try {
return discovery.findOrgNamed(null);
} catch (AuthorizationException e) {
authException.set(e);
throw e;
}
}
@Provides
@Singleton
protected Predicate<URI> successTester(Injector injector,
@Named(PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED) long completed) {
return new RetryablePredicate<URI>(injector.getInstance(TaskSuccess.class), completed);
}
@Provides
@Singleton
protected Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>> provideOrgCatalogItemMapSupplierCache(
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrgCatalogSupplier supplier) {
return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>>(
authException, seconds,
new Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>>() {
@Override
public Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>> get() {
return supplier.get();
}
});
}
@Provides
@Singleton
protected Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> provideOrgVDCSupplierCache(
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrgVDCSupplier supplier) {
return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>>(
authException, seconds,
new Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>>() {
@Override
public Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>> get() {
return supplier.get();
}
});
}
@Singleton
public static class OrgVDCSupplier implements
Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> {
protected final Supplier<Map<String, ? extends Org>> orgSupplier;
private final Function<Org, Iterable<? extends org.jclouds.vcloud.domain.VDC>> allVDCsInOrg;
@Inject
protected OrgVDCSupplier(Supplier<Map<String, ? extends Org>> orgSupplier,
Function<Org, Iterable<? extends org.jclouds.vcloud.domain.VDC>> allVDCsInOrg) {
this.orgSupplier = orgSupplier;
this.allVDCsInOrg = allVDCsInOrg;
}
@Override
public Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>> get() {
return transformValues(
transformValues(orgSupplier.get(), allVDCsInOrg),
new Function<Iterable<? extends org.jclouds.vcloud.domain.VDC>, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>() {
@Override
public Map<String, ? extends org.jclouds.vcloud.domain.VDC> apply(
Iterable<? extends org.jclouds.vcloud.domain.VDC> from) {
return uniqueIndex(from, name);
}
});
}
}
@Singleton
public static class OrgCatalogItemSupplier implements
Supplier<Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>>> {
protected final Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>> catalogSupplier;
private final Function<org.jclouds.vcloud.domain.Catalog, Iterable<? extends CatalogItem>> allCatalogItemsInCatalog;
@Inject
protected OrgCatalogItemSupplier(
Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>>> catalogSupplier,
Function<org.jclouds.vcloud.domain.Catalog, Iterable<? extends CatalogItem>> allCatalogItemsInCatalog) {
this.catalogSupplier = catalogSupplier;
this.allCatalogItemsInCatalog = allCatalogItemsInCatalog;
}
@Override
public Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>> get() {
return transformValues(
catalogSupplier.get(),
new Function<Map<String, ? extends org.jclouds.vcloud.domain.Catalog>, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>>() {
@Override
public Map<String, Map<String, ? extends CatalogItem>> apply(
Map<String, ? extends org.jclouds.vcloud.domain.Catalog> from) {
return transformValues(
from,
new Function<org.jclouds.vcloud.domain.Catalog, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>() {
@Override
public Map<String, ? extends CatalogItem> apply(
org.jclouds.vcloud.domain.Catalog from) {
return uniqueIndex(allCatalogItemsInCatalog.apply(from), name);
}
});
}
});
}
}
@Provides
@Singleton
protected Supplier<Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>>> provideOrgCatalogItemSupplierCache(
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrgCatalogItemSupplier supplier) {
return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>>>(
authException, seconds,
new Supplier<Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>>>() {
@Override
public Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>> get() {
return supplier.get();
}
});
}
@Provides
@TasksList
@Singleton
protected URI provideDefaultTasksList(Org org) {
return org.getTasksList().getId();
}
@Override
protected void bindErrorHandlers() {
bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(ParseVCloudErrorFromHttpResponse.class);
bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(ParseVCloudErrorFromHttpResponse.class);
bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(ParseVCloudErrorFromHttpResponse.class);
}
}

View File

@ -0,0 +1,41 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.config;
import org.jclouds.http.RequiresHttp;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.vcloud.VCloudExpressAsyncClient;
import org.jclouds.vcloud.VCloudExpressClient;
/**
* Configures the VCloud authentication service connection, including logging and http transport.
*
* @author Adrian Cole
*/
@RequiresHttp
@ConfiguresRestClient
public class VCloudExpressRestClientModule extends
BaseVCloudExpressRestClientModule<VCloudExpressClient, VCloudExpressAsyncClient> {
public VCloudExpressRestClientModule() {
super(VCloudExpressClient.class, VCloudExpressAsyncClient.class);
}
}

View File

@ -25,8 +25,7 @@ import org.jclouds.vcloud.VCloudAsyncClient;
import org.jclouds.vcloud.VCloudClient;
/**
* Configures the VCloud authentication service connection, including logging
* and http transport.
* Configures the VCloud authentication service connection, including logging and http transport.
*
* @author Adrian Cole
*/

View File

@ -0,0 +1,69 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.base.CaseFormat;
/**
* The AllocationModel element defines how resources are allocated in a vDC.
*/
public enum AllocationModel {
/**
* Resources are committed to a vDC only when vApps are created in it
*/
ALLOCATION_VAPP,
/**
* Only a percentage of the resources you allocate are committed to the organization vDC.
*/
ALLOCATION_POOL,
/**
* All the resources you allocate are committed as a pool to the organization vDC. vApps in vDCs
* that support this allocation model can specify values for resource and limit.
*/
RESERVATION_POOL,
/**
* The VCloud API returned a model unsupported in the version 1.0 spec.
*/
UNRECOGNIZED_MODEL;
public String value() {
switch (this) {
case ALLOCATION_VAPP:
return "AllocationVApp";
case ALLOCATION_POOL:
return "AllocationPool";
case RESERVATION_POOL:
return "ReservationPool";
default:
return "UnrecognizedModel";
}
}
@Override
public String toString() {
return value();
}
public static AllocationModel fromValue(String model) {
return valueOf(CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(model, "model")));
}
}

View File

@ -19,39 +19,60 @@
package org.jclouds.vcloud.domain;
/**
* reports storage resource consumption in a vDC.
*
* @author Adrian Cole
*/
public class Capacity {
private final String units;
private final int allocated;
private final long allocated;
private final long limit;
private final int used;
private final long overhead;
public Capacity(String units, int allocated, int used) {
public Capacity(String units, long allocated, long limit, int used, long overhead) {
this.units = units;
this.limit = limit;
this.allocated = allocated;
this.used = used;
this.overhead = overhead;
}
public String getUnits() {
return units;
}
public int getAllocated() {
public long getAllocated() {
return allocated;
}
public long getLimit() {
return limit;
}
/**
* percentage of the allocation in use.
*/
public int getUsed() {
return used;
}
/**
* number of Units allocated to vShield Manager virtual machines provisioned from this vDC.
*/
public long getOverhead() {
return overhead;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + allocated;
result = prime * result + (int) (allocated ^ (allocated >>> 32));
result = prime * result + (int) (limit ^ (limit >>> 32));
result = prime * result + (int) (overhead ^ (overhead >>> 32));
result = prime * result + ((units == null) ? 0 : units.hashCode());
result = prime * result + used;
return result;
@ -68,6 +89,10 @@ public class Capacity {
Capacity other = (Capacity) obj;
if (allocated != other.allocated)
return false;
if (limit != other.limit)
return false;
if (overhead != other.overhead)
return false;
if (units == null) {
if (other.units != null)
return false;
@ -77,4 +102,10 @@ public class Capacity {
return false;
return true;
}
@Override
public String toString() {
return "[allocated=" + allocated + ", limit=" + limit + ", overhead=" + overhead + ", units=" + units + ", used="
+ used + "]";
}
}

View File

@ -19,8 +19,11 @@
package org.jclouds.vcloud.domain;
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
import org.jclouds.vcloud.domain.internal.CatalogImpl;
import com.google.inject.ImplementedBy;
@ -31,7 +34,35 @@ import com.google.inject.ImplementedBy;
@org.jclouds.vcloud.endpoints.Catalog
@ImplementedBy(CatalogImpl.class)
public interface Catalog extends NamedResource, Map<String, NamedResource> {
/**
* Reference to the org containing this vDC.
*
* @since vcloud api 1.0
* @return org, or null if this is a version before 1.0 where the org isn't present
*/
NamedResource getOrg();
/**
* optional description
*
* @since vcloud api 0.8
*/
@Nullable
String getDescription();
/**
* readonly element, true if the catalog is published
*
* @since vcloud api 1.0
*/
@Nullable
boolean isPublished();
/**
* readonly container for Task elements. Each element in the container represents a queued,
* running, or failed task owned by this object.
*
* @since vcloud api 1.0
*/
List<Task> getTasks();
}

View File

@ -1,107 +0,0 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.base.CaseFormat;
/**
* @author Adrian Cole
*/
public class FirewallRule {
public static enum Policy {
DENY, ALLOW;
public String value() {
return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, name());
}
@Override
public String toString() {
return value();
}
public static Policy fromValue(String policy) {
return valueOf(CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(policy,
"policy")));
}
}
public static enum Protocol {
TCP, UDP, ICMP;
public String value() {
return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, name());
}
@Override
public String toString() {
return value();
}
public static Protocol fromValue(String protocol) {
return valueOf(CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(
protocol, "protocol")));
}
}
private final Policy policy;
private final Protocol protocol;
private final String sourceIP;
private final String sourcePort;
public FirewallRule(Policy policy, Protocol protocol, String sourceIP, String sourcePort) {
this.policy = policy;
this.protocol = protocol;
this.sourceIP = sourceIP;
this.sourcePort = sourcePort;
}
/**
* One of deny, allow
*/
public Policy getPolicy() {
return policy;
}
/**
* An attribute that specifies the protocol to which the rule applies. One of tcp, udp, icmp
*/
public Protocol getProtocol() {
return protocol;
}
/**
* An IP address to which this rule applies
*/
public String getSourceIP() {
return sourceIP;
}
/**
* An IP port or port range to which this rule applies. A value of * specifies all ports.
*/
public String getSourcePort() {
return sourcePort;
}
}

View File

@ -0,0 +1,53 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.base.CaseFormat;
/**
* The MappingMode element specifies how IP address mapping is implemented by the NAT service.
*
*/
public enum MappingMode {
/**
* the external IP address is specified in the ExternalIP element
*/
MANUAL,
/**
* the external IP address is assigned automatically
*/
AUTOMATIC;
public String value() {
return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, name());
}
@Override
public String toString() {
return value();
}
public static MappingMode fromValue(String mode) {
return valueOf(CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(mode, "mode")));
}
}

View File

@ -1,119 +0,0 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.domain;
/**
* Specifies a set of Network Address Translation rules using a pair of IP addresses and a pair of
* IP port numbers.
*
* @author Adrian Cole
*/
public class NatRule {
private final String externalIP;
private final Integer externalPort;
private final String internalIP;
private final Integer internalPort;
public NatRule(String externalIP, Integer externalPort, String IntegerernalIP,
Integer IntegerernalPort) {
this.externalIP = externalIP;
this.externalPort = externalPort;
this.internalIP = IntegerernalIP;
this.internalPort = IntegerernalPort;
}
/**
* The externallyvisible IP address.
*/
public String getExternalIP() {
return externalIP;
}
/**
* The externallyvisible IP port.
*/
public Integer getExternalPort() {
return externalPort;
}
/**
* The Integerernallyvisible (nonroutable) IP address.
*/
public String getInternalIP() {
return internalIP;
}
/**
* The Integerernallyvisible IP port.
*/
public Integer getInternalPort() {
return internalPort;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((externalIP == null) ? 0 : externalIP.hashCode());
result = prime * result + ((externalPort == null) ? 0 : externalPort.hashCode());
result = prime * result + ((internalIP == null) ? 0 : internalIP.hashCode());
result = prime * result + ((internalPort == null) ? 0 : internalPort.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
NatRule other = (NatRule) obj;
if (externalIP == null) {
if (other.externalIP != null)
return false;
} else if (!externalIP.equals(other.externalIP))
return false;
if (externalPort == null) {
if (other.externalPort != null)
return false;
} else if (!externalPort.equals(other.externalPort))
return false;
if (internalIP == null) {
if (other.internalIP != null)
return false;
} else if (!internalIP.equals(other.internalIP))
return false;
if (internalPort == null) {
if (other.internalPort != null)
return false;
} else if (!internalPort.equals(other.internalPort))
return false;
return true;
}
@Override
public String toString() {
return "NatRule [externalIP=" + externalIP + ", externalPort=" + externalPort
+ ", internalIP=" + internalIP + ", internalPort=" + internalPort + "]";
}
}

View File

@ -0,0 +1,90 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.domain;
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
import org.jclouds.vcloud.domain.internal.OrgImpl;
import com.google.inject.ImplementedBy;
/**
* A vCloud organization is a high-level abstraction that provides a unit of administration for
* objects and resources. As viewed by a user, an organization (represented by an Org element) can
* contain Catalog, Network, and vDC elements. If there are any queued, running, or recently
* completed tasks owned by a member of the organization, it also contains a TasksList element. As
* viewed by an administrator, an organization also contains users, groups, and other information
*
* @author Adrian Cole
*/
@ImplementedBy(OrgImpl.class)
public interface Org extends NamedResource {
/**
* optional description
*
* @since vcloud api 0.8
*/
@Nullable
String getDescription();
/**
* full name of the organization
*
* @since vcloud api 1.0
*/
@Nullable
String getFullName();
/**
* @since vcloud api 0.8
*/
Map<String, NamedResource> getCatalogs();
/**
* @since vcloud api 0.8
*/
Map<String, NamedResource> getVDCs();
/**
* If there are any queued, running, or recently completed tasks owned by a member of the
* organization, it also contains a TasksList.
*
* @since vcloud api 0.8
*/
@Nullable
NamedResource getTasksList();
/**
* @since vcloud api 1.0
*/
Map<String, NamedResource> getNetworks();
/**
* readonly container for Task elements. Each element in the container represents a queued,
* running, or failed task owned by this object.
*
* @since vcloud api 1.0
*/
List<Task> getTasks();
}

View File

@ -1,67 +0,0 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.domain;
/**
* @author Adrian Cole
*/
public class Quota {
private final int limit;
private final int used;
public Quota(int limit, int used) {
this.limit = limit;
this.used = used;
}
public int getLimit() {
return limit;
}
public int getUsed() {
return used;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + limit;
result = prime * result + used;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Quota other = (Quota) obj;
if (limit != other.limit)
return false;
if (used != other.used)
return false;
return true;
}
}

View File

@ -21,14 +21,14 @@ package org.jclouds.vcloud.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import org.jclouds.vcloud.VCloudAsyncClient;
import org.jclouds.vcloud.VCloudExpressAsyncClient;
/**
*
* VirtualResource such as disks or CPU
*
* @author Adrian Cole
* @see VCloudAsyncClient#getVApp
* @see VCloudExpressAsyncClient#getVApp
* @see <a href="http://blogs.vmware.com/vapp/2009/11/index.html"/>
*
*/

View File

@ -0,0 +1,225 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.domain;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Objects such as vAppTemplate, vApp, and Vm have a status attribute whose value indicates the
* state of the object. Status for an object, such as a vAppTemplate or vApp, whose Children (Vm
* objects) each have a status of their own, is computed from the status of the Children.
*
* <h2>NOTE</h2>
* <p/>
* The deployment status of an object is indicated by the value of its deployed attribute.
*
* @since vcloud api 0.8
*
* @author Adrian Cole
*/
public enum Status {
/**
* The {@link VAppTemplate}, {@link VApp}, or {@link Vm} could not be created.
*
* @since vcloud api 1.0
*/
ERROR,
/**
* The {@link VAppTemplate}, {@link VApp}, or {@link Vm} is unresolved.
*
* @since vcloud api 0.8
*/
UNRESOLVED,
/**
* The {@link VAppTemplate}, {@link VApp}, or {@link Vm} is resolved.
*
* @since vcloud api 0.8
*/
RESOLVED,
/**
* The object is deployed.
* <p/>
* note that the documentation does not reference use of this.
*
* @since vcloud api 1.0
*/
DEPLOYED,
/**
* The {@link VApp} or {@link Vm} is suspended.
*
* @since vcloud api 0.8
*/
SUSPENDED,
/**
* The {@link VApp} or {@link Vm} is powered on
*
* @since vcloud api 0.8
*/
ON,
/**
* The {@link VApp} or {@link Vm} waiting for user input.
*
* @since vcloud api 1.0
*/
WAITING_FOR_INPUT,
/**
* The {@link VAppTemplate}, {@link VApp}, or {@link Vm} is in an unknown state.
*
* @since vcloud api 1.0
*/
UNKNOWN,
/**
* The {@link VAppTemplate}, {@link VApp}, or {@link Vm} is in an unrecognized state.
*
* @since vcloud api 1.0
*/
UNRECOGNIZED,
/**
* The {@link VAppTemplate}, {@link VApp}, or {@link Vm} is off.
*
* @since vcloud api 0.8
*/
OFF,
/**
* The {@link VApp} or {@link Vm} is in an inconsistent state.
*
* @since vcloud api 1.0
*/
INCONSISTENT,
/**
* The {@link VAppTemplate} or {@link VApp} have children do not all have the same status.
*
* @since vcloud api 1.0
*/
MIXED,
/**
* The {@link VAppTemplate} Upload initiated, OVF descriptor pending
*
* @since vcloud api 1.0
*/
PENDING_DESCRIPTOR,
/**
* The {@link VAppTemplate} Upload initiated, copying contents
*
* @since vcloud api 1.0
*/
COPYING,
/**
* The {@link VAppTemplate} Upload initiated, disk contents pending
*
* @since vcloud api 1.0
*/
PENDING_CONTENTS,
/**
* The {@link VAppTemplate} Upload has been quarantined
*
* @since vcloud api 1.0
*/
QUARANTINED,
/**
* The {@link VAppTemplate} Upload quarantine period has expired
*
* @since vcloud api 1.0
*/
QUARANTINE_EXPIRED;
public String value() {
switch (this) {
case UNRESOLVED:
return "0";
case RESOLVED:
return "1";
case DEPLOYED:
return "2";
case SUSPENDED:
return "3";
case ON:
return "4";
case WAITING_FOR_INPUT:
return "5";
case UNKNOWN:
return "6";
case UNRECOGNIZED:
return "7";
case OFF:
return "8";
case INCONSISTENT:
return "9";
case MIXED:
return "10";
case PENDING_DESCRIPTOR:
return "11";
case COPYING:
return "12";
case PENDING_CONTENTS:
return "13";
case QUARANTINED:
return "14";
case QUARANTINE_EXPIRED:
return "15";
default:
throw new IllegalArgumentException("invalid status:" + this);
}
}
public static Status fromValue(String status) {
return fromValue(Integer.parseInt(checkNotNull(status, "status")));
}
public static Status fromValue(int v) {
switch (v) {
case 0:
return UNRESOLVED;
case 1:
return RESOLVED;
case 2:
return DEPLOYED;
case 3:
return SUSPENDED;
case 4:
return ON;
case 5:
return WAITING_FOR_INPUT;
case 6:
return UNKNOWN;
case 7:
return UNRECOGNIZED;
case 8:
return OFF;
case 9:
return INCONSISTENT;
case 10:
return MIXED;
case 11:
return PENDING_DESCRIPTOR;
case 12:
return COPYING;
case 13:
return PENDING_CONTENTS;
case 14:
return QUARANTINED;
case 15:
return QUARANTINE_EXPIRED;
default:
throw new IllegalArgumentException("invalid status:" + v);
}
}
}

View File

@ -39,7 +39,7 @@ import com.google.inject.ImplementedBy;
public interface VApp extends NamedResource {
NamedResource getVDC();
VAppStatus getStatus();
Status getStatus();
Long getSize();

View File

@ -1,89 +0,0 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.domain;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Indicates the status of the VApp.
*
* @author Adrian Cole
*/
public enum VAppStatus {
/**
* The vApp is unresolved (one or more file references are unavailable in the cloud)
*/
UNRESOLVED,
/**
* The vApp is resolved (all file references are available in the cloud) but not deployed
*/
RESOLVED,
/**
* The vApp is deployed and powered off
*/
OFF,
/**
* The vApp is deployed and suspended
*/
SUSPENDED,
/**
* The vApp is deployed and powered on
*/
ON;
public String value() {
switch (this) {
case UNRESOLVED:
return "0";
case RESOLVED:
return "1";
case OFF:
return "2";
case SUSPENDED:
return "3";
case ON:
return "4";
default:
throw new IllegalArgumentException("invalid status:" + this);
}
}
public static VAppStatus fromValue(String status) {
return fromValue(Integer.parseInt(checkNotNull(status, "status")));
}
public static VAppStatus fromValue(int v) {
switch (v) {
case 0:
return UNRESOLVED;
case 1:
return RESOLVED;
case 2:
return OFF;
case 3:
return SUSPENDED;
case 4:
return ON;
default:
throw new IllegalArgumentException("invalid status:" + v);
}
}
}

View File

@ -25,7 +25,7 @@ package org.jclouds.vcloud.domain;
*/
public interface VAppTemplate extends NamedResource {
VAppStatus getStatus();
Status getStatus();
String getDescription();

View File

@ -17,20 +17,16 @@
* ====================================================================
*/
package org.jclouds.vcloud.hostingdotcom.domain;
package org.jclouds.vcloud.domain;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.hostingdotcom.domain.internal.HostingDotComVAppImpl;
import com.google.inject.ImplementedBy;
import java.util.Map;
/**
*
* @author Adrian Cole
*/
@ImplementedBy(HostingDotComVAppImpl.class)
public interface HostingDotComVApp extends VApp {
public interface VCloudSession {
String getVCloudToken();
String getUsername();
String getPassword();
Map<String, NamedResource> getOrgs();
}

View File

@ -19,33 +19,132 @@
package org.jclouds.vcloud.domain;
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
import org.jclouds.vcloud.domain.internal.VDCImpl;
import com.google.inject.ImplementedBy;
/**
* A vDC is a deployment environment for vApps. A Vdc element provides a user view of a vDC.
*
* @author Adrian Cole
*/
@org.jclouds.vcloud.endpoints.VDC
@ImplementedBy(VDCImpl.class)
public interface VDC extends NamedResource {
/**
* Reference to the org containing this vDC.
*
* @since vcloud api 1.0
* @return org, or null if this is a version before 1.0 where the org isn't present
*/
NamedResource getOrg();
/**
* The creation status of the vDC
*
* @since vcloud api 1.0
*/
VDCStatus getStatus();
/**
* optional description
*
* @since vcloud api 0.8
*/
@Nullable
String getDescription();
/**
* readonly container for Task elements. Each element in the container represents a queued,
* running, or failed task owned by this object.
*
* @since vcloud api 1.0
*/
List<Task> getTasks();
/**
* defines how resources are allocated by the vDC. The value of this element is set by the
* administrator who created the vDC. It is readonly to users.
*
* @since vcloud api 1.0
*/
AllocationModel getAllocationModel();
/**
* defines the storage capacity available in the vDC
*
* @since vcloud api 0.8
* @return null if the provider doesn't support storage capacity
*/
@Nullable
Capacity getStorageCapacity();
/**
* reports CPU resource consumption in a vDC
*
* @since vcloud api 0.8
* @return null if the provider doesn't support cpu capacity
*/
@Nullable
Capacity getCpuCapacity();
/**
* reports memory resource consumption in a vDC
*
* @since vcloud api 0.8
* @return null if the provider doesn't support memory capacity
*/
@Nullable
Capacity getMemoryCapacity();
Quota getInstantiatedVmsQuota();
Quota getDeployedVmsQuota();
Map<String, NamedResource> getAvailableNetworks();
/**
* container for ResourceEntity elements
*
* @since vcloud api 0.8
*/
Map<String, NamedResource> getResourceEntities();
/**
* container for OrgNetwork elements that represent organization networks contained by the vDC
*
* @since vcloud api 0.8
*/
Map<String, NamedResource> getAvailableNetworks();
/**
* maximum number of virtual NICs allowed in this vDC. Defaults to 0, which specifies an
* unlimited number.
*
* @since vcloud api 1.0
*/
int getNicQuota();
/**
* maximum number of OrgNetwork objects that can be deployed in this vDC. Defaults to 0, which
* specifies an unlimited number.
*
* @since vcloud api 1.0
*/
int getNetworkQuota();
/**
* maximum number of virtual machines that can be deployed in this vDC. Defaults to 0, which
* specifies an unlimited number.
*
* @since vcloud api 0.8
*/
int getVmQuota();
/**
* true if this vDC is enabled
*
* @since vcloud api 1.0
*/
boolean isEnabled();
}

View File

@ -0,0 +1,60 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.domain;
/**
* The creation status of the vDC
*
* @see VDC#getStatus
*/
public enum VDCStatus {
CREATION_FAILED, NOT_READY, READY, UNKNOWN, UNRECOGNIZED_STATUS;
public int value() {
switch (this) {
case CREATION_FAILED:
return -1;
case NOT_READY:
return 0;
case READY:
return 1;
case UNKNOWN:
return 2;
default:
return 3;
}
}
public static VDCStatus fromValue(int status) {
switch (status) {
case -1:
return CREATION_FAILED;
case 0:
return NOT_READY;
case 1:
return READY;
case 2:
return UNKNOWN;
default:
return UNRECOGNIZED_STATUS;
}
}
}

View File

@ -51,50 +51,48 @@ public class VirtualSystem {
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + id;
result = prime * result
+ ((identifier == null) ? 0 : identifier.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((type == null) ? 0 : type.hashCode());
return result;
}
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + id;
result = prime * result + ((identifier == null) ? 0 : identifier.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((type == null) ? 0 : type.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
VirtualSystem other = (VirtualSystem) obj;
if (id != other.id)
return false;
if (identifier == null) {
if (other.identifier != null)
return false;
} else if (!identifier.equals(other.identifier))
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
if (type == null) {
if (other.type != null)
return false;
} else if (!type.equals(other.type))
return false;
return true;
}
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
VirtualSystem other = (VirtualSystem) obj;
if (id != other.id)
return false;
if (identifier == null) {
if (other.identifier != null)
return false;
} else if (!identifier.equals(other.identifier))
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
if (type == null) {
if (other.type != null)
return false;
} else if (!type.equals(other.type))
return false;
return true;
}
@Override
public String toString() {
return "VirtualSystem [id=" + id + ", identifier=" + identifier + ", name=" + name
+ ", type=" + type + "]";
return "VirtualSystem [id=" + id + ", identifier=" + identifier + ", name=" + name + ", type=" + type + "]";
}
}

View File

@ -23,12 +23,15 @@ import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.Task;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.inject.internal.Nullable;
/**
@ -42,26 +45,81 @@ public class CatalogImpl extends LinkedHashMap<String, NamedResource> implements
/** The serialVersionUID */
private static final long serialVersionUID = 8464716396538298809L;
private final String name;
private final String description;
private final String type;
private final URI id;
private final NamedResource org;
@Nullable
private final String description;
private final List<Task> tasks = Lists.newArrayList();
private final boolean published;
public CatalogImpl(String name, URI id, @Nullable String description, Map<String, NamedResource> contents) {
public CatalogImpl(String name, String type, URI id, NamedResource org, @Nullable String description,
Map<String, NamedResource> contents, Iterable<Task> tasks, boolean published) {
this.name = checkNotNull(name, "name");
this.type = checkNotNull(type, "type");
this.org = org;// TODO: once <1.0 is killed check not null
this.description = description;
this.id = checkNotNull(id, "id");
putAll(checkNotNull(contents, "contents"));
Iterables.addAll(this.tasks, checkNotNull(tasks, "tasks"));
this.published = published;
}
/**
* {@inheritDoc}
*/
@Override
public URI getId() {
return id;
}
/**
* {@inheritDoc}
*/
@Override
public String getName() {
return name;
}
/**
* {@inheritDoc}
*/
@Override
public NamedResource getOrg() {
return org;
}
/**
* {@inheritDoc}
*/
public String getDescription() {
return description;
}
/**
* {@inheritDoc}
*/
@Override
public String getType() {
return type;
}
/**
* {@inheritDoc}
*/
@Override
public List<Task> getTasks() {
return tasks;
}
/**
* {@inheritDoc}
*/
@Override
public boolean isPublished() {
return published;
}
@Override
public int hashCode() {
final int prime = 31;
@ -69,6 +127,9 @@ public class CatalogImpl extends LinkedHashMap<String, NamedResource> implements
result = prime * result + ((description == null) ? 0 : description.hashCode());
result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((org == null) ? 0 : org.hashCode());
result = prime * result + ((tasks == null) ? 0 : tasks.hashCode());
result = prime * result + ((type == null) ? 0 : type.hashCode());
return result;
}
@ -96,18 +157,24 @@ public class CatalogImpl extends LinkedHashMap<String, NamedResource> implements
return false;
} else if (!name.equals(other.name))
return false;
if (org == null) {
if (other.org != null)
return false;
} else if (!org.equals(other.org))
return false;
if (tasks == null) {
if (other.tasks != null)
return false;
} else if (!tasks.equals(other.tasks))
return false;
if (type == null) {
if (other.type != null)
return false;
} else if (!type.equals(other.type))
return false;
return true;
}
public String getDescription() {
return description;
}
@Override
public String getType() {
return VCloudMediaType.CATALOG_XML;
}
@Override
public int compareTo(NamedResource o) {
return (this == o) ? 0 : getId().compareTo(o.getId());

Some files were not shown because too many files have changed in this diff Show More