X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/mapping.git/blobdiff_plain/1943cd46cee3f63424e965e9e58f9779a5505cec..c5259b6a754655006e41cae8ff32292b7eee4913:/src/and/Mapping/Utils.java diff --git a/src/and/Mapping/Utils.java b/src/and/Mapping/Utils.java index 57a87e2..ff2393a 100644 --- a/src/and/Mapping/Utils.java +++ b/src/and/Mapping/Utils.java @@ -65,7 +65,7 @@ public class Utils InetAddress addr = InetAddress.getLocalHost() ; name = new String( addr.getCanonicalHostName() ) ; } catch( final Exception e ) { - System.err.println( "Unalbe to retrieve host name !" ) ; + System.err.println( "Unalbe to retrieve host's name !" ) ; e.printStackTrace(); System.exit( 1 ) ; } @@ -77,6 +77,7 @@ public class Utils n.setMemory( memory ) ; n.setNb_cores( nbCore ) ; n.setName( name ) ; + n.setMapped( false ) ; return n ; } @@ -94,36 +95,20 @@ public class Utils if( _an != null ) { - String temp ; - String nom, cluster, site ; - + String cluster = "", site = "" ; ArrayList clusters = new ArrayList() ; 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" ; - // G5K - cluster = tab[ 0 ] ; + String names[] = decodeG5Knames( _an.get( i ).getName() ) ; - //System.out.println( nom + " dans " + cluster + " du site " + site ) ; + cluster = names[ 1 ] ; + site = names[ 2 ] ; - - /* 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 +116,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 +134,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,15 +152,47 @@ 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 - * @param _file File's name * @param _path File's path + * @param _file File's name */ - public static void writeGrid( Grid _gl, String _file, String _path ) + public static void writeGrid( Grid _gl, String _path, String _file ) { - if ( ! _file.equals( "" ) && ! _file.endsWith( ".xml" ) ) + if( _file.equals( "" ) ) + { + System.err.println( "No file's name !\n" ) ; + return ; + } + + if ( ! _file.endsWith( ".xml" ) ) { _file = _file + ".xml"; // On ajoute l'extension xml au nom du fichier } @@ -212,12 +231,18 @@ public class Utils /** * Write an application Graph in a file. * @param _gr Application Graph to be write - * @param _file File's name * @param _path File's path + * @param _file File's name */ - public static void writeGraph( Graph _gr, String _file, String _path ) + public static void writeGraph( Graph _gr, String _path, String _file ) { - if ( ! _file.equals( "" ) && ! _file.endsWith( ".xml" ) ) + if( _file.equals( "" ) ) + { + System.err.println( "No file's name !\n" ) ; + return ; + } + + if ( ! _file.endsWith( ".xml" ) ) { _file = _file + ".xml"; // On ajoute l'extension xml au nom du fichier } @@ -257,28 +282,43 @@ public class Utils /** * Read an application Graph from a file. * @param _file File's name + * @param _path File's path * @return The application Graph read */ - public static Graph readGraph( String _file ) + public static Graph readGraph( String _path, String _file ) { - if ( _file.equals( "" ) || ! _file.endsWith( ".xml" ) ) + if ( _file.equals( "" ) ) { - System.err.println( "Bad file !\n" ) ; + System.err.println( "No file's name !\n" ) ; return null ; } + if ( ! _file.endsWith( ".xml" ) ) + { + _file = _file + ".xml"; // On ajoute l'extension xml au nom du fichier + } + + String path = "" ; + + if( _path.length() != 0 ) + { + path = _path+"/"+_file ; + } else { + path = new String( "./" + _file ) ; + } + Graph gr = null ; XStream xstream = new XStream( new DomDriver() ) ; try { - gr = (Graph) xstream.fromXML( new FileInputStream( _file ) ) ; + gr = (Graph) xstream.fromXML( new FileInputStream( path ) ) ; } catch( FileNotFoundException e ) { System.err.println( "File not found !\n" ) ; e.printStackTrace(); return null ; } catch( ClassCastException e ) { - System.err.println( "The file does not contain a Graph" ) ; + System.err.println( "The file does not contain a valid Graph" ) ; e.printStackTrace() ; return null ; } @@ -290,28 +330,43 @@ public class Utils /** * Read a Grid graph from a file. * @param _file File's name + * @param _path File's path * @return The Grid graph read */ - public static Grid readGrid( String _file ) - { - if ( _file.equals( "" ) || ! _file.endsWith( ".xml" ) ) + public static Grid readGrid( String _path, String _file ) + { + if ( _file.equals( "" ) ) { - System.err.println( "Bad file !\n" ) ; + System.err.println( "No file's name !\n" ) ; return null ; } + if ( ! _file.endsWith( ".xml" ) ) + { + _file = _file + ".xml"; // On ajoute l'extension xml au nom du fichier + } + + String path = "" ; + + if( _path.length() != 0 ) + { + path = _path+"/"+_file ; + } else { + path = new String( "./" + _file ) ; + } + Grid gr = null ; XStream xstream = new XStream( new DomDriver() ) ; try { - gr = (Grid) xstream.fromXML( new FileInputStream( _file ) ) ; + gr = (Grid) xstream.fromXML( new FileInputStream( path ) ) ; } catch( FileNotFoundException e ) { System.err.println( "File not found !\n" ) ; e.printStackTrace(); return null ; } catch( ClassCastException e ) { - System.err.println( "The file does not contain a Grid" ) ; + System.err.println( "The file does not contain a valid Grid" ) ; e.printStackTrace() ; return null ; }