pvillard31 commented on code in PR #11255:
URL: https://github.com/apache/nifi/pull/11255#discussion_r3253301218
##########
nifi-system-tests/nifi-system-test-suite/src/test/java/org/apache/nifi/tests/system/registry/ParameterContextPreservationIT.java:
##########
@@ -245,6 +245,95 @@ void
testNewParameterInInheritedContextSynchronizedDuringUpgrade() throws NiFiCl
assertTrue(p2NamesAfterUpgrade.contains("paramX"), "paramX should
exist on P2 after upgrading to version 2");
}
+ /**
+ * Verifies that a new parameter introduced by a new flow version is
applied only to the parameter context
+ * actually bound to the upgraded process group, even when the local flow
has multiple deployments of the
+ * same versioned flow with REPLACE-strategy suffix-renamed parameter
contexts (P, P (1), P (2)).
+ *
+ * Scenario: Flow F has parameter context P. F is imported three times
with the REPLACE strategy, producing
+ * deployments bound to P, P (1), and P (2) respectively. Version 2 of F
adds parameter Z to P. Upgrading
+ * the third deployment must apply Z only to P (2); P and P (1) must
remain unchanged.
+ */
+ @Test
+ void testNewParameterAppliedOnlyToBoundSuffixedContextDuringUpgrade()
throws NiFiClientException, IOException, InterruptedException {
+ final FlowRegistryClientEntity clientEntity = registerClient();
+ final NiFiClientUtil util = getClientUtil();
+
+ // Build the source flow A bound to parameter context P, save as
version 1
+ final ParameterContextEntity sourceParamContextP =
util.createParameterContext(PARAMETER_CONTEXT_NAME, Map.of(PARAMETER_NAME,
PARAMETER_VALUE));
+ final ProcessGroupEntity sourceGroupA =
util.createProcessGroup(GROUP_A_NAME, "root");
+ util.setParameterContext(sourceGroupA.getId(), sourceParamContextP);
+
+ final ProcessorEntity processor = util.createProcessor(PROCESSOR_TYPE,
sourceGroupA.getId());
+ util.updateProcessorProperties(processor,
Collections.singletonMap(PROCESSOR_PROPERTY_TEXT, PARAMETER_REFERENCE));
+ util.setAutoTerminatedRelationships(processor, RELATIONSHIP_SUCCESS);
+
+ final VersionControlInformationEntity vciV1 =
util.startVersionControl(sourceGroupA, clientEntity, TEST_FLOWS_BUCKET,
FLOW_NAME);
+ final String flowId = vciV1.getVersionControlInformation().getFlowId();
+
+ // Add new parameter paramZ to P and save as version 2
+ final String paramZName = "paramZ";
+ final String paramZValue = "valueZ";
+ final ParameterContextEntity currentSourceP =
getNifiClient().getParamContextClient().getParamContext(sourceParamContextP.getId(),
false);
+ final ParameterContextUpdateRequestEntity sourceUpdate =
util.updateParameterContext(currentSourceP,
+ Map.of(PARAMETER_NAME, PARAMETER_VALUE, paramZName,
paramZValue));
+
util.waitForParameterContextRequestToComplete(sourceParamContextP.getId(),
sourceUpdate.getRequest().getRequestId());
+
+ final ProcessGroupEntity sourceGroupARefreshed =
getNifiClient().getProcessGroupClient().getProcessGroup(sourceGroupA.getId());
+ util.saveFlowVersion(sourceGroupARefreshed, clientEntity, vciV1);
+
+ // Clean up the source flow and parameter context so that subsequent
imports start from a clean slate
+ final ProcessGroupEntity sourceForStopVc =
getNifiClient().getProcessGroupClient().getProcessGroup(sourceGroupA.getId());
+
getNifiClient().getVersionsClient().stopVersionControl(sourceForStopVc);
+ util.deleteAll(sourceGroupA.getId());
+ final ProcessGroupEntity sourceToDelete =
getNifiClient().getProcessGroupClient().getProcessGroup(sourceGroupA.getId());
+
getNifiClient().getProcessGroupClient().deleteProcessGroup(sourceToDelete);
+
+ final ParameterContextEntity sourceContextToDelete =
getNifiClient().getParamContextClient().getParamContext(sourceParamContextP.getId(),
false);
+
getNifiClient().getParamContextClient().deleteParamContext(sourceParamContextP.getId(),
+
String.valueOf(sourceContextToDelete.getRevision().getVersion()));
+
+ // Import version 1 three times. With the REPLACE strategy, each
import creates a new parameter context:
+ // A1 -> P, A2 -> P (1), A3 -> P (2).
+ final ProcessGroupEntity importedA1 =
importFlowWithReplaceParameterContext(clientEntity.getId(), flowId, VERSION_1);
+ final String paramContextId1 =
getNifiClient().getProcessGroupClient().getProcessGroup(importedA1.getId())
+ .getComponent().getParameterContext().getId();
+
+ final ProcessGroupEntity importedA2 =
importFlowWithReplaceParameterContext(clientEntity.getId(), flowId, VERSION_1);
+ final String paramContextId2 =
getNifiClient().getProcessGroupClient().getProcessGroup(importedA2.getId())
+ .getComponent().getParameterContext().getId();
+
+ final ProcessGroupEntity importedA3 =
importFlowWithReplaceParameterContext(clientEntity.getId(), flowId, VERSION_1);
+ final String paramContextId3 =
getNifiClient().getProcessGroupClient().getProcessGroup(importedA3.getId())
+ .getComponent().getParameterContext().getId();
+
+ assertNotEquals(paramContextId1, paramContextId2);
+ assertNotEquals(paramContextId2, paramContextId3);
+ assertNotEquals(paramContextId1, paramContextId3);
+
+ // None of the imported parameter contexts should have paramZ after
importing version 1
+
assertFalse(getParameterNames(getNifiClient().getParamContextClient().getParamContext(paramContextId1,
false)).contains(paramZName));
+
assertFalse(getParameterNames(getNifiClient().getParamContextClient().getParamContext(paramContextId2,
false)).contains(paramZName));
+
assertFalse(getParameterNames(getNifiClient().getParamContextClient().getParamContext(paramContextId3,
false)).contains(paramZName));
+
+ // Upgrade only the third deployment (A3, bound to P (2)) to version 2
+ util.changeFlowVersion(importedA3.getId(), VERSION_2);
+
+ // The parameter context bound to A3 must contain the new parameter
+ final ParameterContextEntity context3AfterUpgrade =
getNifiClient().getParamContextClient().getParamContext(paramContextId3, false);
+
assertTrue(getParameterNames(context3AfterUpgrade).contains(paramZName),
+ "paramZ should be added to the parameter context bound to the
upgraded deployment");
+
+ // The parameter contexts bound to the other deployments must remain
unchanged
+ final ParameterContextEntity context1AfterUpgrade =
getNifiClient().getParamContextClient().getParamContext(paramContextId1, false);
+
assertFalse(getParameterNames(context1AfterUpgrade).contains(paramZName),
+ "paramZ should not leak into the canonical parameter context
bound to a different deployment");
Review Comment:
done, thanks
--
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]