Esempio n. 1
0
  @Override
  public void verifyCanDelete(final boolean ignoreConnections) {
    readLock.lock();
    try {
      if (isRunning()) {
        throw new IllegalStateException(this + " is running");
      }

      if (!ignoreConnections) {
        for (final Set<Connection> connectionSet : connections.values()) {
          for (final Connection connection : connectionSet) {
            connection.verifyCanDelete();
          }
        }

        for (final Connection connection : incomingConnectionsRef.get()) {
          if (connection.getSource().equals(this)) {
            connection.verifyCanDelete();
          } else {
            throw new IllegalStateException(this + " is the destination of another component");
          }
        }
      }
    } finally {
      readLock.unlock();
    }
  }
Esempio n. 2
0
  public static boolean flowFilesQueued(final Connectable connectable) {
    for (final Connection conn : connectable.getIncomingConnections()) {
      if (!conn.getFlowFileQueue().isActiveQueueEmpty()) {
        return true;
      }
    }

    return false;
  }
Esempio n. 3
0
  List<Connection> getIncomingNonLoopConnections() {
    final List<Connection> connections = getIncomingConnections();
    final List<Connection> nonLoopConnections = new ArrayList<>(connections.size());
    for (final Connection connection : connections) {
      if (!connection.getSource().equals(this)) {
        nonLoopConnections.add(connection);
      }
    }

    return nonLoopConnections;
  }
Esempio n. 4
0
  @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");
        }
      }

      writeLock.lock();
      try {
        for (final Set<Connection> connectionList : this.connections.values()) {
          connectionList.remove(connection);
        }

        connectionRemoved = (destinations.remove(connection) != null);
      } finally {
        writeLock.unlock();
      }
    }

    if (connection.getDestination().equals(this)) {
      writeLock.lock();
      try {
        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;
        }
      } finally {
        writeLock.unlock();
      }
    }

    if (!connectionRemoved) {
      throw new IllegalArgumentException(
          "Cannot remove a connection from a ProcessorNode for which the ProcessorNode is not the Source");
    }
  }
Esempio n. 5
0
  @Override
  public void addConnection(final Connection connection) {
    Objects.requireNonNull(connection, "connection cannot be null");

    if (!connection.getSource().equals(this) && !connection.getDestination().equals(this)) {
      throw new IllegalStateException(
          "Cannot a connection to a ProcessorNode for which the ProcessorNode is neither the Source nor the Destination");
    }

    writeLock.lock();
    try {
      List<Connection> updatedIncoming = null;
      if (connection.getDestination().equals(this)) {
        // don't add the connection twice. This may occur if we have a self-loop because we will be
        // told
        // to add the connection once because we are the source and again because we are the
        // destination.
        final List<Connection> incomingConnections = incomingConnectionsRef.get();
        updatedIncoming = new ArrayList<>(incomingConnections);
        if (!updatedIncoming.contains(connection)) {
          updatedIncoming.add(connection);
        }
      }

      if (connection.getSource().equals(this)) {
        // don't add the connection twice. This may occur if we have a self-loop because we will be
        // told
        // to add the connection once because we are the source and again because we are the
        // destination.
        if (!destinations.containsKey(connection)) {
          for (final Relationship relationship : connection.getRelationships()) {
            final Relationship rel = getRelationship(relationship.getName());
            Set<Connection> set = connections.get(rel);
            if (set == null) {
              set = new HashSet<>();
              connections.put(rel, set);
            }

            set.add(connection);

            destinations.put(connection, connection.getDestination());
          }

          final Set<Relationship> autoTerminated = this.undefinedRelationshipsToTerminate.get();
          if (autoTerminated != null) {
            autoTerminated.removeAll(connection.getRelationships());
            this.undefinedRelationshipsToTerminate.set(autoTerminated);
          }
        }
      }

      if (updatedIncoming != null) {
        incomingConnectionsRef.set(Collections.unmodifiableList(updatedIncoming));
      }
    } finally {
      writeLock.unlock();
    }
  }
