5 A filter examine an event and decides if it matches or doesn't. Filters
\r
6 are mainly used in rules to decide if the processing entries should be
\r
7 executed on the given event. They're also used for settings, and systems
\r
8 like the Graph Correlator re-use Highland Park's filter mechanism to
\r
9 specify which alarms fit in a correlation. Some publishers may produce
\r
10 topics with a lot of volume and a subscriber may want only a portion of
\r
11 those messages. The subscriber can certainly filter messages after
\r
12 receiving them, but it may be substantially more efficient to ask the
\r
13 API server to filter the messages before sending them to the
\r
14 subscriber.The standard library includes a number of simple filters. The
\r
15 Equals filter, for example, compares a field's value with some other
\r
16 value and returns true if the values match. The standard library also
\r
17 includes filter classes called And, Or, and Not, so you can compose more
\r
18 complex filters. For example, written in the standard JSON config
\r
21 +-----------------------------------------+
\r
26 | { "class":"Equals", "foo":"abc" }, |
\r
27 | { "class":"Assigned", "field":"bar" } |
\r
30 +-----------------------------------------+
\r
32 - This filter matches events in which the field "foo" has value "abc"
\r
33 and the field "bar" is assigned to some value (as opposed to not being
\r
34 present on the event). Filters are used by the consumers to filter out
\r
35 data and consume only specific set of data which matches the
\r
36 conditions mentioned in filter. Filters can be passed as a query
\r
37 parameter by the consumer in consume request as mentioned below:
\r
38 **http://localhost:8080/DMaaP/dmaaprest/events/DMaaP/consumergroup/mHOeNFY4XiWx4CBa?filter=\\{"class":"Equals",
\r
39 "field":"email", "value":"test@abc.com" }**
\r
40 - Filters can be applied only on data in JSON format i.e. if applied,
\r
41 filters will automatically ignore any non-json data. While consuming,
\r
42 request CONTENT\_TYPE is not relevant to filter.
\r
44 All the supported filter can be found below.
\r
49 - DMaaP Message Router supports all the filters which were supported by
\r
50 DMaaP Message Router and are mentioned below:-
\r
52 - Match all alarms.
\r
54 - Create a set of filters. This filter matches when all of them matches.
\r
56 +-------------+--------------------+------------+---------------------+
\r
57 | **Field** | **Description** | **Type** | **Notes** |
\r
58 +=============+====================+============+=====================+
\r
59 | filters | Combined Filters | LIST | A list of filters |
\r
60 +-------------+--------------------+------------+---------------------+
\r
62 +-------------+--------------------+------------+---------------------+
\r
65 - Choose a field from the event to check for assignment. This filter
\r
66 matches when the field is assigned.
\r
68 +-------------------+--------------------------------------------------------+------------+-----------------+
\r
69 | **Field** | **Description** | **Type** | **Notes** |
\r
70 +===================+========================================================+============+=================+
\r
71 | field | The field to check for on the event. | STRING | A field name |
\r
72 +-------------------+--------------------------------------------------------+------------+-----------------+
\r
73 | emptyIsAssigned | If true, an empty value is considered an assignment. | BOOLEAN | True or False |
\r
74 +-------------------+--------------------------------------------------------+------------+-----------------+
\r
77 - Check if a search string contains another string.
\r
79 +-------------+---------------------------------------------------+------------+--------------+
\r
80 | **Field** | **Description** | **Type** | **Notes** |
\r
81 +=============+===================================================+============+==============+
\r
82 | String | The value to search. Supports ${} notation. | STRING | Any string |
\r
83 +-------------+---------------------------------------------------+------------+--------------+
\r
84 | Value | The value to search for. Supports ${} notation. | STRING | Any string |
\r
85 +-------------+---------------------------------------------------+------------+--------------+
\r
87 +-------------+---------------------------------------------------+------------+--------------+
\r
90 - Check if a search string ends with another string.
\r
92 +-------------+---------------------------------------------------+------------+--------------+
\r
93 | **Field** | **Description** | **Type** | **Notes** |
\r
94 +=============+===================================================+============+==============+
\r
95 | string | The value to search. Supports ${} notation. | STRING | Any string |
\r
96 +-------------+---------------------------------------------------+------------+--------------+
\r
97 | value | The value to search for. Supports ${} notation. | STRING | Any string |
\r
98 +-------------+---------------------------------------------------+------------+--------------+
\r
102 - Choose a field from the event and a value to check for equality.
\r
104 +-------------+----------------------------------------------+------------+--------------+
\r
105 | **Field** | **Description** | **Type** | **Notes** |
\r
106 +=============+==============================================+============+==============+
\r
107 | field | The field to check. Supports ${} notation. | STRING | Any string |
\r
108 +-------------+----------------------------------------------+------------+--------------+
\r
109 | value | The value to match. Supports ${} notation. | STRING | Any string |
\r
110 +-------------+----------------------------------------------+------------+--------------+
\r
112 - **FlatironObjectExists**
\r
114 - Matches when the given object exists in the given Flatiron instance.
\r
116 +-------------+---------------------------------------------+------------+--------------+
\r
117 | **Field** | **Description** | **Type** | **Notes** |
\r
118 +=============+=============================================+============+==============+
\r
119 | oid | The OID of the object to look for. | STRING | Any string |
\r
120 +-------------+---------------------------------------------+------------+--------------+
\r
121 | flatiron | The name of the Flatiron client instance. | STRING | Any string |
\r
122 +-------------+---------------------------------------------+------------+--------------+
\r
125 - Choose a field to test. This filter matches if the expression is
\r
128 +-------------+---------------------------------------------+------------+--------------+
\r
129 | **Field** | **Description** | **Type** | **Notes** |
\r
130 +=============+=============================================+============+==============+
\r
131 | field | The field to test. Supports ${} notation. | STRING | Any string |
\r
132 +-------------+---------------------------------------------+------------+--------------+
\r
135 - Choose a field to test. This filter matches if the expression is
\r
138 +-------------+---------------------------------------------+------------+--------------+
\r
139 | **Field** | **Description** | **Type** | **Notes** |
\r
140 +=============+=============================================+============+==============+
\r
141 | field | The field to test. Supports ${} notation. | STRING | Any string |
\r
142 +-------------+---------------------------------------------+------------+--------------+
\r
144 - **MathCondition**
\r
145 - Choose a field from the event and a value for logical math conditions.
\r
147 +-------------+-------------------------------------------------+------------+-----------------------------------+
\r
148 | **Field** | **Description** | **Type** | **Notes** |
\r
149 +=============+=================================================+============+===================================+
\r
150 | Field | The field to check. Supports ${} notation. | STRING | Any string |
\r
151 +-------------+-------------------------------------------------+------------+-----------------------------------+
\r
152 | Value | The value to consider. Supports ${} notation. | STRING | Any string |
\r
153 +-------------+-------------------------------------------------+------------+-----------------------------------+
\r
154 | operator | The operation. | STRING | One of { "<=", ">=", ">", "<" } |
\r
155 +-------------+-------------------------------------------------+------------+-----------------------------------+
\r
157 +-------------+-------------------------------------------------+------------+-----------------------------------+
\r
160 - Don't match any alarms.
\r
162 - Negate the configured filter.
\r
164 +-------------+-------------------------+------------+-------------+
\r
165 | **Field** | **Description** | **Type** | **Notes** |
\r
166 +=============+=========================+============+=============+
\r
167 | filter | The filter to negate. | FILTER | A filter |
\r
168 +-------------+-------------------------+------------+-------------+
\r
171 - Choose a field from the event and a value to check for inequality.
\r
173 +-------------+----------------------------------------------+------------+--------------+
\r
174 | **Field** | **Description** | **Type** | **Notes** |
\r
175 +=============+==============================================+============+==============+
\r
176 | field | The field to check. Supports ${} notation. | STRING | Any string |
\r
177 +-------------+----------------------------------------------+------------+--------------+
\r
178 | value | The value to match. Supports ${} notation. | STRING | Any string |
\r
179 +-------------+----------------------------------------------+------------+--------------+
\r
182 - Match when the specified field does not have a value from the given
\r
185 +-------------+---------------------------------------------+------------+---------------------+
\r
186 | **Field** | **Description** | **Type** | **Notes** |
\r
187 +=============+=============================================+============+=====================+
\r
188 | field | The field to test. Supports ${} notation. | STRING | Any string |
\r
189 +-------------+---------------------------------------------+------------+---------------------+
\r
190 | values | The matching values. | LIST | A list of strings |
\r
191 +-------------+---------------------------------------------+------------+---------------------+
\r
194 - Match when the specified field has a value from the given list.
\r
196 +-------------+---------------------------------------------+------------+---------------------+
\r
197 | **Field** | **Description** | **Type** | **Notes** |
\r
198 +=============+=============================================+============+=====================+
\r
199 | field | The field to test. Supports ${} notation. | STRING | Any string |
\r
200 +-------------+---------------------------------------------+------------+---------------------+
\r
201 | values | The matching values. | LIST | A list of strings |
\r
202 +-------------+---------------------------------------------+------------+---------------------+
\r
205 - Create a set of filters. This filter matches when any one of them
\r
208 +-------------+--------------------+------------+---------------------+
\r
209 | **Field** | **Description** | **Type** | **Notes** |
\r
210 +=============+====================+============+=====================+
\r
211 | filters | Combined Filters | LIST | A list of filters |
\r
212 +-------------+--------------------+------------+---------------------+
\r
215 - Choose a field from the event to match against the regular expression
\r
218 +-------------+---------------------------------------------------------+------------+--------------+
\r
219 | **Field** | **Description** | **Type** | **Notes** |
\r
220 +=============+=========================================================+============+==============+
\r
221 | field | The text to check for a match. Supports ${} notation. | STRING | Any string |
\r
222 +-------------+---------------------------------------------------------+------------+--------------+
\r
223 | value | The regular expression (pattern) to match. | STRING | Any string |
\r
224 +-------------+---------------------------------------------------------+------------+--------------+
\r
227 - Check if a search string starts with another string.
\r
229 +-------------+---------------------------------------------------+------------+--------------+
\r
230 | **Field** | **Description** | **Type** | **Notes** |
\r
231 +=============+===================================================+============+==============+
\r
232 | string | The value to search. Supports ${} notation. | STRING | Any string |
\r
233 +-------------+---------------------------------------------------+------------+--------------+
\r
234 | Value | The value to search for. Supports ${} notation. | STRING | Any string |
\r
235 +-------------+---------------------------------------------------+------------+--------------+
\r
238 - Choose a field from the event to check for assignment. This filter
\r
239 matches when the field is not assigned.
\r
241 +-------------------+--------------------------------------------------------+------------+-----------------+
\r
242 | **Field** | **Description** | **Type** | **Notes** |
\r
243 +===================+========================================================+============+=================+
\r
244 | field | The field to check for on the event. | STRING | A field name |
\r
245 +-------------------+--------------------------------------------------------+------------+-----------------+
\r
246 | emptyIsAssigned | If true, an empty value is considered an assignment. | BOOLEAN | True or False |
\r
247 +-------------------+--------------------------------------------------------+------------+-----------------+
\r
249 - **WithinSecondsFrom**
\r
250 - This filter matches when the specified epoch time value is within the
\r
251 given number of seconds from the baseline time value. Both time values
\r
252 are assumed to be in seconds. If a value is in milliseconds, set
\r
253 baselineTimeInMillis and/or eventTimeInMillis to true.
\r
255 +------------------------+------------------------------------------------------------+------------+-----------------+
\r
256 | **Field** | **Description** | **Type** | **Notes** |
\r
257 +========================+============================================================+============+=================+
\r
258 | field | The time value to test. Supports ${} | STRING | A field name |
\r
259 +------------------------+------------------------------------------------------------+------------+-----------------+
\r
260 | eventTimeInMillis | Whether to convert the event value from milliseconds. | BOOLEAN | True or False |
\r
261 +------------------------+------------------------------------------------------------+------------+-----------------+
\r
262 | seconds | The number of seconds. | NUMBER | A number |
\r
263 +------------------------+------------------------------------------------------------+------------+-----------------+
\r
264 | baselineTimeInMillis | Whether to convert the baseline value from milliseconds. | BOOLEAN | True or False |
\r
265 +------------------------+------------------------------------------------------------+------------+-----------------+
\r
266 | baseline | The baseline time value. Supports ${}. | STRING | Any string |
\r
267 +------------------------+------------------------------------------------------------+------------+-----------------+
\r
269 - **WithinTimeFromNow**
\r
270 - This filter matches when the named field has an epoch time value
\r
271 within the given number of seconds from the current time. The event's
\r
272 time value is assumed to be in seconds. If it's in milliseconds, set
\r
273 eventTimeInMillis to true.
\r
275 +---------------------+---------------------------------------------------------+------------+-----------------+
\r
276 | **Field** | **Description** | **Type** | **Notes** |
\r
277 +=====================+=========================================================+============+=================+
\r
278 | field | The field to check on the event. | STRING | A field name |
\r
279 +---------------------+---------------------------------------------------------+------------+-----------------+
\r
280 | eventTimeInMillis | Whether to convert the event value from milliseconds. | BOOLEAN | True or False |
\r
281 +---------------------+---------------------------------------------------------+------------+-----------------+
\r
282 | seconds | The number of seconds. | NUMBER | A number |
\r
283 +---------------------+---------------------------------------------------------+------------+-----------------+
\r
287 - Limit is the integer value and DMaaP Message Router will consumes
\r
288 only that set of message which are specified in limit.
\r
292 Suppose if we set limit=2, then only 2 sets of data will be consumed.
\r
293 *Get \ **<<topicName>>/group/2?limit=4***
\r
295 **No of data available** = 4
\r
297 i.e. limit>no of data
\r
298 In this scenario all 4 sets of data will be consumed.
\r
300 - If limit is not passed with the url then by default limit is set to
\r
305 i.e. 4096 sets of data will be consumed.
\r
306 **Timeout and Long Poll:**
\r
308 - Timeout is the integer value which will be treated by DMaaP Message
\r
309 Router as time in millisecond.
\r
315 +-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
\r
316 | `***http://localhost/DMaaP/dmaaprest/events/<<topicName>>/group/2?timeout=20000*** <http://localhost/DMaaP/dmaaprest/events/%3c%3ctopicName%3e%3e/group/2?timeout=20000>`__ |
\r
317 +-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
\r
319 - If there is no data available to be consumed, then DMaaP Message
\r
320 Router will poll for the particular period of time specified in
\r
321 timeout this mechanism is known as Long Poll.
\r
323 - If timeout is not passed with url then DMaaP Message Router will set
\r
324 the value of timeout =10000
\r
326 - i.e. if no set of data are available then DMaaP Message Router will
\r
331 - Meta is a Boolean value.
\r
333 - DMaaP Message Router reads the value of meta from
\r
334 MRConfiguration.properties file at the time of startup.
\r
336 - If the value of meta is not null and if value of meta is one of these
\r
337 values true, yes, on, 1, y, checked then DMaaP Message Router will
\r
338 take meta flag as true, else it will be false.
\r
340 - If meta is set to true then consumer will get the value of message
\r
341 offset along with message.
\r
345 .. |image1| image:: images/image1.png
\r
349 - Pretty is a Boolean value.
\r
351 - DMaaP Message Router reads the value of pretty from
\r
352 MRConfiguration.properties file at the time of startup.
\r
354 - If the value of pretty is not null and if value of pretty is one of
\r
355 these values true, yes, on, 1, y, checked then DMaaP Message Router
\r
356 will take pretty flag as true, else it will be false.
\r
358 - If pretty is set to true then different sets of messages will be
\r
359 printed in next line separated by comma (,).
\r
363 .. |image2| image:: images/image2.png
\r
367 - A filter examine an event and decides if it matches or doesn't.
\r
368 - Filters are mainly used in rules to decide if the processing entries
\r
369 should be executed on the given event. They're also used for settings,
\r
370 and systems like the Graph Correlator re-use Highland Park's filter
\r
371 mechanism to specify which alarms fit in a correlation.
\r
372 - The standard library includes a number of simple filters. The Equals
\r
373 filter, for example, compares a field's value with some other value
\r
374 and returns true if the values match.
\r
375 - The standard library also includes filter classes called And, Or, and
\r
376 Not, so you can compose more complex filters. For example, written in
\r
377 the standard JSON config format:
\r
379 +-----------------------------------------+
\r
384 | { "class":"Equals", "foo":"abc" }, |
\r
385 | { "class":"Assigned", "field":"bar" } |
\r
388 +-----------------------------------------+
\r
390 - This filter matches events in which the field "foo" has value "abc"
\r
391 and the field "bar" is assigned to some value (as opposed to not being
\r
392 present on the event).
\r
393 - Filters are used by the consumers to filter out data and consume only
\r
394 specific set of data which matches the conditions mentioned in filter.
\r
395 - Filters can be passed as a query parameter by the consumer in consume
\r
396 request as mentioned below:
\r
397 - **http://localhost:8080/DMaaP/dmaaprest/events/DMaaP/consumergroup/mHOeNFY4XiWx4CBa?filter=\\{"class":"Equals",
\r
398 "field":"email", "value":"`test@abc.com <mailto:test@att.com>`__" }**
\r
399 - Filters can be applied only on data in JSON format i.e. if applied,
\r
400 filters will automatically ignore any non-json data.
\r
401 - While consuming, request CONTENT\_TYPE is not relevant to filter.
\r
403 The MR API allows a subscriber pass a Highland Park filter as part of
\r
404 the GET request. This will filter the stream of messages sent back to
\r
405 the subscriber, but for this to work, there are some requirements:
\r
407 - The message payload must be JSON
\r
409 - Only a filter built from Highland Park's Standard Library may be
\r
410 used. (The Cambria API server doesn't have access to plugged in
\r
413 - The filter must be encoded properly in the URL path.
\r
415 Server-side filtering can also be setup in the Java client as
\r
418 **Filtering Consumer**
\r
420 You can also provide a Highland Park filter to your consumer instance,
\r
421 and this filter is passed on to the server in the GET request. One way
\r
422 to create the filter is programmatically. In your code, instantiate a
\r
423 filter from the Highland Park Standard Library Then create a String
\r
424 representation of the filter using the FilterIo.write utility. This
\r
425 String can then be passed to the Cambria client instance for use on the
\r
428 Remember, only Highland Park standard library filter components can be
\r
429 used -- no plug-ins are available in the Cambria server context.
\r
433 package org.onap.sa.highlandPark.integration;
\r
435 import java.io.IOException;
\r
437 import java.util.UUID;
\r
439 import org.onap.nsa.cambria.client.CambriaClientFactory;
\r
441 import org.onap.nsa.cambria.client.CambriaConsumer;
\r
443 import org.onap.sa.highlandPark.processor.HpEvent;
\r
445 import org.onap.sa.highlandPark.stdlib.filters.FilterIo;
\r
447 import org.onap.sa.highlandPark.stdlib.filters.OneOf;
\r
449 public class ExampleFilteringConsumer
\r
453 public static void main ( String[] args ) throws IOException,
\r
454 InterruptedException
\r
458 // Cambria clients take a set of 1 or more servers to use in round-robin
\r
461 // If a server becomes unreachable, another in the group is used.
\r
464 serverGroup="ueb01hydc.it.att.com,ueb02hydc.it.att.com,ueb03hydc.it.att.com";
\r
468 final String topic = "TEST-TOPIC";
\r
470 // Cambria clients can run in a cooperative group to handle high-volume
\r
473 // Here, we create a random group name, which means this client is not
\r
476 final String consumerGroup = UUID.randomUUID ().toString ();
\r
478 final String consumerId = "0";
\r
480 // Cambria clients can sit in a tight loop on the client side, using a
\r
483 // to wait for messages, and a limit to tell the server the most to send
\r
486 final int longPollMs = 30\*1000;
\r
488 final int limit = -1;
\r
490 // The Cambria server can filter the returned message stream using
\r
493 // Highland Park system. Here, we create a simple filter to test for the
\r
496 // value being one of the Mobility power alarms.
\r
498 final OneOf oneOf = new OneOf ( "AlarmId", kPowerAlarms );
\r
500 // create the consumer
\r
502 final CambriaConsumer cc = CambriaClientFactory.createConsumer (
\r
503 serverGroup, topic,
\r
505 consumerGroup, consumerId, longPollMs, limit, FilterIo.write ( oneOf )
\r
508 // now loop reading messages. Note that cc.fetch() will wait in its HTTP
\r
511 // method for up to 30 seconds (longPollMs) when nothing's available at
\r
520 for ( String msg : cc.fetch () )
\r
524 System.out.println ( "" + (++count) + ": " + msg );
\r
532 private static final String[] kPowerAlarms =
\r
536 "HUB COMMERCIAL POWER FAIL\_FWD",
\r
538 "HUB COMMERCIAL POWER FAIL",
\r
540 "RBS COMMERCIAL POWER FAIL - Fixed\_FWD",
\r
542 "RBS COMMERCIAL POWER FAIL\_FWD",
\r
544 "RBS COMMERCIAL POWER FAIL - No Generator\_FWD",
\r
546 "RBS COMMERCIAL POWER FAIL - Portable\_FWD",
\r
548 "RBS COMMERCIAL POWER FAIL - Shared\_FWD",
\r
550 "RBS COMMERCIAL POWER FAIL - Yes\_FWD",
\r
552 "RBS COMMERCIAL POWER FAIL - YES\_FWD",
\r
554 "RBS COMMERCIAL POWER FAIL - Fixed",
\r
556 "RBS COMMERCIAL POWER FAIL - No Generator",
\r
558 "RBS COMMERCIAL POWER FAIL - Portable",
\r
560 "RBS COMMERCIAL POWER FAIL - Shared",
\r
562 "RBS COMMERCIAL POWER FAIL - YES",
\r
564 "RBS COMMERCIAL POWER FAIL - Yes",
\r
566 "RBS COMMERCIAL POWER FAIL",
\r
568 "HUB COMMERCIAL POWER FAIL - Fixed",
\r
570 "HUB COMMERCIAL POWER FAIL - No Generator",
\r
572 "HUB COMMERCIAL POWER FAIL - Portable",
\r
574 "HUB COMMERCIAL POWER FAIL - Shared",
\r
576 "HUB COMMERCIAL POWER FAIL - Fixed\_FWD",
\r
578 "HUB COMMERCIAL POWER FAIL - No Generator\_FWD",
\r
580 "HUB COMMERCIAL POWER FAIL - Portable\_FWD",
\r
582 "HUB COMMERCIAL POWER FAIL - Shared\_FWD",
\r
592 MR server-side filtering allows a consumer to filter the stream of
\r
593 messages returned from the GET call. The following link provide details
\r
594 of building some of the filter to illustrate Filter Builder. It is not
\r
595 meant to cover and provide examples of every filter
\r