class Nifipi::Nifi

Attributes

host[RW]
port[RW]

Public Class Methods

new(host, port) click to toggle source
# File lib/nifipi.rb, line 10
def initialize(host, port)
  @host = host
  @port = port
  @base_uri = "http://#{@host}:#{@port}/nifi-api/controller"
  @rev_url = "#{@base_uri}/revision"
  @proc_url = "#{@base_uri}/process-groups/root/processors"
  @conn_url = "#{@base_uri}/process-groups/root/connections"
end

Public Instance Methods

create(opts) click to toggle source

Create a processor Params: opts: Hash representation of the ProcessorDTO

Must contain key "type" which is the fully qualified java type of the processor

Examples: Minimal: nifi.create {“type” => “org.apache.nifi.processors.twitter.GetTwitter”}

Custom name: opts = {“type” => “org.<etc>.GetTwitter”, “name” => “random-test-99”} nifi.create opts

# File lib/nifipi.rb, line 51
def create(opts)
  uri = URI(@proc_url)
  data = {
    "revision" => revision,
    "processor" => opts,
  }
  req = Net::HTTP.new(@host, @port)
  res = req.post(uri.path, data.to_json, Nifipi::JSON_HEADER)
  return res
end
create_connection(opts) click to toggle source
# File lib/nifipi.rb, line 68
def create_connection(opts)
  uri = URI(@conn_url)
  data = {
    "revision" => revision,
    "connection" => opts,
  }
  req = Net::HTTP.new(@host, @port)
  res = req.post(uri.path, data.to_json, Nifipi::JSON_HEADER)
  return res
end
get_all() click to toggle source

Returns all the current processes in JSON format

# File lib/nifipi.rb, line 26
def get_all
  uri = URI(@proc_url)
  procs= JSON.parse(Net::HTTP.get_response(uri).body)
  return procs["processors"]
end
get_all_connections() click to toggle source

Queries service for all connections

# File lib/nifipi.rb, line 63
def get_all_connections
  resp = JSON.parse(Net::HTTP.get_response(URI(@conn_url)).body)
  resp["connections"]
end
revision() click to toggle source

Queries NiFi for the current revision object

# File lib/nifipi.rb, line 33
def revision
  uri = URI(@rev_url)
  revision = JSON.parse(Net::HTTP.get_response(uri).body)
  return revision["revision"]
end
version() click to toggle source

Gets the current version of the flow file NiFi is running

# File lib/nifipi.rb, line 20
def version
  rev = revision
  return rev["version"]
end