|
21 | 21 | import org.apache.nifi.components.connector.ConnectorInitializationContext; |
22 | 22 | import org.apache.nifi.components.connector.FlowUpdateException; |
23 | 23 | import org.apache.nifi.components.connector.components.FlowContext; |
24 | | -import org.apache.nifi.flow.VersionedExternalFlow; |
| 24 | +import org.apache.nifi.flow.VersionedComponentState; |
25 | 25 |
|
26 | 26 | /** |
| 27 | + * Optional {@link Connector} capability for migration from a source flow. |
| 28 | + * |
| 29 | + * <p> |
| 30 | + * Migration runs in two phases: |
| 31 | + * </p> |
| 32 | + * <ol> |
| 33 | + * <li>{@link #migrateConfiguration(ConnectorMigrationContext)} records configuration changes and copied assets.</li> |
| 34 | + * <li>{@link #migrateState(ConnectorMigrationContext)} records component {@link VersionedComponentState}.</li> |
| 35 | + * </ol> |
| 36 | + * |
27 | 37 | * <p> |
28 | | - * An optional capability interface that may be implemented by a {@link Connector} to indicate that it supports |
29 | | - * being populated from an existing source flow (for example, a Versioned Process Group already running on this |
30 | | - * NiFi instance, or an uploaded flow definition). The framework discovers this capability by checking whether a |
31 | | - * Connector is an instance of {@code MigratableConnector}; Connectors that do not implement this interface are |
32 | | - * never offered as migration targets. |
| 38 | + * Connectors must not call |
| 39 | + * {@link ConnectorInitializationContext#updateFlow(FlowContext, org.apache.nifi.flow.VersionedExternalFlow) |
| 40 | + * updateFlow(...)} during migration. The framework applies recorded configuration by calling |
| 41 | + * {@link Connector#applyUpdate(FlowContext, FlowContext) applyUpdate(...)} between phases, then writes recorded |
| 42 | + * state. If any phase fails, migration is rolled back. |
33 | 43 | * </p> |
34 | 44 | * |
35 | | - * <b>Implementation Note:</b> This API is currently experimental, as it is under very active development. As such, |
36 | | - * it is subject to change without notice between releases. |
| 45 | + * <p> |
| 46 | + * Sensitive values are not included in the source flow and must be configured by the user after migration. |
| 47 | + * </p> |
| 48 | + * |
| 49 | + * <p> |
| 50 | + * <b>Implementation Note:</b> This API is experimental and may change between releases. |
| 51 | + * </p> |
37 | 52 | */ |
38 | 53 | public interface MigratableConnector { |
39 | 54 |
|
40 | 55 | /** |
41 | | - * Indicates whether this Connector can be migrated from the source flow described by the given context. |
42 | | - * |
43 | | - * <p> |
44 | | - * Implementations should inspect the source flow structure and metadata using |
45 | | - * {@link ConnectorMigrationContext#getSourceFlow()} and return quickly without mutating the Connector or the |
46 | | - * source flow. This method must not call {@link ConnectorMigrationContext#copyAssetFromSource(String)}. |
47 | | - * </p> |
| 56 | + * Returns whether this Connector supports migration from the source flow in the given context. |
| 57 | + * This method is read-only and must not call context write methods. |
48 | 58 | * |
49 | | - * @param context the migration context describing the source flow and target Connector |
50 | | - * @return {@code true} when this Connector can be migrated from the provided source flow |
| 59 | + * @param context migration context |
| 60 | + * @return {@code true} when migration is supported |
51 | 61 | */ |
52 | 62 | boolean isMigrationSupported(ConnectorMigrationContext context); |
53 | 63 |
|
54 | 64 | /** |
55 | | - * Migrates this Connector by updating its own managed flow to mirror the configuration, parameters, and component |
56 | | - * state captured in the provided source flow. The source flow is a reference: it is read, not modified, and is not |
57 | | - * installed onto the Connector. The Connector remains the owner of its flow and is responsible for translating the |
58 | | - * source into its own representation. |
59 | | - * |
60 | | - * <p> |
61 | | - * The framework guarantees the following preconditions when this method is invoked: |
62 | | - * </p> |
63 | | - * <ul> |
64 | | - * <li>The Connector is stopped.</li> |
65 | | - * <li>The Connector has not had any configuration changes applied by the user and has not been started.</li> |
66 | | - * </ul> |
67 | | - * |
68 | | - * <p> |
69 | | - * Because of these preconditions, the implementation updates the active {@link FlowContext} directly rather than |
70 | | - * making use of {@code prepareForUpdate} and {@code applyUpdate}. Those two lifecycle methods exist to safely |
71 | | - * transition a running Connector from one active configuration to another; for migration, the Connector is |
72 | | - * already required to be in the target-safe state, so the working-to-active swap is unnecessary. |
73 | | - * </p> |
| 65 | + * First migration phase. Record configuration changes using |
| 66 | + * {@link ConnectorMigrationContext#setProperties(String, java.util.Map)} or |
| 67 | + * {@link ConnectorMigrationContext#replaceProperties(String, java.util.Map)}, and copy assets as needed. |
| 68 | + * The framework calls {@link Connector#applyUpdate(FlowContext, FlowContext)} after this method returns. |
74 | 69 | * |
75 | | - * <p> |
76 | | - * Implementations are responsible for transforming the source flow, updating the active {@link FlowContext}, and |
77 | | - * applying any parameter or step configuration changes needed by the Connector. Sensitive parameter values are not |
78 | | - * present in the source flow and must be left for the user to configure after the migration completes. |
79 | | - * </p> |
80 | | - * |
81 | | - * <p> |
82 | | - * Connectors that extend {@code AbstractConnector} can typically retain their {@link ConnectorInitializationContext} |
83 | | - * from {@code initialize(ConnectorInitializationContext)} and call |
84 | | - * {@link ConnectorInitializationContext#updateFlow(FlowContext, VersionedExternalFlow)} using |
85 | | - * {@link ConnectorMigrationContext#getActiveFlowContext()}. |
86 | | - * </p> |
| 70 | + * @param context migration context |
| 71 | + * @throws FlowUpdateException when migration fails |
| 72 | + */ |
| 73 | + void migrateConfiguration(ConnectorMigrationContext context) throws FlowUpdateException; |
| 74 | + |
| 75 | + /** |
| 76 | + * Second migration phase. This method is invoked after the framework rebuilds the managed flow from configuration. |
| 77 | + * Record component state using {@link ConnectorMigrationContext#setComponentState(String, VersionedComponentState)}. |
87 | 78 | * |
88 | | - * @param context the migration context describing the source flow and target Connector |
89 | | - * @throws FlowUpdateException when the migration cannot be completed successfully |
| 79 | + * @param context migration context |
| 80 | + * @throws FlowUpdateException when state migration fails |
90 | 81 | */ |
91 | | - void migrate(ConnectorMigrationContext context) throws FlowUpdateException; |
| 82 | + void migrateState(ConnectorMigrationContext context) throws FlowUpdateException; |
92 | 83 | } |
0 commit comments