Exemple #1
0
def process(flowfile):
  fn = flowfile.getAttribute('filename')
  if 'ethylene' in fn: parser = 'gas'
  elif 'hr' in fn: parser = 'heartrate'
  elif 'power' in fn: parser = 'power'
  path = parser_path + parser + '.py'
  # load the parser if it has been updated
  if parser not in sys.modules or os.path.getmtime(path) > sys.modules[parser].loaded_at:
    try:
      module = imp.load_source(parser, path)
      module.loaded_at = int(time.time())
    except:
      fail(flowfile, 'Loading Module: ' + traceback.format_exc())
      return
  parse_module = sys.modules[parser]

  # Read flowfile content
  data = {}
  instream = session.read(flowfile)
  if hasattr(parse_module, 'format') and parse_module.format.lower() == 'binary':
    data['content'] = IOUtils.toByteArray(instream)
  else:
    data['content'] = IOUtils.toString(instream, StandardCharsets.UTF_8)
  instream.close()

  # Attempt to parse
  try:
    if hasattr(parse_module, 'attributes'):
      for attribute in parse_module.attributes:
        data[attribute] = flowfile.getAttribute(attribute)
    result = parse_module.parse(data)
    flowfile = session.write(flowfile, PyStreamCallback(result))
    session.transfer(flowfile, REL_SUCCESS)
  except:
    fail(flowfile, 'Parsing: ' + traceback.format_exc())
Exemple #2
0
def process(flowfile):
   # Read flowfile content
   data = {}
   instream = session.read(flowfile)
   if hasattr(parse_module, 'format') and parse_module.format.lower() == 'binary':
      data['content'] = IOUtils.toByteArray(instream)
   else:
      data['content'] = IOUtils.toString(instream, StandardCharsets.UTF_8)
   instream.close()

   rootNode = json.load(data)
   for currIndex, elem in enumerate(rootNode):
      rootPath = ${atlas_url} + '/api/atlas/v1/taxanomies/Catalog/terms/'+rootNode[currIndex]['name']
      nextNode(rootNode[currIndex], rootPath)