updated sandbox services so that they compile

This commit is contained in:
Adrian Cole 2011-05-16 22:13:40 -07:00
parent 36e6ca787d
commit ba12d4add5
8 changed files with 163 additions and 117 deletions

View File

@ -31,23 +31,26 @@ import javax.inject.Singleton;
import org.jclouds.Constants;
import org.jclouds.collect.Memoized;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.callables.RunScriptOnNode;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.compute.internal.BaseComputeService;
import org.jclouds.compute.internal.PersistNodeCredentials;
import org.jclouds.compute.options.TemplateOptions;
import org.jclouds.compute.reference.ComputeServiceConstants.Timeouts;
import org.jclouds.compute.strategy.CreateNodesInGroupThenAddToSet;
import org.jclouds.compute.strategy.DestroyNodeStrategy;
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
import org.jclouds.compute.strategy.InitializeRunScriptOnNodeOrPlaceInBadMap;
import org.jclouds.compute.strategy.ListNodesStrategy;
import org.jclouds.compute.strategy.RebootNodeStrategy;
import org.jclouds.compute.strategy.ResumeNodeStrategy;
import org.jclouds.compute.strategy.CreateNodesInGroupThenAddToSet;
import org.jclouds.compute.strategy.SuspendNodeStrategy;
import org.jclouds.domain.Credentials;
import org.jclouds.domain.Location;
import org.jclouds.scriptbuilder.functions.InitAdminAccess;
import org.libvirt.Connect;
import org.libvirt.StorageVol;
import org.xml.sax.InputSource;
@ -72,22 +75,23 @@ public class LibvirtComputeService extends BaseComputeService {
@Memoized Supplier<Set<? extends Image>> images,
@Memoized Supplier<Set<? extends Hardware>> hardwareProfiles,
@Memoized Supplier<Set<? extends Location>> locations, ListNodesStrategy listNodesStrategy,
GetNodeMetadataStrategy getNodeMetadataStrategy, CreateNodesInGroupThenAddToSet runNodesAndAddToSetStrategy,
RebootNodeStrategy rebootNodeStrategy, DestroyNodeStrategy destroyNodeStrategy,
ResumeNodeStrategy resumeNodeStrategy, SuspendNodeStrategy suspendNodeStrategy,
Provider<TemplateBuilder> templateBuilderProvider, Provider<TemplateOptions> templateOptionsProvider,
GetNodeMetadataStrategy getNodeMetadataStrategy,
CreateNodesInGroupThenAddToSet runNodesAndAddToSetStrategy, RebootNodeStrategy rebootNodeStrategy,
DestroyNodeStrategy destroyNodeStrategy, ResumeNodeStrategy resumeNodeStrategy,
SuspendNodeStrategy suspendNodeStrategy, Provider<TemplateBuilder> templateBuilderProvider,
Provider<TemplateOptions> templateOptionsProvider,
@Named("NODE_RUNNING") Predicate<NodeMetadata> nodeRunning,
@Named("NODE_TERMINATED") Predicate<NodeMetadata> nodeTerminated,
@Named("NODE_SUSPENDED") Predicate<NodeMetadata> nodeSuspended,
InitializeRunScriptOnNodeOrPlaceInBadMap.Factory initScriptRunnerFactory, Timeouts timeouts,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, Connect client) {
InitializeRunScriptOnNodeOrPlaceInBadMap.Factory initScriptRunnerFactory, InitAdminAccess initAdminAccess,
RunScriptOnNode.Factory runScriptOnNodeFactory, PersistNodeCredentials persistNodeCredentials,
Timeouts timeouts, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, Connect client) {
super(context, credentialStore, images, hardwareProfiles, locations, listNodesStrategy, getNodeMetadataStrategy,
runNodesAndAddToSetStrategy, rebootNodeStrategy, destroyNodeStrategy, resumeNodeStrategy,
suspendNodeStrategy, templateBuilderProvider, templateOptionsProvider, nodeRunning, nodeTerminated,
nodeSuspended, initScriptRunnerFactory, timeouts, executor);
nodeSuspended, initScriptRunnerFactory, initAdminAccess, runScriptOnNodeFactory, persistNodeCredentials,
timeouts, executor);
this.client = client;
}
@Override

View File

