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

The following examples show how to use org.apache.nifi.controller.service.ControllerServiceNode#addReference() . 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: StandardSchedulingContext.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Override
public void leaseControllerService(final String identifier) {
    final ControllerServiceNode serviceNode = serviceProvider.getControllerServiceNode(identifier);
    if (serviceNode == null) {
        throw new IllegalArgumentException("Cannot lease Controller Service because no Controller Service exists with identifier " + identifier);
    }

    if (serviceNode.getState() != ControllerServiceState.ENABLED) {
        throw new IllegalStateException("Cannot lease Controller Service because Controller Service " + serviceNode.getProxiedControllerService().getIdentifier() + " is not currently enabled");
    }

    if (!serviceNode.isValid()) {
        throw new IllegalStateException("Cannot lease Controller Service because Controller Service " + serviceNode.getProxiedControllerService().getIdentifier() + " is not currently valid");
    }

    serviceNode.addReference(processorNode);
}
 
Example 2
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 3
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);
        }
    }
}