flattened virtualguest.billingItem.id into virtualguest.billingItemId and added test cases for VirtualGuestToNodeMetadata

This commit is contained in:
Adrian Cole 2011-10-02 00:35:01 -07:00
parent 032c1b9246
commit 5d179a6bd8
11 changed files with 322 additions and 223 deletions

View File

@ -59,6 +59,7 @@ public class SoftLayerComputeServiceContextModule extends
@Override
protected void configure() {
super.configure();
install(new SoftLayerParserModule());
bind(new TypeLiteral<ComputeServiceAdapter<VirtualGuest, Set<ProductItem>, ProductItem, Datacenter>>() {})
.to(SoftLayerComputeServiceAdapter.class);
bind(new TypeLiteral<Function<VirtualGuest, NodeMetadata>>() {})

View File

@ -0,0 +1,114 @@
/**
* 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.compute.config;
import java.lang.reflect.Type;
import java.util.Date;
import java.util.Map;
import javax.inject.Singleton;
import org.jclouds.softlayer.domain.Datacenter;
import org.jclouds.softlayer.domain.OperatingSystem;
import org.jclouds.softlayer.domain.PowerState;
import org.jclouds.softlayer.domain.VirtualGuest;
import com.google.common.collect.ImmutableMap;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.google.inject.AbstractModule;
import com.google.inject.TypeLiteral;
/**
*
* @author Adrian Cole
*/
public class SoftLayerParserModule extends AbstractModule {
@Singleton
public static class VirtualGuestAdapter implements JsonSerializer<VirtualGuest>, JsonDeserializer<VirtualGuest> {
public JsonElement serialize(VirtualGuest src, Type typeOfSrc, JsonSerializationContext context) {
return context.serialize(src);
}
public VirtualGuest deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
throws JsonParseException {
return apply(context.<VirtualGuestInternal> deserialize(json, VirtualGuestInternal.class));
}
public VirtualGuest apply(VirtualGuestInternal in) {
return in;
}
/**
* Internal class that flattens billingItem into billingItemId
*/
public static class VirtualGuestInternal extends VirtualGuest {
private BillingItem billingItem;
public VirtualGuestInternal(int accountId, Date createDate, boolean dedicatedAccountHostOnly, String domain,
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, int billingItemId, OperatingSystem operatingSystem, Datacenter datacenter,
PowerState powerState) {
super(accountId, createDate, dedicatedAccountHostOnly, domain, fullyQualifiedDomainName, hostname, id,
lastVerifiedDate, maxCpu, maxCpuUnits, maxMemory, metricPollDate, modifyDate, notes,
privateNetworkOnly, startCpus, statusId, uuid, primaryBackendIpAddress, primaryIpAddress,
billingItemId, operatingSystem, datacenter, powerState);
}
@Override
public int getBillingItemId() {
return billingItem != null ? billingItem.id : -1;
}
}
public static class BillingItem {
private int id = -1;
// for deserializer
BillingItem() {
}
public BillingItem(int id) {
this.id = id;
}
@Override
public String toString() {
return "[id=" + id + "]";
}
}
}
@Override
protected void configure() {
bind(new TypeLiteral<Map<Type, Object>>() {
}).toInstance(ImmutableMap.<Type, Object> of(VirtualGuest.class, new VirtualGuestAdapter()));
}
}

View File

@ -29,8 +29,6 @@ import javax.inject.Singleton;
import org.jclouds.collect.FindResourceInSet;
import org.jclouds.collect.Memoized;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.NodeMetadataBuilder;
import org.jclouds.compute.domain.NodeState;
@ -51,25 +49,18 @@ import com.google.common.collect.ImmutableSet;
public class VirtualGuestToNodeMetadata implements Function<VirtualGuest, NodeMetadata> {
public static final Map<VirtualGuest.State, NodeState> serverStateToNodeState = ImmutableMap
.<VirtualGuest.State, NodeState> builder()
.put(VirtualGuest.State.HALTED, NodeState.PENDING)
.put(VirtualGuest.State.PAUSED, NodeState.SUSPENDED)
.put(VirtualGuest.State.RUNNING, NodeState.RUNNING)
.put(VirtualGuest.State.UNRECOGNIZED, NodeState.UNRECOGNIZED)
.build();
.<VirtualGuest.State, NodeState> builder().put(VirtualGuest.State.HALTED, NodeState.PENDING).put(
VirtualGuest.State.PAUSED, NodeState.SUSPENDED).put(VirtualGuest.State.RUNNING, NodeState.RUNNING)
.put(VirtualGuest.State.UNRECOGNIZED, NodeState.UNRECOGNIZED).build();
private final FindHardwareForVirtualGuest findHardwareForVirtualGuest;
private final FindLocationForVirtualGuest findLocationForVirtualGuest;
private final FindImageForVirtualGuest findImageForVirtualGuest;
private final Map<String, Credentials> credentialStore;
private final FindLocationForVirtualGuest findLocationForVirtualGuest;
@Inject
VirtualGuestToNodeMetadata(Map<String, Credentials> credentialStore, FindHardwareForVirtualGuest findHardwareForVirtualGuest,
FindLocationForVirtualGuest findLocationForVirtualGuest, FindImageForVirtualGuest findImageForVirtualGuest) {
VirtualGuestToNodeMetadata(Map<String, Credentials> credentialStore,
FindLocationForVirtualGuest findLocationForVirtualGuest) {
this.credentialStore = checkNotNull(credentialStore, "credentialStore");
this.findHardwareForVirtualGuest = checkNotNull(findHardwareForVirtualGuest, "findHardwareForVirtualGuest");
this.findLocationForVirtualGuest = checkNotNull(findLocationForVirtualGuest, "findLocationForVirtualGuest");
this.findImageForVirtualGuest = checkNotNull(findImageForVirtualGuest, "findImageForVirtualGuest");
}
@Override
@ -77,67 +68,40 @@ public class VirtualGuestToNodeMetadata implements Function<VirtualGuest, NodeMe
// convert the result object to a jclouds NodeMetadata
NodeMetadataBuilder builder = new NodeMetadataBuilder();
builder.ids(from.getId() + "");
builder.name(from.getNotes());
builder.name(from.getHostname());
builder.location(findLocationForVirtualGuest.apply(from));
builder.group(parseGroupFromName(from.getNotes()));
//TODO determine image id (product price)from virtual guest
// builder.imageId(from.imageId + "");
Image image = findImageForVirtualGuest.apply(from);
if (image != null)
builder.operatingSystem(image.getOperatingSystem());
builder.hardware(findHardwareForVirtualGuest.apply(from));
builder.group(parseGroupFromName(from.getHostname()));
// TODO determine image id (product price)from virtual guest
// builder.imageId(from.imageId + "");
// TODO make operating system from virtual guest
// builder.operatingSystem(OperatingSystem.builder()...);
// TODO make hardware from virtual guest
// builder.hardware(Hardware.builder()...);
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()));
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()));
builder.credentials(credentialStore.get("node#" + from.getId()));
return builder.build();
}
@Singleton
public static class FindHardwareForVirtualGuest extends FindResourceInSet<VirtualGuest, Hardware> {
@Inject
public FindHardwareForVirtualGuest(@Memoized Supplier<Set<? extends Hardware>> hardware) {
super(hardware);
}
@Override
public boolean matches(VirtualGuest from, Hardware input) {
//return input.getProviderId().equals(from.getId() + "");
return false;
}
}
@Singleton
public static class FindImageForVirtualGuest extends FindResourceInSet<VirtualGuest, Image> {
@Inject
public FindImageForVirtualGuest(@Memoized Supplier<Set<? extends Image>> hardware) {
super(hardware);
}
@Override
public boolean matches(VirtualGuest from, Image input) {
// TODO determine the price list from the virtual guest which would have the image in it.
return false;
}
}
@Singleton
public static class FindLocationForVirtualGuest extends FindResourceInSet<VirtualGuest, Location> {
@Inject
public FindLocationForVirtualGuest(@Memoized Supplier<Set<? extends Location>> hardware) {
super(hardware);
public FindLocationForVirtualGuest(@Memoized Supplier<Set<? extends Location>> location) {
super(location);
}
@Override
public boolean matches(VirtualGuest from, Location input) {
Datacenter dc = from.getDatacenter();
if (dc == null) return false;
if (dc == null)
return false;
return input.getId().equals(Integer.toString(dc.getId()));
}
}

View File

@ -196,11 +196,10 @@ public class SoftLayerComputeServiceAdapter implements
if (guest == null)
return;
BillingItemVirtualGuest billingItem = guest.getBillingItem();
if (billingItem == null)
if (guest.getBillingItemId() == -1)
return;
client.getVirtualGuestClient().cancelService(billingItem.getId());
client.getVirtualGuestClient().cancelService(guest.getBillingItemId());
}
@Override

