still failing matching the default image to the yaml images

This commit is contained in:
David Ribeiro Alves 2012-02-28 20:45:42 +00:00
parent 51e24096fe
commit 40a95be772
5 changed files with 163 additions and 136 deletions

View File

@ -29,6 +29,8 @@ import java.util.Map;
import javax.inject.Inject; import javax.inject.Inject;
import org.jclouds.compute.ComputeServiceAdapter; import org.jclouds.compute.ComputeServiceAdapter;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.HardwareBuilder;
import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.Template; import org.jclouds.compute.domain.Template;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
@ -192,4 +194,5 @@ public class VirtualBoxComputeServiceAdapter implements ComputeServiceAdapter<IM
throw Throwables.propagate(e); throw Throwables.propagate(e);
} }
} }
} }

View File

@ -23,7 +23,9 @@ import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_PRECO
import java.io.InputStream; import java.io.InputStream;
import java.net.URI; import java.net.URI;
import java.util.Collections;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import javax.inject.Named; import javax.inject.Named;
@ -37,6 +39,7 @@ import org.jclouds.compute.ComputeServiceAdapter;
import org.jclouds.compute.ComputeServiceAdapter.NodeAndInitialCredentials; import org.jclouds.compute.ComputeServiceAdapter.NodeAndInitialCredentials;
import org.jclouds.compute.config.ComputeServiceAdapterContextModule; import org.jclouds.compute.config.ComputeServiceAdapterContextModule;
import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.HardwareBuilder;
import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.NodeState; import org.jclouds.compute.domain.NodeState;
@ -61,7 +64,7 @@ import org.jclouds.virtualbox.functions.MasterImages;
import org.jclouds.virtualbox.functions.MasterLoader; import org.jclouds.virtualbox.functions.MasterLoader;
import org.jclouds.virtualbox.functions.NodeCreator; import org.jclouds.virtualbox.functions.NodeCreator;
import org.jclouds.virtualbox.functions.YamlImagesFromFileConfig; import org.jclouds.virtualbox.functions.YamlImagesFromFileConfig;
import org.jclouds.virtualbox.functions.admin.ImageFromYamlString; import org.jclouds.virtualbox.functions.admin.ImagesToYamlImagesFromYamlDescriptor;
import org.jclouds.virtualbox.functions.admin.StartJettyIfNotAlreadyRunning; import org.jclouds.virtualbox.functions.admin.StartJettyIfNotAlreadyRunning;
import org.jclouds.virtualbox.functions.admin.StartVBoxIfNotAlreadyRunning; import org.jclouds.virtualbox.functions.admin.StartVBoxIfNotAlreadyRunning;
import org.jclouds.virtualbox.predicates.SshResponds; import org.jclouds.virtualbox.predicates.SshResponds;
@ -80,7 +83,6 @@ import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader; import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache; import com.google.common.cache.LoadingCache;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import com.google.inject.Injector; import com.google.inject.Injector;
import com.google.inject.Provides; import com.google.inject.Provides;
import com.google.inject.TypeLiteral; import com.google.inject.TypeLiteral;
@ -117,7 +119,7 @@ public class VirtualBoxComputeServiceContextModule extends
}).to((Class) StartVBoxIfNotAlreadyRunning.class); }).to((Class) StartVBoxIfNotAlreadyRunning.class);
// the yaml config to image mapper // the yaml config to image mapper
bind(new TypeLiteral<Supplier<Map<Image, YamlImage>>>() { bind(new TypeLiteral<Supplier<Map<Image, YamlImage>>>() {
}).to((Class) ImageFromYamlString.class); }).to((Class) ImagesToYamlImagesFromYamlDescriptor.class);
// the yaml config provider // the yaml config provider
bind(new TypeLiteral<Supplier<String>>() { bind(new TypeLiteral<Supplier<String>>() {
}).to((Class) YamlImagesFromFileConfig.class); }).to((Class) YamlImagesFromFileConfig.class);
@ -140,7 +142,6 @@ public class VirtualBoxComputeServiceContextModule extends
bind(ExecutionType.class).toInstance(ExecutionType.GUI); bind(ExecutionType.class).toInstance(ExecutionType.GUI);
bind(LockType.class).toInstance(LockType.Write); bind(LockType.class).toInstance(LockType.Write);
} }
@Provides @Provides
@ -166,7 +167,6 @@ public class VirtualBoxComputeServiceContextModule extends
return VirtualBoxManager.createInstance(nodeSupplier.get().getId()); return VirtualBoxManager.createInstance(nodeSupplier.get().getId());
} }
@Override @Override
public String toString() { public String toString() {
return "createInstanceByNodeId()"; return "createInstanceByNodeId()";
@ -187,13 +187,15 @@ public class VirtualBoxComputeServiceContextModule extends
return new RetryablePredicate<SshClient>(sshResponds, timeouts.nodeRunning); return new RetryablePredicate<SshClient>(sshResponds, timeouts.nodeRunning);
} }
@Override
protected Supplier provideHardware(
ComputeServiceAdapter<IMachine, IMachine, Image, Location> adapter, Function<IMachine, Hardware> transformer) {
return Suppliers.ofInstance(Collections.singleton(new HardwareBuilder().id("").build()));
}
@Override @Override
protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) { protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) {
Supplier<Map<Image, YamlImage>> imagesSupplier = injector.getInstance(Supplier.class); return template.osFamily(OsFamily.UBUNTU).osVersionMatches("11.04");
// get the first image from the supplier
Image image = Iterables.getFirst(imagesSupplier.get().keySet(), null);
template.fromImage(image);
return template;
} }
@Provides @Provides
@ -211,22 +213,45 @@ public class VirtualBoxComputeServiceContextModule extends
@VisibleForTesting @VisibleForTesting
public static final Map<MachineState, NodeState> machineToNodeState = ImmutableMap public static final Map<MachineState, NodeState> machineToNodeState = ImmutableMap
.<MachineState, NodeState>builder().put(MachineState.Running, NodeState.RUNNING).put( .<MachineState, NodeState> builder()
MachineState.PoweredOff, NodeState.SUSPENDED) .put(MachineState.Running, NodeState.RUNNING)
.put(MachineState.DeletingSnapshot, NodeState.PENDING).put(MachineState.DeletingSnapshotOnline, .put(MachineState.PoweredOff,
NodeState.PENDING).put(MachineState.DeletingSnapshotPaused, NodeState.PENDING).put( NodeState.SUSPENDED)
MachineState.FaultTolerantSyncing, NodeState.PENDING).put(MachineState.LiveSnapshotting, .put(MachineState.DeletingSnapshot,
NodeState.PENDING).put(MachineState.SettingUp, NodeState.PENDING).put(MachineState.Starting, NodeState.PENDING)
NodeState.PENDING).put(MachineState.Stopping, NodeState.PENDING).put(MachineState.Restoring, .put(MachineState.DeletingSnapshotOnline,
NodeState.PENDING)
.put(MachineState.DeletingSnapshotPaused,
NodeState.PENDING)
.put(MachineState.FaultTolerantSyncing,
NodeState.PENDING)
.put(MachineState.LiveSnapshotting,
NodeState.PENDING)
.put(MachineState.SettingUp,
NodeState.PENDING)
.put(MachineState.Starting, NodeState.PENDING)
.put(MachineState.Stopping, NodeState.PENDING)
.put(MachineState.Restoring,
NodeState.PENDING) NodeState.PENDING)
// TODO What to map these states to? // TODO What to map these states to?
.put(MachineState.FirstOnline, NodeState.PENDING).put(MachineState.FirstTransient, NodeState.PENDING).put( .put(MachineState.FirstOnline,
MachineState.LastOnline, NodeState.PENDING).put(MachineState.LastTransient, NodeState.PENDING) NodeState.PENDING)
.put(MachineState.Teleported, NodeState.PENDING).put(MachineState.TeleportingIn, NodeState.PENDING).put( .put(MachineState.FirstTransient,
MachineState.TeleportingPausedVM, NodeState.PENDING) NodeState.PENDING)
.put(MachineState.LastOnline,
NodeState.PENDING)
.put(MachineState.LastTransient,
NodeState.PENDING)
.put(MachineState.Teleported,
NodeState.PENDING)
.put(MachineState.TeleportingIn,
NodeState.PENDING)
.put(MachineState.TeleportingPausedVM,
NodeState.PENDING)
.put(MachineState.Aborted, NodeState.ERROR)
.put(MachineState.Stuck, NodeState.ERROR)
.put(MachineState.Aborted, NodeState.ERROR).put(MachineState.Stuck, NodeState.ERROR) .put(MachineState.Null,
NodeState.UNRECOGNIZED).build();
.put(MachineState.Null, NodeState.UNRECOGNIZED).build();
} }

