From: <hel...@us...> - 2008-09-09 13:52:56
|
Revision: 7028 http://smartfrog.svn.sourceforge.net/smartfrog/?rev=7028&view=rev Author: helgemahrt Date: 2008-09-09 13:52:49 +0000 (Tue, 09 Sep 2008) Log Message: ----------- SFOS-973 Modified Paths: -------------- trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/EnvironmentConstructorImpl.java trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/VirtualMachineConfig.java Added Paths: ----------- trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/CommandDispatcher/ trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/CommandDispatcher/BaseCommand.java trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/CommandDispatcher/Command.java trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/CommandDispatcher/CommandController.java trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/CommandDispatcher/CopyFileFromHostToGuestCommand.java trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/CommandDispatcher/CreateVirtualMachineCommand.java trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/CommandDispatcher/DeleteVirtualMachineCommand.java trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/CommandDispatcher/DispatcherThread.java trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/CommandDispatcher/ExecuteInGuestCommand.java trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/CommandDispatcher/MessageDispatcher.java trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/CommandDispatcher/RevertToSnapshotCommand.java trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/CommandDispatcher/SendCredentialsCommand.java trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/CommandDispatcher/StartVirtualMachineCommand.java trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/CommandDispatcher/TakeSnapshotCommand.java trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/CommandDispatcher/TimerThread.java trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/CommandDispatcher/WaitForToolsCommand.java trunk/core/extras/VAST/src/org/smartfrog/vast/testing/VastSchema.sf Added: trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/CommandDispatcher/BaseCommand.java =================================================================== --- trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/CommandDispatcher/BaseCommand.java (rev 0) +++ trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/CommandDispatcher/BaseCommand.java 2008-09-09 13:52:49 UTC (rev 7028) @@ -0,0 +1,76 @@ +package org.smartfrog.vast.architecture.CommandDispatcher; + +import org.smartfrog.vast.architecture.VirtualMachineConfig; +import org.smartfrog.services.xmpp.XMPPEventExtension; +import org.smartfrog.services.vmware.VMWareConstants; +import org.smartfrog.sfcore.logging.LogSF; + +public abstract class BaseCommand implements Command { + protected Command NextSuccess, NextFailure; + protected MessageDispatcher refMD = null; + protected String Command; + protected LogSF Log; + + protected BaseCommand(MessageDispatcher refMD, String inCmd, LogSF inLog) { + this.refMD = refMD; + this.Command = inCmd; + Log = inLog; + } + + public void handlePacket(VirtualMachineConfig inCfg, XMPPEventExtension inExt) { + if (inExt.getPropertyBag().get(VMWareConstants.VMCMD).equals(Command)) { + if (inExt.getPropertyBag().get(VMWareConstants.VMRESPONSE).equals("success")) { + success(inCfg); + } else { + failure(inCfg); + } + } + } + + public void execute(VirtualMachineConfig inCfg) { + // send the message + refMD.sendMessage(inCfg.getAffinity(), composeMessage(inCfg)); + + // stop the old timer + inCfg.stopTimer(); + + // set the timer + inCfg.setTimer(); + + // start the timer + inCfg.startTimer(); + } + + public void failure(VirtualMachineConfig inCfg) { + // go to failure + inCfg.setCurrentCommand(NextFailure); + NextFailure.execute(inCfg); + } + + public Command getNextOnFailure() { + return NextFailure; + } + + public Command getNextOnSuccess() { + return NextSuccess; + } + + public void setNextOnFailure(Command inCmd) { + NextFailure = inCmd; + } + + public void setNextOnSuccess(Command inCmd) { + NextSuccess = inCmd; + } + + public void success(VirtualMachineConfig inCfg) { + // go to success + inCfg.setCurrentCommand(NextSuccess); + NextSuccess.execute(inCfg); + } + + public void timeOut(VirtualMachineConfig inCfg) { + // retry + this.execute(inCfg); + } +} Added: trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/CommandDispatcher/Command.java =================================================================== --- trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/CommandDispatcher/Command.java (rev 0) +++ trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/CommandDispatcher/Command.java 2008-09-09 13:52:49 UTC (rev 7028) @@ -0,0 +1,68 @@ +package org.smartfrog.vast.architecture.CommandDispatcher; + +import org.smartfrog.vast.architecture.VirtualMachineConfig; +import org.smartfrog.services.xmpp.XMPPEventExtension; + +public interface Command { + /** + * The command times out. + * @param inCfg The virtual machine config class which sent the command. + */ + public void timeOut(VirtualMachineConfig inCfg); + + /** + * The command succeeded. + * @param inCfg The virtual machine config class which sent the command. + */ + public void success(VirtualMachineConfig inCfg); + + /** + * The command failed. + * @param inCfg The virtual machine config class which sent the command. + */ + public void failure(VirtualMachineConfig inCfg); + + /** + * Executes the command. + * @param inCfg The virtual machine config class which sent the command. + */ + public void execute(VirtualMachineConfig inCfg); + + /** + * Gets the next command in case this one succeeds. + * @return The next command in case this one succeeds. + */ + public Command getNextOnSuccess(); + + /** + * Sets the next command in case this one succeeds. + * @param inCmd The next command in case this one succeeds. + */ + public void setNextOnSuccess(Command inCmd); + + /** + * Sets the next command in case this one fails. + * @param inCmd The next command in case this one fails. + */ + public void setNextOnFailure(Command inCmd); + + /** + * Gets the next command in case this one fails. + * @return The next command in case this one fails. + */ + public Command getNextOnFailure(); + + /** + * Composes the XMPP event extension for this command. + * @param inCfg The virtual machine config class which sent the command. + * @return The composed message. + */ + public XMPPEventExtension composeMessage(VirtualMachineConfig inCfg); + + /** + * Handle the response. + * @param inCfg The virtual machine config class which sent the command. + * @param inExt The response XMPP extension. + */ + public void handlePacket(VirtualMachineConfig inCfg, XMPPEventExtension inExt); +} Added: trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/CommandDispatcher/CommandController.java =================================================================== --- trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/CommandDispatcher/CommandController.java (rev 0) +++ trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/CommandDispatcher/CommandController.java 2008-09-09 13:52:49 UTC (rev 7028) @@ -0,0 +1,90 @@ +package org.smartfrog.vast.architecture.CommandDispatcher; + +import org.smartfrog.vast.architecture.VirtualMachineConfig; +import org.smartfrog.services.xmpp.XMPPEventExtension; +import org.smartfrog.services.vmware.VMWareConstants; +import org.smartfrog.avalanche.server.AvalancheServer; +import org.smartfrog.sfcore.logging.LogSF; +import org.jivesoftware.smack.packet.Packet; + +import java.util.ArrayList; + +public class CommandController { + private ArrayList<Command> Commands = new ArrayList<Command>(9); + private ArrayList<VirtualMachineConfig> refVirtualMachines; + + MessageDispatcher msgDisp; + + public CommandController(AvalancheServer inAvlSrv, LogSF inLog) { + // create the message dispatcher + msgDisp = new MessageDispatcher(inAvlSrv); + + // create the commands + RevertToSnapshotCommand revert = new RevertToSnapshotCommand(msgDisp, inLog); + SendCredentialsCommand cred = new SendCredentialsCommand(msgDisp, inLog); + DeleteVirtualMachineCommand delete = new DeleteVirtualMachineCommand(msgDisp, inLog); + CreateVirtualMachineCommand create = new CreateVirtualMachineCommand(msgDisp, inLog); + TakeSnapshotCommand snapshot = new TakeSnapshotCommand(msgDisp, inLog); + StartVirtualMachineCommand start = new StartVirtualMachineCommand(msgDisp, inLog); + WaitForToolsCommand wait = new WaitForToolsCommand(msgDisp, inLog); + CopyFileFromHostToGuestCommand copy = new CopyFileFromHostToGuestCommand(msgDisp, inLog); + ExecuteInGuestCommand exec = new ExecuteInGuestCommand(msgDisp, inLog); + + // concatenate them + revert.setNextOnSuccess(cred); + revert.setNextOnFailure(delete); + + cred.setNextOnSuccess(start); + cred.setNextOnFailure(delete); + + delete.setNextOnSuccess(create); + delete.setNextOnFailure(create); + + create.setNextOnSuccess(snapshot); + create.setNextOnFailure(create); + + snapshot.setNextOnSuccess(start); + snapshot.setNextOnFailure(delete); + + start.setNextOnSuccess(wait); + start.setNextOnFailure(revert); + + wait.setNextOnSuccess(copy); + wait.setNextOnFailure(start); + + copy.setNextOnSuccess(exec); + copy.setNextOnFailure(copy); + + exec.setNextOnFailure(copy); + + // add them to the list + Commands.add(revert); + Commands.add(cred); + Commands.add(delete); + Commands.add(create); + Commands.add(snapshot); + Commands.add(start); + Commands.add(wait); + Commands.add(copy); + Commands.add(exec); + } + + public void executeCommands(ArrayList<VirtualMachineConfig> inVirtualMachines) { + refVirtualMachines = inVirtualMachines; + + for (VirtualMachineConfig cfg : refVirtualMachines) { + cfg.setCurrentCommand(Commands.get(0)); + cfg.getCurrentCommand().execute(cfg); + } + } + + public void handleResponse(Packet inPacket, XMPPEventExtension inExt) { + // get the right virtual machine + for (VirtualMachineConfig virt : refVirtualMachines) { + if (virt.getAffinity().equals(inExt.getHost()) && + virt.getDisplayName().equals(inExt.getPropertyBag().get(VMWareConstants.VMNAME))) { + virt.getCurrentCommand().handlePacket(virt, inExt); + } + } + } +} Added: trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/CommandDispatcher/CopyFileFromHostToGuestCommand.java =================================================================== --- trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/CommandDispatcher/CopyFileFromHostToGuestCommand.java (rev 0) +++ trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/CommandDispatcher/CopyFileFromHostToGuestCommand.java 2008-09-09 13:52:49 UTC (rev 7028) @@ -0,0 +1,42 @@ +package org.smartfrog.vast.architecture.CommandDispatcher; + +import org.smartfrog.services.xmpp.XMPPEventExtension; +import org.smartfrog.services.xmpp.MonitoringConstants; +import org.smartfrog.services.vmware.VMWareConstants; +import org.smartfrog.vast.architecture.VirtualMachineConfig; +import org.smartfrog.vast.architecture.Argument; +import org.smartfrog.sfcore.logging.LogSF; + +import java.net.InetAddress; +import java.net.UnknownHostException; + +public class CopyFileFromHostToGuestCommand extends BaseCommand { + public CopyFileFromHostToGuestCommand(MessageDispatcher refMD, LogSF inLog) { + super(refMD, VMWareConstants.VM_CMD_COPY_HOST_TO_GUEST, inLog); + } + + public XMPPEventExtension composeMessage(VirtualMachineConfig inCfg) { + XMPPEventExtension ext = new XMPPEventExtension(); + try { + ext.setHost(InetAddress.getLocalHost().toString()); + } catch (UnknownHostException e) { + ext.setHost(""); + } + ext.setMessageType(MonitoringConstants.VM_MESSAGE); + + // set the command + ext.getPropertyBag().put("vmcmd", Command); + + // set the path (used like an identifier) + ext.getPropertyBag().put("vmname", inCfg.getDisplayName()); + + // parameters + for (Argument arg : inCfg.getListArguments()) + if (arg.getName().equals("AVALANCHE_HOME")) + ext.getPropertyBag().put(VMWareConstants.VM_COPY_HTOG_DEST, String.format("%s/helper.jar", arg.getValue())); + + ext.getPropertyBag().put(VMWareConstants.VM_COPY_HTOG_SOURCE, inCfg.getHelperPathOnHostOS()); + + return ext; + } +} Added: trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/CommandDispatcher/CreateVirtualMachineCommand.java =================================================================== --- trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/CommandDispatcher/CreateVirtualMachineCommand.java (rev 0) +++ trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/CommandDispatcher/CreateVirtualMachineCommand.java 2008-09-09 13:52:49 UTC (rev 7028) @@ -0,0 +1,40 @@ +package org.smartfrog.vast.architecture.CommandDispatcher; + +import org.smartfrog.services.xmpp.XMPPEventExtension; +import org.smartfrog.services.xmpp.MonitoringConstants; +import org.smartfrog.services.vmware.VMWareConstants; +import org.smartfrog.vast.architecture.VirtualMachineConfig; +import org.smartfrog.sfcore.logging.LogSF; + +import java.net.InetAddress; +import java.net.UnknownHostException; + +public class CreateVirtualMachineCommand extends BaseCommand { + public CreateVirtualMachineCommand(MessageDispatcher refMD, LogSF inLog) { + super(refMD, VMWareConstants.VM_CMD_CREATE, inLog); + } + + public XMPPEventExtension composeMessage(VirtualMachineConfig inCfg) { + XMPPEventExtension ext = new XMPPEventExtension(); + try { + ext.setHost(InetAddress.getLocalHost().toString()); + } catch (UnknownHostException e) { + ext.setHost(""); + } + ext.setMessageType(MonitoringConstants.VM_MESSAGE); + + // set the command + ext.getPropertyBag().put("vmcmd", Command); + + // set the path (used like an identifier) + ext.getPropertyBag().put("vmname", null); + + // fill the propertybag with thr necessary parameters + ext.getPropertyBag().put(VMWareConstants.VM_CREATE_MASTER, inCfg.getSourceImage()); + ext.getPropertyBag().put(VMWareConstants.VM_CREATE_NAME, inCfg.getDisplayName()); + ext.getPropertyBag().put(VMWareConstants.VM_CREATE_USER, inCfg.getGuestUser()); + ext.getPropertyBag().put(VMWareConstants.VM_CREATE_PASS, inCfg.getGuestPass()); + + return ext; + } +} Added: trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/CommandDispatcher/DeleteVirtualMachineCommand.java =================================================================== --- trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/CommandDispatcher/DeleteVirtualMachineCommand.java (rev 0) +++ trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/CommandDispatcher/DeleteVirtualMachineCommand.java 2008-09-09 13:52:49 UTC (rev 7028) @@ -0,0 +1,34 @@ +package org.smartfrog.vast.architecture.CommandDispatcher; + +import org.smartfrog.services.xmpp.XMPPEventExtension; +import org.smartfrog.services.xmpp.MonitoringConstants; +import org.smartfrog.services.vmware.VMWareConstants; +import org.smartfrog.vast.architecture.VirtualMachineConfig; +import org.smartfrog.sfcore.logging.LogSF; + +import java.net.InetAddress; +import java.net.UnknownHostException; + +public class DeleteVirtualMachineCommand extends BaseCommand { + public DeleteVirtualMachineCommand(MessageDispatcher refMD, LogSF inLog) { + super(refMD, VMWareConstants.VM_CMD_DELETE, inLog); + } + + public XMPPEventExtension composeMessage(VirtualMachineConfig inCfg) { + XMPPEventExtension ext = new XMPPEventExtension(); + try { + ext.setHost(InetAddress.getLocalHost().toString()); + } catch (UnknownHostException e) { + ext.setHost(""); + } + ext.setMessageType(MonitoringConstants.VM_MESSAGE); + + // set the command + ext.getPropertyBag().put("vmcmd", Command); + + // set the path (used like an identifier) + ext.getPropertyBag().put("vmname", inCfg.getDisplayName()); + + return ext; + } +} Added: trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/CommandDispatcher/DispatcherThread.java =================================================================== --- trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/CommandDispatcher/DispatcherThread.java (rev 0) +++ trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/CommandDispatcher/DispatcherThread.java 2008-09-09 13:52:49 UTC (rev 7028) @@ -0,0 +1,59 @@ +package org.smartfrog.vast.architecture.CommandDispatcher; + +import org.smartfrog.avalanche.server.AvalancheServer; +import org.smartfrog.services.xmpp.XMPPEventExtension; + +import java.util.ArrayList; + +public class DispatcherThread extends Thread { + private AvalancheServer refAvl = null; + private String TargetHost; + private ArrayList<XMPPEventExtension> Messages = new ArrayList<XMPPEventExtension>(10); + private int SendingInterval = 2000; + + public DispatcherThread(AvalancheServer refAvl, String inHost) { + this.refAvl = refAvl; + TargetHost = inHost; + } + + public void run() { + while (true) { + while (!Messages.isEmpty()) { + // send the command + try { + refAvl.sendXMPPExtension(TargetHost, Messages.get(0)); + } catch (Exception e) { + e.printStackTrace(); + } + + // remove it from the queue + Messages.remove(0); + + try { + Thread.sleep(SendingInterval); + } catch (InterruptedException e) { + + } + } + + // sleep for a while and see if new messages have been queued + try { + Thread.sleep(200); + } catch (InterruptedException e) { + + } + } + } + + public void queueMessage(XMPPEventExtension inMsg) { + Messages.add(inMsg); + } + + public int getSendingInterval() { + return SendingInterval; + } + + public void setSendingInterval(int sendingInterval) { + SendingInterval = sendingInterval; + } +} Added: trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/CommandDispatcher/ExecuteInGuestCommand.java =================================================================== --- trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/CommandDispatcher/ExecuteInGuestCommand.java (rev 0) +++ trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/CommandDispatcher/ExecuteInGuestCommand.java 2008-09-09 13:52:49 UTC (rev 7028) @@ -0,0 +1,114 @@ +package org.smartfrog.vast.architecture.CommandDispatcher; + +import org.smartfrog.services.xmpp.XMPPEventExtension; +import org.smartfrog.services.xmpp.MonitoringConstants; +import org.smartfrog.services.vmware.VMWareConstants; +import org.smartfrog.vast.architecture.VirtualMachineConfig; +import org.smartfrog.vast.architecture.Argument; +import org.smartfrog.sfcore.common.SmartFrogException; +import org.smartfrog.sfcore.logging.LogSF; +import org.smartfrog.sfcore.logging.LogImpl; + +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.rmi.RemoteException; + +public class ExecuteInGuestCommand extends BaseCommand { + public ExecuteInGuestCommand(MessageDispatcher refMD, LogSF inLog) { + super(refMD, VMWareConstants.VM_CMD_EXECUTE, inLog); + } + + public XMPPEventExtension composeMessage(VirtualMachineConfig inCfg) { + XMPPEventExtension ext = new XMPPEventExtension(); + try { + ext.setHost(InetAddress.getLocalHost().toString()); + } catch (UnknownHostException e) { + ext.setHost(""); + } + ext.setMessageType(MonitoringConstants.VM_MESSAGE); + + // set the command + ext.getPropertyBag().put("vmcmd", Command); + + // set the path (used like an identifier) + ext.getPropertyBag().put("vmname", inCfg.getDisplayName()); + + // parameters + + String gwAddr = inCfg.getHostAddress().substring(0, inCfg.getHostAddress().lastIndexOf(".")) + ".1"; + ext.getPropertyBag().put(VMWareConstants.VM_EXECUTE_PARAM, String.format("-jar /tmp/helper.jar -nic %s %s gw %s -nic %s %s -hname %s %s", + inCfg.getHostAddress(), + inCfg.getHostMask(), + gwAddr, + inCfg.getVastNetworkIP(), + inCfg.getVastNetworkMask(), + inCfg.getDisplayName(), + inCfg.getHostList())); + + for (Argument arg : inCfg.getListArguments()) + if (arg.getName().equals("JAVA_HOME")) + ext.getPropertyBag().put(VMWareConstants.VM_EXECUTE_CMD, String.format("%s/bin/java", arg.getValue())); + + return ext; + } + + /** + * Pings a host. + * @param inHost Address to ping. + * @return True if the ping was successful, false otherwise. + */ + private boolean ping(String inHost) { + ProcessBuilder pb; + if (System.getProperty("os.name").toLowerCase().startsWith("windows")) { + pb = new ProcessBuilder("ping", inHost); + } + else { + pb = new ProcessBuilder("ping", "-c", "4", inHost); + } + + try { + Process p = pb.start(); + p.waitFor(); + return (p.exitValue() == 0); + } catch (Exception e) { + Log.error(e); + } + + return false; + } + + public void success(VirtualMachineConfig inCfg) { + try { + // try to ping the machine for 5 * 22 seconds + for (int i = 0; i < 5; ++i) { + if (ping(inCfg.getHostAddress())) { + // vast helper executed, now ignite the virtual machines + // with the appropriate package (sf + test runner + SUT) + refMD.getRefAvl().igniteHosts( new String[]{inCfg.getHostAddress()}, + String.format("%s/temp/vast/%s", refMD.getRefAvl().getAvalancheHome(), inCfg.getSUTPackage()), + String.format("%s/temp/vast/sfinstaller.vm", refMD.getRefAvl().getAvalancheHome())); + return; + } else + Log.info("Ping to " + inCfg.getHostAddress() + " failed. Retrying."); + + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + + } + } + + if (inCfg.getNetworkSetupHelperTries() < 5) { + Log.error("Error: virtual machine " + inCfg.getDisplayName() + " not reachable. Retrying network setup helper."); + + inCfg.setNetworkSetupHelperTries(inCfg.getNetworkSetupHelperTries() + 1); + + // copy the helper into the vm again + failure(inCfg); + } + else Log.error("Error: virtual machine " + inCfg.getDisplayName() + " not reachable. Maximum tries reached."); + } catch (Exception e) { + Log.error(e); + } + } +} Added: trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/CommandDispatcher/MessageDispatcher.java =================================================================== --- trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/CommandDispatcher/MessageDispatcher.java (rev 0) +++ trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/CommandDispatcher/MessageDispatcher.java 2008-09-09 13:52:49 UTC (rev 7028) @@ -0,0 +1,42 @@ +package org.smartfrog.vast.architecture.CommandDispatcher; + +import org.smartfrog.avalanche.server.AvalancheServer; +import org.smartfrog.services.xmpp.XMPPEventExtension; + +import java.util.HashMap; +import java.util.LinkedHashMap; + +public class MessageDispatcher { + private HashMap<String, DispatcherThread> dispatcherThreads = new LinkedHashMap<String, DispatcherThread>(10); + private AvalancheServer refAvl = null; + + public MessageDispatcher(AvalancheServer refAvl) { + this.refAvl = refAvl; + } + + public synchronized void sendMessage(String inHost, XMPPEventExtension inMsg) { + if (dispatcherThreads.containsKey(inHost)) { + // queue message + DispatcherThread dt = dispatcherThreads.get(inHost); + dt.queueMessage(inMsg); + if (!dt.isAlive()) + dt.start(); + } else { + // create new dispatcher thread + DispatcherThread dt = new DispatcherThread(refAvl, inHost); + dt.queueMessage(inMsg); + dt.start(); + + // add it to the hashmap + dispatcherThreads.put(inHost, dt); + } + } + + public AvalancheServer getRefAvl() { + return refAvl; + } + + public void setRefAvl(AvalancheServer refAvl) { + this.refAvl = refAvl; + } +} Added: trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/CommandDispatcher/RevertToSnapshotCommand.java =================================================================== --- trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/CommandDispatcher/RevertToSnapshotCommand.java (rev 0) +++ trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/CommandDispatcher/RevertToSnapshotCommand.java 2008-09-09 13:52:49 UTC (rev 7028) @@ -0,0 +1,34 @@ +package org.smartfrog.vast.architecture.CommandDispatcher; + +import org.smartfrog.services.xmpp.XMPPEventExtension; +import org.smartfrog.services.xmpp.MonitoringConstants; +import org.smartfrog.services.vmware.VMWareConstants; +import org.smartfrog.vast.architecture.VirtualMachineConfig; +import org.smartfrog.sfcore.logging.LogSF; + +import java.net.InetAddress; +import java.net.UnknownHostException; + +public class RevertToSnapshotCommand extends BaseCommand { + public RevertToSnapshotCommand(MessageDispatcher refMD, LogSF inLog) { + super(refMD, VMWareConstants.VM_CMD_REVERT, inLog); + } + + public XMPPEventExtension composeMessage(VirtualMachineConfig inCfg) { + XMPPEventExtension ext = new XMPPEventExtension(); + try { + ext.setHost(InetAddress.getLocalHost().toString()); + } catch (UnknownHostException e) { + ext.setHost(""); + } + ext.setMessageType(MonitoringConstants.VM_MESSAGE); + + // set the command + ext.getPropertyBag().put("vmcmd", Command); + + // set the path (used like an identifier) + ext.getPropertyBag().put("vmname", inCfg.getDisplayName()); + + return ext; + } +} Added: trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/CommandDispatcher/SendCredentialsCommand.java =================================================================== --- trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/CommandDispatcher/SendCredentialsCommand.java (rev 0) +++ trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/CommandDispatcher/SendCredentialsCommand.java 2008-09-09 13:52:49 UTC (rev 7028) @@ -0,0 +1,38 @@ +package org.smartfrog.vast.architecture.CommandDispatcher; + +import org.smartfrog.services.xmpp.XMPPEventExtension; +import org.smartfrog.services.xmpp.MonitoringConstants; +import org.smartfrog.services.vmware.VMWareConstants; +import org.smartfrog.vast.architecture.VirtualMachineConfig; +import org.smartfrog.sfcore.logging.LogSF; + +import java.net.InetAddress; +import java.net.UnknownHostException; + +public class SendCredentialsCommand extends BaseCommand { + public SendCredentialsCommand(MessageDispatcher refMD, LogSF inLog) { + super(refMD, VMWareConstants.VM_CMD_SET_GUEST_CRED, inLog); + } + + public XMPPEventExtension composeMessage(VirtualMachineConfig inCfg) { + XMPPEventExtension ext = new XMPPEventExtension(); + try { + ext.setHost(InetAddress.getLocalHost().toString()); + } catch (UnknownHostException e) { + ext.setHost(""); + } + ext.setMessageType(MonitoringConstants.VM_MESSAGE); + + // set the command + ext.getPropertyBag().put("vmcmd", Command); + + // set the path (used like an identifier) + ext.getPropertyBag().put("vmname", inCfg.getDisplayName()); + + // parameters + ext.getPropertyBag().put(VMWareConstants.VM_SET_GUEST_CRED_USER, inCfg.getGuestUser()); + ext.getPropertyBag().put(VMWareConstants.VM_SET_GUEST_CRED_PASS, inCfg.getGuestPass()); + + return ext; + } +} Added: trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/CommandDispatcher/StartVirtualMachineCommand.java =================================================================== --- trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/CommandDispatcher/StartVirtualMachineCommand.java (rev 0) +++ trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/CommandDispatcher/StartVirtualMachineCommand.java 2008-09-09 13:52:49 UTC (rev 7028) @@ -0,0 +1,34 @@ +package org.smartfrog.vast.architecture.CommandDispatcher; + +import org.smartfrog.services.xmpp.XMPPEventExtension; +import org.smartfrog.services.xmpp.MonitoringConstants; +import org.smartfrog.services.vmware.VMWareConstants; +import org.smartfrog.vast.architecture.VirtualMachineConfig; +import org.smartfrog.sfcore.logging.LogSF; + +import java.net.InetAddress; +import java.net.UnknownHostException; + +public class StartVirtualMachineCommand extends BaseCommand { + public StartVirtualMachineCommand(MessageDispatcher refMD, LogSF inLog) { + super(refMD, VMWareConstants.VM_CMD_START, inLog); + } + + public XMPPEventExtension composeMessage(VirtualMachineConfig inCfg) { + XMPPEventExtension ext = new XMPPEventExtension(); + try { + ext.setHost(InetAddress.getLocalHost().toString()); + } catch (UnknownHostException e) { + ext.setHost(""); + } + ext.setMessageType(MonitoringConstants.VM_MESSAGE); + + // set the command + ext.getPropertyBag().put("vmcmd", Command); + + // set the path (used like an identifier) + ext.getPropertyBag().put("vmname", inCfg.getDisplayName()); + + return ext; + } +} Added: trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/CommandDispatcher/TakeSnapshotCommand.java =================================================================== --- trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/CommandDispatcher/TakeSnapshotCommand.java (rev 0) +++ trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/CommandDispatcher/TakeSnapshotCommand.java 2008-09-09 13:52:49 UTC (rev 7028) @@ -0,0 +1,39 @@ +package org.smartfrog.vast.architecture.CommandDispatcher; + +import org.smartfrog.services.xmpp.XMPPEventExtension; +import org.smartfrog.services.xmpp.MonitoringConstants; +import org.smartfrog.services.vmware.VMWareConstants; +import org.smartfrog.vast.architecture.VirtualMachineConfig; +import org.smartfrog.sfcore.logging.LogSF; + +import java.net.InetAddress; +import java.net.UnknownHostException; + +public class TakeSnapshotCommand extends BaseCommand { + public TakeSnapshotCommand(MessageDispatcher refMD, LogSF inLog) { + super(refMD, VMWareConstants.VM_CMD_TAKE_SNAPSHOT, inLog); + } + + public XMPPEventExtension composeMessage(VirtualMachineConfig inCfg) { + XMPPEventExtension ext = new XMPPEventExtension(); + try { + ext.setHost(InetAddress.getLocalHost().toString()); + } catch (UnknownHostException e) { + ext.setHost(""); + } + ext.setMessageType(MonitoringConstants.VM_MESSAGE); + + // set the command + ext.getPropertyBag().put("vmcmd", Command); + + // set the path (used like an identifier) + ext.getPropertyBag().put("vmname", inCfg.getDisplayName()); + + // fill the propertybag with the parameters + ext.getPropertyBag().put(VMWareConstants.VM_TAKE_SNAPSHOT_NAME, "vast_snapshot"); + ext.getPropertyBag().put(VMWareConstants.VM_TAKE_SNAPSHOT_DESCRIPTION, "Snapshot taken by VAST"); + ext.getPropertyBag().put(VMWareConstants.VM_TAKE_SNAPSHOT_INCLUDE_MEMORY, "false"); + + return ext; + } +} Added: trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/CommandDispatcher/TimerThread.java =================================================================== --- trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/CommandDispatcher/TimerThread.java (rev 0) +++ trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/CommandDispatcher/TimerThread.java 2008-09-09 13:52:49 UTC (rev 7028) @@ -0,0 +1,70 @@ +package org.smartfrog.vast.architecture.CommandDispatcher; + +import org.smartfrog.vast.architecture.VirtualMachineConfig; + +public class TimerThread implements Runnable { + private VirtualMachineConfig refCfg; + private long Time; + private Command command; + private boolean stopTimer = false; + + public TimerThread(VirtualMachineConfig refCfg) { + this.refCfg = refCfg; + } + + public void run() { + long lastTime = System.currentTimeMillis(); + + long tmpTime; + while (true) { + if (stopTimer) { + stopTimer = false; + return; + } + + // use one timevalue to calculate with + tmpTime = System.currentTimeMillis(); + + Time -= (tmpTime - lastTime); + + if (Time <= 0) + break; + + lastTime = tmpTime; + + try { + Thread.sleep(500); + } catch (InterruptedException e) { + } + } + + command.timeOut(refCfg); + } + + /** + * Stops the timer. + */ + public void stopTimer() { + stopTimer = true; + } + + public Command getCommand() { + return command; + } + + public void setCommand(Command command) { + this.command = command; + } + + public long getTime() { + return Time; + } + + /** + * Set the timer. + * @param time Time in miliseconds. + */ + public void setTime(long time) { + Time = time; + } +} Added: trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/CommandDispatcher/WaitForToolsCommand.java =================================================================== --- trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/CommandDispatcher/WaitForToolsCommand.java (rev 0) +++ trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/CommandDispatcher/WaitForToolsCommand.java 2008-09-09 13:52:49 UTC (rev 7028) @@ -0,0 +1,37 @@ +package org.smartfrog.vast.architecture.CommandDispatcher; + +import org.smartfrog.services.xmpp.XMPPEventExtension; +import org.smartfrog.services.xmpp.MonitoringConstants; +import org.smartfrog.services.vmware.VMWareConstants; +import org.smartfrog.vast.architecture.VirtualMachineConfig; +import org.smartfrog.sfcore.logging.LogSF; + +import java.net.InetAddress; +import java.net.UnknownHostException; + +public class WaitForToolsCommand extends BaseCommand { + public WaitForToolsCommand(MessageDispatcher refMD, LogSF inLog) { + super(refMD, VMWareConstants.VM_CMD_WAIT_FOR_TOOLS, inLog); + } + + public XMPPEventExtension composeMessage(VirtualMachineConfig inCfg) { + XMPPEventExtension ext = new XMPPEventExtension(); + try { + ext.setHost(InetAddress.getLocalHost().toString()); + } catch (UnknownHostException e) { + ext.setHost(""); + } + ext.setMessageType(MonitoringConstants.VM_MESSAGE); + + // set the command + ext.getPropertyBag().put("vmcmd", Command); + + // set the path (used like an identifier) + ext.getPropertyBag().put("vmname", inCfg.getDisplayName()); + + // parameters + ext.getPropertyBag().put(VMWareConstants.VM_WAIT_FOR_TOOLS_TIMEOUT, String.format("%d", inCfg.getToolsTimeout())); + + return ext; + } +} Modified: trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/EnvironmentConstructorImpl.java =================================================================== --- trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/EnvironmentConstructorImpl.java 2008-09-09 13:37:35 UTC (rev 7027) +++ trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/EnvironmentConstructorImpl.java 2008-09-09 13:52:49 UTC (rev 7028) @@ -34,6 +34,7 @@ import org.smartfrog.services.filesystem.FileSystem; import org.smartfrog.vast.archive.ZipArchive; import org.smartfrog.vast.archive.TarArchive; +import org.smartfrog.vast.architecture.CommandDispatcher.CommandController; import org.jivesoftware.smack.packet.Packet; import java.rmi.RemoteException; @@ -58,6 +59,11 @@ VirtualMachineConfig VastController = null; /** + * The command controller. + */ + CommandController cmdCtrl = null; + + /** * The list containing the configuration details for the physical machine. */ private ArrayList<PhysicalMachineConfig> listPhysicalMachines = new ArrayList<PhysicalMachineConfig>(); @@ -78,10 +84,6 @@ public synchronized void sfDeploy() throws SmartFrogException, RemoteException { super.sfDeploy(); - - sfLog().info("deploying"); - - sfLog().info("successfully deployed"); } protected void sfDeployWithChildren() throws SmartFrogDeploymentException { @@ -168,10 +170,31 @@ } } + setRemainingValues(); + sfLog().info("successfully deployed with children"); } /** + * Sets the remaining values of the virtual machines which can only be set after all descriptions have been resolved. + */ + private void setRemainingValues() { + for (VirtualMachineConfig virt : listVirtualMachines) { + for (PhysicalMachineConfig phy : listPhysicalMachines) { + if (virt.getAffinity().equals(phy.getHostAddress())) { + for (Argument arg : phy.getListArguments()) + if (arg.getName().equals("AVALANCHE_HOME")) + virt.setHelperPathOnHostOS(String.format("%s/smartfrog/dist/vast/helper.jar", arg.getValue())); + + break; + } + } + + virt.setHostList(HostnameList); + } + } + + /** * Copies the template default.ini file to the package location and replaces the template indicators with the given ip. * @param inSrc * @param inDest @@ -336,6 +359,9 @@ // register the listener with avalanche refAvlServer.addXMPPHandler(new VastListener(this)); + // create the command controller + cmdCtrl = new CommandController(refAvlServer, sfLog()); + try { prepareSUTPackages(); } catch (Exception e1) { @@ -375,20 +401,20 @@ } } - /** - * Deletes the virtual machines. - */ - private void revertVMsToSnapshots() { - for (VirtualMachineConfig virt : listVirtualMachines) { - if (checkPhysicalExistance(virt.getAffinity())) { - try { - refAvlServer.sendVMCommand(virt.getAffinity(), virt.getDisplayName(), "reverttosnapshot"); - } catch (Exception e) { - sfLog().error("Error while trying send reverttosnapshot command", e); - } - } - } - } +// /** +// * Deletes the virtual machines. +// */ +// private void revertVMsToSnapshots() { +// for (VirtualMachineConfig virt : listVirtualMachines) { +// if (checkPhysicalExistance(virt.getAffinity())) { +// try { +// refAvlServer.sendVMCommand(virt.getAffinity(), virt.getDisplayName(), "reverttosnapshot"); +// } catch (Exception e) { +// sfLog().error("Error while trying send reverttosnapshot command", e); +// } +// } +// } +// } /** * Stops the daemons running on the physical hosts. @@ -538,8 +564,8 @@ // check if all machines are running if (checkPhysicalEnv()) { - // first try to revert to snapshots - revertVMsToSnapshots(); + // start the command control + cmdCtrl.executeCommands(listVirtualMachines); } return; @@ -615,200 +641,203 @@ * @param inPacketExtension The packet extension containing the relevant data. */ public void handleVMMessages(Packet inPacket, XMPPEventExtension inPacketExtension) { - // retrieve the basic attributes - String strCommand = inPacketExtension.getPropertyBag().get(VMWareConstants.VMCMD); - String strResponse = inPacketExtension.getPropertyBag().get(VMWareConstants.VMRESPONSE); - String strVMName = inPacketExtension.getPropertyBag().get(VMWareConstants.VMNAME); + cmdCtrl.handleResponse(inPacket, inPacketExtension); - // get the physical host - PhysicalMachineConfig phyHost = null; - for (PhysicalMachineConfig cur : listPhysicalMachines) - if (cur.getHostAddress().equals(inPacketExtension.getHost())) { - phyHost = cur; - break; - } - - // get the according vm - VirtualMachineConfig vmTarget = null; - for (VirtualMachineConfig cur : listVirtualMachines) - if (cur.getDisplayName().equals(strVMName) - && cur.getAffinity().equals(inPacketExtension.getHost())) { - vmTarget = cur; - break; - } - - if (phyHost != null && vmTarget != null) { - try { - if (strCommand.equals(VMWareConstants.VM_CMD_REVERT)) { - if (strResponse.equals("success")) { - // send credentials - HashMap<String, String> map = new HashMap<String, String>(); - map.put(VMWareConstants.VM_SET_GUEST_CRED_USER, vmTarget.getGuestUser()); - map.put(VMWareConstants.VM_SET_GUEST_CRED_PASS, vmTarget.getGuestPass()); - refAvlServer.sendVMCommand(inPacket.getFrom(), strVMName, VMWareConstants.VM_CMD_SET_GUEST_CRED, map); - - // send the start command - refAvlServer.sendVMCommand(inPacket.getFrom(), strVMName, VMWareConstants.VM_CMD_START); - } else { - // send delete command - refAvlServer.sendVMCommand(inPacket.getFrom(), strVMName, VMWareConstants.VM_CMD_DELETE); - - // send create command - HashMap<String, String> map = new HashMap<String, String>(); - map.put(VMWareConstants.VM_CREATE_MASTER, vmTarget.getSourceImage()); - map.put(VMWareConstants.VM_CREATE_NAME, vmTarget.getDisplayName()); - map.put(VMWareConstants.VM_CREATE_USER, vmTarget.getGuestUser()); - map.put(VMWareConstants.VM_CREATE_PASS, vmTarget.getGuestPass()); - refAvlServer.sendVMCommand(vmTarget.getAffinity(), null, VMWareConstants.VM_CMD_CREATE, map); - } - } else if (strCommand.equals(VMWareConstants.VM_CMD_CREATE)) { - // a response to a create command - if (strResponse.equals("success")) { - takeSnapshot(inPacket, strVMName); - } else sfLog().error("Failed to create vm: " + inPacketExtension); - } else if (strCommand.equals(VMWareConstants.VM_CMD_TAKE_SNAPSHOT)) { - if (!strResponse.equals("success")) - sfLog().warn("Failed to take snapshot of vm: " + inPacketExtension); - - // start the vm, regardless of the success or failure of taking a snapshot - refAvlServer.sendVMCommand(inPacket.getFrom(), strVMName, VMWareConstants.VM_CMD_START); - } else if (strCommand.equals(VMWareConstants.VM_CMD_START)) { - if (strResponse.equals("success")) { - sfLog().info("vm created: " + strVMName); - waitForTools(inPacket, strVMName, vmTarget); - } else sfLog().error("Failed to start vm: " + inPacketExtension); - } else if (strCommand.equals(VMWareConstants.VM_CMD_WAIT_FOR_TOOLS)) { - if (strResponse.equals("success")) { - sfLog().info("tools running"); - - // home dir created, copy the helper into the vm - copyHelper(inPacket, strVMName, phyHost, vmTarget); - } else sfLog().error("Error while creating directory in guest os: " + inPacketExtension); - } else if (strCommand.equals(VMWareConstants.VM_CMD_COPY_HOST_TO_GUEST)) { - if (strResponse.equals("success")) { - if (inPacketExtension.getPropertyBag().get(VMWareConstants.VM_COPY_HTOG_DEST).endsWith("helper.jar")) { - sfLog().info("vast helper copied"); - // helper copied, start it - executeHelper(inPacket, strVMName, vmTarget); - } - } else sfLog().error("Error while copying file from host to guest: " + inPacketExtension); - } else if (strCommand.equals(VMWareConstants.VM_CMD_EXECUTE)) { - if (strResponse.equals("success")) { - // try to ping the machine for 1 minute - for (int i = 0; i < 60; ++i) { - if (ping(vmTarget.getHostAddress())) { - // vast helper executed, now ignite the virtual machines - // with the appropriate package (sf + test runner + SUT) - igniteVirtualMachine(vmTarget); - return; - } else - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - - } - } - - if (vmTarget.getNetworkSetupHelperTries() < 5) { - sfLog().error("Error: virtual machine " + vmTarget.getDisplayName() + " not reachable. Retrying network setup helper."); - - // copy the helper into the vm again - copyHelper(inPacket, strVMName, phyHost, vmTarget); - - vmTarget.setNetworkSetupHelperTries(vmTarget.getNetworkSetupHelperTries() + 1); - } - else sfLog().error("Error: virtual machine " + vmTarget.getDisplayName() + " not reachable. Maximum tries reached."); - } - } - } - catch (Exception e) { - sfLog().error(e); - } - } +// // retrieve the basic attributes +// String strCommand = inPacketExtension.getPropertyBag().get(VMWareConstants.VMCMD); +// String strResponse = inPacketExtension.getPropertyBag().get(VMWareConstants.VMRESPONSE); +// String strVMName = inPacketExtension.getPropertyBag().get(VMWareConstants.VMNAME); +// +// // get the physical host +// PhysicalMachineConfig phyHost = null; +// for (PhysicalMachineConfig cur : listPhysicalMachines) +// if (cur.getHostAddress().equals(inPacketExtension.getHost())) { +// phyHost = cur; +// break; +// } +// +// // get the according vm +// VirtualMachineConfig vmTarget = null; +// for (VirtualMachineConfig cur : listVirtualMachines) +// if (cur.getDisplayName().equals(strVMName) +// && cur.getAffinity().equals(inPacketExtension.getHost())) { +// vmTarget = cur; +// break; +// } +// +// if (phyHost != null && vmTarget != null) { +// try { +// if (strCommand.equals(VMWareConstants.VM_CMD_REVERT)) { +// if (strResponse.equals("success")) { +// // send credentials +// HashMap<String, String> map = new HashMap<String, String>(); +// map.put(VMWareConstants.VM_SET_GUEST_CRED_USER, vmTarget.getGuestUser()); +// map.put(VMWareConstants.VM_SET_GUEST_CRED_PASS, vmTarget.getGuestPass()); +// refAvlServer.sendVMCommand(inPacket.getFrom(), strVMName, VMWareConstants.VM_CMD_SET_GUEST_CRED, map); +// +// // send the start command +// refAvlServer.sendVMCommand(inPacket.getFrom(), strVMName, VMWareConstants.VM_CMD_START); +// } else { +// // send delete command +// refAvlServer.sendVMCommand(inPacket.getFrom(), strVMName, VMWareConstants.VM_CMD_DELETE); +// +// // send create command +// HashMap<String, String> map = new HashMap<String, String>(); +// map.put(VMWareConstants.VM_CREATE_MASTER, vmTarget.getSourceImage()); +// map.put(VMWareConstants.VM_CREATE_NAME, vmTarget.getDisplayName()); +// map.put(VMWareConstants.VM_CREATE_USER, vmTarget.getGuestUser()); +// map.put(VMWareConstants.VM_CREATE_PASS, vmTarget.getGuestPass()); +// refAvlServer.sendVMCommand(vmTarget.getAffinity(), null, VMWareConstants.VM_CMD_CREATE, map); +// } +// } else if (strCommand.equals(VMWareConstants.VM_CMD_CREATE)) { +// // a response to a create command +// if (strResponse.equals("success")) { +// takeSnapshot(inPacket, strVMName); +// } else sfLog().error("Failed to create vm: " + inPacketExtension); +// } else if (strCommand.equals(VMWareConstants.VM_CMD_TAKE_SNAPSHOT)) { +// if (!strResponse.equals("success")) +// sfLog().warn("Failed to take snapshot of vm: " + inPacketExtension); +// +// // start the vm, regardless of the success or failure of taking a snapshot +// refAvlServer.sendVMCommand(inPacket.getFrom(), strVMName, VMWareConstants.VM_CMD_START); +// } else if (strCommand.equals(VMWareConstants.VM_CMD_START)) { +// if (strResponse.equals("success")) { +// sfLog().info("vm created: " + strVMName); +// waitForTools(inPacket, strVMName, vmTarget); +// } else sfLog().error("Failed to start vm: " + inPacketExtension); +// } else if (strCommand.equals(VMWareConstants.VM_CMD_WAIT_FOR_TOOLS)) { +// if (strResponse.equals("success")) { +// sfLog().info("tools running"); +// +// // home dir created, copy the helper into the vm +// copyHelper(inPacket, strVMName, phyHost, vmTarget); +// } else sfLog().error("Error while creating directory in guest os: " + inPacketExtension); +// } else if (strCommand.equals(VMWareConstants.VM_CMD_COPY_HOST_TO_GUEST)) { +// if (strResponse.equals("success")) { +// if (inPacketExtension.getPropertyBag().get(VMWareConstants.VM_COPY_HTOG_DEST).endsWith("helper.jar")) { +// sfLog().info("vast helper copied"); +// // helper copied, start it +// executeHelper(inPacket, strVMName, vmTarget); +// } +// } else sfLog().error("Error while copying file from host to guest: " + inPacketExtension); +// } else if (strCommand.equals(VMWareConstants.VM_CMD_EXECUTE)) { +// if (strResponse.equals("success")) { +// // try to ping the machine for 5 * 22 seconds +// for (int i = 0; i < 5; ++i) { +// if (ping(vmTarget.getHostAddress())) { +// // vast helper executed, now ignite the virtual machines +// // with the appropriate package (sf + test runner + SUT) +// igniteVirtualMachine(vmTarget); +// return; +// } else +// sfLog().info("Ping to " + vmTarget.getHostAddress() + " failed. Retrying."); +// try { +// Thread.sleep(1000); +// } catch (InterruptedException e) { +// +// } +// } +// +// if (vmTarget.getNetworkSetupHelperTries() < 5) { +// sfLog().error("Error: virtual machine " + vmTarget.getDisplayName() + " not reachable. Retrying network setup helper."); +// +// // copy the helper into the vm again +// copyHelper(inPacket, strVMName, phyHost, vmTarget); +// +// vmTarget.setNetworkSetupHelperTries(vmTarget.getNetworkSetupHelperTries() + 1); +// } +// else sfLog().error("Error: virtual machine " + vmTarget.getDisplayName() + " not reachable. Maximum tries reached."); +// } +// } +// } +// catch (Exception e) { +// sfLog().error(e); +// } +// } } - private void executeHelper(Packet inPacket, String inVMName, VirtualMachineConfig inVMTarget) throws RemoteException, SmartFrogException { - HashMap<String, String> map = new HashMap<String, String>(); - - String gwAddr = inVMTarget.getHostAddress().substring(0, inVMTarget.getHostAddress().lastIndexOf(".")) + ".1"; - map.put(VMWareConstants.VM_EXECUTE_PARAM, String.format("-jar /tmp/helper.jar -nic %s %s gw %s -nic %s %s -hname %s %s", - inVMTarget.getHostAddress(), - inVMTarget.getHostMask(), - gwAddr, - inVMTarget.getVastNetworkIP(), - inVMTarget.getVastNetworkMask(), - inVMTarget.getDisplayName(), - HostnameList)); - - for (Argument arg : inVMTarget.getListArguments()) - if (arg.getName().equals("JAVA_HOME")) - map.put(VMWareConstants.VM_EXECUTE_CMD, String.format("%s/bin/java", arg.getValue())); - - refAvlServer.sendVMCommand(inPacket.getFrom(), inVMName, VMWareConstants.VM_CMD_EXECUTE, map); - } - - private void copyHelper(Packet inPacket, String inVMName, PhysicalMachineConfig inPhyHost, VirtualMachineConfig inVMTarget) throws RemoteException, SmartFrogException { - HashMap<String, String> map = new HashMap<String, String>(); - - for (Argument arg : inPhyHost.getListArguments()) - if (arg.getName().equals("AVALANCHE_HOME")) - map.put(VMWareConstants.VM_COPY_HTOG_SOURCE, String.format("%s/smartfrog/dist/vast/helper.jar", arg.getValue())); - - for (Argument arg : inVMTarget.getListArguments()) - if (arg.getName().equals("AVALANCHE_HOME")) - map.put(VMWareConstants.VM_COPY_HTOG_DEST, String.format("%s/helper.jar", arg.getValue())); - - refAvlServer.sendVMCommand(inPacket.getFrom(), inVMName, VMWareConstants.VM_CMD_COPY_HOST_TO_GUEST, map); - } - - private void waitForTools(Packet inPacket, String inVMName, VirtualMachineConfig inVMTarget) throws RemoteException, SmartFrogException { - HashMap<String, String> map = new HashMap<String, String>(); - map.put(VMWareConstants.VM_WAIT_FOR_TOOLS_TIMEOUT, String.format("%d", inVMTarget.getToolsTimeout())); - refAvlServer.sendVMCommand(inPacket.getFrom(), inVMName, VMWareConstants.VM_CMD_WAIT_FOR_TOOLS, map); - } - - private void takeSnapshot(Packet inPacket, String inVMName) throws RemoteException, SmartFrogException { - HashMap<String, String> map = new HashMap<String, String>(); - map.put(VMWareConstants.VM_TAKE_SNAPSHOT_NAME, "vast_snapshot"); - map.put(VMWareConstants.VM_TAKE_SNAPSHOT_DESCRIPTION, "Snapshot taken by VAST"); - map.put(VMWareConstants.VM_TAKE_SNAPSHOT_INCLUDE_MEMORY, "false"); - refAvlServer.sendVMCommand(inPacket.getFrom(), inVMName, VMWareConstants.VM_CMD_TAKE_SNAPSHOT, map); - } - - /** - * Ignites a virtual machine. - * - * @param inVM - */ - private void igniteVirtualMachine(VirtualMachineConfig inVM) throws SmartFrogException, RemoteException { - // ignite it with the according package - refAvlServer.igniteHosts(new String[]{inVM.getHostAddress()}, - String.format("%s/temp/vast/%s", refAvlServer.getAvalancheHome(), inVM.getSUTPackage()), - String.format("%s/temp/vast/sfinstaller.vm", refAvlServer.getAvalancheHome())); - } - - /** - * Pings a host. - * @param inHost Address to ping. - * @return True if the ping was successful, false otherwise. - */ - private boolean ping(String inHost) { - ProcessBuilder pb; - if (System.getProperty("os.name").toLowerCase().startsWith("windows")) { - pb = new ProcessBuilder("ping", inHost); - } - else { - pb = new ProcessBuilder("ping", "-c", "4", inHost); - } - - try { - Process p = pb.start(); - p.waitFor(); - return (p.exitValue() == 0); - } catch (Exception e) { - sfLog().error(e); - } - - return false; - } +// private void executeHelper(Packet inPacket, String inVMName, VirtualMachineConfig inVMTarget) throws RemoteException, SmartFrogException { +// HashMap<String, String> map = new HashMap<String, String>(); +// +// String gwAddr = inVMTarget.getHostAddress().substring(0, inVMTarget.getHostAddress().lastIndexOf(".")) + ".1"; +// map.put(VMWareConstants.VM_EXECUTE_PARAM, String.format("-jar /tmp/helper.jar -nic %s %s gw %s -nic %s %s -hname %s %s", +// inVMTarget.getHostAddress(), +// inVMTarget.getHostMask(), +// gwAddr, +// inVMTarget.getVastNetworkIP(), +// inVMTarget.getVastNetworkMask(), +// inVMTarget.getDisplayName(), +// HostnameList)); +// +// for (Argument arg : inVMTarget.getListArguments()) +// if (arg.getName().equals("JAVA_HOME")) +// map.put(VMWareConstants.VM_EXECUTE_CMD, String.format("%s/bin/java", arg.getValue())); +// +// refAvlServer.sendVMCommand(inPacket.getFrom(), inVMName, VMWareConstants.VM_CMD_EXECUTE, map); +// } +// +// private void copyHelper(Packet inPacket, String inVMName, PhysicalMachineConfig inPhyHost, VirtualMachineConfig inVMTarget) throws RemoteException, SmartFrogException { +// HashMap<String, String> map = new HashMap<String, String>(); +// +// for (Argument arg : inPhyHost.getListArguments()) +// if (arg.getName().equals("AVALANCHE_HOME")) +// map.put(VMWareConstants.VM_COPY_HTOG_SOURCE, String.format("%s/smartfrog/dist/vast/helper.jar", arg.getValue())); +// +// for (Argument arg : inVMTarget.getListArguments()) +// if (arg.getName().equals("AVALANCHE_HOME")) +// map.put(VMWareConstants.VM_COPY_HTOG_DEST, String.format("%s/helper.jar", arg.getValue())); +// +// refAvlServer.sendVMCommand(inPacket.getFrom(), inVMName, VMWareConstants.VM_CMD_COPY_HOST_TO_GUEST, map); +// } +// +// private void waitForTools(Packet inPacket, String inVMName, VirtualMachineConfig inVMTarget) throws RemoteException, SmartFrogException { +// HashMap<String, String> map = new HashMap<String, String>(); +// map.put(VMWareConstants.VM_WAIT_FOR_TOOLS_TIMEOUT, String.format("%d", inVMTarget.getToolsTimeout())); +// refAvlServer.sendVMCommand(inPacket.getFrom(), inVMName, VMWareConstants.VM_CMD_WAIT_FOR_TOOLS, map); +// } +// +// private void takeSnapshot(Packet inPacket, String inVMName) throws RemoteException, SmartFrogException { +// HashMap<String, String> map = new HashMap<String, String>(); +// map.put(VMWareConstants.VM_TAKE_SNAPSHOT_NAME, "vast_snapshot"); +// map.put(VMWareConstants.VM_TAKE_SNAPSHOT_DESCRIPTION, "Snapshot taken by VAST"); +// map.put(VMWareConstants.VM_TAKE_SNAPSHOT_INCLUDE_MEMORY, "false"); +// refAvlServer.sendVMCommand(inPacket.getFrom(), inVMName, VMWareConstants.VM_CMD_TAKE_SNAPSHOT, map); +// } +// +// /** +// * Ignites a virtual machine. +// * +// * @param inVM +// */ +// private void igniteVirtualMachine(VirtualMachineConfig inVM) throws SmartFrogException, RemoteException { +// // ignite it with the according package +// refAvlServer.igniteHosts(new String[]{inVM.getHostAddress()}, +// String.format("%s/temp/vast/%s", refAvlServer.getAvalancheHome(), inVM.getSUTPackage()), +// String.format("%s/temp/vast/sfinstaller.vm", refAvlServer.getAvalancheHome())); +// } +// +// /** +// * Pings a host. +// * @param inHost Address to ping. +// * @return True if the ping was successful, false otherwise. +// */ +// private boolean ping(String inHost) { +// ProcessBuilder pb; +// if (System.getProperty("os.name").toLowerCase().startsWith("windows")) { +// pb = new ProcessBuilder("ping", inHost); +// } +// else { +// pb = new ProcessBuilder("ping", "-c", "4", inHost); +// } +// +// try { +// Process p = pb.start(); +// p.waitFor(); +// return (p.exitValue() == 0); +// } catch (Exception e) { +// sfLog().error(e); +// } +// +// return false; +// } } Modified: trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/VirtualMachineConfig.java =================================================================== --- trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/VirtualMachineConfig.java 2008-09-09 13:37:35 UTC (rev 7027) +++ trunk/core/extras/VAST/src/org/smartfrog/vast/architecture/VirtualMachineConfig.java 2008-09-09 13:52:49 UTC (rev 7028) @@ -19,6 +19,9 @@ */ package org.smartfrog.vast.architecture; +import org.smartfrog.vast.architecture.CommandDispatcher.Command; +import org.smartfrog.vast.architecture.CommandDispatcher.TimerThread; + public class VirtualMachineConfig extends PhysicalMachineConfig { public static String ATTR_AFFINITY = "Affinity"; public static String ATTR_NAME = "Name"; @@ -40,7 +43,10 @@ // virtual machine should be created private String SourceImage; - // user account for the guest os + // path to the helper on the host os + private String HelperPathOnHostOS; + + // user account for the guest os private String GuestUser; // password for the user account @@ -71,6 +77,64 @@ // how many times has it been tried to set up the network using the helper? private int NetworkSetupHelperTries; + // the current command that is being processed + private Command currentCommand; + + // command timeout timer + private TimerThread timerThread = new TimerThread(this); + private Thread curThread; + + // list of hostnames which this machine has to know + private String HostList; + + /** + * Sets the timer. Also sets it to the current command. + */ + public void setTimer() { + timerThread.setCommand(currentCommand); + timerThread.setTime(1000 * 120); + } + + /** + * Starts the timer if not already running. + */ + public void startTimer() { + if (curThread != null && !curThread.isAlive()) + curThread = new Thread(timerThread); + } + + /** + * Stops the timer if running. + */ + public void stopTimer() { + if (curThread != null && curThread.isAlive()) + timerThread.stopTimer(); + } + + public String getHostList() { + return HostList; + } + + public void setHostList(String hostList) { + HostList = hostList; + } + + public String getHelperPathOnHostOS() { + return HelperPathOnHostOS; + } + + public void setHelperPathOnHostOS(String helperPathOnHostOS) { + HelperPathOnHostOS = helperPathOnHostOS; + } + + public Command getCurrentCommand() { + return currentCommand; + } + + public void setCurrentCommand(Command currentCommand) { + this.currentCommand = currentCommand; + } + public int getNetworkSetupHelperTries() { return NetworkSetupHelperTries; } Added: trunk/core/extras/VAST/src/org/smartfrog/vast/testing/VastSchema.sf =================================================================== --- trunk/core/extras/VAST/src/org/smartfrog/vast/testing/VastSchema.sf (rev 0) +++ trunk/core/extras/VAST/src/org/smartfrog/vast/testing/VastSchema.sf 2008-09-09 13:52:49 UTC (rev 7028) @@ -0,0 +1,45 @@ +/** (C) Copyright 2008 Hewlett-Packard Development Company, LP + +Disclaimer of Warranty + +The Software is provided "AS IS," without a warranty of any kind. ALL +EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, +INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE HEREBY +EXCLUDED. SmartFrog is not a Hewlett-Packard Product. The Software has +not undergone complete testing and may contain errors and defects. It +may not function properly and is subject to change or withdrawal at +any time. The user must assume the entire risk of using the +Software. No support or maintenance is provided with the Software by +Hewlett-Packard. Do not install the Software if you... [truncated message content] |