mirror of https://github.com/apache/jclouds.git
still failing matching the default image to the yaml images
This commit is contained in:
parent
51e24096fe
commit
40a95be772
|
@ -29,6 +29,8 @@ import java.util.Map;
|
|||
import javax.inject.Inject;
|
||||
|
||||
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.Template;
|
||||
import org.jclouds.domain.Location;
|
||||
|
@ -192,4 +194,5 @@ public class VirtualBoxComputeServiceAdapter implements ComputeServiceAdapter<IM
|
|||
throw Throwables.propagate(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -23,7 +23,9 @@ import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_PRECO
|
|||
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import javax.inject.Named;
|
||||
|
@ -37,6 +39,7 @@ import org.jclouds.compute.ComputeServiceAdapter;
|
|||
import org.jclouds.compute.ComputeServiceAdapter.NodeAndInitialCredentials;
|
||||
import org.jclouds.compute.config.ComputeServiceAdapterContextModule;
|
||||
import org.jclouds.compute.domain.Hardware;
|
||||
import org.jclouds.compute.domain.HardwareBuilder;
|
||||
import org.jclouds.compute.domain.Image;
|
||||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
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.NodeCreator;
|
||||
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.StartVBoxIfNotAlreadyRunning;
|
||||
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.LoadingCache;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
@ -117,7 +119,7 @@ public class VirtualBoxComputeServiceContextModule extends
|
|||
}).to((Class) StartVBoxIfNotAlreadyRunning.class);
|
||||
// the yaml config to image mapper
|
||||
bind(new TypeLiteral<Supplier<Map<Image, YamlImage>>>() {
|
||||
}).to((Class) ImageFromYamlString.class);
|
||||
}).to((Class) ImagesToYamlImagesFromYamlDescriptor.class);
|
||||
// the yaml config provider
|
||||
bind(new TypeLiteral<Supplier<String>>() {
|
||||
}).to((Class) YamlImagesFromFileConfig.class);
|
||||
|
@ -140,7 +142,6 @@ public class VirtualBoxComputeServiceContextModule extends
|
|||
|
||||
bind(ExecutionType.class).toInstance(ExecutionType.GUI);
|
||||
bind(LockType.class).toInstance(LockType.Write);
|
||||
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
@ -166,7 +167,6 @@ public class VirtualBoxComputeServiceContextModule extends
|
|||
return VirtualBoxManager.createInstance(nodeSupplier.get().getId());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "createInstanceByNodeId()";
|
||||
|
@ -187,13 +187,15 @@ public class VirtualBoxComputeServiceContextModule extends
|
|||
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
|
||||
protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) {
|
||||
Supplier<Map<Image, YamlImage>> imagesSupplier = injector.getInstance(Supplier.class);
|
||||
// get the first image from the supplier
|
||||
Image image = Iterables.getFirst(imagesSupplier.get().keySet(), null);
|
||||
template.fromImage(image);
|
||||
return template;
|
||||
return template.osFamily(OsFamily.UBUNTU).osVersionMatches("11.04");
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
@ -211,22 +213,45 @@ public class VirtualBoxComputeServiceContextModule extends
|
|||
|
||||
@VisibleForTesting
|
||||
public static final Map<MachineState, NodeState> machineToNodeState = ImmutableMap
|
||||
.<MachineState, NodeState>builder().put(MachineState.Running, NodeState.RUNNING).put(
|
||||
MachineState.PoweredOff, NodeState.SUSPENDED)
|
||||
.put(MachineState.DeletingSnapshot, NodeState.PENDING).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,
|
||||
.<MachineState, NodeState> builder()
|
||||
.put(MachineState.Running, NodeState.RUNNING)
|
||||
.put(MachineState.PoweredOff,
|
||||
NodeState.SUSPENDED)
|
||||
.put(MachineState.DeletingSnapshot,
|
||||
NodeState.PENDING)
|
||||
.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)
|
||||
// TODO What to map these states to?
|
||||
.put(MachineState.FirstOnline, NodeState.PENDING).put(MachineState.FirstTransient, 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.FirstOnline,
|
||||
NodeState.PENDING)
|
||||
.put(MachineState.FirstTransient,
|
||||
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();
|
||||
|
||||
}
|
||||
|
|
|
@ -35,7 +35,6 @@ import javax.inject.Named;
|
|||
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.compute.domain.Image;
|
||||
import org.jclouds.config.ValueOfConfigurationKeyOrNull;
|
||||
import org.jclouds.virtualbox.domain.HardDisk;
|
||||
import org.jclouds.virtualbox.domain.IsoSpec;
|
||||
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 Function<MasterSpec, IMachine> mastersLoader;
|
||||
private final Map<Image, YamlImage> imageMapping;
|
||||
private final ValueOfConfigurationKeyOrNull cfg;
|
||||
private final String workingDir;
|
||||
private final String adminDisk;
|
||||
private String guestAdditionsIso;
|
||||
private String installationKeySequence;
|
||||
|
||||
@Inject
|
||||
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) {
|
||||
checkNotNull(version, "version");
|
||||
checkNotNull(installationKeySequence, "installationKeySequence");
|
||||
this.mastersLoader = masterLoader;
|
||||
this.cfg = cfg;
|
||||
this.workingDir = cfg.apply(VIRTUALBOX_WORKINGDIR) == null ? VIRTUALBOX_DEFAULT_DIR : cfg
|
||||
.apply(VIRTUALBOX_WORKINGDIR);
|
||||
this.installationKeySequence = installationKeySequence;
|
||||
this.workingDir = workingDir == null ? VIRTUALBOX_DEFAULT_DIR : workingDir;
|
||||
File wdFile = new File(workingDir);
|
||||
if (!wdFile.exists()) {
|
||||
wdFile.mkdirs();
|
||||
|
@ -96,10 +96,13 @@ public class MasterImages extends AbstractLoadingCache<Image, IMachine> {
|
|||
return masters.get(key);
|
||||
}
|
||||
|
||||
checkNotNull(key, key);
|
||||
checkState(new File(guestAdditionsIso).exists(), "guest additions iso does not exist at: " + guestAdditionsIso);
|
||||
|
||||
YamlImage yamlImage = imageMapping.get(key);
|
||||
|
||||
checkNotNull(yamlImage, "could not find yaml image for image: " + key);
|
||||
|
||||
String vmName = VIRTUALBOX_IMAGE_PREFIX + yamlImage.id;
|
||||
|
||||
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()
|
||||
.vm(vmSpecification)
|
||||
.iso(
|
||||
IsoSpec
|
||||
.builder()
|
||||
.sourcePath(yamlImage.iso)
|
||||
.installationScript(
|
||||
cfg.apply(VIRTUALBOX_INSTALLATION_KEY_SEQUENCE).replace("HOSTNAME", vmSpecification.getVmName()))
|
||||
.build())
|
||||
IsoSpec.builder().sourcePath(yamlImage.iso)
|
||||
.installationScript(installationKeySequence.replace("HOSTNAME", vmSpecification.getVmName())).build())
|
||||
.network(
|
||||
NetworkSpec.builder()
|
||||
.natNetworkAdapter(0, NatAdapter.builder().tcpRedirectRule("127.0.0.1", 2222, "", 22).build()).build())
|
||||
|
|
|
@ -41,12 +41,12 @@ import com.google.common.collect.Maps;
|
|||
* @author Andrea Turli
|
||||
*/
|
||||
@Singleton
|
||||
public class ImageFromYamlString implements Supplier<Map<Image, YamlImage>> {
|
||||
public class ImagesToYamlImagesFromYamlDescriptor implements Supplier<Map<Image, YamlImage>> {
|
||||
|
||||
private String yamlDescriptor;
|
||||
|
||||
@Inject
|
||||
public ImageFromYamlString(Supplier<String> yamlDescriptorSupplier) {
|
||||
public ImagesToYamlImagesFromYamlDescriptor(Supplier<String> yamlDescriptorSupplier) {
|
||||
this.yamlDescriptor = yamlDescriptorSupplier.get();
|
||||
checkNotNull(yamlDescriptor, "yaml descriptor");
|
||||
checkState(!yamlDescriptor.equals(""), "yaml descriptor is empty");
|
|
@ -55,7 +55,7 @@ public class ImageFromYamlStringTest {
|
|||
yamlFileLines.append(line).append("\n");
|
||||
}
|
||||
|
||||
ImageFromYamlString parser = new ImageFromYamlString(new Supplier<String>() {
|
||||
ImagesToYamlImagesFromYamlDescriptor parser = new ImagesToYamlImagesFromYamlDescriptor(new Supplier<String>() {
|
||||
|
||||
@Override
|
||||
public String get() {
|
||||
|
|
Loading…
Reference in New Issue