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;
}
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());
}
}
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;
}
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;
}
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");
}
}
Aggregations