Merge pull request #725 from dralves/nodepool

issue 558 - nodepool
This commit is contained in:
Adrian Cole 2012-07-19 04:38:59 -07:00
commit c4dde78b0c
13 changed files with 157 additions and 72 deletions

View File

@ -26,6 +26,7 @@ import static org.jclouds.nodepool.config.NodePoolProperties.MIN_SIZE;
import static org.jclouds.nodepool.config.NodePoolProperties.POOL_ADMIN_ACCESS;
import static org.jclouds.nodepool.config.NodePoolProperties.REMOVE_DESTROYED;
import java.io.File;
import java.net.URI;
import java.util.Properties;
@ -62,7 +63,6 @@ public class NodePoolApiMetadata extends BaseApiMetadata {
public static Properties defaultProperties() {
Properties properties = BaseRestApiMetadata.defaultProperties();
properties.setProperty("nodepool.identity", "nodepool-user");
properties.setProperty(BACKEND_GROUP, "nodepool");
properties.setProperty(METADATA_CONTAINER, "nodes");
properties.setProperty(BACKEND_MODULES,
@ -70,9 +70,12 @@ public class NodePoolApiMetadata extends BaseApiMetadata {
properties.setProperty(MAX_SIZE, 10 + "");
properties.setProperty(MIN_SIZE, 5 + "");
properties.setProperty(REMOVE_DESTROYED, "true");
// by default use the current user's user and private key
properties.setProperty(POOL_ADMIN_ACCESS, "adminUsername=" + System.getProperty("user.name")
+ ",adminPrivateKeyFile=" + System.getProperty("user.home") + "/.ssh/id_rsa");
// by default use the current user's user and private key if one exists, if not the properties
// will need to be set (no default passwords)
if (new File(System.getProperty("user.home") + "/.ssh/id_rsa").exists()) {
properties.setProperty(POOL_ADMIN_ACCESS, "adminUsername=" + System.getProperty("user.name")
+ ",adminPrivateKeyFile=" + System.getProperty("user.home") + "/.ssh/id_rsa");
}
return properties;
}

View File

@ -1,3 +1,22 @@
/*
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you 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.nodepool.config;
import javax.annotation.Nullable;
@ -44,6 +63,7 @@ public class NodePoolComputeServiceContextModule extends JCloudsNativeComputeSer
bind(ComputeServiceContext.class).to(NodePoolComputeServiceContext.class);
install(new LocationsFromComputeServiceAdapterModule<NodeMetadata, Hardware, Image, Location>() {
});
}
@Override

View File

@ -61,8 +61,10 @@ public abstract class BaseNodePoolComputeServiceAdapter implements NodePoolCompu
protected final AdminAccess.Builder initialCredentialsBuilder;
public BaseNodePoolComputeServiceAdapter(@Backend Supplier<ComputeService> backendComputeService,
@Backend Supplier<Template> backendTemplate, @Named(BACKEND_GROUP) String poolGroupName,
NodeMetadataStore metadataStore, @Named(POOL_ADMIN_ACCESS) String poolNodeAdminAccess,
@Backend Supplier<Template> backendTemplate, @Named(BACKEND_GROUP) String poolGroupName,
NodeMetadataStore metadataStore, @Named(POOL_ADMIN_ACCESS) String poolNodeAdminAccess,
AdminAccess.Configuration configuration) {
this.backendComputeService = backendComputeService;
this.poolGroupName = poolGroupName;

View File

@ -1,3 +1,21 @@
/*
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you 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.nodepool.internal;
import static com.google.common.base.Preconditions.checkNotNull;

View File

@ -1,3 +1,21 @@
/*
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you 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.nodepool.internal;
import java.util.HashMap;

View File

@ -23,6 +23,7 @@ import static org.jclouds.nodepool.config.NodePoolProperties.BACKEND_PROVIDER;
import static org.jclouds.nodepool.config.NodePoolProperties.BASEDIR;
import static org.jclouds.nodepool.config.NodePoolProperties.MAX_SIZE;
import static org.jclouds.nodepool.config.NodePoolProperties.MIN_SIZE;
import static org.jclouds.nodepool.config.NodePoolProperties.REMOVE_DESTROYED;
import static org.jclouds.scriptbuilder.domain.Statements.exec;
import java.io.File;
@ -41,7 +42,7 @@ import com.google.inject.Module;
/**
*
* @author Adrian Cole
* @author Adrian Cole, David Alves
*/
@Test(groups = "live", testName = "BYONBackendLiveTest")
public class BYONBackendLiveTest extends BaseComputeServiceContextLiveTest {
@ -61,6 +62,7 @@ public class BYONBackendLiveTest extends BaseComputeServiceContextLiveTest {
contextProperties.setProperty(BASEDIR, basedir);
contextProperties.setProperty(MAX_SIZE, 1 + "");
contextProperties.setProperty(MIN_SIZE, 1 + "");
contextProperties.setProperty(REMOVE_DESTROYED, false + "");
contextProperties.setProperty("nodepool.identity", System.getProperty("user.name"));
StringBuilder nodes = new StringBuilder();

View File

@ -18,6 +18,7 @@
*/
package org.jclouds.nodepool;
import static org.jclouds.nodepool.config.NodePoolProperties.POOL_ADMIN_ACCESS;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertSame;
@ -38,7 +39,6 @@ import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.NodeMetadata.Status;
import org.jclouds.compute.domain.NodeMetadataBuilder;
import org.jclouds.compute.options.TemplateOptions;
import org.jclouds.compute.strategy.PrioritizeCredentialsFromTemplate;
import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
import org.jclouds.nodepool.config.NodePoolProperties;
import org.jclouds.nodepool.internal.NodeMetadataStore;
@ -53,11 +53,9 @@ import com.google.inject.Injector;
/**
* @author Adrian Cole, David Alves
*/
@Test(groups = "unit")
public class NodeMetadataStoreTestDisabled {
// unit tests should have no dependencies, yet this one is failing on cloudbees:
// Guice creation errors: 1) Error injecting constructor, java.lang.IllegalArgumentException: key adminPrivateKeyFile value set to /home/hudson/.ssh/id_rsa, must be an existing file at org.jclouds.nodepool.internal.EagerNodePoolComputeServiceAdapter.<init>(EagerNodePoolComputeServiceAdapter.java:77) at
@Test(groups = "unit", testName = "NodeMetadataStoreTest")
public class NodeMetadataStoreTest {
@Inject
NodeMetadataStore store;
@ -84,6 +82,7 @@ public class NodeMetadataStoreTestDisabled {
overrides.setProperty(NodePoolProperties.BACKEND_PROVIDER, "stub");
overrides.setProperty(NodePoolProperties.MIN_SIZE, "0");
overrides.setProperty(NodePoolProperties.BASEDIR, baseDir);
overrides.setProperty(POOL_ADMIN_ACCESS, "adminUsername=pooluser,adminPassword=poolpass");
// note no ssh module since we are stub and not trying ssh, yet
overrides.setProperty(NodePoolProperties.BACKEND_MODULES, SLF4JLoggingModule.class.getName());
Context nodePoolCtx = ContextBuilder.newBuilder("nodepool").credentials("foo", "bar").overrides(overrides)
@ -102,13 +101,6 @@ public class NodeMetadataStoreTestDisabled {
+ "\"user\":\"testuser\",\"password\":\"testpass\",\"privateKey\":\"pk\",\"authenticateSudo\":true}");
}
@Test(groups = "unit", dependsOnMethods = "testStore")
public void testCredentialsFromStoreOverrideBackendCredentials() {
// test that node store credentials are not overriden from somewhere else
assertNull(createInjector().getBinding(PrioritizeCredentialsFromTemplate.class).getProvider().get()
.apply(null, null));
}
@Test(groups = "unit", dependsOnMethods = "testStore")
public void testLoad() {
NodeMetadata loaded = store.load(nodeMeta1);

View File

@ -18,6 +18,7 @@
*/
package org.jclouds.nodepool;
import static org.jclouds.nodepool.config.NodePoolProperties.POOL_ADMIN_ACCESS;
import static org.testng.Assert.assertEquals;
import java.io.File;
@ -41,27 +42,22 @@ import com.google.inject.TypeLiteral;
@Test(groups = "unit", testName = "NodePoolComputeServiceContextTest")
public class NodePoolComputeServiceContextTest {
//TODO: identity became nodepool-user
@Test(enabled = false)
public void testBinds() {
final String basedir = "target/" + this.getClass().getSimpleName();
new File(basedir).delete();
Properties overrides = new Properties();
overrides.setProperty(NodePoolProperties.BACKEND_PROVIDER, "stub");
overrides.setProperty(NodePoolProperties.BASEDIR, basedir);
// note no ssh module since we are stub and not trying ssh, yet
overrides.setProperty(NodePoolProperties.BACKEND_MODULES, SLF4JLoggingModule.class.getName());
ComputeService stub = ContextBuilder.newBuilder("nodepool")
.credentials("foo", "bar")
.endpoint("gooend")
.apiVersion("1.1")
.buildVersion("1.1-2")
.overrides(overrides)
.buildInjector().getInstance(Key.get(new TypeLiteral<Supplier<ComputeService>>(){}, Backend.class)).get();
overrides.setProperty(POOL_ADMIN_ACCESS, "adminUsername=pooluser,adminPassword=poolpass");
ComputeService stub = ContextBuilder.newBuilder("nodepool").credentials("foo", "bar").endpoint("gooend")
.apiVersion("1.1").buildVersion("1.1-2").overrides(overrides).buildInjector()
.getInstance(Key.get(new TypeLiteral<Supplier<ComputeService>>() {
}, Backend.class)).get();
assertEquals(stub.getContext().unwrap().getIdentity(), "foo");
assertEquals(stub.getContext().utils().injector().getInstance(Key.get(String.class, Credential.class)), "bar");
assertEquals(stub.getContext().unwrap().getProviderMetadata().getEndpoint(), "gooend");
@ -73,5 +69,4 @@ public class NodePoolComputeServiceContextTest {
}
}

View File

@ -67,7 +67,8 @@ import com.google.common.io.Closeables;
import com.google.inject.Module;
public class NodePoolComputeServiceLiveTest extends BaseComputeServiceLiveTest {
final String basedir = "target/" + this.getClass().getSimpleName().toLowerCase();
private final String basedir = "target/" + this.getClass().getSimpleName().toLowerCase();
public NodePoolComputeServiceLiveTest() {
provider = "nodepool";
@ -76,6 +77,9 @@ public class NodePoolComputeServiceLiveTest extends BaseComputeServiceLiveTest {
@Override
protected Properties setupProperties() {
Properties contextProperties = super.setupProperties();
contextProperties.setProperty(BASEDIR, basedir);
contextProperties.setProperty("nodepool.identity", "pooluser");
contextProperties.setProperty(POOL_ADMIN_ACCESS, "adminUsername=pooluser,adminPassword=poolpassword");
contextProperties.setProperty(TIMEOUT_SCRIPT_COMPLETE, (1200 * 1000) + "");
contextProperties.setProperty(TIMEOUT_PORT_OPEN, (1200 * 1000) + "");
contextProperties.setProperty(BASEDIR, basedir);
@ -102,7 +106,7 @@ public class NodePoolComputeServiceLiveTest extends BaseComputeServiceLiveTest {
}
@Override
@Test(enabled = true)
@Test(enabled = true, groups = "live")
public void testCreateAndRunAService() throws Exception {
this.group = this.group + "s";
final String configuration = Strings2.toStringAndClose(RunScriptData.class
@ -125,6 +129,11 @@ public class NodePoolComputeServiceLiveTest extends BaseComputeServiceLiveTest {
watch.reset().start();
// note this is a dependency on the template resolution so we have the
// right process per
// operating system. moreover, we wish this to run as root, so that it
// can change ip
// tables rules and setup our admin user
client.runScriptOnNode(nodeId, installAdminUserJBossAndOpenPorts(node.getOperatingSystem()),
nameTask("configure-jboss"));
@ -170,7 +179,7 @@ public class NodePoolComputeServiceLiveTest extends BaseComputeServiceLiveTest {
}), "jboss", node, JBOSS_PATTERN);
}
@Test(enabled = true, dependsOnMethods = "testCreateAndRunAService")
@Test(enabled = true, groups = "live", dependsOnMethods = "testCreateAndRunAService")
public void testRebuildPoolStateFromStore() {
tearDownContext();
setupContext();
@ -178,13 +187,13 @@ public class NodePoolComputeServiceLiveTest extends BaseComputeServiceLiveTest {
assertEquals(((NodeMetadata) Iterables.get(client.listNodes(), 0)).getGroup(), this.group);
}
@Test(enabled = false, dependsOnMethods = "testRebuildPoolStateFromStore")
@Test(enabled = true, groups = "live", dependsOnMethods = "testRebuildPoolStateFromStore")
public void testIncreasePoolAllowed() throws RunNodesException {
client.createNodesInGroup(this.group, 1);
assertSame(client.listNodes().size(), 2);
}
@Test(enabled = false, dependsOnMethods = "testIncreasePoolAllowed")
@Test(enabled = true, groups = "live", dependsOnMethods = "testIncreasePoolAllowed")
public void testIncreasePoolNotAllowed() throws RunNodesException {
boolean caughtException = false;
try {
@ -195,7 +204,7 @@ public class NodePoolComputeServiceLiveTest extends BaseComputeServiceLiveTest {
assertTrue(caughtException, "expected an exception to be thrown");
}
@Test(enabled = true, dependsOnMethods = "testRebuildPoolStateFromStore")
@Test(enabled = true, groups = "live", dependsOnMethods = "testIncreasePoolNotAllowed")
public void testGetBackendComputeServiceContext() {
NodePoolComputeServiceContext ctx = context.utils().injector().getInstance(NodePoolComputeServiceContext.class);
assertNotNull(ctx.getBackendContext());
@ -204,7 +213,7 @@ public class NodePoolComputeServiceLiveTest extends BaseComputeServiceLiveTest {
NodePredicates.inGroup(ctx.getPoolGroupName())).size(), 2);
}
@Test(enabled = false, dependsOnMethods = "testGetBackendComputeServiceContext")
@Test(enabled = false, groups = "live", dependsOnMethods = "testGetBackendComputeServiceContext")
public void testDestroyPoolNodes() {
client.destroyNodesMatching(NodePredicates.inGroup(this.group));
// after we destroy all nodes we should still have minsize nodes in the pool
@ -212,7 +221,7 @@ public class NodePoolComputeServiceLiveTest extends BaseComputeServiceLiveTest {
assertSame(ctx.getPoolStats().currentSize(), 1);
}
@Test(enabled = true, dependsOnMethods = "testGetBackendComputeServiceContext")
@Test(enabled = true, groups = "live", dependsOnMethods = "testGetBackendComputeServiceContext")
public void testDestroyPool() {
// TODO get the ctx without the injector
NodePoolComputeServiceContext ctx = context.utils().injector().getInstance(NodePoolComputeServiceContext.class);
@ -223,7 +232,7 @@ public class NodePoolComputeServiceLiveTest extends BaseComputeServiceLiveTest {
}
@Override
@Test(enabled = false, dependsOnMethods = "testCompareSizes")
@Test(enabled = false)
public void testAScriptExecutionAfterBootWithBasicTemplate() throws Exception {
}
@ -233,7 +242,7 @@ public class NodePoolComputeServiceLiveTest extends BaseComputeServiceLiveTest {
}
@Override
@Test(enabled = false, dependsOnMethods = "testCompareSizes")
@Test(enabled = false)
public void testConcurrentUseOfComputeServiceToCreateNodes() throws Exception {
}

View File

@ -18,6 +18,8 @@
*/
package org.jclouds.nodepool.config;
import static org.easymock.EasyMock.createNiceMock;
import static org.jclouds.nodepool.config.NodePoolProperties.POOL_ADMIN_ACCESS;
import static org.testng.Assert.assertEquals;
import java.io.File;
@ -25,13 +27,19 @@ import java.util.Properties;
import org.jclouds.ContextBuilder;
import org.jclouds.compute.ComputeService;
import org.jclouds.domain.Credentials;
import org.jclouds.domain.LoginCredentials;
import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
import org.jclouds.nodepool.Backend;
import org.jclouds.rest.annotations.Credential;
import org.jclouds.ssh.SshClient;
import org.testng.annotations.Test;
import com.google.common.base.Supplier;
import com.google.common.net.HostAndPort;
import com.google.inject.AbstractModule;
import com.google.inject.Key;
import com.google.inject.Scopes;
import com.google.inject.TypeLiteral;
/**
@ -40,26 +48,23 @@ import com.google.inject.TypeLiteral;
@Test(groups = "unit", testName = "BindBackendComputeServiceTest")
public class BindBackendComputeServiceTest {
//TODO: identity became nodepool-user
@Test(enabled = false)
public void testBinds() {
final String basedir = "target/" + this.getClass().getSimpleName();
new File(basedir).delete();
Properties overrides = new Properties();
overrides.setProperty(NodePoolProperties.BACKEND_PROVIDER, "stub");
overrides.setProperty(NodePoolProperties.BASEDIR, basedir);
// note no ssh module since we are stub and not trying ssh, yet
overrides.setProperty(NodePoolProperties.BACKEND_MODULES, SLF4JLoggingModule.class.getName());
overrides.setProperty(NodePoolProperties.BACKEND_MODULES, SLF4JLoggingModule.class.getName() + ","
+ StubSshClientModule.class.getName());
overrides.setProperty(POOL_ADMIN_ACCESS, "adminUsername=pooluser,adminPassword=poolpass");
ComputeService stub = ContextBuilder.newBuilder("nodepool").credentials("foo", "bar").endpoint("gooend")
.apiVersion("1.1").buildVersion("1.1-2").overrides(overrides).buildInjector()
.getInstance(Key.get(new TypeLiteral<Supplier<ComputeService>>() {
}, Backend.class)).get();
ComputeService stub = ContextBuilder.newBuilder("nodepool")
.credentials("foo", "bar")
.endpoint("gooend")
.apiVersion("1.1")
.buildVersion("1.1-2")
.overrides(overrides)
.buildInjector().getInstance(Key.get(new TypeLiteral<Supplier<ComputeService>>(){}, Backend.class)).get();
assertEquals(stub.getContext().unwrap().getIdentity(), "foo");
assertEquals(stub.getContext().utils().injector().getInstance(Key.get(String.class, Credential.class)), "bar");
assertEquals(stub.getContext().unwrap().getProviderMetadata().getEndpoint(), "gooend");
@ -71,5 +76,23 @@ public class BindBackendComputeServiceTest {
}
public static class StubSshClientModule extends AbstractModule {
protected void configure() {
bind(SshClient.Factory.class).to(Factory.class).in(Scopes.SINGLETON);
}
private static class Factory implements SshClient.Factory {
@Override
public SshClient create(HostAndPort socket, LoginCredentials credentials) {
return createNiceMock(SshClient.class);
}
@Override
public SshClient create(HostAndPort socket, Credentials credentials) {
return createNiceMock(SshClient.class);
}
}
}
}

View File

@ -41,24 +41,23 @@ import com.google.inject.name.Names;
@Test(groups = "unit", testName = "BindInputStreamToFilesystemBlobStoreTest")
public class BindInputStreamToFilesystemBlobStoreTest {
//TODO: binding error
@Test(enabled = false)
public void testCreatesDir() {
final String basedir = "target/" + this.getClass().getSimpleName();
new File(basedir).delete();
Map<String, InputStream> file = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
bindConstant().annotatedWith(Names.named(NodePoolProperties.BASEDIR)).to(basedir);
bindConstant().annotatedWith(Names.named(NodePoolProperties.METADATA_CONTAINER)).to("barr");
bindConstant().annotatedWith(Names.named(NodePoolProperties.BACKEND_MODULES)).to(
SLF4JLoggingModule.class.getName());
}
}, new BindInputStreamToFilesystemBlobStore()).getInstance(
Key.get(new TypeLiteral<Supplier<Map<String, InputStream>>>() {
})).get();
Map<String, InputStream> file = Guice
.createInjector(new AbstractModule() {
@Override
protected void configure() {
bindConstant().annotatedWith(Names.named(NodePoolProperties.BASEDIR)).to(basedir);
bindConstant().annotatedWith(Names.named(NodePoolProperties.METADATA_CONTAINER)).to("barr");
bindConstant().annotatedWith(Names.named(NodePoolProperties.POOL_ADMIN_ACCESS)).to(
"adminUsername=pooluser,adminPassword=poolpass");
bindConstant().annotatedWith(Names.named(NodePoolProperties.BACKEND_MODULES)).to(
SLF4JLoggingModule.class.getName());
}
}, new BindInputStreamToFilesystemBlobStore())
.getInstance(Key.get(new TypeLiteral<Supplier<Map<String, InputStream>>>() {
}, Names.named("METADATA"))).get();
assert (new File(basedir + "/barr").exists());
assertEquals(file.keySet(), ImmutableSet.of());

View File

@ -1,5 +1,5 @@
<?xml version="1.0"?>
<configuration scan="false">
<configuration scan="false">
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>target/test-data/jclouds.log</file>

View File

@ -10,6 +10,8 @@ import java.util.List;
import org.jclouds.javax.annotation.Nullable;
import clojure.main;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Objects;
import com.google.common.base.Splitter;
@ -64,6 +66,8 @@ import com.google.common.collect.ImmutableMap;
public class AdminAccessBuilderSpec {
private static final long serialVersionUID = -379469670373111569L;
/** Parses a single value. */
protected static interface ValueParser {
void parse(AdminAccessBuilderSpec spec, String key, @Nullable String value);