Dashboard > GridGain User Guide > Table Of Contents > Developers Guide > Topology SPI > GridNodeFilterTopologySpi
GridNodeFilterTopologySpi
Added by ghost, last edited by dozer on Dec 18, 2008  (view change)
Labels: 
(None)


Click on Javadoc link to open Javadoc documentation.

Package

org.gridgain.grid.spi.topology.nodefilter Javadoc

Description

GridNodeFilterTopologySpi Javadoc provides topology SPI implementation based on node filters. This implementation always returns all nodes (local and remote) that fit given filter. 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 Javadoc . 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 Javadoc . Take a look at the following methods on GridNode Javadoc interface which may be used for filtering:

  • GridNode.getPhysicalAddress() Javadoc - in mose cases this parameter represents the IP address the node.
  • GridNode.getAttributes() Javadoc - attributes attached to a grid node. Node attributes are specified in grid configuration via GridConfiguration.getUserAttributes() Javadoc parameter. Note that all system and environment properties are automatically pre-set as node attributes for every node.
  • GridNode.getMetrics() Javadoc - about 50 node metrics parameters that are periodically updated, such as heap, CPU, job counts, average job execution times, etc...

Apache JEXL Node Filter

GridGain also comes with GridJexlNodeFilter Javadoc 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 Javadoc 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%.

Expression variables

Variable named node, which is a GridNode Javadoc instance, is always available in expression.

Configuration

The following configuration parameters can be used to configure GridAttributesTopologySpi Javadoc

Setter Method Description Optional Default
setFilter(GridNodeFilter) Javadoc Sets filter for nodes to be included into task topology. Yes

Examples

As any GridGain SPI, GridNodeFilterTopologySpi Javadoc can be configured either directly from code or from Spring configuration file. Following example shows how to include all Windows XP nodes with more than one processor or core and that are not loaded over 50%. Example of GridNodeFilterTopologySpi Javadoc configuration from code:

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);

or from Spring 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>


For more information about using Spring framework for configuration click here.

Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.2.10 Build:#528 Nov 29, 2006) - Bug/feature request - Contact Administrators