Support Questions

Find answers, ask questions, and share your expertise
Announcements
Check out our newest addition to the community, the Cloudera Data Analytics (CDA) group hub.

Nifi:Automatizied Scheduler

I have attribute names like startDate:2017-09-07 and endDate:2017-09-16 i want to reitrive data with this parameters and after writing response into the base i want to change this parameter i mean (startDate:2017-09-07 and endDate:2017-09-16 with 2017-09-17 and 2017-09-24) i tried this ecmascript code:

<code> var OutputStreamCallback = Java.type("org.apache.nifi.processor.io.OutputStreamCallback");
var StandardCharsets = Java.type("java.nio.charset.StandardCharsets");

Date.prototype.isValid = function () {
    return (Object.prototype.toString.call(this) === "[object Date]")
        && !isNaN(this.getTime());
};
function addDays(date, days) {
    var result =new Date(date);
    result.setDate(result.getDate() + days);
    var dateFormated = result.toISOString().substr(0,10);
    return formatDate(dateFormated);
}
function formatDate(date) {
    var d = new Date(date),
        month = '' + (d.getMonth() + 1),
        day = '' + d.getDate(),
        year = d.getFullYear();

    if (month.length < 2) month = '0' + month;
    if (day.length < 2) day = '0' + day;

    return [year, month, day].join('-');
}
var startDate = startDate.getValue(),
    endDate = endDate.getValue(),
    parametr=parameter.getValue(),
    count=count.getValue();
var flowFile = session.crete();

var  param=8;
    var endDate = addDays(end, param*count);
    var startDate = formatDate(newStart);
    flowFile = session.putAttribute(flowFile, 'startDate', startDate);
    flowFile = session.putAttribute(flowFile, 'endDate', endDate);

    session.transfer(flowFile, REL_SUCCESS)
       

but i don't know how can i make my code known when it should increase count in order to change endDate and startTdate manually and replace it with valid startDate and EndDate is there any service or processor i can use to simplify this task?

4 REPLIES 4

Expert Contributor

You can use a distributedcache to write startdate and enddate values. The retrieve those from the distributecache using fetchdistributedcache. I have a sample setting attached for fetchdistributemapcache. Once you are done incrementing the new value, you can push it back to the cache using putdistributemapcache.

39596-screen-shot-2017-09-28-at-100502-am.png

@Karthik Narayanan can you link me any article or example of how can i use it?

I mean how can i use distributedCashService

Expert Contributor
Take a Tour of the Community
Don't have an account?
Your experience may be limited. Sign in to explore more.