-
Notifications
You must be signed in to change notification settings - Fork 3k
NIFI-16310 Preserve Controller Services created by migrateProperties during versioned flow synchronization #11670
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
Open
awelless
wants to merge
3
commits into
apache:main
Choose a base branch
from
awelless:NIFI-16310-preserve-migration-created-controller-services
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 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
248 changes: 235 additions & 13 deletions
248
...ain/java/org/apache/nifi/flow/synchronization/StandardVersionedComponentSynchronizer.java
Large diffs are not rendered by default.
Oops, something went wrong.
298 changes: 298 additions & 0 deletions
298
...java/org/apache/nifi/flow/synchronization/StandardVersionedComponentSynchronizerTest.java
Large diffs are not rendered by default.
Oops, something went wrong.
97 changes: 97 additions & 0 deletions
97
...fig-extensions/src/main/java/org/apache/nifi/cs/tests/system/StateBackedStoreService.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,97 @@ | ||
| /* | ||
| * 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.cs.tests.system; | ||
|
|
||
| import org.apache.nifi.annotation.behavior.Stateful; | ||
| import org.apache.nifi.annotation.lifecycle.OnEnabled; | ||
| import org.apache.nifi.components.PropertyDescriptor; | ||
| import org.apache.nifi.components.state.Scope; | ||
| import org.apache.nifi.components.state.StateManager; | ||
| import org.apache.nifi.components.state.StateMap; | ||
| import org.apache.nifi.controller.AbstractControllerService; | ||
| import org.apache.nifi.controller.ConfigurationContext; | ||
| import org.apache.nifi.processor.util.StandardValidators; | ||
|
|
||
| import java.io.IOException; | ||
| import java.io.UncheckedIOException; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * Store whose contents live in the component's local state, so that they are subject to the framework's own state | ||
| * lifecycle. The store records when it was first created and how many rows it holds. | ||
| * | ||
| * Removing a Controller Service clears its state, so a service that was torn down and recreated comes back with a | ||
| * later creation timestamp and no rows. Comparing the creation timestamp across an operation therefore distinguishes | ||
| * a preserved service from one that was replaced, even when the replacement carries the same identifier. | ||
| */ | ||
| @Stateful(scopes = Scope.LOCAL, description = "Holds the creation timestamp of the store and the number of rows written to it.") | ||
| public class StateBackedStoreService extends AbstractControllerService implements StoreService { | ||
|
|
||
| static final PropertyDescriptor STORE_NAME = new PropertyDescriptor.Builder() | ||
| .name("Store Name") | ||
| .required(true) | ||
| .defaultValue("store") | ||
| .addValidator(StandardValidators.NON_EMPTY_VALIDATOR) | ||
| .build(); | ||
|
|
||
| static final String CREATED_KEY = "created"; | ||
| static final String ROW_COUNT_KEY = "rowCount"; | ||
| static final String LAST_ROW_KEY = "lastRow"; | ||
|
|
||
| private static final List<PropertyDescriptor> PROPERTIES = List.of(STORE_NAME); | ||
|
|
||
| @Override | ||
| protected List<PropertyDescriptor> getSupportedPropertyDescriptors() { | ||
| return PROPERTIES; | ||
| } | ||
|
|
||
| /** | ||
| * Establishes the store on first enable and leaves it alone afterwards, so that the creation timestamp survives | ||
| * the disable and re-enable cycle that a version change performs. | ||
| */ | ||
| @OnEnabled | ||
| public void onEnabled(final ConfigurationContext context) throws IOException { | ||
| final StateManager stateManager = getStateManager(); | ||
| final StateMap stateMap = stateManager.getState(Scope.LOCAL); | ||
| if (stateMap.get(CREATED_KEY) != null) { | ||
| return; | ||
| } | ||
|
|
||
| final Map<String, String> state = new HashMap<>(); | ||
| state.put(CREATED_KEY, String.valueOf(System.currentTimeMillis())); | ||
| state.put(ROW_COUNT_KEY, "0"); | ||
| stateManager.setState(state, Scope.LOCAL); | ||
| } | ||
|
|
||
| @Override | ||
| public void append(final String row) { | ||
| try { | ||
| final StateManager stateManager = getStateManager(); | ||
| final Map<String, String> state = new HashMap<>(stateManager.getState(Scope.LOCAL).toMap()); | ||
| final long rowCount = Long.parseLong(state.getOrDefault(ROW_COUNT_KEY, "0")); | ||
| state.put(ROW_COUNT_KEY, String.valueOf(rowCount + 1)); | ||
| state.put(LAST_ROW_KEY, row); | ||
| stateManager.setState(state, Scope.LOCAL); | ||
| } catch (final IOException e) { | ||
| throw new UncheckedIOException(e); | ||
| } | ||
| } | ||
|
|
||
| } |
29 changes: 29 additions & 0 deletions
29
...ternate-config-extensions/src/main/java/org/apache/nifi/cs/tests/system/StoreService.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,29 @@ | ||
| /* | ||
| * 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.cs.tests.system; | ||
|
|
||
| import org.apache.nifi.controller.ControllerService; | ||
|
|
||
| /** | ||
| * A store that accumulates rows and whose contents must survive flow and runtime upgrades. | ||
| */ | ||
| public interface StoreService extends ControllerService { | ||
|
|
||
| void append(String row); | ||
|
|
||
| } |
90 changes: 90 additions & 0 deletions
90
...ons/src/main/java/org/apache/nifi/processors/tests/system/MigrateToControllerService.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,90 @@ | ||
| /* | ||
| * 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.processors.tests.system; | ||
|
|
||
| import org.apache.nifi.annotation.behavior.InputRequirement; | ||
| import org.apache.nifi.annotation.behavior.InputRequirement.Requirement; | ||
| import org.apache.nifi.annotation.documentation.CapabilityDescription; | ||
| import org.apache.nifi.components.PropertyDescriptor; | ||
| import org.apache.nifi.cs.tests.system.StateBackedStoreService; | ||
| import org.apache.nifi.cs.tests.system.StoreService; | ||
| import org.apache.nifi.migration.PropertyConfiguration; | ||
| import org.apache.nifi.processor.AbstractProcessor; | ||
| import org.apache.nifi.processor.ProcessContext; | ||
| import org.apache.nifi.processor.ProcessSession; | ||
| import org.apache.nifi.processor.Relationship; | ||
| import org.apache.nifi.processor.exception.ProcessException; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
| import java.util.concurrent.atomic.AtomicLong; | ||
|
|
||
| @CapabilityDescription(""" | ||
| Post-upgrade shape of a processor whose property migration creates the store Controller Service that the pre-upgrade shape did not have. | ||
| Each execution appends a row to the store so that tests can observe whether store contents survive flow and runtime upgrades. | ||
| """) | ||
| @InputRequirement(Requirement.INPUT_FORBIDDEN) | ||
| public class MigrateToControllerService extends AbstractProcessor { | ||
|
|
||
| static final PropertyDescriptor STORE_SERVICE = new PropertyDescriptor.Builder() | ||
| .name("Store Service") | ||
| .required(false) | ||
| .identifiesControllerService(StoreService.class) | ||
| .build(); | ||
|
|
||
| static final Relationship REL_SUCCESS = new Relationship.Builder().name("success").build(); | ||
|
|
||
| private static final List<PropertyDescriptor> PROPERTIES = List.of(STORE_SERVICE); | ||
| private static final Set<Relationship> RELATIONSHIPS = Set.of(REL_SUCCESS); | ||
|
|
||
| private final AtomicLong rowCounter = new AtomicLong(0L); | ||
|
|
||
| @Override | ||
| protected List<PropertyDescriptor> getSupportedPropertyDescriptors() { | ||
| return PROPERTIES; | ||
| } | ||
|
|
||
| @Override | ||
| public Set<Relationship> getRelationships() { | ||
| return RELATIONSHIPS; | ||
| } | ||
|
|
||
| @Override | ||
| public void migrateProperties(final PropertyConfiguration config) { | ||
| final String storeName = config.getPropertyValue("store-name").orElse(null); | ||
| config.removeProperty("store-name"); | ||
|
|
||
| if (storeName != null) { | ||
| final String serviceId = config.createControllerService(StateBackedStoreService.class.getName(), Map.of("Store Name", storeName)); | ||
| config.setProperty(STORE_SERVICE, serviceId); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException { | ||
| final StoreService storeService = context.getProperty(STORE_SERVICE).asControllerService(StoreService.class); | ||
| if (storeService == null) { | ||
| context.yield(); | ||
| return; | ||
| } | ||
|
|
||
| storeService.append("row-" + rowCounter.getAndIncrement()); | ||
| } | ||
|
|
||
| } | ||
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
...ons/src/main/java/org/apache/nifi/processors/tests/system/MigrateToControllerService.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.processors.tests.system; | ||
|
|
||
| import org.apache.nifi.annotation.behavior.InputRequirement; | ||
| import org.apache.nifi.annotation.behavior.InputRequirement.Requirement; | ||
| import org.apache.nifi.annotation.documentation.CapabilityDescription; | ||
| import org.apache.nifi.components.PropertyDescriptor; | ||
| import org.apache.nifi.processor.AbstractProcessor; | ||
| import org.apache.nifi.processor.ProcessContext; | ||
| import org.apache.nifi.processor.ProcessSession; | ||
| import org.apache.nifi.processor.Relationship; | ||
| import org.apache.nifi.processor.exception.ProcessException; | ||
| import org.apache.nifi.processor.util.StandardValidators; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Set; | ||
|
|
||
| @CapabilityDescription(""" | ||
| Pre-upgrade shape of a processor that keeps its store location in a plain property. | ||
| The post-upgrade shape of the same processor, in the alternate-config extensions bundle, migrates that property into a Controller Service. | ||
| """) | ||
| @InputRequirement(Requirement.INPUT_FORBIDDEN) | ||
| public class MigrateToControllerService extends AbstractProcessor { | ||
|
|
||
| static final PropertyDescriptor STORE_NAME = new PropertyDescriptor.Builder() | ||
| .name("store-name") | ||
| .displayName("Store Name") | ||
| .required(true) | ||
| .addValidator(StandardValidators.NON_EMPTY_VALIDATOR) | ||
| .build(); | ||
|
|
||
| static final Relationship REL_SUCCESS = new Relationship.Builder().name("success").build(); | ||
|
|
||
| private static final List<PropertyDescriptor> PROPERTIES = List.of(STORE_NAME); | ||
| private static final Set<Relationship> RELATIONSHIPS = Set.of(REL_SUCCESS); | ||
|
|
||
| @Override | ||
| protected List<PropertyDescriptor> getSupportedPropertyDescriptors() { | ||
| return PROPERTIES; | ||
| } | ||
|
|
||
| @Override | ||
| public Set<Relationship> getRelationships() { | ||
| return RELATIONSHIPS; | ||
| } | ||
|
|
||
| @Override | ||
| public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException { | ||
| context.yield(); | ||
| } | ||
|
|
||
| } |
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
46 changes: 46 additions & 0 deletions
46
...em-tests/nifi-system-test-flow-registry-bundle/nifi-system-test-flow-registry-nar/pom.xml
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,46 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!-- | ||
| 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. | ||
| --> | ||
| <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
|
|
||
| <parent> | ||
| <groupId>org.apache.nifi</groupId> | ||
| <artifactId>nifi-system-test-flow-registry-bundle</artifactId> | ||
| <version>2.13.0-SNAPSHOT</version> | ||
| </parent> | ||
|
|
||
| <artifactId>nifi-system-test-flow-registry-nar</artifactId> | ||
| <packaging>nar</packaging> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>org.apache.nifi</groupId> | ||
| <artifactId>nifi-api</artifactId> | ||
| <scope>provided</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.apache.nifi</groupId> | ||
| <artifactId>nifi-framework-api</artifactId> | ||
| <version>2.13.0-SNAPSHOT</version> | ||
| <scope>provided</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.apache.nifi</groupId> | ||
| <artifactId>nifi-system-test-flow-registry</artifactId> | ||
| <version>2.13.0-SNAPSHOT</version> | ||
| </dependency> | ||
| </dependencies> | ||
| </project> |
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.
Initially I wanted to reuse
MigratePropertiesprocessor, but some of its modifications blocked flow upgrade, so I proceeded with a dedicated processor - controller service pair