pvillard31 commented on code in PR #88:
URL: https://github.com/apache/nifi-api/pull/88#discussion_r3243433647


##########
src/main/java/org/apache/nifi/components/connector/Connector.java:
##########
@@ -78,6 +79,48 @@ public interface Connector {
      */
     VersionedExternalFlow getInitialFlow();
 
+    /**
+     * Indicates whether this Connector can be migrated from the provided 
source flow.
+     *
+     * <p>
+     * Implementations should inspect the source flow structure and metadata 
using {@link ConnectorMigrationContext#getSourceFlow()}
+     * and return quickly without mutating the Connector or the source flow. 
This method must not call
+     * {@link ConnectorMigrationContext#copyAssetFromSource(String)}.
+     * </p>
+     *
+     * @param context the migration context describing the source flow and 
target Connector
+     * @return {@code true} when this Connector can be migrated from the 
provided source flow
+     */
+    default boolean isMigrationSupported(ConnectorMigrationContext context) {

Review Comment:
   Did you think about putting these two methods on a separate optional 
interface like `MigratableConnector` and checking it with `instanceof`, instead 
of adding them to every `Connector`?



##########
src/main/java/org/apache/nifi/components/connector/migration/ConnectorMigrationContext.java:
##########
@@ -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.migration;
+
+import org.apache.nifi.components.connector.AssetReference;
+import org.apache.nifi.components.connector.components.FlowContext;
+import org.apache.nifi.flow.VersionedExternalFlow;
+
+/**
+ * Context provided to a Connector when evaluating or performing migration 
from a Versioned Process Group export. The
+ * source flow exposed through this context is a read-only reference that the 
Connector uses to update its own managed
+ * flow; the source flow itself is never installed onto the Connector.
+ */
+public interface ConnectorMigrationContext {
+
+    /**
+     * Returns the source flow whose configuration, parameters, and component 
state the Connector should mirror into
+     * its own managed flow.
+     *
+     * @return the source flow
+     */
+    VersionedExternalFlow getSourceFlow();
+
+    /**
+     * Indicates whether the migration source is a local Versioned Process 
Group on this NiFi instance.
+     *
+     * @return {@code true} when the source is local
+     */
+    boolean isLocalMigration();
+
+    /**
+     * Returns the active flow context for the Connector being migrated.
+     *
+     * @return the active flow context
+     */
+    FlowContext getActiveFlowContext();

Review Comment:
   Was there a reason to expose the active `FlowContext` on the context, 
instead of passing it as a parameter to `migrate(...)` like the other lifecycle 
methods do?



##########
src/main/java/org/apache/nifi/components/connector/Connector.java:
##########
@@ -78,6 +79,48 @@ public interface Connector {
      */
     VersionedExternalFlow getInitialFlow();
 
+    /**
+     * Indicates whether this Connector can be migrated from the provided 
source flow.
+     *
+     * <p>
+     * Implementations should inspect the source flow structure and metadata 
using {@link ConnectorMigrationContext#getSourceFlow()}
+     * and return quickly without mutating the Connector or the source flow. 
This method must not call
+     * {@link ConnectorMigrationContext#copyAssetFromSource(String)}.
+     * </p>
+     *
+     * @param context the migration context describing the source flow and 
target Connector
+     * @return {@code true} when this Connector can be migrated from the 
provided source flow
+     */
+    default boolean isMigrationSupported(ConnectorMigrationContext context) {
+        return false;
+    }
+
+    /**
+     * Migrates this Connector by updating its own managed flow to mirror the 
configuration, parameters, and component
+     * state captured in the provided source flow. The source flow is a 
reference: it is read, not modified, and is not
+     * installed onto the Connector. The Connector remains the owner of its 
flow and is responsible for translating the
+     * source into its own representation.
+     *
+     * <p>
+     * Implementations are responsible for transforming the source flow, 
updating the active {@link FlowContext}, and
+     * applying any parameter or step configuration changes needed by the 
Connector. Sensitive parameter values are not
+     * present in the source flow and must be left for the user to configure 
after the migration completes.
+     * </p>
+     *
+     * <p>
+     * Connectors extending {@link AbstractConnector} can typically retain 
their {@link ConnectorInitializationContext}
+     * from {@link #initialize(ConnectorInitializationContext)} and call
+     * {@link ConnectorInitializationContext#updateFlow(FlowContext, 
VersionedExternalFlow)} using
+     * {@link ConnectorMigrationContext#getActiveFlowContext()}.
+     * </p>
+     *
+     * @param context the migration context describing the source flow and 
target Connector
+     * @throws FlowUpdateException when the migration cannot be completed 
successfully
+     */
+    default void migrate(ConnectorMigrationContext context) throws 
FlowUpdateException {

Review Comment:
   Should the Javadoc also mention `UnsupportedOperationException`, since the 
default method throws that one and not `FlowUpdateException`?



##########
src/main/java/org/apache/nifi/components/connector/migration/ConnectorMigrationContext.java:
##########
@@ -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.migration;

Review Comment:
   Is the new `connector.migration` sub package there because more migration 
types are coming, or could it stay in the same package as the other context 
interfaces?



##########
src/main/java/org/apache/nifi/components/connector/migration/ConnectorMigrationContext.java:
##########
@@ -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.migration;
+
+import org.apache.nifi.components.connector.AssetReference;
+import org.apache.nifi.components.connector.components.FlowContext;
+import org.apache.nifi.flow.VersionedExternalFlow;
+
+/**
+ * Context provided to a Connector when evaluating or performing migration 
from a Versioned Process Group export. The
+ * source flow exposed through this context is a read-only reference that the 
Connector uses to update its own managed
+ * flow; the source flow itself is never installed onto the Connector.
+ */
+public interface ConnectorMigrationContext {
+
+    /**
+     * Returns the source flow whose configuration, parameters, and component 
state the Connector should mirror into
+     * its own managed flow.
+     *
+     * @return the source flow
+     */
+    VersionedExternalFlow getSourceFlow();
+
+    /**
+     * Indicates whether the migration source is a local Versioned Process 
Group on this NiFi instance.
+     *
+     * @return {@code true} when the source is local
+     */
+    boolean isLocalMigration();
+
+    /**
+     * Returns the active flow context for the Connector being migrated.
+     *
+     * @return the active flow context
+     */
+    FlowContext getActiveFlowContext();
+
+    /**
+     * Copies the referenced source asset into the Connector asset namespace. 
When the source asset cannot be located
+     * in the source asset manager (for example because it was deleted from 
the local source after the migration
+     * request started), the framework logs a warning and returns an {@link 
AssetReference} with no asset identifiers
+     * so the Connector can continue the migration without the missing asset. 
Callers should treat an empty asset
+     * reference as "asset not migrated" and decide how to handle that for the 
affected parameter (typically by
+     * leaving the parameter without an asset reference for the user to 
re-attach after migration completes).
+     *
+     * @param sourceAssetId the identifier of the source asset
+     * @return an asset reference for the newly copied asset, or an asset 
reference with no identifiers when the
+     *         source asset could not be located
+     * @throws IllegalArgumentException when {@code sourceAssetId} is null or 
blank, or when invoked for an uploaded

Review Comment:
   Would `IllegalStateException` fit better than `IllegalArgumentException` for 
the uploaded payload case, since the id is valid and only the context does not 
support the call?



##########
src/main/java/org/apache/nifi/components/connector/migration/ConnectorMigrationContext.java:
##########
@@ -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.migration;
+
+import org.apache.nifi.components.connector.AssetReference;
+import org.apache.nifi.components.connector.components.FlowContext;
+import org.apache.nifi.flow.VersionedExternalFlow;
+
+/**
+ * Context provided to a Connector when evaluating or performing migration 
from a Versioned Process Group export. The
+ * source flow exposed through this context is a read-only reference that the 
Connector uses to update its own managed
+ * flow; the source flow itself is never installed onto the Connector.
+ */
+public interface ConnectorMigrationContext {
+
+    /**
+     * Returns the source flow whose configuration, parameters, and component 
state the Connector should mirror into
+     * its own managed flow.
+     *
+     * @return the source flow
+     */
+    VersionedExternalFlow getSourceFlow();
+
+    /**
+     * Indicates whether the migration source is a local Versioned Process 
Group on this NiFi instance.
+     *
+     * @return {@code true} when the source is local
+     */
+    boolean isLocalMigration();
+
+    /**
+     * Returns the active flow context for the Connector being migrated.
+     *
+     * @return the active flow context
+     */
+    FlowContext getActiveFlowContext();
+
+    /**
+     * Copies the referenced source asset into the Connector asset namespace. 
When the source asset cannot be located
+     * in the source asset manager (for example because it was deleted from 
the local source after the migration
+     * request started), the framework logs a warning and returns an {@link 
AssetReference} with no asset identifiers
+     * so the Connector can continue the migration without the missing asset. 
Callers should treat an empty asset
+     * reference as "asset not migrated" and decide how to handle that for the 
affected parameter (typically by
+     * leaving the parameter without an asset reference for the user to 
re-attach after migration completes).
+     *
+     * @param sourceAssetId the identifier of the source asset
+     * @return an asset reference for the newly copied asset, or an asset 
reference with no identifiers when the
+     *         source asset could not be located
+     * @throws IllegalArgumentException when {@code sourceAssetId} is null or 
blank, or when invoked for an uploaded
+     *                                  payload migration (assets are not 
available on the uploaded-payload path)
+     */
+    AssetReference copyAssetFromSource(String sourceAssetId);

Review Comment:
   How should a Connector tell the user that a source asset was not found, just 
by checking that `getAssetIdentifiers()` is empty, or is there a better signal 
planned?



##########
src/main/java/org/apache/nifi/components/connector/Connector.java:
##########
@@ -78,6 +79,48 @@ public interface Connector {
      */
     VersionedExternalFlow getInitialFlow();
 
+    /**
+     * Indicates whether this Connector can be migrated from the provided 
source flow.
+     *
+     * <p>
+     * Implementations should inspect the source flow structure and metadata 
using {@link ConnectorMigrationContext#getSourceFlow()}
+     * and return quickly without mutating the Connector or the source flow. 
This method must not call
+     * {@link ConnectorMigrationContext#copyAssetFromSource(String)}.
+     * </p>
+     *
+     * @param context the migration context describing the source flow and 
target Connector
+     * @return {@code true} when this Connector can be migrated from the 
provided source flow
+     */
+    default boolean isMigrationSupported(ConnectorMigrationContext context) {
+        return false;
+    }
+
+    /**
+     * Migrates this Connector by updating its own managed flow to mirror the 
configuration, parameters, and component

Review Comment:
   Is the Connector expected to be stopped when `migrate(...)` is called, and 
is it on purpose that it updates the active `FlowContext` directly instead of 
going through `prepareForUpdate` and `applyUpdate`?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to