Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add of grid modifications.
authorSébastien Miquée <sebastien.miquee@univ-fcomte.fr>
Fri, 19 Feb 2010 18:01:38 +0000 (19:01 +0100)
committerSébastien Miquée <sebastien.miquee@univ-fcomte.fr>
Fri, 19 Feb 2010 18:01:38 +0000 (19:01 +0100)
- Implementing the update of the grid architecture with new nodes.

- Allowing to remove nodes from the grid.

src/and/Mapping/Algo.java
src/and/Mapping/Cluster.java
src/and/Mapping/GNode.java
src/and/Mapping/Grid.java
src/and/Mapping/Utils.java

index 5761b67..e85d04f 100644 (file)
@@ -74,6 +74,26 @@ public abstract class Algo implements Serializable
        {
                return mp ;
        }       
+       
+       
+       /**
+        * Return the grid used in the algorithm.
+        * @return The Grid
+        */
+       public Grid getGrid()
+       {
+               return gl ;
+       }
+       
+       
+       /**
+        * Return the graph used in the algorithm.
+        * @return The Graph
+        */
+       public Graph getGraph()
+       {
+               return gr ;
+       }
 }
 
 /** La programmation est un art, respectons ceux qui la pratiquent !! **/
index 8d798f5..0561682 100644 (file)
@@ -156,9 +156,10 @@ public class Cluster implements Serializable
        {
                if( _g != null )
                {
-                       if( nodes.contains( _g ) )
+                       for( int i = 0; i < nodes.size(); i ++ )
                        {
-                               return true ;
+                               if( nodes.get( i ).getId() == _g.getId() )
+                                       return true ;
                        }
                }
                
index c8bdb0d..c1015db 100644 (file)
@@ -283,6 +283,16 @@ public class GNode implements Serializable
                return id ;
        }
        
+       
+       /**
+        * Return the name of the node for the use of the node in a string.
+        * @return The name of the node
+        */
+       public String toString()
+       {
+               return name ;
+       }
+       
 }
 
 /** La programmation est un art, respectons ceux qui la pratiquent !! **/
