formatting

This commit is contained in:
Adrian Cole 2011-10-22 17:53:32 +02:00
parent 8194e84c30
commit aab1290b85
2 changed files with 109 additions and 109 deletions

View File

@ -23,7 +23,6 @@ package org.jclouds.virtualbox.compute;
import static com.google.common.base.Preconditions.checkNotNull;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collections;
import java.util.Map;
@ -48,128 +47,128 @@ import com.google.common.base.Throwables;
import com.google.inject.Singleton;
/**
* Defines the connection between the {@link org.virtualbox_4_1.VirtualBoxManager} implementation and the jclouds
* Defines the connection between the
* {@link org.virtualbox_4_1.VirtualBoxManager} implementation and the jclouds
* {@link org.jclouds.compute.ComputeService}
*
*
* @author Mattias Holmqvist, Andrea Turli
*/
@Singleton
public class VirtualBoxComputeServiceAdapter implements ComputeServiceAdapter<IMachine, IMachine, Image, Location> {
private final VirtualBoxManager manager;
private final VirtualBoxManager manager;
private final JustProvider justProvider;
@Inject
public VirtualBoxComputeServiceAdapter(VirtualBoxManager manager, JustProvider justProvider) {
this.manager = checkNotNull(manager, "manager");
@Inject
public VirtualBoxComputeServiceAdapter(VirtualBoxManager manager, JustProvider justProvider) {
this.manager = checkNotNull(manager, "manager");
this.justProvider = checkNotNull(justProvider, "justProvider");
}
}
@Override
public IMachine createNodeWithGroupEncodedIntoNameThenStoreCredentials(String tag, String name, Template template, Map<String, Credentials> credentialStore) {
return null;
}
@Override
public Iterable<IMachine> listNodes() {
return Collections.emptyList();
}
@Override
public Iterable<IMachine> listHardwareProfiles() {
return manager.getVBox().getMachines();
}
@Override
public Iterable<Image> listImages() {
InputStream is = getClass().getResourceAsStream("/testImages.yaml");
ImageFromYamlStream parser = new ImageFromYamlStream();
return parser.apply(is).asMap().values();
}
@SuppressWarnings("unchecked")
@Override
public Iterable<Location> listLocations() {
public IMachine createNodeWithGroupEncodedIntoNameThenStoreCredentials(String tag, String name, Template template,
Map<String, Credentials> credentialStore) {
return null;
}
@Override
public Iterable<IMachine> listNodes() {
return Collections.emptyList();
}
@Override
public Iterable<IMachine> listHardwareProfiles() {
return manager.getVBox().getMachines();
}
@Override
public Iterable<Image> listImages() {
InputStream is = getClass().getResourceAsStream("/testImages.yaml");
ImageFromYamlStream parser = new ImageFromYamlStream();
return parser.apply(is).asMap().values();
}
@SuppressWarnings("unchecked")
@Override
public Iterable<Location> listLocations() {
return (Iterable<Location>) justProvider.get();
}
}
@Override
public IMachine getNode(String vmName) {
return manager.getVBox().findMachine(vmName);
}
@Override
public IMachine getNode(String vmName) {
return manager.getVBox().findMachine(vmName);
}
@Override
public void destroyNode(String vmName) {
IMachine machine = manager.getVBox().findMachine(vmName);
powerDownMachine(machine);
machine.unregister(CleanupMode.Full);
}
@Override
public void destroyNode(String vmName) {
IMachine machine = manager.getVBox().findMachine(vmName);
powerDownMachine(machine);
machine.unregister(CleanupMode.Full);
}
@Override
public void rebootNode(String vmName) {
IMachine machine = manager.getVBox().findMachine(vmName);
powerDownMachine(machine);
launchVMProcess(machine, manager.getSessionObject());
}
@Override
public void rebootNode(String vmName) {
IMachine machine = manager.getVBox().findMachine(vmName);
powerDownMachine(machine);
launchVMProcess(machine, manager.getSessionObject());
}
@Override
public void resumeNode(String vmName) {
IMachine machine = manager.getVBox().findMachine(vmName);
ISession machineSession;
try {
machineSession = manager.openMachineSession(machine);
machineSession.getConsole().resume();
machineSession.unlockMachine();
} catch (Exception e) {
propogate(e);
}
}
@Override
public void resumeNode(String vmName) {
IMachine machine = manager.getVBox().findMachine(vmName);
ISession machineSession;
try {
machineSession = manager.openMachineSession(machine);
machineSession.getConsole().resume();
machineSession.unlockMachine();
} catch (Exception e) {
propogate(e);
}
}
@Override
public void suspendNode(String vmName) {
IMachine machine = manager.getVBox().findMachine(vmName);
ISession machineSession;
try {
machineSession = manager.openMachineSession(machine);
machineSession.getConsole().pause();
machineSession.unlockMachine();
} catch (Exception e) {
propogate(e);
}
}
@Override
public void suspendNode(String vmName) {
IMachine machine = manager.getVBox().findMachine(vmName);
ISession machineSession;
try {
machineSession = manager.openMachineSession(machine);
machineSession.getConsole().pause();
machineSession.unlockMachine();
} catch (Exception e) {
propogate(e);
}
}
protected <T> T propogate(Exception e) {
Throwables.propagate(e);
assert false;
return null;
}
private void launchVMProcess(IMachine machine, ISession session) {
IProgress prog = machine.launchVMProcess(session, "gui", "");
prog.waitForCompletion(-1);
session.unlockMachine();
}
private void powerDownMachine(IMachine machine) {
try {
ISession machineSession = manager.openMachineSession(machine);
IProgress progress = machineSession.getConsole().powerDown();
progress.waitForCompletion(-1);
machineSession.unlockMachine();
protected <T> T propogate(Exception e) {
Throwables.propagate(e);
assert false;
return null;
}
while (!machine.getSessionState().equals(SessionState.Unlocked)) {
try {
System.out
.println("waiting for unlocking session - session state: "
+ machine.getSessionState());
Thread.sleep(1000);
} catch (InterruptedException e) {
}
}
private void launchVMProcess(IMachine machine, ISession session) {
IProgress prog = machine.launchVMProcess(session, "gui", "");
prog.waitForCompletion(-1);
session.unlockMachine();
}
} catch (Exception e) {
e.printStackTrace();
e.printStackTrace();
}
}
private void powerDownMachine(IMachine machine) {
try {
ISession machineSession = manager.openMachineSession(machine);
IProgress progress = machineSession.getConsole().powerDown();
progress.waitForCompletion(-1);
machineSession.unlockMachine();
while (!machine.getSessionState().equals(SessionState.Unlocked)) {
try {
System.out.println("waiting for unlocking session - session state: " + machine.getSessionState());
Thread.sleep(1000);
} catch (InterruptedException e) {
}
}
} catch (Exception e) {
e.printStackTrace();
e.printStackTrace();
}
}
}

View File

@ -19,7 +19,9 @@
package org.jclouds.virtualbox.functions;
import com.google.common.collect.ImmutableSet;
import java.util.Map;
import java.util.Set;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.NodeState;
import org.jclouds.domain.Credentials;
@ -29,8 +31,7 @@ import org.testng.annotations.Test;
import org.virtualbox_4_1.MachineState;
import org.virtualbox_4_1.VirtualBoxManager;
import java.util.Map;
import java.util.Set;
import com.google.common.collect.ImmutableSet;
//@Test(groups = "live")
public class IMachineToNodeMetadataTest {
@ -49,7 +50,7 @@ public class IMachineToNodeMetadataTest {
IMachineToNodeMetadata parser = new IMachineToNodeMetadata();
IMachineToHardware hwParser = new IMachineToHardware(manager);
// hwParser.apply()
// hwParser.apply()
}
}