Nifi: how to convert multiple log file in one file?

2018-01-03 Thread sally
I have many internal log , which i write myself inside nifi environment, i
want to input all this data inside one log flowFile, but this code trows
Null pointer exception what should i cahnge?

import java.nio.charset.StandardCharsets;
import org.apache.commons.io.IOUtils;
import org.apache.nifi.processor.FlowFileFilter;
import groovy.json.JsonSlurper;
import groovy.json.JsonBuilder;

def flowFile = session.get();
def  n=0;

if(!flowFile)return
def size = flowFile.getAttribute('fileSize');
int value = size as Integer;
log.error("g");
if((value/338)>1){
def ffList = session.get(new FlowFileFilter(){
public FlowFileFilterResult filter(FlowFile ff) {

if( size == ff.getAttribute('fileSize') ){ n++; return
FlowFileFilterResult.ACCEPT_AND_CONTINUE;
}
else{
return FlowFileFilterResult.REJECT_AND_CONTINUE
}
}

})

session.transfer(ffList[n-1],REL_SUCCESS);
session.remove( ffList[0..-2] )
session.remove(flowFile);

}
else{

session.transfer(flowFile,REL_SUCCESS);
}



--
Sent from: http://apache-nifi-developer-list.39713.n7.nabble.com/


Nifi:how to handle with multiple flowfiles?

2017-10-23 Thread sally

I have request data which can be splitted into several flowfile for example
request data for date 2017-02-02 can be splitted to four part 2017-02-02.1
,2017-02-02.2 ( i use this partiotion because webservice uses paging and
it can send only certain amount of data at a time (400 mb) and if there is
more than 400 mb data for this date i have to invoke it several time in this
case 4 time) after that i will put them in directory ,and then i want to
check if i don't miss any part of response data which is represented as
request data only difference is that it contains data of "2017-02-02" sent
by service,but while invoking service and getting response if i got any
error or for some reason can't get response data , i have to know if i am
missing some part of my response data. for this reason i use code below:

 var OutputStreamCallback = 
Java.type("org.apache.nifi.processor.io.OutputStreamCallback");
var StandardCharsets = Java.type("java.nio.charset.StandardCharsets");
var  flowFile=session.get();
var   countAs=flowFile.getAttribute('countAs');
var filename=flowFile.getAttribute('filename');
var  countNumber=filename.substring(11,filename.length);
var  countArray=countArray.push(countNumber);
var j=0;

for(  var  i=0;i<=;i++){
   
if(flowFile.getAttribute('filename').substring(11,flowFile.getAttribute('filename'))==countArray[i]){

session.transfer(flowFile,REL_SUCEESS);
}
} 
IF i don't miss anything i want to put whole reponse data in one flowfile
and then rename it to this format 2017-02-02 and save it in database but
there are several subjects i am interested in:

this code doesn't seems to work properly can you give me any better idea of
how can i check if something is missing?

2.how can i convert this splitted reponse data in one flowfile?



--
Sent from: http://apache-nifi-developer-list.39713.n7.nabble.com/


NIFI:how to handle paging in web service

2017-10-22 Thread sally


I want to get service data which have paging logic like this: every time i
send request, it can get only 700 mb data and if the response data for
certain id is more than 700 mb i will have to invoke service twice, but if
for certain id data is more than 2800mb i will have to invoke service four
times and if one of the part of this 2800 mb will fail i mean if connection
errorr or some kind of error will happen

1.how can i recognize which part of same id data is missing?
2.Can you advice me any kind of architectual solution which can simplify
this process inside nifi environment?



--
Sent from: http://apache-nifi-developer-list.39713.n7.nabble.com/


Nifi:is it possible to use File Lock in nifi?

