mirror of https://github.com/apache/jclouds.git
formatting
This commit is contained in:
parent
8194e84c30
commit
aab1290b85
|
@ -23,7 +23,6 @@ package org.jclouds.virtualbox.compute;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -48,128 +47,128 @@ import com.google.common.base.Throwables;
|
||||||
import com.google.inject.Singleton;
|
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}
|
* {@link org.jclouds.compute.ComputeService}
|
||||||
*
|
*
|
||||||
* @author Mattias Holmqvist, Andrea Turli
|
* @author Mattias Holmqvist, Andrea Turli
|
||||||
*/
|
*/
|
||||||
@Singleton
|
@Singleton
|
||||||
public class VirtualBoxComputeServiceAdapter implements ComputeServiceAdapter<IMachine, IMachine, Image, Location> {
|
public class VirtualBoxComputeServiceAdapter implements ComputeServiceAdapter<IMachine, IMachine, Image, Location> {
|
||||||
|
|
||||||
private final VirtualBoxManager manager;
|
private final VirtualBoxManager manager;
|
||||||
private final JustProvider justProvider;
|
private final JustProvider justProvider;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public VirtualBoxComputeServiceAdapter(VirtualBoxManager manager, JustProvider justProvider) {
|
public VirtualBoxComputeServiceAdapter(VirtualBoxManager manager, JustProvider justProvider) {
|
||||||
this.manager = checkNotNull(manager, "manager");
|
this.manager = checkNotNull(manager, "manager");
|
||||||
this.justProvider = checkNotNull(justProvider, "justProvider");
|
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
|
@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();
|
return (Iterable<Location>) justProvider.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IMachine getNode(String vmName) {
|
public IMachine getNode(String vmName) {
|
||||||
return manager.getVBox().findMachine(vmName);
|
return manager.getVBox().findMachine(vmName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void destroyNode(String vmName) {
|
public void destroyNode(String vmName) {
|
||||||
IMachine machine = manager.getVBox().findMachine(vmName);
|
IMachine machine = manager.getVBox().findMachine(vmName);
|
||||||
powerDownMachine(machine);
|
powerDownMachine(machine);
|
||||||
machine.unregister(CleanupMode.Full);
|
machine.unregister(CleanupMode.Full);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void rebootNode(String vmName) {
|
public void rebootNode(String vmName) {
|
||||||
IMachine machine = manager.getVBox().findMachine(vmName);
|
IMachine machine = manager.getVBox().findMachine(vmName);
|
||||||
powerDownMachine(machine);
|
powerDownMachine(machine);
|
||||||
launchVMProcess(machine, manager.getSessionObject());
|
launchVMProcess(machine, manager.getSessionObject());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void resumeNode(String vmName) {
|
public void resumeNode(String vmName) {
|
||||||
IMachine machine = manager.getVBox().findMachine(vmName);
|
IMachine machine = manager.getVBox().findMachine(vmName);
|
||||||
ISession machineSession;
|
ISession machineSession;
|
||||||
try {
|
try {
|
||||||
machineSession = manager.openMachineSession(machine);
|
machineSession = manager.openMachineSession(machine);
|
||||||
machineSession.getConsole().resume();
|
machineSession.getConsole().resume();
|
||||||
machineSession.unlockMachine();
|
machineSession.unlockMachine();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
propogate(e);
|
propogate(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void suspendNode(String vmName) {
|
public void suspendNode(String vmName) {
|
||||||
IMachine machine = manager.getVBox().findMachine(vmName);
|
IMachine machine = manager.getVBox().findMachine(vmName);
|
||||||
ISession machineSession;
|
ISession machineSession;
|
||||||
try {
|
try {
|
||||||
machineSession = manager.openMachineSession(machine);
|
machineSession = manager.openMachineSession(machine);
|
||||||
machineSession.getConsole().pause();
|
machineSession.getConsole().pause();
|
||||||
machineSession.unlockMachine();
|
machineSession.unlockMachine();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
propogate(e);
|
propogate(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected <T> T propogate(Exception e) {
|
protected <T> T propogate(Exception e) {
|
||||||
Throwables.propagate(e);
|
Throwables.propagate(e);
|
||||||
assert false;
|
assert false;
|
||||||
return null;
|
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();
|
|
||||||
|
|
||||||
while (!machine.getSessionState().equals(SessionState.Unlocked)) {
|
private void launchVMProcess(IMachine machine, ISession session) {
|
||||||
try {
|
IProgress prog = machine.launchVMProcess(session, "gui", "");
|
||||||
System.out
|
prog.waitForCompletion(-1);
|
||||||
.println("waiting for unlocking session - session state: "
|
session.unlockMachine();
|
||||||
+ machine.getSessionState());
|
}
|
||||||
Thread.sleep(1000);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
private void powerDownMachine(IMachine machine) {
|
||||||
e.printStackTrace();
|
try {
|
||||||
e.printStackTrace();
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,9 @@
|
||||||
|
|
||||||
package org.jclouds.virtualbox.functions;
|
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.Image;
|
||||||
import org.jclouds.compute.domain.NodeState;
|
import org.jclouds.compute.domain.NodeState;
|
||||||
import org.jclouds.domain.Credentials;
|
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.MachineState;
|
||||||
import org.virtualbox_4_1.VirtualBoxManager;
|
import org.virtualbox_4_1.VirtualBoxManager;
|
||||||
|
|
||||||
import java.util.Map;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
//@Test(groups = "live")
|
//@Test(groups = "live")
|
||||||
public class IMachineToNodeMetadataTest {
|
public class IMachineToNodeMetadataTest {
|
||||||
|
@ -49,7 +50,7 @@ public class IMachineToNodeMetadataTest {
|
||||||
IMachineToNodeMetadata parser = new IMachineToNodeMetadata();
|
IMachineToNodeMetadata parser = new IMachineToNodeMetadata();
|
||||||
IMachineToHardware hwParser = new IMachineToHardware(manager);
|
IMachineToHardware hwParser = new IMachineToHardware(manager);
|
||||||
|
|
||||||
// hwParser.apply()
|
// hwParser.apply()
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue