Merge pull request #92 from jsonking/master

Issue 158: Modified VirtualGuest with more fields so that VirtualGuestToNodeMetadata can make better progress
This commit is contained in:
Adrian Cole 2011-10-01 17:31:23 -07:00
commit 032c1b9246
10 changed files with 488 additions and 19 deletions

View File

@ -39,7 +39,7 @@ public class SoftLayerPropertiesBuilder extends PropertiesBuilder {
properties.setProperty(PROPERTY_ENDPOINT, "https://api.softlayer.com/rest");
properties.setProperty(PROPERTY_API_VERSION, "3");
properties.setProperty(SoftLayerConstants.PROPERTY_SOFTLAYER_VIRTUALGUEST_PACKAGE_NAME, "Cloud Server");
properties.setProperty(SoftLayerConstants.PROPERTY_SOFTLAYER_VIRTUALGUEST_LOGIN_DETAILS_DELAY, "3000000");
properties.setProperty(SoftLayerConstants.PROPERTY_SOFTLAYER_VIRTUALGUEST_LOGIN_DETAILS_DELAY, ""+60*60*1000);
properties.setProperty(PROPERTY_ISO3166_CODES, "SG,US-CA,US-TX,US-VA,US-WA,US-TX");
return properties;
}

View File

@ -36,6 +36,7 @@ import org.jclouds.compute.domain.NodeMetadataBuilder;
import org.jclouds.compute.domain.NodeState;
import org.jclouds.domain.Credentials;
import org.jclouds.domain.Location;
import org.jclouds.softlayer.domain.Datacenter;
import org.jclouds.softlayer.domain.VirtualGuest;
import com.google.common.base.Function;
@ -85,10 +86,12 @@ public class VirtualGuestToNodeMetadata implements Function<VirtualGuest, NodeMe
if (image != null)
builder.operatingSystem(image.getOperatingSystem());
builder.hardware(findHardwareForVirtualGuest.apply(from));
// TODO get state
// builder.state(serverStateToNodeState.get(from.getState()));
builder.publicAddresses(ImmutableSet.<String> of(from.getPrimaryIpAddress()));
builder.privateAddresses(ImmutableSet.<String> of(from.getPrimaryBackendIpAddress()));
builder.state(serverStateToNodeState.get(from.getPowerState().getKeyName()));
// These are null for 'bad' guest orders in the HALTED state.
if (from.getPrimaryIpAddress()!=null)builder.publicAddresses(ImmutableSet.<String> of(from.getPrimaryIpAddress()));
if (from.getPrimaryBackendIpAddress()!=null)builder.privateAddresses(ImmutableSet.<String> of(from.getPrimaryBackendIpAddress()));
builder.credentials(credentialStore.get("node#"+ from.getId()));
return builder.build();
}
@ -103,7 +106,8 @@ public class VirtualGuestToNodeMetadata implements Function<VirtualGuest, NodeMe
@Override
public boolean matches(VirtualGuest from, Hardware input) {
return input.getProviderId().equals(from.getId() + "");
//return input.getProviderId().equals(from.getId() + "");
return false;
}
}
@ -132,8 +136,9 @@ public class VirtualGuestToNodeMetadata implements Function<VirtualGuest, NodeMe
@Override
public boolean matches(VirtualGuest from, Location input) {
// TODO determine the price list from the virtual guest which would have the image in it.
return false;
Datacenter dc = from.getDatacenter();
if (dc == null) return false;
return input.getId().equals(Integer.toString(dc.getId()));
}
}
}

View File

