Refactored the contextbuilder args.

git-svn-id: http://jclouds.googlecode.com/svn/trunk@2489 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
ivan@ivan.net.nz 2009-12-21 03:55:27 +00:00
parent 2a06d9a37d
commit 8068e4e0e5
18 changed files with 51 additions and 62 deletions

View File

@ -61,7 +61,7 @@ public interface RimuHostingAsyncClient {
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ParseRimuHostingException.class) @ExceptionParser(ParseRimuHostingException.class)
Future<SortedSet<Server>> getInstanceList(); Future<SortedSet<Server>> getServerList();
@GET @Path("/pricing-plans") @GET @Path("/pricing-plans")
@MatrixParams(keys = "server-type", values = "VPS") @MatrixParams(keys = "server-type", values = "VPS")
@ -76,7 +76,7 @@ public interface RimuHostingAsyncClient {
@ExceptionParser(ParseRimuHostingException.class) @ExceptionParser(ParseRimuHostingException.class)
@ResponseParser(ParseNewInstanceResponseFromJsonResponse.class) @ResponseParser(ParseNewInstanceResponseFromJsonResponse.class)
@MapBinder(RimuHostingCreateInstanceBinder.class) @MapBinder(RimuHostingCreateInstanceBinder.class)
Future<NewServerResponse> createInstance(@MapPayloadParam("name") String name, @MapPayloadParam("imageId") String imageId, @MapPayloadParam("planId") String planId); Future<NewServerResponse> createServer(@MapPayloadParam("name") String name, @MapPayloadParam("imageId") String imageId, @MapPayloadParam("planId") String planId);
@POST @Path("/orders/new-vps") @POST @Path("/orders/new-vps")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@ -84,18 +84,18 @@ public interface RimuHostingAsyncClient {
@ExceptionParser(ParseRimuHostingException.class) @ExceptionParser(ParseRimuHostingException.class)
@ResponseParser(ParseNewInstanceResponseFromJsonResponse.class) @ResponseParser(ParseNewInstanceResponseFromJsonResponse.class)
@MapBinder(RimuHostingCreateInstanceBinder.class) @MapBinder(RimuHostingCreateInstanceBinder.class)
Future<NewServerResponse> createInstance(@MapPayloadParam("name") String name, @MapPayloadParam("imageId") String imageId, @MapPayloadParam("planId") String planId, @MapPayloadParam("password") String password); Future<NewServerResponse> createServer(@MapPayloadParam("name") String name, @MapPayloadParam("imageId") String imageId, @MapPayloadParam("planId") String planId, @MapPayloadParam("password") String password);
@GET @Path("/orders/order-{id}-blah/vps") @GET @Path("/orders/order-{id}-blah/vps")
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@ResponseParser(ParseInstanceInfoFromJsonResponse.class) @ResponseParser(ParseInstanceInfoFromJsonResponse.class)
Future<ServerInfo> getInstanceInfo(@PathParam("id") Long id); Future<ServerInfo> getServerInfo(@PathParam("id") Long id);
@GET @Path("/orders/order-{id}-blah") @GET @Path("/orders/order-{id}-blah")
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@ResponseParser(ParseInstanceFromJsonResponse.class) @ResponseParser(ParseInstanceFromJsonResponse.class)
@ExceptionParser(ParseRimuHostingException.class) @ExceptionParser(ParseRimuHostingException.class)
Future<Server> getInstance(@PathParam("id") Long id); Future<Server> getServer(@PathParam("id") Long id);
@PUT @Path("/orders/order-{id}-blah/vps/running-state") @PUT @Path("/orders/order-{id}-blah/vps/running-state")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@ -103,11 +103,11 @@ public interface RimuHostingAsyncClient {
@ResponseParser(ParseInstanceInfoFromJsonResponse.class) @ResponseParser(ParseInstanceInfoFromJsonResponse.class)
@MapBinder(RimuHostingRebootJsonBinder.class) @MapBinder(RimuHostingRebootJsonBinder.class)
@ExceptionParser(ParseRimuHostingException.class) @ExceptionParser(ParseRimuHostingException.class)
Future<ServerInfo> restartInstance(@PathParam("id") Long id); Future<ServerInfo> restartServer(@PathParam("id") Long id);
@DELETE @Path("/orders/order-{id}-blah/vps") @DELETE @Path("/orders/order-{id}-blah/vps")
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@ResponseParser(ParseDestroyResponseFromJsonResponse.class) @ResponseParser(ParseDestroyResponseFromJsonResponse.class)
@ExceptionParser(ParseRimuHostingException.class) @ExceptionParser(ParseRimuHostingException.class)
Future<List<String>> destroyInstance(@PathParam("id") Long id); Future<List<String>> destroyServer(@PathParam("id") Long id);
} }

View File

@ -43,17 +43,17 @@ public interface RimuHostingClient {
SortedSet<Image> getImageList(); SortedSet<Image> getImageList();
SortedSet<Server> getInstanceList(); SortedSet<Server> getServerList();
SortedSet<PricingPlan> getPricingPlanList(); SortedSet<PricingPlan> getPricingPlanList();
NewServerResponse createInstance(String name, String imageId, String planId); NewServerResponse createServer(String name, String imageId, String planId);
NewServerResponse createInstance(String name, String imageId, String planId, String password); NewServerResponse createServer(String name, String imageId, String planId, String password);
Server getInstance(Long id); Server getServer(Long id);
ServerInfo restartInstance(Long id); ServerInfo restartServer(Long id);
List<String> destroyInstance(Long id); List<String> destroyServer(Long id);
} }

