Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ public class NiFiProperties extends ApplicationProperties {
public static final String CONNECTOR_REPOSITORY_IMPLEMENTATION = "nifi.connector.repository.implementation";
public static final String CONNECTOR_SYNC_TIMEOUT = "nifi.connector.sync.timeout";
public static final String DEFAULT_CONNECTOR_SYNC_TIMEOUT = "5 mins";
public static final String CONNECTOR_FLOW_EVOLUTION_TIMEOUT = "nifi.connector.flow.evolution.timeout";
public static final String DEFAULT_CONNECTOR_FLOW_EVOLUTION_TIMEOUT = "30 mins";

// Connector Configuration Provider properties
public static final String CONNECTOR_CONFIGURATION_PROVIDER_IMPLEMENTATION = "nifi.connector.configuration.provider.implementation";
Expand Down
10 changes: 10 additions & 0 deletions nifi-docs/src/main/asciidoc/administration-guide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -3921,6 +3921,16 @@ The NiFi Registry NAR provider retrieves NARs from a NiFi Registry instance. In
|`nifi.nar.library.provider.nifi-registry.url`| The URL of the NiFi Registry instance, such as `http://localhost:18080`. If the URL begins with `https`, then the NiFi keystore and truststore will be used to make the TLS connection.
|====

[[connector_properties]]
=== Connector Properties

These properties configure how NiFi manages Connectors. For what flow evolution is and how it runs, see <<developer-guide.adoc#connector_flow_evolution,Connector Flow Evolution>> in the Developer's Guide.

|====
|*Property*|*Description*
|`nifi.connector.flow.evolution.timeout`|How long a Connector may spend draining its outgoing flow in `prepareForFlowEvolution`. Waiting for other cluster nodes to finish their drain is not limited by this timeout. Accepts any NiFi time duration value such as `30 mins`. The default value is `30 mins`. A timeout leaves the Connector stopped and still pending.
|====

[[secrets_manager_properties]]
=== Secrets Manager Properties

Expand Down
54 changes: 54 additions & 0 deletions nifi-docs/src/main/asciidoc/developer-guide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2700,6 +2700,60 @@ The following command is used to generate a standard binary distribution of Apac

`mvn clean install -Pcontrib-check`

[[connector_flow_evolution]]
== Connector Flow Evolution

A Connector's managed flow is the set of processors, controller services, and connections that the Connector builds from its bundle. Whenever NiFi saves the flow, it records the bundle version that built the managed flow. That recorded version is kept separately from the bundle version the Connector is currently loaded from.

If the loaded bundle version differs from the recorded one, the managed flow must be evolved to match the new version before the Connector runs. This is called flow evolution. It is pending while the two versions differ, and it runs on the next START of the Connector.

=== When the flow is saved

There is no explicit save action. NiFi writes the flow to its flow file, `flow.json.gz` by default, as each change completes. Changes made close together are written as one update, after the delay set by `nifi.flowservice.writedelay.interval`, which defaults to `500 ms`.

Any user action that modifies the flow saves it. Changing a Connector's version records the new Connector bundle, but the managed flow keeps the bundle it was built from until flow evolution saves.

NiFi also saves the flow without a user action in these cases:

* During flow evolution, once, after the upgraded flow is applied. The Connector is recorded as running, because only a START runs an evolution. A failed evolution is not saved.
* When a node reconnects to a cluster and writes the flow it inherited from the cluster.

=== How evolution runs

On the next START, the framework calls `prepareForFlowEvolution(FlowEvolutionContext)` on the Connector. The context describes the outgoing flow and the upgraded bundle. The Connector returns a `CompletableFuture` that completes when the outgoing flow is ready. The framework waits for that future, stops the processors in the outgoing flow, and then applies the upgraded flow as described in <<connector_applying_upgraded_flow>>.

When NiFi restarts with an evolution pending, it restores the outgoing flow with its components stopped, whatever state they were saved in. The Connector's recorded state decides whether the evolution starts, and the hook starts what it needs to drain. A Connector recorded in Troubleshooting mode keeps the saved component states.

The framework does not call `prepareForFlowEvolution` when a Connector leaves the Troubleshooting state. In that case the managed flow must already be empty.

=== Draining in prepareForFlowEvolution

The default implementation of `prepareForFlowEvolution` does nothing and returns a completed future. The framework does not drain FlowFiles for the Connector, so a Connector that removes connections must empty them in its own hook.

* If any connection that the upgraded flow removes still holds FlowFiles, the Connector must drain. The hook must finish with every such connection empty, or the upgrade fails.
* The Connector does not need to drain when every connection that the upgraded flow removes is already empty. A connection that the upgraded flow keeps, with the same identifier, is updated in place and keeps its queue, so it never requires a drain.
* The framework stops the outgoing processors only after the hook's future completes. The hook can start them so that queues empty, and the processors are stopped afterward.
* The framework can cancel the future, for example when the Connector is stopped or the evolution timeout is reached. Stop any work promptly when the future is cancelled. The framework does not wait for code that ignores cancellation.

[[connector_applying_upgraded_flow]]
=== Applying the upgraded flow

Once every node that still has the outgoing flow has drained it, the framework checks again that no connection the upgraded flow removes holds FlowFiles. If one does, the evolution fails and the outgoing flow is kept. Otherwise the framework runs the same `prepareForUpdate` and `applyUpdate` process as a configuration update, saves the resulting flow, and starts the Connector.

Each node prepares on its own. Every node has already finished the hook, so the framework does not wait for the other nodes to reach `UPDATING`.

`prepareForUpdate` and `applyUpdate` must be safe to run again. If either fails, the Connector is left `UPDATE_FAILED`, and the next START calls both again without running the hook. `applyUpdate` therefore has to work on a flow that it has already partly updated.

=== What operators see

In a cluster, each node drains its own Connector. No node applies the upgraded flow until every node that still has the outgoing flow has drained it, so the Connector reports `DRAINING` while the nodes wait for one another. A node that has already applied the upgraded flow has nothing to drain and does not hold back the others. A node that disconnects after applying the upgraded flow does not block the others either: the connected nodes start. `nifi.connector.flow.evolution.timeout` limits only the local drain in `prepareForFlowEvolution`. See <<administration-guide.adoc#connector_properties,Connector Properties>> in the Administration Guide.

If evolution fails before the upgraded flow is applied, including while a node waits for the others to drain, the Connector remains stopped and still pending, and the next START runs the hook again. Stopping the Connector while it drains cancels the attempt. The failure is not saved, so after a restart the Connector comes back in the state that was last saved.

A failure while applying the upgraded flow leaves the Connector `UPDATE_FAILED`. The failure is not saved, so the Connector must be corrected and started again. On a node where `prepareForUpdate` or `applyUpdate` failed, the Connector is still pending and the next START retries both without the hook. On a node where the upgraded flow was applied, the Connector is no longer pending and the next START runs the new flow.

If the upgraded Connector fails to start, the upgraded flow has already been saved, and the Connector is handled like any other Connector that fails to start.

== Supporting migration from a Versioned Process Group

Connectors can implement a one-time migration flow that uses a source Versioned Process Group as a reference for populating a freshly created Connector.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class ConnectorDTO extends ComponentDTO {
private String type;
private BundleDTO bundle;
private String state; // RUNNING, STOPPED
private String flowEvolutionStatus;
private String managedProcessGroupId;
private ConnectorConfigurationDTO activeConfiguration;
private ConnectorConfigurationDTO workingConfiguration;
Expand All @@ -40,6 +41,7 @@ public class ConnectorDTO extends ComponentDTO {
private Boolean multipleVersionsAvailable;
private Boolean extensionMissing;
private Boolean supportsBacklogReporting;
private BundleDTO expectedBundle;

private String configurationUrl;
private String detailsUrl;
Expand Down Expand Up @@ -81,6 +83,17 @@ public void setState(final String state) {
this.state = state;
}

@Schema(description = "The local or merged progress of a pending Connector flow evolution.",
allowableValues = {"INACTIVE", "EVOLVE_DRAIN_PENDING", "EVOLVE_DRAIN_COMPLETE", "FAILED"},
accessMode = Schema.AccessMode.READ_ONLY)
public String getFlowEvolutionStatus() {
return flowEvolutionStatus;
}

public void setFlowEvolutionStatus(final String flowEvolutionStatus) {
this.flowEvolutionStatus = flowEvolutionStatus;
}

@Schema(description = "The identifier of the root Process Group managed by this Connector.")
public String getManagedProcessGroupId() {
return managedProcessGroupId;
Expand Down Expand Up @@ -174,6 +187,16 @@ public void setSupportsBacklogReporting(final Boolean supportsBacklogReporting)
this.supportsBacklogReporting = supportsBacklogReporting;
}

@Schema(description = "The Connector bundle expected by the cluster coordinator when verifying a START. "
+ "Not persisted; used only for cluster run-status verification.")
public BundleDTO getExpectedBundle() {
return expectedBundle;
}

public void setExpectedBundle(final BundleDTO expectedBundle) {
this.expectedBundle = expectedBundle;
}

@Schema(description = "The available actions that can be performed on this Connector.")
public List<ConnectorActionDTO> getAvailableActions() {
return availableActions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.xml.bind.annotation.XmlType;
import org.apache.nifi.web.api.dto.BundleDTO;

@XmlType(name = "connectorRunStatus")
public class ConnectorRunStatusEntity extends ComponentRunStatusEntity {
private static final String[] SUPPORTED_STATE = {"RUNNING", "STOPPED", "DISABLED"};

private BundleDTO expectedBundle;

@Override
protected String[] getSupportedState() {
return SUPPORTED_STATE;
Expand All @@ -33,6 +36,16 @@ protected String[] getSupportedState() {
public String getState() {
return super.getState();
}

@Schema(description = "The Connector bundle the cluster coordinator has loaded. When set on a START, each node "
+ "rejects the request in the validation phase if its loaded bundle differs.")
public BundleDTO getExpectedBundle() {
return expectedBundle;
}

public void setExpectedBundle(final BundleDTO expectedBundle) {
this.expectedBundle = expectedBundle;
}
}


Loading
Loading