public ConnectableComponent mapConnectable(final Connectable connectable) { final ConnectableComponent component = new InstantiatedConnectableComponent(connectable.getIdentifier(), connectable.getProcessGroupIdentifier()); final String versionedId = getIdOrThrow(connectable.getVersionedComponentId(), connectable.getIdentifier(), () -> new IllegalArgumentException("Unable to map Connectable Component with identifier " + connectable.getIdentifier() + " to any version-controlled component")); component.setId(versionedId); component.setComments(connectable.getComments()); final String groupId; if (connectable instanceof RemoteGroupPort) { final RemoteGroupPort port = (RemoteGroupPort) connectable; final RemoteProcessGroup rpg = port.getRemoteProcessGroup(); final Optional<String> rpgVersionedId = rpg.getVersionedComponentId(); groupId = getIdOrThrow(rpgVersionedId, rpg.getIdentifier(), () -> new IllegalArgumentException("Unable to find the Versioned Component ID for Remote Process Group that " + connectable + " belongs to")); } else { groupId = getIdOrThrow(connectable.getProcessGroup().getVersionedComponentId(), connectable.getProcessGroupIdentifier(), () -> new IllegalArgumentException("Unable to find the Versioned Component ID for the Process Group that " + connectable + " belongs to")); } component.setGroupId(groupId); component.setName(connectable.getName()); component.setType(ConnectableComponentType.valueOf(connectable.getConnectableType().name())); return component; }
/** * Verify that removing this connection will not prevent this Port from * still being connected via each relationship * * @param connection to test for removal * @return true if can be removed */ private boolean canConnectionBeRemoved(final Connection connection) { final Connectable source = connection.getSource(); if (!source.isRunning()) { // we don't have to verify that this Connectable is still connected because it's okay to make // the source invalid since it is not running. return true; } for (final Relationship relationship : source.getRelationships()) { if (source.isAutoTerminated(relationship)) { continue; } final Set<Connection> connectionsForRelationship = source.getConnections(relationship); if (connectionsForRelationship == null || connectionsForRelationship.isEmpty()) { return false; } } return true; }
@Override public void verifyCanStart(Connectable connectable) { readLock.lock(); try { if (connectable.getScheduledState() == ScheduledState.STOPPED) { if (scheduler.getActiveThreadCount(connectable) > 0) { throw new IllegalStateException("Cannot start component with id" + connectable.getIdentifier() + " because it is currently stopping"); } connectable.verifyCanStart(); } } finally { readLock.unlock(); } }
private boolean isUpdateable(final Connection connection) { final Connectable source = connection.getSource(); if (source.getConnectableType() != ConnectableType.FUNNEL && source.isRunning()) { return false; } final Connectable destination = connection.getDestination(); if (destination.getConnectableType() != ConnectableType.FUNNEL && destination.isRunning()) { return false; } return true; }
private boolean isInputPort(final Connectable connectable) { if (connectable.getConnectableType() != ConnectableType.INPUT_PORT) { return false; } return findInputPort(connectable.getIdentifier()) != null; }
void adjustCounter(final String name, final long delta) { final String localContext = connectable.getName() + " (" + connectable.getIdentifier() + ")"; final String globalContext = "All " + connectable.getComponentType() + "'s"; counterRepo.adjustCounter(localContext, name, delta); counterRepo.adjustCounter(globalContext, name, delta); }
boolean isAuthorized = connectable.isAuthorized(authorizer, RequestAction.READ, NiFiUserUtils.getNiFiUser()); dto.setId(connectable.getIdentifier()); dto.setName(isAuthorized ? connectable.getName() : connectable.getIdentifier()); dto.setType(connectable.getConnectableType().name()); dto.setVersionedComponentId(connectable.getVersionedComponentId().orElse(null)); dto.setGroupId(connectable.getProcessGroup().getIdentifier()); dto.setRunning(connectable.isRunning()); if (isAuthorized) { dto.setComments(connectable.getComments());
public static Bulletin createBulletin(final Connectable connectable, final String category, final String severity, final String message) { final ComponentType type; switch (connectable.getConnectableType()) { case REMOTE_INPUT_PORT: case REMOTE_OUTPUT_PORT: type = ComponentType.REMOTE_PROCESS_GROUP; break; case INPUT_PORT: type = ComponentType.INPUT_PORT; break; case OUTPUT_PORT: type = ComponentType.OUTPUT_PORT; break; case PROCESSOR: default: type = ComponentType.PROCESSOR; break; } final ProcessGroup group = connectable.getProcessGroup(); final String groupId = group == null ? null : group.getIdentifier(); final String groupName = group == null ? null : group.getName(); return BulletinFactory.createBulletin(groupId, groupName, connectable.getIdentifier(), type, connectable.getName(), category, severity, message); }
public void stopConnectable(final Connectable connectable) { final ProcessGroup group = requireNonNull(connectable).getProcessGroup(); writeLock.lock(); try { switch (requireNonNull(connectable).getConnectableType()) { case FUNNEL: // Ignore. We don't support stopping funnels. break; case INPUT_PORT: case REMOTE_INPUT_PORT: startConnectablesAfterInitialization.remove(connectable); group.stopInputPort((Port) connectable); break; case OUTPUT_PORT: case REMOTE_OUTPUT_PORT: startConnectablesAfterInitialization.remove(connectable); group.stopOutputPort((Port) connectable); break; default: throw new IllegalArgumentException(); } } finally { writeLock.unlock("stopConnectable"); } }
final int requiredNumberOfAvailableRelationships = connectable.isTriggerWhenAnyDestinationAvailable() ? 1 : numRelationships; if (!repositoryContext.isRelationshipAvailabilitySatisfied(requiredNumberOfAvailableRelationships)) { return InvocationResult.yield("Backpressure Applied"); final long batchNanos = connectable.getRunDuration(TimeUnit.NANOSECONDS); final ProcessSessionFactory sessionFactory; final StandardProcessSession rawSession; final boolean batch; if (connectable.isSessionBatchingSupported() && batchNanos > 0L) { rawSession = new StandardProcessSession(repositoryContext, scheduleState::isTerminated); sessionFactory = new BatchingSessionFactory(rawSession); try (final AutoCloseable ncl = NarCloseable.withComponentNarLoader(flowController.getExtensionManager(), connectable.getRunnableComponent().getClass(), connectable.getIdentifier())) { boolean shouldRun = connectable.getScheduledState() == ScheduledState.RUNNING; while (shouldRun) { connectable.onTrigger(processContext, activeSessionFactory); invocationCount++; if (connectable.getScheduledState() != ScheduledState.RUNNING) { break; final int requiredNumberOfAvailableRelationships = connectable.isTriggerWhenAnyDestinationAvailable() ? 1 : numRelationships; shouldRun = repositoryContext.isRelationshipAvailabilitySatisfied(requiredNumberOfAvailableRelationships); final ComponentLog procLog = new SimpleProcessLogger(connectable.getIdentifier(), connectable.getRunnableComponent()); procLog.info("Failed to process session due to task being terminated", new Object[] {tte}); } catch (final ProcessException pe) { final ComponentLog procLog = new SimpleProcessLogger(connectable.getIdentifier(), connectable.getRunnableComponent()); procLog.error("Failed to process session due to {}", new Object[] {pe});
private AffectedComponentEntity createAffectedComponentEntity(final Connectable connectable) { final AffectedComponentEntity entity = new AffectedComponentEntity(); entity.setRevision(dtoFactory.createRevisionDTO(revisionManager.getRevision(connectable.getIdentifier()))); entity.setId(connectable.getIdentifier()); final Authorizable authorizable = getAuthorizable(connectable); final PermissionsDTO permissionsDto = dtoFactory.createPermissionsDto(authorizable); entity.setPermissions(permissionsDto); final AffectedComponentDTO dto = new AffectedComponentDTO(); dto.setId(connectable.getIdentifier()); dto.setReferenceType(connectable.getConnectableType().name()); dto.setState(connectable.getScheduledState().name()); final String groupId = connectable instanceof RemoteGroupPort ? ((RemoteGroupPort) connectable).getRemoteProcessGroup().getIdentifier() : connectable.getProcessGroupIdentifier(); dto.setProcessGroupId(groupId); entity.setComponent(dto); return entity; }
@Override public void verifyCanDelete() { if (!flowFileQueue.isEmpty()) { throw new IllegalStateException("Queue not empty for " + this.getIdentifier()); } if (source.isRunning()) { if (!ConnectableType.FUNNEL.equals(source.getConnectableType())) { throw new IllegalStateException("Source of Connection (" + source.getIdentifier() + ") is running"); } } final Connectable dest = destination.get(); if (dest.isRunning()) { if (!ConnectableType.FUNNEL.equals(dest.getConnectableType())) { throw new IllegalStateException("Destination of Connection (" + dest.getIdentifier() + ") is running"); } } }
dto.setGroupId(connectable.getProcessGroup().getIdentifier()); if (Result.Approved.equals(connectable.checkAuthorization(authorizer, RequestAction.READ, user).getResult())) { dto.setComponentName(connectable.getName()); } else { dto.setComponentType(connectable.getConnectableType().toString()); dto.setComponentName(dto.getComponentId()); dto.setRelationship(null);
@Override public Set<Relationship> getAvailableRelationships() { for (final Connection connection : connectable.getConnections()) { if (connection.getFlowFileQueue().isFull()) { return Collections.emptySet(); } } final Collection<Relationship> relationships = connectable.getRelationships(); if (relationships instanceof Set) { return (Set<Relationship>) relationships; } return new HashSet<>(connectable.getRelationships()); }
addTextElement(element, "zIndex", connection.getZIndex()); final String sourceId = connection.getSource().getIdentifier(); final ConnectableType sourceType = connection.getSource().getConnectableType(); final String sourceGroupId; if (sourceType == ConnectableType.REMOTE_OUTPUT_PORT) { sourceGroupId = ((RemoteGroupPort) connection.getSource()).getRemoteProcessGroup().getIdentifier(); } else { sourceGroupId = connection.getSource().getProcessGroup().getIdentifier(); final ConnectableType destinationType = connection.getDestination().getConnectableType(); final String destinationId = connection.getDestination().getIdentifier(); final String destinationGroupId; if (destinationType == ConnectableType.REMOTE_INPUT_PORT) { destinationGroupId = ((RemoteGroupPort) connection.getDestination()).getRemoteProcessGroup().getIdentifier(); } else { destinationGroupId = connection.getDestination().getProcessGroup().getIdentifier();
connStatus.setId(conn.getIdentifier()); connStatus.setGroupId(conn.getProcessGroup().getIdentifier()); connStatus.setSourceId(conn.getSource().getIdentifier()); connStatus.setSourceName(isSourceAuthorized ? conn.getSource().getName() : conn.getSource().getIdentifier()); connStatus.setDestinationId(conn.getDestination().getIdentifier()); connStatus.setDestinationName(isDestinationAuthorized ? conn.getDestination().getName() : conn.getDestination().getIdentifier()); connStatus.setBackPressureDataSizeThreshold(conn.getFlowFileQueue().getBackPressureDataSizeThreshold()); connStatus.setBackPressureObjectThreshold(conn.getFlowFileQueue().getBackPressureObjectThreshold()); if (ConnectableType.REMOTE_OUTPUT_PORT.equals(source.getConnectableType())) { final RemoteGroupPort remoteOutputPort = (RemoteGroupPort) source; activeGroupThreads += processScheduler.getActiveThreadCount(remoteOutputPort); if (ConnectableType.REMOTE_INPUT_PORT.equals(destination.getConnectableType())) { final RemoteGroupPort remoteInputPort = (RemoteGroupPort) destination; activeGroupThreads += processScheduler.getActiveThreadCount(remoteInputPort);
private DelayProcessingReason getDelayReason(final Worker worker) { final Connectable connectable = worker.getConnectable(); if (ScheduledState.RUNNING != connectable.getScheduledState()) { return DelayProcessingReason.NOT_RUNNING; if (connectable.getYieldExpiration() > System.currentTimeMillis()) { return DelayProcessingReason.YIELDED; if (!connectable.getRelationships().isEmpty()) { availableRelationshipCount = getAvailableRelationshipCount(connectable); if (connectable.hasIncomingConnection() && !Connectables.flowFilesQueued(connectable)) { return DelayProcessingReason.NO_WORK; final int maxThreadCount = worker.getConnectable().getMaxConcurrentTasks(); if (maxThreadCount > 0 && activeThreadCount >= maxThreadCount) { return DelayProcessingReason.TOO_MANY_THREADS;
@Override public String toString() { return "Connection[ID=" + getIdentifier() + ", Source ID=" + getSource().getIdentifier() + ", Dest ID=" + getDestination().getIdentifier() + "]"; }
addIfAppropriate(searchStr, source.getIdentifier(), "Source id", matches); addIfAppropriate(searchStr, source.getName(), "Source name", matches); addIfAppropriate(searchStr, source.getComments(), "Source comments", matches); addIfAppropriate(searchStr, destination.getIdentifier(), "Destination id", matches); addIfAppropriate(searchStr, destination.getName(), "Destination name", matches); addIfAppropriate(searchStr, destination.getComments(), "Destination comments", matches); result.setName("From source " + connection.getSource().getName());
boolean hasNonLoopConnection = Connectables.hasNonLoopConnection(connectable); if (connectable.getConnectableType() == ConnectableType.FUNNEL) { return connectable.hasIncomingConnection() && hasNonLoopConnection && !connectable.getConnections().isEmpty() && Connectables.flowFilesQueued(connectable); final boolean isSourceComponent = connectable.isTriggerWhenEmpty() || !connectable.hasIncomingConnection()