├── .gitignore ├── .travis.yml ├── LICENSE ├── NOTICE ├── README.md ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── src ├── main └── groovy │ └── nifi │ └── client │ ├── NiFi.groovy │ ├── Processor.groovy │ ├── Processors.groovy │ ├── SystemDiagnostics.groovy │ ├── Template.groovy │ ├── Templates.groovy │ ├── Util.groovy │ └── controller │ ├── About.groovy │ ├── Banners.groovy │ ├── BulletinBoard.groovy │ ├── Config.groovy │ ├── Controller.groovy │ ├── ControllerServiceTypes.groovy │ ├── History.groovy │ ├── Identity.groovy │ ├── Prioritizers.groovy │ ├── ProcessGroup.groovy │ ├── ProcessGroups.groovy │ ├── ProcessorTypes.groovy │ ├── Provenance.groovy │ ├── ProvenanceEvent.groovy │ ├── ReportingTaskTypes.groovy │ └── Status.groovy └── test └── groovy └── nifi └── client └── NiFiTest.groovy /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | 3 | .gradle/ 4 | build/ 5 | 6 | .idea/ 7 | *.ipr 8 | *.iws 9 | *.iml 10 | 11 | # Mobile Tools for Java (J2ME) 12 | .mtj.tmp/ 13 | 14 | # Package Files # 15 | *.jar 16 | *.war 17 | *.ear 18 | 19 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 20 | hs_err_pid* 21 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: groovy 2 | 3 | before_install: 4 | - chmod +x gradlew -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | 204 | This product has a binary dependency on HTTPBuilder, which is licensed under Apache Software License version 2 (ASLv2) 205 | 206 | HTTPBuilder is copyright 2009-2011 Thomas Nichols except where otherwise noted. 207 | 208 | This project is licensed under the Apache License Version 2.0 except where 209 | otherwise noted in the source files. 210 | 211 | You are receiving this code free of charge, which represents many hours of 212 | effort from other individuals and corporations. As a responsible member 213 | of the community, you are encouraged (but not required) to donate any 214 | enhancements or improvements back to the community under a similar open 215 | source license. Thank you. -TMN -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | nifi-client 2 | Copyright 2015- Matthew Burgess 3 | 4 | This product includes software developed at 5 | The Apache Software Foundation (http://www.apache.org/). 6 | 7 | The following binary dependencies are used under an Apache Software License v2: 8 | 9 | (ASLv2) Groovy ( 10 | 11 | (ASLv2) HTTPBuilder 12 | 13 | Please see LICENSE for additional copyright and licensing information. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | nifi-client 2 | ------------------------------------ 3 | nifi-client is a JVM client library for interacting with an Apache NiFi instance. It includes a Gradle task that 4 | provides an interactive Groovy Shell with the nifi-client library already loaded. See the Usage section for more details. 5 | 6 | 7 | Project Structure 8 | ------------------------------------ 9 | 10 | nifi-client is a basic Groovy application (originally created from a lazybones groovy-app template. There is a 11 | standard Maven/Gradle project structure for source code and tests. 12 | 13 | 14 | Usage 15 | ------------------------------------ 16 | 17 | Start the shell (use 'gradlew' rather than 'gradle' if you do not have Gradle installed): 18 | 19 | gradle —no-daemon shell 20 | 21 | 22 | Then to connect to your instance: 23 | 24 | nifi = NiFi.bind('http://127.0.0.1:8080') 25 | 26 | 27 | To get a map of templates (the map is name -> properties): 28 | 29 | nifi.templates 30 | 31 | 32 | To upload a template from a file: 33 | 34 | nifi.templates << '/Users/mburgess/datasets/GetUserData.xml’ 35 | 36 | 37 | To instantiate a template, fetch by name and call instantiate: 38 | 39 | nifi.templates.'GetUserData'.instantiate() 40 | 41 | 42 | To export a template: 43 | 44 | nifi.templates.’GetUserData’ >> ‘/path/to/export.xml' 45 | 46 | 47 | To delete a template: 48 | 49 | nifi.templates.'GetUserData’.delete() 50 | 51 | 52 | To get a map of processors (the map is name -> properties): 53 | 54 | nifi.processors 55 | 56 | 57 | To get a list of processor names: 58 | 59 | nifi.processors*.key 60 | 61 | 62 | To start a processor, fetch by name and call start: 63 | 64 | nifi.processors.'Fetch User Data'.start() 65 | 66 | 67 | The above also works for stop(), enable(), and disable() 68 | 69 | 70 | To get the current state of a processor: 71 | 72 | nifi.processors.'Fetch User Data'.state 73 | 74 | 75 | To get the history: 76 | 77 | nifi.controller.history 78 | 79 | 80 | To get the last 10 provenance events: 81 | 82 | nifi.controller.provenance.events(maxResults: 10) 83 | 84 | 85 | To get the lineage for the latest provenance event: 86 | 87 | nifi.controller.provenance.events(maxResults: 1)`[0`].lineage() 88 | 89 | 90 | To get a process group called TestPG on the main canvas: 91 | 92 | nifi.controller.root.groups.'TestPG' 93 | 94 | 95 | To list the process groups under another process group (the parent named TestPG): 96 | 97 | nifi.controller.root.groups.'TestPG'.groups.keySet() 98 | 99 | 100 | 101 | This repo is very much a work in progress, and all contributions, comments, and suggestions are welcome! 102 | 103 | 104 | License 105 | ------------------------------------ 106 | 107 | nifi-client is copyright 2015- Matthew Burgess except where otherwise noted. 108 | 109 | This project is licensed under the Apache License Version 2.0 except where 110 | otherwise noted in the source files. 111 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with 5 | * the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | ******************************************************************************/ 16 | plugins { 17 | id 'com.jfrog.bintray' version '1.4' 18 | id 'java' 19 | id 'maven' 20 | id 'maven-publish' 21 | id 'signing' 22 | id 'groovy' 23 | id 'com.github.johnrengelman.shadow' version '1.2.3' 24 | } 25 | 26 | version = '0.3' 27 | description = "A Groovy/Java client for interacting with an Apache NiFi instance" 28 | group = 'mattyb149' 29 | status = 'RELEASE' 30 | project.ext.apiKey = System.getenv('BINTRAY_API_KEY') ?: System.getProperty('BINTRAY_API_KEY') 31 | 32 | repositories { 33 | mavenCentral() 34 | jcenter() 35 | } 36 | 37 | 38 | configurations { 39 | shell 40 | } 41 | 42 | dependencies { 43 | compile 'org.codehaus.groovy:groovy-all:2.4.5' 44 | compile 'org.codehaus.groovy.modules.http-builder:http-builder:0.7.1' 45 | compile 'org.apache.httpcomponents:httpmime:4.2.1' 46 | 47 | shell("jline:jline:2.11") { 48 | exclude(group: 'junit', module: 'junit') 49 | } 50 | shell('commons-cli:commons-cli:1.2') 51 | 52 | testCompile 'org.spockframework:spock-core:0.7-groovy-2.0' 53 | 54 | shell 'org.codehaus.groovy:groovy-all:2.4.5' 55 | shell 'org.codehaus.groovy.modules.http-builder:http-builder:0.7.1' 56 | shell 'org.apache.httpcomponents:httpmime:4.2.1' 57 | } 58 | 59 | task(shell, dependsOn: 'classes') << { 60 | def classpath = sourceSets.main.runtimeClasspath + configurations.shell 61 | def command = [ 62 | System.getProperty('JAVA_HOME') ? "${System.getProperty('JAVA_HOME') / bin / java}" : 'java', 63 | '-cp', classpath.collect().join(':'), 64 | 'org.codehaus.groovy.tools.shell.Main', 65 | '--color', 66 | '--terminal', 'unix', 67 | '-Dgroovysh.prompt=nifi-shell', '-e', '"import nifi.client.*"' 68 | ] 69 | def proc = new ProcessBuilder(command) 70 | .redirectOutput(ProcessBuilder.Redirect.INHERIT) 71 | .redirectInput(ProcessBuilder.Redirect.INHERIT) 72 | .redirectError(ProcessBuilder.Redirect.INHERIT) 73 | .start() 74 | proc.waitFor() 75 | } 76 | 77 | task('shell-debug', dependsOn: 'classes') << { 78 | def classpath = sourceSets.main.runtimeClasspath + configurations.shell 79 | def command = [ 80 | System.getProperty('JAVA_HOME') ? "${System.getProperty('JAVA_HOME') / bin / java}" : 'java', 81 | '-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=6006', 82 | '-cp', classpath.collect().join(':'), 83 | 'org.codehaus.groovy.tools.shell.Main', 84 | '--color', 85 | '--terminal', 'unix', 86 | '-Dgroovysh.prompt=nifi-shell', '-e', '"import nifi.client.*"' 87 | ] 88 | def proc = new ProcessBuilder(command) 89 | .redirectOutput(ProcessBuilder.Redirect.INHERIT) 90 | .redirectInput(ProcessBuilder.Redirect.INHERIT) 91 | .redirectError(ProcessBuilder.Redirect.INHERIT) 92 | .start() 93 | proc.waitFor() 94 | } 95 | 96 | 97 | // custom tasks for creating source/javadoc jars 98 | task sourcesJar(type: Jar, dependsOn: classes) { 99 | classifier = 'sources' 100 | from sourceSets.main.allSource 101 | } 102 | 103 | task javadocJar(type: Jar, dependsOn: javadoc) { 104 | classifier = 'javadoc' 105 | from javadoc.destinationDir 106 | } 107 | 108 | artifacts { 109 | archives sourcesJar, javadocJar 110 | } 111 | 112 | 113 | publishing { 114 | publications { 115 | mavenJava(MavenPublication) { 116 | if (plugins.hasPlugin('war')) { 117 | from components.web 118 | } else { 119 | from components.java 120 | } 121 | 122 | artifact sourcesJar 123 | artifact javadocJar 124 | artifact shadowJar 125 | } 126 | } 127 | } 128 | 129 | 130 | bintray { 131 | user = System.getProperty('BINTRAY_USER') ?: 'mattyb149' 132 | key = project.ext.apiKey 133 | //configurations = ['default'] 134 | publications = ['mavenJava'] 135 | filesSpec { 136 | from 'files' 137 | into 'standalone_files/level1' 138 | rename '(.+)\\.(.+)', '$1-suffix.$2' 139 | } 140 | 141 | dryRun = false 142 | pkg { 143 | repo = 'maven' 144 | userOrg = group 145 | name = project.name 146 | desc = project.description 147 | websiteUrl = 'https://github.com/mattyb149/nifi-client' 148 | issueTrackerUrl = 'https://github.com/mattyb149/nifi-client/issues' 149 | vcsUrl = 'https://github.com/mattyb149/nifi-client.git' 150 | licenses = ['Apache-2.0'] 151 | labels = ['apache', 'nifi', 'groovy'] 152 | attributes = ['plat': ['linux', 'osx']] 153 | publicDownloadNumbers = true 154 | version { 155 | vcsTag = project.version 156 | } 157 | } 158 | } 159 | 160 | task wrapper(type: Wrapper) { 161 | gradleVersion = "2.12" 162 | } 163 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattyb149/nifi-client/52343d2fdd1f017a1a8f951b36be85f03ed7709e/gradle.properties -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattyb149/nifi-client/52343d2fdd1f017a1a8f951b36be85f03ed7709e/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Mar 18 09:44:39 EDT 2016 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.12-bin.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /src/main/groovy/nifi/client/NiFi.groovy: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with 5 | * the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | ******************************************************************************/ 16 | package nifi.client 17 | 18 | import groovy.json.JsonSlurper 19 | import groovyx.net.http.HTTPBuilder 20 | import nifi.client.controller.Controller 21 | 22 | /** 23 | * Created by mburgess on 12/30/15. 24 | */ 25 | class NiFi { 26 | String urlString 27 | Processors processors 28 | Templates templates 29 | Controller controller 30 | SystemDiagnostics system 31 | def http 32 | 33 | private JsonSlurper slurper = new JsonSlurper() 34 | 35 | private NiFi(String url) { 36 | this.urlString = url 37 | this.http = this.http = new HTTPBuilder(url) 38 | this.processors = new Processors(this, 'root') 39 | this.templates = new Templates(this) 40 | this.controller = new Controller(this) 41 | this.system = new SystemDiagnostics(this) 42 | } 43 | 44 | static NiFi bind(URL url) { 45 | return new NiFi(url.toString()) 46 | } 47 | 48 | static NiFi bind(String url) { 49 | return new NiFi(url) 50 | } 51 | 52 | long getCurrentVersion() { 53 | return slurper.parseText("${urlString}/nifi-api/controller/revision".toURL().text)?.revision?.version ?: -1 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/main/groovy/nifi/client/Processor.groovy: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with 5 | * the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | ******************************************************************************/ 16 | package nifi.client 17 | 18 | import groovy.json.JsonSlurper 19 | import groovyx.net.http.ContentType 20 | 21 | import static groovyx.net.http.Method.PUT 22 | 23 | /** 24 | * Created by mburgess on 12/30/15. 25 | */ 26 | class Processor implements Map { 27 | NiFi nifi 28 | private final JsonSlurper slurper = new JsonSlurper() 29 | protected final Map propertyMap = [:] 30 | protected Map configProperties; // This is exposed as "properties" on the Processor object 31 | 32 | protected Processor(NiFi nifi, Map propMap) { 33 | super() 34 | this.nifi = nifi 35 | this.propertyMap.putAll(propMap) 36 | this.configProperties = new LinkedHashMap(propMap.config.properties as Map) { 37 | @Override 38 | String put(String key, String value) { 39 | super.put(key, value) 40 | updateState([config: [properties: this]]) 41 | value 42 | } 43 | 44 | /*@Override 45 | void putAll(Map m) { 46 | if (m) { 47 | m.each { k, v -> 48 | super.put(k, v) 49 | } 50 | updateState([config: [properties: this]]) 51 | } 52 | }*/ 53 | } 54 | } 55 | 56 | @Override 57 | int size() { 58 | return propertyMap.size() 59 | } 60 | 61 | @Override 62 | boolean isEmpty() { 63 | return propertyMap.isEmpty() 64 | } 65 | 66 | @Override 67 | boolean containsKey(Object key) { 68 | return propertyMap.containsKey(key) 69 | } 70 | 71 | @Override 72 | boolean containsValue(Object value) { 73 | return propertyMap.containsValue(value) 74 | } 75 | 76 | @Override 77 | Object get(Object key) { 78 | // Need to check for our own members before delegating 79 | if ("properties".equals(key)) { 80 | return this.configProperties 81 | } 82 | return propertyMap.get(key) 83 | } 84 | 85 | @Override 86 | Object put(String key, Object value) { 87 | throw new UnsupportedOperationException('Processor property Map is immutable (for now)') 88 | } 89 | 90 | @Override 91 | Object remove(Object key) { 92 | throw new UnsupportedOperationException('Processor property Map is immutable (for now)') 93 | } 94 | 95 | @Override 96 | void putAll(Map m) { 97 | throw new UnsupportedOperationException('Processor property Map is immutable (for now)') 98 | } 99 | 100 | @Override 101 | void clear() { 102 | throw new UnsupportedOperationException('Processor property Map is immutable (for now)') 103 | } 104 | 105 | @Override 106 | Set keySet() { 107 | return propertyMap.keySet() 108 | } 109 | 110 | @Override 111 | Collection values() { 112 | return propertyMap.values() 113 | } 114 | 115 | @Override 116 | Set> entrySet() { 117 | return propertyMap.entrySet() 118 | } 119 | 120 | def set(Map props) { 121 | // Set the properties on the Processor and update it 122 | propertyMap.putAll(props) 123 | updateState(props) 124 | } 125 | 126 | def start() { 127 | updateState(state: 'RUNNING') 128 | } 129 | 130 | def stop() { 131 | updateState(state: 'STOPPED') 132 | } 133 | 134 | def enable() { 135 | updateState(state: 'STOPPED') 136 | } 137 | 138 | def disable() { 139 | updateState(state: 'DISABLED') 140 | } 141 | 142 | def updateState(Map propMap) { 143 | def parentGroupId = propertyMap.parentGroupId 144 | def id = propertyMap.id 145 | def currentVersion = nifi.currentVersion 146 | 147 | try { 148 | 149 | nifi.http.request(PUT) { request -> 150 | uri.path = "/nifi-api/controller/process-groups/${parentGroupId}/processors/${id}" 151 | def putBody = ([revision: [version: currentVersion], processor: ([id: id] << propMap)]) 152 | println putBody 153 | 154 | send ContentType.JSON, putBody 155 | 156 | response.'404' = { throw new Exception("Couldn't process start()") } 157 | 158 | //response.'409' = { resp, xml -> System.out << xml } 159 | 160 | response.success = { resp, xml -> 161 | //println "Got code ${resp.statusLine.statusCode}" 162 | switch (resp.statusLine.statusCode) { 163 | case 200: 164 | // TODO overwrite properties 165 | break 166 | case 201: 167 | break 168 | 169 | default: 170 | // Something went wrong, throw an exception 171 | throw new Exception("Error updating state with $propMap") 172 | break 173 | } 174 | 175 | } 176 | } 177 | propMap 178 | } 179 | catch (e) { 180 | e.printStackTrace(System.err) 181 | } 182 | } 183 | 184 | def history() { 185 | def id = propertyMap.id 186 | slurper.parseText("${nifi.urlString}/nifi-api/controller/history/processors/${id}".toURL().text)?.componentHistory 187 | } 188 | } 189 | -------------------------------------------------------------------------------- /src/main/groovy/nifi/client/Processors.groovy: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with 5 | * the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | ******************************************************************************/ 16 | package nifi.client 17 | 18 | import groovy.json.JsonSlurper 19 | 20 | /** 21 | * Created by mburgess on 12/30/15. 22 | */ 23 | class Processors implements Map { 24 | NiFi nifi 25 | private final JsonSlurper slurper = new JsonSlurper() 26 | private String processGroup 27 | protected final Map processorIdMap = [:] 28 | 29 | Processors(NiFi nifi, String pGroup) { 30 | super() 31 | this.nifi = nifi 32 | this.processGroup = pGroup ?: 'root' 33 | } 34 | 35 | @Override 36 | int size() { 37 | reload() 38 | return processorIdMap.size() 39 | } 40 | 41 | @Override 42 | boolean isEmpty() { 43 | reload() 44 | return processorIdMap.isEmpty() 45 | } 46 | 47 | @Override 48 | boolean containsKey(Object key) { 49 | reload() 50 | return processorIdMap.containsKey(key) 51 | } 52 | 53 | @Override 54 | boolean containsValue(Object value) { 55 | reload() 56 | return processorIdMap.containsValue(value) 57 | } 58 | 59 | @Override 60 | Processor get(Object key) { 61 | reload() 62 | return processorIdMap.get(key) 63 | } 64 | 65 | @Override 66 | Processor put(String key, Processor value) { 67 | throw new UnsupportedOperationException('Processor Map is immutable (for now)') 68 | } 69 | 70 | @Override 71 | Processor remove(Object key) { 72 | throw new UnsupportedOperationException('Processor Map is immutable (for now)') 73 | } 74 | 75 | @Override 76 | void putAll(Map m) { 77 | throw new UnsupportedOperationException('Processor Map is immutable (for now)') 78 | } 79 | 80 | @Override 81 | void clear() { 82 | throw new UnsupportedOperationException('Processor Map is immutable (for now)') 83 | } 84 | 85 | @Override 86 | Set keySet() { 87 | reload() 88 | processorIdMap.keySet() 89 | } 90 | 91 | @Override 92 | Collection values() { 93 | reload() 94 | processorIdMap.values() 95 | } 96 | 97 | @Override 98 | Set> entrySet() { 99 | reload() 100 | processorIdMap.entrySet() 101 | } 102 | 103 | Collection findByType(String type) { 104 | values().findAll { Util.getSimpleName(it.type) == type } 105 | } 106 | 107 | Collection types() { 108 | values().collect { Util.getSimpleName(it.type) }.unique() 109 | } 110 | 111 | def reload() { 112 | synchronized (this.processorIdMap) { 113 | def procs = slurper.parseText("${nifi.urlString}/nifi-api/controller/process-groups/${processGroup ?: 'root'}/processors".toURL().text).processors 114 | def map = this.processorIdMap 115 | // TODO clear the map? 116 | def n = this.nifi 117 | procs.each { p -> 118 | map.put(p.name, new Processor(n, p)) 119 | } 120 | } 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /src/main/groovy/nifi/client/SystemDiagnostics.groovy: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with 5 | * the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | ******************************************************************************/ 16 | package nifi.client 17 | 18 | import groovy.json.JsonSlurper 19 | 20 | /** 21 | * Created by mburgess on 12/30/15. 22 | */ 23 | class SystemDiagnostics implements Map { 24 | NiFi nifi 25 | private final JsonSlurper slurper = new JsonSlurper() 26 | protected final Map status = [:] 27 | private clientId 28 | 29 | protected SystemDiagnostics(NiFi nifi) { 30 | super() 31 | this.nifi = nifi 32 | } 33 | 34 | @Override 35 | int size() { 36 | reload() 37 | return status.size() 38 | } 39 | 40 | @Override 41 | boolean isEmpty() { 42 | reload() 43 | return status.isEmpty() 44 | } 45 | 46 | @Override 47 | boolean containsKey(Object key) { 48 | reload() 49 | return status.containsKey(key) 50 | } 51 | 52 | @Override 53 | boolean containsValue(Object value) { 54 | reload() 55 | return status.containsValue(value) 56 | } 57 | 58 | @Override 59 | Object get(Object key) { 60 | reload() 61 | return status.get(key) 62 | } 63 | 64 | @Override 65 | Object put(String key, Object value) { 66 | throw new UnsupportedOperationException('Processor Map is immutable (for now)') 67 | } 68 | 69 | @Override 70 | Object remove(Object key) { 71 | throw new UnsupportedOperationException('Processor Map is immutable (for now)') 72 | } 73 | 74 | @Override 75 | void putAll(Map m) { 76 | throw new UnsupportedOperationException('Processor Map is immutable (for now)') 77 | } 78 | 79 | @Override 80 | void clear() { 81 | throw new UnsupportedOperationException('Processor Map is immutable (for now)') 82 | } 83 | 84 | @Override 85 | Set keySet() { 86 | reload() 87 | status.keySet() 88 | } 89 | 90 | @Override 91 | Collection values() { 92 | reload() 93 | status.values() 94 | } 95 | 96 | @Override 97 | Set> entrySet() { 98 | reload() 99 | status.entrySet() 100 | } 101 | 102 | 103 | def reload() { 104 | synchronized (this.status) { 105 | status.putAll( slurper.parseText("${nifi.urlString}/nifi-api/system-diagnostics".toURL().text)?.systemDiagnostics ) 106 | } 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /src/main/groovy/nifi/client/Template.groovy: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with 5 | * the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | ******************************************************************************/ 16 | package nifi.client 17 | 18 | import groovy.json.JsonSlurper 19 | import static groovyx.net.http.Method.DELETE 20 | import static groovyx.net.http.Method.POST 21 | import static groovyx.net.http.ContentType.URLENC 22 | 23 | /** 24 | * Created by mburgess on 12/30/15. 25 | */ 26 | class Template implements Map { 27 | NiFi nifi 28 | private final JsonSlurper slurper = new JsonSlurper() 29 | protected Map propertyMap = [:] 30 | 31 | protected Template(NiFi nifi, Map propMap) { 32 | super() 33 | this.nifi = nifi 34 | this.propertyMap = propMap 35 | } 36 | 37 | @Override 38 | int size() { 39 | return propertyMap.size() 40 | } 41 | 42 | @Override 43 | boolean isEmpty() { 44 | return propertyMap.isEmpty() 45 | } 46 | 47 | @Override 48 | boolean containsKey(Object key) { 49 | return propertyMap.containsKey(key) 50 | } 51 | 52 | @Override 53 | boolean containsValue(Object value) { 54 | return propertyMap.containsValue(value) 55 | } 56 | 57 | @Override 58 | String get(Object key) { 59 | return propertyMap.get(key) 60 | } 61 | 62 | @Override 63 | String put(String key, String value) { 64 | throw new UnsupportedOperationException('Processor property Map is immutable (for now)') 65 | } 66 | 67 | @Override 68 | String remove(Object key) { 69 | throw new UnsupportedOperationException('Processor property Map is immutable (for now)') 70 | } 71 | 72 | @Override 73 | void putAll(Map m) { 74 | throw new UnsupportedOperationException('Processor property Map is immutable (for now)') 75 | } 76 | 77 | @Override 78 | void clear() { 79 | throw new UnsupportedOperationException('Processor property Map is immutable (for now)') 80 | } 81 | 82 | @Override 83 | Set keySet() { 84 | return propertyMap.keySet() 85 | } 86 | 87 | @Override 88 | Collection values() { 89 | return propertyMap.values() 90 | } 91 | 92 | @Override 93 | Set> entrySet() { 94 | return propertyMap.entrySet() 95 | } 96 | 97 | def instantiate() { 98 | def tID = this.id 99 | def n = this.nifi 100 | try { 101 | // Need to get latest revision 102 | def latestVersion = nifi.currentVersion 103 | 104 | nifi.http.request(POST) { 105 | uri.path = '/nifi-api/controller/process-groups/root/template-instance' 106 | send URLENC, 107 | [version : latestVersion, 108 | templateId: tID, 109 | originX : '10', 110 | originY : '100'] 111 | 112 | response.success = { instanceResp -> 113 | n.processors.reload() 114 | } 115 | response.'404' = { throw new Exception("Couldn't find template with ID $tID") } 116 | } 117 | } catch (e) { 118 | e.printStackTrace(System.err) 119 | } 120 | } 121 | 122 | def delete() { 123 | def deleteId = this.id 124 | nifi.http.request(DELETE) { uri.path="/nifi-api/controller/templates/$deleteId" } 125 | nifi.templates.reload() 126 | } 127 | 128 | def rightShift(file) { 129 | export(file) 130 | } 131 | 132 | def export(file) { 133 | def exportId = this.id 134 | def template = "${nifi.urlString}/nifi-api/controller/templates/$exportId".toURL().text.getBytes('UTF-8') 135 | (file as File).withOutputStream { out -> 136 | out.write(template) 137 | } 138 | } 139 | 140 | } 141 | -------------------------------------------------------------------------------- /src/main/groovy/nifi/client/Templates.groovy: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with 5 | * the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | ******************************************************************************/ 16 | package nifi.client 17 | 18 | import groovy.json.JsonSlurper 19 | 20 | import static groovyx.net.http.Method.POST 21 | import org.apache.http.entity.mime.MultipartEntity 22 | import org.apache.http.entity.mime.content.StringBody 23 | 24 | /** 25 | * Created by mburgess on 12/30/15. 26 | */ 27 | class Templates implements Map { 28 | 29 | NiFi nifi 30 | protected final JsonSlurper slurper = new JsonSlurper() 31 | protected final Map templateIdMap = [:] 32 | 33 | protected Templates(NiFi nifi) { 34 | super() 35 | this.nifi = nifi 36 | 37 | } 38 | 39 | 40 | @Override 41 | int size() { 42 | reload() 43 | return templateIdMap.size() 44 | } 45 | 46 | @Override 47 | boolean isEmpty() { 48 | reload() 49 | return templateIdMap.isEmpty() 50 | } 51 | 52 | @Override 53 | boolean containsKey(Object key) { 54 | reload() 55 | return templateIdMap.containsKey(key) 56 | } 57 | 58 | @Override 59 | boolean containsValue(Object value) { 60 | reload() 61 | return templateIdMap.containsValue(value) 62 | } 63 | 64 | @Override 65 | Template get(Object key) { 66 | reload() 67 | return templateIdMap.get(key) 68 | } 69 | 70 | @Override 71 | Template put(String key, Template value) { 72 | throw new UnsupportedOperationException('Template Map is immutable (for now)') 73 | } 74 | 75 | @Override 76 | Template remove(Object key) { 77 | Template t = templateIdMap.get(key) 78 | t.delete() 79 | return t 80 | } 81 | 82 | @Override 83 | void putAll(Map m) { 84 | throw new UnsupportedOperationException('Template Map is immutable (for now)') 85 | } 86 | 87 | @Override 88 | void clear() { 89 | throw new UnsupportedOperationException('Template Map is immutable (for now)') 90 | } 91 | 92 | @Override 93 | Set keySet() { 94 | reload() 95 | return templateIdMap.keySet() 96 | } 97 | 98 | @Override 99 | Collection values() { 100 | reload() 101 | return templateIdMap.values() 102 | } 103 | 104 | @Override 105 | Set> entrySet() { 106 | reload() 107 | return templateIdMap.entrySet() 108 | } 109 | 110 | def leftShift(file) { 111 | importTemplate(file) 112 | } 113 | 114 | void importTemplate(file) { 115 | 116 | StringBody body = new StringBody((file as File).text) 117 | nifi.http.request(POST) { request -> 118 | uri.path = '/nifi-api/controller/templates' 119 | 120 | requestContentType = 'multipart/form-data' 121 | MultipartEntity entity = new MultipartEntity() 122 | entity.addPart("template", body) 123 | request.entity = entity 124 | 125 | response.success = { resp, xml -> 126 | switch (resp.statusLine.statusCode) { 127 | case 200: 128 | // TODO Template already exists, perhaps we can delete and re-import here 129 | break 130 | case 201: 131 | // Template was created successfully 132 | reload() 133 | break 134 | 135 | default: 136 | // Something went wrong, throw an exception 137 | throw new Exception("Error importing $file") 138 | break 139 | } 140 | 141 | } 142 | } 143 | } 144 | 145 | 146 | def reload() { 147 | synchronized (this.templateIdMap) { 148 | this.templateIdMap.clear() 149 | def procs = slurper.parseText("${nifi.urlString}/nifi-api/controller/templates".toURL().text).templates 150 | def map = this.templateIdMap 151 | def n = this.nifi 152 | procs.each { p -> 153 | map.put(p.name, new Template(n, p)) 154 | } 155 | } 156 | } 157 | } 158 | -------------------------------------------------------------------------------- /src/main/groovy/nifi/client/Util.groovy: -------------------------------------------------------------------------------- 1 | package nifi.client 2 | 3 | /** 4 | * Created by mburgess on 1/5/16. 5 | */ 6 | class Util { 7 | 8 | static String getSimpleName(String name) { 9 | name[(name.lastIndexOf('.')+1)..(-1)] 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/groovy/nifi/client/controller/About.groovy: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with 5 | * the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | ******************************************************************************/ 16 | package nifi.client.controller 17 | 18 | import groovy.json.JsonSlurper 19 | import nifi.client.NiFi 20 | 21 | /** 22 | * Created by mburgess on 12/30/15. 23 | */ 24 | class About { 25 | NiFi nifi 26 | private final JsonSlurper slurper = new JsonSlurper() 27 | private Object about 28 | private clientId 29 | 30 | protected About(NiFi nifi) { 31 | super() 32 | this.nifi = nifi 33 | } 34 | 35 | def propertyMissing(String name) { 36 | def s = slurper.parseText("${nifi.urlString}/nifi-api/controller/bulletinBoard".toURL().text) 37 | about = s?.about 38 | clientId = s?.revision?.clientId 39 | about[name] 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/groovy/nifi/client/controller/Banners.groovy: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with 5 | * the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | ******************************************************************************/ 16 | package nifi.client.controller 17 | 18 | import groovy.json.JsonSlurper 19 | import nifi.client.NiFi 20 | 21 | /** 22 | * Created by mburgess on 12/30/15. 23 | */ 24 | class Banners { 25 | NiFi nifi 26 | private final JsonSlurper slurper = new JsonSlurper() 27 | private Object banners 28 | private clientId 29 | 30 | protected Banners(NiFi nifi) { 31 | super() 32 | this.nifi = nifi 33 | } 34 | 35 | def propertyMissing(String name) { 36 | def s = slurper.parseText("${nifi.urlString}/nifi-api/controller/bulletinBoard".toURL().text) 37 | banners = s?.banners 38 | clientId = s?.revision?.clientId 39 | banners[name] 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/groovy/nifi/client/controller/BulletinBoard.groovy: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with 5 | * the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | ******************************************************************************/ 16 | package nifi.client.controller 17 | 18 | import groovy.json.JsonSlurper 19 | import nifi.client.NiFi 20 | 21 | /** 22 | * Created by mburgess on 12/30/15. 23 | */ 24 | class BulletinBoard { 25 | NiFi nifi 26 | private final JsonSlurper slurper = new JsonSlurper() 27 | private Object bulletinBoard 28 | private clientId 29 | 30 | protected BulletinBoard(NiFi nifi) { 31 | super() 32 | this.nifi = nifi 33 | } 34 | 35 | def propertyMissing(String name) { 36 | def s = slurper.parseText("${nifi.urlString}/nifi-api/controller/bulletin-board".toURL().text) 37 | bulletinBoard = s?.bulletinBoard 38 | clientId = s?.revision?.clientId 39 | bulletinBoard[name] 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/groovy/nifi/client/controller/Config.groovy: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with 5 | * the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | ******************************************************************************/ 16 | package nifi.client.controller 17 | 18 | import groovy.json.JsonSlurper 19 | import nifi.client.NiFi 20 | 21 | /** 22 | * Created by mburgess on 12/30/15. 23 | */ 24 | class Config { 25 | NiFi nifi 26 | private final JsonSlurper slurper = new JsonSlurper() 27 | private Object config 28 | private clientId 29 | 30 | protected Config(NiFi nifi) { 31 | super() 32 | this.nifi = nifi 33 | } 34 | 35 | def propertyMissing(String name) { 36 | def s = slurper.parseText("${nifi.urlString}/nifi-api/controller/config".toURL().text) 37 | config = s?.config 38 | clientId = s?.revision?.clientId 39 | config[name] 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/groovy/nifi/client/controller/Controller.groovy: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with 5 | * the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | ******************************************************************************/ 16 | package nifi.client.controller 17 | 18 | import groovy.json.JsonSlurper 19 | import nifi.client.NiFi 20 | 21 | /** 22 | * An object corresponding to the Controller data model from the REST API 23 | */ 24 | class Controller { 25 | NiFi nifi 26 | About about 27 | Status status 28 | Banners banners 29 | BulletinBoard bulletins 30 | Config config 31 | ControllerServiceTypes controllerServiceTypes 32 | Identity identity 33 | Prioritizers prioritizers 34 | ProcessorTypes processorTypes 35 | ReportingTaskTypes reportingTaskTypes 36 | History history 37 | ProcessGroup root 38 | Provenance provenance 39 | private final JsonSlurper slurper = new JsonSlurper() 40 | private clientId 41 | private controller 42 | 43 | public Controller(NiFi nifi) { 44 | super() 45 | this.nifi = nifi 46 | this.about = new About(nifi) 47 | this.status = new Status(nifi) 48 | this.banners = new Banners(nifi) 49 | this.bulletins = new BulletinBoard(nifi) 50 | this.config = new Config(nifi) 51 | this.controllerServiceTypes = new ControllerServiceTypes(nifi) 52 | this.identity = new Identity(nifi) 53 | this.prioritizers = new Prioritizers(nifi) 54 | this.processorTypes = new ProcessorTypes(nifi) 55 | this.reportingTaskTypes = new ReportingTaskTypes(nifi) 56 | this.history = new History(nifi) 57 | this.root = new ProcessGroup(nifi, [name:'root', id:'root'], null) 58 | this.provenance = new Provenance(nifi) 59 | } 60 | 61 | def search(String query) { 62 | slurper.parseText("${nifi.urlString}/nifi-api/controller/search-results?q=$query".toURL().text)?.searchResultsDTO 63 | } 64 | 65 | def history(Map queryParams) { 66 | this.history.reload(queryParams) 67 | this.history 68 | } 69 | 70 | def propertyMissing(String name) { 71 | 72 | def s = slurper.parseText("${nifi.urlString}/nifi-api/controller".toURL().text) 73 | controller = s?.controller 74 | clientId = s?.revision?.clientId 75 | controller[name] 76 | 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/main/groovy/nifi/client/controller/ControllerServiceTypes.groovy: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with 5 | * the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | ******************************************************************************/ 16 | package nifi.client.controller 17 | 18 | import groovy.json.JsonSlurper 19 | import nifi.client.NiFi 20 | 21 | /** 22 | * Created by mburgess on 12/30/15. 23 | */ 24 | class ControllerServiceTypes implements Map { 25 | NiFi nifi 26 | private final JsonSlurper slurper = new JsonSlurper() 27 | protected final Map controllerServiceTypes = [:] 28 | 29 | protected ControllerServiceTypes(NiFi nifi) { 30 | super() 31 | this.nifi = nifi 32 | } 33 | 34 | 35 | @Override 36 | int size() { 37 | reload() 38 | return controllerServiceTypes.size() 39 | } 40 | 41 | @Override 42 | boolean isEmpty() { 43 | reload() 44 | return controllerServiceTypes.isEmpty() 45 | } 46 | 47 | @Override 48 | boolean containsKey(Object key) { 49 | reload() 50 | return controllerServiceTypes.containsKey(key) 51 | } 52 | 53 | @Override 54 | boolean containsValue(Object value) { 55 | reload() 56 | return controllerServiceTypes.containsValue(value) 57 | } 58 | 59 | @Override 60 | Object get(Object key) { 61 | reload() 62 | return controllerServiceTypes.get(key) 63 | } 64 | 65 | @Override 66 | Object put(String key, Object value) { 67 | throw new UnsupportedOperationException('ControllerServiceTypes Map is immutable (for now)') 68 | } 69 | 70 | @Override 71 | Object remove(Object key) { 72 | throw new UnsupportedOperationException('ControllerServiceTypes Map is immutable (for now)') 73 | } 74 | 75 | @Override 76 | void putAll(Map m) { 77 | throw new UnsupportedOperationException('ControllerServiceTypes Map is immutable (for now)') 78 | } 79 | 80 | @Override 81 | void clear() { 82 | throw new UnsupportedOperationException('ControllerServiceTypes Map is immutable (for now)') 83 | } 84 | 85 | @Override 86 | Set keySet() { 87 | reload() 88 | controllerServiceTypes.keySet() 89 | } 90 | 91 | @Override 92 | Collection values() { 93 | reload() 94 | controllerServiceTypes.values() 95 | } 96 | 97 | @Override 98 | Set> entrySet() { 99 | reload() 100 | controllerServiceTypes.entrySet() 101 | } 102 | 103 | Collection findByType(String type) { 104 | values().findAll { getSimpleName(it.type) == type } 105 | } 106 | 107 | private String getSimpleName(String name) { 108 | name[(name.lastIndexOf('.')+1)..(-1)] 109 | } 110 | 111 | Collection types() { 112 | values().collect { getSimpleName(it.type) }.unique() 113 | } 114 | 115 | def reload() { 116 | synchronized (this.controllerServiceTypes) { 117 | def procs = slurper.parseText("${nifi.urlString}/nifi-api/controller/controller-service-types".toURL().text).controllerServiceTypes 118 | def map = this.controllerServiceTypes 119 | procs.each { p -> 120 | map.put(getSimpleName(p.type), p) 121 | } 122 | } 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /src/main/groovy/nifi/client/controller/History.groovy: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with 5 | * the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | ******************************************************************************/ 16 | package nifi.client.controller 17 | 18 | import groovy.json.JsonSlurper 19 | import nifi.client.NiFi 20 | 21 | /** 22 | * Created by mburgess on 12/30/15. 23 | */ 24 | class History implements Map { 25 | NiFi nifi 26 | private final JsonSlurper slurper = new JsonSlurper() 27 | protected final Map history = [:] 28 | private offset = 0 29 | private count = 100 30 | private sortOrder 31 | private sortColumn 32 | private startDate 33 | private endDate 34 | private userName 35 | private sourceId 36 | 37 | protected History(NiFi nifi) { 38 | super() 39 | this.nifi = nifi 40 | } 41 | 42 | 43 | @Override 44 | int size() { 45 | reload() 46 | return history.size() 47 | } 48 | 49 | @Override 50 | boolean isEmpty() { 51 | reload() 52 | return history.isEmpty() 53 | } 54 | 55 | @Override 56 | boolean containsKey(Object key) { 57 | reload() 58 | return history.containsKey(key) 59 | } 60 | 61 | @Override 62 | boolean containsValue(Object value) { 63 | reload() 64 | return history.containsValue(value) 65 | } 66 | 67 | @Override 68 | Object get(Object key) { 69 | reload() 70 | return history.get(key) 71 | } 72 | 73 | @Override 74 | Object put(String key, Object value) { 75 | throw new UnsupportedOperationException('ControllerServiceTypes Map is immutable (for now)') 76 | } 77 | 78 | @Override 79 | Object remove(Object key) { 80 | throw new UnsupportedOperationException('ControllerServiceTypes Map is immutable (for now)') 81 | } 82 | 83 | @Override 84 | void putAll(Map m) { 85 | throw new UnsupportedOperationException('ControllerServiceTypes Map is immutable (for now)') 86 | } 87 | 88 | @Override 89 | void clear() { 90 | throw new UnsupportedOperationException('ControllerServiceTypes Map is immutable (for now)') 91 | } 92 | 93 | @Override 94 | Set keySet() { 95 | reload() 96 | history.keySet() 97 | } 98 | 99 | @Override 100 | Collection values() { 101 | reload() 102 | history.values() 103 | } 104 | 105 | @Override 106 | Set> entrySet() { 107 | reload() 108 | history.entrySet() 109 | } 110 | 111 | 112 | def reload(paramMap) { 113 | synchronized (this.history) { 114 | def queryParams = [] as List 115 | 116 | def o = paramMap?.offset ?: offset 117 | if(o != null) queryParams.add("offset=${offset = o}") 118 | 119 | def ct = paramMap?.count ?: count 120 | if(ct != null) queryParams.add("count=${count = ct}") 121 | 122 | def so = paramMap?.sortOrder ?: sortOrder 123 | if(so) queryParams.add("sortOrder=${sortOrder = so}"); 124 | 125 | def sd = paramMap?.startDate ?: startDate 126 | if(sd) queryParams.add("startDate=${startDate = sd}"); 127 | 128 | def ed = paramMap?.endDate ?: endDate 129 | if(ed) queryParams.add("endDate=${endDate = ed}"); 130 | 131 | def un = paramMap?.userName ?: userName 132 | if(un) queryParams.add("userName=${userName = un}"); 133 | 134 | def si = paramMap?.sourceId ?: sourceId 135 | if(si) queryParams.add("sourceId=${sourceId = si}"); 136 | 137 | def queryString = queryParams.join('&') 138 | this.history.clear() 139 | this.history.putAll(slurper.parseText("${nifi.urlString}/nifi-api/controller/history?${queryString}".toURL().text).history) 140 | } 141 | } 142 | } 143 | -------------------------------------------------------------------------------- /src/main/groovy/nifi/client/controller/Identity.groovy: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with 5 | * the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | ******************************************************************************/ 16 | package nifi.client.controller 17 | 18 | import groovy.json.JsonSlurper 19 | import nifi.client.NiFi 20 | 21 | /** 22 | * Created by mburgess on 12/30/15. 23 | */ 24 | class Identity { 25 | NiFi nifi 26 | private final JsonSlurper slurper = new JsonSlurper() 27 | private clientId 28 | 29 | protected Identity(NiFi nifi) { 30 | super() 31 | this.nifi = nifi 32 | } 33 | 34 | def propertyMissing(String prop) { 35 | def s = slurper.parseText("${nifi.urlString}/nifi-api/controller/identity".toURL().text) 36 | clientId = s?.revision?.clientId 37 | switch(prop) { 38 | case 'name': return s?.identity 39 | case 'userId': return s?.userId 40 | case 'clientId': return clientId 41 | } 42 | null 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/groovy/nifi/client/controller/Prioritizers.groovy: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with 5 | * the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | ******************************************************************************/ 16 | package nifi.client.controller 17 | 18 | import groovy.json.JsonSlurper 19 | import nifi.client.NiFi 20 | 21 | /** 22 | * Created by mburgess on 12/30/15. 23 | */ 24 | class Prioritizers implements Map { 25 | NiFi nifi 26 | private final JsonSlurper slurper = new JsonSlurper() 27 | protected final Map prioritizers = [:] 28 | 29 | protected Prioritizers(NiFi nifi) { 30 | super() 31 | this.nifi = nifi 32 | } 33 | 34 | 35 | @Override 36 | int size() { 37 | reload() 38 | return prioritizers.size() 39 | } 40 | 41 | @Override 42 | boolean isEmpty() { 43 | reload() 44 | return prioritizers.isEmpty() 45 | } 46 | 47 | @Override 48 | boolean containsKey(Object key) { 49 | reload() 50 | return prioritizers.containsKey(key) 51 | } 52 | 53 | @Override 54 | boolean containsValue(Object value) { 55 | reload() 56 | return prioritizers.containsValue(value) 57 | } 58 | 59 | @Override 60 | Object get(Object key) { 61 | reload() 62 | return prioritizers.get(key) 63 | } 64 | 65 | @Override 66 | Object put(String key, Object value) { 67 | throw new UnsupportedOperationException('Prioritizer Map is immutable (for now)') 68 | } 69 | 70 | @Override 71 | Object remove(Object key) { 72 | throw new UnsupportedOperationException('Prioritizer Map is immutable (for now)') 73 | } 74 | 75 | @Override 76 | void putAll(Map m) { 77 | throw new UnsupportedOperationException('Prioritizer Map is immutable (for now)') 78 | } 79 | 80 | @Override 81 | void clear() { 82 | throw new UnsupportedOperationException('Prioritizer Map is immutable (for now)') 83 | } 84 | 85 | @Override 86 | Set keySet() { 87 | reload() 88 | prioritizers.keySet() 89 | } 90 | 91 | @Override 92 | Collection values() { 93 | reload() 94 | prioritizers.values() 95 | } 96 | 97 | @Override 98 | Set> entrySet() { 99 | reload() 100 | prioritizers.entrySet() 101 | } 102 | 103 | 104 | private String getSimpleName(String name) { 105 | name[(name.lastIndexOf('.')+1)..(-1)] 106 | } 107 | 108 | Collection types() { 109 | values().collect { getSimpleName(it.type) }.unique() 110 | } 111 | 112 | def reload() { 113 | synchronized (this.prioritizers) { 114 | def procs = slurper.parseText("${nifi.urlString}/nifi-api/controller/prioritizers".toURL().text).prioritizerTypes 115 | def map = this.prioritizers 116 | procs.each { p -> 117 | map.put(getSimpleName(p.type), p) 118 | } 119 | } 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /src/main/groovy/nifi/client/controller/ProcessGroup.groovy: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with 5 | * the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | ******************************************************************************/ 16 | package nifi.client.controller 17 | 18 | import groovy.json.JsonSlurper 19 | import nifi.client.NiFi 20 | import nifi.client.Processors 21 | 22 | import static groovyx.net.http.ContentType.URLENC 23 | import static groovyx.net.http.Method.PUT 24 | 25 | /** 26 | * Created by mburgess on 12/30/15. 27 | */ 28 | class ProcessGroup implements Map { 29 | NiFi nifi 30 | protected Map propertyMap = [:] 31 | protected Processors processors 32 | 33 | protected ProcessGroup(NiFi nifi, Map propMap, String parentId) { 34 | super() 35 | this.nifi = nifi 36 | this.propertyMap.putAll(propMap) 37 | this.propertyMap.put('parentId',parentId) 38 | this.propertyMap.put('groups', new HashMap()) 39 | } 40 | 41 | @Override 42 | int size() { 43 | return propertyMap.size() 44 | } 45 | 46 | @Override 47 | boolean isEmpty() { 48 | return propertyMap.isEmpty() 49 | } 50 | 51 | @Override 52 | boolean containsKey(Object key) { 53 | return propertyMap.containsKey(key) 54 | } 55 | 56 | @Override 57 | boolean containsValue(Object value) { 58 | return propertyMap.containsValue(value) 59 | } 60 | 61 | @Override 62 | Object get(Object key) { 63 | if('groups'.equals(key)) getGroups() 64 | if('processors'.equals(key)) propertyMap.put('processors', new Processors(nifi, id)) 65 | return propertyMap.get(key) 66 | } 67 | 68 | @Override 69 | Object put(String key, Object value) { 70 | throw new UnsupportedOperationException('ProcessGroup property Map is immutable (for now)') 71 | } 72 | 73 | @Override 74 | String remove(Object key) { 75 | throw new UnsupportedOperationException('ProcessGroup property Map is immutable (for now)') 76 | } 77 | 78 | @Override 79 | void putAll(Map m) { 80 | throw new UnsupportedOperationException('ProcessGroup property Map is immutable (for now)') 81 | } 82 | 83 | @Override 84 | void clear() { 85 | throw new UnsupportedOperationException('ProcessGroup property Map is immutable (for now)') 86 | } 87 | 88 | @Override 89 | Set keySet() { 90 | return propertyMap.keySet() 91 | } 92 | 93 | @Override 94 | Collection values() { 95 | return propertyMap.values() 96 | } 97 | 98 | @Override 99 | Set> entrySet() { 100 | return propertyMap.entrySet() 101 | } 102 | 103 | def set(Map props) { 104 | // Set the properties on the ProcessGroup and update it 105 | 106 | } 107 | 108 | def getGroups() { 109 | NiFi n = this.nifi 110 | def pm = this.propertyMap 111 | new JsonSlurper().parseText("${n.urlString}/nifi-api/controller/process-groups/${id}/process-group-references" 112 | .toURL().text)?.processGroups?.each { g -> 113 | pm.get('groups').put(g.name, new ProcessGroup(n, g as Map, this.id)) 114 | } 115 | pm.get('groups') 116 | } 117 | 118 | def start() { 119 | updateState('RUNNING') 120 | } 121 | 122 | def stop() { 123 | updateState('STOPPED') 124 | } 125 | 126 | def enable() { 127 | updateState('STOPPED') 128 | } 129 | 130 | def disable() { 131 | updateState('DISABLED') 132 | } 133 | 134 | def updateState(String newState) { 135 | def parentGroupId = propertyMap.parentGroupId ?: 'root' 136 | def id = propertyMap.id 137 | def currentVersion = nifi.currentVersion 138 | 139 | try { 140 | 141 | nifi.http.request(PUT) { request -> 142 | uri.path = "/nifi-api/controller/process-groups/${parentGroupId}/process-group-references/${id}" 143 | def putBody = [version: currentVersion, state: newState] 144 | 145 | send URLENC, putBody 146 | 147 | response.'404' = { throw new Exception("Couldn't process start()") } 148 | 149 | //response.'409' = { resp, xml -> System.out << xml } 150 | 151 | response.success = { resp, xml -> 152 | //println "Got code ${resp.statusLine.statusCode}" 153 | switch (resp.statusLine.statusCode) { 154 | case 200: 155 | // TODO 156 | break 157 | case 201: 158 | // Template was created successfully 159 | //reload() 160 | break 161 | 162 | default: 163 | // Something went wrong, throw an exception 164 | //throw new Exception("Error importing $file") 165 | break 166 | } 167 | 168 | } 169 | } 170 | } 171 | catch (e) { 172 | e.printStackTrace(System.err) 173 | } 174 | } 175 | 176 | } 177 | -------------------------------------------------------------------------------- /src/main/groovy/nifi/client/controller/ProcessGroups.groovy: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with 5 | * the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | ******************************************************************************/ 16 | package nifi.client.controller 17 | 18 | import groovy.json.JsonSlurper 19 | import nifi.client.NiFi 20 | 21 | /** 22 | * Created by mburgess on 12/30/15. 23 | */ 24 | class ProcessGroups implements Map { 25 | NiFi nifi 26 | private final JsonSlurper slurper = new JsonSlurper() 27 | private String processGroup 28 | protected final Map processorGroupMap = [:] 29 | 30 | protected ProcessGroups(NiFi nifi, String pGroup) { 31 | super() 32 | this.nifi = nifi 33 | this.processGroup = pGroup ?: 'root' 34 | } 35 | 36 | @Override 37 | int size() { 38 | reload() 39 | return processorGroupMap.size() 40 | } 41 | 42 | @Override 43 | boolean isEmpty() { 44 | reload() 45 | return processorGroupMap.isEmpty() 46 | } 47 | 48 | @Override 49 | boolean containsKey(Object key) { 50 | reload() 51 | return processorGroupMap.containsKey(key) 52 | } 53 | 54 | @Override 55 | boolean containsValue(Object value) { 56 | reload() 57 | return processorGroupMap.containsValue(value) 58 | } 59 | 60 | @Override 61 | ProcessGroup get(Object key) { 62 | reload() 63 | return processorGroupMap.get(key) 64 | } 65 | 66 | @Override 67 | ProcessGroup put(String key, ProcessGroup value) { 68 | throw new UnsupportedOperationException('ProcessGroup Map is immutable (for now)') 69 | } 70 | 71 | @Override 72 | ProcessGroup remove(Object key) { 73 | throw new UnsupportedOperationException('ProcessGroup Map is immutable (for now)') 74 | } 75 | 76 | @Override 77 | void putAll(Map m) { 78 | throw new UnsupportedOperationException('ProcessGroup Map is immutable (for now)') 79 | } 80 | 81 | @Override 82 | void clear() { 83 | throw new UnsupportedOperationException('ProcessGroup Map is immutable (for now)') 84 | } 85 | 86 | @Override 87 | Set keySet() { 88 | reload() 89 | processorGroupMap.keySet() 90 | } 91 | 92 | @Override 93 | Collection values() { 94 | reload() 95 | processorGroupMap.values() 96 | } 97 | 98 | @Override 99 | Set> entrySet() { 100 | reload() 101 | processorGroupMap.entrySet() 102 | } 103 | 104 | def reload() { 105 | def pGroup = processGroup ?: 'root' 106 | println "Fetching ${nifi.urlString}/nifi-api/controller/process-groups/${pGroup}" 107 | synchronized (this.processorGroupMap) { 108 | def procs = slurper.parseText("${nifi.urlString}/nifi-api/controller/process-groups/${pGroup}".toURL().text).processGroups 109 | def map = this.processorGroupMap 110 | def n = this.nifi 111 | procs.each { p -> 112 | map.put(p.name, new ProcessGroup(n, p)) 113 | } 114 | } 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /src/main/groovy/nifi/client/controller/ProcessorTypes.groovy: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with 5 | * the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | ******************************************************************************/ 16 | package nifi.client.controller 17 | 18 | import groovy.json.JsonSlurper 19 | import nifi.client.NiFi 20 | 21 | /** 22 | * Created by mburgess on 12/30/15. 23 | */ 24 | class ProcessorTypes implements Map { 25 | NiFi nifi 26 | private final JsonSlurper slurper = new JsonSlurper() 27 | protected final Map processorTypes = [:] 28 | 29 | protected ProcessorTypes(NiFi nifi) { 30 | super() 31 | this.nifi = nifi 32 | } 33 | 34 | @Override 35 | int size() { 36 | reload() 37 | return processorTypes.size() 38 | } 39 | 40 | @Override 41 | boolean isEmpty() { 42 | reload() 43 | return processorTypes.isEmpty() 44 | } 45 | 46 | @Override 47 | boolean containsKey(Object key) { 48 | reload() 49 | return processorTypes.containsKey(key) 50 | } 51 | 52 | @Override 53 | boolean containsValue(Object value) { 54 | reload() 55 | return processorTypes.containsValue(value) 56 | } 57 | 58 | @Override 59 | Object get(Object key) { 60 | reload() 61 | return processorTypes.get(key) 62 | } 63 | 64 | @Override 65 | Object put(String key, Object value) { 66 | throw new UnsupportedOperationException('Processor Map is immutable (for now)') 67 | } 68 | 69 | @Override 70 | Object remove(Object key) { 71 | throw new UnsupportedOperationException('Processor Map is immutable (for now)') 72 | } 73 | 74 | @Override 75 | void putAll(Map m) { 76 | throw new UnsupportedOperationException('Processor Map is immutable (for now)') 77 | } 78 | 79 | @Override 80 | void clear() { 81 | throw new UnsupportedOperationException('Processor Map is immutable (for now)') 82 | } 83 | 84 | @Override 85 | Set keySet() { 86 | reload() 87 | processorTypes.keySet() 88 | } 89 | 90 | @Override 91 | Collection values() { 92 | reload() 93 | processorTypes.values() 94 | } 95 | 96 | @Override 97 | Set> entrySet() { 98 | reload() 99 | processorTypes.entrySet() 100 | } 101 | 102 | def reload() { 103 | synchronized (this.processorTypes) { 104 | def procs = slurper.parseText("${nifi.urlString}/nifi-api/controller/processor-types".toURL().text).processorTypes 105 | def map = this.processorTypes 106 | procs.each { p -> 107 | map.put(nifi.client.Util.getSimpleName(p.type), p) 108 | } 109 | } 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /src/main/groovy/nifi/client/controller/Provenance.groovy: -------------------------------------------------------------------------------- 1 | package nifi.client.controller 2 | 3 | import groovy.json.JsonBuilder 4 | import groovy.json.JsonSlurper 5 | import nifi.client.NiFi 6 | 7 | import static groovyx.net.http.ContentType.URLENC 8 | import static groovyx.net.http.Method.DELETE 9 | import static groovyx.net.http.Method.POST 10 | 11 | /** 12 | * An object corresponding to the provenance model 13 | */ 14 | class Provenance { 15 | NiFi nifi 16 | List events = null 17 | 18 | private static final JsonSlurper slurper = new JsonSlurper() 19 | 20 | protected Provenance(NiFi nifi) { 21 | this.nifi = nifi 22 | } 23 | 24 | def events(Map queryParams) { 25 | 26 | // Need to get latest revision 27 | def latestVersion = nifi.currentVersion 28 | if (latestVersion == -1L) throw new Exception("Bad version") 29 | def options = [version: latestVersion] << queryParams 30 | try { 31 | String retryUrl 32 | nifi.http.request(POST) { 33 | uri.path = '/nifi-api/controller/provenance' 34 | send URLENC, options 35 | 36 | response.success = { instanceResp, json -> 37 | try { 38 | events = [] 39 | retryUrl = parseResponse(json) 40 | 41 | while (retryUrl) { 42 | Thread.sleep(500) 43 | retryUrl = parseResponse(slurper.parseText(retryUrl.toURL().text)) 44 | } 45 | } catch (Exception e) { 46 | nifi.http.request(DELETE) { 47 | uri.path = "/nifi-api/controller/provenance/${json.provenance.id}" 48 | } 49 | } 50 | } 51 | response.'404' = { throw new Exception("Couldn't find template with ID $tID") } 52 | response.'409' = { instanceResp, json -> println "Conflict"; System.out << json; } 53 | } 54 | } catch (e) { 55 | e.printStackTrace(System.err) 56 | } 57 | events 58 | } 59 | 60 | private String parseResponse(json) { 61 | def n = this.nifi 62 | def responseId = json.provenance.id 63 | // Check for completion 64 | if (json.provenance.finished) { 65 | json.provenance.results.provenanceEvents.each { events.add(new ProvenanceEvent(n, it as Map)) } 66 | nifi.http.request(DELETE) { 67 | uri.path = "/nifi-api/controller/provenance/$responseId" 68 | } 69 | return null 70 | } else { 71 | return json.provenance.uri 72 | } 73 | } 74 | 75 | def rightShift(file) { 76 | (file as File).withWriter { out -> 77 | if (events?.isEmpty()) throw new IllegalArgumentException("No events to write") 78 | 79 | def eventNodeIds = [] 80 | events.each { event -> 81 | def lineage = event.lineage() 82 | def links = lineage.links.collect { ['outV': it.targetId, 'inV': it.sourceId] } 83 | def builder = new JsonBuilder() 84 | lineage.nodes.each { node -> 85 | if (!eventNodeIds.contains(node.id)) { 86 | builder.call { 87 | id node.id 88 | eventNodeIds.add(node.id) 89 | 90 | label node.eventType?.toLowerCase() ?: node.type.toLowerCase() 91 | def myInE = links.findResults { 92 | it.outV == node.id ? ['id': UUID.randomUUID(), 'outV': it.inV] : null 93 | } 94 | if (myInE && !myInE.isEmpty()) { 95 | inE { 96 | then myInE 97 | } 98 | } 99 | def myOutE = links.findResults { 100 | it.inV == node.id ? ['id': UUID.randomUUID(), 'inV': it.outV] : null 101 | } 102 | if (myOutE && !myOutE.isEmpty()) { 103 | outE { 104 | then myOutE 105 | } 106 | } 107 | properties { 108 | 'provenanceNodeType'([['id': UUID.randomUUID(), 'value': node.type]] as List) 109 | 'flowFileUuid'([['id': UUID.randomUUID(), 'value': node.flowFileUuid]] as List) 110 | 'timestamp'([['id': UUID.randomUUID(), 'value': node.timestamp]] as List) 111 | 'millis'([['id': UUID.randomUUID(), 'value': node.millis]] as List) 112 | } 113 | } 114 | 115 | out.writeLine(builder.toString()) 116 | } 117 | } 118 | } 119 | } 120 | file 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /src/main/groovy/nifi/client/controller/ProvenanceEvent.groovy: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with 5 | * the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | ******************************************************************************/ 16 | package nifi.client.controller 17 | 18 | import groovy.json.JsonSlurper 19 | import nifi.client.NiFi 20 | 21 | import static groovyx.net.http.ContentType.URLENC 22 | import static groovyx.net.http.Method.DELETE 23 | import static groovyx.net.http.Method.POST 24 | 25 | /** 26 | * An object corresponding to a provenance event 27 | */ 28 | class ProvenanceEvent implements Map { 29 | NiFi nifi 30 | protected Map propertyMap = [:] 31 | Map results = null 32 | 33 | public static final JsonSlurper slurper = new JsonSlurper() 34 | 35 | protected ProvenanceEvent(NiFi nifi, Map propMap) { 36 | super() 37 | this.nifi = nifi 38 | this.propertyMap = propMap 39 | } 40 | 41 | @Override 42 | int size() { 43 | return propertyMap.size() 44 | } 45 | 46 | @Override 47 | boolean isEmpty() { 48 | return propertyMap.isEmpty() 49 | } 50 | 51 | @Override 52 | boolean containsKey(Object key) { 53 | return propertyMap.containsKey(key) 54 | } 55 | 56 | @Override 57 | boolean containsValue(Object value) { 58 | return propertyMap.containsValue(value) 59 | } 60 | 61 | @Override 62 | Object get(Object key) { 63 | if(key == 'results') return results ?: lineage() 64 | return propertyMap.get(key) 65 | } 66 | 67 | @Override 68 | Object put(String key, Object value) { 69 | throw new UnsupportedOperationException('Processor property Map is immutable (for now)') 70 | } 71 | 72 | @Override 73 | Object remove(Object key) { 74 | throw new UnsupportedOperationException('Processor property Map is immutable (for now)') 75 | } 76 | 77 | @Override 78 | void putAll(Map m) { 79 | throw new UnsupportedOperationException('Processor property Map is immutable (for now)') 80 | } 81 | 82 | @Override 83 | void clear() { 84 | throw new UnsupportedOperationException('Processor property Map is immutable (for now)') 85 | } 86 | 87 | @Override 88 | Set keySet() { 89 | return propertyMap.keySet() 90 | } 91 | 92 | @Override 93 | Collection values() { 94 | return propertyMap.values() 95 | } 96 | 97 | @Override 98 | Set> entrySet() { 99 | return propertyMap.entrySet() 100 | } 101 | 102 | def lineage() { 103 | 104 | // Need to get latest revision 105 | def latestVersion = nifi.currentVersion 106 | def options = [ 107 | version : latestVersion, 108 | lineageRequestType: 'FLOWFILE', 109 | uuid : propertyMap.get('flowFileUuid') 110 | ] 111 | try { 112 | String retryUrl 113 | final JsonSlurper slurp = slurper 114 | nifi.http.request(POST) { 115 | uri.path = '/nifi-api/controller/provenance/lineage' 116 | send URLENC, options 117 | 118 | response.success = { instanceResp, json -> 119 | results = [:] 120 | retryUrl = parseResponse(json) 121 | 122 | while (retryUrl) { 123 | Thread.sleep(250) 124 | retryUrl = parseResponse(slurp.parseText(retryUrl.toURL().text)) 125 | } 126 | } 127 | response.'404' = { throw new Exception("Couldn't find lineage query with ID $tID") } 128 | } 129 | } catch (e) { 130 | e.printStackTrace(System.err) 131 | } 132 | results 133 | } 134 | 135 | private String parseResponse(json) { 136 | def responseId = json.lineage.id 137 | // Check for completion 138 | if (json.lineage.finished) { 139 | results = json.lineage.results 140 | nifi.http.request(DELETE) { uri.path = "/nifi-api/controller/provenance/lineage/$responseId" } 141 | return null 142 | } else { 143 | return json.lineage.uri 144 | } 145 | } 146 | } 147 | -------------------------------------------------------------------------------- /src/main/groovy/nifi/client/controller/ReportingTaskTypes.groovy: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with 5 | * the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | ******************************************************************************/ 16 | package nifi.client.controller 17 | 18 | import groovy.json.JsonSlurper 19 | import nifi.client.NiFi 20 | 21 | /** 22 | * Created by mburgess on 12/30/15. 23 | */ 24 | class ReportingTaskTypes implements Map { 25 | NiFi nifi 26 | private final JsonSlurper slurper = new JsonSlurper() 27 | protected final Map reportingTaskTypes = [:] 28 | 29 | protected ReportingTaskTypes(NiFi nifi) { 30 | super() 31 | this.nifi = nifi 32 | } 33 | 34 | @Override 35 | int size() { 36 | reload() 37 | return reportingTaskTypes.size() 38 | } 39 | 40 | @Override 41 | boolean isEmpty() { 42 | reload() 43 | return reportingTaskTypes.isEmpty() 44 | } 45 | 46 | @Override 47 | boolean containsKey(Object key) { 48 | reload() 49 | return reportingTaskTypes.containsKey(key) 50 | } 51 | 52 | @Override 53 | boolean containsValue(Object value) { 54 | reload() 55 | return reportingTaskTypes.containsValue(value) 56 | } 57 | 58 | @Override 59 | Object get(Object key) { 60 | reload() 61 | return reportingTaskTypes.get(key) 62 | } 63 | 64 | @Override 65 | Object put(String key, Object value) { 66 | throw new UnsupportedOperationException('ReportingTaskType Map is immutable (for now)') 67 | } 68 | 69 | @Override 70 | Object remove(Object key) { 71 | throw new UnsupportedOperationException('ReportingTaskType Map is immutable (for now)') 72 | } 73 | 74 | @Override 75 | void putAll(Map m) { 76 | throw new UnsupportedOperationException('ReportingTaskType Map is immutable (for now)') 77 | } 78 | 79 | @Override 80 | void clear() { 81 | throw new UnsupportedOperationException('ReportingTaskType Map is immutable (for now)') 82 | } 83 | 84 | @Override 85 | Set keySet() { 86 | reload() 87 | reportingTaskTypes.keySet() 88 | } 89 | 90 | @Override 91 | Collection values() { 92 | reload() 93 | reportingTaskTypes.values() 94 | } 95 | 96 | @Override 97 | Set> entrySet() { 98 | reload() 99 | reportingTaskTypes.entrySet() 100 | } 101 | 102 | def reload() { 103 | synchronized (this.reportingTaskTypes) { 104 | def procs = slurper.parseText("${nifi.urlString}/nifi-api/controller/reporting-task-types".toURL().text).reportingTaskTypes 105 | def map = this.reportingTaskTypes 106 | procs.each { p -> 107 | map.put(nifi.client.Util.getSimpleName(p.type), p) 108 | } 109 | } 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /src/main/groovy/nifi/client/controller/Status.groovy: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with 5 | * the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | ******************************************************************************/ 16 | package nifi.client.controller 17 | 18 | import groovy.json.JsonSlurper 19 | import nifi.client.NiFi 20 | 21 | /** 22 | * Created by mburgess on 12/30/15. 23 | */ 24 | class Status { 25 | NiFi nifi 26 | private final JsonSlurper slurper = new JsonSlurper() 27 | private Object status 28 | private clientId 29 | 30 | protected Status(NiFi nifi) { 31 | super() 32 | this.nifi = nifi 33 | } 34 | 35 | def propertyMissing(String name) { 36 | def s = slurper.parseText("${nifi.urlString}/nifi-api/controller/status".toURL().text) 37 | status = s?.controllerStatus 38 | clientId = s?.revision?.clientId 39 | status[name] 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/test/groovy/nifi/client/NiFiTest.groovy: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with 5 | * the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | ******************************************************************************/ 16 | package nifi.client 17 | 18 | import org.junit.After 19 | import org.junit.Before 20 | import org.junit.Ignore 21 | import org.junit.Test 22 | 23 | import static junit.framework.Assert.assertEquals 24 | 25 | /** 26 | * Created by mburgess on 12/30/15. 27 | */ 28 | class NiFiTest { 29 | private static final String URL = 'http://127.0.0.1:8080' 30 | 31 | @Before 32 | void setUp() { 33 | 34 | } 35 | 36 | @After 37 | void tearDown() { 38 | 39 | } 40 | 41 | @Test 42 | void testBind() { 43 | NiFi nifi = NiFi.bind(URL) 44 | assertEquals(URL, nifi.urlString) 45 | } 46 | 47 | @Test 48 | void testGetCurrentVersion() { 49 | // TODO define a mock client 50 | NiFi nifi = NiFi.bind(URL) 51 | //assertEquals(1L, nifi.currentVersion) 52 | } 53 | 54 | @Test 55 | @Ignore('Comment out this line if you want to run against a local NiFi instance') 56 | void testGetProcessors() { 57 | NiFi nifi = NiFi.bind(URL) 58 | 59 | println '\nProcessors\n-------------------' 60 | nifi.processors.each { k, v -> println "$k (${v.id}) is ${v.state}" } 61 | 62 | println '\nOriginal Templates\n-------------------' 63 | nifi.templates.each { k, v -> println "$k (${v.id})" } 64 | 65 | nifi.templates << "/Users/mburgess/datasets/GetUserData.xml" 66 | 67 | println '\nTemplates\n-------------------' 68 | nifi.templates.each { k, v -> println "$k (${v.id})" 69 | } 70 | 71 | nifi.templates.'GetUserData'.instantiate() 72 | 73 | nifi.processors.types().each { searchType -> 74 | println "\nType: $searchType" 75 | nifi.processors.findByType(searchType).each { println "\t${it.name}"} 76 | } 77 | 78 | println '\nFinal Processors\n-------------------' 79 | nifi.processors.each { k, v -> println "$k (${v.id}) is ${v.state}" } 80 | 81 | nifi.templates.'GetUserData'.delete() 82 | 83 | println '\nFinal Templates\n-------------------' 84 | nifi.templates.each { k, v -> println "$k (${v.id})" 85 | } 86 | } 87 | } 88 | --------------------------------------------------------------------------------