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
0561682
..
69323eb
100644
(file)
--- a/
src/and/Mapping/Cluster.java
+++ b/
src/and/Mapping/Cluster.java
@@
-14,11
+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 ;
/**
@@
-26,51
+26,11
@@
public class Cluster implements Serializable
*/
public Cluster()
{
- nb_node = 0 ;
name = "" ;
nodes = new ArrayList<GNode>() ;
+ freenodes = new ArrayList<GNode>() ;
site = "" ;
- indice = 0 ;
- }
-
-
- /**
- * Constructor.
- * @param _nb The amount of computing nodes in the cluster
- */
- public Cluster( int _nb )
- {
- nb_node = _nb ;
- name = "" ;
- nodes = 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() ) ;
- }
+ moreNode = 0 ;
}
@@
-90,10
+50,16
@@
public class Cluster implements Serializable
*/
public void addGNode( GNode _n )
{
- _n.setInCluster( true ) ;
- nodes.add( _n ) ;
+ if( _n != null && _n.getClusterName().equalsIgnoreCase( name ) )
+ {
+ _n.setInCluster( true ) ;
+ nodes.add( _n ) ;
- nb_node++ ;
+ if( ! _n.getMapped() )
+ {
+ freenodes.add( _n ) ;
+ }
+ }
}
@@
-107,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
@@
-123,7
+99,7
@@
public class Cluster implements Serializable
*/
public int getNbGNode()
{
- return n
b_node
;
+ return n
odes.size()
;
}
@@
-148,50
+124,101
@@
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 T
rue is _g is in, False els
e
+ * @return T
he position of the nod
e
*/
- public
boolean
isIn( GNode _g )
+ public
int
isIn( GNode _g )
{
+ int pos = -1 ;
+
if( _g != null )
{
- for( int i = 0
; i < nodes.size()
; i ++ )
+ for( int i = 0
; i < nodes.size()
; i ++ )
{
if( nodes.get( i ).getId() == _g.getId() )
- return true ;
+ {
+ pos = i ;
+ break ;
+ }
}
}
- return
false
;
+ return
pos
;
}
+
/**
- * Initialization of indice variable.
+ * 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 void initIndice()
- {
- indice = 0 ;
+ 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 )
+ if( freenodes.size() > 0 )
+ {
+ ret = freenodes.get( 0 ) ;
+ }
+
+ 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 )
{
- ret = nodes.get( indice ) ;
- indice++ ;
+ 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 ;
+ }
/**
@@
-200,20
+227,249
@@
public class Cluster implements Serializable
*/
public void removeGNode( GNode _dead )
{
- if( _dead != null && _dead.getCluster().equals( name ) && _dead.getSite().equals( site ) )
+ if( _dead != null )
+ {
+ if( _dead.getClusterName().equalsIgnoreCase( name )
+ && _dead.getSiteName().equalsIgnoreCase( site ) )
+ {
+ int i = 0 ;
+ for( i = 0 ; i < nodes.size() ; i++ )
+ {
+ 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!" ) ;
+ }
+ }
+
+
+ /**
+ * Set the mapped status of a node of the cluster.
+ * @param _g The mapped node
+ * @param _status The status of the node
+ */
+ public void setGNodeStatus( GNode _g, boolean _status )
+ {
+ if( _g != null )
{
for( int i = 0 ; i < nodes.size() ; i++ )
{
- if(
_dead.getId() == nodes.get( i )
.getId() )
+ if(
nodes.get( i ).getId() == _g
.getId() )
{
- nodes.remove( i ) ;
- nb_node-- ;
+ nodes.get( i ).setMapped( _status ) ;
- break ;
+ if( _status )
+ {
+ 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 ) ) ;
+ }
}
}
}
+ }
+
+
+ /**
+ * Return the amount of available free nodes in the cluster.
+ * @return The amount of free nodes
+ */
+ public int getNbFreeNodes()
+ {
+ 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
+ * of these nodes to be not mapped on.
+ */
+ public void initGNodes()
+ {
+ /** Initialization of local nodes **/
+ /** and reconstruction of the freenodes list **/
+ freenodes = null ;
+ freenodes = new ArrayList<GNode>() ;
+
+ for( int i = 0 ; i < nodes.size() ; i++ )
+ {
+ nodes.get( i ).setMapped( false ) ;
+
+ freenodes.add( nodes.get( i ) ) ;
+ }
+ }
+
+
+ /**
+ * 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 ;
}
}