mirror of https://github.com/apache/jclouds.git
Issue 158: Adding BillingItemVirtualGuest so the node can be shut down
This commit is contained in:
parent
aed4e72e49
commit
def43f2e67
|
@ -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 + "]";
|
||||||
|
}
|
||||||
|
}
|
|
@ -86,6 +86,8 @@ public class VirtualGuest implements Comparable<VirtualGuest> {
|
||||||
private String primaryBackendIpAddress;
|
private String primaryBackendIpAddress;
|
||||||
private String primaryIpAddress;
|
private String primaryIpAddress;
|
||||||
|
|
||||||
|
private BillingItemVirtualGuest billingItem;
|
||||||
|
|
||||||
// for deserializer
|
// for deserializer
|
||||||
VirtualGuest() {
|
VirtualGuest() {
|
||||||
|
|
||||||
|
@ -95,7 +97,7 @@ public class VirtualGuest implements Comparable<VirtualGuest> {
|
||||||
String fullyQualifiedDomainName, String hostname, long id, Date lastVerifiedDate, int maxCpu,
|
String fullyQualifiedDomainName, String hostname, long id, Date lastVerifiedDate, int maxCpu,
|
||||||
String maxCpuUnits, int maxMemory, Date metricPollDate, Date modifyDate, String notes,
|
String maxCpuUnits, int maxMemory, Date metricPollDate, Date modifyDate, String notes,
|
||||||
boolean privateNetworkOnly, int startCpus, int statusId, String uuid, String primaryBackendIpAddress,
|
boolean privateNetworkOnly, int startCpus, int statusId, String uuid, String primaryBackendIpAddress,
|
||||||
String primaryIpAddress) {
|
String primaryIpAddress,BillingItemVirtualGuest billingItem) {
|
||||||
this.accountId = accountId;
|
this.accountId = accountId;
|
||||||
this.createDate = createDate;
|
this.createDate = createDate;
|
||||||
this.dedicatedAccountHostOnly = dedicatedAccountHostOnly;
|
this.dedicatedAccountHostOnly = dedicatedAccountHostOnly;
|
||||||
|
@ -116,6 +118,7 @@ public class VirtualGuest implements Comparable<VirtualGuest> {
|
||||||
this.uuid = uuid;
|
this.uuid = uuid;
|
||||||
this.primaryBackendIpAddress = primaryBackendIpAddress;
|
this.primaryBackendIpAddress = primaryBackendIpAddress;
|
||||||
this.primaryIpAddress = primaryIpAddress;
|
this.primaryIpAddress = primaryIpAddress;
|
||||||
|
this.billingItem = billingItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -266,6 +269,13 @@ public class VirtualGuest implements Comparable<VirtualGuest> {
|
||||||
return primaryIpAddress;
|
return primaryIpAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The billing item for a CloudLayer Compute Instance.
|
||||||
|
*/
|
||||||
|
public BillingItemVirtualGuest getBillingItem() {
|
||||||
|
return billingItem;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
final int prime = 31;
|
final int prime = 31;
|
||||||
|
@ -290,6 +300,7 @@ public class VirtualGuest implements Comparable<VirtualGuest> {
|
||||||
result = prime * result + startCpus;
|
result = prime * result + startCpus;
|
||||||
result = prime * result + statusId;
|
result = prime * result + statusId;
|
||||||
result = prime * result + ((uuid == null) ? 0 : uuid.hashCode());
|
result = prime * result + ((uuid == null) ? 0 : uuid.hashCode());
|
||||||
|
result = prime * result + billingItem.hashCode();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -378,6 +389,8 @@ public class VirtualGuest implements Comparable<VirtualGuest> {
|
||||||
return false;
|
return false;
|
||||||
} else if (!uuid.equals(other.uuid))
|
} else if (!uuid.equals(other.uuid))
|
||||||
return false;
|
return false;
|
||||||
|
if (!billingItem.equals(other.billingItem))
|
||||||
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ import com.google.common.util.concurrent.ListenableFuture;
|
||||||
@RequestFilters(BasicAuthentication.class)
|
@RequestFilters(BasicAuthentication.class)
|
||||||
@Path("/v{jclouds.api-version}")
|
@Path("/v{jclouds.api-version}")
|
||||||
public interface VirtualGuestAsyncClient {
|
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
|
* @see VirtualGuestClient#listVirtualGuests
|
||||||
|
|
|
@ -47,7 +47,7 @@ public class VirtualGuestAsyncClientTest extends BaseSoftLayerAsyncClientTest<Vi
|
||||||
|
|
||||||
assertRequestLineEquals(
|
assertRequestLineEquals(
|
||||||
httpRequest,
|
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");
|
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||||
assertPayloadEquals(httpRequest, null, null, false);
|
assertPayloadEquals(httpRequest, null, null, false);
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ public class VirtualGuestAsyncClientTest extends BaseSoftLayerAsyncClientTest<Vi
|
||||||
|
|
||||||
assertRequestLineEquals(
|
assertRequestLineEquals(
|
||||||
httpRequest,
|
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"
|
// for example, using basic authentication, we should get "only one"
|
||||||
// header
|
// header
|
||||||
assertNonPayloadHeadersEqual(httpRequest,
|
assertNonPayloadHeadersEqual(httpRequest,
|
||||||
|
@ -78,7 +78,7 @@ public class VirtualGuestAsyncClientTest extends BaseSoftLayerAsyncClientTest<Vi
|
||||||
|
|
||||||
assertRequestLineEquals(
|
assertRequestLineEquals(
|
||||||
httpRequest,
|
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");
|
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||||
assertPayloadEquals(httpRequest, null, null, false);
|
assertPayloadEquals(httpRequest, null, null, false);
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@ import static org.testng.Assert.assertTrue;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.jclouds.softlayer.domain.BillingItemVirtualGuest;
|
||||||
import org.jclouds.softlayer.domain.VirtualGuest;
|
import org.jclouds.softlayer.domain.VirtualGuest;
|
||||||
import org.testng.annotations.BeforeGroups;
|
import org.testng.annotations.BeforeGroups;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
@ -71,6 +72,13 @@ public class VirtualGuestClientLiveTest extends BaseSoftLayerClientLiveTest {
|
||||||
assert vg.getUuid() != null : vg;
|
assert vg.getUuid() != null : vg;
|
||||||
assert vg.getPrimaryBackendIpAddress() != null : vg;
|
assert vg.getPrimaryBackendIpAddress() != null : vg;
|
||||||
assert vg.getPrimaryIpAddress() != null : vg;
|
assert vg.getPrimaryIpAddress() != null : vg;
|
||||||
|
|
||||||
|
checkBillingItem(vg.getBillingItem());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkBillingItem(BillingItemVirtualGuest billingItem) {
|
||||||
|
assert null != billingItem;
|
||||||
|
assert billingItem.getId() > 0 : billingItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue