问题
I know it's possible to use the rest-api to retrieve the values in the variable registry, but is there a way to set the variable values? When I change a variable I see that the following POST gets sent:
http://localhost:8080/nifi-api/process-groups/{ID}/variable-registry/update-requests
but I don't really understand where the VariableRegistryEntity comes into play or how I might go about manipulating the variables.
More broadly, what I'm trying to do is manipulate variables inside a custom Nifi processor from another program, so any guidance or ideas on how to do that would be welcome.
回答1:
All the variables(key,values) are stored in variable registry and when we are updating/creating the variables then we are going to have update-requests rest api call in the back end.
If you are building custom processor to use the variables
then you need to create processor
to enable expression language then you can refer the variables by using nifi expression language ${variable_name}
will replace with the variable_value at run time
.
Refer to this link for more details regards to variable registry in NiFi
If you need to update/create any variable in the Nifi you can use below rest api call:
bash$ curl -i -H 'Content-Type: application/json' -X POST -d '{\
"processGroupRevision": {\
"clientId": "<ClientId>",\
"version": 0\
},\
"variableRegistry": {\
"processGroupId": "<process-group-id>",\
"variables": [{\
"variable": {\
"name": "<variable-name>",\
"value": "<variable-value>"\
}\
}]\
}\
}' <URL>/nifi-api/process-groups/<process-group-id>/variable-registry/update-requests
This curl call will update the value
- if variable is already defined and the value got changed and stop and starts all the effected controller services and processor.
- If the variable is not defined yet then creates new variable with the defined value.
How to get ClientID?
you can make the below Get Rest api call:
curl -X GET <URL>/nifi-api/process-groups/<process-group-id>/variable-registry
from the response you can get the clientID details.
回答2:
To update a variable using nifi-api with kerberos authentification you need to get a token from nifi-api and get the version number then curl the api to update the variable
- Get a token
kinit token=$(curl -k -X POST --negotiate -u : https://nifi_hostname:port/nifi-api/access/kerberos)
- Get the version number
curl -k -X GET https://nifi_hostname:port/nifi-api/process-groups/PG-Id/variable-registry -H "Authorization: Bearer $token"
- Update the variable "web_site"
curl -k -X PUT https://nifi_hostname:port/nifi-api/process-groups/PG-ID/variable-registry -H 'Content-Type: application/json' -d '{"processGroupRevision":{"version":version_number},"variableRegistry":{"processGroupId":"PG-ID","variables":[{"variable":{"name":"web_site","value":"stackoverflow"}}]}}' -H "Authorization: Bearer $token"
PG-ID is the process-group Id
来源:https://stackoverflow.com/questions/52010827/how-to-change-nifi-variable-registry-using-rest-api