Merge branch 'master' of github.com:jclouds/jclouds

This commit is contained in:
Lili Nader 2010-08-23 11:44:57 -07:00
commit ec1d97ec16
210 changed files with 6697 additions and 7332 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

@ -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

@ -1,87 +1,87 @@
/**
*
* 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.compute.domain;
import java.util.Map;
import java.util.Set;
import javax.annotation.Nullable;
import org.jclouds.compute.domain.internal.NodeMetadataImpl;
import org.jclouds.domain.Credentials;
import com.google.inject.ImplementedBy;
/**
* @author Adrian Cole
* @author Ivan Meredith
*/
@ImplementedBy(NodeMetadataImpl.class)
public interface NodeMetadata extends ComputeMetadata {
/**
* Tag used for all resources that belong to the same logical group. run, destroy commands are
* scoped to tag.
*
* @return tag for this node, or null, if not a part of a group
*
*/
String getTag();
/**
*
* The id of the image this node was created from, if possible to correlate.
*/
@Nullable
String getImageId();
/**
*
* The operating system this node is running, if possible to determine.
*/
@Nullable
OperatingSystem getOperatingSystem();
/**
* Current State of the node
*/
NodeState getState();
/**
* All public IP addresses, potentially including shared ips.
*/
Set<String> getPublicAddresses();
/**
* All private IP addresses.
*/
Set<String> getPrivateAddresses();
/**
* If possible, these are returned upon all detail requests. However, it is often the case that
* credentials are only available at "run" time.
*/
Credentials getCredentials();
/**
* Other variables present that the provider supports
*/
Map<String, String> getExtra();
/**
*
* 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.compute.domain;
import java.util.Map;
import java.util.Set;
import javax.annotation.Nullable;
import org.jclouds.compute.domain.internal.NodeMetadataImpl;
import org.jclouds.domain.Credentials;
import com.google.inject.ImplementedBy;
/**
* @author Adrian Cole
* @author Ivan Meredith
*/
@ImplementedBy(NodeMetadataImpl.class)
public interface NodeMetadata extends ComputeMetadata {
/**
* Tag used for all resources that belong to the same logical group. run, destroy commands are
* scoped to tag.
*
* @return tag for this node, or null, if not a part of a group
*
*/
String getTag();
/**
*
* The id of the image this node was created from, if possible to correlate.
*/
@Nullable
String getImageId();
/**
*
* The operating system this node is running, if possible to determine.
*/
@Nullable
OperatingSystem getOperatingSystem();
/**
* Current State of the node
*/
NodeState getState();
/**
* All public IP addresses, potentially including shared ips.
*/
Set<String> getPublicAddresses();
/**
* All private IP addresses.
*/
Set<String> getPrivateAddresses();
/**
* If possible, these are returned upon all detail requests. However, it is often the case that
* credentials are only available at "run" time.
*/
Credentials getCredentials();
/**
* Other variables present that the provider supports
*/
Map<String, String> getExtra();
}

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

@ -35,7 +35,6 @@ import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.predicates.NodePredicates;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.compute.strategy.DestroyLoadBalancerStrategy;
import org.jclouds.compute.strategy.ListLoadBalancersStrategy;
import org.jclouds.compute.strategy.LoadBalanceNodesStrategy;
import org.jclouds.domain.Location;
import org.jclouds.http.handlers.BackoffLimitedRetryHandler;
@ -44,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;
@ -69,23 +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 ListLoadBalancersStrategy listLoadBalancersStrategy;
protected final BackoffLimitedRetryHandler backoffLimitedRetryHandler;
@Inject
protected BaseLoadBalancerService(ComputeServiceContext context,
LoadBalanceNodesStrategy loadBalancerStrategy,
protected BaseLoadBalancerService(ComputeServiceContext context, LoadBalanceNodesStrategy loadBalancerStrategy,
DestroyLoadBalancerStrategy destroyLoadBalancerStrategy,
ListLoadBalancersStrategy listLoadBalancersStrategy,
// ListLoadBalancersStrategy listLoadBalancersStrategy,
BackoffLimitedRetryHandler backoffLimitedRetryHandler) {
this.context = checkNotNull(context, "context");
this.loadBalancerStrategy = checkNotNull(loadBalancerStrategy, "loadBalancerStrategy");
this.destroyLoadBalancerStrategy = checkNotNull(destroyLoadBalancerStrategy,
"destroyLoadBalancerStrategy");
this.listLoadBalancersStrategy = checkNotNull(listLoadBalancersStrategy,
"listLoadBalancersStrategy");
this.backoffLimitedRetryHandler = checkNotNull(backoffLimitedRetryHandler,
"backoffLimitedRetryHandler");
this.destroyLoadBalancerStrategy = checkNotNull(destroyLoadBalancerStrategy, "destroyLoadBalancerStrategy");
// this.listLoadBalancersStrategy = checkNotNull(listLoadBalancersStrategy,
// "listLoadBalancersStrategy");
this.backoffLimitedRetryHandler = checkNotNull(backoffLimitedRetryHandler, "backoffLimitedRetryHandler");
}
/**
@ -97,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();
@ -117,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);
}
@ -135,11 +131,12 @@ public class BaseLoadBalancerService implements LoadBalancerService {
boolean successful = destroyLoadBalancerStrategy.execute(loadBalancer);
logger.debug("<< destroyed load balancer(%s) success(%s)", loadBalancer, successful);
}
public Set<String> listLoadBalancers()
{
Set<String> loadBalancerSet = listLoadBalancersStrategy.execute();
return loadBalancerSet;
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

@ -19,14 +19,12 @@
package org.jclouds.http.config;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.cert.X509Certificate;
import java.util.Map;
import javax.annotation.Resource;
import javax.inject.Named;
import javax.inject.Inject;
import javax.inject.Singleton;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext;
@ -40,10 +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.Provides;
import com.google.inject.Scopes;
import com.google.inject.TypeLiteral;
import com.google.inject.name.Names;
/**
* Configures {@link JavaUrlHttpCommandExecutorService}.
@ -65,6 +66,9 @@ public class JavaUrlHttpCommandExecutorServiceModule extends AbstractModule {
bind(HostnameVerifier.class).to(LogToMapHostnameVerifier.class);
bind(TransformingHttpCommandExecutorService.class).to(TransformingHttpCommandExecutorServiceImpl.class).in(
Scopes.SINGLETON);
bind(new TypeLiteral<Supplier<SSLContext>>() {
}).annotatedWith(Names.named("untrusted")).to(new TypeLiteral<UntrustedSSLContextSupplier>() {
});
}
/**
@ -86,14 +90,28 @@ public class JavaUrlHttpCommandExecutorServiceModule extends AbstractModule {
}
}
@Provides
@Singleton
@Named("untrusted")
SSLContext provideUntrustedSSLContext(TrustAllCerts trustAllCerts) throws NoSuchAlgorithmException,
KeyManagementException {
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, new TrustManager[] { trustAllCerts }, new SecureRandom());
return sc;
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;
}
}
}
/**

View File

@ -44,7 +44,6 @@ import java.util.concurrent.ExecutorService;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Provider;
import javax.inject.Singleton;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
@ -64,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;
@ -79,7 +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 Provider<SSLContext> untrustedSSLContextProvider;
private final Supplier<SSLContext> untrustedSSLContextProvider;
private final HostnameVerifier verifier;
private final Field methodField;
@ -88,7 +88,7 @@ public class JavaUrlHttpCommandExecutorService extends BaseHttpCommandExecutorSe
@Named(Constants.PROPERTY_IO_WORKER_THREADS) ExecutorService ioWorkerExecutor,
DelegatingRetryHandler retryHandler, IOExceptionRetryHandler ioRetryHandler,
DelegatingErrorHandler errorHandler, HttpWire wire, HostnameVerifier verifier,
@Named("untrusted") Provider<SSLContext> untrustedSSLContextProvider) throws SecurityException,
@Named("untrusted") Supplier<SSLContext> untrustedSSLContextProvider) throws SecurityException,
NoSuchFieldException {
super(utils, ioWorkerExecutor, retryHandler, ioRetryHandler, errorHandler, wire);
if (utils.getMaxConnections() > 0)

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

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

@ -51,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;
@ -119,7 +120,7 @@ public class BackoffLimitedRetryHandlerTest {
public boolean verify(String hostname, SSLSession session) {
return false;
}
}, new Provider<SSLContext>() {
}, new Supplier<SSLContext>() {
@Override
public SSLContext get() {

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

@ -428,7 +428,7 @@
<encoding>${sourceEncoding}</encoding>
<quiet>true</quiet>
<links>
<link>http://download.oracle.com/docs/cd/E17409_01/javase/6/docs/api/</link>
<link>http://download.oracle.com/javase/6/docs/api/</link>
</links>
<footer><![CDATA[
<!-- Google Analytics -->

View File

@ -1,58 +1,58 @@
/**
*
* 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.rimuhosting.miro.compute;
import static org.testng.Assert.assertEquals;
import org.jclouds.compute.BaseComputeServiceLiveTest;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.domain.Template;
import org.jclouds.ssh.jsch.config.JschSshClientModule;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
/**
* @author Ivan Meredith
*/
@Test(groups = "live", sequential = true, testName = "rimuhosting.RimuHostingNodeServiceLiveTest")
public class RimuHostingComputeServiceLiveTest extends BaseComputeServiceLiveTest {
@BeforeClass
@Override
public void setServiceDefaults() {
provider = "rimuhosting";
tag = "rimuhosting.jclouds";
}
@Test
public void testTemplateBuilder() {
Template defaultTemplate = client.templateBuilder().build();
assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), false);
assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU);
assertEquals(defaultTemplate.getLocation().getId(), "DCDALLAS");
assertEquals(defaultTemplate.getSize().getProviderId(), "MIRO1B");
assertEquals(defaultTemplate.getSize().getCores(), 1.0d);
}
@Override
protected JschSshClientModule getSshModule() {
return new JschSshClientModule();
}
/**
*
* 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.rimuhosting.miro.compute;
import static org.testng.Assert.assertEquals;
import org.jclouds.compute.BaseComputeServiceLiveTest;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.domain.Template;
import org.jclouds.ssh.jsch.config.JschSshClientModule;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
/**
* @author Ivan Meredith
*/
@Test(groups = "live", sequential = true, testName = "rimuhosting.RimuHostingNodeServiceLiveTest")
public class RimuHostingComputeServiceLiveTest extends BaseComputeServiceLiveTest {
@BeforeClass
@Override
public void setServiceDefaults() {
provider = "rimuhosting";
tag = "rimuhosting.jclouds";
}
@Test
public void testTemplateBuilder() {
Template defaultTemplate = client.templateBuilder().build();
assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), false);
assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU);
assertEquals(defaultTemplate.getLocation().getId(), "DCDALLAS");
assertEquals(defaultTemplate.getSize().getProviderId(), "MIRO1B");
assertEquals(defaultTemplate.getSize().getCores(), 1.0d);
}
@Override
protected JschSshClientModule getSshModule() {
return new JschSshClientModule();
}
}

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

