medisyn
Class ScenarioConfig

java.lang.Object
  extended by medisyn.ScenarioConfig
All Implemented Interfaces:
IDataTransferrer

public class ScenarioConfig
extends java.lang.Object
implements IDataTransferrer

Represents a configuration with proxies and proxy groups. Provides saving and loading of configurations. Provides actions with the proxies like copying files to them...

Author:
Leo Bosnjak

Nested Class Summary
private static class ScenarioConfig.HelperOpType
          defines for what operations the HelperThread may be used for
(package private)  class ScenarioConfig.HelperThread
          inner class to execute various functions using a thread
 
Field Summary
private  boolean batchMode
           
private static java.lang.String BLACKLIST_FILE
           
private  java.util.Vector<FileCategory> fileCategories
           
private  java.lang.String fileName
           
private  ScenarioConfig.HelperThread helper
           
private  boolean loaded
           
private  int MIN_BOOTSTRAP_WAIT_TIME_IN_SEC
          Defines the minimum amount of secs to wait before the bootstrapping of some nodes is finished.
private  NodeEdgeMap nodeEdgeMap
           
private  ScenarioNodeMgr nodeMgr
           
private  java.util.Vector<ProxyGroup> proxyGroups
           
private static java.lang.String SCENARIO_FILE_EXT
           
 
Constructor Summary
ScenarioConfig(java.lang.String fileName)
           
 
Method Summary
 boolean addNodeToScenario(Node selectedNode)
          adds a node to the scenario
 boolean addSelectedNodesToSlice(PlanetLabMgr planetLabApi)
          add selected nodes to slice
 boolean bootstrapSelectedNodes(PlanetLabMgr planetLabApi)
          execute install.sh on nodes
 boolean bootstrapSelectedNodes(PlanetLabMgr planetLabApi, boolean waitUntilFinished)
          Calls the bootstrapSelectedNodes method and waits some defined time until this operation is finished.
private  boolean checkConsistency(java.util.Vector<X2XProxy> proxies, java.util.Vector<ProxyGroup> proxyGroups)
          Run a consistency check over the proxies and the proxyGroups.
 boolean copyDirToNodesInternal(PlanetLabMgr planetLabApi, java.lang.String sourceDir, java.lang.String remoteDir, java.util.Vector<Node> nodes)
          Copies the sourceDir from the local filesystem to the remoteDir of every node.
 boolean copyDirToSelectedNodes(PlanetLabMgr planetLabApi, java.lang.String sourceDir, java.lang.String remoteDir, boolean asynchronous)
          scp dir to nodes
 boolean copyDirToSelectedNodes(PlanetLabMgr planetLabApi, java.lang.String sourceDir, java.lang.String remoteDir, boolean asynchronous, java.util.Vector<Node> nodes)
          scp dir to nodes
 void deleteAllProxyGroups()
          Deletes the proxy-groups associations.
 void deleteFileCategory(FileCategory cat)
          deletes a category frome category-vector
 boolean execCmdOnNodesInternal(PlanetLabMgr planetLabApi, java.lang.String command, java.util.Vector<Node> nodes)
          Executes the given command on each node.
 boolean execCmdOnSelectedNodes(PlanetLabMgr planetLabApi, java.lang.String command, boolean asynchronous, java.util.Vector<Node> nodes)
          Executes the given command on each node.
 X2XProxy findNode(java.lang.String hostName)
          Tries to find the X2XProxy which has the given hostname.
 boolean getClientVersionOfSelectedNodes(PlanetLabMgr planetLabApi, java.util.Vector<X2XProxy> badNodes)
          get the version of the scenario-nodes, remember the badNodes
 boolean getClientVersionOfSelectedNodesEx(PlanetLabMgr planetLabApi, java.util.Vector<X2XProxy> badNodes)
          get the version of the scenario-nodes and add the bad nodes to the blacklist
 boolean getDirFromNodesInternal(PlanetLabMgr planetLabApi, java.lang.String remoteDir, java.lang.String localDir, java.util.Vector<Node> nodes)
          Transfers the remote directory from each of the nodes and saves it to the local directory
 boolean getDirFromSelectedNodes(PlanetLabMgr planetLabApi, java.lang.String remoteDir, java.lang.String localDir, boolean asynchronous)
          Transfers the remote directory from each of the nodes and saves it to the local directory
 boolean getDirFromSelectedNodes(PlanetLabMgr planetLabApi, java.lang.String remoteDir, java.lang.String localDir, boolean asynchronous, java.util.Vector<Node> nodes)
          Transfers the remote directory from each of the nodes and saves it to the local directory
 java.util.Vector<FileCategory> getFileCategories()
           
 java.lang.String getFileName()
           
 NodeEdgeMap getNodeEdgeMap()
           
 ScenarioNodeMgr getNodeMgr()
           
 java.util.Vector<X2XProxy> getNodes()
           
 ProxyGroup getProxGroupByName(java.lang.String name)
          returns the ProxyGroup which has the given name.
 java.util.Vector<java.awt.Color> getProxyGroupColors()
           
 java.util.Vector<java.lang.String> getProxyGroupNames()
           
 java.util.Vector<ProxyGroup> getProxyGroups()
           