View File

@ -1,101 +0,0 @@
/**
* 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 int id = -1;
public Builder id(int id) {
this.id = id;
return this;
}
public static Builder fromBillingItemVirtualGuest(BillingItemVirtualGuest in) {
return BillingItemVirtualGuest.builder().id(in.getId());
}
}
private int id = -1;
// for deserializer
BillingItemVirtualGuest() {
}
public BillingItemVirtualGuest(int id) {
this.id = id;
}
@Override
public int compareTo(BillingItemVirtualGuest arg0) {
return new Integer(id).compareTo(arg0.getId());
}
/**
* @return The unique identifier for this billing item.
*/
public int getId() {
return id;
}
public Builder toBuilder() {
return Builder.fromBillingItemVirtualGuest(this);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (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

@ -132,6 +132,6 @@ public class OperatingSystem implements Comparable<OperatingSystem> {
@Override
public String toString() {
return "OperatingSystem [id=" + id + ", passwords=" + passwords + "]";
return "[id=" + id + ", passwords=" + passwords + "]";
}
}

View File

@ -74,7 +74,7 @@ public class VirtualGuest implements Comparable<VirtualGuest> {
private String uuid;
private String primaryBackendIpAddress;
private String primaryIpAddress;
private BillingItemVirtualGuest billingItem;
private int billingItemId;
private OperatingSystem operatingSystem;
private Datacenter datacenter;
private PowerState powerState;
@ -179,8 +179,8 @@ public class VirtualGuest implements Comparable<VirtualGuest> {
return this;
}
public Builder billingItem(BillingItemVirtualGuest billingItem) {
this.billingItem = billingItem;
public Builder billingItemId(int billingItemId) {
this.billingItemId = billingItemId;
return this;
}
@ -204,7 +204,7 @@ public class VirtualGuest implements Comparable<VirtualGuest> {
fullyQualifiedDomainName, hostname, id, lastVerifiedDate, maxCpu,
maxCpuUnits, maxMemory, metricPollDate, modifyDate, notes,
privateNetworkOnly, startCpus, statusId, uuid, primaryBackendIpAddress,
primaryIpAddress,billingItem,operatingSystem,datacenter,powerState);
primaryIpAddress, billingItemId,operatingSystem,datacenter,powerState);
}
public static Builder fromVirtualGuest(VirtualGuest in) {
@ -229,7 +229,7 @@ public class VirtualGuest implements Comparable<VirtualGuest> {
.uuid(in.getUuid())
.primaryBackendIpAddress(in.getPrimaryBackendIpAddress())
.primaryIpAddress(in.getPrimaryIpAddress())
.billingItem(in.getBillingItem())
.billingItemId(in.getBillingItemId())
.operatingSystem(in.getOperatingSystem())
.datacenter(in.getDatacenter())
.powerState(in.getPowerState());
@ -283,7 +283,7 @@ public class VirtualGuest implements Comparable<VirtualGuest> {
private String primaryBackendIpAddress;
private String primaryIpAddress;
private BillingItemVirtualGuest billingItem;
private int billingItemId = -1;
private OperatingSystem operatingSystem;
private Datacenter datacenter;
private PowerState powerState;
@ -297,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, Datacenter datacenter, PowerState powerState) {
String primaryIpAddress,int billingItemId, OperatingSystem operatingSystem, Datacenter datacenter, PowerState powerState) {
this.accountId = accountId;
this.createDate = createDate;
this.dedicatedAccountHostOnly = dedicatedAccountHostOnly;
@ -318,7 +318,7 @@ public class VirtualGuest implements Comparable<VirtualGuest> {
this.uuid = uuid;
this.primaryBackendIpAddress = primaryBackendIpAddress;
this.primaryIpAddress = primaryIpAddress;
this.billingItem = billingItem;
this.billingItemId = billingItemId;
this.operatingSystem = operatingSystem;
this.datacenter = datacenter;
this.powerState = powerState;
@ -475,8 +475,8 @@ public class VirtualGuest implements Comparable<VirtualGuest> {
/**
* @return The billing item for a CloudLayer Compute Instance.
*/
public BillingItemVirtualGuest getBillingItem() {
return billingItem;
public int getBillingItemId() {
return billingItemId;
}
/**
@ -525,7 +525,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 == null) ? 0 : billingItem.hashCode());
result = prime * result + (billingItemId ^ (billingItemId >>> 32));
result = prime * result + ((operatingSystem == null) ? 0 : operatingSystem.hashCode());
result = prime * result + ((datacenter == null) ? 0 : datacenter.hashCode());
result = prime * result + ((powerState == null) ? 0 : powerState.hashCode());
@ -617,10 +617,7 @@ public class VirtualGuest implements Comparable<VirtualGuest> {
return false;
} else if (!uuid.equals(other.uuid))
return false;
if (billingItem == null) {
if (other.billingItem != null)
return false;
} else if (!billingItem.equals(other.billingItem))
if (billingItemId != other.billingItemId)
return false;
if (operatingSystem == null) {
if (other.operatingSystem != null)
@ -649,7 +646,7 @@ 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+", datacenter="+datacenter
+ ", uuid=" + uuid + ", billingItemId="+billingItemId+", operatingSystem="+operatingSystem+", datacenter="+datacenter
+ ", powerState="+powerState+"]";
}

View File

@ -28,7 +28,6 @@ import org.jclouds.domain.Location;
import org.jclouds.location.suppliers.JustProvider;
import org.jclouds.softlayer.domain.Address;
import org.jclouds.softlayer.domain.Datacenter;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
@ -41,24 +40,14 @@ import com.google.common.collect.ImmutableSet;
@Test(singleThreaded = true, groups = "unit")
public class DatacenterToLocationTest {
private DatacenterToLocation function;
@BeforeMethod
public void setup() {
function = new DatacenterToLocation(new JustProvider(ImmutableSet.<String>of(), "softlayer", URI.create("foo")));
}
static DatacenterToLocation function = new DatacenterToLocation(new JustProvider(ImmutableSet.<String> of(), "softlayer",
URI.create("foo")));;
@Test
public void testDatacenterToLocation() {
Address address = Address.builder().country("US")
.state("TX")
.description("This is Texas!")
.build();
Address address = Address.builder().country("US").state("TX").description("This is Texas!").build();
Datacenter datacenter = Datacenter.builder().id(1)
.longName("Texas Datacenter")
.locationAddress(address)
.build();
Datacenter datacenter = Datacenter.builder().id(1).longName("Texas Datacenter").locationAddress(address).build();
Location location = function.apply(datacenter);
@ -70,9 +59,7 @@ public class DatacenterToLocationTest {
@Test
public void testGetIso3166CodeNoCountryAndState() {
Datacenter datacenter = Datacenter.builder().id(1)
.longName("Nowhere")
.build();
Datacenter datacenter = Datacenter.builder().id(1).longName("Nowhere").build();
Location location = function.apply(datacenter);
@ -83,14 +70,9 @@ public class DatacenterToLocationTest {
@Test
public void testGetIso3166CodeCountryOnly() {
Address address = Address.builder().country("US")
.description("This is North America!")
.build();
Address address = Address.builder().country("US").description("This is North America!").build();
Datacenter datacenter = Datacenter.builder().id(1)
.longName("Nowhere")
.locationAddress(address)
.build();
Datacenter datacenter = Datacenter.builder().id(1).longName("Nowhere").locationAddress(address).build();
Location location = function.apply(datacenter);
@ -102,15 +84,10 @@ public class DatacenterToLocationTest {
@Test
public void testGetIso3166CodeWhitespaceTrimmer() {
Address address = Address.builder().country(" US ")
.state(" TX ")
.description("This is spaced out Texas")
.build();
Address address = Address.builder().country(" US ").state(" TX ").description("This is spaced out Texas")
.build();
Datacenter datacenter = Datacenter.builder().id(1)
.longName("Nowhere")
.locationAddress(address)
.build();
Datacenter datacenter = Datacenter.builder().id(1).longName("Nowhere").locationAddress(address).build();
Location location = function.apply(datacenter);

View File

@ -0,0 +1,75 @@
/**
* 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.compute.functions;
import static org.testng.Assert.assertEquals;
import java.net.UnknownHostException;
import java.util.Map;
import java.util.Set;
import org.jclouds.compute.domain.NodeMetadata;
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.compute.functions.VirtualGuestToNodeMetadata.FindLocationForVirtualGuest;
import org.jclouds.softlayer.domain.VirtualGuest;
import org.jclouds.softlayer.parse.ParseVirtualGuestWithNoPasswordTest;
import org.testng.annotations.Test;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
/**
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "VirtualGuestToNodeMetadataTest")
public class VirtualGuestToNodeMetadataTest {
@Test
public void testApplyWhereVirtualGuestWithNoPassword() throws UnknownHostException {
// notice if we've already parsed this properly here, we can rely on it.
VirtualGuest guest = new ParseVirtualGuestWithNoPasswordTest().expected();
// note we are testing when no credentials are here. otherwise would be ("node#416696", new
// Credentials("root", "password"))
Map<String, Credentials> credentialStore = ImmutableMap.<String, Credentials> of();
// setup so that we have an expected Location to be parsed from the guest.
Location expectedLocation = DatacenterToLocationTest.function.apply(guest.getDatacenter());
Supplier<Set<? extends Location>> locationSupplier = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
.<Location> of(expectedLocation));
VirtualGuestToNodeMetadata parser = new VirtualGuestToNodeMetadata(credentialStore,
new FindLocationForVirtualGuest(locationSupplier));
NodeMetadata node = parser.apply(guest);
assertEquals(node, new NodeMetadataBuilder().ids("416696").name("node-246105155").group("node").location(
expectedLocation).state(NodeState.PENDING).publicAddresses(ImmutableSet.of("173.192.29.186"))
.privateAddresses(ImmutableSet.of("10.37.102.194")).build());
// because it wasn't present in the credential store.
assertEquals(node.getCredentials(), null);
}
}

View File

@ -73,9 +73,8 @@ public class VirtualGuestClientLiveTest extends BaseSoftLayerClientLiveTest {
// objectMask: virtualGuests.activeTransaction
for( VirtualGuest guest: client.listVirtualGuests()) {
if (guest.getHostname().startsWith(TEST_HOSTNAME_PREFIX)) {
BillingItemVirtualGuest billingItem = guest.getBillingItem();
if(billingItem!=null) {
client.cancelService(billingItem.getId());
if(guest.getBillingItemId()!=-1) {
client.cancelService(guest.getBillingItemId());
}
}
}
@ -125,8 +124,7 @@ public class VirtualGuestClientLiveTest extends BaseSoftLayerClientLiveTest {
private void checkVirtualGuest(VirtualGuest vg) {
if (vg.getBillingItem()==null) return;//Quotes and shutting down guests
checkBillingItem(vg.getBillingItem());
if (vg.getBillingItemId()==-1) return;//Quotes and shutting down guests
assert vg.getAccountId() > 0 : vg;
assert vg.getCreateDate() != null : vg;
@ -146,9 +144,4 @@ public class VirtualGuestClientLiveTest extends BaseSoftLayerClientLiveTest {
assert vg.getPrimaryIpAddress() != null : vg;
}
private void checkBillingItem(BillingItemVirtualGuest billingItem) {
assert null != billingItem;
assert billingItem.getId() > 0 : billingItem;
}
}

View File

@ -0,0 +1,80 @@
/**
* 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.parse;
import javax.ws.rs.Consumes;
import javax.ws.rs.core.MediaType;
import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.json.BaseItemParserTest;
import org.jclouds.json.config.GsonModule;
import org.jclouds.softlayer.compute.config.SoftLayerParserModule;
import org.jclouds.softlayer.domain.Datacenter;
import org.jclouds.softlayer.domain.OperatingSystem;
import org.jclouds.softlayer.domain.PowerState;
import org.jclouds.softlayer.domain.VirtualGuest;
import org.testng.annotations.Test;
import com.google.inject.Guice;
import com.google.inject.Injector;
/**
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "ParseVirtualGuestWithNoPasswordTest")
public class ParseVirtualGuestWithNoPasswordTest extends BaseItemParserTest<VirtualGuest> {
@Override
public String resource() {
return "/virtual_guest_no_password.json";
}
@Override
@Consumes(MediaType.APPLICATION_JSON)
public VirtualGuest expected() {
return VirtualGuest
.builder()
//TODO: why is there no billingItem in the json?
.id(416696).accountId(93750).billingItemId(0)
.createDate(new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-10-01T11:10:16-08:00"))
.dedicatedAccountHostOnly(true).domain("me.org").fullyQualifiedDomainName("node-246105155.me.org")
.hostname("node-246105155").maxCpu(1).maxCpuUnits("CORE").maxMemory(1024)
.modifyDate(new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-10-01T11:11:31-08:00"))
.primaryBackendIpAddress("10.37.102.194").primaryIpAddress("173.192.29.186").startCpus(1).statusId(1001)
.uuid("694d34c3-9c36-b590-4ba7-4ec58954b9dc")
.operatingSystem(OperatingSystem.builder().id(913812).build())
.datacenter(Datacenter.builder().id(3).name("dal01").longName("Dallas").build())
//TODO: maybe powerState can be flattened like billingItemId
.powerState(new PowerState(VirtualGuest.State.HALTED)).build();
}
protected Injector injector() {
return Guice.createInjector(new SoftLayerParserModule(), new GsonModule() {
@Override
protected void configure() {
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
super.configure();
}
});
}
}