added better logging to softlayer tests

This commit is contained in:
Adrian Cole 2011-10-03 16:36:49 -07:00
parent d5e243f396
commit 98b28d7873
5 changed files with 163 additions and 104 deletions

View File

@ -36,9 +36,8 @@ import java.util.Set;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Converts a ProductOrder into a json string
* valid for placing an order via the softlayer api
* The String is set into the payload of the HttpRequest
* Converts a ProductOrder into a json string valid for placing an order via the softlayer api The
* String is set into the payload of the HttpRequest
*
* @author Jason King
*/
@ -61,13 +60,13 @@ public class ProductOrderToJson implements Binder {
/**
* Builds a Json string suitable for sending to the softlayer api
*
* @param order
* @return
*/
String buildJson(ProductOrder order) {
Iterable<Price> prices = Iterables.transform(order.getPrices(),
new Function<ProductItemPrice,Price>() {
Iterable<Price> prices = Iterables.transform(order.getPrices(), new Function<ProductItemPrice, Price>() {
@Override
public Price apply(ProductItemPrice productItemPrice) {
return new Price(productItemPrice.getId());
@ -82,13 +81,13 @@ public class ProductOrderToJson implements Binder {
}
});
OrderData data = new OrderData(order.getPackageId(),order.getLocation(),
Sets.newLinkedHashSet(prices),Sets.newLinkedHashSet(hosts),
order.getQuantity(),order.getUseHourlyPricing());
OrderData data = new OrderData(order.getPackageId(), order.getLocation(), Sets.newLinkedHashSet(prices), Sets
.newLinkedHashSet(hosts), order.getQuantity(), order.getUseHourlyPricing());
return json.toJson(ImmutableMap.of("parameters", ImmutableList.<OrderData> of(data)));
}
@SuppressWarnings("unused")
private static class OrderData {
private String complexType = "SoftLayer_Container_Product_Order_Virtual_Guest";
private long packageId = -1;
@ -98,8 +97,7 @@ public class ProductOrderToJson implements Binder {
private long quantity;
private boolean useHourlyPricing;
public OrderData( long packageId, String location,
Set<Price> prices,Set<HostnameAndDomain> virtualGuests,
public OrderData(long packageId, String location, Set<Price> prices, Set<HostnameAndDomain> virtualGuests,
long quantity, boolean useHourlyPricing) {
this.packageId = packageId;
this.location = location;
@ -107,10 +105,11 @@ public class ProductOrderToJson implements Binder {
this.virtualGuests = virtualGuests;
this.quantity = quantity;
this.useHourlyPricing = useHourlyPricing;
}
}
}
@SuppressWarnings("unused")
private static class HostnameAndDomain {
private String hostname;
private String domain;
@ -122,6 +121,7 @@ public class ProductOrderToJson implements Binder {
}
@SuppressWarnings("unused")
private static class Price {
private long id;

View File

@ -20,7 +20,6 @@ package org.jclouds.softlayer.compute.functions;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.compute.util.ComputeServiceUtils.parseGroupFromName;
import static org.jclouds.softlayer.compute.functions.ProductItemsToHardware.CORE_SPEED;
import java.util.Map;
import java.util.Set;
@ -28,11 +27,13 @@ import java.util.Set;
import javax.inject.Inject;
import javax.inject.Singleton;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
import org.jclouds.collect.FindResourceInSet;
import org.jclouds.collect.Memoized;
import org.jclouds.compute.domain.*;
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;
import org.jclouds.domain.Credentials;
import org.jclouds.domain.Location;
import org.jclouds.http.HttpResponseException;
@ -41,12 +42,14 @@ import org.jclouds.softlayer.domain.Datacenter;
import org.jclouds.softlayer.domain.ProductItem;
import org.jclouds.softlayer.domain.ProductOrder;
import org.jclouds.softlayer.domain.VirtualGuest;
import org.jclouds.softlayer.predicates.ProductItemPredicates;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import org.jclouds.softlayer.predicates.ProductItemPredicates;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
/**
* @author Adrian Cole
@ -67,9 +70,7 @@ public class VirtualGuestToNodeMetadata implements Function<VirtualGuest, NodeMe
@Inject
VirtualGuestToNodeMetadata(Map<String, Credentials> credentialStore,
FindLocationForVirtualGuest findLocationForVirtualGuest,
GetHardwareForVirtualGuest getHardwareForVirtualGuest,
GetImageForVirtualGuest getImageForVirtualGuest
) {
GetHardwareForVirtualGuest getHardwareForVirtualGuest, GetImageForVirtualGuest getImageForVirtualGuest) {
this.credentialStore = checkNotNull(credentialStore, "credentialStore");
this.findLocationForVirtualGuest = checkNotNull(findLocationForVirtualGuest, "findLocationForVirtualGuest");
this.getHardwareForVirtualGuest = checkNotNull(getHardwareForVirtualGuest, "getHardwareForVirtualGuest");
@ -93,7 +94,8 @@ public class VirtualGuestToNodeMetadata implements Function<VirtualGuest, NodeMe
}
Hardware hardware = getHardwareForVirtualGuest.getHardware(from);
if (hardware!=null) builder.hardware(hardware);
if (hardware != null)
builder.hardware(hardware);
builder.state(serverStateToNodeState.get(from.getPowerState().getKeyName()));
@ -136,7 +138,8 @@ public class VirtualGuestToNodeMetadata implements Function<VirtualGuest, NodeMe
public Hardware getHardware(VirtualGuest guest) {
// 'bad' orders have no start cpu's and cause the order lookup to fail.
if (guest.getStartCpus()<1) return null;
if (guest.getStartCpus() < 1)
return null;
try {
ProductOrder order = client.getVirtualGuestClient().getOrderTemplate(guest.getId());
Iterable<ProductItem> items = Iterables.transform(order.getPrices(), ProductItems.item());
@ -160,7 +163,8 @@ public class VirtualGuestToNodeMetadata implements Function<VirtualGuest, NodeMe
public Image getImage(VirtualGuest guest) {
// 'bad' orders have no start cpu's and cause the order lookup to fail.
if (guest.getStartCpus()<1) return null;
if (guest.getStartCpus() < 1)
return null;
try {
ProductOrder order = client.getVirtualGuestClient().getOrderTemplate(guest.getId());
Iterable<ProductItem> items = Iterables.transform(order.getPrices(), ProductItems.item());

View File

@ -18,13 +18,12 @@
*/
package org.jclouds.softlayer.domain;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Set;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Strings.emptyToNull;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
/**
*

View File

@ -18,20 +18,15 @@
*/
package org.jclouds.softlayer.compute;
import com.google.inject.Module;
import org.jclouds.compute.BaseComputeServiceLiveTest;
import org.jclouds.compute.ComputeServiceContextFactory;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.domain.LocationScope;
import org.jclouds.rest.RestContext;
import org.jclouds.softlayer.SoftLayerAsyncClient;
import org.jclouds.softlayer.SoftLayerClient;
import org.jclouds.sshj.config.SshjSshClientModule;
import org.testng.annotations.Test;
import java.io.IOException;
import static org.testng.Assert.assertEquals;
import com.google.inject.Module;
/**
*

View File

@ -2,8 +2,8 @@
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<!--
For more configuration infromation and examples see the Apache Log4j
website: http://logging.apache.org/log4j/
For more configuration infromation and examples see the Apache
Log4j website: http://logging.apache.org/log4j/
-->
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"
debug="false">
@ -19,13 +19,13 @@
<param name="Threshold" value="TRACE" />
<layout class="org.apache.log4j.PatternLayout">
<!-- The default pattern: Date Priority [Category] Message${symbol_escape}n -->
<!-- The default pattern: Date Priority [Category] Message\n -->
<param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />
<!--
The full pattern: Date MS Priority [Category] (Thread:NDC) Message${symbol_escape}n
<param name="ConversionPattern" value="%d %-5r %-5p [%c] (%t:%x)
%m%n"/>
The full pattern: Date MS Priority [Category]
(Thread:NDC) Message\n <param name="ConversionPattern"
value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
-->
</layout>
</appender>
@ -41,17 +41,69 @@
<param name="Threshold" value="TRACE" />
<layout class="org.apache.log4j.PatternLayout">
<!-- The default pattern: Date Priority [Category] Message${symbol_escape}n -->
<!-- The default pattern: Date Priority [Category] Message\n -->
<param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />
<!--
The full pattern: Date MS Priority [Category] (Thread:NDC) Message${symbol_escape}n
<param name="ConversionPattern" value="%d %-5r %-5p [%c] (%t:%x)
%m%n"/>
The full pattern: Date MS Priority [Category]
(Thread:NDC) Message\n <param name="ConversionPattern"
value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
-->
</layout>
</appender>
<!-- A time/date based rolling appender -->
<appender name="COMPUTEFILE" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="target/test-data/jclouds-compute.log" />
<param name="Append" value="true" />
<!-- Rollover at midnight each day -->
<param name="DatePattern" value="'.'yyyy-MM-dd" />
<param name="Threshold" value="TRACE" />
<layout class="org.apache.log4j.PatternLayout">
<!-- The default pattern: Date Priority [Category] Message\n -->
<param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />
<!--
The full pattern: Date MS Priority [Category]
(Thread:NDC) Message\n <param name="ConversionPattern"
value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
-->
</layout>
</appender>
<!-- A time/date based rolling appender -->
<appender name="SSHFILE" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="target/test-data/jclouds-ssh.log" />
<param name="Append" value="true" />
<!-- Rollover at midnight each day -->
<param name="DatePattern" value="'.'yyyy-MM-dd" />
<param name="Threshold" value="TRACE" />
<layout class="org.apache.log4j.PatternLayout">
<!-- The default pattern: Date Priority [Category] Message\n -->
<param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />
<!--
The full pattern: Date MS Priority [Category]
(Thread:NDC) Message\n <param name="ConversionPattern"
value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
-->
</layout>
</appender>
<appender name="ASYNCCOMPUTE" class="org.apache.log4j.AsyncAppender">
<appender-ref ref="COMPUTEFILE" />
</appender>
<appender name="ASYNCSSH" class="org.apache.log4j.AsyncAppender">
<appender-ref ref="SSHFILE" />
</appender>
<appender name="ASYNC" class="org.apache.log4j.AsyncAppender">
<appender-ref ref="FILE" />
</appender>
@ -74,11 +126,20 @@
<appender-ref ref="ASYNCWIRE" />
</category>
<category name="jclouds.ssh">
<priority value="DEBUG" />
<appender-ref ref="ASYNCSSH" />
</category>
<category name="jclouds.wire">
<priority value="DEBUG" />
<appender-ref ref="ASYNCWIRE" />
</category>
<category name="jclouds.compute">
<priority value="TRACE" />
<appender-ref ref="ASYNCCOMPUTE" />
</category>
<!-- ======================= -->
<!-- Setup the Root category -->
<!-- ======================= -->