Merge branch 'master' of git://github.com/jclouds/jclouds into large-blob

This commit is contained in:
Tibor Kiss 2011-03-22 10:00:16 +01:00
commit c4c6c5b0b2
19 changed files with 955 additions and 423 deletions

View File

@ -28,6 +28,7 @@ import java.util.Set;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.cim.OSType;
import org.jclouds.collect.Memoized;
import org.jclouds.compute.domain.CIMOperatingSystem;
import org.jclouds.compute.domain.Image;
@ -76,7 +77,7 @@ public class VCloudExpressVAppToNodeMetadata implements Function<VCloudExpressVA
builder.name(from.getName());
builder.location(findLocationForResourceInVDC.apply(from.getVDC()));
builder.group(parseGroupFromName(from.getName()));
builder.operatingSystem(from.getOsType() != null ? new CIMOperatingSystem(CIMOperatingSystem.OSType
builder.operatingSystem(from.getOsType() != null ? new CIMOperatingSystem(OSType
.fromValue(from.getOsType()), null, null, from.getOperatingSystemDescription()) : null);
builder.hardware(hardwareForVCloudExpressVApp.apply(from));
builder.state(vAppStatusToNodeState.get(from.getStatus()));

View File

@ -0,0 +1,243 @@
/**
*
* 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.cim;
import org.jclouds.compute.domain.OsFamily;
/**
* Operating system based on DMTF CIM model.
*
* @author Adrian Cole
* @see <a
* href="http://dmtf.org/sites/default/files/cim/cim_schema_v2280/cim_schema_2.28.0Final-Doc.zip"
* />
*/
public enum OSType {
/**
* Other
*/
OTHER(1, "Other", OsFamily.UNRECOGNIZED, false),
/**
* MACOS
*/
MACOS(2, "MACOS", OsFamily.DARWIN, false),
/**
* Solaris
*/
SOLARIS(29, "Solaris", OsFamily.SOLARIS, false),
/**
* LINUX
*/
LINUX(36, "LINUX", OsFamily.LINUX, false),
/**
* FreeBSD
*/
FREEBSD(42, "FreeBSD", OsFamily.FREEBSD, false),
/**
* NetBSD
*/
NETBSD(43, "NetBSD", OsFamily.NETBSD, false),
/**
* OpenBSD
*/
OPENBSD(65, "OpenBSD", OsFamily.OPENBSD, false),
/**
* Not Applicable
*/
NOT_APPLICABLE(66, "Not Applicable", OsFamily.UNRECOGNIZED, false),
/**
* Microsoft Windows Server 2003
*/
WINDOWS_SERVER_2003(69, "Microsoft Windows Server 2003", OsFamily.WINDOWS, false),
/**
* Microsoft Windows Server 2003 64-Bit
*/
WINDOWS_SERVER_2003_64(70, "Microsoft Windows Server 2003 64-Bit", OsFamily.WINDOWS, true),
/**
* Microsoft Windows Server 2008
*/
WINDOWS_SERVER_2008(76, "Microsoft Windows Server 2008", OsFamily.WINDOWS, false),
/**
* Microsoft Windows Server 2008 64-Bit
*/
WINDOWS_SERVER_2008_64(77, "Microsoft Windows Server 2008 64-Bit", OsFamily.WINDOWS, true),
/**
* FreeBSD 64-Bit
*/
FREEBSD_64(78, "FreeBSD 64-Bit", OsFamily.FREEBSD, true),
/**
* RedHat Enterprise Linux
*/
RHEL(79, "RedHat Enterprise Linux", OsFamily.RHEL, false),
/**
* RedHat Enterprise Linux 64-Bit
*/
RHEL_64(80, "RedHat Enterprise Linux 64-Bit", OsFamily.RHEL, true),
/**
* Solaris 64-Bit
*/
SOLARIS_64(81, "Solaris 64-Bit", OsFamily.SOLARIS, true),
/**
* SUSE
*/
SUSE(82, "SUSE", OsFamily.SUSE, false),
/**
* SUSE 64-Bit
*/
SUSE_64(83, "SUSE 64-Bit", OsFamily.SUSE, true),
/**
* SLES
*/
SLES(84, "SLES", OsFamily.SUSE, false),
/**
* SLES 64-Bit
*/
SLES_64(85, "SLES 64-Bit", OsFamily.SUSE, true),
/**
* Novell OES
*/
NOVELL_OES(86, "Novell OES", OsFamily.SUSE, true),
/**
* Mandriva
*/
MANDRIVA(89, "Mandriva", OsFamily.MANDRIVA, false),
/**
* Mandriva 64-Bit
*/
MANDRIVA_64(90, "Mandriva 64-Bit", OsFamily.MANDRIVA, true),
/**
* TurboLinux
*/
TURBOLINUX(91, "TurboLinux", OsFamily.TURBOLINUX, false),
/**
* TurboLinux 64-Bit
*/
TURBOLINUX_64(92, "TurboLinux 64-Bit", OsFamily.TURBOLINUX, true),
/**
* Ubuntu
*/
UBUNTU(93, "Ubuntu", OsFamily.UBUNTU, false),
/**
* Ubuntu 64-Bit
*/
UBUNTU_64(94, "Ubuntu 64-Bit", OsFamily.UBUNTU, true),
/**
* Debian
*/
DEBIAN(95, "Debian", OsFamily.DEBIAN, false),
/**
* Debian 64-Bit
*/
DEBIAN_64(96, "Debian 64-Bit", OsFamily.DEBIAN, false),
/**
* Linux 2.4.x
*/
LINUX_2_4(97, "Linux 2.4.x", OsFamily.LINUX, false),
/**
* Linux 2.4.x 64-Bi
*/
LINUX_2_4_64(98, "Linux 2.4.x 64-Bit", OsFamily.LINUX, true),
/**
* Linux 2.6.x
*/
LINUX_2_6(99, "Linux 2.6.x", OsFamily.LINUX, false),
/**
* Linux 2.6.x 64-Bit
*/
LINUX_2_6_64(100, "Linux 2.6.x 64-Bit", OsFamily.LINUX, true),
/**
* Linux 64-Bit
*/
LINUX_64(101, "Linux 64-Bit", OsFamily.LINUX, true),
/**
* Other 64-Bit
*/
OTHER_64(102, "Other 64-Bit", OsFamily.UNRECOGNIZED, true),
/**
* Microsoft Windows Server 2008 R2
*/
WINDOWS_SERVER_2008_R2(103, "Microsoft Windows Server 2008 R2", OsFamily.WINDOWS, true),
/**
* VMware ESXi
*/
ESXI(104, "VMware ESXi", OsFamily.ESX, true),
/**
* Microsoft Windows 7
*/
WINDOWS_7(105, "Microsoft Windows 7", OsFamily.WINDOWS, false),
/**
* CentOS 32-bit
*/
CENTOS(106, "CentOS 32-bit", OsFamily.CENTOS, false),
/**
* CentOS 64-bit
*/
CENTOS_64(107, "CentOS 64-bit", OsFamily.CENTOS, true),
/**
* Oracle Enterprise Linux 32-bit
*/
ORACLE_ENTERPRISE_LINUX(108, "Oracle Enterprise Linux 32-bit", OsFamily.OEL, false),
/**
* Oracle Enterprise Linux 64-bit
*/
ORACLE_ENTERPRISE_LINUX_64(109, "Oracle Enterprise Linux 64-bit", OsFamily.OEL, true),
/**
* eComStation 32-bitx
*/
ECOMSTATION_32(109, "eComStation 32-bitx", OsFamily.UNRECOGNIZED, false), UNRECOGNIZED(Integer.MAX_VALUE,
"UNRECOGNIZED", null, true);
private final int code;
public int getCode() {
return code;
}
public String getValue() {
return value;
}
public OsFamily getFamily() {
return family;
}
public boolean is64Bit() {
return is64Bit;
}
private final String value;
private final OsFamily family;
private final boolean is64Bit;
OSType(int code, String value, OsFamily family, boolean is64Bit) {
this.code = code;
this.value = value;
this.family = family;
this.is64Bit = is64Bit;
}
public static OSType fromValue(int code) {
for (OSType type : values()) {
if (type.code == code)
return type;
}
return UNRECOGNIZED;
}
}

View File

@ -19,6 +19,9 @@
package org.jclouds.compute.domain;
import javax.annotation.Nullable;
import org.jclouds.cim.OSType;
import org.jclouds.ovf.OvfEnvelope;
import com.google.common.annotations.Beta;
@ -31,228 +34,99 @@ import com.google.common.annotations.Beta;
*/
@Beta
public class CIMOperatingSystem extends OperatingSystem {
public static Builder builder() {
return new Builder();
}
public static class Builder extends OperatingSystem.Builder {
private OSType osType;
/**
* @see CIMOperatingSystem#getOsType
*/
public Builder osType(@Nullable OSType osType) {
this.osType = osType;
return this;
}
/**
* {@inheritDoc}
*/
@Override
public CIMOperatingSystem build() {
return new CIMOperatingSystem(family, name, version, arch, description, is64Bit, osType);
}
public Builder fromCIMOperatingSystem(CIMOperatingSystem in) {
return fromOperatingSystem(in).osType(in.getOsType());
}
/**
* {@inheritDoc}
*/
@Override
public Builder arch(String arch) {
return Builder.class.cast(super.arch(arch));
}
/**
* {@inheritDoc}
*/
@Override
public Builder description(String description) {
return Builder.class.cast(super.description(description));
}
/**
* {@inheritDoc}
*/
@Override
public Builder family(OsFamily family) {
return Builder.class.cast(super.family(family));
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromOperatingSystem(OperatingSystem in) {
return Builder.class.cast(super.fromOperatingSystem(in));
}
/**
* {@inheritDoc}
*/
@Override
public Builder is64Bit(boolean is64Bit) {
return Builder.class.cast(super.is64Bit(is64Bit));
}
/**
* {@inheritDoc}
*/
@Override
public Builder name(String name) {
return Builder.class.cast(super.name(name));
}
/**
* {@inheritDoc}
*/
@Override
public Builder version(String version) {
return Builder.class.cast(super.version(version));
}
}
public static CIMOperatingSystem toComputeOs(org.jclouds.ovf.OperatingSystemSection os) {
return new CIMOperatingSystem(CIMOperatingSystem.OSType.fromValue(os.getId()), "", null, os.getDescription());
return new CIMOperatingSystem(OSType.fromValue(os.getId()), "", null, os.getDescription());
}
public static CIMOperatingSystem toComputeOs(OvfEnvelope ovf) {
return toComputeOs(ovf.getVirtualSystem().getOperatingSystem());
}
public enum OSType {
/**
* Other
*/
OTHER(1, "Other", OsFamily.UNRECOGNIZED, false),
/**
* MACOS
*/
MACOS(2, "MACOS", OsFamily.DARWIN, false),
/**
* Solaris
*/
SOLARIS(29, "Solaris", OsFamily.SOLARIS, false),
/**
* LINUX
*/
LINUX(36, "LINUX", OsFamily.LINUX, false),
/**
* FreeBSD
*/
FREEBSD(42, "FreeBSD", OsFamily.FREEBSD, false),
/**
* NetBSD
*/
NETBSD(43, "NetBSD", OsFamily.NETBSD, false),
/**
* OpenBSD
*/
OPENBSD(65, "OpenBSD", OsFamily.OPENBSD, false),
/**
* Not Applicable
*/
NOT_APPLICABLE(66, "Not Applicable", OsFamily.UNRECOGNIZED, false),
/**
* Microsoft Windows Server 2003
*/
WINDOWS_SERVER_2003(69, "Microsoft Windows Server 2003", OsFamily.WINDOWS, false),
/**
* Microsoft Windows Server 2003 64-Bit
*/
WINDOWS_SERVER_2003_64(70, "Microsoft Windows Server 2003 64-Bit", OsFamily.WINDOWS, true),
/**
* Microsoft Windows Server 2008
*/
WINDOWS_SERVER_2008(76, "Microsoft Windows Server 2008", OsFamily.WINDOWS, false),
/**
* Microsoft Windows Server 2008 64-Bit
*/
WINDOWS_SERVER_2008_64(77, "Microsoft Windows Server 2008 64-Bit", OsFamily.WINDOWS, true),
/**
* FreeBSD 64-Bit
*/
FREEBSD_64(78, "FreeBSD 64-Bit", OsFamily.FREEBSD, true),
/**
* RedHat Enterprise Linux
*/
RHEL(79, "RedHat Enterprise Linux", OsFamily.RHEL, false),
/**
* RedHat Enterprise Linux 64-Bit
*/
RHEL_64(80, "RedHat Enterprise Linux 64-Bit", OsFamily.RHEL, true),
/**
* Solaris 64-Bit
*/
SOLARIS_64(81, "Solaris 64-Bit", OsFamily.SOLARIS, true),
/**
* SUSE
*/
SUSE(82, "SUSE", OsFamily.SUSE, false),
/**
* SUSE 64-Bit
*/
SUSE_64(83, "SUSE 64-Bit", OsFamily.SUSE, true),
/**
* SLES
*/
SLES(84, "SLES", OsFamily.SUSE, false),
/**
* SLES 64-Bit
*/
SLES_64(85, "SLES 64-Bit", OsFamily.SUSE, true),
/**
* Novell OES
*/
NOVELL_OES(86, "Novell OES", OsFamily.SUSE, true),
/**
* Mandriva
*/
MANDRIVA(89, "Mandriva", OsFamily.MANDRIVA, false),
/**
* Mandriva 64-Bit
*/
MANDRIVA_64(90, "Mandriva 64-Bit", OsFamily.MANDRIVA, true),
/**
* TurboLinux
*/
TURBOLINUX(91, "TurboLinux", OsFamily.TURBOLINUX, false),
/**
* TurboLinux 64-Bit
*/
TURBOLINUX_64(92, "TurboLinux 64-Bit", OsFamily.TURBOLINUX, true),
/**
* Ubuntu
*/
UBUNTU(93, "Ubuntu", OsFamily.UBUNTU, false),
/**
* Ubuntu 64-Bit
*/
UBUNTU_64(94, "Ubuntu 64-Bit", OsFamily.UBUNTU, true),
/**
* Debian
*/
DEBIAN(95, "Debian", OsFamily.DEBIAN, false),
/**
* Debian 64-Bit
*/
DEBIAN_64(96, "Debian 64-Bit", OsFamily.DEBIAN, false),
/**
* Linux 2.4.x
*/
LINUX_2_4(97, "Linux 2.4.x", OsFamily.LINUX, false),
/**
* Linux 2.4.x 64-Bi
*/
LINUX_2_4_64(98, "Linux 2.4.x 64-Bit", OsFamily.LINUX, true),
/**
* Linux 2.6.x
*/
LINUX_2_6(99, "Linux 2.6.x", OsFamily.LINUX, false),
/**
* Linux 2.6.x 64-Bit
*/
LINUX_2_6_64(100, "Linux 2.6.x 64-Bit", OsFamily.LINUX, true),
/**
* Linux 64-Bit
*/
LINUX_64(101, "Linux 64-Bit", OsFamily.LINUX, true),
/**
* Other 64-Bit
*/
OTHER_64(102, "Other 64-Bit", OsFamily.UNRECOGNIZED, true),
/**
* Microsoft Windows Server 2008 R2
*/
WINDOWS_SERVER_2008_R2(103, "Microsoft Windows Server 2008 R2", OsFamily.WINDOWS, true),
/**
* VMware ESXi
*/
ESXI(104, "VMware ESXi", OsFamily.ESX, true),
/**
* Microsoft Windows 7
*/
WINDOWS_7(105, "Microsoft Windows 7", OsFamily.WINDOWS, false),
/**
* CentOS 32-bit
*/
CENTOS(106, "CentOS 32-bit", OsFamily.CENTOS, false),
/**
* CentOS 64-bit
*/
CENTOS_64(107, "CentOS 64-bit", OsFamily.CENTOS, true),
/**
* Oracle Enterprise Linux 32-bit
*/
ORACLE_ENTERPRISE_LINUX(108, "Oracle Enterprise Linux 32-bit", OsFamily.OEL, false),
/**
* Oracle Enterprise Linux 64-bit
*/
ORACLE_ENTERPRISE_LINUX_64(109, "Oracle Enterprise Linux 64-bit", OsFamily.OEL, true),
/**
* eComStation 32-bitx
*/
ECOMSTATION_32(109, "eComStation 32-bitx", OsFamily.UNRECOGNIZED, false), UNRECOGNIZED(Integer.MAX_VALUE,
"UNRECOGNIZED", null, true);
private final int code;
public int getCode() {
return code;
}
public String getValue() {
return value;
}
public OsFamily getFamily() {
return family;
}
public boolean is64Bit() {
return is64Bit;
}
private final String value;
private final OsFamily family;
private final boolean is64Bit;
OSType(int code, String value, OsFamily family, boolean is64Bit) {
this.code = code;
this.value = value;
this.family = family;
this.is64Bit = is64Bit;
}
public static OSType fromValue(int code) {
for (OSType type : values()) {
if (type.code == code)
return type;
}
return UNRECOGNIZED;
}
}
private OSType osType;
protected CIMOperatingSystem() {
@ -260,8 +134,14 @@ public class CIMOperatingSystem extends OperatingSystem {
}
public CIMOperatingSystem(OSType osType, String version, String arch, String description) {
super(osType.getFamily(), osType.getValue(), version, arch, description, osType.is64Bit());
this(osType.getFamily(), osType.getValue(), version, arch, description, osType.is64Bit(), osType);
}
public CIMOperatingSystem(@Nullable OsFamily family, @Nullable String name, @Nullable String version,
@Nullable String arch, String description, boolean is64Bit, OSType osType) {
super(family, name, version, arch, description, is64Bit);
this.osType = osType;
}
/**
@ -298,7 +178,7 @@ public class CIMOperatingSystem extends OperatingSystem {
@Override
public String toString() {
return "[osType=" + osType + ", version=" + getVersion() + ", arch=" + getArch() + ", description="
+ getDescription() + "]";
return String.format("[osType=%s, arch=%s, description=%s, family=%s, is64Bit=%s, name=%s, version=%s]", osType,
arch, description, family, is64Bit, name, version);
}
}

View File

@ -32,16 +32,69 @@ import com.google.common.annotations.Beta;
*/
@Beta
public class OperatingSystem {
public static Builder builder() {
return new Builder();
}
public static class Builder {
protected OsFamily family;
protected String name;
protected String arch;
protected String version;
protected String description;
protected boolean is64Bit;
public Builder family(@Nullable OsFamily family) {
this.family = family;
return this;
}
public Builder name(@Nullable String name) {
this.name = name;
return this;
}
public Builder arch(@Nullable String arch) {
this.arch = arch;
return this;
}
public Builder version(@Nullable String version) {
this.version = version;
return this;
}
public Builder description(String description) {
this.description = checkNotNull(description, "description");
return this;
}
public Builder is64Bit(boolean is64Bit) {
this.is64Bit = is64Bit;
return this;
}
public OperatingSystem build() {
return new OperatingSystem(family, name, version, arch, description, is64Bit);
}
public Builder fromOperatingSystem(OperatingSystem in) {
return family(in.getFamily()).name(in.getName()).version(in.getVersion()).arch(in.getArch()).description(
in.getDescription()).is64Bit(in.is64Bit());
}
}
@Nullable
private OsFamily family;
protected OsFamily family;
@Nullable
private String name;
protected String name;
@Nullable
private String arch;
protected String arch;
@Nullable
private String version;
private String description;
private boolean is64Bit;
protected String version;
protected String description;
protected boolean is64Bit;
// for serialization/deserialization
protected OperatingSystem() {
@ -61,9 +114,9 @@ public class OperatingSystem {
/**
* Type of the operating system
* <p/>
* generally, this is used to compare the means by which you use an operating
* system. For example, to determine compatibility of a particular
* bootstrapping or package installation approach.
* generally, this is used to compare the means by which you use an operating system. For
* example, to determine compatibility of a particular bootstrapping or package installation
* approach.
*/
@Nullable
public OsFamily getFamily() {
@ -73,10 +126,9 @@ public class OperatingSystem {
/**
* name of the operating system; ex. {@code Red Hat Enterprise Linux}
*
* <h2>note</h2> While this looks similar to, and may in some cases be the
* same as the java system property {@code os.name} it isn't guaranteed to
* match a particular value. For example, this value could be derived from
* data parsed for a cloud api or the OVF CIM OSType enum value;
* <h2>note</h2> While this looks similar to, and may in some cases be the same as the java
* system property {@code os.name} it isn't guaranteed to match a particular value. For example,
* this value could be derived from data parsed for a cloud api or the OVF CIM OSType enum value;
*
* @return operating system name or null if it couldn't be determined.
*/
@ -88,17 +140,15 @@ public class OperatingSystem {
/**
* architecture of the operating system; ex. {@code x86_64}
* <p/>
* generally, this is used to decide whether an operating system will run
* certain binaries, for example, a 64bit JDK.
* generally, this is used to decide whether an operating system will run certain binaries, for
* example, a 64bit JDK.
*
* <h2>note</h2>
* While this looks similar to, and may in some cases be the same as the java
* system property {@code os.arch} it isn't guaranteed to match a particular
* value. For example, this value could be derived from data parsed for a
* cloud api or the OVF CIM OSType enum value;
* While this looks similar to, and may in some cases be the same as the java system property
* {@code os.arch} it isn't guaranteed to match a particular value. For example, this value could
* be derived from data parsed for a cloud api or the OVF CIM OSType enum value;
*
* @return operating system architecture or null if it couldn't be
* determined.
* @return operating system architecture or null if it couldn't be determined.
*/
@Nullable
public String getArch() {
@ -108,14 +158,12 @@ public class OperatingSystem {
/**
* version of the operating system; ex. {@code 10.0.4}
* <p/>
* generally, this is used to compare versions of the same operating system
* name. It should be meaningful when sorted against, although this isn't
* necessary.
* generally, this is used to compare versions of the same operating system name. It should be
* meaningful when sorted against, although this isn't necessary.
* <h2>note</h2>
* While this looks similar to, and may in some cases be the same as the java
* system property {@code os.version} it isn't guaranteed to match a
* particular value. For example, this value could be derived from data
* parsed for a cloud api or the OVF CIM OSType enum value;
* While this looks similar to, and may in some cases be the same as the java system property
* {@code os.version} it isn't guaranteed to match a particular value. For example, this value
* could be derived from data parsed for a cloud api or the OVF CIM OSType enum value;
*
* @return operating system version or null if it couldn't be determined.
*/
@ -125,12 +173,11 @@ public class OperatingSystem {
}
/**
* description of the operating system; ex. {@code CentOS 32-bit},{@code
* Other Linux (32-bit)}
* description of the operating system; ex. {@code CentOS 32-bit},{@code Other Linux (32-bit)}
* <p/>
* This is the only required field in the operating system object. In some
* implementations, it is this data that is used to parse the value of the
* {@link #name}, {@link #version}, and {@link #arch} fields.
* This is the only required field in the operating system object. In some implementations, it is
* this data that is used to parse the value of the {@link #name}, {@link #version}, and
* {@link #arch} fields.
*
* @return operating system description
*/
@ -198,6 +245,10 @@ public class OperatingSystem {
return true;
}
public Builder toBuilder() {
return builder().fromOperatingSystem(this);
}
@Override
public String toString() {
return "[name=" + name + ", family=" + family + ", version=" + version + ", arch=" + arch + ", is64Bit="

View File

@ -19,62 +19,13 @@
package org.jclouds.compute.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import javax.annotation.Nullable;
/**
*
* @author Adrian Cole
* @see OperatingSystem.Builder
*/
public class OperatingSystemBuilder {
@Nullable
private OsFamily family;
@Nullable
private String name;
@Nullable
private String arch;
@Nullable
private String version;
private String description;
private boolean is64Bit;
@Deprecated
public class OperatingSystemBuilder extends OperatingSystem.Builder {
public OperatingSystemBuilder family(@Nullable OsFamily family) {
this.family = family;
return this;
}
public OperatingSystemBuilder name(@Nullable String name) {
this.name = name;
return this;
}
public OperatingSystemBuilder arch(@Nullable String arch) {
this.arch = arch;
return this;
}
public OperatingSystemBuilder version(@Nullable String version) {
this.version = version;
return this;
}
public OperatingSystemBuilder description(String description) {
this.description = checkNotNull(description, "description");
return this;
}
public OperatingSystemBuilder is64Bit(boolean is64Bit) {
this.is64Bit = is64Bit;
return this;
}
public OperatingSystem build() {
return new OperatingSystem(family, name, version, arch, description, is64Bit);
}
public static OperatingSystem fromOperatingSystem(OperatingSystem in) {
return new OperatingSystem(in.getFamily(), in.getName(), in.getVersion(), in.getArch(), in.getDescription(),
in.is64Bit());
}
}

View File

@ -21,14 +21,59 @@ package org.jclouds.ovf;
import javax.annotation.Nullable;
import org.jclouds.cim.OSType;
/**
* An OperatingSystemSection specifies the operating system installed on a virtual machine.
*
* @author Adrian Cole
*/
public class OperatingSystemSection {
@Nullable
protected final Integer id;
@Nullable
protected final String info;
public static Builder builder() {
return new Builder();
}
@Nullable
public static class Builder {
protected Integer id;
protected String info;
protected String description;
/**
* @see OperatingSystemSection#getID
*/
public Builder id(Integer id) {
this.id = id;
return this;
}
/**
* @see OperatingSystemSection#getInfo
*/
public Builder info(String info) {
this.info = info;
return this;
}
/**
* @see OperatingSystemSection#getDescription
*/
public Builder description(String description) {
this.description = description;
return this;
}
public OperatingSystemSection build() {
return new OperatingSystemSection(id, info, description);
}
public Builder fromOperatingSystemSection(OperatingSystemSection in) {
return id(in.getId()).info(in.getInfo()).description(in.getDescription());
}
}
protected final Integer id;
protected final String info;
protected final String description;
public OperatingSystemSection(@Nullable Integer id, @Nullable String info, @Nullable String description) {
@ -40,6 +85,7 @@ public class OperatingSystemSection {
/**
*
* @return ovf id
* @see OSType#getCode()
*/
public Integer getId() {
return id;
@ -98,6 +144,10 @@ public class OperatingSystemSection {
return true;
}
public Builder toBuilder() {
return builder().fromOperatingSystemSection(this);
}
@Override
public String toString() {
return "[id=" + getId() + ", info=" + getInfo() + ", description=" + getDescription() + "]";

View File

@ -23,10 +23,10 @@ import static org.jclouds.compute.predicates.OperatingSystemPredicates.supportsA
import static org.jclouds.compute.predicates.OperatingSystemPredicates.supportsYum;
import static org.jclouds.compute.predicates.OperatingSystemPredicates.supportsZypper;
import org.jclouds.cim.OSType;
import org.jclouds.compute.domain.CIMOperatingSystem;
import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.domain.CIMOperatingSystem.OSType;
import org.testng.annotations.Test;
/**

View File

@ -24,13 +24,16 @@ package org.jclouds.rest.internal;
*
* @author Adrian Cole
*/
import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.NoSuchElementException;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ExecutionException;
import javax.annotation.Resource;
import javax.inject.Named;
import javax.inject.Qualifier;
import javax.inject.Singleton;
import org.jclouds.Constants;
@ -46,6 +49,9 @@ import org.jclouds.rest.annotations.Delegate;
import org.jclouds.util.Throwables2;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.inject.Inject;
@ -83,6 +89,15 @@ public class AsyncRestClientProxy<T> implements InvocationHandler {
this.delegateMap = delegateMap;
}
private static final Predicate<Annotation> isQualifierPresent = new Predicate<Annotation>() {
@Override
public boolean apply(Annotation input) {
return input.annotationType().isAnnotationPresent(Qualifier.class);
}
};
public Object invoke(Object o, Method method, Object[] args) throws Throwable {
if (method.getName().equals("equals")) {
return this.equals(o);
@ -91,7 +106,12 @@ public class AsyncRestClientProxy<T> implements InvocationHandler {
} else if (method.getName().equals("hashCode")) {
return this.hashCode();
} else if (method.isAnnotationPresent(Provides.class)) {
try {
Annotation qualifier = Iterables.find(ImmutableList.copyOf(method.getAnnotations()), isQualifierPresent);
return injector.getInstance(Key.get(method.getGenericReturnType(), qualifier));
} catch (NoSuchElementException e) {
return injector.getInstance(Key.get(method.getGenericReturnType()));
}
} else if (method.isAnnotationPresent(Delegate.class)) {
return delegateMap.get(new ClassMethodArgs(method.getReturnType(), method, args));
} else if (annotationProcessor.getDelegateOrNull(method) != null

View File

@ -159,6 +159,7 @@ import com.google.inject.Key;
import com.google.inject.Module;
import com.google.inject.Provides;
import com.google.inject.TypeLiteral;
import com.google.inject.name.Names;
import com.sun.jersey.api.uri.UriBuilderImpl;
/**
@ -2174,6 +2175,10 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
@Provides
Set<String> set();
@Named("bar")
@Provides
Set<String> foo();
@POST
@Path("/")
void oneForm(@PathParam("bucket") String path);
@ -2185,6 +2190,13 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
assertEquals(set, ImmutableSet.of("foo"));
}
@Test
public void testProvidesWithGenericQualified() throws SecurityException, NoSuchMethodException,
UnsupportedEncodingException {
Set<String> set = injector.getInstance(AsyncClientFactory.class).create(TestClassForm.class).foo();
assertEquals(set, ImmutableSet.of("bar"));
}
@Test
public void testBuildOneClassForm() throws SecurityException, NoSuchMethodException, UnsupportedEncodingException {
Method oneForm = TestClassForm.class.getMethod("oneForm", String.class);
@ -2234,6 +2246,8 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
protected void configure() {
bind(new TypeLiteral<Set<String>>() {
}).toInstance(ImmutableSet.of("foo"));
bind(new TypeLiteral<Set<String>>() {
}).annotatedWith(Names.named("bar")).toInstance(ImmutableSet.of("bar"));
bind(URI.class).annotatedWith(Localhost2.class).toInstance(
URI.create("http://localhost:1111"));
}

View File

@ -19,8 +19,15 @@
package org.jclouds.savvis.vpdc;
import java.util.Set;
import org.jclouds.compute.domain.CIMOperatingSystem;
import org.jclouds.rest.annotations.Delegate;
import org.jclouds.savvis.vpdc.domain.Resource;
import org.jclouds.savvis.vpdc.features.BrowsingAsyncClient;
import org.jclouds.savvis.vpdc.internal.Org;
import com.google.inject.Provides;
/**
* Provides asynchronous access to VPDC via their REST API.
@ -38,4 +45,21 @@ public interface VPDCAsyncClient {
@Delegate
BrowsingAsyncClient getBrowsingClient();
/**
*
* @return a listing of all orgs that the current user has access to.
*/
@Provides
@Org
Set<Resource> listOrgs();
/**
* predefined by default in the classpath resource {@code
* /savvis-symphonyvpdc/predefined_operatingsystems.json}
*
* @return the operating systems that are predefined in the provider
* @see <a href="https://api.sandbox.symphonyvpdc.savvis.net/doc/spec/api/addSingleVM.html" />
*/
@Provides
Set<CIMOperatingSystem> listPredefinedOperatingSystems();
}

View File

@ -19,10 +19,13 @@
package org.jclouds.savvis.vpdc;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.jclouds.compute.domain.CIMOperatingSystem;
import org.jclouds.concurrent.Timeout;
import org.jclouds.rest.annotations.Delegate;
import org.jclouds.savvis.vpdc.domain.Resource;
import org.jclouds.savvis.vpdc.features.BrowsingClient;
/**
@ -42,4 +45,18 @@ public interface VPDCClient {
@Delegate
BrowsingClient getBrowsingClient();
/**
*
* @return a listing of all orgs that the current user has access to.
*/
Set<Resource> listOrgs();
/**
* predefined by default in the classpath resource {@code
* /savvis-symphonyvpdc/predefined_operatingsystems.json}
*
* @return the operating systems that are predefined in the provider
* @see <a href="https://api.sandbox.symphonyvpdc.savvis.net/doc/spec/api/addSingleVM.html" />
*/
Set<CIMOperatingSystem> listPredefinedOperatingSystems();
}

View File

@ -26,17 +26,22 @@ import static org.jclouds.Constants.PROPERTY_IDENTITY;
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
import static org.jclouds.savvis.vpdc.reference.VCloudConstants.PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED;
import java.io.IOException;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.compute.domain.CIMOperatingSystem;
import org.jclouds.http.HttpErrorHandler;
import org.jclouds.http.annotation.ClientError;
import org.jclouds.http.annotation.Redirection;
import org.jclouds.http.annotation.ServerError;
import org.jclouds.json.Json;
import org.jclouds.location.Provider;
import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.rest.AsyncClientFactory;
import org.jclouds.rest.AuthorizationException;
@ -52,6 +57,7 @@ import org.jclouds.savvis.vpdc.handlers.VPDCErrorHandler;
import org.jclouds.savvis.vpdc.internal.LoginAsyncClient;
import org.jclouds.savvis.vpdc.internal.VCloudToken;
import org.jclouds.savvis.vpdc.predicates.TaskSuccess;
import org.jclouds.util.Strings2;
import com.google.common.base.Predicate;
import com.google.common.base.Supplier;
@ -59,6 +65,7 @@ import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import com.google.inject.Injector;
import com.google.inject.Provides;
import com.google.inject.TypeLiteral;
/**
*
@ -81,7 +88,7 @@ public class VPDCRestClientModule extends RestClientModule<VPDCClient, VPDCAsync
@Provides
@org.jclouds.savvis.vpdc.internal.Org
@Singleton
protected Iterable<org.jclouds.savvis.vpdc.domain.Resource> provideOrgs(Supplier<VCloudSession> cache,
protected Set<org.jclouds.savvis.vpdc.domain.Resource> provideOrgs(Supplier<VCloudSession> cache,
@Named(PROPERTY_IDENTITY) String user) {
VCloudSession discovery = cache.get();
checkState(discovery.getOrgs().size() > 0, "No orgs present for user: " + user);
@ -91,7 +98,7 @@ public class VPDCRestClientModule extends RestClientModule<VPDCClient, VPDCAsync
@Provides
@org.jclouds.savvis.vpdc.internal.Org
@Singleton
protected String provideDefaultOrgId(@org.jclouds.savvis.vpdc.internal.Org Iterable<Resource> orgs) {
protected String provideDefaultOrgId(@org.jclouds.savvis.vpdc.internal.Org Set<Resource> orgs) {
return Iterables.get(orgs, 0).getId();
}
@ -112,6 +119,15 @@ public class VPDCRestClientModule extends RestClientModule<VPDCClient, VPDCAsync
super(VPDCClient.class, VPDCAsyncClient.class, DELEGATE_MAP);
}
@Singleton
@Provides
protected Set<CIMOperatingSystem> provideOperatingSystems(Json json, @Provider String providerName)
throws IOException {
return json.fromJson(Strings2.toStringAndClose(getClass().getResourceAsStream(
"/" + providerName + "/predefined_operatingsystems.json")), new TypeLiteral<Set<CIMOperatingSystem>>() {
}.getType());
}
@Provides
@Singleton
protected Supplier<VCloudSession> provideVCloudTokenCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds,

View File

@ -0,0 +1,209 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <name@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.savvis.vpdc.domain;
import org.jclouds.cim.OSType;
import org.jclouds.compute.domain.OsFamily;
/**
* Savvis Operating System Specification
*
* @see <a href="https://api.sandbox.symphonyvpdc.savvis.net/doc/spec/api/addSingleVM.html" />
* @author Adrian Cole
*/
public class SavvisOperatingSystemSpecification {
public static Builder builder() {
return new Builder();
}
public static class Builder {
private int savvisId;
private int typeId;
private String name;
private OsFamily family;
private String description;
private boolean supportedBySavvis;
/**
* @see SavvisOperatingSystemSpecification#getSavvisId
*/
public Builder savvisId(int savvisId) {
this.savvisId = savvisId;
return this;
}
/**
* @see SavvisOperatingSystemSpecification#getTypeId
*/
public Builder typeId(int typeId) {
this.typeId = typeId;
return this;
}
/**
* @see SavvisOperatingSystemSpecification#getOsFamily
*/
public Builder family(OsFamily family) {
this.family = family;
return this;
}
/**
* @see SavvisOperatingSystemSpecification#getInfo
*/
public Builder name(String name) {
this.name = name;
return this;
}
/**
* @see SavvisOperatingSystemSpecification#getDescription
*/
public Builder description(String description) {
this.description = description;
return this;
}
/**
* @see SavvisOperatingSystemSpecification#isSupportedBySavvis
*/
public Builder supportedBySavvis(boolean supportedBySavvis) {
this.supportedBySavvis = supportedBySavvis;
return this;
}
public SavvisOperatingSystemSpecification build() {
return new SavvisOperatingSystemSpecification(savvisId, typeId, family, name, description, supportedBySavvis);
}
public Builder fromSavvisOperatingSystemSpecification(SavvisOperatingSystemSpecification in) {
return savvisId(in.getSavvisId()).typeId(in.getTypeId()).family(in.getFamily()).name(in.getName())
.description(in.getDescription()).supportedBySavvis(in.isSupportedBySavvis());
}
}
private final int savvisId;
private final int typeId;
private final OsFamily family;
private final String name;
private final String description;
private final boolean supportedBySavvis;
public SavvisOperatingSystemSpecification(int savvisId, int typeId, OsFamily family, String name,
String description, boolean supportedBySavvis) {
this.savvisId = savvisId;
this.typeId = typeId;
this.family = family;
this.name = name;
this.description = description;
this.supportedBySavvis = supportedBySavvis;
}
/**
* @return Internal name used by Savvis
*/
public int getSavvisId() {
return savvisId;
}
/**
*
* @return CIM OS Type Id
* @see OSType#getCode()
*/
public int getTypeId() {
return typeId;
}
/**
*
* @return the name of the OS
*/
public String getName() {
return name;
}
/**
*
* @return the operating system family
*/
public OsFamily getFamily() {
return family;
}
/**
*
* @return description
*/
public String getDescription() {
return description;
}
/**
*
* @return whether or not this operating system is supported by Savvis
*/
public boolean isSupportedBySavvis() {
return supportedBySavvis;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + typeId;
result = prime * result + savvisId;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
SavvisOperatingSystemSpecification other = (SavvisOperatingSystemSpecification) obj;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
if (typeId != other.typeId)
return false;
if (savvisId != other.savvisId)
return false;
return true;
}
public Builder toBuilder() {
return builder().fromSavvisOperatingSystemSpecification(this);
}
@Override
public String toString() {
return String.format("[description=%s, family=%s, name=%s, typeId=%s, savvisId=%s, supportedBySavvis=%s]",
description, family, name, typeId, savvisId, supportedBySavvis);
}
}

View File

@ -59,6 +59,7 @@ public class VPDCErrorHandler implements HttpErrorHandler {
exception = new IllegalArgumentException(message, exception);
break;
case 401:
case 403:
exception = new AuthorizationException(message, exception);
break;
case 404:

View File

@ -0,0 +1,26 @@
[
{
"family": "WINDOWS",
"name": "winLonghorn64Guest",
"version": "2008",
"description": "Microsoft Windows Server 2008 (Enterprise 64bit)",
"is64Bit": true;
"osType": "WINDOWS_SERVER_2008_64"
},
{
"family": "RHEL",
"name": "rhel5Guest",
"version": "5",
"description": "Red Hat Enterprise Linux 5.x 32bit",
"is64Bit": false;
"osType": "RHEL"
},
{
"family": "RHEL_64",
"name": "rhel5_64Guest",
"version": "5",
"description": "Red Hat Enterprise Linux 5.x 64bit",
"is64Bit": true;
"osType": "RHEL_64"
}
]

View File

@ -19,8 +19,9 @@
package org.jclouds.savvis.vpdc;
import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import org.jclouds.http.HttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor;
@ -42,12 +43,18 @@ public class VPDCAsyncClientTest extends BaseVPDCAsyncClientTest<VPDCAsyncClient
private VPDCAsyncClient asyncClient;
private VPDCClient syncClient;
public void testSync() throws SecurityException, NoSuchMethodException, InterruptedException, ExecutionException {
public void testSync() {
assert syncClient.getBrowsingClient() != null;
assertEquals(syncClient.listOrgs().size(), 1);
assertEquals(syncClient.listPredefinedOperatingSystems().size(), 3);
}
public void testAsync() throws SecurityException, NoSuchMethodException, InterruptedException, ExecutionException {
public void testAsync() {
assert asyncClient.getBrowsingClient() != null;
assertEquals(asyncClient.listOrgs().size(), 1);
assertEquals(asyncClient.listPredefinedOperatingSystems().size(), 3);
}
@Override

View File

@ -19,6 +19,7 @@
package org.jclouds.savvis.vpdc.features;
import static org.jclouds.savvis.vpdc.options.GetVAppOptions.Builder.withPowerState;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
@ -27,7 +28,6 @@ import org.jclouds.savvis.vpdc.domain.Org;
import org.jclouds.savvis.vpdc.domain.Resource;
import org.jclouds.savvis.vpdc.domain.VApp;
import org.jclouds.savvis.vpdc.domain.VDC;
import static org.jclouds.savvis.vpdc.options.GetVAppOptions.Builder.withPowerState;
import org.jclouds.savvis.vpdc.reference.VCloudMediaType;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
@ -49,7 +49,9 @@ public class BrowsingClientLiveTest extends BaseVPDCClientLiveTest {
@Test
public void testOrg() throws Exception {
Org response = client.getOrg(null);
for (Resource org : context.getApi().listOrgs()) {
Org response = client.getOrg(org.getId());
assertNotNull(response);
assertNotNull(response.getId());
assertNotNull(response.getHref());
@ -61,12 +63,14 @@ public class BrowsingClientLiveTest extends BaseVPDCClientLiveTest {
assert response.getVDCs().size() >= 1;
assertEquals(client.getOrg(response.getId()).toString(), response.toString());
}
}
@Test
public void testVDC() throws Exception {
Org org = client.getOrg(null);
for (Resource org1 : context.getApi().listOrgs()) {
Org org = client.getOrg(org1.getId());
for (Resource vdc : org.getVDCs()) {
VDC response = client.getVDCInOrg(null, vdc.getId());
VDC response = client.getVDCInOrg(org.getId(), vdc.getId());
assertNotNull(response);
assertNotNull(response.getId());
assertNotNull(response.getHref());
@ -76,15 +80,17 @@ public class BrowsingClientLiveTest extends BaseVPDCClientLiveTest {
assertNotNull(response.getDescription());
assertNotNull(response.getResourceEntities());
assertNotNull(response.getAvailableNetworks());
assertEquals(client.getVDCInOrg(null, response.getId()).toString(), response.toString());
assertEquals(client.getVDCInOrg(org.getId(), response.getId()).toString(), response.toString());
}
}
}
@Test
public void testNetwork() throws Exception {
Org org = client.getOrg(null);
for (Resource org1 : context.getApi().listOrgs()) {
Org org = client.getOrg(org1.getId());
for (Resource vdc : org.getVDCs()) {
VDC VDC = client.getVDCInOrg(null, vdc.getId());
VDC VDC = client.getVDCInOrg(org.getId(), vdc.getId());
for (Resource vApp : VDC.getAvailableNetworks()) {
Network response = client.getNetworkInOrgAndVDC(org.getId(), vdc.getId(), vApp.getId());
assertNotNull(response);
@ -95,17 +101,19 @@ public class BrowsingClientLiveTest extends BaseVPDCClientLiveTest {
assertNotNull(response.getNetmask());
assertNotNull(response.getGateway());
assertNotNull(response.getInternalToExternalNATRules());
assertEquals(client.getNetworkInOrgAndVDC(null, vdc.getId(), response.getId()).toString(), response
.toString());
assertEquals(client.getNetworkInOrgAndVDC(org.getId(), vdc.getId(), response.getId()).toString(),
response.toString());
}
}
}
}
@Test
public void testVApp() throws Exception {
Org org = client.getOrg(null);
for (Resource org1 : context.getApi().listOrgs()) {
Org org = client.getOrg(org1.getId());
for (Resource vdc : org.getVDCs()) {
VDC VDC = client.getVDCInOrg(null, vdc.getId());
VDC VDC = client.getVDCInOrg(org.getId(), vdc.getId());
for (Resource vApp : Iterables.filter(VDC.getResourceEntities(), new Predicate<Resource>() {
@Override
@ -127,8 +135,11 @@ public class BrowsingClientLiveTest extends BaseVPDCClientLiveTest {
assertNotNull(response.getNetworkSection());
assertNotNull(response.getResourceAllocations());
// power state is the only thing that should change
assertEquals(client.getVAppInOrgAndVDC(null, vdc.getId(), response.getId(), withPowerState()).toString()
.replaceFirst("status=[A-Z]+", ""), response.toString().replaceFirst("status=[A-Z]+", ""));
assertEquals(client.getVAppInOrgAndVDC(org.getId(), vdc.getId(), response.getId(), withPowerState())
.toString().replaceFirst("status=[A-Z]+", ""), response.toString().replaceFirst(
"status=[A-Z]+", ""));
}
}
}
}

View File

@ -58,6 +58,17 @@ public class VPDCErrorHandlerTest {
AuthorizationException.class);
}
@Test
public void test403MakesAuthorizationException() {
assertCodeMakes(
"GET",
URI.create("https://savvis.com/foo"),
403,
"HTTP/1.1 403 Forbidden",
"With the User/login credentials provided, no privilege exists to process the current request. Please contact Savvis administrator for further information",
AuthorizationException.class);
}
@Test
public void test404MakesResourceNotFoundException() {
assertCodeMakes("GET", URI.create("https://savvis.com/foo"), 404, "", "Not Found",