Search in sources :

Example 46 with Relationship

use of org.apache.nifi.processor.Relationship in project nifi by apache.

the class Connectables method anyRelationshipAvailable.

public static boolean anyRelationshipAvailable(final Connectable connectable) {
    for (final Relationship relationship : connectable.getRelationships()) {
        final Collection<Connection> connections = connectable.getConnections(relationship);
        boolean available = true;
        for (final Connection connection : connections) {
            if (connection.getFlowFileQueue().isFull()) {
                available = false;
                break;
            }
        }
        if (available) {
            return true;
        }
    }
    return false;
}
Also used : Relationship(org.apache.nifi.processor.Relationship) Connection(org.apache.nifi.connectable.Connection)

Example 47 with Relationship

use of org.apache.nifi.processor.Relationship in project nifi by apache.

the class StandardFlowSynchronizer method updateProcessor.

private void updateProcessor(final ProcessorNode procNode, final ProcessorDTO processorDTO, final ProcessGroup processGroup, final FlowController controller) throws ProcessorInstantiationException {
    final ProcessorConfigDTO config = processorDTO.getConfig();
    procNode.setProcessGroup(processGroup);
    procNode.setLossTolerant(config.isLossTolerant());
    procNode.setPenalizationPeriod(config.getPenaltyDuration());
    procNode.setYieldPeriod(config.getYieldDuration());
    procNode.setBulletinLevel(LogLevel.valueOf(config.getBulletinLevel()));
    updateNonFingerprintedProcessorSettings(procNode, processorDTO);
    if (config.getSchedulingStrategy() != null) {
        procNode.setSchedulingStrategy(SchedulingStrategy.valueOf(config.getSchedulingStrategy()));
    }
    if (config.getExecutionNode() != null) {
        procNode.setExecutionNode(ExecutionNode.valueOf(config.getExecutionNode()));
    }
    // must set scheduling strategy before these two
    procNode.setMaxConcurrentTasks(config.getConcurrentlySchedulableTaskCount());
    procNode.setScheduldingPeriod(config.getSchedulingPeriod());
    if (config.getRunDurationMillis() != null) {
        procNode.setRunDuration(config.getRunDurationMillis(), TimeUnit.MILLISECONDS);
    }
    procNode.setAnnotationData(config.getAnnotationData());
    if (config.getAutoTerminatedRelationships() != null) {
        final Set<Relationship> relationships = new HashSet<>();
        for (final String rel : config.getAutoTerminatedRelationships()) {
            relationships.add(procNode.getRelationship(rel));
        }
        procNode.setAutoTerminatedRelationships(relationships);
    }
    procNode.setProperties(config.getProperties());
    final ScheduledState scheduledState = ScheduledState.valueOf(processorDTO.getState());
    if (ScheduledState.RUNNING.equals(scheduledState)) {
        controller.startProcessor(processGroup.getIdentifier(), procNode.getIdentifier());
    } else if (ScheduledState.DISABLED.equals(scheduledState)) {
        processGroup.disableProcessor(procNode);
    } else if (ScheduledState.STOPPED.equals(scheduledState)) {
        controller.stopProcessor(processGroup.getIdentifier(), procNode.getIdentifier());
    }
}
Also used : ProcessorConfigDTO(org.apache.nifi.web.api.dto.ProcessorConfigDTO) Relationship(org.apache.nifi.processor.Relationship) HashSet(java.util.HashSet)

Example 48 with Relationship

use of org.apache.nifi.processor.Relationship in project nifi by apache.

the class StandardProcessorNode method isValid.

@Override
public boolean isValid() {
    try {
        final ValidationContext validationContext = getValidationContext();
        final Collection<ValidationResult> validationResults = super.validate(validationContext);
        for (final ValidationResult result : validationResults) {
            if (!result.isValid()) {
                return false;
            }
        }
        for (final Relationship undef : getUndefinedRelationships()) {
            if (!isAutoTerminated(undef)) {
                return false;
            }
        }
        switch(getInputRequirement()) {
            case INPUT_ALLOWED:
                break;
            case INPUT_FORBIDDEN:
                {
                    if (!getIncomingNonLoopConnections().isEmpty()) {
                        return false;
                    }
                    break;
                }
            case INPUT_REQUIRED:
                {
                    if (getIncomingNonLoopConnections().isEmpty()) {
                        return false;
                    }
                    break;
                }
        }
    } catch (final Throwable t) {
        LOG.warn("Failed during validation", t);
        return false;
    }
    return true;
}
Also used : Relationship(org.apache.nifi.processor.Relationship) ValidationResult(org.apache.nifi.components.ValidationResult) ValidationContext(org.apache.nifi.components.ValidationContext)

Example 49 with Relationship

use of org.apache.nifi.processor.Relationship in project nifi by apache.

the class StandardProcessorNode method getValidationErrors.

