-
Notifications
You must be signed in to change notification settings - Fork 23
NIFI-16045: Initial API for Processor / Connector Backlog #98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
53 changes: 53 additions & 0 deletions
53
src/main/java/org/apache/nifi/components/BacklogReportingException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.nifi.components; | ||
|
|
||
| /** | ||
| * <p> | ||
| * Thrown by a Connector or Processor that supports backlog reporting but cannot | ||
| * determine its current backlog due to a transient or permanent failure. Typical causes | ||
| * include I/O errors reaching the source system, authorization failures (the component is | ||
| * allowed to consume data but is not authorized to call the offset or listing API), and | ||
| * state errors that prevent computation. | ||
| * </p> | ||
| * | ||
| * <p> | ||
| * This exception is distinct from a Connector or Processor not supporting backlog reporting | ||
| * at all. Components that do not support backlog reporting simply do not implement | ||
| * {@link org.apache.nifi.processor.BacklogReportingProcessor} or | ||
| * {@link org.apache.nifi.components.connector.BacklogReportingConnector}. Components that do | ||
| * support backlog reporting may return {@link java.util.Optional#empty()} when they cannot | ||
| * determine a value right now, or throw this exception when an attempt to determine the | ||
| * backlog fails. Callers should surface the cause rather than silently treat the failure as | ||
| * "not supported". | ||
| * </p> | ||
| */ | ||
| public class BacklogReportingException extends Exception { | ||
|
|
||
| public BacklogReportingException(final String message) { | ||
| super(message); | ||
| } | ||
|
|
||
| public BacklogReportingException(final String message, final Throwable cause) { | ||
| super(message, cause); | ||
| } | ||
|
|
||
| public BacklogReportingException(final Throwable cause) { | ||
| super(cause); | ||
| } | ||
| } |
102 changes: 102 additions & 0 deletions
102
src/main/java/org/apache/nifi/components/connector/BacklogReportingConnector.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.nifi.components.connector; | ||
|
|
||
| import org.apache.nifi.components.Backlog; | ||
| import org.apache.nifi.components.BacklogReportingException; | ||
| import org.apache.nifi.components.connector.components.FlowContext; | ||
| import org.apache.nifi.components.connector.components.ProcessorFacade; | ||
|
|
||
| import java.util.Optional; | ||
|
|
||
| /** | ||
| * <p> | ||
| * Optional capability interface implemented by {@link Connector}s that can report a | ||
| * {@link Backlog} describing how much data remains on the source system(s) the Connector | ||
| * pulls from but has not yet brought into NiFi. Implementing this interface is the opt-in | ||
| * signal: Connectors that do not implement it are simply not asked for backlog, and the | ||
| * framework's REST endpoints return HTTP {@code 409 Conflict} rather than treating "not | ||
| * supported" the same as "supported but currently unknown". | ||
| * </p> | ||
| * | ||
| * <p> | ||
| * This mirrors the {@code BacklogReportingProcessor} capability interface on the Processor | ||
| * side: the {@code Connector} base interface stays focused on lifecycle and configuration, | ||
| * and backlog reporting is layered on as a separate opt-in. | ||
| * </p> | ||
| * | ||
| * <p> | ||
| * Implementations that do report backlog typically derive the value from a single source — | ||
| * most often a single Processor's {@code BacklogReportingProcessor} report exposed via | ||
| * {@link ProcessorFacade#getBacklog()}. Some Connectors may compose a flow-wide picture from | ||
| * multiple sources: for example, summing the {@link Backlog} from multiple Processors, or, for | ||
| * a List/Fetch pattern, also inspecting queues and FlowFile attributes to account for data that | ||
| * has been "Listed" but not yet "Fetched". | ||
| * </p> | ||
| * | ||
| * <h2>Return value semantics</h2> | ||
| * <ul> | ||
| * <li> | ||
| * {@link Optional#empty()} means the Connector cannot report a {@link Backlog} right now, | ||
| * even though it implements this interface. This is distinct from a hard failure. | ||
| * </li> | ||
| * <li> | ||
| * <code>Optional.of(Backlog.caughtUp())</code> means the Connector is fully synchronized | ||
| * with its source as of now. | ||
| * </li> | ||
| * <li> | ||
| * <code>Optional.of(...)</code> with non-zero numeric dimensions means the Connector knows | ||
| * that this much data remains on the source. See {@link Backlog.Precision} for whether the | ||
| * numbers are exact or lower bounds. | ||
| * </li> | ||
| * </ul> | ||
| * | ||
| * <p> | ||
| * Hard failures — source unreachable, authorization denied, state errors that prevent | ||
| * computation — are reported by throwing {@link BacklogReportingException}, not by returning | ||
| * {@link Optional#empty()}. This keeps failures distinguishable from "no value available." | ||
| * </p> | ||
| * | ||
| * <p> | ||
| * <b>Implementation Note:</b> This API is currently experimental, as it is under very active | ||
| * development. As such, it is subject to change without notice between releases. | ||
| * </p> | ||
| */ | ||
| public interface BacklogReportingConnector { | ||
|
|
||
| /** | ||
| * <p> | ||
| * Reports how much data remains on the source system(s) that this Connector pulls from but | ||
| * has not yet brought into NiFi. | ||
| * </p> | ||
| * | ||
| * <p> | ||
| * This method is invoked against the <b>active</b> {@link FlowContext}, because backlog is | ||
| * a runtime property of the running flow. The working flow context is not used for backlog | ||
| * reporting. Expected call frequency is low — typically on the order of once per minute, | ||
| * sometimes once every few minutes. Implementations may cache results internally if computing | ||
| * backlog puts non-trivial load on the source, but caching is not required. | ||
| * </p> | ||
| * | ||
| * @param activeFlowContext the active flow context against which to compute backlog | ||
| * @return the Connector's reported {@link Backlog}, or {@link Optional#empty()} if the Connector | ||
| * cannot determine a value right now (for example, it has never polled the source) | ||
| * @throws BacklogReportingException if the Connector attempted to determine its backlog and failed | ||
| */ | ||
| Optional<Backlog> getBacklog(final FlowContext activeFlowContext) throws BacklogReportingException; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
src/main/java/org/apache/nifi/components/connector/components/QueueSnapshot.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.nifi.components.connector.components; | ||
|
|
||
| import org.apache.nifi.controller.queue.QueueSize; | ||
| import org.apache.nifi.flowfile.FlowFile; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| /** | ||
| * <p> | ||
| * A point-in-time view of a connection's queue, returned by | ||
| * {@link ConnectionFacade#getQueueSnapshot()}. Bundles the connection's total {@link QueueSize} | ||
| * together with the {@link FlowFile}s currently held in this node's active in-memory queue, | ||
| * meaning the FlowFiles resident in memory on this node and available in poll order. | ||
| * </p> | ||
| * | ||
| * <p> | ||
| * The active list and the {@link QueueSize} are captured atomically, so they describe the same | ||
| * point in time. The active list is not always the entire queue. FlowFiles that have been | ||
| * swapped out are excluded from {@link #getActiveFlowFiles()}. On load-balanced connections, | ||
| * FlowFiles in flight between nodes are excluded as well. Those FlowFiles are still counted in | ||
| * {@link #getQueueSize()}. Use {@link #isActiveListExhaustive()} to determine whether the | ||
| * active list contains every FlowFile counted in the queue size. | ||
| * </p> | ||
| * | ||
| * <p> | ||
| * {@link #getActiveFlowFiles()} returns the full active list without a caller-supplied limit, but | ||
| * the list itself is bounded by the framework's maximum active in-memory queue size. The | ||
| * snapshot does not clone the {@link FlowFile} instances; it references the existing active | ||
| * FlowFiles. | ||
| * </p> | ||
| */ | ||
| public interface QueueSnapshot { | ||
|
|
||
| /** | ||
| * @return the total {@link QueueSize} of the connection at the time the snapshot was taken | ||
| */ | ||
| QueueSize getQueueSize(); | ||
|
|
||
| /** | ||
| * @return the active in-memory FlowFiles in poll order, never null; excludes FlowFiles that | ||
| * have been swapped out and, for load-balanced connections, FlowFiles in flight between | ||
| * nodes | ||
| */ | ||
| List<FlowFile> getActiveFlowFiles(); | ||
|
|
||
| /** | ||
| * @return {@code true} if {@link #getActiveFlowFiles()} contains every FlowFile counted in | ||
| * {@link #getQueueSize()}; otherwise {@code false} | ||
| */ | ||
| boolean isActiveListExhaustive(); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the extra blank line at the end of Connector intended, or a stray change?