通过REST发布NIFI模板? [英] Post a NIFI template via REST?

查看:90
本文介绍了通过REST发布NIFI模板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有多个nifi服务器,我希望能够通过脚本通过REST接口将模板POST到

I have multiple nifi servers that I would like to be able to POST templates to via the REST interface from a script

"/controller/templates"端点似乎是正确的REST端点,可支持将任意模板发布到我的Nifi安装中. "snippetId"字段让我感到困惑,如何确定内容将包含模板的代码段的ID"?有没有人举过一个例子,说明我无需使用UI即可将模板"test.xml"上传到服务器上的情况?

The "/controller/templates" endpoint appears to be the proper REST endpoint to support POSTing an arbitrary template to my Nifi installation. The "snippetId" field is what is confusing me, how do I determine "The id of the snippet whose contents will comprise the template"? Does anyone have an example of how I can upload a template "test.xml" to my server without having to use the UI?

推荐答案

所提供的文档有些混乱,我制定的解决方案源自

The provided documentation is somewhat confusing, and the solution I worked out was derived from the nifi api deploy groovy script at https://github.com/aperepel/nifi-api-deploy

最终,要直接发布模板,您可以在Python请求中使用以下内容

Ultimately, to POST a template directly, you can use the following in Python requests

requests.post("%s/nifi-api/controller/templates"%(url,), files={"template":open(filename, 'rb')})

其中filename是模板的文件名,而url是您的nifi实例的路径.我还没有直接解决问题,但这有望使人们也遇到类似的问题!

Where filename is the filename of your template and url is the path to your nifi instance. I haven't figured it out in curl directly but this should hopefully get folks with a similar question started!

请注意,您也不能上传与现有模板同名的模板.在尝试重新上传之前,请确保删除现有模板.使用untangle库解析模板的XML,以下脚本可以正常工作:

Note that you also can't upload a template with the same name as an existing template. Make sure to delete your existing template before attempting to re-upload. Using the untangle library to parse the XML of the template, the following script works just fine:

import untangle, sys, requests

def deploy_template(filename, url):
    p = untangle.parse(filename)
    new_template_name=p.template.name.cdata
    r=requests.get("%s/nifi-api/controller/templates"%(url,), headers={"Accept":"application/json"})

    for each in r.json()["templates"]:
        if each["name"]==new_template_name:
            requests.delete(each["uri"])
    requests.post("%s/nifi-api/controller/templates"%(url,), files={"template":open(filename, 'rb')})

if __name__=="__main__":
    deploy_template(sys.argv[1], sys.argv[2])

这篇关于通过REST发布NIFI模板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