NIFI-250: Merged changes
Project: http://git-wip-us.apache.org/repos/asf/incubator-nifi/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-nifi/commit/ff43b039 Tree: http://git-wip-us.apache.org/repos/asf/incubator-nifi/tree/ff43b039 Diff: http://git-wip-us.apache.org/repos/asf/incubator-nifi/diff/ff43b039 Branch: refs/heads/NIFI-250 Commit: ff43b039085c56bb5f53148e25878ad71972a3db Parents: 7a3d208 2da5792 Author: Mark Payne <[email protected]> Authored: Mon Jan 26 11:53:17 2015 -0500 Committer: Mark Payne <[email protected]> Committed: Mon Jan 26 11:53:17 2015 -0500 ---------------------------------------------------------------------- .../nifi/annotation/behavior/EventDriven.java | 49 ++++ .../annotation/behavior/SideEffectFree.java | 47 ++++ .../annotation/behavior/SupportsBatching.java | 52 ++++ .../annotation/behavior/TriggerSerially.java | 40 +++ .../TriggerWhenAnyDestinationAvailable.java | 42 +++ .../annotation/behavior/TriggerWhenEmpty.java | 42 +++ .../documentation/CapabilityDescription.java | 41 +++ .../nifi/annotation/documentation/Tags.java | 46 +++ .../nifi/annotation/lifecycle/OnAdded.java | 44 +++ .../nifi/annotation/lifecycle/OnDisabled.java | 46 +++ .../nifi/annotation/lifecycle/OnEnabled.java | 64 +++++ .../nifi/annotation/lifecycle/OnRemoved.java | 43 +++ .../nifi/annotation/lifecycle/OnScheduled.java | 62 +++++ .../nifi/annotation/lifecycle/OnShutdown.java | 42 +++ .../nifi/annotation/lifecycle/OnStopped.java | 59 ++++ .../annotation/lifecycle/OnUnscheduled.java | 58 ++++ .../controller/annotation/OnConfigured.java | 3 + .../AbstractSessionFactoryProcessor.java | 4 +- .../annotation/CapabilityDescription.java | 3 + .../nifi/processor/annotation/EventDriven.java | 3 + .../nifi/processor/annotation/OnAdded.java | 2 + .../nifi/processor/annotation/OnRemoved.java | 2 + .../nifi/processor/annotation/OnScheduled.java | 4 +- .../nifi/processor/annotation/OnShutdown.java | 2 + .../nifi/processor/annotation/OnStopped.java | 2 + .../processor/annotation/OnUnscheduled.java | 2 + .../processor/annotation/SideEffectFree.java | 2 + .../processor/annotation/SupportsBatching.java | 2 + .../apache/nifi/processor/annotation/Tags.java | 3 + .../processor/annotation/TriggerSerially.java | 4 +- .../TriggerWhenAnyDestinationAvailable.java | 2 + .../processor/annotation/TriggerWhenEmpty.java | 2 + .../util/ControllerServiceConfiguration.java | 2 +- .../nifi/util/MockControllerServiceLookup.java | 10 + .../apache/nifi/util/MockProcessContext.java | 1 + .../apache/nifi/util/MockProcessSession.java | 1 - .../nifi/util/StandardProcessorTestRunner.java | 231 ++++++++++++++- .../java/org/apache/nifi/util/TestRunner.java | 155 +++++++++++ .../util/TestStandardProcessorTestRunner.java | 86 ++++++ .../cluster/manager/impl/WebClusterManager.java | 26 +- .../nifi/controller/ReportingTaskNode.java | 21 ++ .../service/ControllerServiceNode.java | 9 +- .../service/ControllerServiceProvider.java | 32 ++- .../apache/nifi/controller/FlowController.java | 70 ++++- .../nifi/controller/StandardProcessorNode.java | 46 +-- .../reporting/AbstractReportingTaskNode.java | 99 +++++++ .../scheduling/EventDrivenSchedulingAgent.java | 6 +- .../scheduling/StandardProcessScheduler.java | 120 +++++--- .../service/ControllerServiceLoader.java | 19 +- .../service/StandardControllerServiceNode.java | 85 +++++- .../StandardControllerServiceProvider.java | 65 ++++- .../tasks/ContinuallyRunConnectableTask.java | 6 +- .../tasks/ContinuallyRunProcessorTask.java | 6 +- .../controller/tasks/ReportingTaskWrapper.java | 6 +- .../nifi/groups/StandardProcessGroup.java | 11 +- .../processor/StandardSchedulingContext.java | 4 +- .../org/apache/nifi/util/ReflectionUtils.java | 278 ++++++++++++++----- .../StubAttributeLoggerProcessor.java | 2 +- .../org/apache/nifi/web/api/dto/DtoFactory.java | 28 +- .../nifi/web/controller/ControllerFacade.java | 18 +- .../dao/impl/StandardControllerServiceDAO.java | 9 +- .../webapp/js/nf/canvas/nf-canvas-header.js | 4 +- .../src/main/webapp/js/nf/canvas/nf-settings.js | 102 ++++++- .../hadoop/AbstractHadoopProcessor.java | 5 +- .../hadoop/CreateHadoopSequenceFile.java | 7 +- .../apache/nifi/processors/hadoop/GetHDFS.java | 9 +- .../processors/hadoop/GetHDFSSequenceFile.java | 7 +- .../apache/nifi/processors/hadoop/PutHDFS.java | 6 +- .../apache/nifi/processors/kafka/GetKafka.java | 12 +- .../apache/nifi/processors/kafka/PutKafka.java | 8 +- .../nifi/processors/kafka/TestPutKafka.java | 2 +- .../standard/Base64EncodeContent.java | 41 +-- .../processors/standard/CompressContent.java | 10 +- .../nifi/processors/standard/ControlRate.java | 8 +- .../standard/ConvertCharacterSet.java | 10 +- .../processors/standard/DetectDuplicate.java | 8 +- .../processors/standard/DistributeLoad.java | 14 +- .../processors/standard/EncryptContent.java | 10 +- .../standard/EvaluateRegularExpression.java | 10 +- .../nifi/processors/standard/EvaluateXPath.java | 12 +- .../processors/standard/EvaluateXQuery.java | 10 +- .../standard/ExecuteStreamCommand.java | 8 +- .../processors/standard/GenerateFlowFile.java | 8 +- .../apache/nifi/processors/standard/GetFTP.java | 6 +- .../nifi/processors/standard/GetFile.java | 8 +- .../processors/standard/GetFileTransfer.java | 2 +- .../nifi/processors/standard/GetHTTP.java | 6 +- .../nifi/processors/standard/GetJMSQueue.java | 8 +- .../nifi/processors/standard/GetJMSTopic.java | 14 +- .../nifi/processors/standard/GetSFTP.java | 6 +- .../nifi/processors/standard/HashAttribute.java | 10 +- .../nifi/processors/standard/HashContent.java | 8 +- .../processors/standard/IdentifyMimeType.java | 10 +- .../nifi/processors/standard/InvokeHTTP.java | 6 +- .../nifi/processors/standard/ListenHTTP.java | 8 +- .../nifi/processors/standard/ListenUDP.java | 12 +- .../nifi/processors/standard/LogAttribute.java | 8 +- .../nifi/processors/standard/MergeContent.java | 12 +- .../nifi/processors/standard/ModifyBytes.java | 8 +- .../processors/standard/MonitorActivity.java | 10 +- .../nifi/processors/standard/PostHTTP.java | 10 +- .../nifi/processors/standard/PutEmail.java | 6 +- .../apache/nifi/processors/standard/PutFTP.java | 8 +- .../nifi/processors/standard/PutFile.java | 6 +- .../apache/nifi/processors/standard/PutJMS.java | 6 +- .../nifi/processors/standard/PutSFTP.java | 6 +- .../nifi/processors/standard/ReplaceText.java | 10 +- .../standard/ReplaceTextWithMapping.java | 10 +- .../processors/standard/RouteOnAttribute.java | 10 +- .../processors/standard/RouteOnContent.java | 10 +- .../nifi/processors/standard/ScanAttribute.java | 12 +- .../nifi/processors/standard/ScanContent.java | 10 +- .../processors/standard/SegmentContent.java | 10 +- .../nifi/processors/standard/SplitContent.java | 10 +- .../nifi/processors/standard/SplitText.java | 10 +- .../nifi/processors/standard/SplitXml.java | 10 +- .../nifi/processors/standard/TransformXml.java | 10 +- .../nifi/processors/standard/UnpackContent.java | 10 +- .../nifi/processors/standard/ValidateXml.java | 12 +- .../standard/RESTServiceContentModified.java | 2 +- .../standard/TestCompressContent.java | 5 +- .../standard/TestConvertCharacterSet.java | 3 - .../standard/TestDetectDuplicate.java | 10 +- .../nifi/processors/standard/TestGetHTTP.java | 16 +- .../processors/standard/TestInvokeHTTP.java | 4 +- .../ControllerStatusReportingTask.java | 13 +- .../nifi/controller/MonitorDiskUsage.java | 7 +- .../apache/nifi/controller/MonitorMemory.java | 12 +- .../ganglia/StandardGangliaReporter.java | 15 +- .../cache/client/DistributedMapCacheClient.java | 5 + .../cache/client/DistributedSetCacheClient.java | 5 + .../DistributedMapCacheClientService.java | 9 +- .../DistributedSetCacheClientService.java | 9 +- .../cache/server/DistributedCacheServer.java | 6 +- .../cache/server/DistributedSetCacheServer.java | 6 +- .../server/map/DistributedMapCacheServer.java | 5 + .../nifi/ssl/StandardSSLContextService.java | 9 +- .../apache/nifi/ssl/SSLContextServiceTest.java | 182 +++++------- .../org/apache/nifi/ssl/SSLContextService.java | 5 + .../processors/attributes/UpdateAttribute.java | 11 +- 140 files changed, 2583 insertions(+), 656 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/ff43b039/nifi/nifi-mock/src/main/java/org/apache/nifi/util/MockControllerServiceLookup.java ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/ff43b039/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-cluster/src/main/java/org/apache/nifi/cluster/manager/impl/WebClusterManager.java ---------------------------------------------------------------------- diff --cc nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-cluster/src/main/java/org/apache/nifi/cluster/manager/impl/WebClusterManager.java index 17a6452,656759a..5f1c460 --- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-cluster/src/main/java/org/apache/nifi/cluster/manager/impl/WebClusterManager.java +++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-cluster/src/main/java/org/apache/nifi/cluster/manager/impl/WebClusterManager.java @@@ -63,6 -63,6 +63,7 @@@ import javax.xml.validation.Schema import javax.xml.validation.SchemaFactory; import javax.xml.validation.Validator; ++import org.apache.commons.lang3.StringUtils; import org.apache.nifi.admin.service.AuditService; import org.apache.nifi.cluster.BulletinsPayload; import org.apache.nifi.cluster.ClusterNodeInformation; @@@ -117,6 -117,6 +118,7 @@@ import org.apache.nifi.cluster.protocol import org.apache.nifi.cluster.protocol.message.PrimaryRoleAssignmentMessage; import org.apache.nifi.cluster.protocol.message.ProtocolMessage; import org.apache.nifi.cluster.protocol.message.ProtocolMessage.MessageType; ++import org.apache.nifi.cluster.protocol.message.ReconnectionFailureMessage; import org.apache.nifi.cluster.protocol.message.ReconnectionRequestMessage; import org.apache.nifi.components.PropertyDescriptor; import org.apache.nifi.controller.ControllerService; @@@ -191,7 -191,7 +193,6 @@@ import org.apache.nifi.web.api.entity.P import org.apache.nifi.web.api.entity.RemoteProcessGroupEntity; import org.apache.nifi.web.api.entity.RemoteProcessGroupsEntity; import org.apache.nifi.web.util.WebUtils; --import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.DOMException; @@@ -203,8 -203,8 +204,6 @@@ import org.xml.sax.SAXParseException import com.sun.jersey.api.client.ClientResponse; --import org.apache.nifi.cluster.protocol.message.ReconnectionFailureMessage; -- /** * Provides a cluster manager implementation. The manager federates incoming * HTTP client requests to the nodes' external API using the HTTP protocol. The @@@ -1289,18 -1289,6 +1288,18 @@@ public class WebClusterManager implemen } } + /** + * Adds an instance of a specified controller service. + * + * @param type + * @param id + * @param properties + * @return + */ + @Override - public ControllerServiceNode createControllerService(String type) { - return controllerServiceProvider.createControllerService(type); ++ public ControllerServiceNode createControllerService(final String type, final boolean firstTimeAdded) { ++ return controllerServiceProvider.createControllerService(type, firstTimeAdded); + } @Override public ControllerService getControllerService(String serviceIdentifier) { @@@ -1323,10 -1311,27 +1322,27 @@@ } @Override - public ControllerServiceNode createControllerService(final String type, final String id, final boolean firstTimeAdded) { - return controllerServiceProvider.createControllerService(type, id, firstTimeAdded); + public String getControllerServiceName(final String serviceIdentifier) { + return controllerServiceProvider.getControllerServiceName(serviceIdentifier); } - + + @Override + public void removeControllerService(final ControllerServiceNode serviceNode) { + controllerServiceProvider.removeControllerService(serviceNode); + } + + + @Override + public void enableControllerService(final ControllerServiceNode serviceNode) { + controllerServiceProvider.enableControllerService(serviceNode); + } + + @Override + public void disableControllerService(final ControllerServiceNode serviceNode) { + controllerServiceProvider.disableControllerService(serviceNode); + } + + /** * Handle a bulletins message. * http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/ff43b039/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/controller/service/ControllerServiceProvider.java ---------------------------------------------------------------------- diff --cc nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/controller/service/ControllerServiceProvider.java index ba00799,5f2fc2e..54a506e --- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/controller/service/ControllerServiceProvider.java +++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/controller/service/ControllerServiceProvider.java @@@ -24,14 -25,15 +25,14 @@@ import org.apache.nifi.controller.Contr public interface ControllerServiceProvider extends ControllerServiceLookup { /** - * Creates a new Controller Service of the specified type - * Creates a new Controller Service of the given type and assigns it the given id. If <code>firstTimeadded</code> ++ * Creates a new Controller Service of the specified type and assigns it the given id. If <code>firstTimeadded</code> + * is true, calls any methods that are annotated with {@link OnAdded} * * @param type -- * @param id - * @param properties + * @param firstTimeAdded * @return */ - ControllerServiceNode createControllerService(String type); - ControllerServiceNode createControllerService(String type, String id, boolean firstTimeAdded); ++ ControllerServiceNode createControllerService(String type, boolean firstTimeAdded); /** * Gets the controller service node for the specified identifier. Returns http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/ff43b039/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/FlowController.java ---------------------------------------------------------------------- diff --cc nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/FlowController.java index ae0ef97,7cb2874..38c8d42 --- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/FlowController.java +++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/FlowController.java @@@ -48,8 -48,9 +48,10 @@@ import java.util.concurrent.locks.Reent import javax.net.ssl.SSLContext; +import org.apache.commons.lang3.StringUtils; import org.apache.nifi.admin.service.UserService; + import org.apache.nifi.annotation.lifecycle.OnAdded; + import org.apache.nifi.annotation.lifecycle.OnRemoved; import org.apache.nifi.cluster.BulletinsPayload; import org.apache.nifi.cluster.HeartbeatPayload; import org.apache.nifi.cluster.protocol.DataFlow; @@@ -2523,32 -2556,29 +2556,56 @@@ public class FlowController implements return reportingTasks.values(); } - + /** + * Recursively stops all Processors and Reporting Tasks that are referencing the given Controller Service, + * as well as disabling any Controller Service that references this Controller Service (and stops + * all Reporting Task or Controller Service that is referencing it, and so on). + * @param serviceNode + */ + public void deactiveReferencingComponents(final ControllerServiceNode serviceNode) { + final ControllerServiceReference reference = serviceNode.getReferences(); + + final Set<ConfiguredComponent> components = reference.getActiveReferences(); + for (final ConfiguredComponent component : components) { + if ( component instanceof ControllerServiceNode ) { + deactiveReferencingComponents((ControllerServiceNode) component); + // TODO: DISABLE CONTROLLER SERVICE! + } else if ( component instanceof ReportingTaskNode ) { + stopReportingTask((ReportingTaskNode) component); + } else if ( component instanceof ProcessorNode ) { + final ProcessorNode procNode = (ProcessorNode) component; + stopProcessor(procNode.getProcessGroup().getIdentifier(), procNode.getIdentifier()); + } + } + } + + @Override - public ControllerServiceNode createControllerService(final String type) { - return controllerServiceProvider.createControllerService(type); ++ public ControllerServiceNode createControllerService(final String type, final boolean firstTimeAdded) { ++ return controllerServiceProvider.createControllerService(type, firstTimeAdded); ++ } ++ + public void enableReportingTask(final ReportingTaskNode reportingTaskNode) { + reportingTaskNode.verifyCanEnable(); + + processScheduler.enableReportingTask(reportingTaskNode); + } + + public void disableReportingTask(final ReportingTaskNode reportingTaskNode) { + reportingTaskNode.verifyCanDisable(); + + processScheduler.disableReportingTask(reportingTaskNode); + } + + @Override + public void enableControllerService(final ControllerServiceNode serviceNode) { + serviceNode.verifyCanEnable(); + controllerServiceProvider.enableControllerService(serviceNode); + } + + @Override + public void disableControllerService(final ControllerServiceNode serviceNode) { + serviceNode.verifyCanDisable(); + controllerServiceProvider.disableControllerService(serviceNode); } @Override @@@ -2572,10 -2607,9 +2629,13 @@@ } @Override + public String getControllerServiceName(final String serviceIdentifier) { + return controllerServiceProvider.getControllerServiceName(serviceIdentifier); + } + + public void removeControllerService(final ControllerServiceNode serviceNode) { + controllerServiceProvider.removeControllerService(serviceNode); + } // // Counters http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/ff43b039/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/service/StandardControllerServiceNode.java ---------------------------------------------------------------------- diff --cc nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/service/StandardControllerServiceNode.java index e3e6e6b,741caec..b829bbd --- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/service/StandardControllerServiceNode.java +++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/service/StandardControllerServiceNode.java @@@ -122,4 -136,61 +136,61 @@@ public class StandardControllerServiceN throw new IllegalStateException("Cannot modify Controller Service configuration because it is currently enabled. Please disable the Controller Service first."); } } + + @Override + public void setProperty(final String name, final String value) { + super.setProperty(name, value); + + onConfigured(); + } + + @Override + public boolean removeProperty(String name) { + final boolean removed = super.removeProperty(name); + if ( removed ) { + onConfigured(); + } + + return removed; + } + + @SuppressWarnings("deprecation") + private void onConfigured() { + try (final NarCloseable x = NarCloseable.withNarLoader()) { + final ConfigurationContext configContext = new StandardConfigurationContext(this, serviceProvider); + ReflectionUtils.invokeMethodsWithAnnotation(OnConfigured.class, implementation, configContext); + } catch (final Exception e) { + throw new ProcessorLifeCycleException("Failed to invoke On-Configured Lifecycle methods of " + implementation, e); + } + } + + @Override + public void verifyCanDelete() { + if ( !isDisabled() ) { + throw new IllegalStateException(implementation + " cannot be deleted because it is not disabled"); + } + } + + @Override + public void verifyCanDisable() { + final ControllerServiceReference references = getReferences(); - final int numRunning = references.getRunningReferences().size(); ++ final int numRunning = references.getActiveReferences().size(); + if ( numRunning > 0 ) { + throw new IllegalStateException(implementation + " cannot be disabled because it is referenced by " + numRunning + " components that are currently running"); + } + } + + @Override + public void verifyCanEnable() { + if ( !isDisabled() ) { + throw new IllegalStateException(implementation + " cannot be enabled because it is not disabled"); + } + } + + @Override + public void verifyCanUpdate() { + if ( !isDisabled() ) { + throw new IllegalStateException(implementation + " cannot be updated because it is not disabled"); + } + } } http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/ff43b039/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/service/StandardControllerServiceProvider.java ---------------------------------------------------------------------- diff --cc nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/service/StandardControllerServiceProvider.java index 66cc541,a40e43e..b07fc3f --- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/service/StandardControllerServiceProvider.java +++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/service/StandardControllerServiceProvider.java @@@ -28,12 -28,18 +28,18 @@@ import java.util.HashSet import java.util.List; import java.util.Map; import java.util.Set; +import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; + import org.apache.nifi.annotation.lifecycle.OnAdded; + import org.apache.nifi.annotation.lifecycle.OnEnabled; + import org.apache.nifi.annotation.lifecycle.OnDisabled; + import org.apache.nifi.annotation.lifecycle.OnRemoved; + import org.apache.nifi.controller.ConfigurationContext; import org.apache.nifi.controller.ControllerService; import org.apache.nifi.controller.ValidationContextFactory; -import org.apache.nifi.controller.exception.ControllerServiceAlreadyExistsException; import org.apache.nifi.controller.exception.ControllerServiceNotFoundException; + import org.apache.nifi.controller.exception.ProcessorLifeCycleException; import org.apache.nifi.nar.ExtensionManager; import org.apache.nifi.nar.NarCloseable; import org.apache.nifi.processor.StandardValidationContextFactory; @@@ -90,12 -97,14 +97,12 @@@ public class StandardControllerServiceP } @Override - public ControllerServiceNode createControllerService(final String type) { - public ControllerServiceNode createControllerService(final String type, final String id, final boolean firstTimeAdded) { - if (type == null || id == null) { ++ public ControllerServiceNode createControllerService(final String type, final boolean firstTimeAdded) { + if (type == null) { throw new NullPointerException(); } - if (controllerServices.containsKey(id)) { - throw new ControllerServiceAlreadyExistsException(id); - } - + + final String id = UUID.randomUUID().toString(); final ClassLoader currentContextClassLoader = Thread.currentThread().getContextClassLoader(); try { final ClassLoader cl = ExtensionManager.getClassLoader(type); @@@ -134,9 -144,18 +142,17 @@@ final ValidationContextFactory validationContextFactory = new StandardValidationContextFactory(this); - final ControllerServiceNode serviceNode = new StandardControllerServiceNode(proxiedService, id, validationContextFactory, this); + final ControllerServiceNode serviceNode = new StandardControllerServiceNode(proxiedService, originalService, id, validationContextFactory, this); serviceNodeHolder.set(serviceNode); - serviceNode.setAnnotationData(null); - serviceNode.setName(id); + serviceNode.setName(rawClass.getSimpleName()); + + if ( firstTimeAdded ) { + try (final NarCloseable x = NarCloseable.withNarLoader()) { + ReflectionUtils.invokeMethodsWithAnnotation(OnAdded.class, originalService); + } catch (final Exception e) { + throw new ProcessorLifeCycleException("Failed to invoke On-Added Lifecycle methods of " + originalService, e); + } + } this.controllerServices.put(id, serviceNode); return serviceNode; @@@ -184,8 -228,19 +225,24 @@@ } @Override + public String getControllerServiceName(final String serviceIdentifier) { + final ControllerServiceNode node = getControllerServiceNode(serviceIdentifier); + return node == null ? null : node.getName(); + } ++ + public void removeControllerService(final ControllerServiceNode serviceNode) { + final ControllerServiceNode existing = controllerServices.get(serviceNode.getIdentifier()); + if ( existing == null || existing != serviceNode ) { + throw new IllegalStateException("Controller Service " + serviceNode + " does not exist in this Flow"); + } + + serviceNode.verifyCanDelete(); + + try (final NarCloseable x = NarCloseable.withNarLoader()) { + final ConfigurationContext configurationContext = new StandardConfigurationContext(serviceNode, this); + ReflectionUtils.quietlyInvokeMethodsWithAnnotation(OnRemoved.class, serviceNode.getControllerServiceImplementation(), configurationContext); + } + + controllerServices.remove(serviceNode.getIdentifier()); + } } http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/ff43b039/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/dto/DtoFactory.java ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/ff43b039/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/controller/ControllerFacade.java ---------------------------------------------------------------------- diff --cc nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/controller/ControllerFacade.java index 27c60bb,2dec8fc..603c1d2 --- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/controller/ControllerFacade.java +++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/controller/ControllerFacade.java @@@ -405,8 -406,12 +405,12 @@@ public class ControllerFacade implement } @Override - public ControllerServiceNode createControllerService(String type) { - return flowController.createControllerService(type); - public ControllerServiceNode createControllerService(String type, String id, boolean firstTimeAdded) { - return flowController.createControllerService(type, id, firstTimeAdded); ++ public ControllerServiceNode createControllerService(final String type, final boolean firstTimeAdded) { ++ return flowController.createControllerService(type, firstTimeAdded); + } + + public void removeControllerService(ControllerServiceNode serviceNode) { + flowController.removeControllerService(serviceNode); } @Override @@@ -428,13 -433,17 +432,23 @@@ public boolean isControllerServiceEnabled(final String serviceIdentifier) { return flowController.isControllerServiceEnabled(serviceIdentifier); } + + @Override + public String getControllerServiceName(final String serviceIdentifier) { + return flowController.getControllerServiceName(serviceIdentifier); + } + + @Override + public void enableControllerService(final ControllerServiceNode serviceNode) { + flowController.enableControllerService(serviceNode); + } + + @Override + public void disableControllerService(ControllerServiceNode serviceNode) { + flowController.disableControllerService(serviceNode); + } + /** * Gets the status of this controller. * http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/ff43b039/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/impl/StandardControllerServiceDAO.java ---------------------------------------------------------------------- diff --cc nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/impl/StandardControllerServiceDAO.java index 6feab86,0cdde6b..116394c --- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/impl/StandardControllerServiceDAO.java +++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/impl/StandardControllerServiceDAO.java @@@ -16,8 -16,9 +16,7 @@@ */ package org.apache.nifi.web.dao.impl; --import java.util.HashMap; - import java.util.Map; + import java.util.HashSet; -import java.util.Map; import java.util.Set; import org.apache.nifi.controller.FlowController; @@@ -56,10 -57,8 +55,8 @@@ public class StandardControllerServiceD */ @Override public ControllerServiceNode createControllerService(final ControllerServiceDTO controllerServiceDTO) { - final Map<String, String> temp = new HashMap<>(); - // create the controller service - final ControllerServiceNode controllerService = flowController.createControllerService(controllerServiceDTO.getType(), controllerServiceDTO.getName(), temp); - final ControllerServiceNode controllerService = flowController.createControllerService(controllerServiceDTO.getType(), controllerServiceDTO.getName(), true); ++ final ControllerServiceNode controllerService = flowController.createControllerService(controllerServiceDTO.getType(), true); return controllerService; }
