mirror of https://github.com/apache/jclouds.git
Merge pull request #189 from jsonking/695-1
Issue 695: Remainder of VirtualMachineConfigurationOptions and HardwareConfiguration
This commit is contained in:
commit
f3efe7fafe
|
@ -0,0 +1,134 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.tmrk.enterprisecloud.domain;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
|
||||
/**
|
||||
* <xs:complexType name="ConfigurationOptionRange">
|
||||
* @author Jason King
|
||||
*/
|
||||
public class ConfigurationOptionRange {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public Builder toBuilder() {
|
||||
return new Builder().fromConfigurationOptionRange(this);
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
private int minimum;
|
||||
private int maximum;
|
||||
private int stepFactor;
|
||||
|
||||
/**
|
||||
* @see org.jclouds.tmrk.enterprisecloud.domain.ConfigurationOptionRange#getMinimum
|
||||
*/
|
||||
public Builder minimum(int minimum) {
|
||||
this.minimum = minimum;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.jclouds.tmrk.enterprisecloud.domain.ConfigurationOptionRange#getMaximum
|
||||
*/
|
||||
public Builder maximum(int maximum) {
|
||||
this.maximum = maximum;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.jclouds.tmrk.enterprisecloud.domain.ConfigurationOptionRange#getStepFactor
|
||||
*/
|
||||
public Builder stepFactor(int stepFactor) {
|
||||
this.stepFactor = stepFactor;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ConfigurationOptionRange build() {
|
||||
return new ConfigurationOptionRange(minimum, maximum,stepFactor);
|
||||
}
|
||||
|
||||
public Builder fromConfigurationOptionRange(ConfigurationOptionRange in) {
|
||||
return minimum(in.getMinimum()).maximum(in.getMaximum()).stepFactor(in.getStepFactor());
|
||||
}
|
||||
}
|
||||
|
||||
@XmlElement(name = "Minimum")
|
||||
private int minimum;
|
||||
|
||||
@XmlElement(name = "Maximum")
|
||||
private int maximum;
|
||||
|
||||
@XmlElement(name = "StepFactor")
|
||||
private int stepFactor;
|
||||
|
||||
private ConfigurationOptionRange(int minimum, int maximum, int stepFactor) {
|
||||
this.minimum = minimum;
|
||||
this.maximum = maximum;
|
||||
this.stepFactor = stepFactor;
|
||||
}
|
||||
|
||||
private ConfigurationOptionRange() {
|
||||
//For JAXB
|
||||
}
|
||||
|
||||
public int getMinimum() {
|
||||
return minimum;
|
||||
}
|
||||
|
||||
public int getMaximum() {
|
||||
return maximum;
|
||||
}
|
||||
|
||||
public int getStepFactor() {
|
||||
return stepFactor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
ConfigurationOptionRange that = (ConfigurationOptionRange) o;
|
||||
|
||||
if (maximum != that.maximum) return false;
|
||||
if (minimum != that.minimum) return false;
|
||||
if (stepFactor != that.stepFactor) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = minimum;
|
||||
result = 31 * result + maximum;
|
||||
result = 31 * result + stepFactor;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[minimum="+ minimum +", maximum="+ maximum +", stepFactor="+stepFactor+"]";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,167 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.tmrk.enterprisecloud.domain;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlEnum;
|
||||
import javax.xml.bind.annotation.XmlEnumValue;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* <xs:complexType name="CustomizationOption">
|
||||
* @author Jason King
|
||||
*/
|
||||
public class CustomizationOption {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public Builder toBuilder() {
|
||||
return new Builder().fromConfigurationOptionRange(this);
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
private CustomizationType type;
|
||||
private boolean canPowerOn;
|
||||
private boolean passwordRequired;
|
||||
private boolean sshKeyRequired;
|
||||
|
||||
/**
|
||||
* @see CustomizationOption#getType
|
||||
*/
|
||||
public Builder type(CustomizationType type) {
|
||||
this.type = type;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CustomizationOption#canPowerOn
|
||||
*/
|
||||
public Builder canPowerOn(boolean canPowerOn) {
|
||||
this.canPowerOn = canPowerOn;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CustomizationOption#isPasswordRequired()
|
||||
*/
|
||||
public Builder passwordRequired(boolean passwordRequired) {
|
||||
this.passwordRequired = passwordRequired;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CustomizationOption#isSshKeyRequired()
|
||||
*/
|
||||
public Builder sshKeyRequired(boolean sshKeyRequired) {
|
||||
this.sshKeyRequired = sshKeyRequired;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CustomizationOption build() {
|
||||
return new CustomizationOption(type, canPowerOn, passwordRequired,sshKeyRequired);
|
||||
}
|
||||
|
||||
public Builder fromConfigurationOptionRange(CustomizationOption in) {
|
||||
return type(in.getType()).canPowerOn(in.canPowerOn()).passwordRequired(in.isPasswordRequired()).sshKeyRequired(in.isSshKeyRequired());
|
||||
}
|
||||
}
|
||||
|
||||
@XmlElement(name = "Type")
|
||||
private CustomizationType type;
|
||||
|
||||
@XmlElement(name = "CanPowerOn")
|
||||
private boolean canPowerOn;
|
||||
|
||||
@XmlElement(name = "PasswordRequired")
|
||||
private boolean passwordRequired;
|
||||
|
||||
@XmlElement(name = "SshKeyRequired")
|
||||
private boolean sshKeyRequired;
|
||||
|
||||
private CustomizationOption(CustomizationType type, boolean canPowerOn, boolean passwordRequired, boolean sshKeyRequired) {
|
||||
this.type = checkNotNull(type,"type");
|
||||
this.canPowerOn = canPowerOn;
|
||||
this.passwordRequired = passwordRequired;
|
||||
this.sshKeyRequired = sshKeyRequired;
|
||||
}
|
||||
|
||||
private CustomizationOption() {
|
||||
//For JAXB
|
||||
}
|
||||
|
||||
public CustomizationType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public boolean canPowerOn() {
|
||||
return canPowerOn;
|
||||
}
|
||||
|
||||
public boolean isPasswordRequired() {
|
||||
return passwordRequired;
|
||||
}
|
||||
|
||||
public boolean isSshKeyRequired() {
|
||||
return sshKeyRequired;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
CustomizationOption that = (CustomizationOption) o;
|
||||
|
||||
if (canPowerOn != that.canPowerOn) return false;
|
||||
if (passwordRequired != that.passwordRequired) return false;
|
||||
if (sshKeyRequired != that.sshKeyRequired) return false;
|
||||
if (type != that.type) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = type.hashCode();
|
||||
result = 31 * result + (canPowerOn ? 1 : 0);
|
||||
result = 31 * result + (passwordRequired ? 1 : 0);
|
||||
result = 31 * result + (sshKeyRequired ? 1 : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[type="+type+", canPowerOn="+ canPowerOn +", passwordRequired="+ passwordRequired +", sshKeyRequired="+sshKeyRequired+"]";
|
||||
}
|
||||
|
||||
@XmlEnum
|
||||
public enum CustomizationType {
|
||||
@XmlEnumValue("Linux")
|
||||
LINUX,
|
||||
|
||||
@XmlEnumValue("Windows")
|
||||
WINDOWS;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,156 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.tmrk.enterprisecloud.domain.hardware;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
|
||||
/**
|
||||
* <xs:complexType name="DiskConfigurationOption">
|
||||
* @author Jason King
|
||||
*/
|
||||
public class DiskConfigurationOption {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public Builder toBuilder() {
|
||||
return new Builder().fromConfigurationOptionRange(this);
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
private int minimum;
|
||||
private int maximum;
|
||||
private DiskConfigurationOptionRange systemDisk;
|
||||
private DiskConfigurationOptionRange dataDisk;
|
||||
|
||||
/**
|
||||
* @see DiskConfigurationOption#getMinimum()
|
||||
*/
|
||||
public Builder minimum(int minimum) {
|
||||
this.minimum = minimum;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DiskConfigurationOption#getMaximum()
|
||||
*/
|
||||
public Builder maximum(int maximum) {
|
||||
this.maximum = maximum;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DiskConfigurationOption#getSystemDisk()
|
||||
*/
|
||||
public Builder systemDisk(DiskConfigurationOptionRange systemDisk) {
|
||||
this.systemDisk = systemDisk;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DiskConfigurationOption#getDataDisk()
|
||||
*/
|
||||
public Builder dataDisk(DiskConfigurationOptionRange dataDisk) {
|
||||
this.dataDisk = dataDisk;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DiskConfigurationOption build() {
|
||||
return new DiskConfigurationOption(minimum, maximum, systemDisk, dataDisk);
|
||||
}
|
||||
|
||||
public Builder fromConfigurationOptionRange(DiskConfigurationOption in) {
|
||||
return minimum(in.getMinimum()).maximum(in.getMaximum()).systemDisk(in.getSystemDisk()).dataDisk(in.getDataDisk());
|
||||
}
|
||||
}
|
||||
|
||||
@XmlElement(name = "Minimum")
|
||||
private int minimum;
|
||||
|
||||
@XmlElement(name = "Maximum")
|
||||
private int maximum;
|
||||
|
||||
@XmlElement(name = "SystemDisk")
|
||||
private DiskConfigurationOptionRange systemDisk;
|
||||
|
||||
@XmlElement(name = "DataDisk")
|
||||
private DiskConfigurationOptionRange dataDisk;
|
||||
|
||||
private DiskConfigurationOption(int minimum, int maximum, DiskConfigurationOptionRange systemDisk, DiskConfigurationOptionRange dataDisk) {
|
||||
this.minimum = minimum;
|
||||
this.maximum = maximum;
|
||||
this.systemDisk = systemDisk;
|
||||
this.dataDisk = dataDisk;
|
||||
}
|
||||
|
||||
private DiskConfigurationOption() {
|
||||
//For JAXB
|
||||
}
|
||||
|
||||
public int getMinimum() {
|
||||
return minimum;
|
||||
}
|
||||
|
||||
public int getMaximum() {
|
||||
return maximum;
|
||||
}
|
||||
|
||||
public DiskConfigurationOptionRange getSystemDisk() {
|
||||
return systemDisk;
|
||||
}
|
||||
|
||||
public DiskConfigurationOptionRange getDataDisk() {
|
||||
return dataDisk;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
DiskConfigurationOption that = (DiskConfigurationOption) o;
|
||||
|
||||
if (maximum != that.maximum) return false;
|
||||
if (minimum != that.minimum) return false;
|
||||
if (dataDisk != null ? !dataDisk.equals(that.dataDisk) : that.dataDisk != null)
|
||||
return false;
|
||||
if (systemDisk != null ? !systemDisk.equals(that.systemDisk) : that.systemDisk != null)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = minimum;
|
||||
result = 31 * result + maximum;
|
||||
result = 31 * result + (systemDisk != null ? systemDisk.hashCode() : 0);
|
||||
result = 31 * result + (dataDisk != null ? dataDisk.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[minimum="+minimum+", maximum="+ maximum +", systemDisk="+ systemDisk +", dataDisk="+dataDisk+"]";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,122 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.tmrk.enterprisecloud.domain.hardware;
|
||||
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.ResourceCapacityRange;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
|
||||
/**
|
||||
* <xs:complexType name="DiskConfigurationOptionRange">
|
||||
* @author Jason King
|
||||
*/
|
||||
public class DiskConfigurationOptionRange {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public Builder toBuilder() {
|
||||
return new Builder().fromConfigurationOptionRange(this);
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
private ResourceCapacityRange resourceCapacityRange;
|
||||
private double monthlyCost;
|
||||
|
||||
/**
|
||||
* @see DiskConfigurationOptionRange#getResourceCapacityRange
|
||||
*/
|
||||
public Builder resourceCapacityRange(ResourceCapacityRange resourceCapacityRange) {
|
||||
this.resourceCapacityRange = resourceCapacityRange;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DiskConfigurationOptionRange#getMonthlyCost()
|
||||
*/
|
||||
public Builder monthlyCost(double monthlyCost) {
|
||||
this.monthlyCost = monthlyCost;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public DiskConfigurationOptionRange build() {
|
||||
return new DiskConfigurationOptionRange(resourceCapacityRange, monthlyCost);
|
||||
}
|
||||
|
||||
public Builder fromConfigurationOptionRange(DiskConfigurationOptionRange in) {
|
||||
return resourceCapacityRange(in.getResourceCapacityRange()).monthlyCost(in.getMonthlyCost());
|
||||
}
|
||||
}
|
||||
|
||||
@XmlElement(name = "ResourceCapacityRange")
|
||||
private ResourceCapacityRange resourceCapacityRange;
|
||||
|
||||
@XmlElement(name = "MonthlyCost")
|
||||
private double monthlyCost;
|
||||
|
||||
private DiskConfigurationOptionRange(ResourceCapacityRange resourceCapacityRange, double monthlyCost) {
|
||||
this.resourceCapacityRange = resourceCapacityRange;
|
||||
this.monthlyCost = monthlyCost;
|
||||
}
|
||||
|
||||
private DiskConfigurationOptionRange() {
|
||||
//For JAXB
|
||||
}
|
||||
|
||||
public ResourceCapacityRange getResourceCapacityRange() {
|
||||
return resourceCapacityRange;
|
||||
}
|
||||
|
||||
public double getMonthlyCost() {
|
||||
return monthlyCost;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
DiskConfigurationOptionRange that = (DiskConfigurationOptionRange) o;
|
||||
|
||||
if (Double.compare(that.monthlyCost, monthlyCost) != 0) return false;
|
||||
if (resourceCapacityRange != null ? !resourceCapacityRange.equals(that.resourceCapacityRange) : that.resourceCapacityRange != null)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result;
|
||||
long temp;
|
||||
result = resourceCapacityRange != null ? resourceCapacityRange.hashCode() : 0;
|
||||
temp = monthlyCost != +0.0d ? Double.doubleToLongBits(monthlyCost) : 0L;
|
||||
result = 31 * result + (int) (temp ^ (temp >>> 32));
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[resourceCapacityRange="+resourceCapacityRange+", monthlyCost="+monthlyCost+"]";
|
||||
}
|
||||
}
|
|
@ -29,6 +29,7 @@ import org.jclouds.tmrk.enterprisecloud.domain.network.Nics;
|
|||
import org.jclouds.tmrk.enterprisecloud.domain.network.VirtualNic;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import java.net.URI;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
@ -40,6 +41,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
|||
* <xs:complexType name="HardwareConfiguration">
|
||||
* @author Jason King
|
||||
*/
|
||||
@XmlRootElement(name = "HardwareConfiguration")
|
||||
public class HardwareConfiguration extends BaseResource<HardwareConfiguration> {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
|
|
@ -19,7 +19,8 @@
|
|||
package org.jclouds.tmrk.enterprisecloud.domain.vm;
|
||||
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.ResourceCapacityRange;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.*;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.hardware.DiskConfigurationOption;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
|
@ -48,8 +49,21 @@ public class VirtualMachineConfigurationOptions extends BaseResource<VirtualMach
|
|||
}
|
||||
|
||||
public static class Builder extends BaseResource.Builder<VirtualMachineConfigurationOptions> {
|
||||
//TODO There are additional fields
|
||||
|
||||
protected ConfigurationOptionRange processor;
|
||||
protected ResourceCapacityRange memory;
|
||||
protected DiskConfigurationOption disk;
|
||||
protected ConfigurationOptionRange networkAdapter;
|
||||
protected CustomizationOption customization;
|
||||
//TODO ComputeMatrix field
|
||||
|
||||
/**
|
||||
* @see VirtualMachineConfigurationOptions#getProcessor
|
||||
*/
|
||||
public Builder processor(ConfigurationOptionRange processor) {
|
||||
this.processor = processor;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see VirtualMachineConfigurationOptions#getMemory
|
||||
|
@ -59,13 +73,41 @@ public class VirtualMachineConfigurationOptions extends BaseResource<VirtualMach
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see VirtualMachineConfigurationOptions#getDisk
|
||||
*/
|
||||
public Builder disk(DiskConfigurationOption disk) {
|
||||
this.disk = disk;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see VirtualMachineConfigurationOptions#getNetworkAdapter
|
||||
*/
|
||||
public Builder networkAdapter(ConfigurationOptionRange networkAdapter) {
|
||||
this.networkAdapter = networkAdapter;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see VirtualMachineConfigurationOptions#getCustomization
|
||||
*/
|
||||
public Builder customization(CustomizationOption customization) {
|
||||
this.customization = customization;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VirtualMachineConfigurationOptions build() {
|
||||
return new VirtualMachineConfigurationOptions(href, type, memory);
|
||||
return new VirtualMachineConfigurationOptions(href, type, processor, memory, disk, networkAdapter, customization);
|
||||
}
|
||||
|
||||
public Builder fromVirtualMachineConfigurationOptions(VirtualMachineConfigurationOptions in) {
|
||||
return fromResource(in).memory(in.getMemory());
|
||||
return fromResource(in).processor(in.getProcessor())
|
||||
.memory(in.getMemory())
|
||||
.disk(in.getDisk())
|
||||
.networkAdapter(in.getNetworkAdapter())
|
||||
.customization(in.getCustomization());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -94,12 +136,29 @@ public class VirtualMachineConfigurationOptions extends BaseResource<VirtualMach
|
|||
|
||||
}
|
||||
|
||||
@XmlElement(name = "Processor", required = false)
|
||||
private ConfigurationOptionRange processor;
|
||||
|
||||
@XmlElement(name = "Memory", required = false)
|
||||
private ResourceCapacityRange memory;
|
||||
|
||||
private VirtualMachineConfigurationOptions(URI href, String type, @Nullable ResourceCapacityRange memory) {
|
||||
@XmlElement(name = "Disk", required = false)
|
||||
private DiskConfigurationOption disk;
|
||||
|
||||
@XmlElement(name = "NetworkAdapter", required = false)
|
||||
private ConfigurationOptionRange networkAdapter;
|
||||
|
||||
@XmlElement(name = "Customization", required = false)
|
||||
private CustomizationOption customization;
|
||||
|
||||
private VirtualMachineConfigurationOptions(URI href, String type, @Nullable ConfigurationOptionRange processor, @Nullable ResourceCapacityRange memory,
|
||||
@Nullable DiskConfigurationOption disk, @Nullable ConfigurationOptionRange networkAdapter, @Nullable CustomizationOption customization) {
|
||||
super(href, type);
|
||||
this.processor = processor;
|
||||
this.memory = memory;
|
||||
this.disk = disk;
|
||||
this.networkAdapter = networkAdapter;
|
||||
this.customization = customization;
|
||||
}
|
||||
|
||||
private VirtualMachineConfigurationOptions() {
|
||||
|
@ -108,12 +167,44 @@ public class VirtualMachineConfigurationOptions extends BaseResource<VirtualMach
|
|||
|
||||
/**
|
||||
*
|
||||
* @return memory capacity range
|
||||
* @return processor configuration option range
|
||||
*/
|
||||
public ConfigurationOptionRange getProcessor() {
|
||||
return processor;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return memory capacity configuration range
|
||||
*/
|
||||
public ResourceCapacityRange getMemory() {
|
||||
return memory;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return disk configuration option
|
||||
*/
|
||||
public DiskConfigurationOption getDisk() {
|
||||
return disk;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return network adapter configuration range
|
||||
*/
|
||||
public ConfigurationOptionRange getNetworkAdapter() {
|
||||
return networkAdapter;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return customization option
|
||||
*/
|
||||
public CustomizationOption getCustomization() {
|
||||
return customization;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
@ -122,8 +213,16 @@ public class VirtualMachineConfigurationOptions extends BaseResource<VirtualMach
|
|||
|
||||
VirtualMachineConfigurationOptions that = (VirtualMachineConfigurationOptions) o;
|
||||
|
||||
if (customization != null ? !customization.equals(that.customization) : that.customization != null)
|
||||
return false;
|
||||
if (disk != null ? !disk.equals(that.disk) : that.disk != null)
|
||||
return false;
|
||||
if (memory != null ? !memory.equals(that.memory) : that.memory != null)
|
||||
return false;
|
||||
if (networkAdapter != null ? !networkAdapter.equals(that.networkAdapter) : that.networkAdapter != null)
|
||||
return false;
|
||||
if (processor != null ? !processor.equals(that.processor) : that.processor != null)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -131,12 +230,16 @@ public class VirtualMachineConfigurationOptions extends BaseResource<VirtualMach
|
|||
@Override
|
||||
public int hashCode() {
|
||||
int result = super.hashCode();
|
||||
result = 31 * result + (processor != null ? processor.hashCode() : 0);
|
||||
result = 31 * result + (memory != null ? memory.hashCode() : 0);
|
||||
result = 31 * result + (disk != null ? disk.hashCode() : 0);
|
||||
result = 31 * result + (networkAdapter != null ? networkAdapter.hashCode() : 0);
|
||||
result = 31 * result + (customization != null ? customization.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String string() {
|
||||
return super.string()+", memory="+memory;
|
||||
return super.string()+", memory="+memory+", disk="+disk+", processor="+processor+", networkAdapter="+networkAdapter+", customization="+customization;
|
||||
}
|
||||
}
|
|
@ -22,10 +22,12 @@ import com.google.common.util.concurrent.ListenableFuture;
|
|||
import org.jclouds.http.filters.BasicAuthentication;
|
||||
import org.jclouds.rest.annotations.*;
|
||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.hardware.HardwareConfiguration;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.network.AssignedIpAddresses;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachine;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachineConfigurationOptions;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachines;
|
||||
import org.jclouds.tmrk.enterprisecloud.functions.ReturnEmptyVirtualMachinesOnNotFoundOr404;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
|
@ -51,7 +53,7 @@ public interface VirtualMachineAsyncClient {
|
|||
@GET
|
||||
@Consumes("application/vnd.tmrk.cloud.virtualMachine; type=collection")
|
||||
@JAXBResponseParser
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
@ExceptionParser(ReturnEmptyVirtualMachinesOnNotFoundOr404.class)
|
||||
ListenableFuture<VirtualMachines> getVirtualMachines(@EndpointParam URI uri);
|
||||
|
||||
/**
|
||||
|
@ -73,11 +75,20 @@ public interface VirtualMachineAsyncClient {
|
|||
ListenableFuture<AssignedIpAddresses> getAssignedIpAddresses(@EndpointParam URI uri);
|
||||
|
||||
/**
|
||||
* @see VirtualMachineClient#getVirtualMachineConfigurationOptions
|
||||
* @see VirtualMachineClient#getConfigurationOptions
|
||||
*/
|
||||
@GET
|
||||
@Consumes("application/vnd.tmrk.cloud.virtualMachineConfigurationOptions")
|
||||
@JAXBResponseParser
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<VirtualMachineConfigurationOptions> getVirtualMachineConfigurationOptions(@EndpointParam URI uri);
|
||||
ListenableFuture<VirtualMachineConfigurationOptions> getConfigurationOptions(@EndpointParam URI uri);
|
||||
|
||||
/**
|
||||
* @see VirtualMachineClient#getHardwareConfiguration
|
||||
*/
|
||||
@GET
|
||||
@Consumes("application/vnd.tmrk.cloud.virtualMachineHardware")
|
||||
@JAXBResponseParser
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<HardwareConfiguration> getHardwareConfiguration(@EndpointParam URI uri);
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
package org.jclouds.tmrk.enterprisecloud.features;
|
||||
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.hardware.HardwareConfiguration;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.network.AssignedIpAddresses;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachine;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachineConfigurationOptions;
|
||||
|
@ -69,6 +70,14 @@ public interface VirtualMachineClient {
|
|||
* @param uri the uri for the configuration options. e.g. /cloudapi/ecloud/virtualmachines/{id}/configurationoptions
|
||||
* @return the configuration options
|
||||
*/
|
||||
VirtualMachineConfigurationOptions getVirtualMachineConfigurationOptions(URI uri);
|
||||
VirtualMachineConfigurationOptions getConfigurationOptions(URI uri);
|
||||
|
||||
/**
|
||||
* The Get Virtual Machines Hardware Configuration call returns information
|
||||
* regarding the hardware configuration of a specified virtual machine in a compute pool.
|
||||
* @param uri the uri for the hardware configuration e.g. /cloudapi/ecloud/virtualmachines/{id}/hardwareconfiguration
|
||||
* @return
|
||||
*/
|
||||
HardwareConfiguration getHardwareConfiguration(URI uri);
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.tmrk.enterprisecloud.functions;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.common.collect.Iterables;
|
||||
import org.jclouds.http.functions.ReturnTrueOn404;
|
||||
import org.jclouds.rest.ResourceNotFoundException;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachines;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.jclouds.util.Throwables2.propagateOrNull;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Jason King
|
||||
*/
|
||||
@Singleton
|
||||
public class ReturnEmptyVirtualMachinesOnNotFoundOr404 implements Function<Exception, Object> {
|
||||
private final ReturnTrueOn404 rto404;
|
||||
|
||||
@Inject
|
||||
ReturnEmptyVirtualMachinesOnNotFoundOr404(ReturnTrueOn404 rto404) {
|
||||
this.rto404 = checkNotNull(rto404, "rto404");
|
||||
}
|
||||
|
||||
public Object apply(Exception from) {
|
||||
Iterable<ResourceNotFoundException> throwables = Iterables.filter(Throwables.getCausalChain(from),
|
||||
ResourceNotFoundException.class);
|
||||
if (Iterables.size(throwables) >= 1) {
|
||||
return VirtualMachines.builder().build();
|
||||
} else if (rto404.apply(from)) {
|
||||
return VirtualMachines.builder().build();
|
||||
}
|
||||
return VirtualMachines.class.cast(propagateOrNull(from));
|
||||
}
|
||||
}
|
|
@ -23,6 +23,7 @@ import org.jclouds.http.HttpRequest;
|
|||
import org.jclouds.http.functions.ParseXMLWithJAXB;
|
||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.jclouds.tmrk.enterprisecloud.functions.ReturnEmptyVirtualMachinesOnNotFoundOr404;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -61,7 +62,7 @@ public class VirtualMachineAsyncClientTest extends BaseTerremarkEnterpriseCloudA
|
|||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseXMLWithJAXB.class);
|
||||
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
|
||||
assertExceptionParserClassEquals(method, ReturnEmptyVirtualMachinesOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
}
|
||||
|
@ -80,8 +81,8 @@ public class VirtualMachineAsyncClientTest extends BaseTerremarkEnterpriseCloudA
|
|||
checkFilters(httpRequest);
|
||||
}
|
||||
|
||||
public void testGetVirtualMachineConfigurationOptions() throws SecurityException, NoSuchMethodException, IOException, URISyntaxException {
|
||||
Method method = VirtualMachineAsyncClient.class.getMethod("getVirtualMachineConfigurationOptions", URI.class);
|
||||
public void testGetConfigurationOptions() throws SecurityException, NoSuchMethodException, IOException, URISyntaxException {
|
||||
Method method = VirtualMachineAsyncClient.class.getMethod("getConfigurationOptions", URI.class);
|
||||
HttpRequest httpRequest = processor.createRequest(method,new URI("/cloudapi/ecloud/virtualmachines/5504/configurationoptions"));
|
||||
|
||||
assertRequestLineEquals(httpRequest, "GET https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/virtualmachines/5504/configurationoptions HTTP/1.1");
|
||||
|
@ -94,6 +95,20 @@ public class VirtualMachineAsyncClientTest extends BaseTerremarkEnterpriseCloudA
|
|||
checkFilters(httpRequest);
|
||||
}
|
||||
|
||||
public void testGetHardwareConfiguration() throws SecurityException, NoSuchMethodException, IOException, URISyntaxException {
|
||||
Method method = VirtualMachineAsyncClient.class.getMethod("getHardwareConfiguration", URI.class);
|
||||
HttpRequest httpRequest = processor.createRequest(method,new URI("/cloudapi/ecloud/virtualmachines/5504/hardwareconfiguration"));
|
||||
|
||||
assertRequestLineEquals(httpRequest, "GET https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/virtualmachines/5504/hardwareconfiguration HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/vnd.tmrk.cloud.virtualMachineHardware\nx-tmrk-version: 2011-07-01\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseXMLWithJAXB.class);
|
||||
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TypeLiteral<RestAnnotationProcessor<VirtualMachineAsyncClient>> createTypeLiteral() {
|
||||
return new TypeLiteral<RestAnnotationProcessor<VirtualMachineAsyncClient>>() {
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
package org.jclouds.tmrk.enterprisecloud.features;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.hardware.HardwareConfiguration;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.network.AssignedIpAddresses;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.network.DeviceNetwork;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachine;
|
||||
|
@ -30,9 +31,7 @@ import org.testng.annotations.Test;
|
|||
import java.net.URI;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
import static org.testng.Assert.*;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code VirtualMachineClient}
|
||||
|
@ -53,27 +52,53 @@ public class VirtualMachineClientLiveTest extends BaseTerremarkEnterpriseCloudCl
|
|||
VirtualMachines virtualMachines = client.getVirtualMachines(new URI("/cloudapi/ecloud/virtualMachines/computePools/89"));
|
||||
for( VirtualMachine vm : virtualMachines.getVirtualMachines()) {
|
||||
VirtualMachine virtualMachine = client.getVirtualMachine(vm.getHref());
|
||||
assertNotNull(virtualMachine,"virtualMachine should not be null");
|
||||
assertNotNull(virtualMachine);
|
||||
assertEquals(virtualMachine.getStatus(),VirtualMachine.VirtualMachineStatus.DEPLOYED);
|
||||
}
|
||||
}
|
||||
|
||||
public void testGetVirtualMachinesWhenMissing() throws Exception {
|
||||
VirtualMachines result = client.getVirtualMachines(new URI("/cloudapi/ecloud/virtualMachines/computePools/-1"));
|
||||
assertEquals(result, VirtualMachines.builder().build());
|
||||
}
|
||||
|
||||
public void testGetVirtualMachine() throws Exception {
|
||||
VirtualMachine virtualMachine = client.getVirtualMachine(new URI("/cloudapi/ecloud/virtualMachines/5504"));
|
||||
assertNotNull(virtualMachine,"virtualMachine should not be null");
|
||||
assertEquals(virtualMachine.getStatus(), VirtualMachine.VirtualMachineStatus.DEPLOYED);
|
||||
}
|
||||
|
||||
public void testGetVirtualMachineWhenMissing() throws Exception {
|
||||
VirtualMachine virtualMachine = client.getVirtualMachine(new URI("/cloudapi/ecloud/virtualMachines/-1"));
|
||||
assertNull(virtualMachine);
|
||||
}
|
||||
|
||||
public void testGetAssignedIpAddresses() throws Exception {
|
||||
AssignedIpAddresses assignedIpAddresses = client.getAssignedIpAddresses(new URI("/cloudapi/ecloud/virtualMachines/5504/assignedips"));
|
||||
assertNotNull(assignedIpAddresses,"assignedIpAddresses should not be null");
|
||||
assertNotNull(assignedIpAddresses);
|
||||
DeviceNetwork network = Iterables.getOnlyElement(assignedIpAddresses.getNetworks().getDeviceNetworks());
|
||||
Set<String> ipAddresses = network.getIpAddresses().getIpAddresses();
|
||||
assertTrue(ipAddresses.size()>0, "vm has no assigned ip addresses");
|
||||
}
|
||||
|
||||
public void testGetVirtualMachineConfigurationOptions() throws Exception {
|
||||
VirtualMachineConfigurationOptions virtualMachineConfigurationOptions = client.getVirtualMachineConfigurationOptions(new URI("/cloudapi/ecloud/virtualmachines/5504/configurationoptions"));
|
||||
assertNotNull(virtualMachineConfigurationOptions,"options should not be null");
|
||||
public void testGetAssignedIpAddressesWhenMissing() throws Exception {
|
||||
AssignedIpAddresses assignedIpAddresses = client.getAssignedIpAddresses(new URI("/cloudapi/ecloud/virtualMachines/-1/assignedips"));
|
||||
assertNull(assignedIpAddresses);
|
||||
}
|
||||
|
||||
public void testGetConfigurationOptions() throws Exception {
|
||||
VirtualMachineConfigurationOptions configurationOptions = client.getConfigurationOptions(new URI("/cloudapi/ecloud/virtualmachines/5504/configurationoptions"));
|
||||
assertNotNull(configurationOptions);
|
||||
}
|
||||
|
||||
public void testGetHardwareConfiguration() throws Exception {
|
||||
HardwareConfiguration hardwareConfiguration = client.getHardwareConfiguration(new URI("/cloudapi/ecloud/virtualmachines/5504/hardwareconfiguration"));
|
||||
assertNotNull(hardwareConfiguration);
|
||||
}
|
||||
|
||||
public void testGetHardwareConfigurationWhenMissing() throws Exception {
|
||||
HardwareConfiguration result = client.getHardwareConfiguration(new URI("/cloudapi/ecloud/virtualmachines/-1/hardwareconfiguration"));
|
||||
assertNull(result);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.tmrk.enterprisecloud.functions;
|
||||
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.HttpResponseException;
|
||||
import org.jclouds.http.functions.ReturnTrueOn404;
|
||||
import org.jclouds.rest.ResourceNotFoundException;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachines;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Jason King
|
||||
*/
|
||||
@Test(groups = "unit", testName = "ReturnEmptyVirtualMachinesOnNotFoundOr404Test")
|
||||
public class ReturnEmptyVirtualMachinesOnNotFoundOr404Test {
|
||||
|
||||
private ReturnEmptyVirtualMachinesOnNotFoundOr404 function;
|
||||
private VirtualMachines expected;
|
||||
|
||||
@BeforeMethod
|
||||
public void setUp() {
|
||||
function = new ReturnEmptyVirtualMachinesOnNotFoundOr404(new ReturnTrueOn404());
|
||||
expected = VirtualMachines.builder().build();
|
||||
}
|
||||
|
||||
public void testOn404() {
|
||||
VirtualMachines expected = VirtualMachines.builder().build();
|
||||
assertEquals(function.apply(new HttpResponseException("response exception", null, new HttpResponse(404, "404 message", null))), expected);
|
||||
}
|
||||
|
||||
public void testOnNotFound() {
|
||||
VirtualMachines expected = VirtualMachines.builder().build();
|
||||
assertEquals(function.apply(new ResourceNotFoundException()),expected);
|
||||
}
|
||||
|
||||
public void testOnNotFoundChained() {
|
||||
VirtualMachines expected = VirtualMachines.builder().build();
|
||||
assertEquals(function.apply(new RuntimeException(new ResourceNotFoundException())),expected);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = HttpResponseException.class)
|
||||
public void testOn500() {
|
||||
function.apply(new HttpResponseException("response exception", null, new HttpResponse(500, "500 message", null)));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,142 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.tmrk.enterprisecloud.xml;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Module;
|
||||
import com.google.inject.Provides;
|
||||
import org.jclouds.crypto.Crypto;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.http.functions.ParseXMLWithJAXB;
|
||||
import org.jclouds.logging.config.NullLoggingModule;
|
||||
import org.jclouds.rest.AuthorizationException;
|
||||
import org.jclouds.rest.BaseRestClientTest;
|
||||
import org.jclouds.rest.RestContextSpec;
|
||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.hardware.HardwareConfiguration;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.hardware.VirtualDisk;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.network.NetworkReference;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.network.VirtualNic;
|
||||
import org.jclouds.tmrk.enterprisecloud.features.VirtualMachineAsyncClient;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import javax.inject.Named;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URI;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.jclouds.io.Payloads.newInputStreamPayload;
|
||||
import static org.jclouds.rest.RestContextFactory.contextSpec;
|
||||
import static org.jclouds.rest.RestContextFactory.createContextBuilder;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
import static org.testng.AssertJUnit.assertEquals;
|
||||
import static org.testng.AssertJUnit.assertNotNull;
|
||||
|
||||
/**
|
||||
* Tests behavior of JAXB parsing for VirtualMachines
|
||||
* @author Jason King
|
||||
*
|
||||
*/
|
||||
public class HardwareConfigurationJAXBParsingTest extends BaseRestClientTest {
|
||||
|
||||
@BeforeClass
|
||||
void setupFactory() {
|
||||
RestContextSpec<String, Integer> contextSpec = contextSpec("test", "http://localhost:9999", "1", "", "userfoo",
|
||||
"credentialFoo", String.class, Integer.class,
|
||||
ImmutableSet.<Module> of(new MockModule(), new NullLoggingModule(), new AbstractModule() {
|
||||
|
||||
@Override
|
||||
protected void configure() {}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Provides
|
||||
@Named("exception")
|
||||
Set<String> exception() {
|
||||
throw new AuthorizationException();
|
||||
}
|
||||
|
||||
}));
|
||||
|
||||
injector = createContextBuilder(contextSpec).buildInjector();
|
||||
parserFactory = injector.getInstance(ParseSax.Factory.class);
|
||||
crypto = injector.getInstance(Crypto.class);
|
||||
}
|
||||
|
||||
@Test(groups = "unit", testName = "HardwareConfigurationJAXBParsingTest")
|
||||
public void testParse() throws Exception {
|
||||
|
||||
Method method = VirtualMachineAsyncClient.class.getMethod("getHardwareConfiguration", URI.class);
|
||||
HttpRequest request = factory(VirtualMachineAsyncClient.class).createRequest(method,new URI("/1"));
|
||||
assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class);
|
||||
|
||||
Function<HttpResponse, HardwareConfiguration> parser = (Function<HttpResponse, HardwareConfiguration>) RestAnnotationProcessor
|
||||
.createResponseParser(parserFactory, injector, method, request);
|
||||
|
||||
InputStream is = getClass().getResourceAsStream("/hardwareConfiguration.xml");
|
||||
HardwareConfiguration hardwareConfiguration = parser.apply(new HttpResponse(200, "ok", newInputStreamPayload(is)));
|
||||
|
||||
assertHardwareConfiguration(hardwareConfiguration);
|
||||
}
|
||||
|
||||
private void assertHardwareConfiguration(HardwareConfiguration hardwareConfiguration) throws Exception {
|
||||
assertEquals(1,hardwareConfiguration.getActions().size());
|
||||
assertEquals(1,hardwareConfiguration.getProcessorCount());
|
||||
ResourceCapacity memory = ResourceCapacity.builder().value(384).unit("MB").build();
|
||||
assertEquals(memory,hardwareConfiguration.getMemory());
|
||||
assertDisks(hardwareConfiguration.getVirtualDisks());
|
||||
assertNics(hardwareConfiguration.getVirtualNics());
|
||||
}
|
||||
|
||||
private void assertDisks(Set<VirtualDisk> disks) {
|
||||
VirtualDisk disk = VirtualDisk.builder().index(0).name("Hard Disk 1")
|
||||
.size(ResourceCapacity.builder().value(10).unit("GB").build())
|
||||
.build();
|
||||
|
||||
assertEquals(ImmutableSet.of(disk), disks);
|
||||
}
|
||||
|
||||
|
||||
private void assertNics(Set<VirtualNic> nics) throws Exception {
|
||||
|
||||
assertEquals(1, nics.size());
|
||||
|
||||
NetworkReference network = NetworkReference.builder()
|
||||
.href(new URI("/cloudapi/ecloud/networks/3936"))
|
||||
.name("10.146.204.64/28")
|
||||
.type("application/vnd.tmrk.cloud.network")
|
||||
.networkType(NetworkReference.NetworkType.INTERNAL)
|
||||
.build();
|
||||
|
||||
VirtualNic nic = VirtualNic.builder()
|
||||
.macAddress("00:50:56:b8:00:58")
|
||||
.name("Network adapter 1")
|
||||
.network(network)
|
||||
.unitNumber(7)
|
||||
.build();
|
||||
assertEquals(nic,nics.iterator().next());
|
||||
}
|
||||
}
|
|
@ -33,7 +33,9 @@ import org.jclouds.rest.AuthorizationException;
|
|||
import org.jclouds.rest.BaseRestClientTest;
|
||||
import org.jclouds.rest.RestContextSpec;
|
||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.ResourceCapacityRange;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.*;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.hardware.DiskConfigurationOption;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.hardware.DiskConfigurationOptionRange;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachineConfigurationOptions;
|
||||
import org.jclouds.tmrk.enterprisecloud.features.VirtualMachineAsyncClient;
|
||||
|
@ -50,6 +52,8 @@ import static org.jclouds.io.Payloads.newInputStreamPayload;
|
|||
import static org.jclouds.rest.RestContextFactory.contextSpec;
|
||||
import static org.jclouds.rest.RestContextFactory.createContextBuilder;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests behavior of JAXB parsing for VirtualMachineConfigurationOptions
|
||||
|
@ -85,7 +89,7 @@ public class VirtualMachineConfigurationOptionsJAXBParsingTest extends BaseRestC
|
|||
@Test
|
||||
public void testParseVirtualMachineWithJAXB() throws Exception {
|
||||
|
||||
Method method = VirtualMachineAsyncClient.class.getMethod("getVirtualMachineConfigurationOptions", URI.class);
|
||||
Method method = VirtualMachineAsyncClient.class.getMethod("getConfigurationOptions", URI.class);
|
||||
HttpRequest request = factory(VirtualMachineAsyncClient.class).createRequest(method,new URI("/1"));
|
||||
assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class);
|
||||
|
||||
|
@ -93,9 +97,19 @@ public class VirtualMachineConfigurationOptionsJAXBParsingTest extends BaseRestC
|
|||
.createResponseParser(parserFactory, injector, method, request);
|
||||
|
||||
InputStream is = getClass().getResourceAsStream("/virtualMachineConfigurationOptions.xml");
|
||||
VirtualMachineConfigurationOptions virtualMachineConfigurationOptions = parser.apply(new HttpResponse(200, "ok", newInputStreamPayload(is)));
|
||||
VirtualMachineConfigurationOptions configurationOptions = parser.apply(new HttpResponse(200, "ok", newInputStreamPayload(is)));
|
||||
|
||||
assertMemoryOptions(virtualMachineConfigurationOptions.getMemory());
|
||||
assertProcessorOptions(configurationOptions.getProcessor());
|
||||
assertMemoryOptions(configurationOptions.getMemory());
|
||||
assertDiskConfigurationOption(configurationOptions.getDisk());
|
||||
assertNetworkAdapterOptions(configurationOptions.getNetworkAdapter());
|
||||
assertCustomizationOption(configurationOptions.getCustomization());
|
||||
}
|
||||
|
||||
private void assertProcessorOptions(ConfigurationOptionRange processor) {
|
||||
assertEquals(processor.getMinimum(),1);
|
||||
assertEquals(processor.getMaximum(),8);
|
||||
assertEquals(processor.getStepFactor(),1);
|
||||
}
|
||||
|
||||
private void assertMemoryOptions(ResourceCapacityRange memory) {
|
||||
|
@ -103,4 +117,38 @@ public class VirtualMachineConfigurationOptionsJAXBParsingTest extends BaseRestC
|
|||
assertEquals(memory.getMaximumSize(), ResourceCapacity.builder().value(261120).unit("MB").build());
|
||||
assertEquals(memory.getStepFactor(), ResourceCapacity.builder().value(4).unit("MB").build());
|
||||
}
|
||||
|
||||
private void assertNetworkAdapterOptions(ConfigurationOptionRange networkAdapter) {
|
||||
assertEquals(networkAdapter.getMinimum(),1);
|
||||
assertEquals(networkAdapter.getMaximum(),4);
|
||||
assertEquals(networkAdapter.getStepFactor(),1);
|
||||
}
|
||||
|
||||
private void assertCustomizationOption(CustomizationOption customization) {
|
||||
assertEquals(customization.getType(), CustomizationOption.CustomizationType.LINUX);
|
||||
assertFalse(customization.canPowerOn());
|
||||
assertFalse(customization.isPasswordRequired());
|
||||
assertTrue(customization.isSshKeyRequired());
|
||||
}
|
||||
|
||||
private void assertDiskConfigurationOption(DiskConfigurationOption diskConfigurationOption) {
|
||||
assertEquals(diskConfigurationOption.getMinimum(),1);
|
||||
assertEquals(diskConfigurationOption.getMaximum(), 15);
|
||||
|
||||
ResourceCapacityRange systemDiskRange = ResourceCapacityRange.builder()
|
||||
.minimumSize(ResourceCapacity.builder().value(1).unit("GB").build())
|
||||
.maximumSize(ResourceCapacity.builder().value(512).unit("GB").build())
|
||||
.stepFactor(ResourceCapacity.builder().value(1).unit("GB").build())
|
||||
.build();
|
||||
assertEquals(diskConfigurationOption.getSystemDisk(), DiskConfigurationOptionRange.builder().resourceCapacityRange(systemDiskRange).monthlyCost(0).build());
|
||||
|
||||
ResourceCapacityRange dataDiskRange = ResourceCapacityRange.builder()
|
||||
.minimumSize(ResourceCapacity.builder().value(1).unit("GB").build())
|
||||
.maximumSize(ResourceCapacity.builder().value(512).unit("GB").build())
|
||||
.stepFactor(ResourceCapacity.builder().value(2).unit("GB").build())
|
||||
.build();
|
||||
|
||||
assertEquals(diskConfigurationOption.getDataDisk(), DiskConfigurationOptionRange.builder().resourceCapacityRange(dataDiskRange).monthlyCost(0).build());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
<HardwareConfiguration
|
||||
href="/cloudapi/ecloud/virtualmachines/5504/hardwareconfiguration"
|
||||
type="application/vnd.tmrk.cloud.virtualMachineHardware"
|
||||
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<Actions>
|
||||
<Action href="/cloudapi/ecloud/virtualmachines/5504/hardwareconfiguration"
|
||||
name="edit"
|
||||
type="application/vnd.tmrk.cloud.virtualMachineHardware"/>
|
||||
</Actions>
|
||||
<ProcessorCount>1</ProcessorCount>
|
||||
<Memory>
|
||||
<Unit>MB</Unit>
|
||||
<Value>384</Value>
|
||||
</Memory>
|
||||
<Disks>
|
||||
<Disk>
|
||||
<Index>0</Index>
|
||||
<Size>
|
||||
<Unit>GB</Unit>
|
||||
<Value>10</Value>
|
||||
</Size>
|
||||
<Name>Hard Disk 1</Name>
|
||||
</Disk>
|
||||
</Disks>
|
||||
<Nics>
|
||||
<Nic>
|
||||
<UnitNumber>7</UnitNumber>
|
||||
<Name>Network adapter 1</Name>
|
||||
<MacAddress>00:50:56:b8:00:58</MacAddress>
|
||||
<Network href="/cloudapi/ecloud/networks/3936"
|
||||
name="10.146.204.64/28"
|
||||
type="application/vnd.tmrk.cloud.network">
|
||||
<NetworkType>Internal</NetworkType>
|
||||
</Network>
|
||||
</Nic>
|
||||
</Nics>
|
||||
</HardwareConfiguration>
|
|
@ -53,7 +53,7 @@
|
|||
</MaximumSize>
|
||||
<StepFactor>
|
||||
<Unit>GB</Unit>
|
||||
<Value>1</Value>
|
||||
<Value>2</Value>
|
||||
</StepFactor>
|
||||
</ResourceCapacityRange>
|
||||
<MonthlyCost>0</MonthlyCost>
|
||||
|
|
Loading…
Reference in New Issue