4 import java.io.Serializable;
5 import java.util.ArrayList;
9 * Class representing a computing nodes cluster
10 * @author Sébastien Miquée
13 public class Cluster implements Serializable
15 private static final long serialVersionUID = 1L;
17 // private int nb_node ;
19 private ArrayList<GNode> nodes ;
20 private ArrayList<GNode> freenodes ;
22 // private int indice ;
26 * Default constructor.
32 nodes = new ArrayList<GNode>() ;
33 freenodes = new ArrayList<GNode>() ;
41 // * @param _nb The amount of computing nodes in the cluster
43 // public Cluster( int _nb )
47 // nodes = new ArrayList<GNode>() ;
48 // freenodes = new ArrayList<GNode>() ;
53 // for( int i = 0 ; i < nb_node ; i++ )
55 // nodes.add( new GNode() ) ;
62 // * @param _nb The amount of computing nodes in the cluster
63 // * @param _name Cluster's name
65 // public Cluster( int _nb, String _name )
69 // nodes = new ArrayList<GNode>() ;
73 // for( int i = 0 ; i < nb_node ; i++ )
75 // nodes.add( new GNode() ) ;
81 * Set the name of the cluster.
82 * @param _name Cluster's name
84 public void setName( String _name )
91 * Adding a computing node to the cluster.
92 * @param _n Node to be add
94 public void addGNode( GNode _n )
98 _n.setInCluster( true ) ;
103 if( ! _n.getMapped() )
105 freenodes.add( _n ) ;
112 * Return the list of computing nodes which are in the cluster.
113 * @return The list of nodes
115 public ArrayList<GNode> getGNodes()
122 * Return cluster's name.
123 * @return Cluster's name
125 public String getName()
132 * Return the amount of computing nodes in the cluster.
133 * @return The amount of nodes
135 public int getNbGNode()
138 return nodes.size() ;
143 * Set the site in which the cluster is.
144 * @param _site Site's name
146 public void setSite( String _site )
153 * Return the site's name in which the cluster is.
154 * @return The site's name
156 public String getSite()
163 * Test if a computing node is in the cluster.
164 * @param _g The node to be tested
165 * @return The position of the node
167 public int isIn( GNode _g )
173 for( int i = 0 ; i < nodes.size() ; i ++ )
175 if( nodes.get( i ).getId() == _g.getId() )
188 // * Initialization of indice variable.
190 // public void initIndice()
197 * Return the next computing node in the cluster,
198 * according to the indice variable.
199 * @return The next node in the cluster
201 public GNode nextGNode()
205 // if( indice < nb_node )
207 // ret = nodes.get( indice ) ;
210 if( freenodes.size() > 0 )
212 ret = freenodes.get( 0 ) ;
220 * Remove a failed node from the cluster.
221 * @param _dead The failed node
223 public void removeGNode( GNode _dead )
225 if( _dead != null && _dead.getCluster().equals( name ) && _dead.getSite().equals( site ) )
227 for( int i = 0 ; i < nodes.size() ; i++ )
229 if( _dead.getId() == nodes.get( i ).getId() )
231 freenodes.remove( nodes.remove( i ) ) ;
242 * Set the mapped status of a node of the cluster.
243 * @param _g The mapped node
244 * @param _status The status of the node
246 public void setGNodeStatus( GNode _g, boolean _status )
250 for( int i = 0 ; i < nodes.size() ; i++ )
252 if( nodes.get( i ).getId() == _g.getId() )
254 nodes.get( i ).setMapped( _status ) ;
258 freenodes.remove( nodes.get(i) ) ;
260 if( ! freenodes.contains( nodes.get( i ) ) )
261 freenodes.add( nodes.get( i ) ) ;
270 * Return the amount of available free nodes in the cluster.
271 * @return The amount of free nodes
273 public int getNbFreeNodes()
275 return freenodes.size() ;
280 * Compute and return the real available computing power of the cluster,
281 * including the heterogeneity degree of the platform.
282 * @param _het The heterogeneity degree of the platform
283 * @return The real available computing power
285 public double getAvailablePower( double _het )
289 /** If there is some available nodes **/
290 if( freenodes.size() > 0 )
293 double totalPower = 0 ;
298 for( int i = 0 ; i < freenodes.size() ; i++ )
300 totalPower += freenodes.get( i ).getPower() ;
303 ret = Math.pow( ( totalPower / freenodes.size() ), ( 2 * het) ) *
304 ( freenodes.size() / ( het * het) ) ;
312 * Initialization of computing nodes in this cluster. Set all
313 * of these nodes to be not mapped on.
315 public void initGNodes()
317 /** Initialization of local nodes **/
318 /** and reconstruction of the freenodes list **/
320 freenodes = new ArrayList<GNode>() ;
322 for( int i = 0 ; i < nodes.size() ; i++ )
324 nodes.get( i ).setMapped( false ) ;
326 freenodes.add( nodes.get( i ) ) ;
332 /** La programmation est un art, respectons ceux qui la pratiquent !! **/