View File

@ -43,8 +43,7 @@ public class RimuHostingContextBuilder extends RestContextBuilder<RimuHostingAsy
super(new TypeLiteral<RimuHostingAsyncClient>() { super(new TypeLiteral<RimuHostingAsyncClient>() {
}, new TypeLiteral<RimuHostingClient>() { }, new TypeLiteral<RimuHostingClient>() {
}, props); }, props);
checkNotNull(properties.getProperty(RimuHostingConstants.PROPERTY_RIMUHOSTING_USER)); checkNotNull(properties.getProperty(RimuHostingConstants.PROPERTY_RIMUHOSTING_APIKEY));
checkNotNull(properties.getProperty(RimuHostingConstants.PROPERTY_RIMUHOSTING_PASSWORD));
} }
protected void addClientModule(List<Module> modules) { protected void addClientModule(List<Module> modules) {

View File

@ -47,9 +47,9 @@ import java.util.Properties;
*/ */
public class RimuHostingContextFactory { public class RimuHostingContextFactory {
public static RestContext<RimuHostingAsyncClient, RimuHostingClient> createContext(String user, String password, public static RestContext<RimuHostingAsyncClient, RimuHostingClient> createContext(String apikey,
Module... modules) { Module... modules) {
return new RimuHostingContextBuilder(new RimuHostingPropertiesBuilder(user, password).build()) return new RimuHostingContextBuilder(new RimuHostingPropertiesBuilder(apikey).build())
.withModules(modules).buildContext(); .withModules(modules).buildContext();
} }

View File

@ -47,14 +47,13 @@ public class RimuHostingPropertiesBuilder extends HttpPropertiesBuilder {
super(properties); super(properties);
} }
public RimuHostingPropertiesBuilder(String id, String secret) { public RimuHostingPropertiesBuilder(String secret) {
super(); super();
withCredentials(id, secret); withCredentials(secret);
} }
public RimuHostingPropertiesBuilder withCredentials(String id, String secret) { public RimuHostingPropertiesBuilder withCredentials(String secret) {
properties.setProperty(PROPERTY_RIMUHOSTING_USER, checkNotNull(id, "user")); properties.setProperty(PROPERTY_RIMUHOSTING_APIKEY, checkNotNull(secret, "password"));
properties.setProperty(PROPERTY_RIMUHOSTING_PASSWORD, checkNotNull(secret, "password"));
return this; return this;
} }

View File

@ -58,7 +58,7 @@ public class RimuHostingContextModule extends AbstractModule {
@Provides @Provides
@Singleton @Singleton
RestContext<RimuHostingAsyncClient, RimuHostingClient> provideContext(Closer closer, RimuHostingAsyncClient asyncApi, RestContext<RimuHostingAsyncClient, RimuHostingClient> provideContext(Closer closer, RimuHostingAsyncClient asyncApi,
RimuHostingClient syncApi, @RimuHosting URI endPoint, @Named(RimuHostingConstants.PROPERTY_RIMUHOSTING_USER) String account) { RimuHostingClient syncApi, @RimuHosting URI endPoint, @Named(RimuHostingConstants.PROPERTY_RIMUHOSTING_APIKEY) String account) {
return new RestContextImpl<RimuHostingAsyncClient, RimuHostingClient>(closer, asyncApi, syncApi, endPoint, account); return new RestContextImpl<RimuHostingAsyncClient, RimuHostingClient>(closer, asyncApi, syncApi, endPoint, account);
} }

View File

@ -58,7 +58,7 @@ public class RimuHostingRestClientModule extends AbstractModule {
@Provides @Provides
@Singleton @Singleton
public RimuHostingAuthentication provideRimuHostingAuthentication( public RimuHostingAuthentication provideRimuHostingAuthentication(
@Named(RimuHostingConstants.PROPERTY_RIMUHOSTING_PASSWORD) String apikey) @Named(RimuHostingConstants.PROPERTY_RIMUHOSTING_APIKEY) String apikey)
throws UnsupportedEncodingException { throws UnsupportedEncodingException {
return new RimuHostingAuthentication(apikey); return new RimuHostingAuthentication(apikey);
} }

View File

@ -30,6 +30,5 @@ package org.jclouds.rimuhosting.miro.reference;
*/ */
public interface RimuHostingConstants { public interface RimuHostingConstants {
public static final String PROPERTY_RIMUHOSTING_ENDPOINT = "jclouds.rimuhosting.endpoint"; public static final String PROPERTY_RIMUHOSTING_ENDPOINT = "jclouds.rimuhosting.endpoint";
public static final String PROPERTY_RIMUHOSTING_USER = "jclouds.rimuhosting.user"; public static final String PROPERTY_RIMUHOSTING_APIKEY = "jclouds.rimuhosting.password";
public static final String PROPERTY_RIMUHOSTING_PASSWORD = "jclouds.rimuhosting.password";
} }

View File

@ -62,7 +62,7 @@ public class RimuHostingComputeService implements ComputeService {
@Override @Override
public CreateServerResponse createServer(String name, Profile profile, Image image) { public CreateServerResponse createServer(String name, Profile profile, Image image) {
NewServerResponse serverResponse = rhClient.createInstance(name, checkNotNull(imageNameMap NewServerResponse serverResponse = rhClient.createServer(name, checkNotNull(imageNameMap
.get(image), "image not supported: " + image), checkNotNull(profileNameMap .get(image), "image not supported: " + image), checkNotNull(profileNameMap
.get(profile), "profile not supported: " + profile)); .get(profile), "profile not supported: " + profile));
return new RimuHostingCreateServerResponse(serverResponse); return new RimuHostingCreateServerResponse(serverResponse);
@ -70,7 +70,7 @@ public class RimuHostingComputeService implements ComputeService {
public SortedSet<org.jclouds.compute.domain.ServerIdentity> listServers() { public SortedSet<org.jclouds.compute.domain.ServerIdentity> listServers() {
SortedSet<org.jclouds.compute.domain.ServerIdentity> servers = new TreeSet<org.jclouds.compute.domain.ServerIdentity>(); SortedSet<org.jclouds.compute.domain.ServerIdentity> servers = new TreeSet<org.jclouds.compute.domain.ServerIdentity>();
SortedSet<Server> rhServers = rhClient.getInstanceList(); SortedSet<Server> rhServers = rhClient.getServerList();
for (Server rhServer : rhServers) { for (Server rhServer : rhServers) {
servers.add(new RimuHostingServer(rhServer, rhClient)); servers.add(new RimuHostingServer(rhServer, rhClient));
} }
@ -84,14 +84,16 @@ public class RimuHostingComputeService implements ComputeService {
@Override @Override
public SortedSet<org.jclouds.compute.domain.ServerIdentity> getServerByName(String id) { public SortedSet<org.jclouds.compute.domain.ServerIdentity> getServerByName(String id) {
SortedSet<org.jclouds.compute.domain.ServerIdentity> serverSet = new TreeSet<org.jclouds.compute.domain.ServerIdentity>(); SortedSet<org.jclouds.compute.domain.ServerIdentity> serverSet = new TreeSet<org.jclouds.compute.domain.ServerIdentity>();
for (Server rhServer : rhClient.getInstanceList()) { for (Server rhServer : rhClient.getServerList()) {
if(rhServer.getName().equals(id)){
serverSet.add(new RimuHostingServer(rhServer, rhClient)); serverSet.add(new RimuHostingServer(rhServer, rhClient));
} }
}
return serverSet; return serverSet;
} }
@Override @Override
public void destroyServer(String id) { public void destroyServer(String id) {
rhClient.destroyInstance(new Long(id)); rhClient.destroyServer(new Long(id));
} }
} }

View File

@ -46,7 +46,7 @@ public class RimuHostingCreateServerResponse extends CreateServerResponseImpl {
public RimuHostingCreateServerResponse(NewServerResponse rhServerResponse) { public RimuHostingCreateServerResponse(NewServerResponse rhServerResponse) {
super(rhServerResponse.getServer().getId().toString(), super(rhServerResponse.getServer().getId().toString(),
rhServerResponse.getServer().getName(), rhServerResponse.getServer().getName(),
ServerState.PENDING,// TODO need a real state! ServerState.RUNNING,// TODO need a real state!
getPublicAddresses(rhServerResponse.getServer()), ImmutableList.<InetAddress> of(), getPublicAddresses(rhServerResponse.getServer()), ImmutableList.<InetAddress> of(),
22, LoginType.SSH, new Credentials("root", rhServerResponse.getNewInstanceRequest() 22, LoginType.SSH, new Credentials("root", rhServerResponse.getNewInstanceRequest()
.getCreateOptions().getPassword())); .getCreateOptions().getPassword()));

View File

@ -42,7 +42,7 @@ public class RimuHostingServer implements ServerIdentity {
} }
public Boolean destroy() { public Boolean destroy() {
rhClient.destroyInstance(rhServer.getId()); rhClient.destroyServer(rhServer.getId());
return Boolean.TRUE; return Boolean.TRUE;
} }

View File

@ -45,10 +45,9 @@ public class RimuHostingClientLiveTest {
@BeforeGroups(groups = {"live"}) @BeforeGroups(groups = {"live"})
public void setupClient() { public void setupClient() {
String user = checkNotNull(System.getProperty("jclouds.test.user"), "jclouds.test.user");
String password = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key"); String password = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key");
connection = RimuHostingContextFactory.createContext(user, password, new Log4JLoggingModule()) connection = RimuHostingContextFactory.createContext(password, new Log4JLoggingModule())
.getApi(); .getApi();
} }
@ -78,12 +77,12 @@ public class RimuHostingClientLiveTest {
@Test @Test
public void testLifeCycle() { public void testLifeCycle() {
//Get the first image, we dont really care what it is in this test. //Get the first image, we dont really care what it is in this test.
NewServerResponse serverResponse = connection.createInstance("test.jclouds.org", "lenny", "MIRO1B"); NewServerResponse serverResponse = connection.createServer("test.jclouds.org", "lenny", "MIRO1B");
Server server = serverResponse.getServer(); Server server = serverResponse.getServer();
//Now we have the server, lets restart it //Now we have the server, lets restart it
assertNotNull(server.getId()); assertNotNull(server.getId());
ServerInfo serverInfo = connection.restartInstance(server.getId()); ServerInfo serverInfo = connection.restartServer(server.getId());
connection.destroyInstance(server.getId()); connection.destroyServer(server.getId());
//Should be running now. //Should be running now.
assertEquals(serverInfo.getState(), RunningState.RUNNING); assertEquals(serverInfo.getState(), RunningState.RUNNING);
assertEquals(server.getName(),"test.jclouds.org"); assertEquals(server.getName(),"test.jclouds.org");

View File

@ -56,7 +56,7 @@ public class RimuHostingComputeClient {
public Long start(String name, String planId, String imageId) { public Long start(String name, String planId, String imageId) {
logger.debug(">> instantiating RimuHosting VPS name(%s) plan(%s) image(%s)", name, planId, imageId); logger.debug(">> instantiating RimuHosting VPS name(%s) plan(%s) image(%s)", name, planId, imageId);
NewServerResponse serverRespone = rhClient.createInstance(name, imageId, planId); NewServerResponse serverRespone = rhClient.createServer(name, imageId, planId);
logger.debug(">> VPS id(%d) started and running.", serverRespone.getServer().getId()); logger.debug(">> VPS id(%d) started and running.", serverRespone.getServer().getId());
return serverRespone.getServer().getId(); return serverRespone.getServer().getId();
} }
@ -64,16 +64,16 @@ public class RimuHostingComputeClient {
public void reboot(Long id) { public void reboot(Long id) {
Server server = rhClient.getInstance(id); Server server = rhClient.getServer(id);
logger.debug(">> rebooting VPS(%d)", server.getId()); logger.debug(">> rebooting VPS(%d)", server.getId());
rhClient.restartInstance(id); rhClient.restartServer(id);
logger.debug("<< on VPS(%d)", server.getId()); logger.debug("<< on VPS(%d)", server.getId());
} }
public void destroy(Long id) { public void destroy(Long id) {
Server server = rhClient.getInstance(id); Server server = rhClient.getServer(id);
logger.debug(">> destroy VPS(%d)", server.getId()); logger.debug(">> destroy VPS(%d)", server.getId());
rhClient.destroyInstance(id); rhClient.destroyServer(id);
logger.debug(">> destroyed VPS"); logger.debug(">> destroyed VPS");
} }
} }

View File

@ -68,7 +68,7 @@ public class RimuHostingComputeClientLiveTest {
String planId = "MIRO1B"; String planId = "MIRO1B";
id = client.start(serverName, planId, imageId); id = client.start(serverName, planId, imageId);
Server server = rhClient.getInstance(id); Server server = rhClient.getServer(id);
assertEquals(imageId, server.getImageId()); assertEquals(imageId, server.getImageId());
assertEquals(serverName, server.getName()); assertEquals(serverName, server.getName());
assertEquals(new Integer(160), server.getInstanceParameters().getRam()); assertEquals(new Integer(160), server.getInstanceParameters().getRam());
@ -82,10 +82,8 @@ public class RimuHostingComputeClientLiveTest {
@BeforeGroups(groups = { "live" }) @BeforeGroups(groups = { "live" })
public void setupClient() { public void setupClient() {
String account = checkNotNull(System.getProperty("jclouds.test.user"), "jclouds.test.user");
String key = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key"); String key = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key");
Injector injector = new RimuHostingContextBuilder(new RimuHostingPropertiesBuilder( Injector injector = new RimuHostingContextBuilder(new RimuHostingPropertiesBuilder(key).relaxSSLHostname().build()).withModules(new Log4JLoggingModule(),
account, key).relaxSSLHostname().build()).withModules(new Log4JLoggingModule(),
new JschSshClientModule(), new AbstractModule() { new JschSshClientModule(), new AbstractModule() {
@Override @Override

View File

@ -51,16 +51,14 @@ public class RimuHostingContextBuilderTest {
RimuHostingContextBuilder builder = newBuilder(); RimuHostingContextBuilder builder = newBuilder();
assertEquals(builder.getProperties().getProperty(RimuHostingConstants.PROPERTY_RIMUHOSTING_ENDPOINT), assertEquals(builder.getProperties().getProperty(RimuHostingConstants.PROPERTY_RIMUHOSTING_ENDPOINT),
"https://rimuhosting.com/r"); "https://rimuhosting.com/r");
assertEquals(builder.getProperties().getProperty(RimuHostingConstants.PROPERTY_RIMUHOSTING_USER), assertEquals(builder.getProperties().getProperty(RimuHostingConstants.PROPERTY_RIMUHOSTING_APIKEY),
"user");
assertEquals(builder.getProperties().getProperty(RimuHostingConstants.PROPERTY_RIMUHOSTING_PASSWORD),
"password"); "password");
} }
public void testBuildContext() { public void testBuildContext() {
RestContext<RimuHostingAsyncClient, RimuHostingClient> context = newBuilder().buildContext(); RestContext<RimuHostingAsyncClient, RimuHostingClient> context = newBuilder().buildContext();
assertEquals(context.getClass(), RestContextImpl.class); assertEquals(context.getClass(), RestContextImpl.class);
assertEquals(context.getAccount(), "user"); assertEquals(context.getAccount(), "password");
assertEquals(context.getEndPoint(), URI.create("https://rimuhosting.com/r")); assertEquals(context.getEndPoint(), URI.create("https://rimuhosting.com/r"));
} }
@ -80,8 +78,7 @@ public class RimuHostingContextBuilderTest {
} }
private RimuHostingContextBuilder newBuilder() { private RimuHostingContextBuilder newBuilder() {
RimuHostingContextBuilder builder = new RimuHostingContextBuilder(new RimuHostingPropertiesBuilder( RimuHostingContextBuilder builder = new RimuHostingContextBuilder(new RimuHostingPropertiesBuilder("password").build());
"user", "password").build());
return builder; return builder;
} }

View File

@ -57,11 +57,8 @@ public class RimuHostingContextModuleTest {
@Override @Override
protected void configure() { protected void configure() {
bindConstant().annotatedWith( bindConstant().annotatedWith(
Jsr330.named(RimuHostingConstants.PROPERTY_RIMUHOSTING_USER)).to( Jsr330.named(RimuHostingConstants.PROPERTY_RIMUHOSTING_APIKEY)).to(
"user"); "apikey");
bindConstant().annotatedWith(
Jsr330.named(RimuHostingConstants.PROPERTY_RIMUHOSTING_PASSWORD)).to(
"password");
bindConstant().annotatedWith( bindConstant().annotatedWith(
Jsr330.named(RimuHostingConstants.PROPERTY_RIMUHOSTING_ENDPOINT)).to( Jsr330.named(RimuHostingConstants.PROPERTY_RIMUHOSTING_ENDPOINT)).to(
"http://localhost"); "http://localhost");

View File

@ -50,8 +50,7 @@ public class RimuHostingComputeServiceLiveTest {
public void setupClient() { public void setupClient() {
String account = "ddd"; String account = "ddd";
String key = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key"); String key = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key");
Injector injector = new RimuHostingContextBuilder(new RimuHostingPropertiesBuilder(account, Injector injector = new RimuHostingContextBuilder(new RimuHostingPropertiesBuilder(key).relaxSSLHostname().build()).withModules(new Log4JLoggingModule())
key).relaxSSLHostname().build()).withModules(new Log4JLoggingModule())
.buildInjector(); .buildInjector();
rhClient = injector.getInstance(RimuHostingClient.class); rhClient = injector.getInstance(RimuHostingClient.class);
@ -62,7 +61,7 @@ public class RimuHostingComputeServiceLiveTest {
public void testServerCreate() { public void testServerCreate() {
CreateServerResponse server = rhServerService.createServer("test.com", Profile.SMALLEST, CreateServerResponse server = rhServerService.createServer("test.com", Profile.SMALLEST,
Image.CENTOS_53); Image.CENTOS_53);
assertNotNull(rhClient.getInstance(Long.valueOf(server.getId()))); assertNotNull(rhClient.getServer(Long.valueOf(server.getId())));
rhServerService.destroyServer(server.getId()); rhServerService.destroyServer(server.getId());
} }
} }