changed factories to not use varargs as it makes scripting ugly. also added NONE options for the same reason.

git-svn-id: http://jclouds.googlecode.com/svn/trunk@2645 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
adrian.f.cole 2010-01-13 06:34:35 +00:00
parent 6ff6abd36c
commit 2d19e33828
10 changed files with 70 additions and 106 deletions

View File

@ -1,81 +0,0 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.
* ====================================================================
*/
package org.jclouds.aws.ec2;
import static org.testng.Assert.assertEquals;
import java.util.List;
import org.apache.log4j.AppenderSkeleton;
import org.apache.log4j.ConsoleAppender;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.apache.log4j.SimpleLayout;
import org.apache.log4j.spi.LoggingEvent;
import org.testng.annotations.Test;
import org.testng.collections.Lists;
import com.google.common.collect.ImmutableList;
/**
*
* @author Adrian Cole
*/
@Test
public class TestLogger {
static class AppenderForTesting extends AppenderSkeleton {
private static List<String> messages = Lists.newArrayList();
protected void append(LoggingEvent event) {
messages.add(event.getLoggerName() + ":" + event.getRenderedMessage());
}
public void close() {
}
public boolean requiresLayout() {
return false;
}
public static List<String> getMessages() {
return messages;
}
public static void clear() {
messages.clear();
}
}
static class LogApples {
final Logger logger = LogManager.getLogger(LogApples.class);
public void log(String in) {
logger.info(in);
}
}
@Test
void testFoo() {
Logger.getRootLogger().addAppender(new AppenderForTesting());
Logger.getRootLogger().addAppender(new ConsoleAppender(new SimpleLayout()));
new LogApples().log("foo");
assertEquals(AppenderForTesting.getMessages(), ImmutableList.of("foo"));
}
}

View File

