Issue 77: added log4j to rackspace

git-svn-id: http://jclouds.googlecode.com/svn/trunk@1637 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
adrian.f.cole 2009-07-17 15:19:41 +00:00
parent 3fd5333732
commit 2d68a4e748
3 changed files with 107 additions and 12 deletions

View File

@ -32,6 +32,8 @@ import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.util.DateService;
import org.joda.time.DateTime;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
@ -59,6 +61,21 @@ public class ParserModule extends AbstractModule {
private final static TypeLiteral<ParseSax.Factory> parseSaxFactoryLiteral = new TypeLiteral<ParseSax.Factory>() {
};
static class DateTimeAdapter implements JsonSerializer<DateTime>, JsonDeserializer<DateTime> {
private final static DateService dateService = new DateService();
public JsonElement serialize(DateTime src, Type typeOfSrc, JsonSerializationContext context) {
return new JsonPrimitive(dateService.iso8601DateFormat(src));
}
public DateTime deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
throws JsonParseException {
String toParse = json.getAsJsonPrimitive().getAsString();
return dateService.iso8601DateParse(toParse);
}
}
static class InetAddressAdapter implements JsonSerializer<InetAddress>,
JsonDeserializer<InetAddress> {
public JsonElement serialize(InetAddress src, Type typeOfSrc, JsonSerializationContext context) {
@ -98,6 +115,7 @@ public class ParserModule extends AbstractModule {
Gson provideGson() {
GsonBuilder gson = new GsonBuilder();
gson.registerTypeAdapter(InetAddress.class, new InetAddressAdapter());
gson.registerTypeAdapter(DateTime.class, new DateTimeAdapter());
return gson.create();
}

View File

@ -29,9 +29,11 @@ import static org.testng.Assert.assertTrue;
import java.util.List;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.rackspace.cloudservers.domain.Flavor;
import org.jclouds.rackspace.cloudservers.domain.Image;
import org.jclouds.rackspace.cloudservers.domain.Server;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
/**
@ -44,11 +46,17 @@ public class CloudServersConnectionLiveTest {
protected static final String sysRackspaceUser = System.getProperty(PROPERTY_RACKSPACE_USER);
protected static final String sysRackspaceKey = System.getProperty(PROPERTY_RACKSPACE_KEY);
CloudServersConnection connection;
@BeforeGroups(groups = { "live" })
public void setupConnection() {
connection = CloudServersContextBuilder.newBuilder(sysRackspaceUser, sysRackspaceKey)
.withModule(new Log4JLoggingModule()).withJsonDebug().buildContext().getConnection();
}
@Test
public void testListServers() throws Exception {
CloudServersConnection connection = CloudServersContextBuilder.newBuilder(sysRackspaceUser,
sysRackspaceKey).withJsonDebug().buildContext().getConnection();
List<Server> response = connection.listServers();
assert null != response;
long initialContainerCount = response.size();
@ -58,8 +66,6 @@ public class CloudServersConnectionLiveTest {
@Test
public void testListServersDetail() throws Exception {
CloudServersConnection connection = CloudServersContextBuilder.newBuilder(sysRackspaceUser,
sysRackspaceKey).withJsonDebug().buildContext().getConnection();
List<Server> response = connection.listServerDetails();
assert null != response;
long initialContainerCount = response.size();
@ -68,8 +74,6 @@ public class CloudServersConnectionLiveTest {
@Test
public void testListFlavors() throws Exception {
CloudServersConnection connection = CloudServersContextBuilder.newBuilder(sysRackspaceUser,
sysRackspaceKey).withJsonDebug().buildContext().getConnection();
List<Flavor> response = connection.listFlavors();
assert null != response;
long flavorCount = response.size();
@ -83,8 +87,6 @@ public class CloudServersConnectionLiveTest {
@Test
public void testListFlavorsDetail() throws Exception {
CloudServersConnection connection = CloudServersContextBuilder.newBuilder(sysRackspaceUser,
sysRackspaceKey).withJsonDebug().buildContext().getConnection();
List<Flavor> response = connection.listFlavorDetails();
assert null != response;
long flavorCount = response.size();
@ -99,8 +101,6 @@ public class CloudServersConnectionLiveTest {
@Test
public void testListImages() throws Exception {
CloudServersConnection connection = CloudServersContextBuilder.newBuilder(sysRackspaceUser,
sysRackspaceKey).withJsonDebug().buildContext().getConnection();
List<Image> response = connection.listImages();
assert null != response;
long imageCount = response.size();
@ -114,8 +114,6 @@ public class CloudServersConnectionLiveTest {
@Test
public void testListImagesDetail() throws Exception {
CloudServersConnection connection = CloudServersContextBuilder.newBuilder(sysRackspaceUser,
sysRackspaceKey).withJsonDebug().buildContext().getConnection();
List<Image> response = connection.listImageDetails();
assert null != response;
long imageCount = response.size();

View File

@ -0,0 +1,79 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.com>
====================================================================
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF 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.
====================================================================
-->
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<!--
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">
<!-- 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>
<appender name="ASYNC" class="org.apache.log4j.AsyncAppender">
<appender-ref ref="FILE" />
</appender>
<!-- ================ -->
<!-- Limit categories -->
<!-- ================ -->
<category name="org.jclouds">
<priority value="TRACE" />
</category>
<!-- ======================= -->
<!-- Setup the Root category -->
<!-- ======================= -->
<root>
<priority value="WARN" />
<appender-ref ref="ASYNC" />
</root>
</log4j:configuration>