Member since
03-20-2017
5
Posts
0
Kudos Received
0
Solutions
03-29-2017
03:26 PM
1 Kudo
An alternative to using an environment variable is to use the file-based Variable Registry, where you could create a file perhaps called var_registry.properties with the entry PGPASSWORD=<my_pg_password> And edit conf/nifi.properties to use that file for the registry: nifi.variable.registry.properties=var_registry.properties Then you could use PGPASSWORD in your groovy script the same way you'd use an environment variable: ${PGPASSWORD}
... View more
03-24-2017
09:02 PM
It is Option #2 above, the file contents are put in the content repo, and the filename is added as an attribute. If you want the file to reside on the local file system, you can use PutFile before your ExecuteScript processor, and you can get at the filename by getting the flow file from the session: def flowFile = session.get() and getting the "filename" attribute from it: def filename = flowFile.getAttribute(CoreAttributes.FILENAME.key()) In your case, it doesn't seem like you really need a file per se; rather you need to get its contents to the "psql" command. For that I'd recommend using ProcessBuilder instead of just copyCommand.execute(). You might be able to do something like this (NOTE: not a complete script, just a snippet): import java.io.*
def pb = new ProcessBuilder('psql --host=<AWS RDS> --port=5432 --dbname=<AWS DB name> --username=<AWS DB user> --no-password --command="copy kiran_test.poc_test from STDIN"')
def p = pb.start()
def psqlStdin = p.getOutputStream()
// Something like:
// def bw = new BufferedWriter(new OutputStreamWriter(psqlStdIn))
// if you are using the Writer paradigm, or use PipedInputStream and PipedOutputStream
session.read(flowFile, {inputStream ->
// write from inputStream (i.e. flow file contents) to psqlStdIn (aka "pipe to psql")
} as InputStreamCallback)
This should alleviate the need to write out the file(s) to the file system, although it becomes a more complex script. A complete alternative is a PostgreSQL Bulk Loader processor or something, that can do all this with the driver 🙂
... View more
03-22-2017
07:08 PM
1 Kudo
Kiran, I believe this has to do with groovy's execute method. I think it is sending the quotes as part of the actual sql to the psql command. Meaning postgres is failing because it doesn't expect the single quotes in a command. Something like the below command would work. import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.SQLException;
import groovy.sql.Sql;
def copyCommand = ['psql', '--host=localhost', '--port=5432', '--dbname=db', '--username=uname', '--no-password', '-c', 'create database kiran_test_0']
println copyCommand //run psql tool as an external process
def process = copyCommand.execute()
def out = new StringBuffer()
def err = new StringBuffer()
process.waitForProcessOutput(out, err) //wait for the process to finish
println "exit code: ${process.exitValue()}"
if (out.size()) {
println "Success: $out"
}
if (err.size()) {
println "Error: $err"
throw new RuntimeException("$err")
}
... View more
03-22-2017
12:28 AM
@Kiran Dasari t2.micro instance has only 1 vCPU core, but apparently RHEL OpenJDK assumes multi core machine by default. There's a github issue (not for NiFi, but Elasticsearch) suggesting use '-XX:-AssumeMP' to disable this assumption. You can add JVM argument from <NIFI_HOME>/conf/bootstrap.conf. I tried this option with t2.micro. Without this, I got the same error as you reported. By adding the option NiFi proceeded startup further, but I also needed to reduce JVM heap size to have NiFi up and running. Changed bootstrap.conf as follows: # JVM memory settings: from 512m to 256m
java.arg.2=-Xms256m
java.arg.3=-Xmx256m
# Add this to disable AssumeMP
# https://github.com/elastic/elasticsearch/issues/22245
java.arg.15=-XX:-AssumeMP
NiFi is running without issue for 30 minutes. I hope it's longer enough to confirm that the configuration can address your issue, too. Thanks, Koji
... View more