@ -0,0 +1,102 @@
/**
* 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.softlayer.domain;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* The power state class provides a common set of values for which a guest's power state will be presented in the SoftLayer API.
* @author Jason King
* @see <a href= "http://sldn.softlayer.com/reference/datatypes/SoftLayer_Virtual_Guest_Power_State"
* />
*/
public class PowerState implements Comparable<PowerState> {
public static Builder builder() {
return new Builder();
}
public static class Builder {
private VirtualGuest.State keyName;
public Builder keyName(VirtualGuest.State keyName) {
this.keyName = keyName;
return this;
}
public PowerState build() {
return new PowerState(keyName);
}
public static Builder fromAddress(PowerState in) {
return PowerState.builder().keyName(in.getKeyName());
}
}
private VirtualGuest.State keyName;
// for deserializer
PowerState() {
}
public PowerState(VirtualGuest.State keyName) {
this.keyName = checkNotNull(keyName,"keyName cannot be null or empty:"+keyName);
}
@Override
public int compareTo(PowerState arg0) {
return keyName.compareTo(arg0.keyName);
}
/**
* Maps onto {@code VirtualGuest.State}
* @return The key name of a power state.
*
*/
public VirtualGuest.State getKeyName() {
return keyName;
}
public Builder toBuilder() {
return Builder.fromAddress(this);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
PowerState that = (PowerState) o;
if (keyName != null ? !keyName.equals(that.keyName) : that.keyName != null)
return false;
return true;
}
@Override
public int hashCode() {
return keyName != null ? keyName.hashCode() : 0;
}
@Override
public String toString() {
return "[keyName=" + keyName + "]";
}
}

View File

