import and.Mapping.Graph;
import and.Mapping.Grid;
import and.Mapping.LSM;
-import and.Mapping.Mapping;
import and.Mapping.QM;
import and.Mapping.Simple;
import and.Mapping.Utils;
private ArrayList<GNode> gnodes = null;
private Algo al = null ;
private int count = 0 ;
- private boolean inDemand = false, operating = false ;
+ private boolean inDemand = false, operating = false, authorized = false ;
// private boolean daemonListChange ;
// Constructors
SuperNodeListe.Instance().viewAll();
}
- public void sendSurplus(Vector<?> nodes) throws RemoteException {
+ public void sendSurplus(Vector<?> nodes, ArrayList<GNode> _gnodes) throws RemoteException {
System.out.println("Recieved " + nodes.size() + " nodes");
for (int i = 0; i < nodes.size(); i++) {
.setNbOfNodes(Register.Instance().getSize());
new ForwardCount().start();
} catch (Exception e) {
- System.out.println("Error changing Server in SendSurplus : "
+ System.err.println("Error changing Server in SendSurplus : "
+ e);
}
}
+
+ /** Updating gnodes **/
+ if( _gnodes != null )
+ {
+ gnodes = _gnodes ;
+ }
}
public void setToken() throws RemoteException {
System.out.println("Put token to true");
} catch (Exception e) {
- System.out
+ System.err
.println("Unable to heartBeat the next SuperNode with the new Token : "
+ e);
}
public synchronized void workerRegistering(JaceInterface workerStub,
String workerIP, String workerName, int port, GNode g)
throws RemoteException {
- System.out.println("CONNEXION of " + workerName);
+ System.out.println("CONNECTION of " + workerName);
// Create the node
Node noeud = new Node(workerStub);
noeud.setId( count ) ;
noeud.setId( Long.parseLong( workerIP.replace( ".", "" ) ) ) ;
- g.setNode(noeud);
+ g.setNode( noeud ) ;
g.setId( noeud.getId() ) ;
+ g.setMapped( false ) ;
workingOnGnodes() ;
- gnodes.add(g);
+ gnodes.add( g ) ;
// daemonListChange = true ;
.setNbOfNodes(Register.Instance().getSize());
SuperNodeListe.Instance().forwardCountNode();
+ authorized = true ;
SuperNodeListe.Instance().addGNode( g ) ;
+ authorized = false ;
operating = false ;
}
/** Mapping !! Sébastien Miquée **/
/*********************************/
+ /**
+ * Search and return to the requester spawner a register containing
+ * computation nodes plus some extra nodes if needed. This method requires
+ * as parameters the mapping algorithm choice and its parameters, and the
+ * amount of requested nodes and the task to be used, in order to
+ * construct the tasks graph.
+ * @param spawnerIP IP of the requester
+ * @param nbTasks Amount of tasks
+ * @param t Tasks to be executed
+ * @param nbNoeuds Total amount of requested nodes
+ * @param algo Identifier of the mapping algorithm
+ * @param paramAlgo Parameter of the mapping algorithm
+ *
+ * @author Sébastien Miquée
+ */
+ @Override
public Register getRegisterSpawner(String spawnerIP, int nbTasks, Task t,
int nbNoeuds, int algo, double paramAlgo) throws RemoteException {
/** Initialization of Grid architecture (G5K for now) **/
Grid grid = Utils.createGridG5k(gnodes);
- grid.initClusters();
+// grid.initClusters();
+
/** Creation of tasks GTask **/
ArrayList<GTask> ts = new ArrayList<GTask>();
}
}
}
+
Graph graph = new Graph();
/** Launching the Mapping **/
al.map();
- /** Transforming mapping in register **/
- Mapping mp = al.getMapping();
/** Creating the register **/
- ArrayList<GNode> ag = mp.getMappedGNodes();
+ ArrayList<GNode> ag = al.getMapping().getMappedGNodes();
- for (int i = 0; i < ag.size(); i++) {
+ authorized = true ;
+
+ for( int i = 0; i < ag.size(); i++ ) {
reg.addNode((Node) ag.get(i).getNode());
- gnodes.remove(ag.get(i));
- Register.Instance().removeNode((Node) ag.get(i).getNode());
+ delGNodeFromList( (Node) ag.get(i).getNode(), 2 ) ;
+// gnodes.remove(ag.get(i));
+// Register.Instance().removeNode((Node) ag.get(i).getNode());
+ }
+
+
+ /** Searching extra nodes if any **/
+ if( nbNoeuds > nbTasks )
+ {
+ int nb = nbNoeuds - nbTasks ;
+ GNode sup = null ;
+
+ for( int i = 0 ; i < nb ; i ++ )
+ {
+ sup = al.getOtherGNode( gnodes ) ;
+ reg.addNodeBeg( (Node) sup.getNode() ) ;
+ delGNodeFromList( (Node) sup.getNode(), 2 ) ;
+ }
}
+
+ authorized = false ;
if (ag.size() != 0) {
SuperNodeListe.Instance().forwardCountNode();
}
-// daemonListChange = false ;
-
- System.out.println( "Spawner returned reg: " + reg ) ;
+// System.out.println( "Spawner returned reg: " + reg ) ;
- /** Mapping distribution over other Super Nodes */
+ /** Mapping distribution over other SuperNodes */
SuperNodeListe.Instance().setMapping( al ) ;
operating = false ;
- /* Returning result */
+ /** Returning result **/
return reg ;
}
- /*****************************************/
- /**** Sébastien Miquée ****/
- /** **/
- /** Recherche nouveau noeud **/
- /*****************************************/
- protected GNode delGNodeFromList( Node _n )
+ /**
+ * Suppress a node from the gnodes list if this node is free, or remove
+ * it from the Mapping class of the mapping algorithm if this node is
+ * a computation node. After having done the local suppression of the node
+ * it propagates the suppression to other SuperNodes.
+ * @param _n The fallen node
+ * @param _mode Choice of the list (0: gnodes, 1: mapping, 2:just mapped)
+ *
+ * @author Sébastien Miquée
+ */
+ @Override
+ public GNode delGNodeFromList( Node _n, int _mode ) throws RemoteException
{
GNode removedGNode = null ;
if( _n != null )
- {
- workingOnGnodes() ;
+ {
+ boolean free = false ;
+
+ if( ! operating )
+ {
+ workingOnGnodes() ;
+ free = true ;
+ }
- for( int i = 0 ; i < gnodes.size() ; i++ )
+ /** The dead node is not in the mapping **/
+ if( _mode == 0 || _mode == 2)
{
- if( ((Node)gnodes.get(i).getNode()).getId() == _n.getId() )
+ for( int i = 0 ; i < gnodes.size() ; i++ )
{
- removedGNode = gnodes.remove( i ) ;
- break ;
+ if( ((Node)gnodes.get(i).getNode()).getId() == _n.getId() )
+ {
+ removedGNode = gnodes.remove( i ) ;
+ Register.Instance().removeNodeOfName( removedGNode.getName() ) ;
+ break ;
+ }
}
}
-
-// daemonListChange = true ;
-
- SuperNodeListe.Instance().removeGNode( removedGNode ) ;
- operating = false ;
+ /** The dead node is in the mapping **/
+ if( _mode == 1 )
+ {
+ ArrayList<GNode> temp = al.getMapping().getMappedGNodes() ;
+
+ for( int i = 0 ; i < temp.size() ; i++ )
+ {
+ if( ((Node)temp.get(i).getNode()).getId() == _n.getId() )
+ {
+ removedGNode = temp.get( i ) ;
+ Register.Instance().removeNodeOfName( removedGNode.getName() ) ;
+ break ;
+ }
+ }
+ }
+
+ /** Removing the dead node from the Grid **/
+ if( _mode == 0 || _mode == 1 ) {
+ al.getGrid().removeGNode( removedGNode ) ;
+ }
+
+ /** Propagation of the deletion **/
+ SuperNodeListe.Instance().removeGNode( removedGNode, _mode ) ;
+
+ if( free )
+ {
+ operating = false ;
+ }
}
}
+ /**
+ * Determine if this SuperNode can operate on the gnodes list.
+ * It asks other SuperNodes to know if their are working on this list
+ * and set the authorization, or not.
+ *
+ * @author Sébastien Miquée
+ */
private void workingOnGnodes()
{
boolean tmp = true ;
while( ! operating )
{
inDemand = true ;
+ tmp = true ;
tmp = tmp && SuperNodeListe.Instance().workingOnGnodes() ;
inDemand = false ;
}
-
+ /**
+ * Search and return a new node when one failed or when JaceP2P needs another
+ * one. For the first case, the given failed node should not be null, and
+ * null in the other case.
+ * @param _spawnerIP IP of the requester
+ * @param _deadNode The failed node
+ *
+ * @author Sébastien Miquée
+ */
+ @Override
public Node getNewNode( String _spawnerIP, Node _deadNode ) throws RemoteException
{
Node node = null ;
if( _deadNode != null )
{
- gnode = delGNodeFromList( _deadNode ) ;
-
+ authorized = true ;
+
+ gnode = delGNodeFromList( _deadNode, 1 ) ;
+
remp = al.replaceNode( gnode, gnodes ) ;
if( remp != null )
{
System.out.println( "Replacing node found." ) ;
- node = (Node) remp.getNode() ;
- delGNodeFromList( node ) ;
+
+ remp.setMapped( true ) ;
+
+ delGNodeFromList( (Node) remp.getNode(), 2 ) ;
+
+ authorized = false ;
+
SuperNodeListe.Instance().forwardCountNode();
} else {
System.err.println( "Replacing node not found !!" ) ;
if( remp != null )
{
System.out.println( "Other new node found." ) ;
- node = (Node) remp.getNode() ;
- delGNodeFromList( node ) ;
+
+ remp.setMapped( true ) ;
+
+ authorized = true ;
+
+ delGNodeFromList( (Node) remp.getNode(), 2 ) ;
+
+ authorized = false ;
+
SuperNodeListe.Instance().forwardCountNode();
} else {
System.err.println( "Other new node not found !!" ) ;
}
}
+
+ /** Updating all mapping **/
+ updateMappedNode( gnode, remp ) ;
+ propagateReplaceNode( gnode, remp ) ;
+
+
/** Free the gnodes use **/
operating = false ;
}
- /**********************************************************/
- /**********************************************************/
-
+ /**
+ * Replace a failed GNode in the mapping by another one.
+ * This method is called by the SuperNodeList, to broadcast the modification.
+ * @param _dead The failed node
+ * @param _remp The replacing node
+ *
+ * @author Sébastien Miquée
+ */
@Override
- public void addGNode( GNode _g ) throws RemoteException
+ public void updateMappedNode( GNode _dead, GNode _remp )
{
- if( _g != null )
+ if( _remp != null )
{
- workingOnGnodes() ;
-
- gnodes.add( _g ) ;
+ int pos = 0 ;
+
+ pos = al.getMapping().getIdOfAssociation( _dead ) ;
+
+ if( pos != -1 )
+ {
+ /** Changing the node in the mapping **/
+ al.getMapping().getMapping().get( pos ).setGNode( _remp ) ;
+
+ System.out.println( "Succesfully replacing the fallen node in the mapping." ) ;
+ }
- operating = false ;
+ /** Changing the status in the grid **/
+ al.getGrid().setMappedStatus( _remp, true ) ;
+
+ al.updateGrid() ;
+ } else {
+ System.err.println( "The new GNode is null!" ) ;
}
}
+
+ /**
+ * Inform all SuperNodes of the replacement of a failed computing node.
+ * @param _dead The failed node
+ * @param _remp The replacing node
+ *
+ * @author Sébastien Miquée
+ */
+ private void propagateReplaceNode( GNode _dead, GNode _remp ) throws RemoteException
+ {
+ if( _remp != null )
+ {
+ SuperNodeListe.Instance().propagateReplaceNode( _dead, _remp ) ;
+ }
+ }
+
+ /**********************************************************/
+ /**********************************************************/
+
@Override
- public void removeGNode( GNode _g ) throws RemoteException
+ /**
+ * Add a new node in the list.
+ * @param _g The new node
+ *
+ * @author Sébastien Miquée
+ */
+ public void addGNode( GNode _g ) throws RemoteException
{
if( _g != null )
{
- workingOnGnodes() ;
+ boolean free = false ;
- for( int i = 0 ; i < gnodes.size() ; i++ )
+ if( ! operating )
{
- if( ((Node)gnodes.get(i).getNode()).getId() == ((Node)_g.getNode()).getId() )
- {
- gnodes.remove( i ) ;
- break ;
- }
- }
+ workingOnGnodes() ;
+ free = true ;
+ }
+
+ gnodes.add( _g ) ;
- operating = false ;
+ if( free )
+ operating = false ;
}
-
}
+// @Override
+// public void removeGNode( GNode _g ) throws RemoteException
+// {
+// if( _g != null )
+// {
+// boolean free = false ;
+//
+// if( ! operating )
+// {
+// workingOnGnodes() ;
+// free = true ;
+// }
+//
+// for( int i = 0 ; i < gnodes.size() ; i++ )
+// {
+// if( ((Node)gnodes.get(i).getNode()).getId() == ((Node)_g.getNode()).getId() )
+// {
+// gnodes.remove( i ) ;
+// Register.Instance().removeNodeOfName( _g.getName() ) ;
+// break ;
+// }
+// }
+//
+// if( free )
+// operating = false ;
+// }
+//
+// }
+
+
+ /**
+ * Set the local mapping with another done on an other SuperNode.
+ * @param _al The new mapping
+ *
+ * @author Sébastien Miquée
+ */
@Override
public void setMapping( Algo _al ) throws RemoteException
{
al = _al ;
}
+
@Override
/**
* Allow or deny the use of operations on the gnodes list, in order to
* do a mapping operation.
- * @author miquee
* @return The authorization or not to block gnodes
+ *
+ * @author Sébastien Miquée
*/
- public boolean blockForMapping()
+ public boolean blockForMapping() throws RemoteException
{
while( inDemand )
{
}
}
- if( operating )
+ if( operating && ! authorized )
{
return false ;
} else {
return true ;
}
}
+
+ /**
+ * Return the array containing the current not mapped nodes available.
+ * @return The array of available nodes
+ *
+ * @author Sébastien Miquée
+ */
+ @Override
+ public ArrayList<GNode> getGNodes() throws RemoteException
+ {
+ return gnodes ;
+ }
}