Issue 158: Adding BillingItemVirtualGuest so the node can be shut down

This commit is contained in:
Jason King 2011-09-20 11:47:16 +01:00
parent aed4e72e49
commit def43f2e67
5 changed files with 127 additions and 5 deletions

View File

@ -0,0 +1,101 @@
/**
* 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;
import static com.google.common.base.Strings.emptyToNull;
/**
*
* @author Jason King
* @see <a href= "http://sldn.softlayer.com/reference/datatypes/SoftLayer_Billing_Item_Virtual_Guest"
* />
*/
public class BillingItemVirtualGuest implements Comparable<BillingItemVirtualGuest> {
public static Builder builder() {
return new Builder();
}
public static class Builder {
private long id = -1;
public Builder id(long id) {
this.id = id;
return this;
}
public static Builder fromBillingItemVirtualGuest(BillingItemVirtualGuest in) {
return BillingItemVirtualGuest.builder().id(in.getId());
}
}
private long id = -1;
// for deserializer
BillingItemVirtualGuest() {
}
public BillingItemVirtualGuest(long id) {
this.id = id;
}
@Override
public int compareTo(BillingItemVirtualGuest arg0) {
return new Long(id).compareTo(arg0.getId());
}
/**
* @return The unique identifier for this billing item.
*/
public long getId() {
return id;
}
public Builder toBuilder() {
return Builder.fromBillingItemVirtualGuest(this);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (int) (id ^ (id >>> 32));
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
BillingItemVirtualGuest other = (BillingItemVirtualGuest) obj;
if (id != other.id)
return false;
return true;
}
@Override
public String toString() {
return "[id=" + id + "]";
}
}

View File

@ -86,6 +86,8 @@ public class VirtualGuest implements Comparable<VirtualGuest> {
private String primaryBackendIpAddress;
private String primaryIpAddress;
private BillingItemVirtualGuest billingItem;
// for deserializer
VirtualGuest() {
@ -95,7 +97,7 @@ public class VirtualGuest implements Comparable<VirtualGuest> {
String fullyQualifiedDomainName, String hostname, long 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) {
String primaryIpAddress,BillingItemVirtualGuest billingItem) {
this.accountId = accountId;
this.createDate = createDate;
this.dedicatedAccountHostOnly = dedicatedAccountHostOnly;
@ -116,6 +118,7 @@ public class VirtualGuest implements Comparable<VirtualGuest> {
this.uuid = uuid;
this.primaryBackendIpAddress = primaryBackendIpAddress;
this.primaryIpAddress = primaryIpAddress;
this.billingItem = billingItem;
}
@Override
@ -266,6 +269,13 @@ public class VirtualGuest implements Comparable<VirtualGuest> {
return primaryIpAddress;
}
/**
* @return The billing item for a CloudLayer Compute Instance.
*/
public BillingItemVirtualGuest getBillingItem() {
return billingItem;
}
@Override
public int hashCode() {
final int prime = 31;
@ -290,6 +300,7 @@ public class VirtualGuest implements Comparable<VirtualGuest> {
result = prime * result + startCpus;
result = prime * result + statusId;
result = prime * result + ((uuid == null) ? 0 : uuid.hashCode());
result = prime * result + billingItem.hashCode();
return result;
}
@ -378,6 +389,8 @@ public class VirtualGuest implements Comparable<VirtualGuest> {
return false;
} else if (!uuid.equals(other.uuid))
return false;
if (!billingItem.equals(other.billingItem))
return false;
return true;
}

View File

@ -48,7 +48,7 @@ import com.google.common.util.concurrent.ListenableFuture;
@RequestFilters(BasicAuthentication.class)
@Path("/v{jclouds.api-version}")
public interface VirtualGuestAsyncClient {
public static String GUEST_MASK = "powerState;networkVlans;operatingSystem.passwords;datacenter";
public static String GUEST_MASK = "powerState;networkVlans;operatingSystem.passwords;datacenter;virtualGuests.billingItem";
/**
* @see VirtualGuestClient#listVirtualGuests

View File

@ -47,7 +47,7 @@ public class VirtualGuestAsyncClientTest extends BaseSoftLayerAsyncClientTest<Vi
assertRequestLineEquals(
httpRequest,
"GET https://api.softlayer.com/rest/v3/SoftLayer_Account/VirtualGuests.json?objectMask=powerState%3BnetworkVlans%3BoperatingSystem.passwords%3Bdatacenter HTTP/1.1");
"GET https://api.softlayer.com/rest/v3/SoftLayer_Account/VirtualGuests.json?objectMask=powerState%3BnetworkVlans%3BoperatingSystem.passwords%3Bdatacenter%3BvirtualGuests.billingItem HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);
@ -57,7 +57,7 @@ public class VirtualGuestAsyncClientTest extends BaseSoftLayerAsyncClientTest<Vi
assertRequestLineEquals(
httpRequest,
"GET https://api.softlayer.com/rest/v3/SoftLayer_Account/VirtualGuests.json?objectMask=powerState%3BnetworkVlans%3BoperatingSystem.passwords%3Bdatacenter HTTP/1.1");
"GET https://api.softlayer.com/rest/v3/SoftLayer_Account/VirtualGuests.json?objectMask=powerState%3BnetworkVlans%3BoperatingSystem.passwords%3Bdatacenter%3BvirtualGuests.billingItem HTTP/1.1");
// for example, using basic authentication, we should get "only one"
// header
assertNonPayloadHeadersEqual(httpRequest,
@ -78,7 +78,7 @@ public class VirtualGuestAsyncClientTest extends BaseSoftLayerAsyncClientTest<Vi
assertRequestLineEquals(
httpRequest,
"GET https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/1234.json?objectMask=powerState%3BnetworkVlans%3BoperatingSystem.passwords%3Bdatacenter HTTP/1.1");
"GET https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/1234.json?objectMask=powerState%3BnetworkVlans%3BoperatingSystem.passwords%3Bdatacenter%3BvirtualGuests.billingItem HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);

View File

@ -23,6 +23,7 @@ import static org.testng.Assert.assertTrue;
import java.util.Set;
import org.jclouds.softlayer.domain.BillingItemVirtualGuest;
import org.jclouds.softlayer.domain.VirtualGuest;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
@ -71,6 +72,13 @@ public class VirtualGuestClientLiveTest extends BaseSoftLayerClientLiveTest {
assert vg.getUuid() != null : vg;
assert vg.getPrimaryBackendIpAddress() != null : vg;
assert vg.getPrimaryIpAddress() != null : vg;
checkBillingItem(vg.getBillingItem());
}
private void checkBillingItem(BillingItemVirtualGuest billingItem) {
assert null != billingItem;
assert billingItem.getId() > 0 : billingItem;
}
}