@Override
public Collection<ValidationResult> getValidationErrors() {
    final List<ValidationResult> results = new ArrayList<>();
    try {
        // we are willing to make in order to save on validation costs that would be unnecessary most of the time.
        if (getScheduledState() == ScheduledState.STOPPED) {
            final ValidationContext validationContext = getValidationContext();
            final Collection<ValidationResult> validationResults = super.validate(validationContext);
            for (final ValidationResult result : validationResults) {
                if (!result.isValid()) {
                    results.add(result);
                }
            }
            for (final Relationship relationship : getUndefinedRelationships()) {
                if (!isAutoTerminated(relationship)) {
                    final ValidationResult error = new ValidationResult.Builder().explanation("Relationship '" + relationship.getName() + "' is not connected to any component and is not auto-terminated").subject("Relationship " + relationship.getName()).valid(false).build();
                    results.add(error);
                }
            }
            switch(getInputRequirement()) {
                case INPUT_ALLOWED:
                    break;
                case INPUT_FORBIDDEN:
                    {
                        final int incomingConnCount = getIncomingNonLoopConnections().size();
                        if (incomingConnCount != 0) {
                            results.add(new ValidationResult.Builder().explanation("Processor does not allow upstream connections but currently has " + incomingConnCount).subject("Upstream Connections").valid(false).build());
                        }
                        break;
                    }
                case INPUT_REQUIRED:
                    {
                        if (getIncomingNonLoopConnections().isEmpty()) {
                            results.add(new ValidationResult.Builder().explanation("Processor requires an upstream connection but currently has none").subject("Upstream Connections").valid(false).build());
                        }
                        break;
                    }
            }
        }
    } catch (final Throwable t) {
        results.add(new ValidationResult.Builder().explanation("Failed to run validation due to " + t.toString()).valid(false).build());
    }
    return results;
}
Also used : Relationship(org.apache.nifi.processor.Relationship) HashCodeBuilder(org.apache.commons.lang3.builder.HashCodeBuilder) EqualsBuilder(org.apache.commons.lang3.builder.EqualsBuilder) ArrayList(java.util.ArrayList) ValidationResult(org.apache.nifi.components.ValidationResult) ValidationContext(org.apache.nifi.components.ValidationContext)

Example 50 with Relationship

use of org.apache.nifi.processor.Relationship in project nifi by apache.

the class StandardProcessorNode method removeConnection.

@Override
public void removeConnection(final Connection connection) {
    boolean connectionRemoved = false;
    if (requireNonNull(connection).getSource().equals(this)) {
        for (final Relationship relationship : connection.getRelationships()) {
            final Set<Connection> connectionsForRelationship = getConnections(relationship);
            if ((connectionsForRelationship == null || connectionsForRelationship.size() <= 1) && isRunning()) {
                throw new IllegalStateException("This connection cannot be removed because its source is running and removing it will invalidate this processor");
            }
        }
        for (final Set<Connection> connectionList : this.connections.values()) {
            connectionList.remove(connection);
        }
        connectionRemoved = (destinations.remove(connection) != null);
    }
    if (connection.getDestination().equals(this)) {
        final List<Connection> incomingConnections = incomingConnectionsRef.get();
        if (incomingConnections.contains(connection)) {
            final List<Connection> updatedIncoming = new ArrayList<>(incomingConnections);
            updatedIncoming.remove(connection);
            incomingConnectionsRef.set(Collections.unmodifiableList(updatedIncoming));
            return;
        }
    }
    if (!connectionRemoved) {
        throw new IllegalArgumentException("Cannot remove a connection from a ProcessorNode for which the ProcessorNode is not the Source");
    }
}
Also used : Relationship(org.apache.nifi.processor.Relationship) Connection(org.apache.nifi.connectable.Connection) ArrayList(java.util.ArrayList)

Aggregations

Relationship (org.apache.nifi.processor.Relationship)106 ArrayList (java.util.ArrayList)41 HashSet (java.util.HashSet)40 HashMap (java.util.HashMap)32 FlowFile (org.apache.nifi.flowfile.FlowFile)32 Map (java.util.Map)31 IOException (java.io.IOException)26 PropertyDescriptor (org.apache.nifi.components.PropertyDescriptor)26 Test (org.junit.Test)23 List (java.util.List)20 Set (java.util.Set)19 Connection (org.apache.nifi.connectable.Connection)18 TestRunner (org.apache.nifi.util.TestRunner)18 ProcessException (org.apache.nifi.processor.exception.ProcessException)17 ProcessSession (org.apache.nifi.processor.ProcessSession)15 InputStream (java.io.InputStream)14 DynamicRelationship (org.apache.nifi.annotation.behavior.DynamicRelationship)12 Processor (org.apache.nifi.processor.Processor)12 Collections (java.util.Collections)11 AtomicLong (java.util.concurrent.atomic.AtomicLong)10