@ -42,7 +42,7 @@ public class LibvirtComputeServiceLiveTest extends BaseComputeServiceLiveTest {
}
@Override
protected Properties getRestProperties() {
protected Properties setupRestProperties() {
Properties restProperties = new Properties();
restProperties.setProperty("libvirt.contextbuilder", LibvirtComputeServiceContextBuilder.class.getName());
restProperties.setProperty("libvirt.propertiesbuilder", LibvirtPropertiesBuilder.class.getName());

View File

@ -176,7 +176,6 @@ public class SDNAsyncClientTest extends RestClientTest<SDNAsyncClient> {
bind(String.class).annotatedWith(SessionToken.class).toInstance("sessiontoken");
bind(String.class).annotatedWith(Names.named(SDNConstants.PROPERTY_SDN_APPKEY)).toInstance("appKey");
bind(String.class).annotatedWith(Names.named(SDNConstants.PROPERTY_SDN_APPNAME)).toInstance("appname");
bind(String.class).annotatedWith(Names.named(SDNConstants.PROPERTY_SDN_USERNAME)).toInstance("username");
}

View File

@ -20,41 +20,37 @@ package org.jclouds.nirvanix.sdn.filters;
import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.lang.reflect.Method;
import java.net.URI;
import java.util.Properties;
import javax.ws.rs.POST;
import org.jclouds.concurrent.MoreExecutors;
import org.jclouds.concurrent.config.ExecutorServiceModule;
import org.jclouds.date.DateService;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
import org.jclouds.logging.Logger;
import org.jclouds.logging.Logger.LoggerFactory;
import org.jclouds.nirvanix.sdn.SDNPropertiesBuilder;
import org.jclouds.http.RequiresHttp;
import org.jclouds.nirvanix.sdn.SDNAsyncClient;
import org.jclouds.nirvanix.sdn.SDNClient;
import org.jclouds.nirvanix.sdn.SessionToken;
import org.jclouds.nirvanix.sdn.config.SDNRestClientModule;
import org.jclouds.nirvanix.sdn.reference.SDNConstants;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.RestContextFactory;
import org.jclouds.rest.RestContextSpec;
import org.jclouds.rest.annotations.EndpointParam;
import org.jclouds.rest.config.RestModule;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.Provides;
import com.google.inject.Module;
import com.google.inject.TypeLiteral;
import com.google.inject.name.Names;
@Test(groups = "unit", testName = "sdn.AddSessionTokenToRequestTest")
public class AddSessionTokenToRequestTest {
private Injector injector;
private AddSessionTokenToRequest filter;
@Test(groups = "unit", testName = "AddSessionTokenToRequestTest")
public class AddSessionTokenToRequestTest extends RestClientTest<SDNAsyncClient> {
private static interface TestService {
@POST
@ -93,34 +89,44 @@ public class AddSessionTokenToRequestTest {
assert token.equals(filter.getSessionToken());
}
/**
* before class, as we need to ensure that the filter is threadsafe.
*
*/
@Override
protected void checkFilters(HttpRequest request) {
}
private AddSessionTokenToRequest filter;
@BeforeClass
protected void createFilter() {
injector = Guice.createInjector(new RestModule(), new ExecutorServiceModule(MoreExecutors.sameThreadExecutor(),
MoreExecutors.sameThreadExecutor()), new JavaUrlHttpCommandExecutorServiceModule(), new AbstractModule() {
protected void configure() {
bind(DateService.class);
Names.bindProperties(this.binder(),
new SDNPropertiesBuilder(new Properties()).credentials("appkey/appname/username", "password").build());
bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() {
public Logger getLogger(String category) {
return Logger.NULL;
}
});
}
@SuppressWarnings("unused")
@SessionToken
@Provides
String authTokenProvider() {
return System.currentTimeMillis() + "";
}
});
@Override
protected void setupFactory() throws IOException {
super.setupFactory();
filter = injector.getInstance(AddSessionTokenToRequest.class);
}
@Override
protected TypeLiteral<RestAnnotationProcessor<SDNAsyncClient>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<SDNAsyncClient>>() {
};
}
protected Module createModule() {
return new TestSDNRestClientModule();
}
@RequiresHttp
@ConfiguresRestClient
static class TestSDNRestClientModule extends SDNRestClientModule {
@Override
public void configure() {
bind(String.class).annotatedWith(SessionToken.class).toInstance("sessiontoken");
bind(String.class).annotatedWith(Names.named(SDNConstants.PROPERTY_SDN_APPKEY)).toInstance("appKey");
bind(String.class).annotatedWith(Names.named(SDNConstants.PROPERTY_SDN_APPNAME)).toInstance("appname");
bind(String.class).annotatedWith(Names.named(SDNConstants.PROPERTY_SDN_USERNAME)).toInstance("username");
}
}
@Override
public RestContextSpec<SDNClient, SDNAsyncClient> createContextSpec() {
return new RestContextFactory().createContextSpec("sdn", "user", "password", new Properties());
}
}

View File

@ -18,99 +18,113 @@
*/
package org.jclouds.nirvanix.sdn.filters;
import static org.easymock.EasyMock.expect;
import static org.easymock.classextension.EasyMock.createMock;
import static org.easymock.classextension.EasyMock.replay;
import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.lang.reflect.Method;
import java.net.URI;
import java.util.Properties;
import javax.ws.rs.POST;
import org.jclouds.concurrent.MoreExecutors;
import org.jclouds.concurrent.config.ExecutorServiceModule;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
import org.jclouds.logging.Logger;
import org.jclouds.logging.Logger.LoggerFactory;
import org.jclouds.nirvanix.sdn.SDNPropertiesBuilder;
import org.jclouds.nirvanix.sdn.config.SDNAuthRestClientModule;
import org.jclouds.http.RequiresHttp;
import org.jclouds.nirvanix.sdn.SDNAsyncClient;
import org.jclouds.nirvanix.sdn.SDNClient;
import org.jclouds.nirvanix.sdn.SessionToken;
import org.jclouds.nirvanix.sdn.config.SDNRestClientModule;
import org.jclouds.nirvanix.sdn.reference.SDNConstants;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.RestContextFactory;
import org.jclouds.rest.RestContextSpec;
import org.jclouds.rest.annotations.EndpointParam;
import org.jclouds.rest.config.RestModule;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.common.base.Throwables;
import com.google.inject.Module;
import com.google.inject.TypeLiteral;
import com.google.inject.name.Names;
@Test(groups = "unit", sequential = true, testName = "sdn.InsertUserContextIntoPathTest")
@Test(groups = "unit", singleThreaded = true, testName = "sdn.InsertUserContextIntoPathTest")
// sequential as easymock isn't threadsafe
public class InsertUserContextIntoPathTest {
public class InsertUserContextIntoPathTest extends RestClientTest<TestService> {
private Injector injector;
private InsertUserContextIntoPath filter;
private RestAnnotationProcessor<TestService> factory;
private Method method;
private static interface TestService {
@POST
public void foo(@EndpointParam URI endpoint);
}
public void testRequestInvalid() {
HttpRequest request = factory.createRequest(method, URI.create("https://host/path"));
HttpRequest request = processor.createRequest(method, URI.create("https://host/path"));
request = filter.filter(request);
request = filter.filter(request);
assertEquals(request.getEndpoint().getPath(), "/token/appname/username/path");
assertEquals(request.getEndpoint().getPath(), "/sessiontoken/appname/username/path");
assertEquals(request.getEndpoint().getHost(), "host");
}
public void testRequestNoSession() {
HttpRequest request = factory.createRequest(method, URI.create("https://host/path"));
HttpRequest request = processor.createRequest(method, URI.create("https://host/path"));
request = filter.filter(request);
assertEquals(request.getEndpoint().getPath(), "/token/appname/username/path");
assertEquals(request.getEndpoint().getPath(), "/sessiontoken/appname/username/path");
assertEquals(request.getEndpoint().getHost(), "host");
}
public void testRequestAlreadyHasSession() {
HttpRequest request = factory.createRequest(method, URI.create("https://host/token/appname/username/path"));
HttpRequest request = processor.createRequest(method, URI.create("https://host/sessiontoken/appname/username/path"));
request = filter.filter(request);
assertEquals(request.getEndpoint().getPath(), "/token/appname/username/path");
assertEquals(request.getEndpoint().getPath(), "/sessiontoken/appname/username/path");
assertEquals(request.getEndpoint().getHost(), "host");
}
private InsertUserContextIntoPath filter;
@BeforeClass
protected void createFilter() throws SecurityException, NoSuchMethodException {
injector = Guice.createInjector(new RestModule(), new ExecutorServiceModule(MoreExecutors.sameThreadExecutor(),
MoreExecutors.sameThreadExecutor()), new JavaUrlHttpCommandExecutorServiceModule(), new AbstractModule() {
protected void configure() {
install(new SDNAuthRestClientModule());
bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() {
public Logger getLogger(String category) {
return Logger.NULL;
}
});
AddSessionTokenToRequest sessionManager = createMock(AddSessionTokenToRequest.class);
expect(sessionManager.getSessionToken()).andReturn("token").anyTimes();
replay(sessionManager);
bind(AddSessionTokenToRequest.class).toInstance(sessionManager);
Names.bindProperties(this.binder(),
new SDNPropertiesBuilder(new Properties()).credentials("appkey/appname/username", "password").build());
}
});
@Override
protected void setupFactory() throws IOException {
super.setupFactory();
filter = injector.getInstance(InsertUserContextIntoPath.class);
factory = injector.getInstance(Key.get(new TypeLiteral<RestAnnotationProcessor<TestService>>() {
}));
try {
method = TestService.class.getMethod("foo", URI.class);
} catch (Exception e) {
Throwables.propagate(e);
}
}
@Override
protected TypeLiteral<RestAnnotationProcessor<TestService>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<TestService>>() {
};
}
protected Module createModule() {
return new TestSDNRestClientModule();
}
@RequiresHttp
@ConfiguresRestClient
static class TestSDNRestClientModule extends SDNRestClientModule {
@Override
public void configure() {
bind(String.class).annotatedWith(SessionToken.class).toInstance("sessiontoken");
bind(String.class).annotatedWith(Names.named(SDNConstants.PROPERTY_SDN_APPKEY)).toInstance("appKey");
bind(String.class).annotatedWith(Names.named(SDNConstants.PROPERTY_SDN_APPNAME)).toInstance("appname");
bind(String.class).annotatedWith(Names.named(SDNConstants.PROPERTY_SDN_USERNAME)).toInstance("username");
}
}
@Override
public RestContextSpec<SDNClient, SDNAsyncClient> createContextSpec() {
return new RestContextFactory().createContextSpec("sdn", "user", "password", new Properties());
}
@Override
protected void checkFilters(HttpRequest request) {
}
}
interface TestService {
@POST
public void foo(@EndpointParam URI endpoint);
}

View File

@ -24,7 +24,10 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.inject.Inject;
import org.jclouds.http.HttpRequest;
import org.jclouds.json.Json;
import org.jclouds.rimuhosting.miro.data.CreateOptions;
import org.jclouds.rimuhosting.miro.data.NewServerData;
import org.jclouds.rimuhosting.miro.domain.MetaData;
@ -33,6 +36,10 @@ import org.jclouds.rimuhosting.miro.domain.MetaData;
* @author Ivan Meredith
*/
public class CreateServerOptions extends RimuHostingJsonBinder {
@Inject
public CreateServerOptions(Json jsonBinder) {
super(jsonBinder);
}
private String password;
private List<MetaData> metaData = new ArrayList<MetaData>();

View File

@ -21,7 +21,10 @@ package org.jclouds.rimuhosting.miro.binder;
import java.util.HashMap;
import java.util.Map;
import javax.inject.Inject;
import org.jclouds.http.HttpRequest;
import org.jclouds.json.Json;
import org.jclouds.rest.binders.BindToJsonPayload;
/**
@ -32,6 +35,11 @@ import org.jclouds.rest.binders.BindToJsonPayload;
* @author Ivan Meredith
*/
public class RimuHostingJsonBinder extends BindToJsonPayload {
@Inject
public RimuHostingJsonBinder(Json jsonBinder) {
super(jsonBinder);
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
return bindToRequest(request, (Object) postParams);

View File

@ -20,7 +20,10 @@ package org.jclouds.rimuhosting.miro.binder;
import java.util.Map;
import javax.inject.Inject;
import org.jclouds.http.HttpRequest;
import org.jclouds.json.Json;
import com.google.common.collect.ImmutableMap;
@ -32,6 +35,11 @@ import com.google.common.collect.ImmutableMap;
* @author Ivan Meredith
*/
public class RimuHostingRebootJsonBinder extends RimuHostingJsonBinder {
@Inject
public RimuHostingRebootJsonBinder(Json jsonBinder) {
super(jsonBinder);
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
return super.bindToRequest(request, (Object) ImmutableMap.of("running_state", "RESTARTING"));