Java Code Examples for org.apache.nifi.controller.service.ControllerServiceNode#removeReference()

The following examples show how to use org.apache.nifi.controller.service.ControllerServiceNode#removeReference() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractConfiguredComponent.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
private void setProperty(final String name, final String value) {
    if (null == name || null == value) {
        throw new IllegalArgumentException("Name or Value can not be null");
    }

    final PropertyDescriptor descriptor = component.getPropertyDescriptor(name);

    final String oldValue = properties.put(descriptor, value);
    if (!value.equals(oldValue)) {

        if (descriptor.getControllerServiceDefinition() != null) {
            if (oldValue != null) {
                final ControllerServiceNode oldNode = serviceProvider.getControllerServiceNode(oldValue);
                if (oldNode != null) {
                    oldNode.removeReference(this);
                }
            }

            final ControllerServiceNode newNode = serviceProvider.getControllerServiceNode(value);
            if (newNode != null) {
                newNode.addReference(this);
            }
        }

        try {
            component.onPropertyModified(descriptor, oldValue, value);
        } catch (final Exception e) {
            // nothing really to do here...
        }
    }
}
 
Example 2
Source File: AbstractConfiguredComponent.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Removes the property and value for the given property name if a
 * descriptor and value exists for the given name. If the property is
 * optional its value might be reset to default or will be removed entirely
 * if was a dynamic property.
 *
 * @param name the property to remove
 * @return true if removed; false otherwise
 * @throws java.lang.IllegalArgumentException if the name is null
 */
private boolean removeProperty(final String name) {
    if (null == name) {
        throw new IllegalArgumentException("Name can not be null");
    }

    final PropertyDescriptor descriptor = component.getPropertyDescriptor(name);
    String value = null;
    if (!descriptor.isRequired() && (value = properties.remove(descriptor)) != null) {

        if (descriptor.getControllerServiceDefinition() != null) {
            if (value != null) {
                final ControllerServiceNode oldNode = serviceProvider.getControllerServiceNode(value);
                if (oldNode != null) {
                    oldNode.removeReference(this);
                }
            }
        }

        try {
            component.onPropertyModified(descriptor, value, null);
        } catch (final Exception e) {
            logger.error(e.getMessage(), e);
        }

        return true;
    }

    return false;
}
 
Example 3
Source File: FlowController.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Override
public void removeReportingTask(final ReportingTaskNode reportingTaskNode) {
    final ReportingTaskNode existing = reportingTasks.get(reportingTaskNode.getIdentifier());
    if (existing == null || existing != reportingTaskNode) {
        throw new IllegalStateException("Reporting Task " + reportingTaskNode + " does not exist in this Flow");
    }

    reportingTaskNode.verifyCanDelete();

    try (final NarCloseable x = NarCloseable.withComponentNarLoader(reportingTaskNode.getReportingTask().getClass(), reportingTaskNode.getReportingTask().getIdentifier())) {
        ReflectionUtils.quietlyInvokeMethodsWithAnnotation(OnRemoved.class, reportingTaskNode.getReportingTask(), reportingTaskNode.getConfigurationContext());
    }

    for (final Map.Entry<PropertyDescriptor, String> entry : reportingTaskNode.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(reportingTaskNode);
                }
            }
        }
    }

    reportingTasks.remove(reportingTaskNode.getIdentifier());
    ExtensionManager.removeInstanceClassLoaderIfExists(reportingTaskNode.getIdentifier());
}
 
Example 4
Source File: FlowController.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
public void removeRootControllerService(final ControllerServiceNode service) {
    final ControllerServiceNode existing = rootControllerServices.get(requireNonNull(service).getIdentifier());
    if (existing == null) {
        throw new IllegalStateException(service + " is not a member of this Process Group");
    }

    service.verifyCanDelete();

    try (final NarCloseable x = NarCloseable.withComponentNarLoader(service.getControllerServiceImplementation().getClass(), service.getIdentifier())) {
        final ConfigurationContext configurationContext = new StandardConfigurationContext(service, controllerServiceProvider, null, variableRegistry);
        ReflectionUtils.quietlyInvokeMethodsWithAnnotation(OnRemoved.class, service.getControllerServiceImplementation(), configurationContext);
    }

    for (final Map.Entry<PropertyDescriptor, String> entry : service.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 referencedNode = getRootControllerService(value);
                if (referencedNode != null) {
                    referencedNode.removeReference(service);
                }
            }
        }
    }

    rootControllerServices.remove(service.getIdentifier());
    getStateManagerProvider().onComponentRemoved(service.getIdentifier());

    ExtensionManager.removeInstanceClassLoaderIfExists(service.getIdentifier());

    LOG.info("{} removed from Flow Controller", service, this);
}
 
