Search in sources :

Example 1 with StateManagerProvider

use of org.apache.nifi.components.state.StateManagerProvider in project nifi by apache.

the class StandardProcessGroup method removeProcessor.

@Override
public void removeProcessor(final ProcessorNode processor) {
    boolean removed = false;
    final String id = requireNonNull(processor).getIdentifier();
    writeLock.lock();
    try {
        if (!processors.containsKey(id)) {
            throw new IllegalStateException(processor.getIdentifier() + " is not a member of this Process Group");
        }
        processor.verifyCanDelete();
        for (final Connection conn : processor.getConnections()) {
            conn.verifyCanDelete();
        }
        try (final NarCloseable x = NarCloseable.withComponentNarLoader(processor.getProcessor().getClass(), processor.getIdentifier())) {
            final StandardProcessContext processContext = new StandardProcessContext(processor, controllerServiceProvider, encryptor, getStateManager(processor.getIdentifier()), () -> false);
            ReflectionUtils.quietlyInvokeMethodsWithAnnotation(OnRemoved.class, processor.getProcessor(), processContext);
        } catch (final Exception e) {
            throw new ComponentLifeCycleException("Failed to invoke 'OnRemoved' methods of processor with id " + processor.getIdentifier(), e);
        }
        for (final Map.Entry<PropertyDescriptor, String> entry : processor.getProperties().entrySet()) {
            final PropertyDescriptor descriptor = entry.getKey();
            if (descriptor.getControllerServiceDefinition() != null) {
                final String value = entry.getValue() == null ? descriptor.getDefaultValue() : entry.getValue();
                if (value != null) {
                    final ControllerServiceNode serviceNode = controllerServiceProvider.getControllerServiceNode(value);
                    if (serviceNode != null) {
                        serviceNode.removeReference(processor);
                    }
                }
            }
        }
        processors.remove(id);
        onComponentModified();
        flowController.onProcessorRemoved(processor);
        LogRepositoryFactory.getRepository(processor.getIdentifier()).removeAllObservers();
        final StateManagerProvider stateManagerProvider = flowController.getStateManagerProvider();
        scheduler.submitFrameworkTask(new Runnable() {

            @Override
            public void run() {
                stateManagerProvider.onComponentRemoved(processor.getIdentifier());
            }
        });
        // must copy to avoid a concurrent modification
        final Set<Connection> copy = new HashSet<>(processor.getConnections());
        for (final Connection conn : copy) {
            removeConnection(conn);
        }
        removed = true;
        LOG.info("{} removed from flow", processor);
    } finally {
        if (removed) {
            try {
                ExtensionManager.removeInstanceClassLoader(id);
            } catch (Throwable t) {
            }
        }
        writeLock.unlock();
    }
}
Also used : NarCloseable(org.apache.nifi.nar.NarCloseable) PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) VersionedPropertyDescriptor(org.apache.nifi.registry.flow.VersionedPropertyDescriptor) Connection(org.apache.nifi.connectable.Connection) VersionedConnection(org.apache.nifi.registry.flow.VersionedConnection) ComponentLifeCycleException(org.apache.nifi.controller.exception.ComponentLifeCycleException) NiFiRegistryException(org.apache.nifi.registry.client.NiFiRegistryException) IOException(java.io.IOException) ProcessorInstantiationException(org.apache.nifi.controller.exception.ProcessorInstantiationException) ComponentLifeCycleException(org.apache.nifi.controller.exception.ComponentLifeCycleException) ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) StandardProcessContext(org.apache.nifi.processor.StandardProcessContext) Map(java.util.Map) HashMap(java.util.HashMap) StateManagerProvider(org.apache.nifi.components.state.StateManagerProvider) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet)

Example 2 with StateManagerProvider

use of org.apache.nifi.components.state.StateManagerProvider in project nifi by apache.

the class StandardControllerServiceProviderTest method setup.

@Before
public void setup() throws Exception {
    String id = "id";
    String clazz = "org.apache.nifi.controller.service.util.TestControllerService";
    ControllerServiceProvider provider = new StandardControllerServiceProvider(null, null, null, new StateManagerProvider() {

        @Override
        public StateManager getStateManager(final String componentId) {
            return Mockito.mock(StateManager.class);
        }

        @Override
        public void shutdown() {
        }

        @Override
        public void enableClusterProvider() {
        }

        @Override
        public void disableClusterProvider() {
        }

        @Override
        public void onComponentRemoved(String componentId) {
        }
    }, variableRegistry, nifiProperties);
    ControllerServiceNode node = provider.createControllerService(clazz, id, systemBundle.getBundleDetails().getCoordinate(), null, true);
    proxied = node.getProxiedControllerService();
    implementation = node.getControllerServiceImplementation();
}
Also used : StateManager(org.apache.nifi.components.state.StateManager) StateManagerProvider(org.apache.nifi.components.state.StateManagerProvider) Before(org.junit.Before)

Aggregations

StateManagerProvider (org.apache.nifi.components.state.StateManagerProvider)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 Map (java.util.Map)1 PropertyDescriptor (org.apache.nifi.components.PropertyDescriptor)1 StateManager (org.apache.nifi.components.state.StateManager)1 Connection (org.apache.nifi.connectable.Connection)1 ComponentLifeCycleException (org.apache.nifi.controller.exception.ComponentLifeCycleException)1 ProcessorInstantiationException (org.apache.nifi.controller.exception.ProcessorInstantiationException)1 ControllerServiceNode (org.apache.nifi.controller.service.ControllerServiceNode)1 NarCloseable (org.apache.nifi.nar.NarCloseable)1 StandardProcessContext (org.apache.nifi.processor.StandardProcessContext)1 NiFiRegistryException (org.apache.nifi.registry.client.NiFiRegistryException)1 VersionedConnection (org.apache.nifi.registry.flow.VersionedConnection)1 VersionedPropertyDescriptor (org.apache.nifi.registry.flow.VersionedPropertyDescriptor)1 Before (org.junit.Before)1