2017-10-18 Thread sally
I  want  to use File lock  and Thread sleep  in nifi processor( ExecuteScript
processor code)  Can   you   link me  any article  or example   of  relative
cases, now  i  use  simple   java  file  lock  and  thread  sleepsbut 
when  several (ExecuteScipt  processor   works at the  same  time)  neither
file  lock   nor sleep  logicworks   properly i  mean  several 
processor  can get access  to  file at the same  time  and  Thread  sleep 
can  kill processSession  and  turn  of  processor at all .  what  should  i 
change? here  is my  code  example :
import java.nio.charset.StandardCharsets 
import org.apache.commons.io.IOUtils
import org.apache.nifi.processor.io.StreamCallback
import groovy.xml.MarkupBuilder
import groovy.xml.StreamingMarkupBuilder
import org.w3c.dom.Document
import org.xml.sax.SAXException
import javax.xml.parsers.DocumentBuilder
import javax.xml.parsers.DocumentBuilderFactory
import javax.xml.parsers.ParserConfigurationException
import javax.xml.transform.Transformer
import javax.xml.transform.TransformerConfigurationException
import javax.xml.transform.TransformerException
import javax.xml.transform.TransformerFactory
import javax.xml.transform.dom.DOMSource
import javax.xml.transform.stream.StreamResult
import java.nio.channels.Channels
import java.nio.channels.FileLock
import java.nio.channels.OverlappingFileLockException
import java.text.SimpleDateFormat
import java.util.concurrent.TimeUnit
import java.io.*
import java.util.*
import groovy.util.XmlParser

 def static addDays(def date) {
SimpleDateFormat sdf = new SimpleDateFormat("-MM-dd");
Calendar c = Calendar.getInstance();
c.setTime(sdf.parse(date));
c.add(Calendar.DATE, 1);  // number of days to add
String m = sdf.format(c.getTime());  // dt is now the new date
return m;
}
def  flowFile=session.get()
ArrayList value = new ArrayList<>();
if(flowFile!=null){ 
  value.add(flowFile.getAttribute('filename');
  session.remove(flowFile);
}
 File file = new
File("C://Users//user//Desktop//try2//nifi-1.3.0//4//conf2.xml");
String content = "";
String material = "";
BufferedReader s;
BufferedWriter w;
RandomAccessFile ini = new RandomAccessFile(file, "rwd");
FileLock lock = ini.getChannel().lock();
DocumentBuilder dBuilder;
Document document, doc;
String date="";
String data="";

try {
String sCurrentLine;
s = new BufferedReader(Channels.newReader(ini.getChannel(),
"UTF-8"));
while ((sCurrentLine = s.readLine()) != null) {
content += sCurrentLine;
}
ini.seek(0);
  def xml = new XmlParser().parseText(content)
for(int i=0;i
p.runAs[0].text() == "false" && p.start[0].text() ==
date.toString()
}).each({ p ->
p.start[0].value = addDays( p.start[0].text())
p.runAs[0].value = "true"
})
}
def stringWriter = new StringWriter()
new XmlNodePrinter(new PrintWriter(stringWriter)).print(xml)
def newXml = stringWriter.toString()
TransformerFactory transformerFactory =
TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
InputStream stream1 = new
ByteArrayInputStream(newXml.toString().getBytes("UTF-8"));
DocumentBuilderFactory dbFactory1 =
DocumentBuilderFactory.newInstance();
dBuilder = dbFactory1.newDocumentBuilder();
document = dBuilder.parse(stream1);
DOMSource source=new DOMSource(document);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
StreamResult result1 = new StreamResult(bos);
try {
transformer.transform(source, result1);
} catch (TransformerException e) {
e.printStackTrace();
}
byte[] array = bos.toByteArray();
data = bos.toString();
if (!data.isEmpty()) {
 ini.setLength(0);
w = new BufferedWriter(Channels.newWriter(ini.getChannel(),
"UTF-8"));
w.write(data);
lock.release();
w.close();
}
else{
ini.setLength(0);
w = new BufferedWriter(Channels.newWriter(ini.getChannel(),
"UTF-8"));
w.write(content);
lock.release();
w.close();

}
}catch (FileNotFoundException e) {
TimeUnit.SECONDS.sleep(5);
} catch (IOException e) {
e.printStackTrace();
} catch (TransformerConfigurationException e) {
   

nifi: How to update and trnaform xml file inside ExecuteScript processor

2017-10-14 Thread sally

Question by sally sally 12 secs ago nifi-processorjavaapache-nifigroovy 
I want to read xml file from folder and i want to update it and make new
flowfile(my code will be placed in nifi processor) which will containt this
renewated data but i can't parse xml document properly i got error like
this:org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot
cast object 'com.sun.org.apache.xerces.internal.dom.DeepNodeListImpl@181ae3f

1.what should i change?( except changing doc = builder.parse(inputStream)
with doc=builder.parse(file) because i need to use string data for later
processing)

Another reason why i can't fulfill my task is that i can't make flowfile in
which i would have placed all renewated xml data, for some reason i got
empty flowfile even if i use this doc=builder.parse(file) i means use config
file phisically( File file=new File('path')), what should i change to
improve this case.
if i use string content, should i use any alternative way to get xml tag
data except using NodeList( i mean is it possible to use any better use
case)? here is my groovy code:

import org.apache.commons.io.IOUtils;
 
import java.nio.charset.StandardCharsets;
 
import  java.io.RandomAccessFile;
 
import java.nio.channels.FileLock;
 
import java.io.BufferedReader;
 
import org.apache.commons.io.IOUtils;
 
import java.nio.charset.StandardCharsets;
 
File file =newFile("C://Users//user//Desktop//2//conf.xml");
 
String content ='';RandomAccessFile ini =newRandomAccessFile(file,"rws");
 
FileLock lock = ini.getChannel().lock();BufferedReader s;
 
DocumentBuilder dBuilder =null;Document doc=null;String
start,startDate,endDate,runAs,makeVersion,patch;
 
try{String sCurrentLine;
   
s=newBufferedReader(Channels.newReader(ini.getChannel(),"UTF-8"));while((sCurrentLine
= s.readLine())!=null){
content+=sCurrentLine;}//make  xml
parsingDocumentBuilderFactory factory
=DocumentBuilderFactory.newInstance();DocumentBuilder builder =
factory.newDocumentBuilder();InputStream inputStream
=newByteArrayInputStream(content.getBytes());
doc = builder.parse(inputStream);NodeList nList =
doc.getElementsByTagName("localAttributes");
 
for(int temp =0; temp < nList.getLength(); temp++){Node nNode =
nList.item(temp);
 
if(nNode.getNodeType()==Node.ELEMENT_NODE){Element eElement =(Element)
nNode;
start =
eElement.getElementsByTagName("start").item(0).getTextContent();
startDate =
eElement.getElementsByTagName("startDate").item(0).getTextContent();
endDate =
eElement.getElementsByTagName("endDate").item(0).getTextContent();
patch =
eElement.getElementsByTagName("patch").item(0).getTextContent();
runAs =
eElement.getElementsByTagName("runAs").item(0).getTextContent();
makeVersion =
eElement.getElementsByTagName("makeVersion").item(0).getTextContent();}}
flowFile1 = session.putAttribute(flowFile1,"start", start);
flowFile1 = session.putAttribute(flowFile1,"startDate",
startDate);
flowFile1 = session.putAttribute(flowFile1,"endDate", endDate);
flowFile1 = session.putAttribute(flowFile1,"runAs", runAs);
flowFile1 = session.putAttribute(flowFile1,"patch", patch);
flowFile1 = session.putAttribute(flowFile1,"makeVersion",
makeVersion);
 
flowFile1 =
session.putAttribute(flowFile1,"filename","conf.xml");
 
DocumentBuilderFactory builderFactory =DocumentBuilderFactory.newInstance();
 
DocumentBuilder builder = builderFactory.newDocumentBuilder();Document
xmlDocument = builder.parse(inputStream);
 
XPath xPath =XPathFactory.newInstance().newXPath();XPathExpression
myNodeList =(XPathExpression) xPath.compile("/localAttributes");
 
Node nodeGettingChanged =(Node)
myNodeList.evaluate(xmlDocument,XPathConstants.NODE);NodeList childNodes =
nodeGettingChanged.getChildNodes();for(int i =0; i !=
childNodes.getLength();++i){Node child = childNodes.item(i);
 
if(!(child
instanceofElement))continue;if(child.getNodeName().equals("runAs"))
child.getFirstChild().setNodeValue("false");}
 
TransformerFactory transformerFactory
=TransformerFactory.newInstance();Transformer transformer =null;
transformer = transformerFactory.newTransformer();DOMSource
source =newDOMSource(xmlDocument);StreamResult file1
=newStreamResult(inputStream);
 
try{
transformer.transform(source,
file1);}catch(TransformerException e){
e.printStackTrace();}
session.write(flowFile1,newStreamCallback(){@Overridepublicvoid
process(InputStream inputStream,OutputStream outputStream)throwsIOException{
 
TransformerFactory transformerFactory =TransformerFactory

How to use Filelock in nifi?

2017-10-14 Thread sally

I want to use filelock inside nifi ExecuteScript processor code ( i want to
prevent reading and writing inside xml file by several processor), but i
don't want to get lock exceptions (when two processor wants to read the same
file) Should i use Thread.sleep() or any relative logic which is implemented
in java for it , or I should use any nifi logic?.

Here is severla subjects i am interested in:

is it good practice to use fileLocks inside nifi and if it isn't what should
i use instead of it ?
Here is my code but i always get empty responses, what should i change to
get good response i mean(flowfile in which i have written my config.xml
data)
 import org.apache.commons.io.IOUtils;
import java.nio.charset.StandardCharsets;
import  java.io.RandomAccessFile;
import java.nio.channels.FileLock;
import java.io.BufferedReader;
import org.apache.commons.io.IOUtils;
import java.nio.charset.StandardCharsets;
File file = new File("C://Users//user//Desktop//2//conf.xml");
String content = '';
RandomAccessFile ini = new RandomAccessFile(file, "rws");
   FileLock lock = ini.getChannel().lock();
  BufferedReader  s;

try {
String sCurrentLine;

s= new
BufferedReader(Channels.newReader(ini.getChannel(), "UTF-8"));
while ((sCurrentLine = s.readLine()) != null) {
content+=sCurrentLine;
}
  FlowFile flowFile=session.create();

 
flowFile=session.putAttribute(flowFile,"filename","conf.xml");
session.write(flowFile, {outputStream ->
   
outputStream.write(content.getBytes(StandardCharsets.UTF_8));
} as OutputStreamCallback);



   s.close();
 session.transfer(flowFile,REL_SUCCESS);

} 


catch (FileNotFoundException e) {
e.printStackTrace();


} catch (Exception e) {
e.printStackTrace();
}
  finally {
lock.release();
ini.close();

}



--
Sent from: http://apache-nifi-developer-list.39713.n7.nabble.com/


Re: Nifi: how to remove session based on atribute value in nifi

2017-10-13 Thread sally
It  was  helpful, thank  you



--
Sent from: http://apache-nifi-developer-list.39713.n7.nabble.com/


Nifi: how to remove session based on atribute value in nifi

2017-10-11 Thread sally
I want to remove session in case i get certain data from file i have code
like this,but i got errors "flowfile has already marked for removal", what
should i change to get rid of extra errors?

In case of session rollback flowfile will dissapear in queues also?
2.should i use rollback instead of remove()?

NodeList childNodes = nodeGettingChanged.getChildNodes();for(int i =0; i !=
childNodes.getLength();++i)
{Node child = childNodes.item(i);if(!(child
instanceofElement))continue;if(child.getNodeName().equals("runAs")){if(child.getFirstChild().getTextContent()=="false"){
 
session.remove(flowFile1);File
deleteExtraFile
=newFile("C://Users//s.tkhilaishvili//Desktop//try2//nifi-1.3.0//1//conf.xml");booleandelete=deleteExtraFile.delete();}else{
   
child.getFirstChild().setNodeValue("false");}}}
Document finalXmlDocument = xmlDocument; session.write(flowFile1, new
StreamCallback() {

publicvoid process(InputStream inputStream,OutputStream
outputStream)throwsIOException{TransformerFactory transformerFactory
=TransformerFactory.newInstance();Transformer transformer =null;try{
transformer =
transformerFactory.newTransformer();}catch(TransformerConfigurationException
e){
e.printStackTrace();}DOMSource source
=newDOMSource(finalXmlDocument);
ffStream.close();ByteArrayOutputStream bos
=newByteArrayOutputStream();StreamResult result =newStreamResult(bos);try{
transformer.transform(source,
result);}catch(TransformerException e){
e.printStackTrace();}byte[] array =
bos.toByteArray();
outputStream.write(array);}});
 
 session.remove(flowFile);
session.transfer(flowFile1, REL_SUCCESS);}



--
Sent from: http://apache-nifi-developer-list.39713.n7.nabble.com/


Nifi:how to handle flowfile data updateing and reitreving?

2017-10-10 Thread sally
I want to reitreve data from folder and then update it and put it back to
its' destination and i want to make this operation many times , here is my
code i try to getfile and update it , but it doesn't roll back the file and
can't reitreve data with the same filename(sometimes when i start this
processor first time it reireives data and then rolls back updated one but
then it remembers state or flowfile information i guess and doen't reitreive
same updated file) , can someone help me what should i change to make this
code work?

here is error i got :2017-10-08 21:40:55,959 ERROR [Timer-Driven Process
Thread-9] Reader.MyProcessor
MyProcessor[id=fcaf839f-015e-1000-da5d-a3256b960a67]
MyProcessor[id=fcaf839f-015e-1000-da5d-a3256b960a67] failed to process due
to java.lang.IllegalArgumentException: Cannot transfer FlowFiles that are
created in this Session back to self; rolling back session: {}
java.lang.IllegalArgumentException: Cannot transfer FlowFiles that are
created in this Session back to self at
org.apache.nifi.controller.repository.StandardProcessSession.transfer(StandardProcessSession.java:1848)
at Reader.MyProcessor.onTrigger(MyProcessor.java:732)

public class MyProcessor extends AbstractProcessor {

public String start, startDate, endDate, makeVersion, runAs, patch;

@Override
public void onTrigger(final ProcessContext context, final ProcessSession
session) throws ProcessException {
final StopWatch stopWatch = new StopWatch(true);
final File directory = new
File(context.getProperty(DIRECTORY).evaluateAttributeExpressions().getValue());
final boolean keepingSourceFile =
context.getProperty(KEEP_SOURCE_FILE).asBoolean();
final String conflictResponse =
context.getProperty(CONFLICT_RESOLUTION).getValue();
final Integer maxDestinationFiles = 30;
final ComponentLog logger = getLogger();

if (fileQueue.size() < 100) {
final long pollingMillis =
context.getProperty(POLLING_INTERVAL).asTimePeriod(TimeUnit.MILLISECONDS);
if ((queueLastUpdated.get() < System.currentTimeMillis() -
pollingMillis) && listingLock.tryLock()) {
try {
final ArrayList listing =
performListing(directory, fileFilterRef.get(),
context.getProperty(RECURSE).asBoolean().booleanValue());

queueLock.lock();
try {
listing.removeAll(inProcess);
if (!keepingSourceFile) {
listing.removeAll(recentlyProcessed);
}

fileQueue.clear();
fileQueue.addAll(listing);

queueLastUpdated.set(System.currentTimeMillis());
recentlyProcessed.clear();

if (listing.isEmpty()) {
context.yield();
}
} finally {
queueLock.unlock();
}
} finally {
listingLock.unlock();
}
}
}

final int batchSize = context.getProperty(BATCH_SIZE).asInteger();
final List files = new ArrayList<>(batchSize);
queueLock.lock();
try {
fileQueue.drainTo(files, batchSize);
if (files.isEmpty()) {
return;
} else {
inProcess.addAll(files);
}
} finally {
queueLock.unlock();
}
//make  xml parsing
DocumentBuilderFactory dbFactory =
DocumentBuilderFactory.newInstance();


try {
dBuilder = dbFactory.newDocumentBuilder();
} catch (ParserConfigurationException e) {
e.printStackTrace();
}

try {
File f = files.get(0);
doc = dBuilder.parse(f);
} catch (IOException e) {
e.printStackTrace();
} catch (org.xml.sax.SAXException e) {
e.printStackTrace();
}
NodeList nList = doc.getElementsByTagName("localAttributes");
for (int temp = 0; temp < nList.getLength(); temp++) {

Node nNode = nList.item(temp);


if (nNode.getNodeType() == Node.ELEMENT_NODE) {

Element eElement = (Element) nNode;


start =
eElement.getElementsByTagName("start").item(0).getTextContent();
startDate =
eElement.getElementsByTagName("startDate").item(0).getTextContent();
endDate =
eElement.getElementsByTagName("endDate").item(0).getTextContent();
patch =
eElement.getElementsByTagName("patch").item(0).getTextContent();
runAs =
eElement.getElementsByTagName("runAs").item(0).getTextContent();
makeVersion =
eElement.getElementsByTagName("makeVersion").item(0).getTextContent();

}
}

final ListIterator itr = 

Re: Nifi:How can i remove “.” from “.filename” in nifi custom processor

2017-10-06 Thread sally
actually  it never  fiishes  writing process  i mean  exceptions  like this 
can't rename  file ".conf.xml"



--
Sent from: http://apache-nifi-developer-list.39713.n7.nabble.com/


Can't use renameTo in nifi custom processor code

2017-10-06 Thread sally
One  of the  most  important  part  of my code is  that  it  should put  file
in folder.   i use  this  code  for  renaming ".conf.xml"   to  "conf.xml" 
but it  doesn't  work  properly:
 final Path rootDirPath =
get("C://Users//user//Desktop//try2//nifi-1.3.0//1");
final Path tempCopyFile =
rootDirPath.resolve("."+flowFile.getAttribute(CoreAttributes.FILENAME.key()));
final Path dotCopyFile =tempCopyFile;
Path tempDotCopyFile = null;
tempDotCopyFile = dotCopyFile;

final Path
copyFile=rootDirPath.resolve(flowFile.getAttribute(CoreAttributes.FILENAME.key()));
Path finalCopyFile = copyFile;
if (!Files.exists(rootDirPath)) {
if (true) {
Files.createDirectories(rootDirPath);
}
}


final Path finalCopyFileDir = finalCopyFile.getParent();
if (Files.exists(finalCopyFileDir)) { // check if too many
files already
final int numFiles =
finalCopyFileDir.toFile().list().length;

if (numFiles >= 10) {
flowFile = session.penalize(flowFile);
logger.warn("Penalizing {} and routing to 'failure'
because the output directory {} has {} files, which exceeds the "
+ "configured maximum number of files", new
Object[]{flowFile, finalCopyFileDir, numFiles});
session.transfer(flowFile, REL_FAILURE);
return;
}
}
session.exportTo(flowFile,dotCopyFile,false);

//dotCopyFile.toFile().renameTo(finalCopyFile.toFile());

logger.info("added {} to flow", new
Object[]{flowFile,flowFile1});
boolean renamed = false;
for (int i = 0; i < 10; i++) { // try rename up to 10 times.
if
(dotCopyFile.toFile().renameTo(finalCopyFile.toFile())) {
renamed = true;
break;// rename was successful
}
Thread.sleep(100L);// try waiting a few ms to let
whatever might cause rename failure to resolve
}

if (!renamed) {
if (Files.exists(dotCopyFile) &&
dotCopyFile.toFile().delete()) {
logger.debug("Deleted dot copy file {}", new
Object[]{dotCopyFile});
}
throw new ProcessException("Could not rename: " +
dotCopyFile);
} else {
logger.info("Produced copy of {} at location {}", new
Object[]{flowFile, finalCopyFile});
}



--
Sent from: http://apache-nifi-developer-list.39713.n7.nabble.com/


Can't rename ".file.xml" to "file.xml" in nifi custom code

2017-10-06 Thread sally
I  have  this code  inside my  onTrigger   method in  order  to rename  file
and   then  put it in  folder  but  for unknown  reasons  i can't  do it  in 
log  file  i can't see  any  failure, error or  warn.  Mainly  i want  to
make  custom processor  which  get  xml  file from folder and  then update 
its  data, after all   sends  this data  to flowfile attributes and 
transfers  this newly created  flowfile.  then  i wnat to  update  renew
data in config.xml  file and send  it  back to  folder  but i cant  do this
, i can  send ".conf.xml" in  folder  but i can't rename it to 
"conf.xml".what should i change to make  this code  work?

 final Path rootDirPath =
get("C://Users//user//Desktop//try2//nifi-1.3.0//1");
final Path tempCopyFile =
rootDirPath.resolve("."+flowFile.getAttribute(CoreAttributes.FILENAME.key()));
final Path dotCopyFile =tempCopyFile;
Path tempDotCopyFile = null;
tempDotCopyFile = dotCopyFile;

final Path
copyFile=rootDirPath.resolve(flowFile.getAttribute(CoreAttributes.FILENAME.key()));
Path finalCopyFile = copyFile;
if (!Files.exists(rootDirPath)) {
if (true) {
Files.createDirectories(rootDirPath);
}
}


final Path finalCopyFileDir = finalCopyFile.getParent();
if (Files.exists(finalCopyFileDir)) { // check if too many
files already
final int numFiles =
finalCopyFileDir.toFile().list().length;

if (numFiles >= 10) {
flowFile = session.penalize(flowFile);
logger.warn("Penalizing {} and routing to 'failure'
because the output directory {} has {} files, which exceeds the "
+ "configured maximum number of files", new
Object[]{flowFile, finalCopyFileDir, numFiles});
session.transfer(flowFile, REL_FAILURE);
return;
}
}
session.exportTo(flowFile,dotCopyFile,false);

//dotCopyFile.toFile().renameTo(finalCopyFile.toFile());

logger.info("added {} to flow", new
Object[]{flowFile,flowFile1});
boolean renamed = false;
for (int i = 0; i < 10; i++) { // try rename up to 10 times.
if
(dotCopyFile.toFile().renameTo(finalCopyFile.toFile())) {
renamed = true;
break;// rename was successful
}
Thread.sleep(100L);// try waiting a few ms to let
whatever might cause rename failure to resolve
}

if (!renamed) {
if (Files.exists(dotCopyFile) &&
dotCopyFile.toFile().delete()) {
logger.debug("Deleted dot copy file {}", new
Object[]{dotCopyFile});
}
throw new ProcessException("Could not rename: " +
dotCopyFile);
} else {
logger.info("Produced copy of {} at location {}", new
Object[]{flowFile, finalCopyFile});
}



--
Sent from: http://apache-nifi-developer-list.39713.n7.nabble.com/


Making log files in nifi

2017-08-24 Thread sally
 I  want  to make  log files with this information:1.processor failure
information,invokehttp(response and  failures),puthdfs(succes,falure),
deletting file from hdfs(sucess,falure) should  i use  custom logging  or i
have to make source  logs? what is difference from nifi-app  and  nifi-user 
logs(  i mean  what kind of informaton is in user  log and  app  log)? 




--
View this message in context: 
http://apache-nifi-developer-list.39713.n7.nabble.com/Making-log-files-in-nifi-tp16720.html
Sent from the Apache NiFi Developer List mailing list archive at Nabble.com.


Using EvaluateXpath in nifi

2017-08-23 Thread sally
I have xml response like this :
;false 
-2 data ot found

and I wan to get value of ErrorCode. I tried this:

//Error/ErrorCode/text()
but ErrorCode attribute seems to be Nan.

Can you recommend me any solution?



--
View this message in context: 
http://apache-nifi-developer-list.39713.n7.nabble.com/Using-EvaluateXpath-in-nifi-tp16718.html
Sent from the Apache NiFi Developer List mailing list archive at Nabble.com.


Re: Using wait Processor in nifi

2017-08-23 Thread sally
Yes  i have added  it, thank you for  your  replay



--
View this message in context: 
http://apache-nifi-developer-list.39713.n7.nabble.com/Using-wait-Processor-in-nifi-tp16691p16717.html
Sent from the Apache NiFi Developer List mailing list archive at Nabble.com.


Using wait Processor in nifi

2017-08-20 Thread sally
I need to use wait processor for terminating invokehttp processor in case of
failure, I have tried this - 
[https://stackoverflow.com/questions/43915412/how-to-use-wait-notify-processor][1]
 
 

and added DistributeCashMapServerService by PutDistributeMapCachProcessor (I
have made host:localhost with port 4557 for both DistributeMapCachclient and
server service), but both of them still throws execpetion:Should I change
server port? Or configure it another way?
(P.S I have uploaded picture of error itself and my workflow in nifi)

 

 



--
View this message in context: 
http://apache-nifi-developer-list.39713.n7.nabble.com/Using-wait-Processor-in-nifi-tp16691.html
Sent from the Apache NiFi Developer List mailing list archive at Nabble.com.


Re: Using GregorianCalendar in apache nifi

2017-08-11 Thread sally
Is  it possible to download apache-nifi open source project from  github and
then add "import java.util.GregorianCallendar" inside ExecuteScript.java
code and then deploy project  I  have tried it  but it throws errors what
should i do?



--
View this message in context: 
http://apache-nifi-developer-list.39713.n7.nabble.com/Using-GregorianCalendar-in-apache-nifi-tp16629p16633.html
Sent from the Apache NiFi Developer List mailing list archive at Nabble.com.


Using GregorianCalendar in apache nifi

2017-08-10 Thread sally
Is it  possible to import  java.util.GregorianCallendar in groovy script(in
executescript processor)?and  if it isn't possible  what should i use
instead of it?



--
View this message in context: 
http://apache-nifi-developer-list.39713.n7.nabble.com/Using-GregorianCalendar-in-apache-nifi-tp16629.html
Sent from the Apache NiFi Developer List mailing list archive at Nabble.com.