@ -48,6 +48,7 @@ import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Guice;
import com.google.inject.Injector;
@ -68,11 +69,12 @@ public class EC2ComputeServiceLiveTest {
private ComputeServiceContext<?, ?> context;
@BeforeGroups(groups = { "live" })
public void setupClient() throws InterruptedException, ExecutionException, TimeoutException, IOException {
public void setupClient() throws InterruptedException, ExecutionException, TimeoutException,
IOException {
String user = checkNotNull(System.getProperty("jclouds.test.user"), "jclouds.test.user");
String password = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key");
context = new ComputeServiceContextFactory().createContext("ec2", user, password,
new Log4JLoggingModule());
ImmutableSet.of(new Log4JLoggingModule()));
Injector injector = Guice.createInjector(new JschSshClientModule());
sshFactory = injector.getInstance(SshClient.Factory.class);
SocketOpen socketOpen = injector.getInstance(SocketOpen.class);

View File

@ -29,6 +29,8 @@ import javax.inject.Inject;
import org.jclouds.domain.Credentials;
import org.jclouds.http.HttpPropertiesBuilder;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.io.Resources;
import com.google.inject.Module;
@ -55,18 +57,31 @@ public class BlobStoreContextFactory {
this.properties = properties;
}
public BlobStoreContext<?, ?> createContext(URI blobStore, Module... modules) {
public BlobStoreContext<?, ?> createContext(URI blobStore, Iterable<? extends Module> modules) {
return createContext(blobStore, Credentials.parse(blobStore), modules);
}
public BlobStoreContext<?, ?> createContext(URI blobStore, Credentials creds, Module... modules) {
public BlobStoreContext<?, ?> createContext(URI blobStore) {
return createContext(blobStore, ImmutableSet.<Module> of());
}
public BlobStoreContext<?, ?> createContext(URI blobStore, Credentials creds,
Iterable<? extends Module> modules) {
return createContext(checkNotNull(blobStore.getHost(), "host"), checkNotNull(creds.account,
"account"), creds.key, modules);
}
public BlobStoreContext<?, ?> createContext(URI blobStore, Credentials creds) {
return createContext(blobStore, creds, ImmutableSet.<Module> of());
}
public BlobStoreContext<?, ?> createContext(String hint, String account, String key) {
return createContext(hint, account, key, ImmutableSet.<Module> of());
}
@SuppressWarnings("unchecked")
public BlobStoreContext<?, ?> createContext(String hint, String account, String key,
Module... modules) {
Iterable<? extends Module> modules) {
checkNotNull(hint, "hint");
checkNotNull(account, "account");
String propertiesBuilderKey = String.format("%s.propertiesbuilder", hint);
@ -82,11 +97,10 @@ public class BlobStoreContextFactory {
.forName(propertiesBuilderClassName);
Class<BlobStoreContextBuilder<?, ?>> contextBuilderClass = (Class<BlobStoreContextBuilder<?, ?>>) Class
.forName(contextBuilderClassName);
HttpPropertiesBuilder builder = propertiesBuilderClass.getConstructor(String.class,
String.class).newInstance(account, key);
return contextBuilderClass.getConstructor(Properties.class).newInstance(builder.build())
.withModules(modules).buildContext();
.withModules(Iterables.toArray(modules, Module.class)).buildContext();
} catch (Exception e) {
throw new RuntimeException("error instantiating " + contextBuilderClassName, e);
}

View File

@ -200,4 +200,10 @@ public class MutableResourceMetadataImpl implements MutableResourceMetadata, Ser
this.location = location;
}
@Override
public String toString() {
return "[type=" + type + ", id=" + id + ", name=" + name + ", size=" + size
+ ", lastModified=" + lastModified + "]";
}
}

View File

@ -44,6 +44,9 @@ import java.util.List;
*
*/
public class GetOptions {
public static final GetOptions NONE = new GetOptions();
private final List<String> ranges = new ArrayList<String>();
private Date ifModifiedSince;
private Date ifUnmodifiedSince;
@ -171,8 +174,8 @@ public class GetOptions {
/**
* For use in the request header: If-None-Match
* <p />
* Return the object only if its payload tag (ETag) is different from the one specified, otherwise
* return a 304 (not modified).
* Return the object only if its payload tag (ETag) is different from the one specified,
* otherwise return a 304 (not modified).
*
* @see GetOptions#ifETagDoesntMatch(String)
*/

View File

@ -38,6 +38,8 @@ import static com.google.common.base.Preconditions.checkNotNull;
*/
public class ListContainerOptions extends ListOptions {
public static final ListContainerOptions NONE = new ListContainerOptions();
private String dir;
private boolean recursive;

View File

@ -37,6 +37,8 @@ import static com.google.common.base.Preconditions.checkNotNull;
*/
public class ListOptions {
public static final ListOptions NONE = new ListOptions();
private Integer maxKeys;
private String marker;
@ -67,7 +69,6 @@ public class ListOptions {
return this;
}
public static class Builder {
/**
@ -86,6 +87,5 @@ public class ListOptions {
return options.maxResults(maxKeys);
}
}
}

View File

@ -29,6 +29,8 @@ import javax.inject.Inject;
import org.jclouds.domain.Credentials;
import org.jclouds.http.HttpPropertiesBuilder;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.io.Resources;
import com.google.inject.Module;
@ -45,8 +47,8 @@ public class ComputeServiceContextFactory {
static Properties init() throws IOException {
Properties properties = new Properties();
properties.load(Resources.newInputStreamSupplier(
Resources.getResource("compute.properties")).getInput());
properties.load(Resources.newInputStreamSupplier(Resources.getResource("compute.properties"))
.getInput());
return properties;
}
@ -55,18 +57,32 @@ public class ComputeServiceContextFactory {
this.properties = properties;
}
public ComputeServiceContext<?, ?> createContext(URI computeService, Module... modules) {
return createContext(computeService, Credentials.parse(computeService), modules);
public ComputeServiceContext<?, ?> createContext(URI blobStore,
Iterable<? extends Module> modules) {
return createContext(blobStore, Credentials.parse(blobStore), modules);
}
public ComputeServiceContext<?, ?> createContext(URI computeService, Credentials creds, Module... modules) {
return createContext(checkNotNull(computeService.getHost(), "host"), checkNotNull(creds.account,
public ComputeServiceContext<?, ?> createContext(URI blobStore) {
return createContext(blobStore, ImmutableSet.<Module> of());
}
public ComputeServiceContext<?, ?> createContext(URI blobStore, Credentials creds,
Iterable<? extends Module> modules) {
return createContext(checkNotNull(blobStore.getHost(), "host"), checkNotNull(creds.account,
"account"), creds.key, modules);
}
public ComputeServiceContext<?, ?> createContext(URI blobStore, Credentials creds) {
return createContext(blobStore, creds, ImmutableSet.<Module> of());
}
public ComputeServiceContext<?, ?> createContext(String hint, String account, String key) {
return createContext(hint, account, key, ImmutableSet.<Module> of());
}
@SuppressWarnings("unchecked")
public ComputeServiceContext<?, ?> createContext(String hint, String account, String key,
Module... modules) {
Iterable<? extends Module> modules) {
checkNotNull(hint, "hint");
checkNotNull(account, "account");
String propertiesBuilderKey = String.format("%s.propertiesbuilder", hint);
@ -86,7 +102,7 @@ public class ComputeServiceContextFactory {
HttpPropertiesBuilder builder = propertiesBuilderClass.getConstructor(String.class,
String.class).newInstance(account, key);
return contextBuilderClass.getConstructor(Properties.class).newInstance(builder.build())
.withModules(modules).buildContext();
.withModules(Iterables.toArray(modules, Module.class)).buildContext();
} catch (Exception e) {
throw new RuntimeException("error instantiating " + contextBuilderClassName, e);
}

View File

@ -45,6 +45,7 @@ import org.jclouds.tools.ant.logging.config.AntLoggingModule;
import com.google.common.base.CaseFormat;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.MapMaker;
import com.google.common.io.Files;
import com.google.common.io.Resources;
@ -52,6 +53,7 @@ import com.google.inject.Module;
import com.google.inject.Provider;
/**
* @author Adrian Cole
* @author Ivan Meredith
*/
public class ComputeTask extends Task {
@ -61,11 +63,12 @@ public class ComputeTask extends Task {
* we don't have a reference to the project during the constructor, so we need to defer expansion
* with a Provider.
*/
private static Provider<Module[]> defaultModulesProvider = new Provider<Module[]>() {
private static Provider<Iterable<? extends Module>> defaultModulesProvider = new Provider<Iterable<? extends Module>>() {
@Override
public Module[] get() {
return new Module[] { new AntLoggingModule(project, ComputeServiceConstants.COMPUTE_LOGGER) };
public Iterable<Module> get() {
return ImmutableSet.of((Module) new AntLoggingModule(project,
ComputeServiceConstants.COMPUTE_LOGGER));
}
};

View File

@ -41,7 +41,6 @@ import org.jclouds.http.HttpUtils;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.google.inject.Module;
/**
@ -87,8 +86,8 @@ public class BlobStoreFileProvider extends AbstractOriginatingFileProvider {
.toChar(rootName.getUserName()))), UserAuthenticatorUtils
.toString(UserAuthenticatorUtils.getData(authData,
UserAuthenticationData.PASSWORD, UserAuthenticatorUtils
.toChar(rootName.getPassword())))),
Iterables.toArray(modules, Module.class)).getBlobStore();
.toChar(rootName.getPassword())))), modules)
.getBlobStore();
} catch (IOException e) {
throw new FileSystemException("vfs.provider.blobstore/properties.error", name, e);
} finally {