Mark Payne created NIFI-6503:
--------------------------------

             Summary: Cleanup code around Controller Service management
                 Key: NIFI-6503
                 URL: https://issues.apache.org/jira/browse/NIFI-6503
             Project: Apache NiFi
          Issue Type: Improvement
          Components: Core Framework
            Reporter: Mark Payne
            Assignee: Mark Payne


In reviewing code for the Controller Services, I see a lot of overlapping code 
that is not very clean. `StandardControllerServiceProvider` maintains a cache 
of all Controller Services. `StandardFlowManager` also keeps a cache of the 
Controller Services that exist at the 'root' or 'controller' level. There's no 
need to be caching these services twice. `StandardFlowManager` should be simply 
delegating calls to `StandardControllerServiceProvider` or vice-versa.

When a Controller Service is removed from the 
`StandardControllerServiceProvider`, it first gets the Process Group of the 
service. If there is none, it's a root-level controller service so the class 
delegates to `StandardFlowManager` to handle the cleanup of the removed 
Controller Service. If there is a Process Group, it delegates the cleanup to 
the associated Process Group. Both of those pieces of code are nearly 
identical. This code should be removed from both places and instead relocated 
to the `StandardControllerServiceProvider` to handle.

`ComponentNode` should probably have a method along the lines of 
`List<ControllerServiceNode> 
getReferencedControllerServices(ControllerServiceProvider provider)` so that 
places that need to iterate over the referenced services can do so much more 
easily. Depending on the actions taken against this List, it may make more 
sense to instead return a `ControllerServiceReferences` type of object that is 
capable of performing those actions instead of requiring the caller iterate 
over each of them. For example, a `removeReference(ComponentNode 
referencingComponent)` method to remove references from all services. This 
would more easily facilitate logging, etc. Also note that this is denoted as a 
`List`, not a `Set` because if a Processor references a Controller Service 
multiple times, it's important to evaluate things like `removeReference` 
multiples times. A convenience method of `ControllerServiceReferences 
distinct()` could be useful here as well.



--
This message was sent by Atlassian JIRA
(v7.6.14#76016)

Reply via email to