GridGain™ 4.3.1e
Enterprise "Big Data" Edition

org.gridgain.grid.spi.topology.nodefilter
Class GridNodeFilterTopologySpi

java.lang.Object
  extended by org.gridgain.grid.spi.GridSpiAdapter
      extended by org.gridgain.grid.spi.topology.nodefilter.GridNodeFilterTopologySpi
All Implemented Interfaces:
GridSpi, GridSpiJsonConfigurable, GridSpiManagementMBean, GridTopologySpi, GridNodeFilterTopologySpiMBean

@GridSpiInfo(author="GridGain Systems",
             url="www.gridgain.com",
             email="support@gridgain.com",
             version="4.3.1e.10112012")
@GridSpiMultipleInstancesSupport(value=true)
public class GridNodeFilterTopologySpi
extends GridSpiAdapter
implements GridTopologySpi, GridNodeFilterTopologySpiMBean

This class provides implementation for topology SPI based on GridPredicate2. The implementation returns nodes that are accepted by GridPredicate2 provided in configuration. If no predicate filter was provided, all nodes, local and remote, will be included into topology.

This topology allows for fine grained node provisioning for grid task execution. Nodes can be filtered based on any parameter available on GridNode. For example, you can filter nodes based on operating system, number of CPU's, available heap memory, average job execution time, current CPU load, any node attribute and about 50 more metrics available in GridNodeMetrics. Here some of the methods on GridNode interface which may be used for filtering:

Apache JEXL Predicate Filter

GridGain also comes with GridJexlPredicate2 implementation which allows you to conveniently filter nodes based on Apache JEXL expression language. Refer to Apache JEXL documentation for specifics of JEXL expression language. GridJexlPredicate2 allows for a fairly simple way to provide complex SLA-based task topology specifications. For example, the configuration examples below show how the SPI can be configured with GridJexlPredicate2 to include all Windows XP nodes with more than one processor or core and that are not loaded over 50%.

Configuration

Mandatory

This SPI has no mandatory configuration parameters.

Optional

This SPI has following optional configuration parameters:

Java Example

GridNodeFilterTopologySpi needs to be explicitely configured.
 GridNodeFilterTopologySpi topSpi = new GridNodeFilterTopologySpi();

 GridJexlPredicate2<GridNode, GridTaskSession> filter = new GridJexlPredicate2<GridNode, GridTaskSession>(
     "node.metrics().availableProcessors > 1 && " +
     "node.metrics().averageCpuLoad < 0.5 && " +
     "node.attributes().get('os.name') == 'Windows XP'", "node", "ses");

 // Add filter.
 topSpi.setFilter(filter);

 GridConfigurationAdapter cfg = new GridConfigurationAdapter();

 // Override topology SPI.
 cfg.setTopologySpi(topSpi);

 // Starts grid.
 G.start(cfg);
 

Spring Example

GridNodeFilterTopologySpi can be configured from Spring XML configuration file:
 <bean id="grid.custom.cfg" class="org.gridgain.grid.GridConfigurationAdapter" singleton="true">
       ...
       <property name="topologySpi">
           <bean class="org.gridgain.grid.spi.topology.nodefilter.GridNodeFilterTopologySpi">
               <property name="filter">
                    <bean class="org.gridgain.grid.lang.GridJexlPredicate2">
                        <constructor-arg>
                            <value>
                                <![CDATA[elem1.metrics().availableProcessors > 1 &&
                                elem1.metrics().averageCpuLoad < 0.5 &&
                                elem1.attributes().get('os.name') == 'Windows XP']]>
                            </value>
                        </constructor-arg>
                    </bean>
                </property>
           </bean>
       </property>
       ...
 </bean>
 

 