View File

@ -35,7 +35,6 @@ import javax.inject.Named;
import org.jclouds.Constants; import org.jclouds.Constants;
import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.Image;
import org.jclouds.config.ValueOfConfigurationKeyOrNull;
import org.jclouds.virtualbox.domain.HardDisk; import org.jclouds.virtualbox.domain.HardDisk;
import org.jclouds.virtualbox.domain.IsoSpec; import org.jclouds.virtualbox.domain.IsoSpec;
import org.jclouds.virtualbox.domain.MasterSpec; import org.jclouds.virtualbox.domain.MasterSpec;
@ -66,20 +65,21 @@ public class MasterImages extends AbstractLoadingCache<Image, IMachine> {
private final Map<Image, IMachine> masters = Maps.newHashMap(); private final Map<Image, IMachine> masters = Maps.newHashMap();
private final Function<MasterSpec, IMachine> mastersLoader; private final Function<MasterSpec, IMachine> mastersLoader;
private final Map<Image, YamlImage> imageMapping; private final Map<Image, YamlImage> imageMapping;
private final ValueOfConfigurationKeyOrNull cfg;
private final String workingDir; private final String workingDir;
private final String adminDisk; private final String adminDisk;
private String guestAdditionsIso; private String guestAdditionsIso;
private String installationKeySequence;
@Inject @Inject
public MasterImages(@Named(Constants.PROPERTY_BUILD_VERSION) String version, public MasterImages(@Named(Constants.PROPERTY_BUILD_VERSION) String version,
Function<MasterSpec, IMachine> masterLoader, ValueOfConfigurationKeyOrNull cfg, @Named(VIRTUALBOX_INSTALLATION_KEY_SEQUENCE) String installationKeySequence,
@Named(VIRTUALBOX_WORKINGDIR) String workingDir, Function<MasterSpec, IMachine> masterLoader,
Supplier<Map<Image, YamlImage>> yamlMapper) { Supplier<Map<Image, YamlImage>> yamlMapper) {
checkNotNull(version, "version"); checkNotNull(version, "version");
checkNotNull(installationKeySequence, "installationKeySequence");
this.mastersLoader = masterLoader; this.mastersLoader = masterLoader;
this.cfg = cfg; this.installationKeySequence = installationKeySequence;
this.workingDir = cfg.apply(VIRTUALBOX_WORKINGDIR) == null ? VIRTUALBOX_DEFAULT_DIR : cfg this.workingDir = workingDir == null ? VIRTUALBOX_DEFAULT_DIR : workingDir;
.apply(VIRTUALBOX_WORKINGDIR);
File wdFile = new File(workingDir); File wdFile = new File(workingDir);
if (!wdFile.exists()) { if (!wdFile.exists()) {
wdFile.mkdirs(); wdFile.mkdirs();
@ -96,10 +96,13 @@ public class MasterImages extends AbstractLoadingCache<Image, IMachine> {
return masters.get(key); return masters.get(key);
} }
checkNotNull(key, key);
checkState(new File(guestAdditionsIso).exists(), "guest additions iso does not exist at: " + guestAdditionsIso); checkState(new File(guestAdditionsIso).exists(), "guest additions iso does not exist at: " + guestAdditionsIso);
YamlImage yamlImage = imageMapping.get(key); YamlImage yamlImage = imageMapping.get(key);
checkNotNull(yamlImage, "could not find yaml image for image: " + key);
String vmName = VIRTUALBOX_IMAGE_PREFIX + yamlImage.id; String vmName = VIRTUALBOX_IMAGE_PREFIX + yamlImage.id;
HardDisk hardDisk = HardDisk.builder().diskpath(adminDisk).autoDelete(true).controllerPort(0).deviceSlot(1).build(); HardDisk hardDisk = HardDisk.builder().diskpath(adminDisk).autoDelete(true).controllerPort(0).deviceSlot(1).build();
@ -114,12 +117,8 @@ public class MasterImages extends AbstractLoadingCache<Image, IMachine> {
.builder() .builder()
.vm(vmSpecification) .vm(vmSpecification)
.iso( .iso(
IsoSpec IsoSpec.builder().sourcePath(yamlImage.iso)
.builder() .installationScript(installationKeySequence.replace("HOSTNAME", vmSpecification.getVmName())).build())
.sourcePath(yamlImage.iso)
.installationScript(
cfg.apply(VIRTUALBOX_INSTALLATION_KEY_SEQUENCE).replace("HOSTNAME", vmSpecification.getVmName()))
.build())
.network( .network(
NetworkSpec.builder() NetworkSpec.builder()
.natNetworkAdapter(0, NatAdapter.builder().tcpRedirectRule("127.0.0.1", 2222, "", 22).build()).build()) .natNetworkAdapter(0, NatAdapter.builder().tcpRedirectRule("127.0.0.1", 2222, "", 22).build()).build())

View File

@ -41,12 +41,12 @@ import com.google.common.collect.Maps;
* @author Andrea Turli * @author Andrea Turli
*/ */
@Singleton @Singleton
public class ImageFromYamlString implements Supplier<Map<Image, YamlImage>> { public class ImagesToYamlImagesFromYamlDescriptor implements Supplier<Map<Image, YamlImage>> {
private String yamlDescriptor; private String yamlDescriptor;
@Inject @Inject
public ImageFromYamlString(Supplier<String> yamlDescriptorSupplier) { public ImagesToYamlImagesFromYamlDescriptor(Supplier<String> yamlDescriptorSupplier) {
this.yamlDescriptor = yamlDescriptorSupplier.get(); this.yamlDescriptor = yamlDescriptorSupplier.get();
checkNotNull(yamlDescriptor, "yaml descriptor"); checkNotNull(yamlDescriptor, "yaml descriptor");
checkState(!yamlDescriptor.equals(""), "yaml descriptor is empty"); checkState(!yamlDescriptor.equals(""), "yaml descriptor is empty");

View File

@ -55,7 +55,7 @@ public class ImageFromYamlStringTest {
yamlFileLines.append(line).append("\n"); yamlFileLines.append(line).append("\n");
} }
ImageFromYamlString parser = new ImageFromYamlString(new Supplier<String>() { ImagesToYamlImagesFromYamlDescriptor parser = new ImagesToYamlImagesFromYamlDescriptor(new Supplier<String>() {
@Override @Override
public String get() { public String get() {