From b5a7cb08ee803935699d211fd2abb0afddcbc98a Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=A9bastien=20Miqu=C3=A9e?= Date: Fri, 26 Feb 2010 08:13:27 +0100 Subject: [PATCH] Implementation of multiple mapping algorithm possibility. - Adding a list of mapping algorithm and the complete management of it. - Adding a field and some functions in the Spawner in order to communicate its mapping identifier to SuperNodes and other Spawners. - Correction of some bugs and managing some comments. --- src/jaceP2P/JaceSpawner.java | 43 +++++- src/jaceP2P/JaceSpawnerInterface.java | 2 + src/jaceP2P/JaceSpawnerServer.java | 6 +- src/jaceP2P/JaceSuperNode.java | 2 +- src/jaceP2P/JaceSuperNodeInterface.java | 6 +- src/jaceP2P/JaceSuperNodeServer.java | 170 ++++++++++++++++++------ src/jaceP2P/SuperNodeListe.java | 36 ++++- 7 files changed, 212 insertions(+), 53 deletions(-) diff --git a/src/jaceP2P/JaceSpawner.java b/src/jaceP2P/JaceSpawner.java index a6b1244..85014e0 100644 --- a/src/jaceP2P/JaceSpawner.java +++ b/src/jaceP2P/JaceSpawner.java @@ -1,6 +1,7 @@ package jaceP2P; import java.rmi.Naming; +import java.rmi.RemoteException; import java.util.Calendar; import java.util.GregorianCalendar; import java.util.Vector; @@ -38,6 +39,7 @@ public class JaceSpawner { // Variables for Mapping private int algo; private double paramAlgo ; + private String idAlgo ; public JaceSpawner(String superNode, int port, String comProtocol, String[] args, int nbDaemonPerSpawner, int nbDaemonPerThread, @@ -262,7 +264,7 @@ public class JaceSpawner { } // /System.out.println("is running = false"); if (!JaceDaemon.Instance().isRunning()) - System.exit(0); + System.exit( 1 ) ; } public synchronized void signalDeadNode(JaceInterface host, int rankOfDead) { @@ -641,6 +643,7 @@ public class JaceSpawner { ListeTask t = Register.Instance().getListeOfTasks(); ScanThreadSpawner.Instance().kill(); HeartBeatSpawner.Instance().kill(); + for (int i = 0; i < s + 1; i++) { new KillThread(i, debut, nbOfDaemonsPerSpawner, @@ -657,6 +660,7 @@ public class JaceSpawner { int nbsdc = RunningApplication.Instance() .getNumberOfSpawnerDisconnections(); + System.out.println("Application finished successfully !"); // System.out.println("Application finished successfully !!!!!!"); // System.out.println("Application finished successfully !!!!!!"); @@ -679,10 +683,12 @@ public class JaceSpawner { RunningApplication.Instance().purge(); // System.exit(1); } + + /** Suprresion of the mapping algorithm on the SuperNode **/ + centralServer.removeAlgo( idAlgo, 0 ) ; } - } catch (Exception e) { - System.out - .println("w aiiiiiiiiiiiiiirrrr" + e + " index=" + index); + } catch( Exception e ) { + System.err.println( "Error the application nodes scan!\n " + e ) ; z = index; } /* @@ -831,7 +837,7 @@ public class JaceSpawner { .println("JaceP2P_Error in JaceSpawner.exportObject() when creating the local JaceSpawnerServer " + e); // System.err.println("exit ds JaceSpawner.exportObject"); - System.exit(0); + System.exit( 1 ) ; } } @@ -938,6 +944,9 @@ public class JaceSpawner { connectSuperNode(); } } + + idAlgo = LocalHost.Instance().getIP() ; + if (registerSpawner.getSize() != (nbTasks + nbExtraSpawners)) { System.err.println("I did not recieve enough nodes from superNode!!!! \n killing application !!!!"); for (int i = 0; i < registerSpawner.getSize(); i++) { @@ -947,7 +956,7 @@ public class JaceSpawner { System.err.println("The reserved node was unable to reconnect to the super node"); } } - System.exit(0); + System.exit( 1 ) ; } spawnersList = new Vector(); @@ -988,6 +997,18 @@ public class JaceSpawner { System.exit(0); } } + + + /** + * Set the identifier of the mapping algorithm used. + * @param _s The mapping identifier + * + * @author Sébastien Miquée + */ + public void setIdAlgo( String _s ) throws RemoteException + { + idAlgo = _s ; + } public class TransformThread extends Thread { int i; @@ -1083,11 +1104,21 @@ public class JaceSpawner { System.out.println("waiting till transform of spawner " + j + " is finished"); while ((spawnersList.elementAt(j) instanceof Node)) + { try { Thread.sleep(20); } catch (Exception e) { } + } + + try { + ((JaceSpawnerInterface)spawnersList.elementAt( i )).setIdAlgo( idAlgo ) ; + } catch (RemoteException e) { + System.err.println( "Unable to set Mapping Algorithm identifier" ) ; + e.printStackTrace(); + } + } System.out.println("End Transformation of all spawners. Beginning the computing processes"); diff --git a/src/jaceP2P/JaceSpawnerInterface.java b/src/jaceP2P/JaceSpawnerInterface.java index 7d42998..0a769bf 100644 --- a/src/jaceP2P/JaceSpawnerInterface.java +++ b/src/jaceP2P/JaceSpawnerInterface.java @@ -38,4 +38,6 @@ public interface JaceSpawnerInterface extends Remote { public Register getRegister(int rank) throws RemoteException; public boolean ping() throws RemoteException; + + public void setIdAlgo( String _s ) throws RemoteException ; } diff --git a/src/jaceP2P/JaceSpawnerServer.java b/src/jaceP2P/JaceSpawnerServer.java index 9528cf0..d04069b 100644 --- a/src/jaceP2P/JaceSpawnerServer.java +++ b/src/jaceP2P/JaceSpawnerServer.java @@ -23,7 +23,6 @@ public class JaceSpawnerServer extends UnicastRemoteObject implements @SuppressWarnings("unchecked") public void startProcess(Vector spawnersList) throws RemoteException { JaceSpawner.Instance().startProcess(spawnersList); - } public Register getRegister(int rank) throws RemoteException { @@ -144,4 +143,9 @@ public class JaceSpawnerServer extends UnicastRemoteObject implements // Register.Instance().getListeOfTasks().viewAll(); } + @Override + public void setIdAlgo( String _s ) throws RemoteException + { + JaceSpawner.Instance().setIdAlgo( _s ) ; + } } diff --git a/src/jaceP2P/JaceSuperNode.java b/src/jaceP2P/JaceSuperNode.java index 4dcd3e9..09b25b3 100644 --- a/src/jaceP2P/JaceSuperNode.java +++ b/src/jaceP2P/JaceSuperNode.java @@ -152,7 +152,7 @@ public class JaceSuperNode { SuperNodeListe.Instance().forwardCountNode(); try { - snodeServer.delGNodeFromList( host, 0 ) ; + snodeServer.delGNodeFromList( host, 0, "" ) ; } catch (RemoteException e) { System.err.println( "Unable to remove the dead node from the list !" ) ; e.printStackTrace(); diff --git a/src/jaceP2P/JaceSuperNodeInterface.java b/src/jaceP2P/JaceSuperNodeInterface.java index c5f2e3a..e54e9b3 100644 --- a/src/jaceP2P/JaceSuperNodeInterface.java +++ b/src/jaceP2P/JaceSuperNodeInterface.java @@ -51,15 +51,17 @@ public interface JaceSuperNodeInterface extends Remote { // public void removeGNode( GNode _g ) throws RemoteException ; - public GNode delGNodeFromList( Node _n, int _mode ) throws RemoteException ; + public GNode delGNodeFromList( Node _n, int _mode, String _spawnerIp ) throws RemoteException ; public boolean blockForMapping() throws RemoteException ; public void setMapping( Algo al ) throws RemoteException ; - public void updateMappedNode(GNode dead, GNode remp) throws RemoteException ; + public void updateMappedNode(GNode dead, GNode remp, String _spawnerIP) throws RemoteException ; public ArrayList getGNodes() throws RemoteException ; + + public void removeAlgo( String _id, int _mode ) throws RemoteException ; } /** ! **/ diff --git a/src/jaceP2P/JaceSuperNodeServer.java b/src/jaceP2P/JaceSuperNodeServer.java index d2f5786..5f74bbb 100644 --- a/src/jaceP2P/JaceSuperNodeServer.java +++ b/src/jaceP2P/JaceSuperNodeServer.java @@ -24,7 +24,7 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements // Attributes private int beat; private ArrayList gnodes = null; - private Algo al = null ; + private ArrayList algos = null ; private int count = 0 ; private boolean inDemand = false, operating = false, authorized = false ; // private boolean daemonListChange ; @@ -35,6 +35,7 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements super() ; beat = timeBeat ; gnodes = new ArrayList() ; + algos = new ArrayList() ; // daemonListChange = true ; } @@ -220,14 +221,14 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements 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 ; } @@ -241,29 +242,33 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements 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 ts = new ArrayList(); - 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++) @@ -285,9 +290,9 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements // } 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; @@ -301,7 +306,8 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements al = new DefaultMapping( graph, grid, gnodes ) ; } - if (al != null) { + if (al != null) + { /** Launching the Mapping **/ al.map(); @@ -313,7 +319,7 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements 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()); } @@ -329,7 +335,7 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements { sup = al.getOtherGNode( gnodes ) ; reg.addNodeBeg( (Node) sup.getNode() ) ; - delGNodeFromList( (Node) sup.getNode(), 2 ) ; + delGNodeFromList( (Node) sup.getNode(), 2, spawnerIP ) ; } } @@ -338,6 +344,12 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements if (ag.size() != 0) { SuperNodeListe.Instance().forwardCountNode(); } + + /** Setting the algorithm's identifier **/ + al.setIdS( spawnerIP ) ; + + /** Adding the algorithm in the list **/ + algos.add( al ) ; } @@ -364,7 +376,7 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements * @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 ; @@ -395,7 +407,16 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements /** The dead node is in the mapping **/ if( _mode == 1 ) { - ArrayList 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 temp = algos.get( idAlgo ).getMapping().getMappedGNodes() ; for( int i = 0 ; i < temp.size() ; i++ ) { @@ -410,11 +431,16 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements /** 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 ) { @@ -427,6 +453,27 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements } + /** + * 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 @@ -479,6 +526,14 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements { 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() ; @@ -487,9 +542,9 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements { 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 ) { @@ -497,7 +552,7 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements remp.setMapped( true ) ; - delGNodeFromList( (Node) remp.getNode(), 2 ) ; + delGNodeFromList( (Node) remp.getNode(), 2, _spawnerIP ) ; authorized = false ; @@ -506,7 +561,7 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements System.err.println( "Replacing node not found !!" ) ; } } else { - remp = al.getOtherGNode( gnodes ) ; + remp = algos.get( idAlgo ).getOtherGNode( gnodes ) ; if( remp != null ) { @@ -516,7 +571,7 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements authorized = true ; - delGNodeFromList( (Node) remp.getNode(), 2 ) ; + delGNodeFromList( (Node) remp.getNode(), 2, _spawnerIP ) ; authorized = false ; @@ -526,10 +581,15 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements } } + 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 **/ @@ -548,26 +608,34 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements * @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!" ) ; } @@ -581,11 +649,11 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements * * @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 ) ; } } @@ -659,7 +727,8 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements @Override public void setMapping( Algo _al ) throws RemoteException { - al = _al ; + if( searchAlgo( _al.getIdS() ) == -1 ) + algos.add( _al ) ; } @@ -702,6 +771,31 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements 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 ) ; + } + } + } + } /** ! **/ diff --git a/src/jaceP2P/SuperNodeListe.java b/src/jaceP2P/SuperNodeListe.java index 017128a..b207bba 100644 --- a/src/jaceP2P/SuperNodeListe.java +++ b/src/jaceP2P/SuperNodeListe.java @@ -368,8 +368,8 @@ public class SuperNodeListe implements Cloneable { } } } - - public void removeGNode( GNode _g, int _mode ) + + public void removeGNode( GNode _g, int _mode, String _spawnerIP ) { if( _g != null ) { @@ -385,7 +385,7 @@ public class SuperNodeListe implements Cloneable { // if not me, I inform the other super nodes remoteStub = d.getStub() ; try { - remoteStub.delGNodeFromList( (Node)_g.getNode(), _mode ) ; + remoteStub.delGNodeFromList( (Node)_g.getNode(), _mode, _spawnerIP ) ; } catch( Exception e ) { System.err.println( "Unable to remove GNode on SuperNode " + d.getIP() ) ; } @@ -444,7 +444,7 @@ public class SuperNodeListe implements Cloneable { } } - public void propagateReplaceNode( GNode _dead, GNode _remp ) + public void propagateReplaceNode( GNode _dead, GNode _remp, String _spawnerIP ) { if( _dead != null && _remp != null ) { @@ -459,7 +459,7 @@ public class SuperNodeListe implements Cloneable { // if not me, I inform the other super nodes remoteStub = d.getStub() ; try { - remoteStub.updateMappedNode( _dead, _remp ) ; + remoteStub.updateMappedNode( _dead, _remp, _spawnerIP ) ; } catch( Exception e ) { System.err.println( "Unable to propagate replacing node on SuperNode " + d.getIP() ) ; } @@ -468,4 +468,30 @@ public class SuperNodeListe implements Cloneable { } } + + /** + * Send to all SuperNode the deletion of a mapping algorithm. + * @param id The mapping algorithm's identifier + */ + public void removeAlgo( String _id ) + { + SuperNodeData d = null ; + JaceSuperNodeInterface remoteStub = null ; + + for( int i = 0 ; i < liste.size() ; i++ ) + { + d = (SuperNodeData) liste.elementAt( i ) ; + if( ! d.getIP().equals( LocalHost.Instance().getIP() ) ) + { + // if not me, I inform the other super nodes + remoteStub = d.getStub() ; + try { + remoteStub.removeAlgo( _id, 1 ) ; + } catch( Exception e ) { + System.err.println( "Unable to propagate the mapping algorithm deletion " + d.getIP() ) ; + } + } + } + } + } -- 2.20.1