Constructor Summary
GridNodeFilterTopologySpi()
           
 
Method Summary
 GridPredicate2<GridNode,GridTaskSession> getFilter()
          Gets node predicate filter for nodes to be included into topology.
 Collection<GridNode> getTopology(GridTaskSession ses, Collection<? extends GridNode> grid)
          This method is called by GridGain right before calling GridTask.map(List, Object) to obtain a topology for the task's split.
 void setFilter(GridPredicate2<GridNode,GridTaskSession> filter)
          Sets filter for nodes to be included into task topology.
 void spiStart(String gridName)
          This method is called to start SPI.
 void spiStop()
          This method is called to stop SPI.
 String toString()
          
 
Methods inherited from class org.gridgain.grid.spi.GridSpiAdapter
assertParameter, checkConfigurationConsistency0, configInfo, createSpiAttributeName, getAuthor, getConsistentAttributeNames, getGridGainHome, getLocalNodeId, getName, getNodeAttributes, getSpiContext, getStartTimestamp, getStartTimestampFormatted, getUpTime, getUpTimeFormatted, getVendorEmail, getVendorUrl, getVersion, injectables, onContextDestroyed, onContextDestroyed0, onContextInitialized, onContextInitialized0, registerMBean, setJson, setName, startInfo, startStopwatch, stopInfo, unregisterMBean
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.gridgain.grid.spi.GridSpi
getName, getNodeAttributes, onContextDestroyed, onContextInitialized
 
Methods inherited from interface org.gridgain.grid.spi.GridSpiJsonConfigurable
setJson
 
Methods inherited from interface org.gridgain.grid.spi.GridSpiManagementMBean
getAuthor, getGridGainHome, getLocalNodeId, getName, getStartTimestamp, getStartTimestampFormatted, getUpTime, getUpTimeFormatted, getVendorEmail, getVendorUrl, getVersion
 

Constructor Detail

GridNodeFilterTopologySpi

public GridNodeFilterTopologySpi()
Method Detail

getFilter

public GridPredicate2<GridNode,GridTaskSession> getFilter()
Gets node predicate filter for nodes to be included into topology.

Specified by:
getFilter in interface GridNodeFilterTopologySpiMBean
Returns:
Node predicate filter for nodes to be included into topology.

setFilter

@GridSpiConfiguration(optional=true)
public void setFilter(GridPredicate2<GridNode,GridTaskSession> filter)
Sets filter for nodes to be included into task topology.

Parameters:
filter - Filter to use.
See Also:
GridJexlPredicate2

spiStart

public void spiStart(@Nullable
                     String gridName)
              throws GridSpiException
This method is called to start SPI. After this method returns successfully kernel assumes that SPI is fully operational.

Specified by:
spiStart in interface GridSpi
Throws:
GridSpiException - Throws in case of any error during SPI start.
Parameters:
gridName - Name of grid instance this SPI is being started for (null for default grid).

spiStop

public void spiStop()
             throws GridSpiException
This method is called to stop SPI. After this method returns kernel assumes that this SPI is finished and all resources acquired by it are released.

Note that this method can be called at any point including during recovery of failed start. It should make no assumptions on what state SPI will be in when this method is called.

Specified by:
spiStop in interface GridSpi
Throws:
GridSpiException - Thrown in case of any error during SPI stop.

getTopology

public Collection<GridNode> getTopology(GridTaskSession ses,
                                        Collection<? extends GridNode> grid)
                                 throws GridSpiException
This method is called by GridGain right before calling GridTask.map(List, Object) to obtain a topology for the task's split.

Specified by:
getTopology in interface GridTopologySpi
Throws:
GridSpiException - Thrown in case if topology cannot be obtained.
Parameters:
ses - Current task's session. If implementation does not depend on task's information it may ignore it.
grid - Full set of all grid nodes.
Returns:
Topology to use for execution of the task represented by the session passed in.

toString

public String toString()

Overrides:
toString in class Object

GridGain™ 4.3.1e
Enterprise "Big Data" Edition

GridGain - In-Memory Big Data
Enterprise "Big Data" Edition, ver. 4.3.1e.10112012
2012 Copyright © GridGain Systems
Follow us:   Follow GridGain on Github Join GridGain User Group Follow GridGain on Twitter Follow GridGain on Vimeo