static java.lang.String getSCENARIO_FILE_EXT()
           
 boolean isBatchMode()
           
 boolean loadConfig()
          load an existing config file
 void printProxyGroups()
          prints the proxy-grups and their proxies to stdout
 boolean randomSelectNodes(NodeEdgeMap map)
          randomly select some nodes from different continents select at most one node from a City of the appropriate region TODO: write the selected nodes and their location to a file
private  void randomSelectNodesFromVec(java.util.Vector<Node> Nodes, int nodesToSelect, boolean atmostOneNodePerCity, java.util.Vector<Node> selectedNodes)
          helper function to randomly select N nodes from the Vector, The selected Nodes are removed from Vector "Nodes"!
 boolean removeNodeFromScenario(Node toRemove)
          removes a node from the scenario
 boolean saveConfig()
          save config into file for later use
 void setBatchMode(boolean batchMode)
           
 void setFileCategories(java.util.Vector<FileCategory> fileCategories)
           
 void setFileName(java.lang.String fileName)
           
 void setNodeEdgeMap(NodeEdgeMap nodeEdgeMap)
          Set the node edge map and recalculate the Nodes and Edges!
 void setNodeMgr(ScenarioNodeMgr nodeMgr)
           
 void setProxyGroups(java.util.Vector<ProxyGroup> proxyGroups)
           
 boolean updateEdgeData()
          On each call the existing edges are deleted from the map first.
 boolean updateNodeData()
          Iterate thrugh all the proxy-nodes, try to find the appropriate planetLabNode and update the data of each proxy
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MIN_BOOTSTRAP_WAIT_TIME_IN_SEC

private final int MIN_BOOTSTRAP_WAIT_TIME_IN_SEC
Defines the minimum amount of secs to wait before the bootstrapping of some nodes is finished.

See Also:
Constant Field Values

BLACKLIST_FILE

private static final java.lang.String BLACKLIST_FILE
See Also:
Constant Field Values

SCENARIO_FILE_EXT

private static final java.lang.String SCENARIO_FILE_EXT
See Also:
Constant Field Values

fileName

private java.lang.String fileName

nodeMgr

private ScenarioNodeMgr nodeMgr

fileCategories

private java.util.Vector<FileCategory> fileCategories

proxyGroups

private java.util.Vector<ProxyGroup> proxyGroups

loaded

private boolean loaded

batchMode

private boolean batchMode

nodeEdgeMap

private NodeEdgeMap nodeEdgeMap

helper

private ScenarioConfig.HelperThread helper
Constructor Detail

ScenarioConfig

public ScenarioConfig(java.lang.String fileName)
Parameters:
fileName - - including file-ext but without path
Method Detail

updateNodeData

public boolean updateNodeData()
Iterate thrugh all the proxy-nodes, try to find the appropriate planetLabNode and update the data of each proxy

Returns:
true if successful

updateEdgeData

public boolean updateEdgeData()
On each call the existing edges are deleted from the map first. Then the new edges are created from each proxy to it's group leader.

Returns:
true if successful

deleteFileCategory

public void deleteFileCategory(FileCategory cat)
deletes a category frome category-vector

Parameters:
cat - - the category to delete

checkConsistency

private boolean checkConsistency(java.util.Vector<X2XProxy> proxies,
                                 java.util.Vector<ProxyGroup> proxyGroups)
Run a consistency check over the proxies and the proxyGroups.

Returns:
true if successful

saveConfig

public boolean saveConfig()
                   throws java.lang.Exception
save config into file for later use

Returns:
true if save was successful
Throws:
java.lang.Exception - - if an exception occoured

loadConfig

public boolean loadConfig()
load an existing config file

Returns:
true if loading was successful

deleteAllProxyGroups

public void deleteAllProxyGroups()
Deletes the proxy-groups associations. --> The nodes are now on their own again.


addNodeToScenario

public boolean addNodeToScenario(Node selectedNode)
adds a node to the scenario

Parameters:
selectedNode -
Returns:
true if successful, false if an exception occoured

removeNodeFromScenario

public boolean removeNodeFromScenario(Node toRemove)
removes a node from the scenario

