Chaffelson / nipyapi

A convenient Python wrapper for Apache NiFi
Other
244 stars 76 forks source link

Modify Template before deploy it in the canvas #166

Closed hamzabekkouri closed 4 years ago

hamzabekkouri commented 4 years ago

Description

I would like to deploy template that is already created manually from Apache Nifi UI, when I want to deploy his template, I want to change some conf, for example name, props, .. before the upload of it. my problem is the get_template deos not give all info about tempate to do some if,else on it, when I do if,else on deploy_Template, it will be created

What I Did

from nipyapi import config,canvas,nifi,templates from nipyapi.nifi import models

Nifi URL

config.nifi_config.host = 'http://192.168.23.128:8090/nifi-api'

variable

root_id = canvas.get_root_pg_id() pg = canvas.get_process_group(root_id,'id') # ProcessGroupEntity list_projet = ["P0001","P0002"]

nifiTemplates = templates.list_all_templates(native=True) template_name = "SDR_SERVICE" list_template = nifiTemplates.templates

for value in list_template: template=value.template print("template name : %s"%template.name) if (template.name == template_name): template_id = template.id print("this template exist and its id is %s"%template_id) break else: print("is not our searched template anymore")

templates.deploy_template(pg.id,template_id,-500,0)

Chaffelson commented 4 years ago

This is a limitation of the way the standardised Swagger client is generated from the definition - it converts requests for a file contents into a request for the path to the file then reads it in during execution of the call so it can automatically handle serialisation etc. There might be a way to override this so that you directly supply the content rather than the path, but in practice you could read in the file, save it to a temp path, then submit that to the client to work around the limitation.

hamzabekkouri commented 4 years ago

that was helpful for me thank you very much for your help @Chaffelson

ekovacs commented 4 years ago

@hamzabekkouri when i was in a similar situation, i opted for: turning the template - downloaded from - nifi to a jinja2 template. whatever i wanted to change at runtime, i made into template variable.

then i rendered the template into a temp dir, and uploaded that rendered template.

hamzabekkouri commented 4 years ago

@ekovacs I understand what you mean exactly, that was a great idea, I have this one time, but I hesitate to do it, thank you for your affirmation