addressed the issues raised in adrian's review

This commit is contained in:
David Ribeiro Alves 2012-03-10 15:58:43 +00:00
parent 4412aaf726
commit a77e4fda7d
6 changed files with 86 additions and 7 deletions

View File

@ -20,6 +20,7 @@
package org.jclouds.virtualbox.compute;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.collect.Iterables.filter;
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_IMAGE_PREFIX;
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_NODE_PREFIX;
@ -90,7 +91,7 @@ public class VirtualBoxComputeServiceAdapter implements ComputeServiceAdapter<IM
Template template) {
try {
Master master = mastersLoader.get(template.getImage());
checkNotNull(master, "could not find a master for image: "+template.getClass());
checkState(master != null, "could not find a master for image: "+template.getClass());
NodeSpec nodeSpec = NodeSpec.builder().master(master).name(name).tag(tag).template(template).build();
return cloneCreator.apply(nodeSpec);
} catch (Exception e) {

View File

@ -24,6 +24,8 @@ import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Collections;
import java.util.Set;
import javax.annotation.Nullable;
import org.virtualbox_4_1.NATProtocol;
import org.virtualbox_4_1.NetworkAttachmentType;
@ -117,7 +119,7 @@ public class NetworkAdapter {
return this;
}
public Builder staticIp(String staticIp) {
public Builder staticIp(@Nullable String staticIp) {
this.staticIp = staticIp;
return this;
}

View File

@ -76,6 +76,7 @@ import com.google.common.collect.Maps;
@Singleton
public class MastersCache extends AbstractLoadingCache<Image, Master> {
// TODO parameterize
public static final int MASTER_PORT = 2222;
@Resource

View File

@ -1,5 +1,5 @@
/**
mh * Licensed to jclouds, Inc. (jclouds) under one or more
* 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
@ -54,10 +54,18 @@ import com.google.common.base.Supplier;
@Singleton
public class NodeCreator implements Function<NodeSpec, NodeAndInitialCredentials<IMachine>> {
// TODO parameterize
public static final int NODE_PORT_INIT = 3000;
// TODO parameterize
public static final String VMS_NETWORK = "33.33.33.";
// TODO parameterize
public static final String HOST_ONLY_IFACE_NAME = "vboxnet0";
// TODO parameterize
public static final boolean USE_LINKED = true;
private final Supplier<VirtualBoxManager> manager;
private final Function<CloneSpec, IMachine> cloner;
private final AtomicInteger nodePorts;
@ -70,7 +78,7 @@ public class NodeCreator implements Function<NodeSpec, NodeAndInitialCredentials
MachineUtils machineUtils, Function<IMachine, NodeMetadata> imachineToNodeMetadata) {
this.manager = manager;
this.cloner = cloner;
this.nodePorts = new AtomicInteger(3000);
this.nodePorts = new AtomicInteger(NODE_PORT_INIT);
this.nodeIps = new AtomicInteger(1);
this.machineUtils = machineUtils;
this.imachineToNodeMetadata = imachineToNodeMetadata;
@ -115,7 +123,7 @@ public class NodeCreator implements Function<NodeSpec, NodeAndInitialCredentials
NetworkSpec networkSpec = NetworkSpec.builder().addNIC(natIfaceCard).addNIC(hostOnlyIfaceCard).build();
CloneSpec cloneSpec = CloneSpec.builder().linked(true).master(master.getMachine()).network(networkSpec)
CloneSpec cloneSpec = CloneSpec.builder().linked(USE_LINKED).master(master.getMachine()).network(networkSpec)
.vm(cloneVmSpec).build();
IMachine cloned = cloner.apply(cloneSpec);

View File

@ -25,7 +25,6 @@ import java.io.File;
import java.net.URI;
import java.util.Properties;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import javax.inject.Inject;
import javax.inject.Named;
@ -41,6 +40,7 @@ import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.domain.Template;
import org.jclouds.compute.strategy.PrioritizeCredentialsFromTemplate;
import org.jclouds.concurrent.MoreExecutors;
import org.jclouds.concurrent.config.ExecutorServiceModule;
import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
import org.jclouds.sshj.config.SshjSshClientModule;
@ -112,7 +112,7 @@ public class BaseVirtualBoxClientLiveTest extends BaseVersionedServiceLiveTest {
@Inject
protected LoadingCache<Image, Master> mastersCache;
private final ExecutorService singleThreadExec = Executors.newSingleThreadExecutor();
private final ExecutorService singleThreadExec = MoreExecutors.sameThreadExecutor();
@Override
protected void setupCredentials() {

View File

@ -0,0 +1,67 @@
/**
* 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.virtualbox.statements;
import static junit.framework.Assert.assertEquals;
import org.jclouds.scriptbuilder.domain.OsFamily;
import org.jclouds.virtualbox.domain.NetworkAdapter;
import org.jclouds.virtualbox.domain.NetworkInterfaceCard;
import org.testng.annotations.Test;
import org.virtualbox_4_1.NetworkAttachmentType;
public class SetIpAddressTest {
@Test
public void testSetIpeth0() {
NetworkInterfaceCard networkInterfaceCard = NetworkInterfaceCard
.builder()
.slot(0L)
.addNetworkAdapter(
NetworkAdapter.builder().staticIp("127.0.0.1").networkAttachmentType(NetworkAttachmentType.NAT)
.build()).build();
SetIpAddress setIpAddressStmtm = new SetIpAddress(networkInterfaceCard);
assertEquals("ifconfig eth0 127.0.0.1;", setIpAddressStmtm.render(OsFamily.UNIX));
}
@Test
public void testSetIpeth3() {
NetworkInterfaceCard networkInterfaceCard = NetworkInterfaceCard
.builder()
.slot(3L)
.addNetworkAdapter(
NetworkAdapter.builder().staticIp("localhost").networkAttachmentType(NetworkAttachmentType.NAT)
.build()).build();
SetIpAddress setIpAddressStmtm = new SetIpAddress(networkInterfaceCard);
assertEquals("ifconfig eth3 localhost;", setIpAddressStmtm.render(OsFamily.UNIX));
}
@Test(expectedExceptions = IllegalArgumentException.class)
public void testThrowsIllegalArgumentExceptionOnWrongSlot() {
NetworkInterfaceCard networkInterfaceCard = NetworkInterfaceCard
.builder()
.slot(4L)
.addNetworkAdapter(
NetworkAdapter.builder().staticIp("localhost").networkAttachmentType(NetworkAttachmentType.NAT)
.build()).build();
SetIpAddress setIpAddressStmtm = new SetIpAddress(networkInterfaceCard);
}
}