mirror of https://github.com/apache/jclouds.git
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:
parent
6ff6abd36c
commit
2d19e33828
|
@ -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"));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -48,6 +48,7 @@ import org.testng.annotations.AfterTest;
|
||||||
import org.testng.annotations.BeforeGroups;
|
import org.testng.annotations.BeforeGroups;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.inject.Guice;
|
import com.google.inject.Guice;
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
|
|
||||||
|
@ -68,11 +69,12 @@ public class EC2ComputeServiceLiveTest {
|
||||||
private ComputeServiceContext<?, ?> context;
|
private ComputeServiceContext<?, ?> context;
|
||||||
|
|
||||||
@BeforeGroups(groups = { "live" })
|
@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 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");
|
||||||
context = new ComputeServiceContextFactory().createContext("ec2", user, password,
|
context = new ComputeServiceContextFactory().createContext("ec2", user, password,
|
||||||
new Log4JLoggingModule());
|
ImmutableSet.of(new Log4JLoggingModule()));
|
||||||
Injector injector = Guice.createInjector(new JschSshClientModule());
|
Injector injector = Guice.createInjector(new JschSshClientModule());
|
||||||
sshFactory = injector.getInstance(SshClient.Factory.class);
|
sshFactory = injector.getInstance(SshClient.Factory.class);
|
||||||
SocketOpen socketOpen = injector.getInstance(SocketOpen.class);
|
SocketOpen socketOpen = injector.getInstance(SocketOpen.class);
|
||||||
|
|
|
@ -29,6 +29,8 @@ import javax.inject.Inject;
|
||||||
import org.jclouds.domain.Credentials;
|
import org.jclouds.domain.Credentials;
|
||||||
import org.jclouds.http.HttpPropertiesBuilder;
|
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.common.io.Resources;
|
||||||
import com.google.inject.Module;
|
import com.google.inject.Module;
|
||||||
|
|
||||||
|
@ -55,18 +57,31 @@ public class BlobStoreContextFactory {
|
||||||
this.properties = properties;
|
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);
|
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,
|
return createContext(checkNotNull(blobStore.getHost(), "host"), checkNotNull(creds.account,
|
||||||
"account"), creds.key, modules);
|
"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")
|
@SuppressWarnings("unchecked")
|
||||||
public BlobStoreContext<?, ?> createContext(String hint, String account, String key,
|
public BlobStoreContext<?, ?> createContext(String hint, String account, String key,
|
||||||
Module... modules) {
|
Iterable<? extends Module> modules) {
|
||||||
checkNotNull(hint, "hint");
|
checkNotNull(hint, "hint");
|
||||||
checkNotNull(account, "account");
|
checkNotNull(account, "account");
|
||||||
String propertiesBuilderKey = String.format("%s.propertiesbuilder", hint);
|
String propertiesBuilderKey = String.format("%s.propertiesbuilder", hint);
|
||||||
|
@ -82,11 +97,10 @@ public class BlobStoreContextFactory {
|
||||||
.forName(propertiesBuilderClassName);
|
.forName(propertiesBuilderClassName);
|
||||||
Class<BlobStoreContextBuilder<?, ?>> contextBuilderClass = (Class<BlobStoreContextBuilder<?, ?>>) Class
|
Class<BlobStoreContextBuilder<?, ?>> contextBuilderClass = (Class<BlobStoreContextBuilder<?, ?>>) Class
|
||||||
.forName(contextBuilderClassName);
|
.forName(contextBuilderClassName);
|
||||||
|
|
||||||
HttpPropertiesBuilder builder = propertiesBuilderClass.getConstructor(String.class,
|
HttpPropertiesBuilder builder = propertiesBuilderClass.getConstructor(String.class,
|
||||||
String.class).newInstance(account, key);
|
String.class).newInstance(account, key);
|
||||||
return contextBuilderClass.getConstructor(Properties.class).newInstance(builder.build())
|
return contextBuilderClass.getConstructor(Properties.class).newInstance(builder.build())
|
||||||
.withModules(modules).buildContext();
|
.withModules(Iterables.toArray(modules, Module.class)).buildContext();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException("error instantiating " + contextBuilderClassName, e);
|
throw new RuntimeException("error instantiating " + contextBuilderClassName, e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -200,4 +200,10 @@ public class MutableResourceMetadataImpl implements MutableResourceMetadata, Ser
|
||||||
this.location = location;
|
this.location = location;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "[type=" + type + ", id=" + id + ", name=" + name + ", size=" + size
|
||||||
|
+ ", lastModified=" + lastModified + "]";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -44,6 +44,9 @@ import java.util.List;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class GetOptions {
|
public class GetOptions {
|
||||||
|
|
||||||
|
public static final GetOptions NONE = new GetOptions();
|
||||||
|
|
||||||
private final List<String> ranges = new ArrayList<String>();
|
private final List<String> ranges = new ArrayList<String>();
|
||||||
private Date ifModifiedSince;
|
private Date ifModifiedSince;
|
||||||
private Date ifUnmodifiedSince;
|
private Date ifUnmodifiedSince;
|
||||||
|
@ -171,8 +174,8 @@ public class GetOptions {
|
||||||
/**
|
/**
|
||||||
* For use in the request header: If-None-Match
|
* For use in the request header: If-None-Match
|
||||||
* <p />
|
* <p />
|
||||||
* Return the object only if its payload tag (ETag) is different from the one specified, otherwise
|
* Return the object only if its payload tag (ETag) is different from the one specified,
|
||||||
* return a 304 (not modified).
|
* otherwise return a 304 (not modified).
|
||||||
*
|
*
|
||||||
* @see GetOptions#ifETagDoesntMatch(String)
|
* @see GetOptions#ifETagDoesntMatch(String)
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -38,6 +38,8 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
*/
|
*/
|
||||||
public class ListContainerOptions extends ListOptions {
|
public class ListContainerOptions extends ListOptions {
|
||||||
|
|
||||||
|
public static final ListContainerOptions NONE = new ListContainerOptions();
|
||||||
|
|
||||||
private String dir;
|
private String dir;
|
||||||
|
|
||||||
private boolean recursive;
|
private boolean recursive;
|
||||||
|
|
|
@ -37,6 +37,8 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
*/
|
*/
|
||||||
public class ListOptions {
|
public class ListOptions {
|
||||||
|
|
||||||
|
public static final ListOptions NONE = new ListOptions();
|
||||||
|
|
||||||
private Integer maxKeys;
|
private Integer maxKeys;
|
||||||
private String marker;
|
private String marker;
|
||||||
|
|
||||||
|
@ -67,7 +69,6 @@ public class ListOptions {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static class Builder {
|
public static class Builder {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -86,6 +87,5 @@ public class ListOptions {
|
||||||
return options.maxResults(maxKeys);
|
return options.maxResults(maxKeys);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,8 @@ import javax.inject.Inject;
|
||||||
import org.jclouds.domain.Credentials;
|
import org.jclouds.domain.Credentials;
|
||||||
import org.jclouds.http.HttpPropertiesBuilder;
|
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.common.io.Resources;
|
||||||
import com.google.inject.Module;
|
import com.google.inject.Module;
|
||||||
|
|
||||||
|
@ -45,8 +47,8 @@ public class ComputeServiceContextFactory {
|
||||||
|
|
||||||
static Properties init() throws IOException {
|
static Properties init() throws IOException {
|
||||||
Properties properties = new Properties();
|
Properties properties = new Properties();
|
||||||
properties.load(Resources.newInputStreamSupplier(
|
properties.load(Resources.newInputStreamSupplier(Resources.getResource("compute.properties"))
|
||||||
Resources.getResource("compute.properties")).getInput());
|
.getInput());
|
||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,18 +57,32 @@ public class ComputeServiceContextFactory {
|
||||||
this.properties = properties;
|
this.properties = properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ComputeServiceContext<?, ?> createContext(URI computeService, Module... modules) {
|
public ComputeServiceContext<?, ?> createContext(URI blobStore,
|
||||||
return createContext(computeService, Credentials.parse(computeService), modules);
|
Iterable<? extends Module> modules) {
|
||||||
|
return createContext(blobStore, Credentials.parse(blobStore), modules);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ComputeServiceContext<?, ?> createContext(URI computeService, Credentials creds, Module... modules) {
|
public ComputeServiceContext<?, ?> createContext(URI blobStore) {
|
||||||
return createContext(checkNotNull(computeService.getHost(), "host"), checkNotNull(creds.account,
|
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);
|
"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")
|
@SuppressWarnings("unchecked")
|
||||||
public ComputeServiceContext<?, ?> createContext(String hint, String account, String key,
|
public ComputeServiceContext<?, ?> createContext(String hint, String account, String key,
|
||||||
Module... modules) {
|
Iterable<? extends Module> modules) {
|
||||||
checkNotNull(hint, "hint");
|
checkNotNull(hint, "hint");
|
||||||
checkNotNull(account, "account");
|
checkNotNull(account, "account");
|
||||||
String propertiesBuilderKey = String.format("%s.propertiesbuilder", hint);
|
String propertiesBuilderKey = String.format("%s.propertiesbuilder", hint);
|
||||||
|
@ -86,7 +102,7 @@ public class ComputeServiceContextFactory {
|
||||||
HttpPropertiesBuilder builder = propertiesBuilderClass.getConstructor(String.class,
|
HttpPropertiesBuilder builder = propertiesBuilderClass.getConstructor(String.class,
|
||||||
String.class).newInstance(account, key);
|
String.class).newInstance(account, key);
|
||||||
return contextBuilderClass.getConstructor(Properties.class).newInstance(builder.build())
|
return contextBuilderClass.getConstructor(Properties.class).newInstance(builder.build())
|
||||||
.withModules(modules).buildContext();
|
.withModules(Iterables.toArray(modules, Module.class)).buildContext();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException("error instantiating " + contextBuilderClassName, e);
|
throw new RuntimeException("error instantiating " + contextBuilderClassName, e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,6 +45,7 @@ import org.jclouds.tools.ant.logging.config.AntLoggingModule;
|
||||||
|
|
||||||
import com.google.common.base.CaseFormat;
|
import com.google.common.base.CaseFormat;
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.MapMaker;
|
import com.google.common.collect.MapMaker;
|
||||||
import com.google.common.io.Files;
|
import com.google.common.io.Files;
|
||||||
import com.google.common.io.Resources;
|
import com.google.common.io.Resources;
|
||||||
|
@ -52,6 +53,7 @@ import com.google.inject.Module;
|
||||||
import com.google.inject.Provider;
|
import com.google.inject.Provider;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @author Adrian Cole
|
||||||
* @author Ivan Meredith
|
* @author Ivan Meredith
|
||||||
*/
|
*/
|
||||||
public class ComputeTask extends Task {
|
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
|
* we don't have a reference to the project during the constructor, so we need to defer expansion
|
||||||
* with a Provider.
|
* with a Provider.
|
||||||
*/
|
*/
|
||||||
private static Provider<Module[]> defaultModulesProvider = new Provider<Module[]>() {
|
private static Provider<Iterable<? extends Module>> defaultModulesProvider = new Provider<Iterable<? extends Module>>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Module[] get() {
|
public Iterable<Module> get() {
|
||||||
return new Module[] { new AntLoggingModule(project, ComputeServiceConstants.COMPUTE_LOGGER) };
|
return ImmutableSet.of((Module) new AntLoggingModule(project,
|
||||||
|
ComputeServiceConstants.COMPUTE_LOGGER));
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -41,7 +41,6 @@ import org.jclouds.http.HttpUtils;
|
||||||
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.Iterables;
|
|
||||||
import com.google.inject.Module;
|
import com.google.inject.Module;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -87,8 +86,8 @@ public class BlobStoreFileProvider extends AbstractOriginatingFileProvider {
|
||||||
.toChar(rootName.getUserName()))), UserAuthenticatorUtils
|
.toChar(rootName.getUserName()))), UserAuthenticatorUtils
|
||||||
.toString(UserAuthenticatorUtils.getData(authData,
|
.toString(UserAuthenticatorUtils.getData(authData,
|
||||||
UserAuthenticationData.PASSWORD, UserAuthenticatorUtils
|
UserAuthenticationData.PASSWORD, UserAuthenticatorUtils
|
||||||
.toChar(rootName.getPassword())))),
|
.toChar(rootName.getPassword())))), modules)
|
||||||
Iterables.toArray(modules, Module.class)).getBlobStore();
|
.getBlobStore();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new FileSystemException("vfs.provider.blobstore/properties.error", name, e);
|
throw new FileSystemException("vfs.provider.blobstore/properties.error", name, e);
|
||||||
} finally {
|
} finally {
|
||||||
|
|
Loading…
Reference in New Issue