Example 5
Source File: AbstractComponentNode.java    From nifi with Apache License 2.0 5 votes vote down vote up
private void setProperty(final String name, final PropertyConfiguration propertyConfiguration, final Function<PropertyDescriptor, PropertyConfiguration> valueToCompareFunction) {
    if (name == null || propertyConfiguration == null || propertyConfiguration.getRawValue() == null) {
        throw new IllegalArgumentException("Name or Value can not be null");
    }

    final PropertyDescriptor descriptor = getComponent().getPropertyDescriptor(name);
    final PropertyConfiguration propertyModComparisonValue = valueToCompareFunction.apply(descriptor);
    final PropertyConfiguration oldConfiguration = properties.put(descriptor, propertyConfiguration);
    final String effectiveValue = propertyConfiguration.getEffectiveValue(getParameterContext());

    if (!propertyConfiguration.equals(oldConfiguration)) {
        if (descriptor.getControllerServiceDefinition() != null) {
            if (oldConfiguration != null) {
                final ControllerServiceNode oldNode = serviceProvider.getControllerServiceNode(effectiveValue);
                if (oldNode != null) {
                    oldNode.removeReference(this, descriptor);
                }
            }

            final ControllerServiceNode newNode = serviceProvider.getControllerServiceNode(effectiveValue);
            if (newNode != null) {
                newNode.addReference(this, descriptor);
            }
        }
    }

    // In the case of a component "reload", we want to call onPropertyModified when the value is changed from the descriptor's default.
    // However, we do not want to update any controller service references because those are tied to the ComponentNode. We only want to
    // allow the newly created component's internal state to be updated.
    if (!propertyConfiguration.equals(propertyModComparisonValue)) {
        try {
            final String oldValue = oldConfiguration == null ? null : oldConfiguration.getEffectiveValue(getParameterContext());
            onPropertyModified(descriptor, oldValue, effectiveValue);
        } catch (final Exception e) {
            // nothing really to do here...
            logger.error("Failed to notify {} that property {} changed", this, descriptor, e);
        }
    }
}
 
Example 6
Source File: AbstractComponentNode.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Removes the property and value for the given property name if a
 * descriptor and value exists for the given name. If the property is
 * optional its value might be reset to default or will be removed entirely
 * if was a dynamic property.
 *
 * @param name the property to remove
 * @param allowRemovalOfRequiredProperties whether or not the property should be removed if it's required
 * @return true if removed; false otherwise
 * @throws java.lang.IllegalArgumentException if the name is null
 */
private boolean removeProperty(final String name, final boolean allowRemovalOfRequiredProperties) {
    if (null == name) {
        throw new IllegalArgumentException("Name can not be null");
    }

    final PropertyDescriptor descriptor = getComponent().getPropertyDescriptor(name);

    final boolean allowRemoval = allowRemovalOfRequiredProperties || !descriptor.isRequired();
    if (!allowRemoval) {
        return false;
    }

    final PropertyConfiguration propertyConfiguration = properties.remove(descriptor);
    if (propertyConfiguration == null || propertyConfiguration.getRawValue() == null) {
        return false;
    }

    final String value = propertyConfiguration.getEffectiveValue(getParameterContext());
    if (descriptor.getControllerServiceDefinition() != null) {
        if (value != null) {
            final ControllerServiceNode oldNode = serviceProvider.getControllerServiceNode(value);
            if (oldNode != null) {
                oldNode.removeReference(this, descriptor);
            }
        }
    }

    try {
        onPropertyModified(descriptor, value, null);
    } catch (final Exception e) {
        getLogger().error(e.getMessage(), e);
    }

    return true;
}
 
