Status from the Jar

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

Status from the Jar

Ankit Dhar
Hi team,
    I have a jar which does one operation .
Like it fetches the csv file and processes it.
My problem is I want to know weather the jar worked or it didn't , So is
there any option in nifi, So  that I can check weather the execution was
successful or not

Thanks in Advance.

--
ankit
Reply | Threaded
Open this post in threaded view
|

Re: Status from the Jar

Brett Ryan
Hi Anakit. From a processor you can control whatever your relationships are for down stream processors. This can be achieved by a few steps.

Create a static relationship reference within your processor. For example, if you want to handle success and failure routing behaviour

    static final Relationship REL_SUCCESS = new Relationship.Builder()
            .name("success")
            .description("Your process succeeds")
            .build();
    static final Relationship REL_FAILURE = new Relationship.Builder()
            .name("failure")
            .description("Something within the process failed.")
            .build();

    private static final Set<Relationship> RELATIONSHIPS;

    static {
        // ..
        Set<Relationship> r = new HashSet<>();
        r.add(REL_SUCCESS);
        r.add(REL_FAILURE);
        RELATIONSHIPS = Collections.unmodifiableSet(r);
    }

Now in your trigger method you can route to any of these relationships.

    @Override
    public void onTrigger(ProcessContext pc, ProcessSession ps) throws ProcessException {
        final FlowFile ff = ps.get();
        if (ff == null) {
            return;
        }

        try {
            // do something.
            ps.transfer(ff, REL_SUCCESS);
        } catch (Throwable t) {
            // if something fails
            ps.transfer(ff, REL_FAILURE);
        }
    }

While this demonstrates failing from an exception, you can fail from anywhere you like.

You can also have as many relationships as you like, well; I'm not sure on the practical and allowable limitations.

> On 8 Jan 2018, at 20:40, Ankit Dhar <[hidden email]> wrote:
>
> Hi team,
>    I have a jar which does one operation .
> Like it fetches the csv file and processes it.
> My problem is I want to know weather the jar worked or it didn't , So is
> there any option in nifi, So  that I can check weather the execution was
> successful or not
>
> Thanks in Advance.
>
> --
> ankit


signature.asc (891 bytes) Download Attachment