com.ace.moab.api.node
Class PriorityFunction

java.lang.Object
  extended by com.ace.moab.api.node.PriorityFunction
All Implemented Interfaces:
java.lang.Comparable<PriorityFunction>

public class PriorityFunction
extends java.lang.Object
implements java.lang.Comparable<PriorityFunction>

Represents a priority function within moab. Each node can be configured to have a function that explains it's priority used when moab assigns jobs to nodes. This function is simply a list of coefficients and numerical node attributes that are added together.

For example, a priority function could be: 10 * AMEM + -1 * CPROCS . This function would take the node's available memory, multiply it by 10, then subtract the number of configured processors. The resulting value would be a double.

The priority function is only useful when moab has been configured with a NODEALLOCATIONPOLICY set to PRIORITY within moab's configuration file. This priority has nothing to do with a Job's priority, as that is calculated and used elsewhere for scheduling jobs, not which nodes the job should run on.

Author:
Scott Brown

Constructor Summary
PriorityFunction()
           Empty constructor.
PriorityFunction(MoabNode owner)
           Owner constructor.
PriorityFunction(PriorityFunction other, MoabNode owner)
           Copy constructor.
 
Method Summary
 void addExpression(FunctionExpression expr)
          Add an expression to the function.
 void addExpression(PriorityComponent attribute, double value)
          Add an expression to the function.
 int compareTo(PriorityFunction o)
           
 double evaluate()
          Calculates the value of the function based on the current values of the owner node.
 java.lang.Double evaluateForNode(MoabNode node)
          Calculates the value of the function based on the current values of the given node.
 java.util.Set<FunctionExpression> getExpressions()
          Gets the list of FunctionExpressions that make up this Priority function.
 MoabNode getOwner()
          Get the owner node of this function.
 void parseFunctionString(java.lang.String funcString)
          Sets the function's expressions attributes based on the input string.
 void removeExpression(FunctionExpression expr)
          Removes an expression from the list of expressions that make up this Priority Function.
 void setOwner(MoabNode owner)
          Set the owner node of this function.
 java.lang.String toMoabString()
          Get a string representation of the priority function in a format that Moab can parse.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PriorityFunction

public PriorityFunction()

Empty constructor. Creates a new priority function that by default is empty (has no expressions). Attempting to create a priority function that belongs to an owner, it is better to use the constructor that accepts a MoabNode for the owner.

Sets the owner MoabNode to null.


PriorityFunction

public PriorityFunction(MoabNode owner)

Owner constructor. Creates a new priority function that by default is empty (has no expressions). A PriorityFunction object should have an owner of type MoabNode. This owner is the node whose priority is determined using this function.

Parameters:
owner - The MoabNode that contains this priority function.

PriorityFunction

public PriorityFunction(PriorityFunction other,
                        MoabNode owner)

Copy constructor. Creates a priority function based on the other priority function. This is useful when the default node has a set priority function but this node's priority function is not set. The priority function for this node can then be created using this priority function and a new owner can be set for it.

Parameters:
other - the PriorityFunction that will be copied.
owner - the new owner of the priority function.
Method Detail

addExpression

public void addExpression(FunctionExpression expr)
Add an expression to the function.

Parameters:
expr - the FunctionExpression to add to the function.

addExpression

public void addExpression(PriorityComponent attribute,
                          double value)
Add an expression to the function. This method creates a FunctionExpression object that in turn is added to the function.

Parameters:
attribute - A priority component used as the attribute of the FunctionExpression.
value - the value to be assigned as a factor to the FunctionExpression

compareTo

public int compareTo(PriorityFunction o)
Specified by:
compareTo in interface java.lang.Comparable<PriorityFunction>

evaluate

public double evaluate()
Calculates the value of the function based on the current values of the owner node. If owner is null, this method will throw an error.

Returns:
the calculated value of the evaluated function.

evaluateForNode

public java.lang.Double evaluateForNode(MoabNode node)
Calculates the value of the function based on the current values of the given node. If node is null, this method will throw an error.

Parameters:
node - the MoabNode that will be used to calculate the value of the function expression
Returns:
the calculated value of the evaluated function

getExpressions

public java.util.Set<FunctionExpression> getExpressions()
Gets the list of FunctionExpressions that make up this Priority function.

Returns:
the list of FunctionExpressions that make up this Priority function.

getOwner

public MoabNode getOwner()
Get the owner node of this function. Can be null.

Returns:
the owner of the function.

removeExpression

public void removeExpression(FunctionExpression expr)
Removes an expression from the list of expressions that make up this Priority Function.

Parameters:
expr - the expression to be removed from the list of expressions that make up this Priority Function.

toMoabString

public java.lang.String toMoabString()
Get a string representation of the priority function in a format that Moab can parse. If the function is empty, an empty string is returned.

Returns:
A Moab-parseable string representation of the priority function.

parseFunctionString

public void parseFunctionString(java.lang.String funcString)
                         throws java.text.ParseException
Sets the function's expressions attributes based on the input string. This input string is reported from Moab and is parsed from the NodeXMLInterface. See Moab's MPrioFToString function for more details on how the input string is formatted.

Parameters:
funcString - String representing a node's priority function.
Throws:
java.text.ParseException - if the parsing fails, this error is thrown.

setOwner

public void setOwner(MoabNode owner)
Set the owner node of this function. Can be null.

Parameters:
owner - the owner of the function.


Copyright © 2001-2009 Cluster Resources, Inc. All Rights Reserved.