1
votes

Trying to create a PutMongo processor in nipyapi connected with local instance. I have specified all the required configurations but doesnt seem to work.

PutMongoFile = canvas.create_processor(
    root_process_group,
    processor_PutMongo, 
    (randrange(0,4000), randrange(0,4000)), 
    name=None,
    config=processor_PutMongo_config)

Get the following error:

*AttributeError                            Traceback (most recent call last)
<ipython-input-48-ef1b815cdbdb> in <module>
----> 1 PutMongoFile = canvas.create_processor(root_process_group,processor_PutMongo,(randrange(0,4000),randrange(0,4000)),name=None,config=processor_PutMongo_config)
~\AppData\Roaming\Python\Python38\site-packages\nipyapi\canvas.py in create_processor(parent_pg, processor, location, name, config)
    503     """
    504     if name is None:
--> 505         processor_name = processor.type.split('.')[-1]
    506     else:
    507         processor_name = name
AttributeError: 'list' object has no attribute 'type'*

Appreciate any help!!!

2
Did you follow this? community.cloudera.com/t5/Community-Articles/… Specifically the sections ##get the processors processor_GenFlowFile = canvas.get_processor_type('org.apache.nifi.processors.standard.GenerateFlowFile', identifier_type='name') processor_PutFile = canvas.get_processor_type('org.apache.nifi.processors.standard.PutFile', identifier_type='name') - Sdairs

2 Answers

1
votes

We resolved this in an Issue discussion on the Repo here. The get_processor_type method is greedy by default and will return a list if more than one Processor Type is found, in this case finding both PutMongo and PutMongoRecord. I have updated the method to allow exact matching only, and implemented better checks for this in the next release

0
votes
processor_PutMongo = canvas.get_processor_type('org.apache.nifi.processors.mongodb.PutMongo', identifier_type='name')

This returns a list of dictionaries containing details of both the processors, PutMongo & PutMongoRecord.

This is the exact JSON you would get when you would be printing processor_PutMongo:

[
   {
      "bundle":{
         "artifact":"nifi-mongodb-nar",
         "group":"org.apache.nifi",
         "version":"1.13.2"
      },
      "controller_service_apis":"None",
      "deprecation_reason":"None",
      "description":"Creates FlowFiles from documents in MongoDB loaded by a user-specified query.",
      "explicit_restrictions":"None",
      "restricted":false,
      "tags":[
         "read",
         "get",
         "mongodb"
      ],
      "type":"org.apache.nifi.processors.mongodb.GetMongo",
      "usage_restriction":"None"
   },
   {
      "bundle":{
         "artifact":"nifi-mongodb-nar",
         "group":"org.apache.nifi",
         "version":"1.13.2"
      },
      "controller_service_apis":"None",
      "deprecation_reason":"None",
      "description": "A record-based version of GetMongo that uses the Record writers to write the MongoDB result set.",
      "explicit_restrictions":"None",
      "restricted":false,
      "tags":[
         "mongo",
         "get",
         "fetch",
         "record",
         "json",
         "mongodb"
      ],
      "type":"org.apache.nifi.processors.mongodb.GetMongoRecord",
      "usage_restriction":"None"
   }
]

The shortest solution would be to just extract either the first or the second element of the list by their indexes.

For e.g.

PutMongo = canvas.create_processor(new_processor_group, processor_PutMongo[0],(randrange(0,20000),randrange(0,20000)),name=None,config=processor_PutMongo_config)