@ -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 BlueLockVCloudDirectorComputeClient extends BaseVCloudComputeClient {
public class BlueLockVCloudDirectorComputeClient extends VCloudComputeClientImpl {
private final PopulateDefaultLoginCredentialsForImageStrategy credentialsProvider;
@Inject
protected BlueLockVCloudDirectorComputeClient(PopulateDefaultLoginCredentialsForImageStrategy credentialsProvider,
VCloudClient client, Predicate<URI> successTester, Map<VAppStatus, NodeState> vAppStatusToNodeState) {
VCloudClient client, Predicate<URI> successTester, Map<Status, NodeState> vAppStatusToNodeState) {
super(client, successTester, vAppStatusToNodeState);
this.credentialsProvider = credentialsProvider;
}

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.VCloudExpressClient;
import org.jclouds.vcloud.compute.BaseVCloudExpressComputeClient;
import org.jclouds.vcloud.compute.internal.VCloudExpressComputeClientImpl;
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 BlueLockVCloudExpressComputeClient extends BaseVCloudExpressComputeClient {
public class BlueLockVCloudExpressComputeClient extends VCloudExpressComputeClientImpl {
private final PopulateDefaultLoginCredentialsForImageStrategy credentialsProvider;
@Inject
protected BlueLockVCloudExpressComputeClient(PopulateDefaultLoginCredentialsForImageStrategy credentialsProvider,
VCloudExpressClient client, Predicate<URI> successTester, Map<VAppStatus, NodeState> vAppStatusToNodeState) {
VCloudExpressClient client, Predicate<URI> successTester, Map<Status, NodeState> vAppStatusToNodeState) {
super(client, successTester, vAppStatusToNodeState);
this.credentialsProvider = credentialsProvider;
}

View File

@ -29,10 +29,10 @@ import javax.inject.Named;
import org.jclouds.http.RequiresHttp;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.vcloud.VCloudExpressClient;
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;
@ -47,7 +47,7 @@ import com.google.common.collect.Iterables;
public class BlueLockVCloudExpressRestClientModule extends VCloudExpressRestClientModule {
@Override
protected URI provideDefaultNetwork(VCloudExpressClient client) {
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());
@ -62,7 +62,7 @@ public class BlueLockVCloudExpressRestClientModule extends VCloudExpressRestClie
}
@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

@ -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,66 +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.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.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.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.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;
@ -86,258 +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#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(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#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);
public interface VCloudAsyncClient extends CommonVCloudAsyncClient {
/**
* @see VCloudClient#instantiateVAppTemplateInVDC
@ -349,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
@ -363,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.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.options.CloneVAppOptions;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
@ -48,140 +38,8 @@ import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
* @author Adrian Cole
*/
@Timeout(duration = 300, timeUnit = TimeUnit.SECONDS)
public interface VCloudClient {
public interface VCloudClient extends 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);
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);
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);
VApp instantiateVAppTemplateInVDC(URI vDC, URI template, String appName, InstantiateVAppTemplateOptions... options);

View File

@ -19,28 +19,20 @@
package org.jclouds.vcloud;
import static org.jclouds.vcloud.VCloudExpressMediaType.CATALOGITEM_XML;
import static org.jclouds.vcloud.VCloudExpressMediaType.CATALOG_XML;
import static org.jclouds.vcloud.VCloudExpressMediaType.NETWORK_XML;
import static org.jclouds.vcloud.VCloudExpressMediaType.ORG_XML;
import static org.jclouds.vcloud.VCloudExpressMediaType.TASKSLIST_XML;
import static org.jclouds.vcloud.VCloudExpressMediaType.TASK_XML;
import static org.jclouds.vcloud.VCloudExpressMediaType.VAPPTEMPLATE_XML;
import static org.jclouds.vcloud.VCloudExpressMediaType.VAPP_XML;
import static org.jclouds.vcloud.VCloudExpressMediaType.VDC_XML;
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.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;
@ -49,38 +41,18 @@ 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.domain.network.OrgNetwork;
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
import org.jclouds.vcloud.functions.OrganizationNameAndCatalogNameToEndpoint;
import org.jclouds.vcloud.functions.OrganizationNameAndTasksListNameToEndpoint;
import org.jclouds.vcloud.functions.OrganizationNameAndVDCNameToEndpoint;
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.OrganizationHandler;
import org.jclouds.vcloud.xml.OrgNetworkFromVCloudExpressNetworkHandler;
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 +60,33 @@ 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 VCloudExpressAsyncClient {
public interface VCloudExpressAsyncClient extends CommonVCloudAsyncClient {
/**
* @see VCloudExpressClient#getDefaultOrganization
*/
@Deprecated
@GET
@Endpoint(Org.class)
@Consumes(ORG_XML)
@XMLResponseParser(OrganizationHandler.class)
ListenableFuture<? extends Organization> getDefaultOrganization();
/**
* @see VCloudExpressClient#getOrganization
*/
@GET
@XMLResponseParser(OrganizationHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@Consumes(ORG_XML)
ListenableFuture<? extends Organization> getOrganization(@EndpointParam URI orgId);
/**
* @see VCloudExpressClient#getOrganizationNamed
*/
@GET
@XMLResponseParser(OrganizationHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@Consumes(ORG_XML)
ListenableFuture<? extends Organization> findOrganizationNamed(
@Nullable @EndpointParam(parser = OrgNameToEndpoint.class) String orgName);
/**
* @see VCloudExpressClient#getDefaultCatalog
*/
@Deprecated
@GET
@Endpoint(org.jclouds.vcloud.endpoints.Catalog.class)
@Consumes(CATALOG_XML)
@XMLResponseParser(CatalogHandler.class)
ListenableFuture<? extends Catalog> getDefaultCatalog();
/**
* @see VCloudExpressClient#getCatalog
*/
@GET
@XMLResponseParser(CatalogHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@Consumes(CATALOG_XML)
ListenableFuture<? extends Catalog> getCatalog(@EndpointParam URI catalogId);
/**
* @see VCloudExpressClient#findCatalogInOrgNamed
*/
@GET
@XMLResponseParser(CatalogHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@Consumes(CATALOG_XML)
ListenableFuture<? extends Catalog> findCatalogInOrgNamed(
@Nullable @EndpointParam(parser = OrganizationNameAndCatalogNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrganizationNameAndCatalogNameToEndpoint.class) String catalogName);
/**
* @see VCloudExpressClient#getVAppTemplate
*/
@GET
@Consumes(VAPPTEMPLATE_XML)
@XMLResponseParser(VAppTemplateHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends VAppTemplate> getVAppTemplate(@EndpointParam URI vAppTemplate);
/**
* @see VCloudExpressClient#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 VCloudExpressClient#getCatalogItem
*/
@GET
@Consumes(CATALOGITEM_XML)
@XMLResponseParser(CatalogItemHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends CatalogItem> getCatalogItem(@EndpointParam URI catalogItem);
/**
* @see VCloudExpressClient#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 VCloudExpressClient#findNetworkInOrgVDCNamed
* @see VCloudClient#findNetworkInOrgVDCNamed
*/
@Override
@GET
@Consumes(NETWORK_XML)
@XMLResponseParser(NetworkHandler.class)
@XMLResponseParser(OrgNetworkFromVCloudExpressNetworkHandler.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);
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 VCloudExpressClient#getNetwork
* @see VCloudClient#getNetwork
*/
@Override
@GET
@Consumes(NETWORK_XML)
@XMLResponseParser(NetworkHandler.class)
@XMLResponseParser(OrgNetworkFromVCloudExpressNetworkHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends Network> getNetwork(@EndpointParam URI network);
/**
* @see VCloudExpressClient#getDefaultVDC
*/
@Deprecated
@GET
@Endpoint(org.jclouds.vcloud.endpoints.VDC.class)
@XMLResponseParser(VDCHandler.class)
@Consumes(VDC_XML)
ListenableFuture<? extends VDC> getDefaultVDC();
/**
* @see VCloudExpressClient#getVDC(URI)
*/
@GET
@XMLResponseParser(VDCHandler.class)
@Consumes(VDC_XML)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends VDC> getVDC(@EndpointParam URI vdc);
/**
* @see VCloudExpressClient#findVDCInOrgNamed(String, String)
*/
@GET
@XMLResponseParser(VDCHandler.class)
@Consumes(VDC_XML)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends VDC> findVDCInOrgNamed(
@Nullable @EndpointParam(parser = OrganizationNameAndVDCNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrganizationNameAndVDCNameToEndpoint.class) String vdcName);
/**
* @see VCloudExpressClient#getTasksList
*/
@GET
@Consumes(TASKSLIST_XML)
@XMLResponseParser(TasksListHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends TasksList> getTasksList(@EndpointParam URI tasksListId);
/**
* @see VCloudExpressClient#getTasksListInOrg
*/
@GET
@Consumes(TASKSLIST_XML)
@XMLResponseParser(TasksListHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends TasksList> findTasksListInOrgNamed(
@Nullable @EndpointParam(parser = OrganizationNameAndTasksListNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrganizationNameAndTasksListNameToEndpoint.class) String tasksListName);
/**
* @see VCloudExpressClient#getDefaultTasksList
*/
@Deprecated
@GET
@Endpoint(org.jclouds.vcloud.endpoints.TasksList.class)
@Consumes(TASKSLIST_XML)
@XMLResponseParser(TasksListHandler.class)
ListenableFuture<? extends TasksList> getDefaultTasksList();
/**
* @see VCloudExpressClient#deployVApp
*/
@POST
@Consumes(TASK_XML)
@Path("/action/deploy")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> deployVApp(@EndpointParam URI vAppId);
/**
* @see VCloudExpressClient#deleteVApp
*/
@DELETE
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
ListenableFuture<Void> deleteVApp(@EndpointParam URI vAppId);
/**
* @see VCloudExpressClient#undeployVApp
*/
@POST
@Consumes(TASK_XML)
@Path("/action/undeploy")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> undeployVApp(@EndpointParam URI vAppId);
/**
* @see VCloudExpressClient#powerOnVApp
*/
@POST
@Consumes(TASK_XML)
@Path("/power/action/powerOn")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> powerOnVApp(@EndpointParam URI vAppId);
/**
* @see VCloudExpressClient#powerOffVApp
*/
@POST
@Consumes(TASK_XML)
@Path("/power/action/powerOff")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> powerOffVApp(@EndpointParam URI vAppId);
/**
* @see VCloudExpressClient#shutdownVApp
*/
@POST
@Path("/power/action/shutdown")
ListenableFuture<Void> shutdownVApp(@EndpointParam URI vAppId);
/**
* @see VCloudExpressClient#resetVApp
*/
@POST
@Consumes(TASK_XML)
@Path("/power/action/reset")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> resetVApp(@EndpointParam URI vAppId);
/**
* @see VCloudExpressClient#suspendVApp
*/
@POST
@Consumes(TASK_XML)
@Path("/power/action/suspend")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> suspendVApp(@EndpointParam URI vAppId);
/**
* @see VCloudExpressClient#getTask
*/
@GET
@Consumes(TASK_XML)
@XMLResponseParser(TaskHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends Task> getTask(@EndpointParam URI taskId);
/**
* @see VCloudExpressClient#cancelTask
*/
@POST
@Path("/action/cancel")
ListenableFuture<Void> cancelTask(@EndpointParam URI taskId);
/**
* @see VCloudExpressClient#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 VCloudExpressClient#getVApp
*/
@GET
@Consumes(VAPP_XML)
@XMLResponseParser(VAppHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends VApp> getVApp(@EndpointParam URI vApp);
ListenableFuture<? extends OrgNetwork> getNetwork(@EndpointParam URI network);
/**
* @see VCloudExpressClient#instantiateVAppTemplateInVDC
@ -391,9 +98,9 @@ public interface VCloudExpressAsyncClient {
@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 VCloudExpressClient#cloneVAppInVDC
@ -405,7 +112,7 @@ public interface VCloudExpressAsyncClient {
@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,11 @@ 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 = 300, timeUnit = TimeUnit.SECONDS)
public interface VCloudExpressClient {
/**
* 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);
public interface VCloudExpressClient extends CommonVCloudClient {
VApp instantiateVAppTemplateInVDC(URI vDC, URI template, String appName, InstantiateVAppTemplateOptions... options);

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
@ -67,7 +67,7 @@ public class VCloudExpressPropertiesBuilder extends PropertiesBuilder {
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);
properties.setProperty(PROPERTY_VCLOUD_DEFAULT_FENCEMODE, FenceMode.BRIDGED.toString());
}
}

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
@ -44,11 +44,10 @@ public class VCloudPropertiesBuilder extends PropertiesBuilder {
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);
properties.setProperty(PROPERTY_VCLOUD_DEFAULT_FENCEMODE, FenceMode.BRIDGED.toString());
properties.setProperty(PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED, 180l * 1000l + "");
return properties;
}
@ -63,7 +62,6 @@ public class VCloudPropertiesBuilder extends PropertiesBuilder {
+ properties.getProperty(PROPERTY_VCLOUD_VERSION_SCHEMA));
}
public VCloudPropertiesBuilder withApiVersion(String version) {
properties.setProperty(PROPERTY_API_VERSION, "1.0");
return this;

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

@ -1,216 +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;
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.VCloudExpressClient;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VAppStatus;
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;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.google.inject.Inject;
/**
* @author Adrian Cole
*/
@Singleton
public class BaseVCloudExpressComputeClient implements VCloudExpressComputeClient {
@Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
protected Logger logger = Logger.NULL;
protected final VCloudExpressClient client;
protected final Predicate<URI> taskTester;
protected final Map<VAppStatus, NodeState> vAppStatusToNodeState;
@Inject
public BaseVCloudExpressComputeClient(VCloudExpressClient client, Predicate<URI> successTester,
Map<VAppStatus, NodeState> vAppStatusToNodeState) {
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) {
Map<String, String> response = parseResponse(template, vAppResponse);
checkState(response.containsKey("id"), "bad configuration: [id] should be in response");
checkState(response.containsKey("username"), "bad configuration: [username] should be in response");
checkState(response.containsKey("password"), "bad configuration: [password] should be in response");
return response;
}
protected Map<String, String> parseResponse(VAppTemplate template, VApp vAppResponse) {
Map<String, String> config = Maps.newLinkedHashMap();// Allows nulls
config.put("id", vAppResponse.getId().toASCIIString());
config.put("username", null);
config.put("password", null);
return config;
}
@Override
public void reboot(URI id) {
VApp vApp = client.getVApp(id);
logger.debug(">> resetting vApp(%s)", vApp.getName());
Task task = client.resetVApp(vApp.getId());
if (!taskTester.apply(task.getLocation())) {
throw new TaskException("resetVApp", vApp, task);
}
logger.debug("<< on vApp(%s)", vApp.getName());
}
@Override
public void stop(URI id) {
VApp vApp = client.getVApp(id);
vApp = powerOffVAppIfDeployed(vApp);
vApp = undeployVAppIfDeployed(vApp);
deleteVApp(vApp);
logger.debug("<< deleted vApp(%s)", vApp.getName());
}
private void deleteVApp(VApp vApp) {
logger.debug(">> deleting vApp(%s)", vApp.getName());
client.deleteVApp(vApp.getId());
}
private VApp undeployVAppIfDeployed(VApp vApp) {
if (vApp.getStatus().compareTo(VAppStatus.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())) {
throw new TaskException("undeploy", vApp, task);
}
vApp = client.getVApp(vApp.getId());
logger.debug("<< %s vApp(%s)", vApp.getStatus(), vApp.getName());
}
return vApp;
}
private VApp powerOffVAppIfDeployed(VApp vApp) {
if (vApp.getStatus().compareTo(VAppStatus.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())) {
throw new TaskException("powerOff", vApp, task);
}
vApp = client.getVApp(vApp.getId());
logger.debug("<< %s vApp(%s)", vApp.getStatus(), vApp.getName());
}
return vApp;
}
public static class TaskException extends VAppException {
private final Task task;
/** The serialVersionUID */
private static final long serialVersionUID = 251801929573211256L;
public TaskException(String type, VApp vApp, Task task) {
super(String.format("failed to %s vApp %s status %s;task %s status %s", type, vApp.getName(),
vApp.getStatus(), task.getLocation(), task.getStatus()), vApp);
this.task = task;
}
public Task getTask() {
return task;
}
}
public static class VAppException extends RuntimeException {
private final VApp vApp;
/** The serialVersionUID */
private static final long serialVersionUID = 251801929573211256L;
public VAppException(String message, VApp vApp) {
super(message);
this.vApp = vApp;
}
public VApp getvApp() {
return vApp;
}
}
@Override
public Set<String> getPrivateAddresses(URI id) {
return ImmutableSet.of();
}
@Override
public Set<String> getPublicAddresses(URI id) {
VApp vApp = client.getVApp(id);
return Sets.newHashSet(vApp.getNetworkToAddresses().values());
}
}

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

@ -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.VCloudExpressComputeClientImpl;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import com.google.inject.ImplementedBy;
@ -33,11 +33,11 @@ import com.google.inject.ImplementedBy;
*
* @author Adrian Cole
*/
@ImplementedBy(BaseVCloudExpressComputeClient.class)
public interface VCloudExpressComputeClient {
@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:
* 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 VCloudExpressComputeClient {
* 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

@ -27,11 +27,25 @@ 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.vcloud.compute.BaseVCloudComputeClient;
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.domain.VAppStatus;
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;
@ -41,7 +55,7 @@ import com.google.inject.Provides;
import com.google.inject.util.Providers;
/**
* Configures the {@link VCloudComputeServiceContext}; requires {@link BaseVCloudComputeClient}
* Configures the {@link VCloudComputeServiceContext}; requires {@link VCloudComputeClientImpl}
* bound.
*
* @author Adrian Cole
@ -49,20 +63,28 @@ import com.google.inject.util.Providers;
public abstract class CommonVCloudComputeServiceContextModule 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();
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<VAppStatus, NodeState> provideVAppStatusToNodeState() {
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();
}
@ -75,4 +97,14 @@ public abstract class CommonVCloudComputeServiceContextModule extends BaseComput
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,38 +19,25 @@
package org.jclouds.vcloud.compute.config;
import java.util.Set;
import javax.inject.Singleton;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.domain.Image;
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.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.VCloudImageSupplier;
import com.google.common.base.Supplier;
import com.google.inject.Injector;
import com.google.inject.Provides;
import com.google.inject.Scopes;
import com.google.inject.TypeLiteral;
/**
* Configures the {@link VCloudComputeServiceContext}; requires {@link BaseVCloudComputeClient}
* Configures the {@link VCloudComputeServiceContext}; requires {@link VCloudComputeClientImpl}
* bound.
*
* @author Adrian Cole
@ -67,21 +54,11 @@ public class VCloudComputeServiceContextModule extends CommonVCloudComputeServic
}).to(new TypeLiteral<RestContextImpl<VCloudClient, VCloudClient>>() {
}).in(Scopes.SINGLETON);
bind(AddNodeWithTagStrategy.class).to(VCloudAddNodeWithTagStrategy.class);
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);
}
@Override
protected Supplier<Set<? extends Location>> getSourceLocationSupplier(Injector injector) {
return injector.getInstance(OrgAndVDCToLocationSupplier.class);
@Provides
@Singleton
CommonVCloudComputeClient provideCommonVCloudComputeClient(VCloudComputeClient in) {
return in;
}
@Override
protected Supplier<Set<? extends Image>> getSourceImageSupplier(Injector injector) {
return injector.getInstance(VCloudImageSupplier.class);
}
}

View File

@ -19,39 +19,26 @@
package org.jclouds.vcloud.compute.config;
import java.util.Set;
import javax.inject.Singleton;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.domain.Image;
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.VCloudExpressClient;
import org.jclouds.vcloud.compute.BaseVCloudExpressComputeClient;
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 org.jclouds.vcloud.compute.strategy.VCloudExpressDestroyNodeStrategy;
import org.jclouds.vcloud.compute.strategy.VCloudExpressGetNodeMetadataStrategy;
import org.jclouds.vcloud.compute.strategy.VCloudExpressListNodesStrategy;
import org.jclouds.vcloud.compute.strategy.VCloudExpressRebootNodeStrategy;
import org.jclouds.vcloud.compute.suppliers.OrganizationAndVDCToLocationSupplier;
import org.jclouds.vcloud.compute.suppliers.VCloudExpressImageSupplier;
import com.google.common.base.Supplier;
import com.google.inject.Injector;
import com.google.inject.Provides;
import com.google.inject.Scopes;
import com.google.inject.TypeLiteral;
/**
* Configures the {@link VCloudComputeServiceContext}; requires
* {@link BaseVCloudExpressComputeClient} bound.
* {@link VCloudExpressComputeClientImpl} bound.
*
* @author Adrian Cole
*/
@ -67,21 +54,11 @@ public class VCloudExpressComputeServiceContextModule extends CommonVCloudComput
}).to(new TypeLiteral<RestContextImpl<VCloudExpressClient, VCloudExpressClient>>() {
}).in(Scopes.SINGLETON);
bind(AddNodeWithTagStrategy.class).to(VCloudExpressAddNodeWithTagStrategy.class);
bind(DestroyNodeStrategy.class).to(VCloudExpressDestroyNodeStrategy.class);
bind(RunNodesAndAddToSetStrategy.class).to(EncodeTagIntoNameRunNodesAndAddToSetStrategy.class);
bind(ListNodesStrategy.class).to(VCloudExpressListNodesStrategy.class);
bind(GetNodeMetadataStrategy.class).to(VCloudExpressGetNodeMetadataStrategy.class);
bind(RebootNodeStrategy.class).to(VCloudExpressRebootNodeStrategy.class);
}
@Override
protected Supplier<Set<? extends Location>> getSourceLocationSupplier(Injector injector) {
return injector.getInstance(OrganizationAndVDCToLocationSupplier.class);
@Provides
@Singleton
CommonVCloudComputeClient provideCommonVCloudComputeClient(VCloudExpressComputeClient in) {
return in;
}
@Override
protected Supplier<Set<? extends Image>> getSourceImageSupplier(Injector injector) {
return injector.getInstance(VCloudExpressImageSupplier.class);
}
}

View File

@ -31,7 +31,7 @@ import javax.annotation.Resource;
import javax.inject.Singleton;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.compute.BaseVCloudExpressComputeClient;
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 BaseVCloudExpressComputeClient} bound.
* {@link VCloudExpressComputeClientImpl} bound.
*
* @author Adrian Cole
*/

View File

@ -1,61 +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 javax.inject.Inject;
import javax.inject.Provider;
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.VAppTemplate;
import org.jclouds.vcloud.functions.AllCatalogItemsInOrganization;
import com.google.common.base.Function;
import com.google.common.collect.Iterables;
/**
* @author Adrian Cole
*/
@Singleton
public class ImagesInOrganization implements Function<Organization, Iterable<? extends Image>> {
private final AllCatalogItemsInOrganization allCatalogItemsInOrganization;
private final Function<Iterable<? extends CatalogItem>, Iterable<? extends VAppTemplate>> vAppTemplatesForCatalogItems;
private final Provider<ImageForVAppTemplate> imageForVAppTemplateProvider;
@Inject
ImagesInOrganization(AllCatalogItemsInOrganization allCatalogItemsInOrganization,
Provider<ImageForVAppTemplate> imageForVAppTemplateProvider,
Function<Iterable<? extends CatalogItem>, Iterable<? extends VAppTemplate>> vAppTemplatesForCatalogItems) {
this.imageForVAppTemplateProvider = imageForVAppTemplateProvider;
this.allCatalogItemsInOrganization = allCatalogItemsInOrganization;
this.vAppTemplatesForCatalogItems = vAppTemplatesForCatalogItems;
}
@Override
public Iterable<? extends Image> apply(Organization from) {
Iterable<? extends CatalogItem> catalogs = allCatalogItemsInOrganization.apply(from);
Iterable<? extends VAppTemplate> vAppTemplates = vAppTemplatesForCatalogItems.apply(catalogs);
return Iterables.transform(vAppTemplates, imageForVAppTemplateProvider.get().withParent(from));
}
}

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())) {

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

@ -38,7 +38,7 @@ 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.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 VCloudExpressAddNodeWithTagStrategy implements AddNodeWithTagStrategy {
protected final VCloudExpressClient client;
protected final VCloudExpressComputeClient computeClient;
protected final Map<VAppStatus, NodeState> vAppStatusToNodeState;
protected final Map<Status, NodeState> vAppStatusToNodeState;
@Inject
protected VCloudExpressAddNodeWithTagStrategy(VCloudExpressClient client, VCloudExpressComputeClient computeClient,
Map<VAppStatus, NodeState> vAppStatusToNodeState) {
Map<Status, NodeState> vAppStatusToNodeState) {
this.client = client;
this.computeClient = computeClient;
this.vAppStatusToNodeState = vAppStatusToNodeState;

View File

@ -1,55 +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.strategy;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import javax.inject.Inject;
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.VCloudExpressComputeClient;
/**
* @author Adrian Cole
*/
@Singleton
public class VCloudExpressDestroyNodeStrategy implements DestroyNodeStrategy {
protected final VCloudExpressComputeClient computeClient;
protected final GetNodeMetadataStrategy getNode;
@Inject
protected VCloudExpressDestroyNodeStrategy(VCloudExpressComputeClient computeClient, GetNodeMetadataStrategy getNode) {
this.computeClient = computeClient;
this.getNode = getNode;
}
@Override
public NodeMetadata execute(String id) {
computeClient.stop(URI.create(checkNotNull(id, "node.id")));
return getNode.execute(id);
}
}

View File

@ -1,95 +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.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.domain.Location;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.VCloudExpressClient;
import org.jclouds.vcloud.compute.VCloudExpressComputeClient;
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.VAppStatus;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableMap;
/**
* @author Adrian Cole
*/
@Singleton
public class VCloudExpressGetNodeMetadataStrategy implements GetNodeMetadataStrategy {
@Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
public Logger logger = Logger.NULL;
protected final VCloudExpressClient client;
protected final VCloudExpressComputeClient computeClient;
protected final Supplier<Set<? extends Image>> images;
protected final FindLocationForResource findLocationForResourceInVDC;
protected final GetExtra getExtra;
protected final Map<VAppStatus, NodeState> vAppStatusToNodeState;
@Inject
protected VCloudExpressGetNodeMetadataStrategy(VCloudExpressClient client, VCloudExpressComputeClient 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

@ -1,141 +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.strategy;
import static org.jclouds.compute.reference.ComputeServiceConstants.COMPUTE_LOGGER;
import static org.jclouds.compute.reference.ComputeServiceConstants.PROPERTY_BLACKLIST_NODES;
import java.util.Map;
import java.util.Set;
import javax.annotation.Resource;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.compute.domain.ComputeMetadata;
import org.jclouds.compute.domain.ComputeType;
import org.jclouds.compute.domain.NodeMetadata;
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.VCloudExpressClient;
import org.jclouds.vcloud.VCloudExpressMediaType;
import org.jclouds.vcloud.compute.functions.FindLocationForResource;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.endpoints.Org;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Predicate;
import com.google.common.base.Splitter;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Sets;
import com.google.inject.Inject;
import com.google.inject.internal.util.ImmutableSet;
/**
* @author Adrian Cole
*/
// TODO REFACTOR!!! needs to be parallel
@Singleton
public class VCloudExpressListNodesStrategy implements ListNodesStrategy {
@Resource
@Named(COMPUTE_LOGGER)
public Logger logger = Logger.NULL;
protected final VCloudExpressGetNodeMetadataStrategy getNodeMetadata;
protected final VCloudExpressClient client;
protected final FindLocationForResource findLocationForResourceInVDC;
Set<String> blackListVAppNames = ImmutableSet.<String> of();
@Inject(optional = true)
void setBlackList(@Named(PROPERTY_BLACKLIST_NODES) String blackListNodes) {
if (blackListNodes != null && !"".equals(blackListNodes))
this.blackListVAppNames = ImmutableSet.copyOf(Splitter.on(',').split(blackListNodes));
}
private final Supplier<Map<String, NamedResource>> orgNameToEndpoint;
@Inject
protected VCloudExpressListNodesStrategy(VCloudExpressClient client,
@Org Supplier<Map<String, NamedResource>> orgNameToEndpoint,
VCloudExpressGetNodeMetadataStrategy getNodeMetadata, FindLocationForResource findLocationForResourceInVDC) {
this.client = client;
this.orgNameToEndpoint = orgNameToEndpoint;
this.getNodeMetadata = getNodeMetadata;
this.findLocationForResourceInVDC = findLocationForResourceInVDC;
}
@Override
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 resource : client.getVDC(vdc.getId()).getResourceEntities().values()) {
if (validVApp(resource)) {
nodes.add(convertVAppToComputeMetadata(vdc, resource));
}
}
}
}
return nodes;
}
private boolean validVApp(NamedResource resource) {
return resource.getType().equals(VCloudExpressMediaType.VAPP_XML)
&& !blackListVAppNames.contains(resource.getName());
}
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());
}
@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 resource : client.getVDC(vdc.getId()).getResourceEntities().values()) {
if (validVApp(resource) && filter.apply(convertVAppToComputeMetadata(vdc, resource))) {
addVAppToSetRetryingIfNotYetPresent(nodes, vdc, resource);
}
}
}
}
return nodes;
}
@VisibleForTesting
void addVAppToSetRetryingIfNotYetPresent(Set<NodeMetadata> nodes, NamedResource vdc, NamedResource resource) {
NodeMetadata node = null;
int i = 0;
while (node == null && i++ < 3) {
try {
node = getNodeMetadata.execute(resource.getId().toASCIIString());
nodes.add(node);
} catch (NullPointerException e) {
logger.warn("vApp %s not yet present in vdc %s", resource.getName(), vdc.getName());
}
}
}
}

View File

@ -1,60 +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.strategy;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import javax.inject.Inject;
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.VCloudExpressClient;
import org.jclouds.vcloud.domain.Task;
import com.google.common.base.Predicate;
/**
* @author Adrian Cole
*/
@Singleton
public class VCloudExpressRebootNodeStrategy implements RebootNodeStrategy {
private final VCloudExpressClient client;
protected final Predicate<URI> taskTester;
protected final GetNodeMetadataStrategy getNode;
@Inject
protected VCloudExpressRebootNodeStrategy(VCloudExpressClient client, Predicate<URI> taskTester, GetNodeMetadataStrategy getNode) {
this.client = client;
this.taskTester = taskTester;
this.getNode = getNode;
}
@Override
public NodeMetadata execute(String in) {
URI id = URI.create(checkNotNull(in, "node.id"));
Task task = client.resetVApp(id);
taskTester.apply(task.getLocation());
return getNode.execute(in);
}
}

View File

@ -40,12 +40,12 @@ import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
import org.jclouds.domain.Location;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.VCloudClient;
import org.jclouds.vcloud.compute.VCloudComputeClient;
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.VAppStatus;
import org.jclouds.vcloud.domain.Status;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableMap;
@ -58,16 +58,16 @@ public class VCloudGetNodeMetadataStrategy implements GetNodeMetadataStrategy {
@Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
public Logger logger = Logger.NULL;
protected final VCloudClient client;
protected final VCloudComputeClient computeClient;
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<VAppStatus, NodeState> vAppStatusToNodeState;
protected final Map<Status, NodeState> vAppStatusToNodeState;
@Inject
VCloudGetNodeMetadataStrategy(VCloudClient client, VCloudComputeClient computeClient,
Map<VAppStatus, NodeState> vAppStatusToNodeState, GetExtra getExtra,
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");

View File

@ -36,7 +36,7 @@ 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.domain.NamedResource;
@ -61,7 +61,7 @@ public class VCloudListNodesStrategy implements ListNodesStrategy {
@Named(COMPUTE_LOGGER)
public Logger logger = Logger.NULL;
protected final VCloudGetNodeMetadataStrategy getNodeMetadata;
protected final VCloudClient client;
protected final CommonVCloudClient client;
protected final FindLocationForResource findLocationForResourceInVDC;
Set<String> blackListVAppNames = ImmutableSet.<String> of();
@ -74,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,
VCloudGetNodeMetadataStrategy 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;

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

@ -1,70 +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.suppliers;
import java.util.Map;
import java.util.Set;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.domain.Location;
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 com.google.common.base.Supplier;
import com.google.common.collect.Sets;
/**
* @author Adrian Cole
*/
@Singleton
public class OrganizationAndVDCToLocationSupplier implements Supplier<Set<? extends Location>> {
private final String providerName;
private final Supplier<Map<String, NamedResource>> orgNameToResource;
private final Supplier<Map<String, ? extends Organization>> orgNameToVDCResource;
@Inject
OrganizationAndVDCToLocationSupplier(@org.jclouds.rest.annotations.Provider String providerName,
@Org Supplier<Map<String, NamedResource>> orgNameToResource,
Supplier<Map<String, ? extends Organization>> orgNameToVDCResource) {
this.providerName = providerName;
this.orgNameToResource = orgNameToResource;
this.orgNameToVDCResource = orgNameToVDCResource;
}
@Override
public Set<? extends Location> get() {
Location provider = new LocationImpl(LocationScope.PROVIDER, providerName, providerName, null);
Set<Location> locations = Sets.newLinkedHashSet();
for (NamedResource org : orgNameToResource.get().values()) {
Location orgL = new VCloudLocation(org, provider);
for (NamedResource vdc : orgNameToVDCResource.get().get(org.getName()).getVDCs().values()) {
locations.add(new VCloudLocation(vdc, orgL));
}
}
return locations;
}
}

View File

@ -1,92 +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.suppliers;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Iterables.concat;
import static com.google.common.collect.Sets.newLinkedHashSet;
import static org.jclouds.concurrent.FutureIterables.transformParallel;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
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 com.google.common.base.Function;
import com.google.common.base.Supplier;
/**
* @author Adrian Cole
*/
@Singleton
public class VCloudExpressImageSupplier implements Supplier<Set<? extends Image>> {
@Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
public Logger logger = Logger.NULL;
private final Supplier<Map<String, ? extends Organization>> orgMap;
private final ImagesInOrganization imagesInOrganization;
private final ExecutorService executor;
@Inject
VCloudExpressImageSupplier(Supplier<Map<String, ? extends Organization>> orgMap, ImagesInOrganization imagesInOrganization,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
this.orgMap = checkNotNull(orgMap, "orgMap");
this.imagesInOrganization = checkNotNull(imagesInOrganization, "imagesInOrganization");
this.executor = checkNotNull(executor, "executor");
}
@Override
public Set<? extends Image> get() {
Iterable<? extends Organization> orgs = checkNotNull(orgMap.get().values(), "orgs");
Iterable<Iterable<? extends Image>> images = transformParallel(orgs,
new Function<Organization, Future<Iterable<? extends Image>>>() {
@Override
public Future<Iterable<? extends Image>> apply(final Organization from) {
checkNotNull(from, "org");
return executor.submit(new Callable<Iterable<? extends Image>>() {
@Override
public Iterable<? extends Image> call() throws Exception {
return imagesInOrganization.apply(from);
}
});
}
}, executor, null, logger, "images in " + orgs);
return newLinkedHashSet(concat(images));
}
}

View File

@ -39,7 +39,6 @@ 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.ImagesInOrg;
import org.jclouds.vcloud.domain.Org;
import com.google.common.base.Function;
@ -56,11 +55,12 @@ public class VCloudImageSupplier implements Supplier<Set<? extends Image>> {
public Logger logger = Logger.NULL;
private final Supplier<Map<String, ? extends Org>> orgMap;
private final ImagesInOrg imagesInOrg;
private final Function<Org, Iterable<? extends Image>> imagesInOrg;
private final ExecutorService executor;
@Inject
VCloudImageSupplier(Supplier<Map<String, ? extends Org>> orgMap, ImagesInOrg imagesInOrg,
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.imagesInOrg = checkNotNull(imagesInOrg, "imagesInOrg");

View File

@ -19,56 +19,24 @@
package org.jclouds.vcloud.config;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.base.Throwables.propagate;
import static com.google.common.collect.Iterables.get;
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_IDENTITY;
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED;
import java.net.URI;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.TimeUnit;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.domain.Location;
import org.jclouds.http.RequiresHttp;
import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.rest.AsyncClientFactory;
import org.jclouds.rest.AuthorizationException;
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.Catalog;
import org.jclouds.vcloud.domain.CatalogItem;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.Organization;
import org.jclouds.vcloud.domain.VAppTemplate;
import org.jclouds.vcloud.domain.VCloudSession;
import org.jclouds.vcloud.domain.VDC;
import org.jclouds.vcloud.endpoints.TasksList;
import org.jclouds.vcloud.functions.VCloudExpressAllCatalogItemsInCatalog;
import org.jclouds.vcloud.functions.VCloudExpressAllCatalogsInOrganization;
import org.jclouds.vcloud.functions.VCloudExpressAllVDCsInOrganization;
import org.jclouds.vcloud.functions.VCloudExpressOrganizationsForNames;
import org.jclouds.vcloud.functions.VCloudExpressOrganizatonsForLocations;
import org.jclouds.vcloud.functions.VCloudExpressVAppTemplatesForCatalogItems;
import org.jclouds.vcloud.predicates.VCloudExpressTaskSuccess;
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.VCloudExpressLoginAsyncClient;
@ -86,273 +54,6 @@ public abstract class BaseVCloudExpressRestClientModule<S extends VCloudExpressC
super(syncClientType, asyncClientType);
}
@Override
protected void configure() {
super.configure();
bind(new TypeLiteral<Function<Catalog, Iterable<? extends CatalogItem>>>() {
}).to(new TypeLiteral<VCloudExpressAllCatalogItemsInCatalog>() {
});
bind(new TypeLiteral<Function<Organization, Iterable<? extends Catalog>>>() {
}).to(new TypeLiteral<VCloudExpressAllCatalogsInOrganization>() {
});
bind(new TypeLiteral<Function<Organization, Iterable<? extends VDC>>>() {
}).to(new TypeLiteral<VCloudExpressAllVDCsInOrganization>() {
});
bind(new TypeLiteral<Function<Iterable<String>, Iterable<? extends Organization>>>() {
}).to(new TypeLiteral<VCloudExpressOrganizationsForNames>() {
});
bind(new TypeLiteral<Function<Iterable<? extends Location>, Iterable<? extends Organization>>>() {
}).to(new TypeLiteral<VCloudExpressOrganizatonsForLocations>() {
});
bind(new TypeLiteral<Function<Iterable<? extends CatalogItem>, Iterable<? extends VAppTemplate>>>() {
}).to(new TypeLiteral<VCloudExpressVAppTemplatesForCatalogItems>() {
});
}
@Provides
@Singleton
protected Organization provideOrganization(VCloudExpressClient discovery) {
if (authException.get() != null)
throw authException.get();
try {
return discovery.findOrganizationNamed(null);
} catch (AuthorizationException e) {
authException.set(e);
throw e;
}
}
@Override
protected URI provideDefaultNetwork(VCloudExpressClient 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;
}
}
@Override
protected Predicate<URI> successTester(Injector injector,
@Named(PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED) long completed) {
return new RetryablePredicate<URI>(injector.getInstance(VCloudExpressTaskSuccess.class), completed);
}
@Provides
@Singleton
@org.jclouds.vcloud.endpoints.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;
}
});
}
@Provides
@org.jclouds.vcloud.endpoints.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
@org.jclouds.vcloud.endpoints.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
@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();
}
});
}
@Singleton
public static class OrganizationMapSupplier implements Supplier<Map<String, ? extends Organization>> {
protected final Supplier<VCloudSession> sessionSupplier;
private final Function<Iterable<String>, Iterable<? extends Organization>> organizationsForNames;
@Inject
protected OrganizationMapSupplier(Supplier<VCloudSession> sessionSupplier,
Function<Iterable<String>, Iterable<? extends Organization>> 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 Function<Organization, Iterable<? extends org.jclouds.vcloud.domain.Catalog>> allCatalogsInOrganization;
@Inject
protected OrganizationCatalogSupplier(Supplier<Map<String, ? extends Organization>> orgSupplier,
Function<Organization, Iterable<? extends org.jclouds.vcloud.domain.Catalog>> 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 Function<Organization, Iterable<? extends org.jclouds.vcloud.domain.VDC>> allVDCsInOrganization;
@Inject
protected OrganizationVDCSupplier(Supplier<Map<String, ? extends Organization>> orgSupplier,
Function<Organization, Iterable<? extends org.jclouds.vcloud.domain.VDC>> 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 Function<org.jclouds.vcloud.domain.Catalog, Iterable<? extends CatalogItem>> allCatalogItemsInCatalog;
@Inject
protected OrganizationCatalogItemSupplier(
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>>>> 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
protected VCloudExpressLoginAsyncClient provideVCloudLogin(AsyncClientFactory factory) {
@ -380,11 +81,4 @@ public abstract class BaseVCloudExpressRestClientModule<S extends VCloudExpressC
});
}
@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

@ -19,56 +19,24 @@
package org.jclouds.vcloud.config;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.base.Throwables.propagate;
import static com.google.common.collect.Iterables.get;
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_IDENTITY;
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED;
import java.net.URI;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.TimeUnit;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.domain.Location;
import org.jclouds.http.RequiresHttp;
import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.rest.AsyncClientFactory;
import org.jclouds.rest.AuthorizationException;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.suppliers.RetryOnTimeOutButNotOnAuthorizationExceptionSupplier;
import org.jclouds.vcloud.VCloudAsyncClient;
import org.jclouds.vcloud.VCloudClient;
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.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.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.VCloudLoginAsyncClient;
@ -86,280 +54,6 @@ public abstract class BaseVCloudRestClientModule<S extends VCloudClient, A exten
super(syncClientType, asyncClientType);
}
@Override
protected void configure() {
super.configure();
bind(new TypeLiteral<Function<Catalog, Iterable<? extends CatalogItem>>>() {
}).to(new TypeLiteral<AllCatalogItemsInCatalog>() {
});
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<Iterable<? extends CatalogItem>, Iterable<? extends VAppTemplate>>>() {
}).to(new TypeLiteral<VAppTemplatesForCatalogItems>() {
});
}
@Override
protected URI provideDefaultNetwork(VCloudClient 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(VCloudClient discovery) {
if (authException.get() != null)
throw authException.get();
try {
return discovery.findOrgNamed(null);
} catch (AuthorizationException e) {
authException.set(e);
throw e;
}
}
@Override
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
@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);
}
});
}
}
@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();
}
@Provides
@Singleton
protected VCloudLoginAsyncClient provideVCloudLogin(AsyncClientFactory factory) {

View File

@ -22,8 +22,11 @@ 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;
@ -34,6 +37,7 @@ import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_TIMEO
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;
@ -44,30 +48,48 @@ 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.endpoints.Catalog;
import org.jclouds.vcloud.domain.VDC;
import org.jclouds.vcloud.endpoints.Network;
import org.jclouds.vcloud.endpoints.Org;
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;
@ -78,7 +100,8 @@ import domain.VCloudVersionsAsyncClient;
*/
@RequiresHttp
@ConfiguresRestClient
public abstract class CommonVCloudRestClientModule<S, A> extends RestClientModule<S, A> {
public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extends CommonVCloudAsyncClient> extends
RestClientModule<S, A> {
public CommonVCloudRestClientModule(Class<S> syncClientType, Class<A> asyncClientType) {
super(syncClientType, asyncClientType);
@ -88,16 +111,142 @@ public abstract class CommonVCloudRestClientModule<S, A> extends RestClientModul
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;
@Provides
@Singleton
protected abstract Predicate<URI> successTester(Injector injector,
@Named(PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED) long completed);
@VCloudToken
@Provides
String provideVCloudToken(Supplier<VCloudSession> cache) {
@ -105,21 +254,21 @@ public abstract class CommonVCloudRestClientModule<S, A> extends RestClientModul
}
@Provides
@Org
@org.jclouds.vcloud.endpoints.Org
@Singleton
protected URI provideOrg(@Org Iterable<NamedResource> orgs) {
protected URI provideOrg(@org.jclouds.vcloud.endpoints.Org Iterable<NamedResource> orgs) {
return getLast(orgs).getId();
}
@Provides
@Org
@org.jclouds.vcloud.endpoints.Org
@Singleton
protected String provideOrgName(@Org Iterable<NamedResource> orgs) {
protected String provideOrgName(@org.jclouds.vcloud.endpoints.Org Iterable<NamedResource> orgs) {
return getLast(orgs).getName();
}
@Provides
@Org
@org.jclouds.vcloud.endpoints.Org
@Singleton
protected Supplier<Map<String, NamedResource>> provideVDCtoORG(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
final OrgNameToOrgSupplier supplier) {
@ -180,7 +329,7 @@ public abstract class CommonVCloudRestClientModule<S, A> extends RestClientModul
}
@Provides
@Org
@org.jclouds.vcloud.endpoints.Org
@Singleton
protected Iterable<NamedResource> provideOrgs(Supplier<VCloudSession> cache, @Named(PROPERTY_IDENTITY) String user) {
VCloudSession discovery = cache.get();
@ -235,18 +384,13 @@ public abstract class CommonVCloudRestClientModule<S, A> extends RestClientModul
}
@Provides
@Catalog
@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
@Network
@Singleton
protected abstract URI provideDefaultNetwork(S client);
@Provides
@Named(PROPERTY_VCLOUD_DEFAULT_NETWORK)
@Singleton
@ -254,6 +398,162 @@ public abstract class CommonVCloudRestClientModule<S, A> extends RestClientModul
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);

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

@ -19,22 +19,35 @@
package org.jclouds.vcloud.domain;
import java.util.Map;
import static com.google.common.base.Preconditions.checkNotNull;
import org.jclouds.vcloud.domain.internal.OrganizationImpl;
import com.google.inject.ImplementedBy;
import com.google.common.base.CaseFormat;
/**
* @author Adrian Cole
* The MappingMode element specifies how IP address mapping is implemented by the NAT service.
*
*/
@ImplementedBy(OrganizationImpl.class)
public interface Organization extends NamedResource {
public enum MappingMode {
/**
* the external IP address is specified in the ExternalIP element
*/
MANUAL,
/**
* the external IP address is assigned automatically
*/
AUTOMATIC;
Map<String, NamedResource> getCatalogs();
public String value() {
return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, name());
}
Map<String, NamedResource> getVDCs();
@Override
public String toString() {
return value();
}
Map<String, NamedResource> getTasksLists();
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

@ -19,38 +19,72 @@
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
* 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.
* 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

@ -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

@ -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

@ -17,32 +17,44 @@
* ====================================================================
*/
package org.jclouds.vcloud.hostingdotcom;
import org.jclouds.compute.util.ComputeServiceUtils;
import org.jclouds.util.Utils;
import org.testng.annotations.Test;
import com.google.common.collect.Iterables;
package org.jclouds.vcloud.domain;
/**
* The creation status of the vDC
*
* @author Adrian Cole
*
* @see VDC#getStatus
*/
@Test(groups = "unit")
public class ProvidersInPropertiesTest {
public enum VDCStatus {
@Test
public void testSupportedProviders() {
Iterable<String> providers = Utils.getSupportedProviders();
assert Iterables.contains(providers, "hostingdotcom") : providers;
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;
}
}
@Test
public void testSupportedComputeServiceProviders() {
Iterable<String> providers = ComputeServiceUtils.getSupportedProviders();
assert Iterables.contains(providers, "hostingdotcom") : providers;
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.VCloudExpressMediaType;
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 VCloudExpressMediaType.CATALOG_XML;
}
@Override
public int compareTo(NamedResource o) {
return (this == o) ? 0 : getId().compareTo(o.getId());

View File

@ -19,14 +19,21 @@
package org.jclouds.vcloud.domain.internal;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.domain.Task;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
/**
* Locations of resources in vCloud
@ -34,34 +41,37 @@ import org.jclouds.vcloud.domain.Org;
* @author Adrian Cole
*
*/
public class OrgImpl implements Org {
private final String name;
private final URI id;
public class OrgImpl extends NamedResourceImpl implements Org {
private final String fullName;
@Nullable
private final String description;
private final Map<String, NamedResource> catalogs;
private final Map<String, NamedResource> vdcs;
private final Map<String, NamedResource> networks;
private final Map<String, NamedResource> catalogs = Maps.newLinkedHashMap();
private final Map<String, NamedResource> vdcs = Maps.newLinkedHashMap();
private final Map<String, NamedResource> networks = Maps.newLinkedHashMap();
private final NamedResource tasksList;
private final List<Task> tasks = Lists.newArrayList();
public OrgImpl(String name, URI id, String description, Map<String, NamedResource> catalogs,
Map<String, NamedResource> vdcs, Map<String, NamedResource> networks, @Nullable NamedResource tasksList) {
this.name = name;
this.id = id;
public OrgImpl(String name, String type, URI id, String fullName, String description,
Map<String, NamedResource> catalogs, Map<String, NamedResource> vdcs, Map<String, NamedResource> networks,
@Nullable NamedResource tasksList, Iterable<Task> tasks) {
super(name, type, id);
this.fullName = checkNotNull(fullName, "fullName");
this.description = description;
this.catalogs = catalogs;
this.vdcs = vdcs;
this.networks = networks;
this.catalogs.putAll(checkNotNull(catalogs, "catalogs"));
this.vdcs.putAll(checkNotNull(vdcs, "vdcs"));
this.networks.putAll(checkNotNull(networks, "networks"));
this.tasksList = tasksList;
Iterables.addAll(this.tasks, checkNotNull(tasks, "tasks"));
}
@Override
public String getName() {
return name;
public String getFullName() {
return fullName;
}
@Override
public URI getId() {
return id;
public String getDescription() {
return description;
}
@Override
@ -74,20 +84,30 @@ public class OrgImpl implements Org {
return vdcs;
}
@Override
public Map<String, NamedResource> getNetworks() {
return networks;
}
@Override
public NamedResource getTasksList() {
return tasksList;
}
@Override
public List<Task> getTasks() {
return tasks;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
int result = super.hashCode();
result = prime * result + ((catalogs == null) ? 0 : catalogs.hashCode());
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 + ((fullName == null) ? 0 : fullName.hashCode());
result = prime * result + ((networks == null) ? 0 : networks.hashCode());
result = prime * result + ((tasks == null) ? 0 : tasks.hashCode());
result = prime * result + ((tasksList == null) ? 0 : tasksList.hashCode());
result = prime * result + ((vdcs == null) ? 0 : vdcs.hashCode());
return result;
@ -97,7 +117,7 @@ public class OrgImpl implements Org {
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
@ -112,21 +132,21 @@ public class OrgImpl implements Org {
return false;
} else if (!description.equals(other.description))
return false;
if (id == null) {
if (other.id != null)
if (fullName == null) {
if (other.fullName != null)
return false;
} else if (!id.equals(other.id))
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
} else if (!fullName.equals(other.fullName))
return false;
if (networks == null) {
if (other.networks != null)
return false;
} else if (!networks.equals(other.networks))
return false;
if (tasks == null) {
if (other.tasks != null)
return false;
} else if (!tasks.equals(other.tasks))
return false;
if (tasksList == null) {
if (other.tasksList != null)
return false;
@ -140,11 +160,6 @@ public class OrgImpl implements Org {
return true;
}
@Override
public String getType() {
return VCloudMediaType.ORG_XML;
}
@Override
public int compareTo(NamedResource o) {
return (this == o) ? 0 : getId().compareTo(o.getId());
@ -152,16 +167,7 @@ public class OrgImpl implements Org {
@Override
public String toString() {
return "[id=" + id + ", name=" + name + ", type=" + getType() + "]";
return "[id=" + getId() + ", name=" + getName() + ", type=" + getType() + "]";
}
@Override
public Map<String, NamedResource> getNetworks() {
return networks;
}
@Override
public String getDescription() {
return description;
}
}

View File

@ -1,139 +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.internal;
import java.net.URI;
import java.util.Map;
import org.jclouds.vcloud.VCloudExpressMediaType;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.Organization;
/**
* Locations of resources in vCloud
*
* @author Adrian Cole
*
*/
public class OrganizationImpl implements Organization {
private final String name;
private final URI id;
private final Map<String, NamedResource> catalogs;
private final Map<String, NamedResource> vdcs;
private final Map<String, NamedResource> tasksLists;
public OrganizationImpl(String name, URI id, Map<String, NamedResource> catalogs, Map<String, NamedResource> vdcs,
Map<String, NamedResource> tasksLists) {
this.name = name;
this.id = id;
this.catalogs = catalogs;
this.vdcs = vdcs;
this.tasksLists = tasksLists;
}
@Override
public String getName() {
return name;
}
@Override
public URI getId() {
return id;
}
@Override
public Map<String, NamedResource> getCatalogs() {
return catalogs;
}
@Override
public Map<String, NamedResource> getVDCs() {
return vdcs;
}
@Override
public Map<String, NamedResource> getTasksLists() {
return tasksLists;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((catalogs == null) ? 0 : catalogs.hashCode());
result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((tasksLists == null) ? 0 : tasksLists.hashCode());
result = prime * result + ((vdcs == null) ? 0 : vdcs.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
OrganizationImpl other = (OrganizationImpl) obj;
if (catalogs == null) {
if (other.catalogs != null)
return false;
} else if (!catalogs.equals(other.catalogs))
return false;
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
if (tasksLists == null) {
if (other.tasksLists != null)
return false;
} else if (!tasksLists.equals(other.tasksLists))
return false;
if (vdcs == null) {
if (other.vdcs != null)
return false;
} else if (!vdcs.equals(other.vdcs))
return false;
return true;
}
@Override
public String getType() {
return VCloudExpressMediaType.ORG_XML;
}
@Override
public int compareTo(NamedResource o) {
return (this == o) ? 0 : getId().compareTo(o.getId());
}
@Override
public String toString() {
return "[id=" + id + ", name=" + name + ", type=" + getType() + "]";
}
}

View File

@ -28,7 +28,7 @@ import org.jclouds.vcloud.VCloudExpressMediaType;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.ResourceAllocation;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.domain.Status;
import org.jclouds.vcloud.domain.VirtualSystem;
import com.google.common.collect.ListMultimap;
@ -42,7 +42,7 @@ public class VAppImpl implements VApp {
private final String name;
private final URI id;
private final NamedResource vDC;
private final VAppStatus status;
private final Status status;
private final Long size;
private final ListMultimap<String, String> networkToAddresses;
private final String operatingSystemDescription;
@ -53,13 +53,13 @@ public class VAppImpl implements VApp {
/** The serialVersionUID */
private static final long serialVersionUID = 8464716396538298809L;
public VAppImpl(String name, URI id, VAppStatus status, Long size, NamedResource vDC,
public VAppImpl(String name, URI id, Status status, Long size, NamedResource vDC,
ListMultimap<String, String> networkToAddresses, Integer osType, String operatingSystemDescription,
VirtualSystem system, Set<ResourceAllocation> resourceAllocations) {
this.name = checkNotNull(name, "name");
this.id = checkNotNull(id, "id");
this.status = checkNotNull(status, "status");
this.size = size;// hostingdotcom
this.size = size;
this.vDC = vDC;
this.networkToAddresses = checkNotNull(networkToAddresses, "networkToAddresses");
this.osType = osType;
@ -69,7 +69,7 @@ public class VAppImpl implements VApp {
}
@Override
public VAppStatus getStatus() {
public Status getStatus() {
return status;
}

View File

@ -24,7 +24,7 @@ import java.net.URI;
import javax.annotation.Nullable;
import org.jclouds.vcloud.VCloudExpressMediaType;
import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.domain.Status;
import org.jclouds.vcloud.domain.VAppTemplate;
/**
@ -37,9 +37,9 @@ public class VAppTemplateImpl extends NamedResourceImpl implements VAppTemplate
/** The serialVersionUID */
private static final long serialVersionUID = 8464716396538298809L;
private final String description;
private final VAppStatus status;
private final Status status;
public VAppTemplateImpl(String name, URI id, @Nullable String description, @Nullable VAppStatus status) {
public VAppTemplateImpl(String name, URI id, @Nullable String description, @Nullable Status status) {
super(name, VCloudExpressMediaType.VAPPTEMPLATE_XML, id);
this.description = description;
this.status = status;
@ -50,7 +50,7 @@ public class VAppTemplateImpl extends NamedResourceImpl implements VAppTemplate
return description;
}
public VAppStatus getStatus() {
public Status getStatus() {
return status;
}

View File

@ -22,13 +22,21 @@ package org.jclouds.vcloud.domain.internal;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.List;
import java.util.Map;
import org.jclouds.vcloud.VCloudExpressMediaType;
import javax.annotation.Nullable;
import org.jclouds.vcloud.domain.AllocationModel;
import org.jclouds.vcloud.domain.Capacity;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.Quota;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VDC;
import org.jclouds.vcloud.domain.VDCStatus;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
/**
* Locations of resources in vCloud
@ -36,71 +44,176 @@ import org.jclouds.vcloud.domain.VDC;
* @author Adrian Cole
*
*/
public class VDCImpl implements VDC {
public class VDCImpl extends NamedResourceImpl implements VDC {
private final String name;
private final URI id;
private final VDCStatus status;
private final NamedResource org;
@Nullable
private final String description;
private final List<Task> tasks = Lists.newArrayList();
private final AllocationModel allocationModel;
private final Capacity storageCapacity;
private final Capacity cpuCapacity;
private final Capacity memoryCapacity;
private final Quota instantiatedVmsQuota;
private final Quota deployedVmsQuota;
private final Map<String, NamedResource> availableNetworks;
private final Map<String, NamedResource> resourceEntities;
private final Map<String, NamedResource> resourceEntities = Maps.newLinkedHashMap();
private final Map<String, NamedResource> availableNetworks = Maps.newLinkedHashMap();
private final int nicQuota;
private final int networkQuota;
private final int vmQuota;
private final boolean isEnabled;
public VDCImpl(String name, URI id, String description, Capacity storageCapacity, Capacity cpuCapacity,
Capacity memoryCapacity, Quota instantiatedVmsQuota, Quota deployedVmsQuota,
Map<String, NamedResource> resourceEntities, Map<String, NamedResource> availableNetworks) {
this.name = checkNotNull(name, "name");
this.id = checkNotNull(id, "id");
public VDCImpl(String name, String type, URI id, VDCStatus status, NamedResource org, @Nullable String description,
Iterable<Task> tasks, AllocationModel allocationModel, @Nullable Capacity storageCapacity,
@Nullable Capacity cpuCapacity, @Nullable Capacity memoryCapacity,
Map<String, NamedResource> resourceEntities, Map<String, NamedResource> availableNetworks, int nicQuota,
int networkQuota, int vmQuota, boolean isEnabled) {
super(name, type, id);
this.status = checkNotNull(status, "status");
this.org = org;// TODO: once <1.0 is killed check not null
this.description = description;
this.storageCapacity = storageCapacity;
this.cpuCapacity = cpuCapacity;
this.memoryCapacity = memoryCapacity;
this.instantiatedVmsQuota = instantiatedVmsQuota;
this.deployedVmsQuota = deployedVmsQuota;
this.availableNetworks = checkNotNull(availableNetworks, "availableNetworks");
this.resourceEntities = checkNotNull(resourceEntities, "resourceEntities");
Iterables.addAll(this.tasks, checkNotNull(tasks, "tasks"));
this.allocationModel = checkNotNull(allocationModel, "allocationModel");
this.storageCapacity = storageCapacity;// TODO: once <1.0 is killed check not null
this.cpuCapacity = cpuCapacity;// TODO: once <1.0 is killed check not null
this.memoryCapacity = memoryCapacity;// TODO: once <1.0 is killed check not null
this.resourceEntities.putAll(checkNotNull(resourceEntities, "resourceEntities"));
this.availableNetworks.putAll(checkNotNull(availableNetworks, "availableNetworks"));
this.nicQuota = nicQuota;
this.networkQuota = networkQuota;
this.vmQuota = vmQuota;
this.isEnabled = isEnabled;
}
/** The serialVersionUID */
private static final long serialVersionUID = 8464716396538298809L;
/**
* {@inheritDoc}
*/
@Override
public String getName() {
return name;
public VDCStatus getStatus() {
return status;
}
/**
* {@inheritDoc}
*/
@Override
public URI getId() {
return id;
public NamedResource getOrg() {
return org;
}
/**
* {@inheritDoc}
*/
@Override
public Map<String, NamedResource> getAvailableNetworks() {
return availableNetworks;
public String getDescription() {
return description;
}
/**
* {@inheritDoc}
*/
@Override
public List<Task> getTasks() {
return tasks;
}
/**
* {@inheritDoc}
*/
@Override
public AllocationModel getAllocationModel() {
return allocationModel;
}
/**
* {@inheritDoc}
*/
@Override
public Capacity getStorageCapacity() {
return storageCapacity;
}
/**
* {@inheritDoc}
*/
@Override
public Capacity getCpuCapacity() {
return cpuCapacity;
}
/**
* {@inheritDoc}
*/
@Override
public Capacity getMemoryCapacity() {
return memoryCapacity;
}
/**
* {@inheritDoc}
*/
@Override
public Map<String, NamedResource> getResourceEntities() {
return resourceEntities;
}
/**
* {@inheritDoc}
*/
@Override
public Map<String, NamedResource> getAvailableNetworks() {
return availableNetworks;
}
/**
* {@inheritDoc}
*/
@Override
public int getNicQuota() {
return nicQuota;
}
/**
* {@inheritDoc}
*/
@Override
public int getNetworkQuota() {
return networkQuota;
}
/**
* {@inheritDoc}
*/
@Override
public int getVmQuota() {
return vmQuota;
}
/**
* {@inheritDoc}
*/
@Override
public boolean isEnabled() {
return isEnabled;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
int result = super.hashCode();
result = prime * result + ((allocationModel == null) ? 0 : allocationModel.hashCode());
result = prime * result + ((availableNetworks == null) ? 0 : availableNetworks.hashCode());
result = prime * result + ((cpuCapacity == null) ? 0 : cpuCapacity.hashCode());
result = prime * result + ((deployedVmsQuota == null) ? 0 : deployedVmsQuota.hashCode());
result = prime * result + ((description == null) ? 0 : description.hashCode());
result = prime * result + ((instantiatedVmsQuota == null) ? 0 : instantiatedVmsQuota.hashCode());
result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result + (isEnabled ? 1231 : 1237);
result = prime * result + ((memoryCapacity == null) ? 0 : memoryCapacity.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + networkQuota;
result = prime * result + nicQuota;
result = prime * result + ((org == null) ? 0 : org.hashCode());
result = prime * result + ((resourceEntities == null) ? 0 : resourceEntities.hashCode());
result = prime * result + ((status == null) ? 0 : status.hashCode());
result = prime * result + ((storageCapacity == null) ? 0 : storageCapacity.hashCode());
result = prime * result + ((tasks == null) ? 0 : tasks.hashCode());
result = prime * result + vmQuota;
return result;
}
@ -108,11 +221,16 @@ public class VDCImpl implements VDC {
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
VDCImpl other = (VDCImpl) obj;
if (allocationModel == null) {
if (other.allocationModel != null)
return false;
} else if (!allocationModel.equals(other.allocationModel))
return false;
if (availableNetworks == null) {
if (other.availableNetworks != null)
return false;
@ -123,91 +241,56 @@ public class VDCImpl implements VDC {
return false;
} else if (!cpuCapacity.equals(other.cpuCapacity))
return false;
if (deployedVmsQuota == null) {
if (other.deployedVmsQuota != null)
return false;
} else if (!deployedVmsQuota.equals(other.deployedVmsQuota))
return false;
if (description == null) {
if (other.description != null)
return false;
} else if (!description.equals(other.description))
return false;
if (instantiatedVmsQuota == null) {
if (other.instantiatedVmsQuota != null)
return false;
} else if (!instantiatedVmsQuota.equals(other.instantiatedVmsQuota))
return false;
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
if (isEnabled != other.isEnabled)
return false;
if (memoryCapacity == null) {
if (other.memoryCapacity != null)
return false;
} else if (!memoryCapacity.equals(other.memoryCapacity))
return false;
if (name == null) {
if (other.name != null)
if (networkQuota != other.networkQuota)
return false;
if (nicQuota != other.nicQuota)
return false;
if (org == null) {
if (other.org != null)
return false;
} else if (!name.equals(other.name))
} else if (!org.equals(other.org))
return false;
if (resourceEntities == null) {
if (other.resourceEntities != null)
return false;
} else if (!resourceEntities.equals(other.resourceEntities))
return false;
if (status == null) {
if (other.status != null)
return false;
} else if (!status.equals(other.status))
return false;
if (storageCapacity == null) {
if (other.storageCapacity != null)
return false;
} else if (!storageCapacity.equals(other.storageCapacity))
return false;
if (tasks == null) {
if (other.tasks != null)
return false;
} else if (!tasks.equals(other.tasks))
return false;
if (vmQuota != other.vmQuota)
return false;
return true;
}
@Override
public String getDescription() {
return description;
}
@Override
public Capacity getStorageCapacity() {
return storageCapacity;
}
@Override
public Capacity getCpuCapacity() {
return cpuCapacity;
}
@Override
public Capacity getMemoryCapacity() {
return memoryCapacity;
}
@Override
public Quota getInstantiatedVmsQuota() {
return instantiatedVmsQuota;
}
@Override
public Quota getDeployedVmsQuota() {
return deployedVmsQuota;
}
@Override
public String getType() {
return VCloudExpressMediaType.VDC_XML;
}
@Override
public int compareTo(NamedResource o) {
return (this == o) ? 0 : getId().compareTo(o.getId());
}
@Override
public String toString() {
return "[id=" + id + ", name=" + name + ", description=" + description + "]";
return "[id=" + getId() + ", name=" + getName() + ", org=" + org + ", description=" + description + ", status="
+ status + ", isEnabled=" + isEnabled + "]";
}
}

View File

@ -0,0 +1,128 @@
/**
*
* 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.network;
import javax.annotation.Nullable;
/**
* specifies the properties of the networks DHCP service
*/
public class DhcpService {
private final boolean enabled;
@Nullable
private final Integer defaultLeaseTime;
@Nullable
private final Integer maxLeaseTime;
@Nullable
private final IpRange ipRange;
public DhcpService(boolean enabled, @Nullable Integer defaultLeaseTime, @Nullable Integer maxLeaseTime,
@Nullable IpRange ipRange) {
this.enabled = enabled;
this.defaultLeaseTime = defaultLeaseTime;
this.maxLeaseTime = maxLeaseTime;
this.ipRange = ipRange;
}
/**
* @return true if the service is enabled
*
* @since vcloud api 0.8
*/
public boolean isEnabled() {
return enabled;
}
/**
* default duration of a DCHP address lease
*
* @since vcloud api 0.9
*/
@Nullable
public Integer getDefaultLeaseTime() {
return defaultLeaseTime;
}
/**
* maximum duration of a DCHP address lease.
*
* @since vcloud api 0.9
*/
@Nullable
public Integer getMaxLeaseTime() {
return maxLeaseTime;
}
/**
* @return range of IP addresses available to DHCP clients
*
* @since vcloud api 0.9
*/
@Nullable
public IpRange getIpRange() {
return ipRange;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((defaultLeaseTime == null) ? 0 : defaultLeaseTime.hashCode());
result = prime * result + (enabled ? 1231 : 1237);
result = prime * result + ((ipRange == null) ? 0 : ipRange.hashCode());
result = prime * result + ((maxLeaseTime == null) ? 0 : maxLeaseTime.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;
DhcpService other = (DhcpService) obj;
if (defaultLeaseTime == null) {
if (other.defaultLeaseTime != null)
return false;
} else if (!defaultLeaseTime.equals(other.defaultLeaseTime))
return false;
if (enabled != other.enabled)
return false;
if (ipRange == null) {
if (other.ipRange != null)
return false;
} else if (!ipRange.equals(other.ipRange))
return false;
if (maxLeaseTime == null) {
if (other.maxLeaseTime != null)
return false;
} else if (!maxLeaseTime.equals(other.maxLeaseTime))
return false;
return true;
}
@Override
public String toString() {
return "[defaultLeaseTime=" + defaultLeaseTime + ", enabled=" + enabled + ", ipRange=" + ipRange
+ ", maxLeaseTime=" + maxLeaseTime + "]";
}
}

View File

@ -0,0 +1,115 @@
/**
*
* 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.network;
import javax.annotation.Nullable;
/**
* The Features element defines the DHCP and firewall features of a network.
*/
public class Features {
@Nullable
private final DhcpService dhcpService;
@Nullable
private final FirewallService firewallService;
@Nullable
private final NatService natService;
public Features(@Nullable DhcpService dhcpService, @Nullable FirewallService firewallService,
@Nullable NatService natService) {
this.dhcpService = dhcpService;
this.firewallService = firewallService;
this.natService = natService;
}
/**
* specifies the properties of the networks DHCP service
*
* @since vcloud api 0.9, but emulated for 0.8
*/
@Nullable
public DhcpService getDhcpService() {
return dhcpService;
}
/**
* defines the firewall service capabilities of the network
*
* @since vcloud api 0.8
*/
@Nullable
public FirewallService getFirewallService() {
return firewallService;
}
/**
* defines the NAT service capabilities of the network
*
* @since vcloud api 0.8
*/
@Nullable
public NatService getNatService() {
return natService;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((dhcpService == null) ? 0 : dhcpService.hashCode());
result = prime * result + ((firewallService == null) ? 0 : firewallService.hashCode());
result = prime * result + ((natService == null) ? 0 : natService.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;
Features other = (Features) obj;
if (dhcpService == null) {
if (other.dhcpService != null)
return false;
} else if (!dhcpService.equals(other.dhcpService))
return false;
if (firewallService == null) {
if (other.firewallService != null)
return false;
} else if (!firewallService.equals(other.firewallService))
return false;
if (natService == null) {
if (other.natService != null)
return false;
} else if (!natService.equals(other.natService))
return false;
return true;
}
@Override
public String toString() {
return "[dhcpService=" + dhcpService + ", firewallService=" + firewallService + ", natService=" + natService
+ "]";
}
}

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.network;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.base.CaseFormat;
/**
*
* The FenceMode element contains one of the following strings that specify how a network is
* connected to its parent network.
*
* @author Adrian Cole
*/
public enum FenceMode {
/**
* The two networks are bridged.
* <p/>
* Note that in vcloud 0.8 this was called ALLOW_IN_OUT, and so our implementation automatically
* converts this for you. Use bridged instead of allowInOut.
*
* @since vcloud api 0.9
*/
BRIDGED,
/**
* The two networks are not connected.
*
* @since vcloud api 0.8
*/
ISOLATED,
/**
* The two networks are connected as specified in their NatService elements.
*
* @since vcloud api 0.8
*/
NAT_ROUTED;
public String value() {
return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, name());
}
@Override
public String toString() {
return value();
}
public static FenceMode fromValue(String fenceMode) {
return valueOf(CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(fenceMode, "fenceMode")));
}
}

View File

@ -0,0 +1,98 @@
/**
*
* 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.network;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.List;
import javax.annotation.Nullable;
import org.jclouds.vcloud.domain.network.firewall.FirewallRule;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
/**
* The FirewallService element defines the firewall service capabilities of a network.
*/
public class FirewallService {
private final boolean enabled;
List<FirewallRule> firewallRules = Lists.newArrayList();
public FirewallService(boolean enabled, Iterable<? extends FirewallRule> firewallRules) {
this.enabled = enabled;
Iterables.addAll(this.firewallRules, checkNotNull(firewallRules, "firewallRules"));
}
/**
* @return Firewall rules for the network
*
* @since vcloud api 0.8
*/
public List<? extends FirewallRule> getFirewallRules() {
return firewallRules;
}
/**
* @return true if the service is enabled
*
* @since vcloud api 0.9
*/
@Nullable
public boolean isEnabled() {
return enabled;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (enabled ? 1231 : 1237);
result = prime * result + ((firewallRules == null) ? 0 : firewallRules.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;
FirewallService other = (FirewallService) obj;
if (enabled != other.enabled)
return false;
if (firewallRules == null) {
if (other.firewallRules != null)
return false;
} else if (!firewallRules.equals(other.firewallRules))
return false;
return true;
}
@Override
public String toString() {
return "[enabled=" + enabled + ", firewallRules=" + firewallRules + "]";
}
}

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.network;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* The IpRange element defines a range of IP addresses available on a network.
*
*/
public class IpRange {
private final String startAddress;
private final String endAddress;
public IpRange(String startAddress, String endAddress) {
this.startAddress = checkNotNull(startAddress, "startAddress");
this.endAddress = checkNotNull(endAddress, "endAddress");
}
/**
* @return lowest IP address in the range
*
* @since vcloud api 0.9
*/
public String getStartAddress() {
return startAddress;
}
/**
* @return highest IP address in the range
*
* @since vcloud api 0.9
*/
public String getEndAddress() {
return endAddress;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((endAddress == null) ? 0 : endAddress.hashCode());
result = prime * result + ((startAddress == null) ? 0 : startAddress.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;
IpRange other = (IpRange) obj;
if (endAddress == null) {
if (other.endAddress != null)
return false;
} else if (!endAddress.equals(other.endAddress))
return false;
if (startAddress == null) {
if (other.startAddress != null)
return false;
} else if (!startAddress.equals(other.startAddress))
return false;
return true;
}
@Override
public String toString() {
return "[startAddress=" + startAddress + ", endAddress=" + endAddress + "]";
}
}

View File

@ -0,0 +1,192 @@
package org.jclouds.vcloud.domain.network;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Set;
import javax.annotation.Nullable;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
/**
* The IpScope element defines the address range, gateway, netmask, and other properties of the
* network.
*
*/
public class IpScope {
private final boolean inherited;
@Nullable
private final String gateway;
@Nullable
private final String netmask;
@Nullable
private final String dns1;
@Nullable
private final String dns2;
@Nullable
private final String dnsSuffix;
private final Set<IpRange> ipRanges = Sets.newLinkedHashSet();
private final Set<String> allocatedIpAddresses = Sets.newLinkedHashSet();
public IpScope(boolean inherited, @Nullable String gateway, @Nullable String netmask, @Nullable String dns1,
@Nullable String dns2, @Nullable String dnsSuffix, Iterable<IpRange> ipRanges,
Iterable<String> allocatedIpAddresses) {
this.inherited = inherited;
this.gateway = gateway;
this.netmask = netmask;
this.dns1 = dns1;
this.dns2 = dns2;
this.dnsSuffix = dnsSuffix;
Iterables.addAll(this.ipRanges, checkNotNull(ipRanges, "ipRanges"));
Iterables.addAll(this.allocatedIpAddresses, checkNotNull(allocatedIpAddresses, "allocatedIpAddresses"));
}
/**
* @return true of the values in this IpScope element are inherited from the ParentNetwork of the
* containing Configuration
* @since vcloud api 0.9
*/
public boolean isInherited() {
return inherited;
}
/**
* @return IP address of the network gateway
*
* @since vcloud api 0.8
*/
@Nullable
public String getGateway() {
return gateway;
}
/**
* @return netmask to apply to addresses on the network
*
* @since vcloud api 0.8
*/
@Nullable
public String getNetmask() {
return netmask;
}
/**
* @return IP address of the primary DNS server for this network
*
* @since vcloud api 0.9
*/
@Nullable
public String getDns1() {
return dns1;
}
/**
* @return IP address of the secondary DNS server for this network
*
* @since vcloud api 0.9
*/
@Nullable
public String getDns2() {
return dns2;
}
/**
* @return suffix to be applied when resolving hostnames that are not fullyqualified.
*
* @since vcloud api 0.9
*/
@Nullable
public String getDnsSuffix() {
return dnsSuffix;
}
/**
* @return A container for IpRange elements.
*
* @since vcloud api 0.9
*/
public Set<IpRange> getIpRanges() {
return ipRanges;
}
/**
* @return A list of addresses allocated from any of the specified IpRanges
*
* @since vcloud api 0.9
*/
public Set<String> getAllocatedIpAddresses() {
return allocatedIpAddresses;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((allocatedIpAddresses == null) ? 0 : allocatedIpAddresses.hashCode());
result = prime * result + ((dns1 == null) ? 0 : dns1.hashCode());
result = prime * result + ((dns2 == null) ? 0 : dns2.hashCode());
result = prime * result + ((dnsSuffix == null) ? 0 : dnsSuffix.hashCode());
result = prime * result + ((gateway == null) ? 0 : gateway.hashCode());
result = prime * result + (inherited ? 1231 : 1237);
result = prime * result + ((ipRanges == null) ? 0 : ipRanges.hashCode());
result = prime * result + ((netmask == null) ? 0 : netmask.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;
IpScope other = (IpScope) obj;
if (allocatedIpAddresses == null) {
if (other.allocatedIpAddresses != null)
return false;
} else if (!allocatedIpAddresses.equals(other.allocatedIpAddresses))
return false;
if (dns1 == null) {
if (other.dns1 != null)
return false;
} else if (!dns1.equals(other.dns1))
return false;
if (dns2 == null) {
if (other.dns2 != null)
return false;
} else if (!dns2.equals(other.dns2))
return false;
if (dnsSuffix == null) {
if (other.dnsSuffix != null)
return false;
} else if (!dnsSuffix.equals(other.dnsSuffix))
return false;
if (gateway == null) {
if (other.gateway != null)
return false;
} else if (!gateway.equals(other.gateway))
return false;
if (inherited != other.inherited)
return false;
if (ipRanges == null) {
if (other.ipRanges != null)
return false;
} else if (!ipRanges.equals(other.ipRanges))
return false;
if (netmask == null) {
if (other.netmask != null)
return false;
} else if (!netmask.equals(other.netmask))
return false;
return true;
}
@Override
public String toString() {
return "[allocatedIpAddresses=" + allocatedIpAddresses + ", dns1=" + dns1 + ", dns2=" + dns2 + ", dnsSuffix="
+ dnsSuffix + ", gateway=" + gateway + ", inherited=" + inherited + ", ipRanges=" + ipRanges
+ ", netmask=" + netmask + "]";
}
}

View File

@ -0,0 +1,137 @@
/**
*
* 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.network;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.List;
import javax.annotation.Nullable;
import org.jclouds.vcloud.domain.network.nat.NatPolicy;
import org.jclouds.vcloud.domain.network.nat.NatRule;
import org.jclouds.vcloud.domain.network.nat.NatType;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
/**
* The NatService element defines the network address translation capabilities of a network.
*/
public class NatService {
private final boolean enabled;
@Nullable
private final NatType type;
@Nullable
private final NatPolicy policy;
private final List<NatRule> natRules = Lists.newArrayList();
public NatService(boolean enabled, @Nullable NatType type, @Nullable NatPolicy policy,
Iterable<? extends NatRule> natRules) {
this.enabled = enabled;
this.type = type;
this.policy = policy;
Iterables.addAll(this.natRules, checkNotNull(natRules, "natRules"));
}
/**
* @return Nat rules for the network
*
* @since vcloud api 0.8
*/
public List<? extends NatRule> getNatRules() {
return natRules;
}
/**
* @return true if the service is enabled
*
* @since vcloud api 0.9
*/
public boolean isEnabled() {
return enabled;
}
/**
* @return specifies how Network Address Translation is implemented by the NAT service
*
* @since vcloud api 0.9
*/
@Nullable
public NatType getType() {
return type;
}
/**
* @return specifies how packets are handled by the NAT service.
*
* @since vcloud api 0.9
*/
@Nullable
public NatPolicy getPolicy() {
return policy;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (enabled ? 1231 : 1237);
result = prime * result + ((natRules == null) ? 0 : natRules.hashCode());
result = prime * result + ((policy == null) ? 0 : policy.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;
NatService other = (NatService) obj;
if (enabled != other.enabled)
return false;
if (natRules == null) {
if (other.natRules != null)
return false;
} else if (!natRules.equals(other.natRules))
return false;
if (policy == null) {
if (other.policy != null)
return false;
} else if (!policy.equals(other.policy))
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 "[enabled=" + enabled + ", natRules=" + natRules + ", policy=" + policy + ", type=" + type + "]";
}
}

View File

@ -0,0 +1,125 @@
/**
*
* 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.network;
import java.util.List;
import java.util.Set;
import javax.annotation.Nullable;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.Task;
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.Network
@ImplementedBy(VDCImpl.class)
public interface OrgNetwork extends NamedResource {
/**
* The org this network belongs to.
*
* @since vcloud api 0.9
*/
@Nullable
NamedResource getOrg();
/**
* 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 0.9
*/
List<Task> getTasks();
/**
*
* @return properties of the network
*
* @since vcloud api 0.9, but emulated for 0.8
*/
Configuration getConfiguration();
/**
* A reference the network pool from which this network is provisioned. This element, which is
* required when creating a NatRouted or Isolated network, is returned in response to a creation
* request but not shown in subsequent GET requests.
*
* @since vcloud api 0.9
*/
@Nullable
NamedResource getNetworkPool();
/**
* list of external IP addresses that this network can use for NAT.
*
* @since vcloud api 0.9
*/
Set<String> getAllowedExternalIpAddresses();
/**
* The Configuration element specifies properties of a network.
*/
interface Configuration {
/**
* defines the address range, gateway, netmask, and other properties of the network.
*
* @since vcloud api 0.9, but emulated for 0.8
*/
@Nullable
IpScope getIpScope();
/**
* reference to a network to which this network connects
*
* @since vcloud api 0.9
*/
@Nullable
NamedResource getParentNetwork();
/**
* defines how this network is connected to its ParentNetwork
*
* @since vcloud api 0.8
*/
FenceMode getFenceMode();
/**
* defines a set of network features.
*
* @since vcloud api 0.9, but emulated for 0.8
*/
@Nullable Features getFeatures();
}
}

View File

@ -17,19 +17,23 @@
* ====================================================================
*/
package org.jclouds.vcloud.domain;
package org.jclouds.vcloud.domain.network;
import java.util.Set;
import javax.annotation.Nullable;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.network.firewall.FirewallRule;
import org.jclouds.vcloud.domain.network.nat.rules.PortForwardingRule;
/**
*
* A network that is available in a vDC.
*
* @author Adrian Cole
*/
public interface Network extends NamedResource {
public interface VCloudExpressNetwork extends NamedResource {
/**
*
* @return Description of the network
@ -58,7 +62,7 @@ public interface Network extends NamedResource {
/**
* return the networks fence modes.
*/
Set<String> getFenceModes();
Set<FenceMode> getFenceModes();
/**
* return True if the network provides DHCP services
@ -70,7 +74,7 @@ public interface Network extends NamedResource {
*
* @return Network Address Translation rules for the network
*/
Set<NatRule> getNatRules();
Set<PortForwardingRule> getNatRules();
/**
* @return Firewall rules for the network

View File

@ -17,38 +17,40 @@
* ====================================================================
*/
package org.jclouds.vcloud.functions;
package org.jclouds.vcloud.domain.network.firewall;
import java.net.URI;
import static com.google.common.base.Preconditions.checkNotNull;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.vcloud.domain.Organization;
import org.jclouds.vcloud.endpoints.VDC;
import com.google.common.base.Function;
import com.google.common.base.CaseFormat;
/**
* specifies how packets are handled by the firewall
*
* @author Adrian Cole
*/
@Singleton
public class VDCNameToEndpoint implements Function<Object, URI> {
private final URI defaultVDC;
private final Organization org;
public enum FirewallPolicy {
/**
* drop packets of this type
*/
DROP,
/**
* allow packets of this type to pass through the firewall
*/
ALLOW;
@Inject
public VDCNameToEndpoint(Organization org, @VDC URI defaultVDC) {
this.org = org;
this.defaultVDC = defaultVDC;
public String value() {
return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, name());
}
public URI apply(Object from) {
@Override
public String toString() {
return value();
}
public static FirewallPolicy fromValue(String policy) {
try {
return from == null ? defaultVDC : org.getVDCs().get(from).getId();
} catch (NullPointerException e) {
throw new IllegalArgumentException("vdc name: " + from + " not in " + org.getVDCs());
return valueOf(CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(policy, "policy")));
} catch (IllegalArgumentException e) {
return DROP;
}
}

View File

@ -0,0 +1,63 @@
package org.jclouds.vcloud.domain.network.firewall;
/**
* The Protocols element specifies the protocols to which firewall rules apply.
*
* @since vcloud api 0.9 emulated for 0.8
*
*
*/
public class FirewallProtocols {
private final boolean tcp;
private final boolean udp;
public FirewallProtocols(boolean tcp, boolean udp) {
this.tcp = tcp;
this.udp = udp;
}
/**
* @return true if the firewall rules apply to the TCP protocol
*/
public boolean isTcp() {
return tcp;
}
/**
* @return true if the firewall rules apply to the UDP protocol
*/
public boolean isUdp() {
return udp;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (tcp ? 1231 : 1237);
result = prime * result + (udp ? 1231 : 1237);
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
FirewallProtocols other = (FirewallProtocols) obj;
if (tcp != other.tcp)
return false;
if (udp != other.udp)
return false;
return true;
}
@Override
public String toString() {
return "Protocols [tcp=" + tcp + ", udp=" + udp + "]";
}
}

View File

@ -0,0 +1,156 @@
/**
*
* 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.network.firewall;
import static com.google.common.base.Preconditions.checkNotNull;
import javax.annotation.Nullable;
/**
* The FirewallRule element defines a single firewall rule.
*
* @author Adrian Cole
* @since vcloud api 0.8
*/
public class FirewallRule {
private final boolean enabled;
@Nullable
private final String description;
@Nullable
private final FirewallPolicy policy;
@Nullable
private final FirewallProtocols protocols;
private final int port;
private final String destinationIp;
public FirewallRule(boolean enabled, @Nullable String description, @Nullable FirewallPolicy policy,
@Nullable FirewallProtocols protocols, int port, String destinationIp) {
this.enabled = enabled;
this.description = description;
this.policy = policy;
this.protocols = protocols;
this.port = port;
this.destinationIp = checkNotNull(destinationIp, "destinationIp");
}
/**
* @return true if the rule is enabled
*/
public boolean isEnabled() {
return enabled;
}
/**
* @return description of the rule
*/
@Nullable
public String getDescription() {
return description;
}
/**
* @return specifies how packets are handled by the firewall
*/
@Nullable
public FirewallPolicy getPolicy() {
return policy;
}
/**
* @return specifies the protocols to which this firewall rule applies
*/
@Nullable
public FirewallProtocols getProtocols() {
return protocols;
}
/**
* @return specifies the network port to which this firewall rule applies. A value of 1 matches
* any port.
*/
public int getPort() {
return port;
}
/**
* @return specifies the destination IP address, inside the firewall, to which this firewall rule
* applies
*/
public String getDestinationIp() {
return destinationIp;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((description == null) ? 0 : description.hashCode());
result = prime * result + ((destinationIp == null) ? 0 : destinationIp.hashCode());
result = prime * result + (enabled ? 1231 : 1237);
result = prime * result + ((policy == null) ? 0 : policy.hashCode());
result = prime * result + port;
result = prime * result + ((protocols == null) ? 0 : protocols.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;
FirewallRule other = (FirewallRule) obj;
if (description == null) {
if (other.description != null)
return false;
} else if (!description.equals(other.description))
return false;
if (destinationIp == null) {
if (other.destinationIp != null)
return false;
} else if (!destinationIp.equals(other.destinationIp))
return false;
if (enabled != other.enabled)
return false;
if (policy == null) {
if (other.policy != null)
return false;
} else if (!policy.equals(other.policy))
return false;
if (port != other.port)
return false;
if (protocols == null) {
if (other.protocols != null)
return false;
} else if (!protocols.equals(other.protocols))
return false;
return true;
}
@Override
public String toString() {
return "[description=" + description + ", destinationIp=" + destinationIp + ", enabled=" + enabled + ", policy="
+ policy + ", port=" + port + ", protocols=" + protocols + "]";
}
}

View File

@ -0,0 +1,281 @@
/**
*
* 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.network.internal;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.List;
import java.util.Set;
import javax.annotation.Nullable;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.internal.NamedResourceImpl;
import org.jclouds.vcloud.domain.network.Features;
import org.jclouds.vcloud.domain.network.FenceMode;
import org.jclouds.vcloud.domain.network.IpScope;
import org.jclouds.vcloud.domain.network.OrgNetwork;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
/**
*
* @author Adrian Cole
*/
public class OrgNetworkImpl extends NamedResourceImpl implements OrgNetwork {
@Nullable
private final NamedResource org;
@Nullable
private final String description;
private final List<Task> tasks = Lists.newArrayList();
private final Configuration configuration;
@Nullable
private final NamedResource networkPool;
private final Set<String> allowedExternalIpAddresses = Sets.newLinkedHashSet();
public OrgNetworkImpl(String name, String type, URI id, @Nullable NamedResource org, @Nullable String description,
Iterable<Task> tasks, Configuration configuration, @Nullable NamedResource networkPool,
Iterable<String> allowedExternalIpAddresses) {
super(name, type, id);
this.org = org;
this.description = description;
Iterables.addAll(this.tasks, checkNotNull(tasks, "tasks"));
this.configuration = checkNotNull(configuration, "configuration");
this.networkPool = networkPool;
Iterables.addAll(this.allowedExternalIpAddresses, checkNotNull(allowedExternalIpAddresses,
"allowedExternalIpAddresses"));
}
public static class ConfigurationImpl implements Configuration {
@Nullable
private final IpScope ipScope;
@Nullable
private final NamedResource parentNetwork;
private final FenceMode fenceMode;
private final Features features;
public ConfigurationImpl(@Nullable IpScope ipScope, @Nullable NamedResource parentNetwork, FenceMode fenceMode,
@Nullable Features features) {
this.ipScope = ipScope;
this.parentNetwork = parentNetwork;
this.fenceMode = checkNotNull(fenceMode, "fenceMode");
this.features = features;
}
/**
* {@inheritDoc}
*/
@Override
public IpScope getIpScope() {
return ipScope;
}
/**
* {@inheritDoc}
*/
@Override
public NamedResource getParentNetwork() {
return parentNetwork;
}
/**
* {@inheritDoc}
*/
@Override
public FenceMode getFenceMode() {
return fenceMode;
}
/**
* {@inheritDoc}
*/
@Override
@Nullable
public Features getFeatures() {
return features;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((features == null) ? 0 : features.hashCode());
result = prime * result + ((fenceMode == null) ? 0 : fenceMode.hashCode());
result = prime * result + ((ipScope == null) ? 0 : ipScope.hashCode());
result = prime * result + ((parentNetwork == null) ? 0 : parentNetwork.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;
ConfigurationImpl other = (ConfigurationImpl) obj;
if (features == null) {
if (other.features != null)
return false;
} else if (!features.equals(other.features))
return false;
if (fenceMode == null) {
if (other.fenceMode != null)
return false;
} else if (!fenceMode.equals(other.fenceMode))
return false;
if (ipScope == null) {
if (other.ipScope != null)
return false;
} else if (!ipScope.equals(other.ipScope))
return false;
if (parentNetwork == null) {
if (other.parentNetwork != null)
return false;
} else if (!parentNetwork.equals(other.parentNetwork))
return false;
return true;
}
@Override
public String toString() {
return "[features=" + features + ", fenceMode=" + fenceMode + ", ipScope=" + ipScope + ", parentNetwork="
+ parentNetwork + "]";
}
}
/**
* {@inheritDoc}
*/
@Override
public NamedResource getOrg() {
return org;
}
/**
* {@inheritDoc}
*/
@Override
public String getDescription() {
return description;
}
/**
* {@inheritDoc}
*/
@Override
public List<Task> getTasks() {
return tasks;
}
/**
* {@inheritDoc}
*/
@Override
public Configuration getConfiguration() {
return configuration;
}
/**
* {@inheritDoc}
*/
@Override
public NamedResource getNetworkPool() {
return networkPool;
}
/**
* {@inheritDoc}
*/
@Override
public Set<String> getAllowedExternalIpAddresses() {
return allowedExternalIpAddresses;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((allowedExternalIpAddresses == null) ? 0 : allowedExternalIpAddresses.hashCode());
result = prime * result + ((configuration == null) ? 0 : configuration.hashCode());
result = prime * result + ((description == null) ? 0 : description.hashCode());
result = prime * result + ((networkPool == null) ? 0 : networkPool.hashCode());
result = prime * result + ((org == null) ? 0 : org.hashCode());
result = prime * result + ((tasks == null) ? 0 : tasks.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
OrgNetworkImpl other = (OrgNetworkImpl) obj;
if (allowedExternalIpAddresses == null) {
if (other.allowedExternalIpAddresses != null)
return false;
} else if (!allowedExternalIpAddresses.equals(other.allowedExternalIpAddresses))
return false;
if (configuration == null) {
if (other.configuration != null)
return false;
} else if (!configuration.equals(other.configuration))
return false;
if (description == null) {
if (other.description != null)
return false;
} else if (!description.equals(other.description))
return false;
if (networkPool == null) {
if (other.networkPool != null)
return false;
} else if (!networkPool.equals(other.networkPool))
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;
return true;
}
@Override
public String toString() {
return "[allowedExternalIpAddresses=" + allowedExternalIpAddresses + ", configuration=" + configuration
+ ", description=" + description + ", networkPool=" + networkPool + ", org=" + org + ", tasks=" + tasks
+ "]";
}
}

View File

@ -17,16 +17,17 @@
* ====================================================================
*/
package org.jclouds.vcloud.domain.internal;
package org.jclouds.vcloud.domain.network.internal;
import java.net.URI;
import java.util.Set;
import org.jclouds.vcloud.VCloudExpressMediaType;
import org.jclouds.vcloud.domain.FirewallRule;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.NatRule;
import org.jclouds.vcloud.domain.Network;
import org.jclouds.vcloud.domain.internal.NamedResourceImpl;
import org.jclouds.vcloud.domain.network.FenceMode;
import org.jclouds.vcloud.domain.network.VCloudExpressNetwork;
import org.jclouds.vcloud.domain.network.firewall.FirewallRule;
import org.jclouds.vcloud.domain.network.nat.rules.PortForwardingRule;
import com.google.common.collect.Sets;
import com.google.inject.internal.Nullable;
@ -37,7 +38,7 @@ import com.google.inject.internal.Nullable;
* @author Adrian Cole
*
*/
public class NetworkImpl extends NamedResourceImpl implements Network {
public class VCloudExpressNetworkImpl extends NamedResourceImpl implements VCloudExpressNetwork {
/** The serialVersionUID */
private static final long serialVersionUID = 8464716396538298809L;
@ -45,15 +46,16 @@ public class NetworkImpl extends NamedResourceImpl implements Network {
private final Set<String> dnsServers = Sets.newHashSet();
private final String gateway;
private final String netmask;
private final Set<String> fenceModes = Sets.newHashSet();
private final Set<FenceMode> fenceModes = Sets.newHashSet();
@Nullable
private final Boolean dhcp;
private final Set<NatRule> natRules = Sets.newHashSet();
private final Set<PortForwardingRule> natRules = Sets.newHashSet();
private final Set<FirewallRule> firewallRules = Sets.newHashSet();
public NetworkImpl(String name, URI id, String description, Set<String> dnsServers, String gateway,
String netmask, Set<String> fenceModes, Boolean dhcp, Set<NatRule> natRules, Set<FirewallRule> firewallRules) {
super(name, VCloudExpressMediaType.NETWORK_XML, id);
public VCloudExpressNetworkImpl(String name, String type, URI id, String description, Set<String> dnsServers,
String gateway, String netmask, Set<FenceMode> fenceModes, Boolean dhcp, Set<PortForwardingRule> natRules,
Set<FirewallRule> firewallRules) {
super(name, type, id);
this.description = description;
this.dnsServers.addAll(dnsServers);
this.gateway = gateway;
@ -95,7 +97,7 @@ public class NetworkImpl extends NamedResourceImpl implements Network {
/**
* {@inheritDoc}
*/
public Set<String> getFenceModes() {
public Set<FenceMode> getFenceModes() {
return fenceModes;
}
@ -109,7 +111,7 @@ public class NetworkImpl extends NamedResourceImpl implements Network {
/**
* {@inheritDoc}
*/
public Set<NatRule> getNatRules() {
public Set<PortForwardingRule> getNatRules() {
return natRules;
}
@ -148,7 +150,7 @@ public class NetworkImpl extends NamedResourceImpl implements Network {
return false;
if (getClass() != obj.getClass())
return false;
NetworkImpl other = (NetworkImpl) obj;
VCloudExpressNetworkImpl other = (VCloudExpressNetworkImpl) obj;
if (description == null) {
if (other.description != null)
return false;
@ -195,9 +197,9 @@ public class NetworkImpl extends NamedResourceImpl implements Network {
@Override
public String toString() {
return "NetworkImpl [id=" + getId() + ", name=" + getName() + ", type=" + getType() + ", description="
+ description + ", dhcp=" + dhcp + ", dnsServers=" + dnsServers + ", fenceModes=" + fenceModes
+ ", firewallRules=" + firewallRules + ", gateway=" + gateway + ", natRules=" + natRules + ", netmask="
+ netmask + "]";
+ description + ", dhcp=" + dhcp + ", dnsServers=" + dnsServers + ", fenceModes=" + fenceModes
+ ", firewallRules=" + firewallRules + ", gateway=" + gateway + ", natRules=" + natRules + ", netmask="
+ netmask + "]";
}
}

View File

@ -0,0 +1,66 @@
/**
*
* 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.network.internal;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.network.DhcpService;
import org.jclouds.vcloud.domain.network.Features;
import org.jclouds.vcloud.domain.network.FenceMode;
import org.jclouds.vcloud.domain.network.FirewallService;
import org.jclouds.vcloud.domain.network.IpRange;
import org.jclouds.vcloud.domain.network.IpScope;
import org.jclouds.vcloud.domain.network.NatService;
import org.jclouds.vcloud.domain.network.VCloudExpressNetwork;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
/**
*
* @author Adrian Cole
*/
public class VCloudExpressOrgNetworkAdapter extends OrgNetworkImpl {
public VCloudExpressOrgNetworkAdapter(VCloudExpressNetwork in) {
super(in.getName(), in.getType(), in.getId(), null, in.getDescription(), ImmutableSet.<Task> of(),
parseConfiguration(in), null, ImmutableSet.<String> of());
}
static Configuration parseConfiguration(VCloudExpressNetwork in) {
String dns1 = (in.getDnsServers().size() > 0) ? Iterables.get(in.getDnsServers(), 0) : null;
String dns2 = (in.getDnsServers().size() > 1) ? Iterables.get(in.getDnsServers(), 1) : null;
String gateway = in.getGateway();
String netmask = in.getNetmask();
FenceMode mode = in.getFenceModes().size() > 0 ? Iterables.get(in.getFenceModes(), 0) : FenceMode.BRIDGED;
DhcpService dhcp = in.isDhcp() != null && in.isDhcp() ? new DhcpService(true, null, null, null) : null;
NatService nat = in.getNatRules().size() > 0 ? new NatService(true, null, null, in.getNatRules()) : null;
FirewallService firewall = in.getFirewallRules().size() > 0 ? new FirewallService(true, in.getFirewallRules())
: null;
return new OrgNetworkImpl.ConfigurationImpl(new IpScope(true, gateway, netmask, dns1, dns2, null, ImmutableSet
.<IpRange> of(), ImmutableSet.<String> of()), null, mode, new Features(dhcp, firewall, nat));
}
}

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.domain.network.nat;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.base.CaseFormat;
/**
* The Policy element of a NatService element specifies how packets are handled by the NAT service.
*
*/
public enum NatPolicy {
/**
* packets of this type pass through the firewall in both directions
*/
ALLOW_TRAFFIC,
/**
* only inbound packets of this type pass through the firewall
*/
ALLOW_TRAFFIC_IN;
public String value() {
return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, name());
}
@Override
public String toString() {
return value();
}
public static NatPolicy fromValue(String policy) {
try {
return valueOf(CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(policy, "policy")));
} catch (IllegalArgumentException e) {
return ALLOW_TRAFFIC_IN;
}
}
}

View File

@ -17,26 +17,35 @@
* ====================================================================
*/
package org.jclouds.vcloud.domain;
package org.jclouds.vcloud.domain.network.nat;
/**
*
* The FenceMode element contains one of the following strings that specify how
* a network is connected to its parent network.
* The Protocol specifies the network protocol to which this rule applies
*
* @since vcloud api 0.9
*
* @author Adrian Cole
*/
public interface FenceMode {
public enum NatProtocol {
/**
* The two networks are bridged.
* the rule applies to the TCP protocol
*
* @since vcloud api 0.9
*/
public static final String BRIDGED = "bridged";
TCP,
/**
* The two networks are not connected.
* the rule applies to the UDP protocol
*
* @since vcloud api 0.9
*/
public static final String ISOLATED = "isolated";
UDP,
/**
* The two networks are connected as specified in their NatService elements.
* the rule applies to the TCP and UDP protocols.
*
* @since vcloud api 0.9
*/
public static final String NAT_ROUTED = "natRouted";
TCP_UDP;
}

View File

@ -17,20 +17,22 @@
* ====================================================================
*/
package org.jclouds.vcloud.hostingdotcom.domain;
package org.jclouds.vcloud.domain.network.nat;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.hostingdotcom.domain.internal.HostingDotComVAppImpl;
import com.google.inject.ImplementedBy;
import javax.annotation.Nullable;
/**
*
* Defines a rule associated with Nat
*
* @since vcloud api 0.9
*
* @author Adrian Cole
*/
@ImplementedBy(HostingDotComVAppImpl.class)
public interface HostingDotComVApp extends VApp {
String getUsername();
String getPassword();
public interface NatRule {
/**
* IP address to which this NAT rule maps the IP address specified in the InternalIp element.
*/
@Nullable
String getExternalIP();
}

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.network.nat;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.base.CaseFormat;
/**
*
* The NatType element specifies how network address translation is implemented by the NAT service.
*
* @since vcloud api 0.9
*
* @author Adrian Cole
*/
public enum NatType {
/**
* NAT service implemented by IP address translation
*
* @since vcloud api 0.9
*/
IP_TRANSLATION,
/**
* NAT service implemented by network port forwarding
*
* @since vcloud api 0.9
*/
PORT_FORWARDING;
public String value() {
return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, name());
}
@Override
public String toString() {
return value();
}
public static NatType fromValue(String natType) {
return valueOf(CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(natType, "natType")));
}
}

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.network.nat.rules;
import static com.google.common.base.Preconditions.checkNotNull;
import javax.annotation.Nullable;
import org.jclouds.vcloud.domain.MappingMode;
import org.jclouds.vcloud.domain.network.nat.NatRule;
/**
* The OneToOneVmRule element describes a NAT rule that specifies network address translation
* details for a single virtual machine. The external IP address can be specified manually or
* assigned automatically at deployment time. The internal IP address is discovered by looking up
* the specified VmReference and NIC ID.
*
* @since vcloud 0.9
* @author Adrian Cole
*/
public class OneToOneVmRule implements NatRule {
private final MappingMode mappingMode;
@Nullable
private final String externalIP;
@Nullable
private final String vAppScopedVmId;
private final int vmNicId;
public OneToOneVmRule(MappingMode mappingMode, @Nullable String externalIp, @Nullable String vAppScopedVmId,
int vmNicId) {
this.mappingMode = checkNotNull(mappingMode, "mappingMode");
this.externalIP = externalIp;
this.vAppScopedVmId = vAppScopedVmId;
this.vmNicId = vmNicId;
}
/**
* @return how IP address mapping is implemented by the NAT service
* @since vcloud 0.9
*/
public MappingMode getMappingMode() {
return mappingMode;
}
/**
* @return if MappingMode is manual, specifies the external IP address of this Vm, otherwise
* null.
* @since vcloud 0.9
*/
@Nullable
@Override
public String getExternalIP() {
return externalIP;
}
/**
* @return readonly identifier created on import
* @since vcloud 0.9
*/
@Nullable
public String getVAppScopedVmId() {
return vAppScopedVmId;
}
/**
* @return device number of the NIC on the referenced virtual machine
* @since vcloud 0.9
*/
public int getVmNicId() {
return vmNicId;
}
}

View File

@ -0,0 +1,137 @@
/**
*
* 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.network.nat.rules;
import static com.google.common.base.Preconditions.checkNotNull;
import org.jclouds.vcloud.domain.network.nat.NatProtocol;
import org.jclouds.vcloud.domain.network.nat.NatRule;
/**
* The PortForwardingRule element describes a NAT rule that maps an IP address and port in an
* organization network to an external IP address and port.
*
* @since vcloud 0.8
* @author Adrian Cole
*/
public class PortForwardingRule implements NatRule {
private final String externalIP;
private final int externalPort;
private final String internalIP;
private final int internalPort;
private final NatProtocol protocol;
public PortForwardingRule(String externalIP, int externalPort, String internalIP, int internalPort,
NatProtocol protocol) {
this.externalIP = checkNotNull(externalIP, "externalIP");
this.externalPort = externalPort;
this.internalIP = checkNotNull(internalIP, "internalIP");
this.internalPort = internalPort;
this.protocol = checkNotNull(protocol, "protocol");
}
/**
* IP address to which this NAT rule maps the IP address specified in the InternalIp element.
*/
@Override
public String getExternalIP() {
return externalIP;
}
/**
* network port to which this NAT rule maps the port number specified in the InternalPort element
*/
public int getExternalPort() {
return externalPort;
}
/**
* IP address to which this NAT rule maps the IP address specified in the ExternalIp element.
*/
public String getInternalIP() {
return internalIP;
}
/**
* network port to which this NAT rule maps the port number specified in the ExternalPort
* element.
*/
public int getInternalPort() {
return internalPort;
}
/**
* specifies the network protocol to which this rule applies
*/
public NatProtocol getProtocol() {
return protocol;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((externalIP == null) ? 0 : externalIP.hashCode());
result = prime * result + externalPort;
result = prime * result + ((internalIP == null) ? 0 : internalIP.hashCode());
result = prime * result + internalPort;
result = prime * result + ((protocol == null) ? 0 : protocol.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;
PortForwardingRule other = (PortForwardingRule) obj;
if (externalIP == null) {
if (other.externalIP != null)
return false;
} else if (!externalIP.equals(other.externalIP))
return false;
if (externalPort != other.externalPort)
return false;
if (internalIP == null) {
if (other.internalIP != null)
return false;
} else if (!internalIP.equals(other.internalIP))
return false;
if (internalPort != other.internalPort)
return false;
if (protocol == null) {
if (other.protocol != null)
return false;
} else if (!protocol.equals(other.protocol))
return false;
return true;
}
@Override
public String toString() {
return "[externalIP=" + externalIP + ", externalPort=" + externalPort + ", internalIP=" + internalIP
+ ", internalPort=" + internalPort + ", protocol=" + protocol + "]";
}
}

View File

@ -0,0 +1,157 @@
/**
*
* 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.network.nat.rules;
import static com.google.common.base.Preconditions.checkNotNull;
import javax.annotation.Nullable;
import org.jclouds.vcloud.domain.network.nat.NatProtocol;
import org.jclouds.vcloud.domain.network.nat.NatRule;
/**
* The VmRule element describes a NAT rule that maps an IP address and port in a vApp network to an
* external IP address and port. The external IP address, external port, and internal port are
* specified in the element. The internal IP address is discovered by looking up the specified
* VmReference and VmNicId.
*
* @since vcloud 0.9
* @author Adrian Cole
*/
public class VmRule implements NatRule {
@Nullable
private final String externalIP;
private final int externalPort;
@Nullable
private final String vAppScopedLocalId;
private final int vmNicId;
private final int internalPort;
private final NatProtocol protocol;
public VmRule(@Nullable String externalIP, int externalPort, @Nullable String vAppScopedLocalId, int vmNicId,
int internalPort, NatProtocol protocol) {
this.externalIP = externalIP;
this.externalPort = externalPort;
this.vAppScopedLocalId = vAppScopedLocalId;
this.vmNicId = vmNicId;
this.internalPort = internalPort;
this.protocol = checkNotNull(protocol, "protocol");
}
/**
* IP address to which this NAT rule maps the IP address specified in the InternalIp element.
*/
@Nullable
public String getExternalIP() {
return externalIP;
}
/**
* network port to which this NAT rule maps the port number specified in the InternalPort element
*/
public Integer getExternalPort() {
return externalPort;
}
/**
* @return readonly identifier created on import
* @since vcloud 0.9
*/
@Nullable
public String getVAppScopedLocalId() {
return vAppScopedLocalId;
}
/**
* @return device number of the NIC on the referenced virtual machine
* @since vcloud 0.9
*/
public int getVmNicId() {
return vmNicId;
}
/**
* network port to which this NAT rule maps the port number specified in the ExternalPort
* element.
*/
public Integer getInternalPort() {
return internalPort;
}
/**
* specifies the network protocol to which this rule applies
*/
public NatProtocol getProtocol() {
return protocol;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((externalIP == null) ? 0 : externalIP.hashCode());
result = prime * result + externalPort;
result = prime * result + internalPort;
result = prime * result + ((protocol == null) ? 0 : protocol.hashCode());
result = prime * result + ((vAppScopedLocalId == null) ? 0 : vAppScopedLocalId.hashCode());
result = prime * result + vmNicId;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
VmRule other = (VmRule) obj;
if (externalIP == null) {
if (other.externalIP != null)
return false;
} else if (!externalIP.equals(other.externalIP))
return false;
if (externalPort != other.externalPort)
return false;
if (internalPort != other.internalPort)
return false;
if (protocol == null) {
if (other.protocol != null)
return false;
} else if (!protocol.equals(other.protocol))
return false;
if (vAppScopedLocalId == null) {
if (other.vAppScopedLocalId != null)
return false;
} else if (!vAppScopedLocalId.equals(other.vAppScopedLocalId))
return false;
if (vmNicId != other.vmNicId)
return false;
return true;
}
@Override
public String toString() {
return "[externalIP=" + externalIP + ", externalPort=" + externalPort + ", internalPort=" + internalPort
+ ", protocol=" + protocol + ", vAppScopedLocalId=" + vAppScopedLocalId + ", vmNicId=" + vmNicId + "]";
}
}

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