Parameters:
toRemove - - the node to remove
Returns:
true if the node has been removed

randomSelectNodes

public boolean randomSelectNodes(NodeEdgeMap map)
randomly select some nodes from different continents select at most one node from a City of the appropriate region TODO: write the selected nodes and their location to a file

Parameters:
map - - NodeEdgeMap
Returns:
true if successful
See Also:
ImageViewer.handleTakesPartChange(boolean)

randomSelectNodesFromVec

private void randomSelectNodesFromVec(java.util.Vector<Node> Nodes,
                                      int nodesToSelect,
                                      boolean atmostOneNodePerCity,
                                      java.util.Vector<Node> selectedNodes)
helper function to randomly select N nodes from the Vector, The selected Nodes are removed from Vector "Nodes"!

Parameters:
Nodes - - the pool of nodes to select some from
nodesToSelect - - nr of nodes to chose from the pool
atmostOneNodePerCity - - if the option is true: at most one node of a city in the region is selected
selectedNodes - - result set, may already contain nodes

copyDirToSelectedNodes

public boolean copyDirToSelectedNodes(PlanetLabMgr planetLabApi,
                                      java.lang.String sourceDir,
                                      java.lang.String remoteDir,
                                      boolean asynchronous)
scp dir to nodes

Parameters:
sourceDir - - local directory path to copy to the selected nodes. If empty or null, the DEFAULT_COPY_DIR is taken.
asynchronous - - if true: copy operation will be asynchronously executed in a thread. Note that only one asynchronous copy operation is allowed at a time.

copyDirToSelectedNodes

public boolean copyDirToSelectedNodes(PlanetLabMgr planetLabApi,
                                      java.lang.String sourceDir,
                                      java.lang.String remoteDir,
                                      boolean asynchronous,
                                      java.util.Vector<Node> nodes)
scp dir to nodes

Parameters:
sourceDir - - local directory path to copy to the selected nodes. If empty or null, the DEFAULT_COPY_DIR is taken.
asynchronous - - if true: copy operation will be asynchronously executed in a thread. Note that only one asynchronous copy operation is allowed at a time.
nodes - - The nodes to copy to

copyDirToNodesInternal

public boolean copyDirToNodesInternal(PlanetLabMgr planetLabApi,
                                      java.lang.String sourceDir,
                                      java.lang.String remoteDir,
                                      java.util.Vector<Node> nodes)
Copies the sourceDir from the local filesystem to the remoteDir of every node.

Specified by:
copyDirToNodesInternal in interface IDataTransferrer
Parameters:
planetLabApi -
sourceDir - - The directory to copy from
nodes - - The nodes to copy to

getDirFromSelectedNodes

public boolean getDirFromSelectedNodes(PlanetLabMgr planetLabApi,
                                       java.lang.String remoteDir,
                                       java.lang.String localDir,
                                       boolean asynchronous)
Transfers the remote directory from each of the nodes and saves it to the local directory

Parameters:
planetLabApi -
remoteDir - - the remote directory which is located at each node
localDir - - the local directory which is used as destination for the remote directories of the nodes. A subdirectory named like the hostname of each node will be created to save the remote dir of the node.
asynchronous - - if true, then the work will be done using a separate thread

getDirFromSelectedNodes

public boolean getDirFromSelectedNodes(PlanetLabMgr planetLabApi,
                                       java.lang.String remoteDir,
                                       java.lang.String localDir,
                                       boolean asynchronous,
                                       java.util.Vector<Node> nodes)
Transfers the remote directory from each of the nodes and saves it to the local directory

Parameters:
planetLabApi -
remoteDir - - the remote directory which is located at each node
localDir - - the local directory which is used as destination for the remote directories of the nodes. A subdirectory named like the hostname of each node will be created to save the remote dir of the node.
asynchronous - - if true, then the work will be done using a separate thread
nodes - - the nodes from which the directory will be copied to our pc

getDirFromNodesInternal

public boolean getDirFromNodesInternal(PlanetLabMgr planetLabApi,
                                       java.lang.String remoteDir,
                                       java.lang.String localDir,
                                       java.util.Vector<Node> nodes)
Transfers the remote directory from each of the nodes and saves it to the local directory

Specified by:
getDirFromNodesInternal in interface IDataTransferrer
Parameters:
planetLabApi -
remoteDir - - the remote directory which is located at each node
localDir - - the local directory which is used as destination for the remote directories of the nodes. A subdirectory named like the hostname of each node will be created to save the remote dir of the node.
nodes - - the nodes from which the directory will be copied to our pc

execCmdOnSelectedNodes