Example 7
Source File: StandardFlowManager.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public void removeReportingTask(final ReportingTaskNode reportingTaskNode) {
    final ReportingTaskNode existing = allReportingTasks.get(reportingTaskNode.getIdentifier());
    if (existing == null || existing != reportingTaskNode) {
        throw new IllegalStateException("Reporting Task " + reportingTaskNode + " does not exist in this Flow");
    }

    reportingTaskNode.verifyCanDelete();

    final Class<?> taskClass = reportingTaskNode.getReportingTask().getClass();
    try (final NarCloseable x = NarCloseable.withComponentNarLoader(flowController.getExtensionManager(), taskClass, reportingTaskNode.getReportingTask().getIdentifier())) {
        ReflectionUtils.quietlyInvokeMethodsWithAnnotation(OnRemoved.class, reportingTaskNode.getReportingTask(), reportingTaskNode.getConfigurationContext());
    }

    for (final Map.Entry<PropertyDescriptor, String> entry : reportingTaskNode.getEffectivePropertyValues().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 = flowController.getControllerServiceProvider().getControllerServiceNode(value);
                if (serviceNode != null) {
                    serviceNode.removeReference(reportingTaskNode, descriptor);
                }
            }
        }
    }

    allReportingTasks.remove(reportingTaskNode.getIdentifier());
    LogRepositoryFactory.removeRepository(reportingTaskNode.getIdentifier());
    processScheduler.onReportingTaskRemoved(reportingTaskNode);

    flowController.getExtensionManager().removeInstanceClassLoader(reportingTaskNode.getIdentifier());
}
 
Example 8
Source File: StandardFlowManager.java    From nifi with Apache License 2.0 5 votes vote down vote up
public void removeRootControllerService(final ControllerServiceNode service) {
    final ControllerServiceNode existing = rootControllerServices.get(requireNonNull(service).getIdentifier());
    if (existing == null) {
        throw new IllegalStateException(service + " is not a member of this Process Group");
    }

    service.verifyCanDelete();

    final ExtensionManager extensionManager = flowController.getExtensionManager();
    final VariableRegistry variableRegistry = flowController.getVariableRegistry();

    try (final NarCloseable x = NarCloseable.withComponentNarLoader(extensionManager, service.getControllerServiceImplementation().getClass(), service.getIdentifier())) {
        final ConfigurationContext configurationContext = new StandardConfigurationContext(service, flowController.getControllerServiceProvider(), null, variableRegistry);
        ReflectionUtils.quietlyInvokeMethodsWithAnnotation(OnRemoved.class, service.getControllerServiceImplementation(), configurationContext);
    }

    for (final Map.Entry<PropertyDescriptor, String> entry : service.getEffectivePropertyValues().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 referencedNode = getRootControllerService(value);
                if (referencedNode != null) {
                    referencedNode.removeReference(service, descriptor);
                }
            }
        }
    }

    rootControllerServices.remove(service.getIdentifier());
    flowController.getStateManagerProvider().onComponentRemoved(service.getIdentifier());

    extensionManager.removeInstanceClassLoader(service.getIdentifier());

    logger.info("{} removed from Flow Controller", service);
}
 
Example 9
Source File: StandardProcessGroup.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
@Override
public void removeControllerService(final ControllerServiceNode service) {
    boolean removed = false;
    writeLock.lock();
    try {
        final ControllerServiceNode existing = controllerServices.get(requireNonNull(service).getIdentifier());
        if (existing == null) {
            throw new IllegalStateException("ControllerService " + service.getIdentifier() + " is not a member of this Process Group");
        }

        service.verifyCanDelete();

        try (final NarCloseable x = NarCloseable.withComponentNarLoader(service.getControllerServiceImplementation().getClass(), service.getIdentifier())) {
            final ConfigurationContext configurationContext = new StandardConfigurationContext(service, controllerServiceProvider, null, variableRegistry);
            ReflectionUtils.quietlyInvokeMethodsWithAnnotation(OnRemoved.class, service.getControllerServiceImplementation(), configurationContext);
        }

        for (final Map.Entry<PropertyDescriptor, String> entry : service.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 referencedNode = getControllerService(value);
                    if (referencedNode != null) {
                        referencedNode.removeReference(service);
                    }
                }
            }
        }

        controllerServices.remove(service.getIdentifier());
        flowController.getStateManagerProvider().onComponentRemoved(service.getIdentifier());

        removed = true;
        LOG.info("{} removed from {}", service, this);

    } finally {
        if (removed) {
            try {
                ExtensionManager.removeInstanceClassLoaderIfExists(service.getIdentifier());
            } catch (Throwable t) {
            }
        }
        writeLock.unlock();
    }
}