NiFi 1.0.0-RC3 REST API to start a processgroup

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

NiFi 1.0.0-RC3 REST API to start a processgroup

jgianfreda
Hi,

I'm trying to work with the REST API to create a workflow from scratch.

I have some troubles with how to start a process-group. I've found this
route in the API, and it is also the route used by the GUI to start or stop
a process

Schedule or unschedule comopnents in the specified Process Group
PUT /flow/process-groups/{id}

But the documentation does not give any information about the query body and
nifi is excpecting one.

And if I give an empty body it says "Unsupportded media type"

Here's a full curl query example I tried

curl -H "Content-type = application/json" -v -XPUT
http://localhost:8080/nifi-api/flow/process-groups/988462af-0156-1000-3649-4ee9c8253192

Any idea?



--
View this message in context: http://apache-nifi-developer-list.39713.n7.nabble.com/NiFi-1-0-0-RC3-REST-API-to-start-a-processgroup-tp13104.html
Sent from the Apache NiFi Developer List mailing list archive at Nabble.com.
Reply | Threaded
Open this post in threaded view
|

RE: NiFi 1.0.0-RC3 REST API to start a processgroup

Peter Wicks (pwicks)
Hi,

I have created a custom wizard using ASP.Net/C# that uses only the 1.0 API to create data flows in NiFI.

The code may not be 100% translatable, but here is how I do it in C#:


public ProcessorGroup ChangeProcessGroupRunningState(string groupId, bool running)
        {
            using (var client = GetNifiClient())
            {
                StringContent jsonMessage = new StringContent(
                    JsonConvert.SerializeObject(new { id = groupId, state = (running ? "RUNNING" : "STOPPED") }),
                    Encoding.UTF8,
                    "application/json");

                var result = client.PutAsync(_baseURL + string.Format("/flow/process-groups/{0}", groupId), jsonMessage).Result;
                var jsonString = result.Content.ReadAsStringAsync().Result;

                return JSONToObject<ProcessorGroup>(jsonString);
            }
        }

In the above code I build a JSON message with the Process Group ID and a state name, either RUNNING or STOPPED, and pass it to the URL. My URL format appears to match yours.
`GetNiFiCilent` just builds a basic HTTP Rest client and injects my Authorization token.

The key for what is missing from your example is you have no JSON message of what you want to change.

Regards,
  Peter
       

-----Original Message-----
From: jgianfreda [mailto:[hidden email]]
Sent: Tuesday, August 23, 2016 1:48 AM
To: [hidden email]
Subject: NiFi 1.0.0-RC3 REST API to start a processgroup

Hi,

I'm trying to work with the REST API to create a workflow from scratch.

I have some troubles with how to start a process-group. I've found this route in the API, and it is also the route used by the GUI to start or stop a process

Schedule or unschedule comopnents in the specified Process Group PUT /flow/process-groups/{id}

But the documentation does not give any information about the query body and nifi is excpecting one.

And if I give an empty body it says "Unsupportded media type"

Here's a full curl query example I tried

curl -H "Content-type = application/json" -v -XPUT
http://localhost:8080/nifi-api/flow/process-groups/988462af-0156-1000-3649-4ee9c8253192

Any idea?



--
View this message in context: http://apache-nifi-developer-list.39713.n7.nabble.com/NiFi-1-0-0-RC3-REST-API-to-start-a-processgroup-tp13104.html
Sent from the Apache NiFi Developer List mailing list archive at Nabble.com.
Reply | Threaded
Open this post in threaded view
|

Re: NiFi 1.0.0-RC3 REST API to start a processgroup

Matt Gilman
Hey,

I just wanted to follow up. I see that the documentation for the request
body is missing. I've filed a JIRA to address that in the formal 1.0.0
release [1].

Also, I wanted to add that you can always pop open your Dev Tools in your
browser and watch the requests in there to see the endpoints in action.

Let me know if you need additional details. Thanks!

Matt

[1] https://issues.apache.org/jira/browse/NIFI-2633

On Tue, Aug 23, 2016 at 8:52 AM, Peter Wicks (pwicks) <[hidden email]>
wrote:

> Hi,
>
> I have created a custom wizard using ASP.Net/C# that uses only the 1.0 API
> to create data flows in NiFI.
>
> The code may not be 100% translatable, but here is how I do it in C#:
>
>
> public ProcessorGroup ChangeProcessGroupRunningState(string groupId, bool
> running)
>         {
>             using (var client = GetNifiClient())
>             {
>                 StringContent jsonMessage = new StringContent(
>                     JsonConvert.SerializeObject(new { id = groupId, state
> = (running ? "RUNNING" : "STOPPED") }),
>                     Encoding.UTF8,
>                     "application/json");
>
>                 var result = client.PutAsync(_baseURL +
> string.Format("/flow/process-groups/{0}", groupId), jsonMessage).Result;
>                 var jsonString = result.Content.
> ReadAsStringAsync().Result;
>
>                 return JSONToObject<ProcessorGroup>(jsonString);
>             }
>         }
>
> In the above code I build a JSON message with the Process Group ID and a
> state name, either RUNNING or STOPPED, and pass it to the URL. My URL
> format appears to match yours.
> `GetNiFiCilent` just builds a basic HTTP Rest client and injects my
> Authorization token.
>
> The key for what is missing from your example is you have no JSON message
> of what you want to change.
>
> Regards,
>   Peter
>
>
> -----Original Message-----
> From: jgianfreda [mailto:[hidden email]]
> Sent: Tuesday, August 23, 2016 1:48 AM
> To: [hidden email]
> Subject: NiFi 1.0.0-RC3 REST API to start a processgroup
>
> Hi,
>
> I'm trying to work with the REST API to create a workflow from scratch.
>
> I have some troubles with how to start a process-group. I've found this
> route in the API, and it is also the route used by the GUI to start or stop
> a process
>
> Schedule or unschedule comopnents in the specified Process Group PUT
> /flow/process-groups/{id}
>
> But the documentation does not give any information about the query body
> and nifi is excpecting one.
>
> And if I give an empty body it says "Unsupportded media type"
>
> Here's a full curl query example I tried
>
> curl -H "Content-type = application/json" -v -XPUT
> http://localhost:8080/nifi-api/flow/process-groups/
> 988462af-0156-1000-3649-4ee9c8253192
>
> Any idea?
>
>
>
> --
> View this message in context: http://apache-nifi-developer-
> list.39713.n7.nabble.com/NiFi-1-0-0-RC3-REST-API-to-start-a-
> processgroup-tp13104.html
> Sent from the Apache NiFi Developer List mailing list archive at
> Nabble.com.
>