// Attributes
private int beat;
private ArrayList<GNode> gnodes = null;
- private Algo al = null ;
+ private ArrayList<Algo> algos = null ;
private int count = 0 ;
private boolean inDemand = false, operating = false, authorized = false ;
// private boolean daemonListChange ;
super() ;
beat = timeBeat ;
gnodes = new ArrayList<GNode>() ;
+ algos = new ArrayList<Algo>() ;
// daemonListChange = true ;
}
int nbNoeuds, int algo, double paramAlgo) throws RemoteException {
// Have we the correct application ?
- if (t == null) {
- System.err.println( "Problem of class transmission !" ) ;
+ if( t == null ) {
+ System.err.println( "Problem of class transmission!" ) ;
return null ;
}
if( t.getDependencies( 0 ) == null )
{
- System.err.println( "No redifinition of getDependencies() functions !" ) ;
+ System.err.println( "No redifinition of getDependencies() function!" ) ;
return null ;
}
Grid grid = Utils.createGridG5k(gnodes);
// grid.initClusters();
+
+ /** Informing about the grid heterogeneity **/
+ System.out.println( "\nHeterogeneity of the grid : " + grid.getHeterogenityDegre() + "\n" ) ;
+
/** Creation of tasks GTask **/
ArrayList<GTask> ts = new ArrayList<GTask>();
- for (int i = 0; i < nbTasks; i++) {
- ts.add(new GTask( i ) ) ;
+ for( int i = 0; i < nbTasks; i++ ) {
+ ts.add( new GTask( i ) ) ;
}
/** Research of dependencies **/
- for (int i = 0; i < nbTasks; i++) {
- int dep[] = null;
- dep = t.getDependencies(i);
+ for( int i = 0; i < nbTasks; i++ ) {
+ int dep[] = null ;
+ dep = t.getDependencies( i ) ;
/** Adding dependencies to tasks **/
- for (int j = 0; j < dep.length; j++) {
- if (dep[j] != -1) {
- ts.get(i).addDependance(ts.get(dep[j]));
+ for( int j = 0; j < dep.length; j++ ) {
+ if( dep[j] != -1 ) {
+ ts.get( i ).addDependance( ts.get( dep[ j ] ) ) ;
} else {
- break;
+ break ;
}
}
}
-
+ /** Creation of the application interaction graph **/
Graph graph = new Graph();
for( int i = 0 ; i < ts.size() ; i++)
// } catch( Exception e ) {}
/** Selection of the mapping algorithm **/
- al = null ;
+ Algo al = null ;
- switch (algo) {
+ switch( algo ) {
case 0:
al = new Simple(graph, grid);
break;
al = new DefaultMapping( graph, grid, gnodes ) ;
}
- if (al != null) {
+ if (al != null)
+ {
/** Launching the Mapping **/
al.map();
for( int i = 0; i < ag.size(); i++ ) {
reg.addNode((Node) ag.get(i).getNode());
- delGNodeFromList( (Node) ag.get(i).getNode(), 2 ) ;
+ delGNodeFromList( (Node) ag.get(i).getNode(), 2, spawnerIP ) ;
// gnodes.remove(ag.get(i));
// Register.Instance().removeNode((Node) ag.get(i).getNode());
}
{
sup = al.getOtherGNode( gnodes ) ;
reg.addNodeBeg( (Node) sup.getNode() ) ;
- delGNodeFromList( (Node) sup.getNode(), 2 ) ;
+ delGNodeFromList( (Node) sup.getNode(), 2, spawnerIP ) ;
}
}
if (ag.size() != 0) {
SuperNodeListe.Instance().forwardCountNode();
}
+
+ /** Setting the algorithm's identifier **/
+ al.setIdS( spawnerIP ) ;
+
+ /** Adding the algorithm in the list **/
+ algos.add( al ) ;
}
* @author Sébastien Miquée
*/
@Override
- public GNode delGNodeFromList( Node _n, int _mode ) throws RemoteException
+ public GNode delGNodeFromList( Node _n, int _mode, String _spawnerIp ) throws RemoteException
{
GNode removedGNode = null ;
/** The dead node is in the mapping **/
if( _mode == 1 )
{
- ArrayList<GNode> temp = al.getMapping().getMappedGNodes() ;
+ /** Searching the algorithm **/
+ int idAlgo = searchAlgo( _spawnerIp ) ;
+
+ if( idAlgo == -1 )
+ {
+ 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++ )
{
/** Removing the dead node from the Grid **/
if( _mode == 0 || _mode == 1 ) {
- al.getGrid().removeGNode( removedGNode ) ;
+ int idAlgo = searchAlgo( _spawnerIp ) ;
+
+ if( idAlgo != -1 && _mode == 1 )
+ {
+ algos.get( idAlgo ).getGrid().removeGNode( removedGNode ) ;
+ }
}
/** Propagation of the deletion **/
- SuperNodeListe.Instance().removeGNode( removedGNode, _mode ) ;
+ SuperNodeListe.Instance().removeGNode( removedGNode, _mode, _spawnerIp ) ;
if( free )
{
}
+ /**
+ * Search the position of the mapping algorithm in the list.
+ * @param _id Identifier of the algorithm
+ * @return The position in the list
+ */
+ private int searchAlgo( String _id )
+ {
+ int id = -1 ;
+
+ for( int i = 0 ; i < algos.size() ; i++ )
+ {
+ if( algos.get( i ).getIdS().equals( _id ) )
+ {
+ id = i ;
+ break ;
+ }
+ }
+
+ return id ;
+ }
+
/**
* Determine if this SuperNode can operate on the gnodes list.
* It asks other SuperNodes to know if their are working on this list
{
Node node = null ;
GNode remp = null, gnode = null ;
+
+ int idAlgo = searchAlgo( _spawnerIP ) ;
+
+ if( idAlgo == -1 )
+ {
+ System.err.println( "No algorithm found for this Spawner!" ) ;
+ return null ;
+ }
/** Can we use gnodes ?**/
workingOnGnodes() ;
{
authorized = true ;
- gnode = delGNodeFromList( _deadNode, 1 ) ;
+ gnode = delGNodeFromList( _deadNode, 1, _spawnerIP ) ;
- remp = al.replaceNode( gnode, gnodes ) ;
+ remp = algos.get( idAlgo ).replaceNode( gnode, gnodes ) ;
if( remp != null )
{
remp.setMapped( true ) ;
- delGNodeFromList( (Node) remp.getNode(), 2 ) ;
+ delGNodeFromList( (Node) remp.getNode(), 2, _spawnerIP ) ;
authorized = false ;
System.err.println( "Replacing node not found !!" ) ;
}
} else {
- remp = al.getOtherGNode( gnodes ) ;
+ remp = algos.get( idAlgo ).getOtherGNode( gnodes ) ;
if( remp != null )
{
authorized = true ;
- delGNodeFromList( (Node) remp.getNode(), 2 ) ;
+ delGNodeFromList( (Node) remp.getNode(), 2, _spawnerIP ) ;
authorized = false ;
}
}
+ if( remp != null )
+ {
+ node = (Node) remp.getNode() ;
+ }
+
/** Updating all mapping **/
- updateMappedNode( gnode, remp ) ;
- propagateReplaceNode( gnode, remp ) ;
+ updateMappedNode( gnode, remp, _spawnerIP ) ;
+ propagateReplaceNode( gnode, remp, _spawnerIP ) ;
/** Free the gnodes use **/
* @author Sébastien Miquée
*/
@Override
- public void updateMappedNode( GNode _dead, GNode _remp )
+ public void updateMappedNode( GNode _dead, GNode _remp, String _spawnerIP )
{
if( _remp != null )
{
int pos = 0 ;
+
+ int idAlgo = searchAlgo( _spawnerIP ) ;
+
+ if( idAlgo == -1 )
+ {
+ System.err.println( "No algorithm found for this Spawner!" ) ;
+ return ;
+ }
- pos = al.getMapping().getIdOfAssociation( _dead ) ;
+ pos = algos.get( idAlgo ).getMapping().getIdOfAssociation( _dead ) ;
if( pos != -1 )
{
/** Changing the node in the mapping **/
- al.getMapping().getMapping().get( pos ).setGNode( _remp ) ;
+ algos.get( idAlgo ).getMapping().getMapping().get( pos ).setGNode( _remp ) ;
System.out.println( "Succesfully replacing the fallen node in the mapping." ) ;
}
/** Changing the status in the grid **/
- al.getGrid().setMappedStatus( _remp, true ) ;
+ algos.get( idAlgo ).getGrid().setMappedStatus( _remp, true ) ;
- al.updateGrid() ;
+ 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 ) throws RemoteException
+ private void propagateReplaceNode( GNode _dead, GNode _remp, String _spawnerIP ) throws RemoteException
{
if( _remp != null )
{
- SuperNodeListe.Instance().propagateReplaceNode( _dead, _remp ) ;
+ SuperNodeListe.Instance().propagateReplaceNode( _dead, _remp, _spawnerIP ) ;
}
}
@Override
public void setMapping( Algo _al ) throws RemoteException
{
- al = _al ;
+ if( searchAlgo( _al.getIdS() ) == -1 )
+ algos.add( _al ) ;
}
return gnodes ;
}
+
+ /**
+ * Remove a mapping algorithm of the algorithms list.
+ * @param _id The algorithm identifier
+ * @param _mode Indicate if the information should be transmitted
+ *
+ * @author Sébastien Miquée
+ */
+ public void removeAlgo( String _id, int _mode ) throws RemoteException
+ {
+ int i ;
+
+ i = searchAlgo( _id ) ;
+
+ if( i != -1 )
+ {
+ algos.remove( i ) ;
+
+ if( _mode == 0 )
+ {
+ SuperNodeListe.Instance().removeAlgo( _id ) ;
+ }
+ }
+ }
+
}
/** ! **/