forked from zaratsian/Apache_NiFi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython_ExecuteScript.xml
More file actions
627 lines (620 loc) · 23.8 KB
/
python_ExecuteScript.xml
File metadata and controls
627 lines (620 loc) · 23.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
<?xml version="1.0" ?>
<template encoding-version="1.0">
<description></description>
<groupId>86e85593-0156-1000-de74-34836a4cd39e</groupId>
<name>python_ExecuteScript</name>
<snippet>
<connections>
<id>440fe4d5-0157-1000-0000-000000000000</id>
<parentGroupId>86e85593-0156-1000-0000-000000000000</parentGroupId>
<backPressureDataSizeThreshold>1 GB</backPressureDataSizeThreshold>
<backPressureObjectThreshold>10000</backPressureObjectThreshold>
<destination>
<groupId>86e85593-0156-1000-0000-000000000000</groupId>
<id>44023d4c-0157-1000-0000-000000000000</id>
<type>PROCESSOR</type>
</destination>
<flowFileExpiration>0 sec</flowFileExpiration>
<labelIndex>1</labelIndex>
<name></name>
<selectedRelationships>success</selectedRelationships>
<source>
<groupId>86e85593-0156-1000-0000-000000000000</groupId>
<id>440276ec-0157-1000-0000-000000000000</id>
<type>PROCESSOR</type>
</source>
<zIndex>0</zIndex>
</connections>
<connections>
<id>44cc6dee-0157-1000-0000-000000000000</id>
<parentGroupId>86e85593-0156-1000-0000-000000000000</parentGroupId>
<backPressureDataSizeThreshold>1 GB</backPressureDataSizeThreshold>
<backPressureObjectThreshold>10000</backPressureObjectThreshold>
<bends>
<x>754.280472882269</x>
<y>261.1654684925437</y>
</bends>
<bends>
<x>754.280472882269</x>
<y>311.1654684925437</y>
</bends>
<destination>
<groupId>86e85593-0156-1000-0000-000000000000</groupId>
<id>44023d4c-0157-1000-0000-000000000000</id>
<type>PROCESSOR</type>
</destination>
<flowFileExpiration>0 sec</flowFileExpiration>
<labelIndex>1</labelIndex>
<name></name>
<selectedRelationships>failure</selectedRelationships>
<source>
<groupId>86e85593-0156-1000-0000-000000000000</groupId>
<id>44023d4c-0157-1000-0000-000000000000</id>
<type>PROCESSOR</type>
</source>
<zIndex>0</zIndex>
</connections>
<connections>
<id>4524787f-0157-1000-0000-000000000000</id>
<parentGroupId>86e85593-0156-1000-0000-000000000000</parentGroupId>
<backPressureDataSizeThreshold>1 GB</backPressureDataSizeThreshold>
<backPressureObjectThreshold>10000</backPressureObjectThreshold>
<destination>
<groupId>86e85593-0156-1000-0000-000000000000</groupId>
<id>45240b89-0157-1000-0000-000000000000</id>
<type>PROCESSOR</type>
</destination>
<flowFileExpiration>0 sec</flowFileExpiration>
<labelIndex>1</labelIndex>
<name></name>
<selectedRelationships>success</selectedRelationships>
<source>
<groupId>86e85593-0156-1000-0000-000000000000</groupId>
<id>44023d4c-0157-1000-0000-000000000000</id>
<type>PROCESSOR</type>
</source>
<zIndex>0</zIndex>
</connections>
<connections>
<id>459336f1-0157-1000-0000-000000000000</id>
<parentGroupId>86e85593-0156-1000-0000-000000000000</parentGroupId>
<backPressureDataSizeThreshold>1 GB</backPressureDataSizeThreshold>
<backPressureObjectThreshold>10000</backPressureObjectThreshold>
<bends>
<x>1129.8499554404893</x>
<y>490.89508311281577</y>
</bends>
<bends>
<x>1129.8499554404893</x>
<y>540.8950831128158</y>
</bends>
<destination>
<groupId>86e85593-0156-1000-0000-000000000000</groupId>
<id>45240b89-0157-1000-0000-000000000000</id>
<type>PROCESSOR</type>
</destination>
<flowFileExpiration>0 sec</flowFileExpiration>
<labelIndex>1</labelIndex>
<name></name>
<selectedRelationships>failure</selectedRelationships>
<source>
<groupId>86e85593-0156-1000-0000-000000000000</groupId>
<id>45240b89-0157-1000-0000-000000000000</id>
<type>PROCESSOR</type>
</source>
<zIndex>0</zIndex>
</connections>
<processors>
<id>44023d4c-0157-1000-0000-000000000000</id>
<parentGroupId>86e85593-0156-1000-0000-000000000000</parentGroupId>
<position>
<x>299.2804728822689</x>
<y>221.1654684925437</y>
</position>
<config>
<bulletinLevel>WARN</bulletinLevel>
<comments></comments>
<concurrentlySchedulableTaskCount>1</concurrentlySchedulableTaskCount>
<descriptors>
<entry>
<key>Script Engine</key>
<value>
<allowableValues>
<displayName>ECMAScript</displayName>
<value>ECMAScript</value>
</allowableValues>
<allowableValues>
<displayName>Groovy</displayName>
<value>Groovy</value>
</allowableValues>
<allowableValues>
<displayName>lua</displayName>
<value>lua</value>
</allowableValues>
<allowableValues>
<displayName>python</displayName>
<value>python</value>
</allowableValues>
<allowableValues>
<displayName>ruby</displayName>
<value>ruby</value>
</allowableValues>
<defaultValue>ECMAScript</defaultValue>
<description>The engine to execute scripts</description>
<displayName>Script Engine</displayName>
<dynamic>false</dynamic>
<name>Script Engine</name>
<required>true</required>
<sensitive>false</sensitive>
<supportsEl>false</supportsEl>
</value>
</entry>
<entry>
<key>Script File</key>
<value>
<description>Path to script file to execute. Only one of Script File or Script Body may be used</description>
<displayName>Script File</displayName>
<dynamic>false</dynamic>
<name>Script File</name>
<required>false</required>
<sensitive>false</sensitive>
<supportsEl>true</supportsEl>
</value>
</entry>
<entry>
<key>Script Body</key>
<value>
<description>Body of script to execute. Only one of Script File or Script Body may be used</description>
<displayName>Script Body</displayName>
<dynamic>false</dynamic>
<name>Script Body</name>
<required>false</required>
<sensitive>false</sensitive>
<supportsEl>false</supportsEl>
</value>
</entry>
<entry>
<key>Module Directory</key>
<value>
<description>Comma-separated list of paths to files and/or directories which contain modules required by the script.</description>
<displayName>Module Directory</displayName>
<dynamic>false</dynamic>
<name>Module Directory</name>
<required>false</required>
<sensitive>false</sensitive>
<supportsEl>false</supportsEl>
</value>
</entry>
</descriptors>
<lossTolerant>false</lossTolerant>
<penaltyDuration>30 sec</penaltyDuration>
<properties>
<entry>
<key>Script Engine</key>
<value>python</value>
</entry>
<entry>
<key>Script File</key>
</entry>
<entry>
<key>Script Body</key>
<value>import json
import java.io
from org.apache.commons.io import IOUtils
# Get flowFile Session
flowFile = session.get()
# Open data.json file and parse json values
filename = flowFile.getAttribute('filename')
filepath = flowFile.getAttribute('absolute.path')
data = json.loads(open(filepath + filename, "r").read())
data_value1 = data["record"]["value1"]
# Calculate arbitrary new value within python
new_value = data_value1 * 100
# Add/Put values to flowFile as new attributes
if (flowFile != None):
flowFile = session.putAttribute(flowFile, "from_python_string", "python string example")
flowFile = session.putAttribute(flowFile, "from_python_number", str(new_value))
session.transfer(flowFile, REL_SUCCESS)
session.commit()
#ZEND</value>
</entry>
<entry>
<key>Module Directory</key>
</entry>
</properties>
<runDurationMillis>0</runDurationMillis>
<schedulingPeriod>0 sec</schedulingPeriod>
<schedulingStrategy>TIMER_DRIVEN</schedulingStrategy>
<yieldDuration>1 sec</yieldDuration>
</config>
<name>ExecuteScript</name>
<relationships>
<autoTerminate>false</autoTerminate>
<name>failure</name>
</relationships>
<relationships>
<autoTerminate>false</autoTerminate>
<name>success</name>
</relationships>
<style></style>
<type>org.apache.nifi.processors.script.ExecuteScript</type>
</processors>
<processors>
<id>440276ec-0157-1000-0000-000000000000</id>
<parentGroupId>86e85593-0156-1000-0000-000000000000</parentGroupId>
<position>
<x>0.0</x>
<y>0.0</y>
</position>
<config>
<bulletinLevel>WARN</bulletinLevel>
<comments></comments>
<concurrentlySchedulableTaskCount>1</concurrentlySchedulableTaskCount>
<descriptors>
<entry>
<key>Input Directory</key>
<value>
<description>The input directory from which to pull files</description>
<displayName>Input Directory</displayName>
<dynamic>false</dynamic>
<name>Input Directory</name>
<required>true</required>
<sensitive>false</sensitive>
<supportsEl>true</supportsEl>
</value>
</entry>
<entry>
<key>File Filter</key>
<value>
<defaultValue>[^\.].*</defaultValue>
<description>Only files whose names match the given regular expression will be picked up</description>
<displayName>File Filter</displayName>
<dynamic>false</dynamic>
<name>File Filter</name>
<required>true</required>
<sensitive>false</sensitive>
<supportsEl>false</supportsEl>
</value>
</entry>
<entry>
<key>Path Filter</key>
<value>
<description>When Recurse Subdirectories is true, then only subdirectories whose path matches the given regular expression will be scanned</description>
<displayName>Path Filter</displayName>
<dynamic>false</dynamic>
<name>Path Filter</name>
<required>false</required>
<sensitive>false</sensitive>
<supportsEl>false</supportsEl>
</value>
</entry>
<entry>
<key>Batch Size</key>
<value>
<defaultValue>10</defaultValue>
<description>The maximum number of files to pull in each iteration</description>
<displayName>Batch Size</displayName>
<dynamic>false</dynamic>
<name>Batch Size</name>
<required>true</required>
<sensitive>false</sensitive>
<supportsEl>false</supportsEl>
</value>
</entry>
<entry>
<key>Keep Source File</key>
<value>
<allowableValues>
<displayName>true</displayName>
<value>true</value>
</allowableValues>
<allowableValues>
<displayName>false</displayName>
<value>false</value>
</allowableValues>
<defaultValue>false</defaultValue>
<description>If true, the file is not deleted after it has been copied to the Content Repository; this causes the file to be picked up continually and is useful for testing purposes. If not keeping original NiFi will need write permissions on the directory it is pulling from otherwise it will ignore the file.</description>
<displayName>Keep Source File</displayName>
<dynamic>false</dynamic>
<name>Keep Source File</name>
<required>true</required>
<sensitive>false</sensitive>
<supportsEl>false</supportsEl>
</value>
</entry>
<entry>
<key>Recurse Subdirectories</key>
<value>
<allowableValues>
<displayName>true</displayName>
<value>true</value>
</allowableValues>
<allowableValues>
<displayName>false</displayName>
<value>false</value>
</allowableValues>
<defaultValue>true</defaultValue>
<description>Indicates whether or not to pull files from subdirectories</description>
<displayName>Recurse Subdirectories</displayName>
<dynamic>false</dynamic>
<name>Recurse Subdirectories</name>
<required>true</required>
<sensitive>false</sensitive>
<supportsEl>false</supportsEl>
</value>
</entry>
<entry>
<key>Polling Interval</key>
<value>
<defaultValue>0 sec</defaultValue>
<description>Indicates how long to wait before performing a directory listing</description>
<displayName>Polling Interval</displayName>
<dynamic>false</dynamic>
<name>Polling Interval</name>
<required>true</required>
<sensitive>false</sensitive>
<supportsEl>false</supportsEl>
</value>
</entry>
<entry>
<key>Ignore Hidden Files</key>
<value>
<allowableValues>
<displayName>true</displayName>
<value>true</value>
</allowableValues>
<allowableValues>
<displayName>false</displayName>
<value>false</value>
</allowableValues>
<defaultValue>true</defaultValue>
<description>Indicates whether or not hidden files should be ignored</description>
<displayName>Ignore Hidden Files</displayName>
<dynamic>false</dynamic>
<name>Ignore Hidden Files</name>
<required>true</required>
<sensitive>false</sensitive>
<supportsEl>false</supportsEl>
</value>
</entry>
<entry>
<key>Minimum File Age</key>
<value>
<defaultValue>0 sec</defaultValue>
<description>The minimum age that a file must be in order to be pulled; any file younger than this amount of time (according to last modification date) will be ignored</description>
<displayName>Minimum File Age</displayName>
<dynamic>false</dynamic>
<name>Minimum File Age</name>
<required>true</required>
<sensitive>false</sensitive>
<supportsEl>false</supportsEl>
</value>
</entry>
<entry>
<key>Maximum File Age</key>
<value>
<description>The maximum age that a file must be in order to be pulled; any file older than this amount of time (according to last modification date) will be ignored</description>
<displayName>Maximum File Age</displayName>
<dynamic>false</dynamic>
<name>Maximum File Age</name>
<required>false</required>
<sensitive>false</sensitive>
<supportsEl>false</supportsEl>
</value>
</entry>
<entry>
<key>Minimum File Size</key>
<value>
<defaultValue>0 B</defaultValue>
<description>The minimum size that a file must be in order to be pulled</description>
<displayName>Minimum File Size</displayName>
<dynamic>false</dynamic>
<name>Minimum File Size</name>
<required>true</required>
<sensitive>false</sensitive>
<supportsEl>false</supportsEl>
</value>
</entry>
<entry>
<key>Maximum File Size</key>
<value>
<description>The maximum size that a file can be in order to be pulled</description>
<displayName>Maximum File Size</displayName>
<dynamic>false</dynamic>
<name>Maximum File Size</name>
<required>false</required>
<sensitive>false</sensitive>
<supportsEl>false</supportsEl>
</value>
</entry>
</descriptors>
<lossTolerant>false</lossTolerant>
<penaltyDuration>30 sec</penaltyDuration>
<properties>
<entry>
<key>Input Directory</key>
<value>/tmp</value>
</entry>
<entry>
<key>File Filter</key>
<value>data\.json</value>
</entry>
<entry>
<key>Path Filter</key>
</entry>
<entry>
<key>Batch Size</key>
<value>10</value>
</entry>
<entry>
<key>Keep Source File</key>
<value>true</value>
</entry>
<entry>
<key>Recurse Subdirectories</key>
<value>false</value>
</entry>
<entry>
<key>Polling Interval</key>
<value>0 sec</value>
</entry>
<entry>
<key>Ignore Hidden Files</key>
<value>true</value>
</entry>
<entry>
<key>Minimum File Age</key>
<value>0 sec</value>
</entry>
<entry>
<key>Maximum File Age</key>
</entry>
<entry>
<key>Minimum File Size</key>
<value>0 B</value>
</entry>
<entry>
<key>Maximum File Size</key>
</entry>
</properties>
<runDurationMillis>0</runDurationMillis>
<schedulingPeriod>10 sec</schedulingPeriod>
<schedulingStrategy>TIMER_DRIVEN</schedulingStrategy>
<yieldDuration>1 sec</yieldDuration>
</config>
<name>GetFile</name>
<relationships>
<autoTerminate>false</autoTerminate>
<name>success</name>
</relationships>
<style></style>
<type>org.apache.nifi.processors.standard.GetFile</type>
</processors>
<processors>
<id>45240b89-0157-1000-0000-000000000000</id>
<parentGroupId>86e85593-0156-1000-0000-000000000000</parentGroupId>
<position>
<x>674.8499554404895</x>
<y>450.89508311281577</y>
</position>
<config>
<bulletinLevel>WARN</bulletinLevel>
<comments></comments>
<concurrentlySchedulableTaskCount>1</concurrentlySchedulableTaskCount>
<descriptors>
<entry>
<key>Attributes List</key>
<value>
<description>Comma separated list of attributes to be included in the resulting JSON. If this value is left empty then all existing Attributes will be included. This list of attributes is case sensitive. If an attribute specified in the list is not found it will be be emitted to the resulting JSON with an empty string or NULL value.</description>
<displayName>Attributes List</displayName>
<dynamic>false</dynamic>
<name>Attributes List</name>
<required>false</required>
<sensitive>false</sensitive>
<supportsEl>false</supportsEl>
</value>
</entry>
<entry>
<key>Destination</key>
<value>
<allowableValues>
<displayName>flowfile-attribute</displayName>
<value>flowfile-attribute</value>
</allowableValues>
<allowableValues>
<displayName>flowfile-content</displayName>
<value>flowfile-content</value>
</allowableValues>
<defaultValue>flowfile-attribute</defaultValue>
<description>Control if JSON value is written as a new flowfile attribute 'JSONAttributes' or written in the flowfile content. Writing to flowfile content will overwrite any existing flowfile content.</description>
<displayName>Destination</displayName>
<dynamic>false</dynamic>
<name>Destination</name>
<required>true</required>
<sensitive>false</sensitive>
<supportsEl>false</supportsEl>
</value>
</entry>
<entry>
<key>Include Core Attributes</key>
<value>
<allowableValues>
<displayName>true</displayName>
<value>true</value>
</allowableValues>
<allowableValues>
<displayName>false</displayName>
<value>false</value>
</allowableValues>
<defaultValue>true</defaultValue>
<description>Determines if the FlowFile org.apache.nifi.flowfile.attributes.CoreAttributes which are contained in every FlowFile should be included in the final JSON value generated.</description>
<displayName>Include Core Attributes</displayName>
<dynamic>false</dynamic>
<name>Include Core Attributes</name>
<required>true</required>
<sensitive>false</sensitive>
<supportsEl>false</supportsEl>
</value>
</entry>
<entry>
<key>Null Value</key>
<value>
<allowableValues>
<displayName>true</displayName>
<value>true</value>
</allowableValues>
<allowableValues>
<displayName>false</displayName>
<value>false</value>
</allowableValues>
<defaultValue>false</defaultValue>
<description>If true a non existing or empty attribute will be NULL in the resulting JSON. If false an empty string will be placed in the JSON</description>
<displayName>Null Value</displayName>
<dynamic>false</dynamic>
<name>Null Value</name>
<required>true</required>
<sensitive>false</sensitive>
<supportsEl>false</supportsEl>
</value>
</entry>
</descriptors>
<lossTolerant>false</lossTolerant>
<penaltyDuration>30 sec</penaltyDuration>
<properties>
<entry>
<key>Attributes List</key>
<value>filename, from_python_number, from_python_string</value>
</entry>
<entry>
<key>Destination</key>
<value>flowfile-attribute</value>
</entry>
<entry>
<key>Include Core Attributes</key>
<value>true</value>
</entry>
<entry>
<key>Null Value</key>
<value>false</value>
</entry>
</properties>
<runDurationMillis>0</runDurationMillis>
<schedulingPeriod>0 sec</schedulingPeriod>
<schedulingStrategy>TIMER_DRIVEN</schedulingStrategy>
<yieldDuration>1 sec</yieldDuration>
</config>
<name>AttributesToJSON</name>
<relationships>
<autoTerminate>false</autoTerminate>
<name>failure</name>
</relationships>
<relationships>
<autoTerminate>true</autoTerminate>
<name>success</name>
</relationships>
<style></style>
<type>org.apache.nifi.processors.standard.AttributesToJSON</type>
</processors>
</snippet>
<timestamp>09/19/2016 23:35:27 EDT</timestamp>
</template>