mirror of https://github.com/apache/jclouds.git
added better logging to softlayer tests
This commit is contained in:
parent
d5e243f396
commit
98b28d7873
|
@ -36,10 +36,9 @@ 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
|
||||
*/
|
||||
public class ProductOrderToJson implements Binder {
|
||||
|
@ -53,7 +52,7 @@ public class ProductOrderToJson implements Binder {
|
|||
|
||||
@Override
|
||||
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
|
||||
checkNotNull(input,"order");
|
||||
checkNotNull(input, "order");
|
||||
ProductOrder order = ProductOrder.class.cast(input);
|
||||
request.setPayload(buildJson(order));
|
||||
return request;
|
||||
|
@ -61,34 +60,34 @@ 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>() {
|
||||
@Override
|
||||
public Price apply(ProductItemPrice productItemPrice) {
|
||||
return new Price(productItemPrice.getId());
|
||||
}
|
||||
});
|
||||
Iterable<Price> prices = Iterables.transform(order.getPrices(), new Function<ProductItemPrice, Price>() {
|
||||
@Override
|
||||
public Price apply(ProductItemPrice productItemPrice) {
|
||||
return new Price(productItemPrice.getId());
|
||||
}
|
||||
});
|
||||
|
||||
Iterable<HostnameAndDomain> hosts = Iterables.transform(order.getVirtualGuests(),
|
||||
new Function<VirtualGuest,HostnameAndDomain>() {
|
||||
@Override
|
||||
public HostnameAndDomain apply(VirtualGuest virtualGuest) {
|
||||
return new HostnameAndDomain(virtualGuest.getHostname(),virtualGuest.getDomain());
|
||||
}
|
||||
});
|
||||
new Function<VirtualGuest, HostnameAndDomain>() {
|
||||
@Override
|
||||
public HostnameAndDomain apply(VirtualGuest virtualGuest) {
|
||||
return new HostnameAndDomain(virtualGuest.getHostname(), virtualGuest.getDomain());
|
||||
}
|
||||
});
|
||||
|
||||
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)));
|
||||
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,30 +97,31 @@ public class ProductOrderToJson implements Binder {
|
|||
private long quantity;
|
||||
private boolean useHourlyPricing;
|
||||
|
||||
public OrderData( long packageId, String location,
|
||||
Set<Price> prices,Set<HostnameAndDomain> virtualGuests,
|
||||
long quantity, boolean useHourlyPricing ) {
|
||||
public OrderData(long packageId, String location, Set<Price> prices, Set<HostnameAndDomain> virtualGuests,
|
||||
long quantity, boolean useHourlyPricing) {
|
||||
this.packageId = packageId;
|
||||
this.location = location;
|
||||
this.prices = prices;
|
||||
this.virtualGuests = virtualGuests;
|
||||
this.quantity = quantity;
|
||||
this.useHourlyPricing = useHourlyPricing;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static class HostnameAndDomain {
|
||||
private String hostname;
|
||||
private String domain;
|
||||
|
||||
public HostnameAndDomain(String hostname,String domain) {
|
||||
public HostnameAndDomain(String hostname, String domain) {
|
||||
this.hostname = hostname;
|
||||
this.domain = domain;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static class Price {
|
||||
private long id;
|
||||
|
||||
|
|
|
@ -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
|
||||
|
@ -56,7 +59,7 @@ public class VirtualGuestToNodeMetadata implements Function<VirtualGuest, NodeMe
|
|||
|
||||
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)
|
||||
VirtualGuest.State.PAUSED, NodeState.SUSPENDED).put(VirtualGuest.State.RUNNING, NodeState.RUNNING)
|
||||
.put(VirtualGuest.State.UNRECOGNIZED, NodeState.UNRECOGNIZED).build();
|
||||
|
||||
private final Map<String, Credentials> credentialStore;
|
||||
|
@ -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");
|
||||
|
@ -87,13 +88,14 @@ public class VirtualGuestToNodeMetadata implements Function<VirtualGuest, NodeMe
|
|||
builder.group(parseGroupFromName(from.getHostname()));
|
||||
|
||||
Image image = getImageForVirtualGuest.getImage(from);
|
||||
if (image!=null) {
|
||||
if (image != null) {
|
||||
builder.imageId(image.getId());
|
||||
builder.operatingSystem(image.getOperatingSystem());
|
||||
}
|
||||
|
||||
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,13 +138,14 @@ 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());
|
||||
Iterable<ProductItem> items = Iterables.transform(order.getPrices(), ProductItems.item());
|
||||
return new ProductItemsToHardware().apply(Sets.newLinkedHashSet(items));
|
||||
} catch (HttpResponseException e) {
|
||||
//Shouldn't happen any more - was blowing up in Singapore
|
||||
// Shouldn't happen any more - was blowing up in Singapore
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -160,14 +163,15 @@ 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());
|
||||
Iterable<ProductItem> items = Iterables.transform(order.getPrices(), ProductItems.item());
|
||||
ProductItem os = Iterables.find(items, ProductItemPredicates.categoryCode("os"));
|
||||
return new ProductItemToImage().apply(os);
|
||||
} catch (HttpResponseException e) {
|
||||
//Shouldn't happen any more - was blowing up in Singapore
|
||||
// Shouldn't happen any more - was blowing up in Singapore
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
|
@ -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;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
<?xml version="1.0" encoding="UTF-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">
|
||||
debug="false">
|
||||
|
||||
<!-- A time/date based rolling appender -->
|
||||
<appender name="WIREFILE" class="org.apache.log4j.DailyRollingFileAppender">
|
||||
|
@ -19,72 +19,133 @@
|
|||
<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="FILE" class="org.apache.log4j.DailyRollingFileAppender">
|
||||
<param name="File" value="target/test-data/jclouds.log" />
|
||||
<param name="Append" value="true" />
|
||||
<!-- A time/date based rolling appender -->
|
||||
<appender name="FILE" class="org.apache.log4j.DailyRollingFileAppender">
|
||||
<param name="File" value="target/test-data/jclouds.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>
|
||||
|
||||
<!-- Rollover at midnight each day -->
|
||||
<param name="DatePattern" value="'.'yyyy-MM-dd" />
|
||||
<!-- 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>
|
||||
|
||||
<param name="Threshold" value="TRACE" />
|
||||
|
||||
<layout class="org.apache.log4j.PatternLayout">
|
||||
<!-- The default pattern: Date Priority [Category] Message${symbol_escape}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"/>
|
||||
-->
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<appender name="ASYNC" class="org.apache.log4j.AsyncAppender">
|
||||
<appender-ref ref="FILE" />
|
||||
</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>
|
||||
|
||||
<appender name="ASYNCWIRE" class="org.apache.log4j.AsyncAppender">
|
||||
<appender-ref ref="WIREFILE" />
|
||||
</appender>
|
||||
|
||||
<!-- ================ -->
|
||||
<!-- Limit categories -->
|
||||
<!-- ================ -->
|
||||
|
||||
<category name="org.jclouds">
|
||||
<priority value="DEBUG" />
|
||||
</appender>
|
||||
|
||||
<!-- ================ -->
|
||||
<!-- Limit categories -->
|
||||
<!-- ================ -->
|
||||
|
||||
<category name="org.jclouds">
|
||||
<priority value="DEBUG" />
|
||||
<appender-ref ref="ASYNC" />
|
||||
</category>
|
||||
|
||||
</category>
|
||||
|
||||
<category name="jclouds.headers">
|
||||
<priority value="DEBUG" />
|
||||
<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>
|
||||
|
||||
<!-- ======================= -->
|
||||
<!-- Setup the Root category -->
|
||||
<!-- ======================= -->
|
||||
|
||||
<root>
|
||||
<priority value="WARN" />
|
||||
</root>
|
||||
<category name="jclouds.compute">
|
||||
<priority value="TRACE" />
|
||||
<appender-ref ref="ASYNCCOMPUTE" />
|
||||
</category>
|
||||
<!-- ======================= -->
|
||||
<!-- Setup the Root category -->
|
||||
<!-- ======================= -->
|
||||
|
||||
<root>
|
||||
<priority value="WARN" />
|
||||
</root>
|
||||
|
||||
</log4j:configuration>
|
||||
|
|
Loading…
Reference in New Issue