index 16e46b1..eb3fb4f 100644 (file)
@@ -196,8 +196,8 @@ public class Grid implements Serializable
        
        
        /**
-        * Plop !!
-        * @param _gnodes
+        * Upgrade the grid with new nodes.
+        * @param _gnodes The list of new nodes
         */
        public void updateGrid( ArrayList<GNode> _gnodes )
        {
@@ -205,7 +205,55 @@ public class Grid implements Serializable
                {
                        for( int i = 0 ; i < _gnodes.size() ; i++ )
                        {
+                               /** Searching the cluster in which the node should be added **/
+                               int j = 0 ;
+                               for( j = 0; j < clusters.size(); j++ )
+                               {
+                                       if( _gnodes.get( i ).getCluster().equalsIgnoreCase( clusters.get( j ).getName() ) )
+                                       {
+                                               if( ! clusters.get( j ).isIn( _gnodes.get( i ) ) )
+                                               {
+                                                       _gnodes.get( i ).setCluster( clusters.get( j ).getName() ) ;
+                                                       _gnodes.get( i ).setSite( clusters.get( j ).getSite() ) ;
+                                                       _gnodes.get( i ).setInCluster( true ) ;
+                                                       _gnodes.get( i ).setMapped( false ) ;
+                                               
+                                                       clusters.get( i ).addGNode( _gnodes.get( j ) ) ;
+                                                       nb_node++ ;
+                                                       gnodesList.add( _gnodes.get( i ) ) ;
+                                               }
+                                               
+                                               break ;
+                                       }
+                               }
                                
+                               /** The cluster was not found, so it is a new one **/
+                               if( j == clusters.size() )
+                               {
+                                       String site = "", cluster = "" ;
+                                       Cluster nClust = new Cluster() ;
+                                       
+                                       
+                                       String names[] = Utils.decodeG5Knames( _gnodes.get( i ).getName() ) ;
+                                       
+                                       cluster = names[ 1 ] ;
+                                       site = names[ 2 ] ;
+                                       
+                                       nClust.setName( cluster ) ;
+                                       nClust.setSite( site ) ;
+                                       
+                                       _gnodes.get( i ).setInCluster( true ) ;
+                                       _gnodes.get( i ).setMapped( false ) ;
+                                       _gnodes.get( i ).setSite( site ) ;
+                                       _gnodes.get( i ).setCluster( cluster ) ;
+                                       
+                                       nClust.addGNode( _gnodes.get( i ) ) ;
+                                       nb_cluster++ ;
+                                       
+                                       clusters.add( nClust ) ;
+                                       nb_node++ ;
+                                       gnodesList.add( _gnodes.get( i ) ) ;
+                               }
                        }
                        
                        gnodesList_done = false ;
@@ -228,7 +276,7 @@ public class Grid implements Serializable
                                site = _dead.getSite() ;
                                cluster = _dead.getCluster() ;
                        
-                               /* Removing GNode from its cluster */                   
+                               /** Removing GNode from its cluster **/                 
                                for( int j = 0 ; j < clusters.size() ; j++ )
                                {
                                        if( clusters.get( j ).getName().equals( cluster ) && clusters.get( j ).getSite().equals( site ))
@@ -240,7 +288,7 @@ public class Grid implements Serializable
                                }
                        }
                        
-                       /* Removing the dead node from the global list */
+                       /** Removing the dead node from the global list **/
                        for( int i = 0 ; i < nb_node ; i++ )
                        {
                                if( _dead.getId() == gnodesList.get( i ).getId() )
index 25cd4a7..7e05ca2 100644 (file)
@@ -94,36 +94,20 @@ public class Utils
                
                if( _an != null )
                {
-                       String temp ;
-                       String nom, cluster, site ;
-               
+                       String cluster = "", site = "" ;                
                        
                        ArrayList<Cluster> clusters = new ArrayList<Cluster>() ;
                        
                        for( int i = 0 ; i < _an.size() ; i++ )
                        {
                                /* Variables edition */
-                               String tab[] = new String[ 5 ] ;                                
-                               
-                               temp = _an.get( i ).getName().trim().replace('.', '!' ) ;
-                               
-                               tab = temp.split( "!" ) ;
-                               
-                               nom = tab[ 0 ] ;
-                               site = tab[ 1 ] ;
-                               
-                               tab = nom.split( "-" ) ;
                                
-                               // IUT
-                               //cluster = "iut" ;
+                               String names[] = decodeG5Knames( _an.get( i ).getName() ) ;
                                
-                               // G5K
-                               cluster = tab[ 0 ] ;
+                               cluster = names[ 1 ] ;
+                               site = names[ 2 ] ;
                                
-                               //System.out.println( nom + " dans " + cluster + " du site " + site ) ;
-                               
-                               
-                               /* Insertion du noeud dans son cluster */
+                               /* Insertion of the node in its cluster */
                                boolean trouve = false ;
                                
                                for( int j = 0 ; j < clusters.size() ; j++ )
@@ -131,6 +115,7 @@ public class Utils
                                        if( clusters.get( j ).getName().equals( cluster ) && clusters.get( j ).getSite().equals( site ))
                                        {
                                                _an.get( i ).setInCluster( true ) ;
+                                               _an.get( i ).setMapped( false ) ;
                                                _an.get( i ).setSite( clusters.get( j ).getSite() ) ;
                                                _an.get( i ).setCluster( clusters.get( j ).getName() ) ;
                                                clusters.get( j ).addGNode( _an.get( i ) ) ;
@@ -148,6 +133,7 @@ public class Utils
                                        cl.setSite( site ) ;
                                        
                                        _an.get( i ).setInCluster( true ) ;
+                                       _an.get( i ).setMapped( false ) ;
                                        _an.get( i ).setSite( site ) ;
                                        _an.get( i ).setCluster( cluster ) ;
                                        
@@ -165,6 +151,32 @@ public class Utils
        }
 
        
+       /**
+        * Return the three parts of the name of a node on Grid'5000.
+        * @param _name The full name of the G5K node
+        * @return The three parts of the name
+        */
+       protected static String[] decodeG5Knames( String _name ) 
+       {
+               String temp = "" ;
+               String tab[] = new String[ 5 ] ;        
+               String ret[] = new String[ 3 ] ;
+               
+               temp = _name.replace('.', '!' ) ;
+               
+               tab = temp.split( "!" ) ;
+               
+               ret[0] = tab[ 0 ] ;
+               ret[2] = tab[ 1 ] ;
+               
+               tab = ret[0].split( "-" ) ;
+               
+               ret[ 1 ] = tab[ 0 ] ;
+               
+               return ret ;
+       }
+
+       
        /**
         * Write the Grid object in an XML file.
         * @param _gl Grid graph to be write