Package org.opennms.netmgt.filter
Class JdbcFilterDao
- java.lang.Object
-
- org.opennms.netmgt.filter.JdbcFilterDao
-
-
Constructor Summary
Constructors Constructor Description JdbcFilterDao()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
afterPropertiesSet()
afterPropertiesSetvoid
destroy()
void
flushActiveIpAddressListCache()
protected java.net.InetAddress
getActiveIPAddress(java.lang.String rule, java.lang.String address)
java.util.List<java.net.InetAddress>
getActiveIPAddressList(java.lang.String rule)
Get the (non-deleted) IP addresses that match the specified rule.DatabaseSchemaConfig
getDatabaseSchemaConfigFactory()
getDatabaseSchemaConfigFactoryjavax.sql.DataSource
getDataSource()
getDataSourcejava.lang.String
getInterfaceWithServiceStatement(java.lang.String rule)
getInterfaceWithServiceStatementjava.util.List<java.net.InetAddress>
getIPAddressList(java.lang.String rule)
Get the IP addresses (including deleted) that match the specified rule.java.util.Map<java.net.InetAddress,java.util.Set<java.lang.String>>
getIPAddressServiceMap(java.lang.String rule)
getIPServiceMapjava.util.Map<java.lang.Integer,java.util.Map<java.net.InetAddress,java.util.Set<java.lang.String>>>
getNodeIPAddressServiceMap(java.lang.String rule)
Retrieve a mapping of IP-services scoped by node that match the given rule.java.lang.String
getNodeIPServiceMappingStatement(java.lang.String rule)
getNodeIPServiceMappingStatementjava.util.SortedMap<java.lang.Integer,java.lang.String>
getNodeMap(java.lang.String rule)
This method returns a map of all node IDs and node labels that match the rule that is passed in, sorted by node ID.java.lang.String
getNodeMappingStatement(java.lang.String rule)
getNodeMappingStatementprotected java.lang.String
getSQLStatement(java.lang.String rule)
This method parses a rule and returns the SQL select statement equivalent of the rule.protected java.lang.String
getSQLStatement(java.lang.String rule, long nodeId, java.lang.String ipaddr, java.lang.String service)
This method should be called if you want to put constraints on the node, interface or service that is returned in the rule.boolean
isRuleMatching(java.lang.String rule)
Does this rule match anything in the database? In particular, does it return at least one record from the database?boolean
isValid(java.lang.String addr, java.lang.String rule)
isValidvoid
setDatabaseSchemaConfigFactory(DatabaseSchemaConfig factory)
setDatabaseSchemaConfigFactoryvoid
setDataSource(javax.sql.DataSource dataSource)
setDataSourcevoid
validateRule(java.lang.String rule)
validateRule
-
-
-
Method Detail
-
setDataSource
public void setDataSource(javax.sql.DataSource dataSource)
setDataSource
- Parameters:
dataSource
- aDataSource
object.
-
getDataSource
public javax.sql.DataSource getDataSource()
getDataSource
- Returns:
- a
DataSource
object.
-
setDatabaseSchemaConfigFactory
public void setDatabaseSchemaConfigFactory(DatabaseSchemaConfig factory)
setDatabaseSchemaConfigFactory
- Parameters:
factory
- aDatabaseSchemaConfigFactory
object.
-
getDatabaseSchemaConfigFactory
public DatabaseSchemaConfig getDatabaseSchemaConfigFactory()
getDatabaseSchemaConfigFactory
- Returns:
- a
DatabaseSchemaConfigFactory
object.
-
afterPropertiesSet
public void afterPropertiesSet()
afterPropertiesSet
- Specified by:
afterPropertiesSet
in interfaceorg.springframework.beans.factory.InitializingBean
-
destroy
@PreDestroy @Transactional(propagation=NOT_SUPPORTED) public void destroy() throws java.lang.Exception
- Throws:
java.lang.Exception
-
getNodeMap
public java.util.SortedMap<java.lang.Integer,java.lang.String> getNodeMap(java.lang.String rule) throws FilterParseException
This method returns a map of all node IDs and node labels that match the rule that is passed in, sorted by node ID. This method returns a map of all nodeids and nodelabels that match the rule that is passed in, sorted by nodeid.- Specified by:
getNodeMap
in interfaceFilterDao
- Parameters:
rule
- an expression rule to be parsed and executed.- Returns:
- SortedMap containing all node IDs and node labels selected by the rule.
- Throws:
FilterParseException
- if a rule is syntactically incorrect or failed in executing the SQL statement
-
getIPAddressServiceMap
public java.util.Map<java.net.InetAddress,java.util.Set<java.lang.String>> getIPAddressServiceMap(java.lang.String rule) throws FilterParseException
getIPServiceMap
- Specified by:
getIPAddressServiceMap
in interfaceFilterDao
- Parameters:
rule
- aString
object.- Returns:
- a
Map
object. - Throws:
FilterParseException
- if any.
-
getNodeIPAddressServiceMap
public java.util.Map<java.lang.Integer,java.util.Map<java.net.InetAddress,java.util.Set<java.lang.String>>> getNodeIPAddressServiceMap(java.lang.String rule) throws FilterParseException
Description copied from interface:FilterDao
Retrieve a mapping of IP-services scoped by node that match the given rule.- Specified by:
getNodeIPAddressServiceMap
in interfaceFilterDao
- Parameters:
rule
- filter rule to evaluate- Returns:
- map of IP-services
- Throws:
FilterParseException
- if the rule is invalid
-
flushActiveIpAddressListCache
@CacheEvict(value="activeIpAddressList", allEntries=true) public void flushActiveIpAddressListCache()
- Specified by:
flushActiveIpAddressListCache
in interfaceFilterDao
-
getActiveIPAddressList
@Cacheable("activeIpAddressList") public java.util.List<java.net.InetAddress> getActiveIPAddressList(java.lang.String rule) throws FilterParseException
Get the (non-deleted) IP addresses that match the specified rule.- Specified by:
getActiveIPAddressList
in interfaceFilterDao
- Parameters:
rule
- the filter rule- Returns:
- a
List
of IP addresses. - Throws:
FilterParseException
- if a rule is syntactically incorrect or failed in executing the SQL statement.
-
getActiveIPAddress
protected java.net.InetAddress getActiveIPAddress(java.lang.String rule, java.lang.String address)
-
getIPAddressList
public java.util.List<java.net.InetAddress> getIPAddressList(java.lang.String rule) throws FilterParseException
Get the IP addresses (including deleted) that match the specified rule.- Specified by:
getIPAddressList
in interfaceFilterDao
- Parameters:
rule
- the filter rule- Returns:
- a
List
of IP addresses. - Throws:
FilterParseException
- if a rule is syntactically incorrect or failed in executing the SQL statement.
-
isValid
public boolean isValid(java.lang.String addr, java.lang.String rule) throws FilterParseException
isValid
This method verifies if an ip address adheres to a given rule.- Specified by:
isValid
in interfaceFilterDao
- Parameters:
addr
- aString
object.rule
- aString
object.- Returns:
- a boolean.
- Throws:
FilterParseException
- if a rule is syntactically incorrect or failed in executing the SQL statement.
-
isRuleMatching
public boolean isRuleMatching(java.lang.String rule) throws FilterParseException
Does this rule match anything in the database? In particular, does it return at least one record from the database?- Specified by:
isRuleMatching
in interfaceFilterDao
- Parameters:
rule
- rule to match on- Returns:
- true if there is at least one match, false otherwise
- Throws:
FilterParseException
- if any.
-
validateRule
public void validateRule(java.lang.String rule) throws FilterParseException
validateRule
- Specified by:
validateRule
in interfaceFilterDao
- Parameters:
rule
- aString
object.- Throws:
FilterParseException
- if any.
-
getNodeMappingStatement
public java.lang.String getNodeMappingStatement(java.lang.String rule) throws FilterParseException
getNodeMappingStatement
- Parameters:
rule
- aString
object.- Returns:
- a
String
object. - Throws:
FilterParseException
- if any.
-
getNodeIPServiceMappingStatement
public java.lang.String getNodeIPServiceMappingStatement(java.lang.String rule) throws FilterParseException
getNodeIPServiceMappingStatement
- Parameters:
rule
- aString
object.- Returns:
- a
String
object. - Throws:
FilterParseException
- if any.
-
getInterfaceWithServiceStatement
public java.lang.String getInterfaceWithServiceStatement(java.lang.String rule) throws FilterParseException
getInterfaceWithServiceStatement
- Parameters:
rule
- aString
object.- Returns:
- a
String
object. - Throws:
FilterParseException
- if any.
-
getSQLStatement
protected java.lang.String getSQLStatement(java.lang.String rule) throws FilterParseException
This method parses a rule and returns the SQL select statement equivalent of the rule.- Parameters:
rule
- aString
object.- Returns:
- the SQL select statement
- Throws:
FilterParseException
- if any.
-
getSQLStatement
protected java.lang.String getSQLStatement(java.lang.String rule, long nodeId, java.lang.String ipaddr, java.lang.String service) throws FilterParseException
This method should be called if you want to put constraints on the node, interface or service that is returned in the rule. This is useful to see if a particular node, interface, or service matches in the rule, and is primarily used to filter notices. A sub-select is built containing joins constrained by node, interface, and service if they are not null or blank. This select is then ANDed with the filter rule to get the complete SQL statement.- Parameters:
nodeId
- a node id to constrain againstipaddr
- an ipaddress to constrain againstservice
- a service name to constrain againstrule
- aString
object.- Returns:
- a
String
object. - Throws:
FilterParseException
- if any.
-
-