Esempio n. 6
0
  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;
  }
  private void addConnection(final Element parentElement, final Connection connection) {
    final Document doc = parentElement.getOwnerDocument();
    final Element element = doc.createElement("connection");
    parentElement.appendChild(element);
    addTextElement(element, "id", connection.getIdentifier());
    addTextElement(element, "name", connection.getName());

    final Element bendPointsElement = doc.createElement("bendPoints");
    element.appendChild(bendPointsElement);
    for (final Position bendPoint : connection.getBendPoints()) {
      addPosition(bendPointsElement, bendPoint, "bendPoint");
    }

    addTextElement(element, "labelIndex", connection.getLabelIndex());
    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();
    }

    addTextElement(element, "sourceId", sourceId);
    addTextElement(element, "sourceGroupId", sourceGroupId);
    addTextElement(element, "sourceType", sourceType.toString());

    addTextElement(element, "destinationId", destinationId);
    addTextElement(element, "destinationGroupId", destinationGroupId);
    addTextElement(element, "destinationType", destinationType.toString());

    for (final Relationship relationship : connection.getRelationships()) {
      addTextElement(element, "relationship", relationship.getName());
    }

    addTextElement(
        element,
        "maxWorkQueueSize",
        connection.getFlowFileQueue().getBackPressureObjectThreshold());
    addTextElement(
        element,
        "maxWorkQueueDataSize",
        connection.getFlowFileQueue().getBackPressureDataSizeThreshold());

    addTextElement(
        element, "flowFileExpiration", connection.getFlowFileQueue().getFlowFileExpiration());
    for (final FlowFilePrioritizer comparator : connection.getFlowFileQueue().getPriorities()) {
      final String className = comparator.getClass().getCanonicalName();
      addTextElement(element, "queuePrioritizerClass", className);
    }

    parentElement.appendChild(element);
  }
Esempio n. 8
0
  @Override
  public void updateConnection(final Connection connection) throws IllegalStateException {
    if (requireNonNull(connection).getSource().equals(this)) {
      writeLock.lock();
      try {
        //
        // update any relationships
        //
        // first check if any relations were removed.
        final List<Relationship> existingRelationships = new ArrayList<>();
        for (final Map.Entry<Relationship, Set<Connection>> entry : connections.entrySet()) {
          if (entry.getValue().contains(connection)) {
            existingRelationships.add(entry.getKey());
          }
        }

        for (final Relationship rel : connection.getRelationships()) {
          if (!existingRelationships.contains(rel)) {
            // relationship was removed. Check if this is legal.
            final Set<Connection> connectionsForRelationship = getConnections(rel);
            if (connectionsForRelationship != null
                && connectionsForRelationship.size() == 1
                && this.isRunning()
                && !isAutoTerminated(rel)
                && getRelationships().contains(rel)) {
              // if we are running and we do not terminate undefined relationships and this is the
              // only
              // connection that defines the given relationship, and that relationship is required,
              // then it is not legal to remove this relationship from this connection.
              throw new IllegalStateException(
                  "Cannot remove relationship "
                      + rel.getName()
                      + " from Connection because doing so would invalidate Processor "
                      + this
                      + ", which is currently running");
            }
          }
        }

        // remove the connection from any list that currently contains
        for (final Set<Connection> list : connections.values()) {
          list.remove(connection);
        }

        // add the connection in for all relationships listed.
        for (final Relationship rel : connection.getRelationships()) {
          Set<Connection> set = connections.get(rel);
          if (set == null) {
            set = new HashSet<>();
            connections.put(rel, set);
          }
          set.add(connection);
        }

        // update to the new destination
        destinations.put(connection, connection.getDestination());

        final Set<Relationship> autoTerminated = this.undefinedRelationshipsToTerminate.get();
        if (autoTerminated != null) {
          autoTerminated.removeAll(connection.getRelationships());
          this.undefinedRelationshipsToTerminate.set(autoTerminated);
        }
      } finally {
        writeLock.unlock();
      }
    }

    if (connection.getDestination().equals(this)) {
      writeLock.lock();
      try {
        // update our incoming connections -- we can just remove & re-add the connection to
        // update the list.
        final List<Connection> incomingConnections = incomingConnectionsRef.get();
        final List<Connection> updatedIncoming = new ArrayList<>(incomingConnections);
        updatedIncoming.remove(connection);
        updatedIncoming.add(connection);
        incomingConnectionsRef.set(Collections.unmodifiableList(updatedIncoming));
      } finally {
        writeLock.unlock();
      }
    }
  }