GridGain™ 2.1.0
Java API Specification

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, GridSpiManagementMBean, GridTopologySpi, GridNodeFilterTopologySpiMBean

@GridSpiInfo(author="GridGain Systems",
             url="www.gridgain.org",
             email="support@gridgain.com",
             version="x.x")
public class GridNodeFilterTopologySpi
extends GridSpiAdapter
implements GridTopologySpi, GridNodeFilterTopologySpiMBean

This class provides implementation for topology SPI based on GridNodeFilter. The implementation returns nodes that are accepted by GridNodeFilter provided in configuration. If no filters were 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. Take a look at the following methods on GridNode interface which may be used for filtering:

Apache JEXL Node Filter

GridGain also comes with GridJexlNodeFilter 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. GridJexlNodeFilter 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 GridJexlNodeFilter 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();

 GridNodeFilter filter = new GridJexlNodeFilter(
     "node.metrics.availableProcessors > 1 && " + 
     "node.metrics.averageCpuLoad < 0.5 && " + 
     "node.attributes['os.name'] == 'Windows XP'");

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

 GridConfigurationAdapter cfg = new GridConfigurationAdapter();

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

 // Start grid.
 GridFactory.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.GridJexlNodeFilter">
                        <property name="expression">
                            <value>
                                <![CDATA[node.metrics.availableProcessors > 1 &&
                                node.metrics.averageCpuLoad < 0.5 &&
                                node.attributes['os.name'] == 'Windows XP']]>
                            </value>
                        </property>
                    </bean>
                </property>
           </bean>
       </property>
       ...
 </bean>
 





See Also:

  Documentation
  Email Support
  Online Forums
  Issue Tracking

Author:   2005-2008 Copyright © GridGain Systems. All Rights Reserved. ver. 2.1.0

 

Constructor Summary
GridNodeFilterTopologySpi()
           
 
Method Summary
 GridNodeFilter getFilter()
          Gets node filter for nodes to be included into topology.
 Collection<GridNode> getTopology(GridTaskSession ses, Collection<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(GridNodeFilter 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, configInfo, createSpiAttributeName, getAuthor, getConsistentAttributeNames, getGridGainHome, getLocalNodeId, getName, getNodeAttributes, getSpiContext, getStartTimestamp, getStartTimestampFormatted, getUpTime, getUpTimeFormatted, getVendorEmail, getVendorUrl, getVersion, onContextDestroyed, onContextInitialized, registerMBean, setName, setSpiContext, 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.GridSpiManagementMBean
getAuthor, getGridGainHome, getLocalNodeId, getName, getStartTimestamp, getStartTimestampFormatted, getUpTime, getUpTimeFormatted, getVendorEmail, getVendorUrl, getVersion
 

Constructor Detail

GridNodeFilterTopologySpi

public GridNodeFilterTopologySpi()
Method Detail

getFilter

public GridNodeFilter getFilter()
Gets node filter for nodes to be included into topology.

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

setFilter

@GridSpiConfiguration(optional=true)
public void setFilter(GridNodeFilter filter)
Sets filter for nodes to be included into task topology.

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

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<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™ 2.1.0
Java API Specification

GridGain™ - Grid Computing Made Simple, ver. 2.1.0.19122008
2005-2008 Copyright © GridGain Systems. All Rights Reserved.