import and.Mapping.Algo;
import and.Mapping.DefaultMapping;
+import and.Mapping.FT_AIAC_QM;
+import and.Mapping.FT_FEC;
import and.Mapping.GNode;
import and.Mapping.GTask;
import and.Mapping.Graph;
import and.Mapping.Grid;
-import and.Mapping.LSM;
-import and.Mapping.QM;
+import and.Mapping.Maheve;
import and.Mapping.Simple;
-import and.Mapping.Utils;
public class JaceSuperNodeServer extends UnicastRemoteObject implements
private int beat;
private ArrayList<GNode> gnodes = null;
private ArrayList<Algo> algos = null ;
- private int count = 0 ;
private boolean inDemand = false, operating = false, authorized = false ;
-// private boolean daemonListChange ;
// Constructors
beat = timeBeat ;
gnodes = new ArrayList<GNode>() ;
algos = new ArrayList<Algo>() ;
-// daemonListChange = true ;
}
public int getSuperNodeBeat() throws RemoteException {
// Create the node
Node noeud = new Node(workerStub);
noeud.setName(workerName);
- noeud.setIP(workerIP);
+ noeud.setIP(g.getIP());
noeud.setAliveFlag(true);
noeud.setAliveTime();
noeud.setPort(port);
noeud.setAppliName(null);
noeud.setNbOfBeats(0);
- noeud.setId( count ) ;
- noeud.setId( Long.parseLong( workerIP.replace( ".", "" ) ) ) ;
+
+ String sid = workerIP.replace( ".", "" ) + port ;
+ Long id = Long.parseLong( sid ) ;
+ noeud.setId( id ) ;
g.setNode( noeud ) ;
- g.setId( noeud.getId() ) ;
+ g.setId( id ) ;
g.setMapped( false ) ;
workingOnGnodes() ;
gnodes.add( g ) ;
+ updateGrids( g ) ;
-// daemonListChange = true ;
// Insert the node in the Register.Instance() of the Super Node
Register.Instance().addNode(noeud);
operating = false ;
}
+
+ /**
+ * Update all mapping algorithms with a new node.
+ * @param _g The new node
+ *
+ * @author Sébastien Miquée
+ */
+ private synchronized void updateGrids( GNode _g )
+ {
+ if( _g != null )
+ {
+ for( int i = 0 ; i < algos.size() ; i++ )
+ {
+ algos.get( i ).getGrid().addGNode( _g ) ;
+ }
+ }
+
+ }
+
/****************************************************/
/****************************************************/
* @author Sébastien Miquée
*/
@Override
- public Register getRegisterSpawner(String spawnerIP, int nbTasks, Task t,
+ public synchronized Register getRegisterSpawner(String spawnerIP, int nbTasks, Task t,
int nbNoeuds, int algo, double paramAlgo) throws RemoteException {
// Have we the correct application ?
workingOnGnodes() ;
/** Initialization of Grid architecture (G5K for now) **/
- Grid grid = Utils.createGridG5k(gnodes);
-// grid.initClusters();
+ Grid grid = new Grid() ;
+
+ for( int i = 0 ; i < gnodes.size() ; i++ )
+ {
+ grid.addGNode( gnodes.get( i ) ) ;
+ }
/** Informing about the grid heterogeneity **/
graph.addGTask(ts.get(i));
}
- // -- debug !
- // graph.print() ;
-
- // try {
- // Thread.sleep(10000) ;
- // } catch( Exception e ) {}
-
- // grid.print() ;
- //
- // try {
- // Thread.sleep( 10000 ) ;
- // } catch( Exception e ) {}
-
+ /** TODO Loading algorithm class with parameters in a configuration file **/
/** Selection of the mapping algorithm **/
Algo al = null ;
al = new Simple(graph, grid);
break;
case 1:
- al = new QM(graph, grid, paramAlgo);
+ al = new FT_AIAC_QM(graph, grid, paramAlgo);
break;
case 2:
- al = new LSM(graph, grid, paramAlgo);
+ al = new FT_FEC(graph, grid, paramAlgo);
break;
+ case 3:
+ al = new Maheve( graph, grid ) ;
+ break ;
default:
al = new DefaultMapping( graph, grid, gnodes ) ;
}
/** Creating the register **/
ArrayList<GNode> ag = al.getMapping().getMappedGNodes();
+
+ System.out.println("NB returned nodes : "+ag.size());
+
+ /** Setting the algorithm's identifier **/
+ al.setIdS( spawnerIP ) ;
+
+ /** Adding the algorithm in the list **/
+ algos.add( al ) ;
+
+ int idAlgo = searchAlgo( spawnerIP ) ;
+
+ /** Mapping distribution over other SuperNodes */
+ SuperNodeListe.Instance().setMapping( al ) ;
+
+
+
authorized = true ;
for( int i = 0; i < ag.size(); i++ ) {
reg.addNode((Node) ag.get(i).getNode());
- delGNodeFromList( (Node) ag.get(i).getNode(), 2, spawnerIP ) ;
-// gnodes.remove(ag.get(i));
-// Register.Instance().removeNode((Node) ag.get(i).getNode());
+
+ ag.get(i).setMapped( true ) ;
+ setMapped( ag.get(i), 1 ) ;
+ Register.Instance().removeNode((Node) ag.get(i).getNode());
}
for( int i = 0 ; i < nb ; i ++ )
{
- sup = al.getOtherGNode( gnodes ) ;
+ sup = algos.get(idAlgo).getOtherGNode( gnodes ) ;
+ algos.get(idAlgo).getMapping().addOtherNode( sup ) ;
reg.addNodeBeg( (Node) sup.getNode() ) ;
- delGNodeFromList( (Node) sup.getNode(), 2, spawnerIP ) ;
+ setMapped( sup, 1 ) ;
+ Register.Instance().removeNode((Node) sup.getNode());
}
}
if (ag.size() != 0) {
SuperNodeListe.Instance().forwardCountNode();
}
-
- /** Setting the algorithm's identifier **/
- al.setIdS( spawnerIP ) ;
-
- /** Adding the algorithm in the list **/
- algos.add( al ) ;
}
-// System.out.println( "Spawner returned reg: " + reg ) ;
-
- /** Mapping distribution over other SuperNodes */
- SuperNodeListe.Instance().setMapping( al ) ;
-
operating = false ;
/** Returning result **/
}
+ public synchronized void setMapped( GNode _g, int _mode ) throws RemoteException
+ {
+ if( _g != null )
+ {
+ _g.setMapped( true ) ;
+
+ for( int i = 0 ; i < gnodes.size() ; i++ )
+ {
+ if( _g.getId() == gnodes.get( i ).getId() )
+ {
+ gnodes.remove( i ) ;
+ break ;
+ }
+ }
+
+ for( int i = 0 ; i < algos.size() ; i++ )
+ {
+ algos.get( i ).getGrid().setMappedStatus( _g, true ) ;
+ }
+
+ if( _mode == 1 )
+ {
+ authorized = true ;
+
+ SuperNodeListe.Instance().setMappedGNode( _g, 0 ) ;
+
+ authorized = false ;
+ }
+ } else {
+ System.err.println( "GNode is null is setMapped!" ) ;
+ }
+ }
+
/**
* 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
* @author Sébastien Miquée
*/
@Override
- public GNode delGNodeFromList( Node _n, int _mode, String _spawnerIp ) throws RemoteException
+ public synchronized GNode delGNodeFromList( Node _n, int _mode, String _spawnerIp ) throws RemoteException
{
GNode removedGNode = null ;
workingOnGnodes() ;
free = true ;
}
-
- /** The dead node is not in the mapping **/
- if( _mode == 0 || _mode == 2)
+
+ if( _mode == 0 )
{
+ GNode dead = null ;
+
for( int i = 0 ; i < gnodes.size() ; i++ )
{
- if( ((Node)gnodes.get(i).getNode()).getId() == _n.getId() )
+ if( _n.getId() == ((Node) gnodes.get(i).getNode()).getId() )
{
- removedGNode = gnodes.remove( i ) ;
- Register.Instance().removeNodeOfName( removedGNode.getName() ) ;
+ dead = gnodes.remove( i ) ;
break ;
}
}
- }
-
- /** The dead node is in the mapping **/
- if( _mode == 1 )
- {
- /** Searching the algorithm **/
- int idAlgo = searchAlgo( _spawnerIp ) ;
- if( idAlgo == -1 )
+ if( dead != null )
{
- System.err.println( "No algorithm found for this Spawner!" ) ;
- return null ;
- }
-
- ArrayList<GNode> temp = algos.get( idAlgo ).getMapping().getMappedGNodes() ;
-
- for( int i = 0 ; i < temp.size() ; i++ )
- {
- if( ((Node)temp.get(i).getNode()).getId() == _n.getId() )
+ for( int i = 0 ; i < algos.size() ; i++ )
{
- removedGNode = temp.get( i ) ;
- Register.Instance().removeNodeOfName( removedGNode.getName() ) ;
- break ;
+ algos.get( i ).getGrid().removeGNode( dead ) ;
+ Register.Instance().removeNodeOfName( dead.getName() ) ;
+ SuperNodeListe.Instance().removeGNode( dead, _mode, _spawnerIp ) ;
}
- }
- }
-
- /** Removing the dead node from the Grid **/
- if( _mode == 0 || _mode == 1 ) {
- int idAlgo = searchAlgo( _spawnerIp ) ;
-
- if( idAlgo != -1 && _mode == 1 )
- {
- algos.get( idAlgo ).getGrid().removeGNode( removedGNode ) ;
+ } else {
+ System.err.println( "The dead node signaled does not exist!" ) ;
}
}
- /** Propagation of the deletion **/
- SuperNodeListe.Instance().removeGNode( removedGNode, _mode, _spawnerIp ) ;
-
if( free )
{
operating = false ;
*
* @author Sébastien Miquée
*/
- private void workingOnGnodes()
+ private synchronized void workingOnGnodes()
{
boolean tmp = true ;
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 _rank The task number number of the dead node
+ *
+ * @author Sébastien Miquée
+ */
+ @Override
+ public synchronized Node getNewNode( String _spawnerIP, int _rank ) throws RemoteException
+ {
+ int idNode = -1 ;
+ int idAlgo = searchAlgo( _spawnerIP ) ;
+
+ if( idAlgo == -1 )
+ {
+ System.err.println( "No algorithm found for this Spawner!" ) ;
+ return null ;
+ }
+
+ /** We have to replace a Spawner **/
+ if( _rank == -2 )
+ {
+ idNode = -2 ;
+ } else {
+ /** We have to replace a computing node **/
+ idNode = algos.get( idAlgo ).getMapping().getIdOfAssociation( _rank ) ;
+ }
+
+ if( idNode == -1 )
+ {
+ System.err.println( "No tasks corresponds to rank "+_rank+"!" ) ;
+ return null ;
+ }
+
+ GNode dead = null ;
+
+ if( idNode >= 0 )
+ {
+ dead = algos.get( idAlgo ).getMapping().getAssociation( idNode ).getGNode() ;
+ }
+
+ if( dead == null && idNode >= 0 )
+ {
+ System.err.println( "The GNode corresponding to the task "+_rank+" is null!" ) ;
+ System.err.println( "Trying to find a new node for this task (not optimal)..." ) ;
+ }
+
+ return getNewNode( _spawnerIP, dead ) ;
+ }
/**
* Search and return a new node when one failed or when JaceP2P needs another
* @author Sébastien Miquée
*/
@Override
- public Node getNewNode( String _spawnerIP, Node _deadNode ) throws RemoteException
+ public synchronized Node getNewNode( String _spawnerIP, GNode _deadNode ) throws RemoteException
{
Node node = null ;
- GNode remp = null, gnode = null ;
+ GNode remp = null ;
int idAlgo = searchAlgo( _spawnerIP ) ;
return null ;
}
+
/** Can we use gnodes ?**/
workingOnGnodes() ;
- if( _deadNode != null )
+ if( _deadNode != null )
{
authorized = true ;
- gnode = delGNodeFromList( _deadNode, 1, _spawnerIP ) ;
+ removeMappedGNode( _deadNode, 1 ) ;
+
+ authorized = false ;
- remp = algos.get( idAlgo ).replaceNode( gnode, gnodes ) ;
+ remp = algos.get( idAlgo ).replaceNode( _deadNode, gnodes ) ;
if( remp != null )
{
System.out.println( "Replacing node found." ) ;
+ authorized = true ;
+
remp.setMapped( true ) ;
- delGNodeFromList( (Node) remp.getNode(), 2, _spawnerIP ) ;
+ setMapped( remp, 1 ) ;
+ Register.Instance().removeNodeOfName( remp.getName() ) ;
+
+
+ /** Updating all mapping **/
+ updateMappedNode( _deadNode, remp, _spawnerIP ) ;
+ propagateReplaceNode( _deadNode, remp, _spawnerIP ) ;
authorized = false ;
authorized = true ;
- delGNodeFromList( (Node) remp.getNode(), 2, _spawnerIP ) ;
+ setMapped( remp, 1 ) ;
+ Register.Instance().removeNodeOfName( remp.getName() ) ;
authorized = false ;
if( remp != null )
{
node = (Node) remp.getNode() ;
+ } else {
+ System.err.println( "SuperNode: No new node found!" ) ;
}
- /** Updating all mapping **/
- updateMappedNode( gnode, remp, _spawnerIP ) ;
- propagateReplaceNode( gnode, remp, _spawnerIP ) ;
-
-
/** Free the gnodes use **/
operating = false ;
}
+ public synchronized void removeMappedGNode( GNode _g, int _mode ) throws RemoteException
+ {
+ if( _g != null )
+ {
+ for( int i = 0 ; i < algos.size() ; i++ )
+ {
+ algos.get( i ).getGrid().removeGNode( _g ) ;
+ }
+
+ if( _mode == 1 )
+ {
+ SuperNodeListe.Instance().removeGNode( _g, 0 ) ;
+ }
+ } else {
+ System.err.println( "GNode to be deleted is null!" ) ;
+ }
+ }
+
/**
* Replace a failed GNode in the mapping by another one.
* This method is called by the SuperNodeList, to broadcast the modification.
* @author Sébastien Miquée
*/
@Override
- public void updateMappedNode( GNode _dead, GNode _remp, String _spawnerIP )
+ public synchronized void updateMappedNode( GNode _dead, GNode _remp, String _spawnerIP )
{
if( _remp != null )
{
if( pos != -1 )
{
/** Changing the node in the mapping **/
- algos.get( idAlgo ).getMapping().getMapping().get( pos ).setGNode( _remp ) ;
-
- System.out.println( "Succesfully replacing the fallen node in the mapping." ) ;
- }
+ if( algos.get( idAlgo ).getMapping().getMapping().get( pos ).setGNode( _remp ) )
+ {
+ System.out.println( "Succesfully replacing the fallen node in the mapping." ) ;
+ } else {
+ System.err.println( "Failed in replacing the fallen node in the mapping!" ) ;
+ }
+ } else {
+ System.err.println( "The dead node was not found in the mapping!" ) ;
+ }
- /** Changing the status in the grid **/
- algos.get( idAlgo ).getGrid().setMappedStatus( _remp, true ) ;
-
- algos.get( idAlgo ).updateGrid() ;
} else {
System.err.println( "The new GNode is null!" ) ;
- }
+ }
}
*
* @author Sébastien Miquée
*/
- private void propagateReplaceNode( GNode _dead, GNode _remp, String _spawnerIP ) throws RemoteException
+ private synchronized void propagateReplaceNode( GNode _dead, GNode _remp, String _spawnerIP ) throws RemoteException
{
if( _remp != null )
{
SuperNodeListe.Instance().propagateReplaceNode( _dead, _remp, _spawnerIP ) ;
+ } else {
+ System.err.println( "The replacement node is null!" ) ;
}
}
gnodes.add( _g ) ;
+ updateGrids( _g ) ;
+
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
+ public synchronized void setMapping( Algo _al ) throws RemoteException
{
if( searchAlgo( _al.getIdS() ) == -1 )
- algos.add( _al ) ;
+ {
+ algos.add( _al ) ;
+ } else {
+ System.err.println( "I already have this mapping algorithm!" ) ;
+ }
}
*/
public void removeAlgo( String _id, int _mode ) throws RemoteException
{
- int i ;
+ int pos ;
- i = searchAlgo( _id ) ;
+ pos = searchAlgo( _id ) ;
- if( i != -1 )
+ if( pos != -1 )
{
- algos.remove( i ) ;
+ algos.remove( pos ) ;
if( _mode == 0 )
{
SuperNodeListe.Instance().removeAlgo( _id ) ;
}
+ } else {
+ System.err.println( "The mapping algorithm requested for deletion does not exist!" ) ;
}
}
+
+ // ** Tests ** //
+ public Algo getAlgo( String _spID ) throws RemoteException
+ {
+ int pos ;
+ Algo ret = null ;
+
+ pos = searchAlgo( _spID ) ;
+
+ if( pos != -1 )
+ {
+ ret = algos.get( pos ) ;
+ }
+
+ return ret ;
+ }
+
+
}
/** ! **/