public boolean execCmdOnSelectedNodes(PlanetLabMgr planetLabApi,
                                      java.lang.String command,
                                      boolean asynchronous,
                                      java.util.Vector<Node> nodes)
Executes the given command on each node.

Parameters:
planetLabApi -
command - - The shell command to execute on each node.
asynchronous - - if true, then the work will be done using a separate thread
nodes - - the nodes from which the directory will be copied to our pc

execCmdOnNodesInternal

public boolean execCmdOnNodesInternal(PlanetLabMgr planetLabApi,
                                      java.lang.String command,
                                      java.util.Vector<Node> nodes)
Executes the given command on each node.

Specified by:
execCmdOnNodesInternal in interface IDataTransferrer
Parameters:
planetLabApi -
command - - The shell command to execute on each node.
nodes - - the nodes from which the directory will be copied to our pc

addSelectedNodesToSlice

public boolean addSelectedNodesToSlice(PlanetLabMgr planetLabApi)
add selected nodes to slice

Returns:
true if successful

getClientVersionOfSelectedNodes

public boolean getClientVersionOfSelectedNodes(PlanetLabMgr planetLabApi,
                                               java.util.Vector<X2XProxy> badNodes)
get the version of the scenario-nodes, remember the badNodes

Returns:
true if successful

getClientVersionOfSelectedNodesEx

public boolean getClientVersionOfSelectedNodesEx(PlanetLabMgr planetLabApi,
                                                 java.util.Vector<X2XProxy> badNodes)
get the version of the scenario-nodes and add the bad nodes to the blacklist


bootstrapSelectedNodes

public boolean bootstrapSelectedNodes(PlanetLabMgr planetLabApi)
execute install.sh on nodes


bootstrapSelectedNodes

public boolean bootstrapSelectedNodes(PlanetLabMgr planetLabApi,
                                      boolean waitUntilFinished)
Calls the bootstrapSelectedNodes method and waits some defined time until this operation is finished.

Returns:
true if bootstrapping could be started successfully

getFileName

public java.lang.String getFileName()
Returns:
the fileName

setFileName

public void setFileName(java.lang.String fileName)
Parameters:
fileName - the fileName to set

getNodeMgr

public ScenarioNodeMgr getNodeMgr()
Returns:
the nodes

setNodeMgr

public void setNodeMgr(ScenarioNodeMgr nodeMgr)
Parameters:
nodeMgr - - containing the nodes to set

getNodes

public java.util.Vector<X2XProxy> getNodes()
Returns:
the nodes of the NodeMgr

getFileCategories

public java.util.Vector<FileCategory> getFileCategories()
Returns:
the fileCategories

setFileCategories

public void setFileCategories(java.util.Vector<FileCategory> fileCategories)
Parameters:
fileCategories - the fileCategories to set

getProxyGroups

public java.util.Vector<ProxyGroup> getProxyGroups()
Returns:
the proxyGroups

getProxyGroupNames

public java.util.Vector<java.lang.String> getProxyGroupNames()
Returns:
the names of the proxyGroups

getProxyGroupColors

public java.util.Vector<java.awt.Color> getProxyGroupColors()
Returns:
the colors of the proxyGroups

getProxGroupByName

public ProxyGroup getProxGroupByName(java.lang.String name)
returns the ProxyGroup which has the given name.

Parameters:
name -
Returns:
the ProxyGroup with the given name, if it can be found, null otherwise.

findNode

public X2XProxy findNode(java.lang.String hostName)
Tries to find the X2XProxy which has the given hostname.

Parameters:
hostName -
Returns:
the X2XProxy with the given name, if it can be found, null otherwise.

setProxyGroups

public void setProxyGroups(java.util.Vector<ProxyGroup> proxyGroups)
Parameters:
proxyGroups - the proxyGroups to set

printProxyGroups

public void printProxyGroups()
                      throws java.lang.Exception
prints the proxy-grups and their proxies to stdout

Throws:
java.lang.Exception
See Also:
ProxyGenerator.printProxyGroups(ProxyGroup)

isBatchMode

public boolean isBatchMode()
Returns:
the batchMode

setBatchMode

public void setBatchMode(boolean batchMode)
Parameters:
batchMode - the batchMode to set

getNodeEdgeMap

public NodeEdgeMap getNodeEdgeMap()
Returns:
the NodeEdgeMap

setNodeEdgeMap

public void setNodeEdgeMap(NodeEdgeMap nodeEdgeMap)
Set the node edge map and recalculate the Nodes and Edges!

Parameters:
nodeEdgeMap -

getSCENARIO_FILE_EXT

public static java.lang.String getSCENARIO_FILE_EXT()
Returns:
the file extension ".xml" of scenario and result files.