A
lgorithmique
N
umérique
D
istribuée
Public GIT Repository
projects
/
mapping.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
| inline |
side by side
New version of MAHEVE plus corrections.
[mapping.git]
/
src
/
and
/
Mapping
/
Cluster.java
diff --git
a/src/and/Mapping/Cluster.java
b/src/and/Mapping/Cluster.java
index
39c48bd
..
69323eb
100644
(file)
--- a/
src/and/Mapping/Cluster.java
+++ b/
src/and/Mapping/Cluster.java
@@
-14,12
+14,11
@@
public class Cluster implements Serializable
{
private static final long serialVersionUID = 1L;
-// private int nb_node ;
private String name ;
private ArrayList<GNode> nodes ;
private ArrayList<GNode> freenodes ;
private String site ;
-
// private int indic
e ;
+
private int moreNod
e ;
/**
@@
-27,56
+26,14
@@
public class Cluster implements Serializable
*/
public Cluster()
{
-// nb_node = 0 ;
name = "" ;
nodes = new ArrayList<GNode>() ;
freenodes = new ArrayList<GNode>() ;
site = "" ;
-
// indic
e = 0 ;
+
moreNod
e = 0 ;
}
-// /**
-// * Constructor.
-// * @param _nb The amount of computing nodes in the cluster
-// */
-// public Cluster( int _nb )
-// {
-// nb_node = _nb ;
-// name = "" ;
-// nodes = new ArrayList<GNode>() ;
-// freenodes = new ArrayList<GNode>() ;
-// site = "" ;
-//// indice = 0 ;
-//
-//
-// for( int i = 0 ; i < nb_node ; i++ )
-// {
-// nodes.add( new GNode() ) ;
-// }
-// }
-
-
-// /**
-// * Constructor.
-// * @param _nb The amount of computing nodes in the cluster
-// * @param _name Cluster's name
-// */
-// public Cluster( int _nb, String _name )
-// {
-//// nb_node = _nb ;
-// name = _name ;
-// nodes = new ArrayList<GNode>() ;
-// site = "" ;
-//// indice = 0 ;
-//
-// for( int i = 0 ; i < nb_node ; i++ )
-// {
-// nodes.add( new GNode() ) ;
-// }
-// }
-
-
/**
* Set the name of the cluster.
* @param _name Cluster's name
@@
-93,13
+50,11
@@
public class Cluster implements Serializable
*/
public void addGNode( GNode _n )
{
- if( _n != null )
+ if( _n != null
&& _n.getClusterName().equalsIgnoreCase( name )
)
{
_n.setInCluster( true ) ;
nodes.add( _n ) ;
-// nb_node++ ;
-
if( ! _n.getMapped() )
{
freenodes.add( _n ) ;
@@
-118,6
+73,16
@@
public class Cluster implements Serializable
}
+ /**
+ * Return the list of free computing nodes which are in the cluster.
+ * @return The list of free nodes
+ */
+ public ArrayList<GNode> getFreeGNodes()
+ {
+ return freenodes ;
+ }
+
+
/**
* Return cluster's name.
* @return Cluster's name
@@
-134,7
+99,6
@@
public class Cluster implements Serializable
*/
public int getNbGNode()
{
-// return nb_node ;
return nodes.size() ;
}
@@
-160,7
+124,8
@@
public class Cluster implements Serializable
/**
- * Test if a computing node is in the cluster.
+ * Test if a computing node is in the cluster, and return its position (if
+ * it exists).
* @param _g The node to be tested
* @return The position of the node
*/
@@
-176,37
+141,44
@@
public class Cluster implements Serializable
{
pos = i ;
break ;
- }
-
+ }
}
}
return pos ;
}
-// /**
-// * Initialization of indice variable.
-// */
-// public void initIndice()
-// {
-// indice = 0 ;
-// }
-
-
+
+ /**
+ * Test if a computing node is in the cluster, and return it (if
+ * it exists).
+ * @param _g The node to be tested
+ * @return The position of the node
+ */
+ public GNode exists( GNode _g )
+ {
+ if( _g != null )
+ {
+ for( int i = 0 ; i < nodes.size() ; i ++ )
+ {
+ if( nodes.get( i ).getId() == _g.getId() )
+ {
+ return nodes.get( i ) ;
+ }
+ }
+ }
+
+ return null ;
+ }
+
/**
- * Return the next computing node in the cluster,
- * according to the indice variable.
+ * Return the next available computing node in the cluster.
* @return The next node in the cluster
*/
public GNode nextGNode()
{
GNode ret = null ;
-// if( indice < nb_node )
-// {
-// ret = nodes.get( indice ) ;
-// indice++ ;
-// }
if( freenodes.size() > 0 )
{
ret = freenodes.get( 0 ) ;
@@
-214,6
+186,39
@@
public class Cluster implements Serializable
return ret ;
}
+
+
+ /**
+ * Return the next available computing node in the cluster,
+ * according to the moreNode iterator.
+ * @return The next node in the cluster
+ */
+ public GNode moreGNode()
+ {
+ GNode ret = null ;
+
+ if( freenodes.size() > 0 )
+ {
+ if( moreNode >= freenodes.size() )
+ {
+ System.err.println( "No more free node available" );
+ } else {
+ ret = freenodes.get( moreNode ) ;
+ moreNode++ ;
+ }
+ }
+
+ return ret ;
+ }
+
+
+ /**
+ * (Re-)Initialize the moreNode counter.
+ */
+ public void initMoreGNode()
+ {
+ moreNode = 0 ;
+ }
/**
@@
-222,18
+227,41
@@
public class Cluster implements Serializable
*/
public void removeGNode( GNode _dead )
{
- if( _dead != null
&& _dead.getCluster().equals( name ) && _dead.getSite().equals( site )
)
+ if( _dead != null )
{
- for( int i = 0 ; i < nodes.size() ; i++ )
+ if( _dead.getClusterName().equalsIgnoreCase( name )
+ && _dead.getSiteName().equalsIgnoreCase( site ) )
{
- if( _dead.getId() == nodes.get( i ).getId() )
+ int i = 0 ;
+ for( i = 0 ; i < nodes.size() ; i++ )
{
- freenodes.remove( nodes.remove( i ) ) ;
-// nb_node-- ;
-
- break ;
+ if( _dead.getId() == nodes.get( i ).getId() )
+ {
+ nodes.remove( i ) ;
+
+ int j = 0 ;
+ for( j = 0 ; j < freenodes.size() ; j++ )
+ {
+ if( freenodes.get(j).getId() == _dead.getId() )
+ {
+ freenodes.remove( j ) ;
+ break ;
+ }
+ }
+
+ break ;
+ }
}
+
+ if( i > nodes.size() )
+ {
+ System.err.println( "(Cluster) The GNode was not found in the list!" );
+ }
+ } else {
+ System.err.println( "(Cluster) The GNode to be deleted is not mine!" ) ;
}
+ } else {
+ System.err.println( "(Cluster) The GNode to be deleted is null!" ) ;
}
}
@@
-255,7
+283,15
@@
public class Cluster implements Serializable
if( _status )
{
- freenodes.remove( nodes.get(i) ) ;
+ for( int j = 0 ; j < freenodes.size() ; j++ )
+ {
+ if( freenodes.get(j).getId() == nodes.get(i).getId() )
+ {
+ freenodes.remove( j ) ;
+ break ;
+ }
+ }
+
} else {
if( ! freenodes.contains( nodes.get( i ) ) )
freenodes.add( nodes.get( i ) ) ;
@@
-274,7
+310,86
@@
public class Cluster implements Serializable
{
return freenodes.size() ;
}
+
+
+ /**
+ * Compute and return the available computing power of the cluster.
+ * @return The available computing power
+ */
+ public double getAvailablePower()
+ {
+ double ret = 0 ;
+
+ /** If there is some available nodes **/
+ if( freenodes.size() > 0 )
+ {
+ for( int i = 0 ; i < freenodes.size() ; i++ )
+ {
+ ret += freenodes.get( i ).getPower() ;
+ }
+ }
+
+ return ret ;
+ }
+
+
+ /**
+ * Compute and return the average available computing power of the cluster.
+ * @return The available available computing power
+ */
+ public double getAvgAvailablePower()
+ {
+ double ret = 0 ;
+
+ /** If there is some available nodes **/
+ if( freenodes.size() > 0 )
+ {
+ for( int i = 0 ; i < freenodes.size() ; i++ )
+ {
+ ret += freenodes.get( i ).getPower() ;
+ }
+
+ ret = ret / freenodes.size() ;
+ }
+
+ return ret ;
+ }
+
+ public double getAvgPower()
+ {
+ double ret = 0 ;
+
+ /** If there is some available nodes **/
+ if( nodes.size() > 0 )
+ {
+ for( int i = 0 ; i < nodes.size() ; i++ )
+ {
+ ret += nodes.get( i ).getPower() ;
+ }
+
+ ret = ret / nodes.size() ;
+ }
+
+ return ret ;
+ }
+
+
+ public double getPower()
+ {
+ double ret = 0 ;
+
+ /** If there is some available nodes **/
+ if( nodes.size() > 0 )
+ {
+ for( int i = 0 ; i < nodes.size() ; i++ )
+ {
+ ret += nodes.get( i ).getPower() ;
+ }
+ }
+
+ return ret ;
+ }
/**
* Initialization of computing nodes in this cluster. Set all
@@
-295,6
+410,68
@@
public class Cluster implements Serializable
}
}
+
+ /**
+ * Replace a node in the cluster (in case of a reconnection for example).
+ * @param _g The node to be replaced
+ */
+ public void replaceGNode( GNode _g )
+ {
+ if( _g != null )
+ {
+ removeGNode( _g ) ;
+ addGNode( _g ) ;
+ }
+ }
+
+
+ /**
+ * Search and return the better (most powerful) available node
+ * of the cluster.
+ * @return The best available node
+ */
+ public GNode getBetterFreeGNode()
+ {
+ GNode ret = null ;
+
+ if( freenodes.size() > 0 )
+ {
+ ret = freenodes.get( 0 ) ;
+ }
+
+ for( int i = 1 ; i < freenodes.size() ; i++ )
+ {
+ if( freenodes.get( i ).getPower() > ret.getPower() )
+ {
+ ret = freenodes.get( i ) ;
+ }
+ }
+
+ return ret ;
+ }
+
+
+ /**
+ * Construct and return a copy of the current Cluster.
+ * @return A copy of the cluster
+ */
+ public Cluster clone()
+ {
+ Cluster copy = new Cluster() ;
+
+ copy.setName( name ) ;
+ copy.setSite( site ) ;
+
+ for( int i = 0 ; i < nodes.size() ; i++ )
+ {
+ GNode newgn = (GNode) nodes.get( i ).clone() ;
+ newgn.setCluster( copy ) ;
+ copy.addGNode( newgn ) ;
+ }
+
+ return copy ;
+ }
+
}
/** La programmation est un art, respectons ceux qui la pratiquent !! **/