@ -18,12 +18,12 @@
*/
package org.jclouds.softlayer.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.base.CaseFormat;
import com.google.gson.annotations.SerializedName;
import java.util.Date;
import com.google.common.base.CaseFormat;
import com.google.gson.annotations.SerializedName;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* The virtual guest data type presents the structure in which all virtual guests will be presented.
@ -76,6 +76,8 @@ public class VirtualGuest implements Comparable<VirtualGuest> {
private String primaryIpAddress;
private BillingItemVirtualGuest billingItem;
private OperatingSystem operatingSystem;
private Datacenter datacenter;
private PowerState powerState;
public Builder id(int id) {
this.id = id;
@ -187,12 +189,22 @@ public class VirtualGuest implements Comparable<VirtualGuest> {
return this;
}
public Builder datacenter(Datacenter datacenter) {
this.datacenter = datacenter;
return this;
}
public Builder powerState(PowerState powerState) {
this.powerState = powerState;
return this;
}
public VirtualGuest build() {
return new VirtualGuest(accountId, createDate, dedicatedAccountHostOnly, domain,
fullyQualifiedDomainName, hostname, id, lastVerifiedDate, maxCpu,
maxCpuUnits, maxMemory, metricPollDate, modifyDate, notes,
privateNetworkOnly, startCpus, statusId, uuid, primaryBackendIpAddress,
primaryIpAddress,billingItem,operatingSystem);
primaryIpAddress,billingItem,operatingSystem,datacenter,powerState);
}
public static Builder fromVirtualGuest(VirtualGuest in) {
@ -218,8 +230,9 @@ public class VirtualGuest implements Comparable<VirtualGuest> {
.primaryBackendIpAddress(in.getPrimaryBackendIpAddress())
.primaryIpAddress(in.getPrimaryIpAddress())
.billingItem(in.getBillingItem())
.operatingSystem(in.getOperatingSystem());
.operatingSystem(in.getOperatingSystem())
.datacenter(in.getDatacenter())
.powerState(in.getPowerState());
}
}
@ -272,7 +285,9 @@ public class VirtualGuest implements Comparable<VirtualGuest> {
private BillingItemVirtualGuest billingItem;
private OperatingSystem operatingSystem;
private Datacenter datacenter;
private PowerState powerState;
// for deserializer
VirtualGuest() {
@ -282,7 +297,7 @@ public class VirtualGuest implements Comparable<VirtualGuest> {
String fullyQualifiedDomainName, String hostname, int id, Date lastVerifiedDate, int maxCpu,
String maxCpuUnits, int maxMemory, Date metricPollDate, Date modifyDate, String notes,
boolean privateNetworkOnly, int startCpus, int statusId, String uuid, String primaryBackendIpAddress,
String primaryIpAddress,BillingItemVirtualGuest billingItem, OperatingSystem operatingSystem) {
String primaryIpAddress,BillingItemVirtualGuest billingItem, OperatingSystem operatingSystem, Datacenter datacenter, PowerState powerState) {
this.accountId = accountId;
this.createDate = createDate;
this.dedicatedAccountHostOnly = dedicatedAccountHostOnly;
@ -305,6 +320,8 @@ public class VirtualGuest implements Comparable<VirtualGuest> {
this.primaryIpAddress = primaryIpAddress;
this.billingItem = billingItem;
this.operatingSystem = operatingSystem;
this.datacenter = datacenter;
this.powerState = powerState;
}
@Override
@ -469,6 +486,21 @@ public class VirtualGuest implements Comparable<VirtualGuest> {
return operatingSystem;
}
/**
* @return The guest's datacenter
*/
public Datacenter getDatacenter() {
return datacenter;
}
/**
* @return The current power state of a virtual guest.
*/
public PowerState getPowerState() {
return powerState;
}
@Override
public int hashCode() {
final int prime = 31;
@ -495,6 +527,8 @@ public class VirtualGuest implements Comparable<VirtualGuest> {
result = prime * result + ((uuid == null) ? 0 : uuid.hashCode());
result = prime * result + ((billingItem == null) ? 0 : billingItem.hashCode());
result = prime * result + ((operatingSystem == null) ? 0 : operatingSystem.hashCode());
result = prime * result + ((datacenter == null) ? 0 : datacenter.hashCode());
result = prime * result + ((powerState == null) ? 0 : powerState.hashCode());
return result;
}
@ -593,6 +627,16 @@ public class VirtualGuest implements Comparable<VirtualGuest> {
return false;
} else if (!operatingSystem.equals(other.operatingSystem))
return false;
if (datacenter == null) {
if (other.datacenter != null)
return false;
} else if (!datacenter.equals(other.datacenter))
return false;
if (powerState == null) {
if (other.powerState != null)
return false;
} else if (!powerState.equals(other.powerState))
return false;
return true;
}
@ -605,7 +649,8 @@ public class VirtualGuest implements Comparable<VirtualGuest> {
+ ", metricPollDate=" + metricPollDate + ", modifyDate=" + modifyDate + ", notes=" + notes
+ ", primaryBackendIpAddress=" + primaryBackendIpAddress + ", primaryIpAddress=" + primaryIpAddress
+ ", privateNetworkOnly=" + privateNetworkOnly + ", startCpus=" + startCpus + ", statusId=" + statusId
+ ", uuid=" + uuid + ", billingItem="+billingItem+", operatingSystem="+operatingSystem+"]";
+ ", uuid=" + uuid + ", billingItem="+billingItem+", operatingSystem="+operatingSystem+", datacenter="+datacenter
+ ", powerState="+powerState+"]";
}
}

View File

@ -57,7 +57,7 @@ public class SoftLayerComputeServiceAdapterLiveTest extends BaseSoftLayerClientL
super.setupClient();
adapter = new SoftLayerComputeServiceAdapter(context.getApi(),
ProductPackageClientLiveTest.CLOUD_SERVER_PACKAGE_NAME,
new SoftLayerComputeServiceAdapter.VirtualGuestHasLoginDetailsPresent(context.getApi()),300000);
new SoftLayerComputeServiceAdapter.VirtualGuestHasLoginDetailsPresent(context.getApi()),60*60*1000);
}
@Test
@ -89,7 +89,7 @@ public class SoftLayerComputeServiceAdapterLiveTest extends BaseSoftLayerClientL
protected void doConnectViaSsh(VirtualGuest guest, Credentials creds) {
SshClient ssh = computeContext.utils().sshFactory()
.create(new IPSocket(guest.getPrimaryBackendIpAddress(), 22), creds);
.create(new IPSocket(guest.getPrimaryIpAddress(), 22), creds);
try {
ssh.connect();
ExecResponse hello = ssh.exec("echo hello");

View File

@ -0,0 +1,4 @@
{"accountId":93750,"createDate":"2011-09-28T01:52:45-08:00","dedicatedAccountHostOnlyFlag":false,"domain":"jclouds.org","fullyQualifiedDomainName":"foo-ef4.jclouds.org","hostname":"foo-ef4","id":413348,"lastVerifiedDate":null,"maxCpu":null,"maxCpuUnits":"CORE","maxMemory":256,"metricPollDate":null,"modifyDate":null,"privateNetworkOnlyFlag":false,"startCpus":null,"statusId":1001,"globalIdentifier":"9a8b20f0-a758-4c1f-b65b-0e63b791009f","managedResourceFlag":false,"networkVlans":[],"powerState":{
"keyName":"HALTED",
"name":"Halted"
}}

View File

@ -0,0 +1,89 @@
{"accountId":93750,"createDate":"2011-10-01T06:10:38-08:00","dedicatedAccountHostOnlyFlag":true,"domain":"me.org","fullyQualifiedDomainName":"node-1928752820.me.org","hostname":"node-1928752820","id":416591,"lastVerifiedDate":null,"maxCpu":1,"maxCpuUnits":"CORE","maxMemory":1024,"metricPollDate":"2011-10-01T09:36:00-08:00","modifyDate":"2011-10-01T10:47:14-08:00","privateNetworkOnlyFlag":false,"startCpus":1,"statusId":1001,"uuid":"754c011b-7e80-8185-7e5a-c6424873c509","datacenter":{
"id":3,
"longName":"Dallas",
"name":"dal01"
},"globalIdentifier":"0f10b863-f6b3-49a3-a2b9-9b0fe956a912","managedResourceFlag":false,"networkVlans":[
{
"accountId":93750,
"id":144615,
"modifyDate":"2011-09-30T11:35:27-08:00",
"networkVrfId":null,
"primarySubnetId":171267,
"vlanNumber":1673
},
{
"accountId":93750,
"id":144616,
"modifyDate":"2011-09-30T11:35:30-08:00",
"networkVrfId":null,
"primarySubnetId":329652,
"vlanNumber":1622
}
],"operatingSystem":{
"hardwareId":null,
"id":913636,
"manufacturerLicenseInstance":"",
"passwords":[
{
"createDate":"2011-10-01T06:12:33-08:00",
"id":728987,
"modifyDate":"2011-10-01T06:12:33-08:00",
"password":"XKL4cHym",
"port":null,
"softwareId":913636,
"username":"root",
"software":{
"hardwareId":null,
"id":913636,
"manufacturerLicenseInstance":"",
"passwords":[
{
"createDate":"2011-10-01T06:12:33-08:00",
"id":728987,
"modifyDate":"2011-10-01T06:12:33-08:00",
"password":"XKL4cHym",
"port":null,
"softwareId":913636,
"username":"root",
"software":null
}
],
"softwareLicense":{
"id":427,
"softwareDescriptionId":408,
"softwareDescription":{
"controlPanel":0,
"id":408,
"manufacturer":"Ubuntu",
"name":"Ubuntu ",
"operatingSystem":1,
"requiredUser":"root",
"upgradeSwDescId":null,
"version":"8.04-64 Minimal for CCI",
"virtualLicense":0,
"virtualizationPlatform":0
}
}
}
}
],
"softwareLicense":{
"id":427,
"softwareDescriptionId":408,
"softwareDescription":{
"controlPanel":0,
"id":408,
"manufacturer":"Ubuntu",
"name":"Ubuntu ",
"operatingSystem":1,
"requiredUser":"root",
"upgradeSwDescId":null,
"version":"8.04-64 Minimal for CCI",
"virtualLicense":0,
"virtualizationPlatform":0
}
}
},"powerState":{
"keyName":"HALTED",
"name":"Halted"
},"primaryBackendIpAddress":"10.37.102.197","primaryIpAddress":"173.192.29.189"}

View File

@ -0,0 +1,46 @@
{"accountId":93750,"createDate":"2011-10-01T11:10:16-08:00","dedicatedAccountHostOnlyFlag":true,"domain":"me.org","fullyQualifiedDomainName":"node-246105155.me.org","hostname":"node-246105155","id":416696,"lastVerifiedDate":null,"maxCpu":1,"maxCpuUnits":"CORE","maxMemory":1024,"metricPollDate":null,"modifyDate":"2011-10-01T11:11:31-08:00","privateNetworkOnlyFlag":false,"startCpus":1,"statusId":1001,"uuid":"694d34c3-9c36-b590-4ba7-4ec58954b9dc","datacenter":{
"id":3,
"longName":"Dallas",
"name":"dal01"
},"globalIdentifier":"a867e0a2-01f6-4c80-ad0f-2688f2eab1a7","managedResourceFlag":false,"networkVlans":[
{
"accountId":93750,
"id":144615,
"modifyDate":"2011-09-30T11:35:27-08:00",
"networkVrfId":null,
"primarySubnetId":171267,
"vlanNumber":1673
},
{
"accountId":93750,
"id":144616,
"modifyDate":"2011-09-30T11:35:30-08:00",
"networkVrfId":null,
"primarySubnetId":329652,
"vlanNumber":1622
}
],"operatingSystem":{
"hardwareId":null,
"id":913812,
"manufacturerLicenseInstance":"",
"passwords":[],
"softwareLicense":{
"id":427,
"softwareDescriptionId":408,
"softwareDescription":{
"controlPanel":0,
"id":408,
"manufacturer":"Ubuntu",
"name":"Ubuntu ",
"operatingSystem":1,
"requiredUser":"root",
"upgradeSwDescId":null,
"version":"8.04-64 Minimal for CCI",
"virtualLicense":0,
"virtualizationPlatform":0
}
}
},"powerState":{
"keyName":"HALTED",
"name":"Halted"
},"primaryBackendIpAddress":"10.37.102.194","primaryIpAddress":"173.192.29.186"}

View File

@ -0,0 +1,89 @@
{"accountId":93750,"createDate":"2011-10-01T06:10:38-08:00","dedicatedAccountHostOnlyFlag":true,"domain":"me.org","fullyQualifiedDomainName":"node-1928752820.me.org","hostname":"node-1928752820","id":416591,"lastVerifiedDate":null,"maxCpu":1,"maxCpuUnits":"CORE","maxMemory":1024,"metricPollDate":"2011-10-01T09:36:00-08:00","modifyDate":"2011-10-01T10:45:44-08:00","privateNetworkOnlyFlag":false,"startCpus":1,"statusId":1001,"uuid":"754c011b-7e80-8185-7e5a-c6424873c509","datacenter":{
"id":3,
"longName":"Dallas",
"name":"dal01"
},"globalIdentifier":"0f10b863-f6b3-49a3-a2b9-9b0fe956a912","managedResourceFlag":false,"networkVlans":[
{
"accountId":93750,
"id":144615,
"modifyDate":"2011-09-30T11:35:27-08:00",
"networkVrfId":null,
"primarySubnetId":171267,
"vlanNumber":1673
},
{
"accountId":93750,
"id":144616,
"modifyDate":"2011-09-30T11:35:30-08:00",
"networkVrfId":null,
"primarySubnetId":329652,
"vlanNumber":1622
}
],"operatingSystem":{
"hardwareId":null,
"id":913636,
"manufacturerLicenseInstance":"",
"passwords":[
{
"createDate":"2011-10-01T06:12:33-08:00",
"id":728987,
"modifyDate":"2011-10-01T06:12:33-08:00",
"password":"XKL4cHym",
"port":null,
"softwareId":913636,
"username":"root",
"software":{
"hardwareId":null,
"id":913636,
"manufacturerLicenseInstance":"",
"passwords":[
{
"createDate":"2011-10-01T06:12:33-08:00",
"id":728987,
"modifyDate":"2011-10-01T06:12:33-08:00",
"password":"XKL4cHym",
"port":null,
"softwareId":913636,
"username":"root",
"software":null
}
],
"softwareLicense":{
"id":427,
"softwareDescriptionId":408,
"softwareDescription":{
"controlPanel":0,
"id":408,
"manufacturer":"Ubuntu",
"name":"Ubuntu ",
"operatingSystem":1,
"requiredUser":"root",
"upgradeSwDescId":null,
"version":"8.04-64 Minimal for CCI",
"virtualLicense":0,
"virtualizationPlatform":0
}
}
}
}
],
"softwareLicense":{
"id":427,
"softwareDescriptionId":408,
"softwareDescription":{
"controlPanel":0,
"id":408,
"manufacturer":"Ubuntu",
"name":"Ubuntu ",
"operatingSystem":1,
"requiredUser":"root",
"upgradeSwDescId":null,
"version":"8.04-64 Minimal for CCI",
"virtualLicense":0,
"virtualizationPlatform":0
}
}
},"powerState":{
"keyName":"PAUSED",
"name":"Paused"
},"primaryBackendIpAddress":"10.37.102.197","primaryIpAddress":"173.192.29.189"}

View File

@ -0,0 +1,89 @@
{"accountId":93750,"createDate":"2011-10-01T06:10:38-08:00","dedicatedAccountHostOnlyFlag":true,"domain":"me.org","fullyQualifiedDomainName":"node-1928752820.me.org","hostname":"node-1928752820","id":416591,"lastVerifiedDate":null,"maxCpu":1,"maxCpuUnits":"CORE","maxMemory":1024,"metricPollDate":"2011-10-01T09:36:00-08:00","modifyDate":"2011-10-01T09:36:29-08:00","privateNetworkOnlyFlag":false,"startCpus":1,"statusId":1001,"uuid":"754c011b-7e80-8185-7e5a-c6424873c509","datacenter":{
"id":3,
"longName":"Dallas",
"name":"dal01"
},"globalIdentifier":"0f10b863-f6b3-49a3-a2b9-9b0fe956a912","managedResourceFlag":false,"networkVlans":[
{
"accountId":93750,
"id":144615,
"modifyDate":"2011-09-30T11:35:27-08:00",
"networkVrfId":null,
"primarySubnetId":171267,
"vlanNumber":1673
},
{
"accountId":93750,
"id":144616,
"modifyDate":"2011-09-30T11:35:30-08:00",
"networkVrfId":null,
"primarySubnetId":329652,
"vlanNumber":1622
}
],"operatingSystem":{
"hardwareId":null,
"id":913636,
"manufacturerLicenseInstance":"",
"passwords":[
{
"createDate":"2011-10-01T06:12:33-08:00",
"id":728987,
"modifyDate":"2011-10-01T06:12:33-08:00",
"password":"XKL4cHym",
"port":null,
"softwareId":913636,
"username":"root",
"software":{
"hardwareId":null,
"id":913636,
"manufacturerLicenseInstance":"",
"passwords":[
{
"createDate":"2011-10-01T06:12:33-08:00",
"id":728987,
"modifyDate":"2011-10-01T06:12:33-08:00",
"password":"XKL4cHym",
"port":null,
"softwareId":913636,
"username":"root",
"software":null
}
],
"softwareLicense":{
"id":427,
"softwareDescriptionId":408,
"softwareDescription":{
"controlPanel":0,
"id":408,
"manufacturer":"Ubuntu",
"name":"Ubuntu ",
"operatingSystem":1,
"requiredUser":"root",
"upgradeSwDescId":null,
"version":"8.04-64 Minimal for CCI",
"virtualLicense":0,
"virtualizationPlatform":0
}
}
}
}
],
"softwareLicense":{
"id":427,
"softwareDescriptionId":408,
"softwareDescription":{
"controlPanel":0,
"id":408,
"manufacturer":"Ubuntu",
"name":"Ubuntu ",
"operatingSystem":1,
"requiredUser":"root",
"upgradeSwDescId":null,
"version":"8.04-64 Minimal for CCI",
"virtualLicense":0,
"virtualizationPlatform":0
}
}
},"powerState":{
"keyName":"RUNNING",
"name":"Running"
},"primaryBackendIpAddress":"10.37.102.197","primaryIpAddress":"173.192.29.189"}