如何通过Nipyapi删除RouteOnAttribute处理器中的指定属性
Hey there! I’ve worked with nipyapi alongside NiFi 1.11 before, so I can walk you through exactly how to delete the p11012 attribute from your RouteOnAttribute processor—mimicking the manual "Remove" button action. Here's a step-by-step implementation tailored to your environment:
1. Initialize nipyapi Connection
First, make sure you’ve set up the nipyapi connection to your NiFi instance. If you haven’t already, add this code:
import nipyapi # Point to your NiFi API endpoint nipyapi.config.nifi_config.host = "http://your-nifi-host:port/nifi-api" # Uncomment below if your NiFi uses basic authentication # nipyapi.security.set_service_credentials(username="your-username", password="your-password")
2. Locate the Target RouteOnAttribute Processor
You need to fetch the processor you want to modify. Use either its name (if unique) or UUID:
# Option 1: Fetch by processor name target_processor = nipyapi.nifi.get_processor_by_name("Your-RouteOnAttribute-Processor-Name") # Option 2: Fetch directly by UUID (more reliable if names aren't unique) # target_processor = nipyapi.nifi.get_processor(processor_id="your-processor-uuid")
3. Modify the Processor's Properties
RouteOnAttribute’s routing attributes are stored in the processor's properties dictionary. We’ll filter out the p11012 attribute while keeping the rest of the config intact:
# Get the current configuration of the processor current_config = target_processor.component.config # Filter out the attribute we want to delete updated_properties = { key: value for key, value in current_config.properties.items() if key != "p11012" } # Update the config with the filtered properties current_config.properties = updated_properties
4. Submit the Configuration Change to NiFi
Finally, send the updated config back to NiFi to apply the change:
# Build the update request, preserving existing settings like routing strategy update_request = nipyapi.nifi.UpdateProcessorRequest( revision=target_processor.revision, component=nipyapi.nifi.ProcessorConfigDTO( properties=current_config.properties, routing_strategy=current_config.routing_strategy, description=current_config.description, auto_terminated_relationships=current_config.auto_terminated_relationships ), disconnected_node_acknowledged=True ) # Execute the update nipyapi.nifi.update_processor( processor_id=target_processor.id, update_processor_request=update_request )
Quick Notes
- Before making changes, you can print
current_config.propertiesto double-check the attribute names match what you’re targeting; - Ensure your NiFi user account has write permissions to modify processor configurations;
- This works seamlessly with NiFi 1.11 and the latest nipyapi version, as the property structure for RouteOnAttribute hasn’t changed in a way that breaks compatibility here;
- After running the code, you’ll see the
p11012attribute is gone from the processor’s config in the NiFi UI—just like if you’d clicked the "Remove" button manually.
内容的提问来源于stack exchange,提问作者Hamza bekkouri

