mirror of https://github.com/apache/jclouds.git
Refactored the contextbuilder args.
git-svn-id: http://jclouds.googlecode.com/svn/trunk@2489 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
parent
2a06d9a37d
commit
8068e4e0e5
|
@ -61,7 +61,7 @@ public interface RimuHostingAsyncClient {
|
|||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ParseRimuHostingException.class)
|
||||
Future<SortedSet<Server>> getInstanceList();
|
||||
Future<SortedSet<Server>> getServerList();
|
||||
|
||||
@GET @Path("/pricing-plans")
|
||||
@MatrixParams(keys = "server-type", values = "VPS")
|
||||
|
@ -76,7 +76,7 @@ public interface RimuHostingAsyncClient {
|
|||
@ExceptionParser(ParseRimuHostingException.class)
|
||||
@ResponseParser(ParseNewInstanceResponseFromJsonResponse.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")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
|
@ -84,18 +84,18 @@ public interface RimuHostingAsyncClient {
|
|||
@ExceptionParser(ParseRimuHostingException.class)
|
||||
@ResponseParser(ParseNewInstanceResponseFromJsonResponse.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")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ResponseParser(ParseInstanceInfoFromJsonResponse.class)
|
||||
Future<ServerInfo> getInstanceInfo(@PathParam("id") Long id);
|
||||
Future<ServerInfo> getServerInfo(@PathParam("id") Long id);
|
||||
|
||||
@GET @Path("/orders/order-{id}-blah")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ResponseParser(ParseInstanceFromJsonResponse.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")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
|
@ -103,11 +103,11 @@ public interface RimuHostingAsyncClient {
|
|||
@ResponseParser(ParseInstanceInfoFromJsonResponse.class)
|
||||
@MapBinder(RimuHostingRebootJsonBinder.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")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ResponseParser(ParseDestroyResponseFromJsonResponse.class)
|
||||
@ExceptionParser(ParseRimuHostingException.class)
|
||||
Future<List<String>> destroyInstance(@PathParam("id") Long id);
|
||||
Future<List<String>> destroyServer(@PathParam("id") Long id);
|
||||
}
|
||||
|
|
|
@ -43,17 +43,17 @@ public interface RimuHostingClient {
|
|||
|
||||
SortedSet<Image> getImageList();
|
||||
|
||||
SortedSet<Server> getInstanceList();
|
||||
SortedSet<Server> getServerList();
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -43,8 +43,7 @@ public class RimuHostingContextBuilder extends RestContextBuilder<RimuHostingAsy
|
|||
super(new TypeLiteral<RimuHostingAsyncClient>() {
|
||||
}, new TypeLiteral<RimuHostingClient>() {
|
||||
}, props);
|
||||
checkNotNull(properties.getProperty(RimuHostingConstants.PROPERTY_RIMUHOSTING_USER));
|
||||
checkNotNull(properties.getProperty(RimuHostingConstants.PROPERTY_RIMUHOSTING_PASSWORD));
|
||||
checkNotNull(properties.getProperty(RimuHostingConstants.PROPERTY_RIMUHOSTING_APIKEY));
|
||||
}
|
||||
|
||||
protected void addClientModule(List<Module> modules) {
|
||||
|
|
|
@ -47,9 +47,9 @@ import java.util.Properties;
|
|||
*/
|
||||
public class RimuHostingContextFactory {
|
||||
|
||||
public static RestContext<RimuHostingAsyncClient, RimuHostingClient> createContext(String user, String password,
|
||||
public static RestContext<RimuHostingAsyncClient, RimuHostingClient> createContext(String apikey,
|
||||
Module... modules) {
|
||||
return new RimuHostingContextBuilder(new RimuHostingPropertiesBuilder(user, password).build())
|
||||
return new RimuHostingContextBuilder(new RimuHostingPropertiesBuilder(apikey).build())
|
||||
.withModules(modules).buildContext();
|
||||
}
|
||||
|
||||
|
|
|
@ -47,14 +47,13 @@ public class RimuHostingPropertiesBuilder extends HttpPropertiesBuilder {
|
|||
super(properties);
|
||||
}
|
||||
|
||||
public RimuHostingPropertiesBuilder(String id, String secret) {
|
||||
public RimuHostingPropertiesBuilder(String secret) {
|
||||
super();
|
||||
withCredentials(id, secret);
|
||||
withCredentials(secret);
|
||||
}
|
||||
|
||||
public RimuHostingPropertiesBuilder withCredentials(String id, String secret) {
|
||||
properties.setProperty(PROPERTY_RIMUHOSTING_USER, checkNotNull(id, "user"));
|
||||
properties.setProperty(PROPERTY_RIMUHOSTING_PASSWORD, checkNotNull(secret, "password"));
|
||||
public RimuHostingPropertiesBuilder withCredentials(String secret) {
|
||||
properties.setProperty(PROPERTY_RIMUHOSTING_APIKEY, checkNotNull(secret, "password"));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ public class RimuHostingContextModule extends AbstractModule {
|
|||
@Provides
|
||||
@Singleton
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ public class RimuHostingRestClientModule extends AbstractModule {
|
|||
@Provides
|
||||
@Singleton
|
||||
public RimuHostingAuthentication provideRimuHostingAuthentication(
|
||||
@Named(RimuHostingConstants.PROPERTY_RIMUHOSTING_PASSWORD) String apikey)
|
||||
@Named(RimuHostingConstants.PROPERTY_RIMUHOSTING_APIKEY) String apikey)
|
||||
throws UnsupportedEncodingException {
|
||||
return new RimuHostingAuthentication(apikey);
|
||||
}
|
||||
|
|
|
@ -30,6 +30,5 @@ package org.jclouds.rimuhosting.miro.reference;
|
|||
*/
|
||||
public interface RimuHostingConstants {
|
||||
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_PASSWORD = "jclouds.rimuhosting.password";
|
||||
public static final String PROPERTY_RIMUHOSTING_APIKEY = "jclouds.rimuhosting.password";
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@ public class RimuHostingComputeService implements ComputeService {
|
|||
|
||||
@Override
|
||||
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(profile), "profile not supported: " + profile));
|
||||
return new RimuHostingCreateServerResponse(serverResponse);
|
||||
|
@ -70,7 +70,7 @@ public class RimuHostingComputeService implements ComputeService {
|
|||
|
||||
public SortedSet<org.jclouds.compute.domain.ServerIdentity> listServers() {
|
||||
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) {
|
||||
servers.add(new RimuHostingServer(rhServer, rhClient));
|
||||
}
|
||||
|
@ -84,14 +84,16 @@ public class RimuHostingComputeService implements ComputeService {
|
|||
@Override
|
||||
public SortedSet<org.jclouds.compute.domain.ServerIdentity> getServerByName(String id) {
|
||||
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));
|
||||
}
|
||||
}
|
||||
return serverSet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroyServer(String id) {
|
||||
rhClient.destroyInstance(new Long(id));
|
||||
rhClient.destroyServer(new Long(id));
|
||||
}
|
||||
}
|
|
@ -46,7 +46,7 @@ public class RimuHostingCreateServerResponse extends CreateServerResponseImpl {
|
|||
public RimuHostingCreateServerResponse(NewServerResponse rhServerResponse) {
|
||||
super(rhServerResponse.getServer().getId().toString(),
|
||||
rhServerResponse.getServer().getName(),
|
||||
ServerState.PENDING,// TODO need a real state!
|
||||
ServerState.RUNNING,// TODO need a real state!
|
||||
getPublicAddresses(rhServerResponse.getServer()), ImmutableList.<InetAddress> of(),
|
||||
22, LoginType.SSH, new Credentials("root", rhServerResponse.getNewInstanceRequest()
|
||||
.getCreateOptions().getPassword()));
|
||||
|
|
|
@ -42,7 +42,7 @@ public class RimuHostingServer implements ServerIdentity {
|
|||
}
|
||||
|
||||
public Boolean destroy() {
|
||||
rhClient.destroyInstance(rhServer.getId());
|
||||
rhClient.destroyServer(rhServer.getId());
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
|
|
|
@ -45,10 +45,9 @@ public class RimuHostingClientLiveTest {
|
|||
|
||||
@BeforeGroups(groups = {"live"})
|
||||
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");
|
||||
|
||||
connection = RimuHostingContextFactory.createContext(user, password, new Log4JLoggingModule())
|
||||
connection = RimuHostingContextFactory.createContext(password, new Log4JLoggingModule())
|
||||
.getApi();
|
||||
}
|
||||
|
||||
|
@ -78,12 +77,12 @@ public class RimuHostingClientLiveTest {
|
|||
@Test
|
||||
public void testLifeCycle() {
|
||||
//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();
|
||||
//Now we have the server, lets restart it
|
||||
assertNotNull(server.getId());
|
||||
ServerInfo serverInfo = connection.restartInstance(server.getId());
|
||||
connection.destroyInstance(server.getId());
|
||||
ServerInfo serverInfo = connection.restartServer(server.getId());
|
||||
connection.destroyServer(server.getId());
|
||||
//Should be running now.
|
||||
assertEquals(serverInfo.getState(), RunningState.RUNNING);
|
||||
assertEquals(server.getName(),"test.jclouds.org");
|
||||
|
|
|
@ -56,7 +56,7 @@ public class RimuHostingComputeClient {
|
|||
|
||||
public Long start(String name, String planId, String 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());
|
||||
return serverRespone.getServer().getId();
|
||||
}
|
||||
|
@ -64,16 +64,16 @@ public class RimuHostingComputeClient {
|
|||
|
||||
|
||||
public void reboot(Long id) {
|
||||
Server server = rhClient.getInstance(id);
|
||||
Server server = rhClient.getServer(id);
|
||||
logger.debug(">> rebooting VPS(%d)", server.getId());
|
||||
rhClient.restartInstance(id);
|
||||
rhClient.restartServer(id);
|
||||
logger.debug("<< on VPS(%d)", server.getId());
|
||||
}
|
||||
|
||||
public void destroy(Long id) {
|
||||
Server server = rhClient.getInstance(id);
|
||||
Server server = rhClient.getServer(id);
|
||||
logger.debug(">> destroy VPS(%d)", server.getId());
|
||||
rhClient.destroyInstance(id);
|
||||
rhClient.destroyServer(id);
|
||||
logger.debug(">> destroyed VPS");
|
||||
}
|
||||
}
|
|
@ -68,7 +68,7 @@ public class RimuHostingComputeClientLiveTest {
|
|||
String planId = "MIRO1B";
|
||||
|
||||
id = client.start(serverName, planId, imageId);
|
||||
Server server = rhClient.getInstance(id);
|
||||
Server server = rhClient.getServer(id);
|
||||
assertEquals(imageId, server.getImageId());
|
||||
assertEquals(serverName, server.getName());
|
||||
assertEquals(new Integer(160), server.getInstanceParameters().getRam());
|
||||
|
@ -82,10 +82,8 @@ public class RimuHostingComputeClientLiveTest {
|
|||
|
||||
@BeforeGroups(groups = { "live" })
|
||||
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");
|
||||
Injector injector = new RimuHostingContextBuilder(new RimuHostingPropertiesBuilder(
|
||||
account, key).relaxSSLHostname().build()).withModules(new Log4JLoggingModule(),
|
||||
Injector injector = new RimuHostingContextBuilder(new RimuHostingPropertiesBuilder(key).relaxSSLHostname().build()).withModules(new Log4JLoggingModule(),
|
||||
new JschSshClientModule(), new AbstractModule() {
|
||||
|
||||
@Override
|
||||
|
|
|
@ -51,16 +51,14 @@ public class RimuHostingContextBuilderTest {
|
|||
RimuHostingContextBuilder builder = newBuilder();
|
||||
assertEquals(builder.getProperties().getProperty(RimuHostingConstants.PROPERTY_RIMUHOSTING_ENDPOINT),
|
||||
"https://rimuhosting.com/r");
|
||||
assertEquals(builder.getProperties().getProperty(RimuHostingConstants.PROPERTY_RIMUHOSTING_USER),
|
||||
"user");
|
||||
assertEquals(builder.getProperties().getProperty(RimuHostingConstants.PROPERTY_RIMUHOSTING_PASSWORD),
|
||||
assertEquals(builder.getProperties().getProperty(RimuHostingConstants.PROPERTY_RIMUHOSTING_APIKEY),
|
||||
"password");
|
||||
}
|
||||
|
||||
public void testBuildContext() {
|
||||
RestContext<RimuHostingAsyncClient, RimuHostingClient> context = newBuilder().buildContext();
|
||||
assertEquals(context.getClass(), RestContextImpl.class);
|
||||
assertEquals(context.getAccount(), "user");
|
||||
assertEquals(context.getAccount(), "password");
|
||||
assertEquals(context.getEndPoint(), URI.create("https://rimuhosting.com/r"));
|
||||
}
|
||||
|
||||
|
@ -80,8 +78,7 @@ public class RimuHostingContextBuilderTest {
|
|||
}
|
||||
|
||||
private RimuHostingContextBuilder newBuilder() {
|
||||
RimuHostingContextBuilder builder = new RimuHostingContextBuilder(new RimuHostingPropertiesBuilder(
|
||||
"user", "password").build());
|
||||
RimuHostingContextBuilder builder = new RimuHostingContextBuilder(new RimuHostingPropertiesBuilder("password").build());
|
||||
return builder;
|
||||
}
|
||||
|
||||
|
|
|
@ -57,11 +57,8 @@ public class RimuHostingContextModuleTest {
|
|||
@Override
|
||||
protected void configure() {
|
||||
bindConstant().annotatedWith(
|
||||
Jsr330.named(RimuHostingConstants.PROPERTY_RIMUHOSTING_USER)).to(
|
||||
"user");
|
||||
bindConstant().annotatedWith(
|
||||
Jsr330.named(RimuHostingConstants.PROPERTY_RIMUHOSTING_PASSWORD)).to(
|
||||
"password");
|
||||
Jsr330.named(RimuHostingConstants.PROPERTY_RIMUHOSTING_APIKEY)).to(
|
||||
"apikey");
|
||||
bindConstant().annotatedWith(
|
||||
Jsr330.named(RimuHostingConstants.PROPERTY_RIMUHOSTING_ENDPOINT)).to(
|
||||
"http://localhost");
|
||||
|
|
|
@ -50,8 +50,7 @@ public class RimuHostingComputeServiceLiveTest {
|
|||
public void setupClient() {
|
||||
String account = "ddd";
|
||||
String key = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key");
|
||||
Injector injector = new RimuHostingContextBuilder(new RimuHostingPropertiesBuilder(account,
|
||||
key).relaxSSLHostname().build()).withModules(new Log4JLoggingModule())
|
||||
Injector injector = new RimuHostingContextBuilder(new RimuHostingPropertiesBuilder(key).relaxSSLHostname().build()).withModules(new Log4JLoggingModule())
|
||||
.buildInjector();
|
||||
|
||||
rhClient = injector.getInstance(RimuHostingClient.class);
|
||||
|
@ -62,7 +61,7 @@ public class RimuHostingComputeServiceLiveTest {
|
|||
public void testServerCreate() {
|
||||
CreateServerResponse server = rhServerService.createServer("test.com", Profile.SMALLEST,
|
||||
Image.CENTOS_53);
|
||||
assertNotNull(rhClient.getInstance(Long.valueOf(server.getId())));
|
||||
assertNotNull(rhClient.getServer(Long.valueOf(server.getId())));
|
||||
rhServerService.destroyServer(server.getId());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue