org.apache.nifi.annotation.behavior.InputRequirement Java Examples

The following examples show how to use org.apache.nifi.annotation.behavior.InputRequirement. 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: HtmlDocumentationWriter.java    From nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Add in the documentation information regarding the component whether it accepts an
 * incoming relationship or not.
 *
 * @param configurableComponent the component to describe
 * @param xmlStreamWriter the stream writer to use
 * @throws XMLStreamException thrown if there was a problem writing the XML
 */
private void writeInputRequirementInfo(ConfigurableComponent configurableComponent, XMLStreamWriter xmlStreamWriter)
        throws XMLStreamException {
    final InputRequirement inputRequirement = configurableComponent.getClass().getAnnotation(InputRequirement.class);

    if(inputRequirement != null) {
        writeSimpleElement(xmlStreamWriter, "h3", "Input requirement: ");
        switch (inputRequirement.value()) {
            case INPUT_FORBIDDEN:
                xmlStreamWriter.writeCharacters("This component does not allow an incoming relationship.");
                break;
            case INPUT_ALLOWED:
                xmlStreamWriter.writeCharacters("This component allows an incoming relationship.");
                break;
            case INPUT_REQUIRED:
                xmlStreamWriter.writeCharacters("This component requires an incoming relationship.");
                break;
            default:
                xmlStreamWriter.writeCharacters("This component does not have input requirement.");
                break;
        }
    }
}
 
Example #2
Source File: ProcessorDetails.java    From nifi with Apache License 2.0 6 votes vote down vote up
public ProcessorDetails(final LoggableComponent<Processor> processor) {
    this.processor = processor.getComponent();
    this.componentLog = processor.getLogger();
    this.bundleCoordinate = processor.getBundleCoordinate();

    this.procClass = this.processor.getClass();
    this.triggerWhenEmpty = procClass.isAnnotationPresent(TriggerWhenEmpty.class);
    this.sideEffectFree = procClass.isAnnotationPresent(SideEffectFree.class);
    this.batchSupported = procClass.isAnnotationPresent(SupportsBatching.class);
    this.triggeredSerially = procClass.isAnnotationPresent(TriggerSerially.class);
    this.triggerWhenAnyDestinationAvailable = procClass.isAnnotationPresent(TriggerWhenAnyDestinationAvailable.class);
    this.eventDrivenSupported = procClass.isAnnotationPresent(EventDriven.class) && !triggeredSerially && !triggerWhenEmpty;
    this.executionNodeRestricted = procClass.isAnnotationPresent(PrimaryNodeOnly.class);

    final boolean inputRequirementPresent = procClass.isAnnotationPresent(InputRequirement.class);
    if (inputRequirementPresent) {
        this.inputRequirement = procClass.getAnnotation(InputRequirement.class).value();
    } else {
        this.inputRequirement = InputRequirement.Requirement.INPUT_ALLOWED;
    }
}
 
Example #3
Source File: MockProcessContext.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new MockProcessContext for the given Processor with given name
 *
 * @param component being mocked
 * @param componentName the name to be given the component;
 * @param stateManager state manager
 * @param variableRegistry variableRegistry
 */
public MockProcessContext(final ConfigurableComponent component,
                          final String componentName,
                          final StateManager stateManager,
                          final VariableRegistry variableRegistry) {
    this.component = Objects.requireNonNull(component);
    this.componentName = componentName == null ? "" : componentName;
    this.inputRequirement = component.getClass().getAnnotation(InputRequirement.class);
    this.stateManager = stateManager;
    this.variableRegistry = variableRegistry;
}
 
Example #4
Source File: StatelessProcessContext.java    From nifi with Apache License 2.0 5 votes vote down vote up
public StatelessProcessContext(final ConfigurableComponent component, final StatelessControllerServiceLookup lookup, final String componentName,
                               final SLF4JComponentLog logger, final StateManager stateManager, final VariableRegistry variableRegistry, final ParameterContext parameterContext) {
    this.component = Objects.requireNonNull(component);
    this.componentName = componentName == null ? "" : componentName;
    this.inputRequirement = component.getClass().getAnnotation(InputRequirement.class);
    this.lookup = lookup;
    this.stateManager = stateManager;
    this.variableRegistry = variableRegistry;
    this.identifier = component.getIdentifier();
    this.logger = logger;
    this.parameterContext = parameterContext;
}
 
Example #5
Source File: AbstractDocumentationWriter.java    From nifi with Apache License 2.0 4 votes vote down vote up
private InputRequirement.Requirement getInputRequirement(final ConfigurableComponent component) {
    final InputRequirement annotation = component.getClass().getAnnotation(InputRequirement.class);
    return annotation == null ? null : annotation.value();
}
 
Example #6
Source File: XmlDocumentationWriter.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Override
protected void writeInputRequirementInfo(final InputRequirement.Requirement requirement) throws IOException {
    writeTextElement("inputRequirement", requirement == null ? null : requirement.name());
}
 
Example #7
Source File: MockPropertyValue.java    From nifi with Apache License 2.0 4 votes vote down vote up
private void validateExpressionScope(boolean attributesAvailable) {
    // language scope is not null, we have attributes available but scope is not equal to FF attributes
    // it means that we're not evaluating against flow file attributes even though attributes are available
    if(expressionLanguageScope != null
            && (attributesAvailable && !ExpressionLanguageScope.FLOWFILE_ATTRIBUTES.equals(expressionLanguageScope))) {
        throw new IllegalStateException("Attempting to evaluate expression language for " + propertyDescriptor.getName()
                + " using flow file attributes but the scope evaluation is set to " + expressionLanguageScope + ". The"
                + " proper scope should be set in the property descriptor using"
                + " PropertyDescriptor.Builder.expressionLanguageSupported(ExpressionLanguageScope)");
    }

    // if the service lookup is an instance of the validation context, we're in the validate() method
    // at this point we don't have any flow file available and we should not care about the scope
    // even though it is defined as FLOWFILE_ATTRIBUTES
    if(expressionLanguageScope != null
            && ExpressionLanguageScope.FLOWFILE_ATTRIBUTES.equals(expressionLanguageScope)
            && this.serviceLookup instanceof MockValidationContext) {
        return;
    }

    // we check if the input requirement is INPUT_FORBIDDEN
    // in that case, we don't care if attributes are not available even though scope is FLOWFILE_ATTRIBUTES
    // it likely means that the property has been defined in a common/abstract class used by multiple processors with
    // different input requirements.
    if(expressionLanguageScope != null
            && ExpressionLanguageScope.FLOWFILE_ATTRIBUTES.equals(expressionLanguageScope)
            && (this.serviceLookup.getInputRequirement() == null
                || this.serviceLookup.getInputRequirement().value().equals(InputRequirement.Requirement.INPUT_FORBIDDEN))) {
        return;
    }

    // if we have a processor where input requirement is INPUT_ALLOWED, we need to check if there is an
    // incoming connection or not. If not, we don't care if attributes are not available even though scope is FLOWFILE_ATTRIBUTES
    if(expressionLanguageScope != null
            && ExpressionLanguageScope.FLOWFILE_ATTRIBUTES.equals(expressionLanguageScope)
            && !((MockProcessContext) this.serviceLookup).hasIncomingConnection()) {
        return;
    }

    // we're trying to evaluate against flow files attributes but we don't have any attributes available.
    if(expressionLanguageScope != null
            && (!attributesAvailable && ExpressionLanguageScope.FLOWFILE_ATTRIBUTES.equals(expressionLanguageScope))) {
        throw new IllegalStateException("Attempting to evaluate expression language for " + propertyDescriptor.getName()
                + " without using flow file attributes but the scope evaluation is set to " + expressionLanguageScope + ". The"
                + " proper scope should be set in the property descriptor using"
                + " PropertyDescriptor.Builder.expressionLanguageSupported(ExpressionLanguageScope)");
    }
}
 
Example #8
Source File: MockProcessContext.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Override
public InputRequirement getInputRequirement() {
    return inputRequirement;
}
 
Example #9
Source File: MockControllerServiceLookup.java    From nifi with Apache License 2.0 4 votes vote down vote up
public InputRequirement getInputRequirement() {
    return null;
}
 
Example #10
Source File: ProcessorDetails.java    From nifi with Apache License 2.0 4 votes vote down vote up
public InputRequirement.Requirement getInputRequirement() {
    return inputRequirement;
}
 
Example #11
Source File: AbstractDocumentationWriter.java    From nifi with Apache License 2.0 votes vote down vote up
protected abstract void writeInputRequirementInfo(InputRequirement.Requirement requirement) throws IOException;