fixed rest parser module in softlayer, as it wasn't applied at the correct context (rest not compute)

This commit is contained in:
Adrian Cole 2011-10-03 22:08:47 -07:00
parent 68e2f417f8
commit 007ebc693e
9 changed files with 77 additions and 100 deletions

View File

@ -36,7 +36,6 @@ import org.jclouds.softlayer.compute.functions.ProductItemsToHardware;
import org.jclouds.softlayer.compute.functions.VirtualGuestToNodeMetadata;
import org.jclouds.softlayer.compute.options.SoftLayerTemplateOptions;
import org.jclouds.softlayer.compute.strategy.SoftLayerComputeServiceAdapter;
import org.jclouds.softlayer.config.SoftLayerParserModule;
import org.jclouds.softlayer.domain.Datacenter;
import org.jclouds.softlayer.domain.ProductItem;
import org.jclouds.softlayer.domain.VirtualGuest;
@ -60,7 +59,6 @@ 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>>() {})
@ -83,4 +81,4 @@ public class SoftLayerComputeServiceContextModule extends
.osDescriptionMatches(".*Minimal Install.*")
.minCores(2);
}
}
}

View File

@ -24,6 +24,8 @@ import java.util.Map;
import javax.inject.Singleton;
import org.jclouds.json.config.GsonModule.DateAdapter;
import org.jclouds.json.config.GsonModule.Iso8601DateAdapter;
import org.jclouds.softlayer.domain.Datacenter;
import org.jclouds.softlayer.domain.OperatingSystem;
import org.jclouds.softlayer.domain.PowerState;
@ -37,7 +39,7 @@ 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;
import com.google.inject.Provides;
/**
*
@ -105,10 +107,15 @@ public class SoftLayerParserModule extends AbstractModule {
}
}
@Provides
@Singleton
public Map<Type, Object> provideCustomAdapterBindings() {
return ImmutableMap.<Type, Object> of(VirtualGuest.class, new VirtualGuestAdapter());
}
@Override
protected void configure() {
bind(new TypeLiteral<Map<Type, Object>>() {
}).toInstance(ImmutableMap.<Type, Object> of(VirtualGuest.class, new VirtualGuestAdapter()));
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
}
}

View File

@ -18,7 +18,8 @@
*/
package org.jclouds.softlayer.config;
import com.google.common.collect.ImmutableMap;
import java.util.Map;
import org.jclouds.http.HttpErrorHandler;
import org.jclouds.http.HttpRetryHandler;
import org.jclouds.http.RequiresHttp;
@ -26,16 +27,21 @@ import org.jclouds.http.annotation.ClientError;
import org.jclouds.http.annotation.Redirection;
import org.jclouds.http.annotation.ServerError;
import org.jclouds.http.handlers.BackoffLimitedRetryHandler;
import org.jclouds.json.config.GsonModule.DateAdapter;
import org.jclouds.json.config.GsonModule.Iso8601DateAdapter;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.config.RestClientModule;
import org.jclouds.softlayer.SoftLayerAsyncClient;
import org.jclouds.softlayer.SoftLayerClient;
import org.jclouds.softlayer.features.*;
import org.jclouds.softlayer.features.AccountAsyncClient;
import org.jclouds.softlayer.features.AccountClient;
import org.jclouds.softlayer.features.DatacenterAsyncClient;
import org.jclouds.softlayer.features.DatacenterClient;
import org.jclouds.softlayer.features.ProductPackageAsyncClient;
import org.jclouds.softlayer.features.ProductPackageClient;
import org.jclouds.softlayer.features.VirtualGuestAsyncClient;
import org.jclouds.softlayer.features.VirtualGuestClient;
import org.jclouds.softlayer.handlers.SoftLayerErrorHandler;
import java.util.Map;
import com.google.common.collect.ImmutableMap;
/**
* Configures the SoftLayer connection.
@ -47,11 +53,11 @@ import java.util.Map;
public class SoftLayerRestClientModule extends RestClientModule<SoftLayerClient, SoftLayerAsyncClient> {
public static final Map<Class<?>, Class<?>> DELEGATE_MAP = ImmutableMap.<Class<?>, Class<?>> builder()//
.put(VirtualGuestClient.class, VirtualGuestAsyncClient.class)//
.put(DatacenterClient.class, DatacenterAsyncClient.class)//
.put(ProductPackageClient.class, ProductPackageAsyncClient.class)//
.put(AccountClient.class, AccountAsyncClient.class)//
.build();
.put(VirtualGuestClient.class, VirtualGuestAsyncClient.class)//
.put(DatacenterClient.class, DatacenterAsyncClient.class)//
.put(ProductPackageClient.class, ProductPackageAsyncClient.class)//
.put(AccountClient.class, AccountAsyncClient.class)//
.build();
public SoftLayerRestClientModule() {
super(SoftLayerClient.class, SoftLayerAsyncClient.class, DELEGATE_MAP);
@ -59,7 +65,7 @@ public class SoftLayerRestClientModule extends RestClientModule<SoftLayerClient,
@Override
protected void configure() {
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
install(new SoftLayerParserModule());
super.configure();
}

View File

@ -18,8 +18,9 @@
*/
package org.jclouds.softlayer.parse;
import com.google.inject.Guice;
import com.google.inject.Injector;
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;
@ -28,8 +29,8 @@ import org.jclouds.softlayer.domain.PowerState;
import org.jclouds.softlayer.domain.VirtualGuest;
import org.testng.annotations.Test;
import javax.ws.rs.Consumes;
import javax.ws.rs.core.MediaType;
import com.google.inject.Guice;
import com.google.inject.Injector;
/**
*
@ -58,15 +59,7 @@ public class ParseBadVirtualGuest extends BaseItemParserTest<VirtualGuest> {
}
protected Injector injector() {
return Guice.createInjector(new SoftLayerParserModule(), new GsonModule() {
@Override
protected void configure() {
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
super.configure();
}
});
return Guice.createInjector(new SoftLayerParserModule(), new GsonModule());
}
}

View File

@ -18,11 +18,14 @@
*/
package org.jclouds.softlayer.parse;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.inject.Guice;
import com.google.inject.Injector;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import java.util.Set;
import javax.ws.rs.Consumes;
import javax.ws.rs.core.MediaType;
import org.jclouds.http.HttpResponse;
import org.jclouds.json.BaseItemParserTest;
import org.jclouds.json.config.GsonModule;
@ -34,12 +37,11 @@ import org.jclouds.softlayer.domain.ProductOrder;
import org.jclouds.softlayer.predicates.ProductItemPredicates;
import org.testng.annotations.Test;
import javax.ws.rs.Consumes;
import javax.ws.rs.core.MediaType;
import java.util.Set;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.inject.Guice;
import com.google.inject.Injector;
/**
*
@ -99,15 +101,7 @@ public class ParseProductOrderTest extends BaseItemParserTest<ProductOrder> {
}
protected Injector injector() {
return Guice.createInjector(new SoftLayerParserModule(), new GsonModule() {
@Override
protected void configure() {
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
super.configure();
}
});
return Guice.createInjector(new SoftLayerParserModule(), new GsonModule());
}
}

View File

@ -18,17 +18,22 @@
*/
package org.jclouds.softlayer.parse;
import com.google.inject.Guice;
import com.google.inject.Injector;
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.config.SoftLayerParserModule;
import org.jclouds.softlayer.domain.*;
import org.jclouds.softlayer.domain.Datacenter;
import org.jclouds.softlayer.domain.OperatingSystem;
import org.jclouds.softlayer.domain.Password;
import org.jclouds.softlayer.domain.PowerState;
import org.jclouds.softlayer.domain.VirtualGuest;
import org.testng.annotations.Test;
import javax.ws.rs.Consumes;
import javax.ws.rs.core.MediaType;
import com.google.inject.Guice;
import com.google.inject.Injector;
/**
*
@ -64,15 +69,7 @@ public class ParseVirtualGuestHaltedTest extends BaseItemParserTest<VirtualGuest
}
protected Injector injector() {
return Guice.createInjector(new SoftLayerParserModule(), new GsonModule() {
@Override
protected void configure() {
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
super.configure();
}
});
return Guice.createInjector(new SoftLayerParserModule(), new GsonModule());
}
}

View File

@ -64,15 +64,7 @@ public class ParseVirtualGuestPausedTest extends BaseItemParserTest<VirtualGuest
}
protected Injector injector() {
return Guice.createInjector(new SoftLayerParserModule(), new GsonModule() {
@Override
protected void configure() {
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
super.configure();
}
});
return Guice.createInjector(new SoftLayerParserModule(), new GsonModule());
}
}

View File

@ -18,17 +18,22 @@
*/
package org.jclouds.softlayer.parse;
import com.google.inject.Guice;
import com.google.inject.Injector;
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.config.SoftLayerParserModule;
import org.jclouds.softlayer.domain.*;
import org.jclouds.softlayer.domain.Datacenter;
import org.jclouds.softlayer.domain.OperatingSystem;
import org.jclouds.softlayer.domain.Password;
import org.jclouds.softlayer.domain.PowerState;
import org.jclouds.softlayer.domain.VirtualGuest;
import org.testng.annotations.Test;
import javax.ws.rs.Consumes;
import javax.ws.rs.core.MediaType;
import com.google.inject.Guice;
import com.google.inject.Injector;
/**
*
@ -64,15 +69,7 @@ public class ParseVirtualGuestRunningTest extends BaseItemParserTest<VirtualGues
}
protected Injector injector() {
return Guice.createInjector(new SoftLayerParserModule(), new GsonModule() {
@Override
protected void configure() {
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
super.configure();
}
});
return Guice.createInjector(new SoftLayerParserModule(), new GsonModule());
}
}

View File

@ -18,8 +18,9 @@
*/
package org.jclouds.softlayer.parse;
import com.google.inject.Guice;
import com.google.inject.Injector;
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;
@ -30,8 +31,8 @@ import org.jclouds.softlayer.domain.PowerState;
import org.jclouds.softlayer.domain.VirtualGuest;
import org.testng.annotations.Test;
import javax.ws.rs.Consumes;
import javax.ws.rs.core.MediaType;
import com.google.inject.Guice;
import com.google.inject.Injector;
/**
*
@ -64,15 +65,7 @@ public class ParseVirtualGuestWithNoPasswordTest extends BaseItemParserTest<Virt
}
protected Injector injector() {
return Guice.createInjector(new SoftLayerParserModule(), new GsonModule() {
@Override
protected void configure() {
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
super.configure();
}
});
return Guice.createInjector(new SoftLayerParserModule(), new GsonModule());
}
}