diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/controller/flow/AbstractFlowManager.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/controller/flow/AbstractFlowManager.java index 4a8a714398..176a0d01cf 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/controller/flow/AbstractFlowManager.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/controller/flow/AbstractFlowManager.java @@ -594,8 +594,8 @@ public abstract class AbstractFlowManager implements FlowManager { } @Override - public ParameterContext createParameterContext(final String id, final String name, final Map parameters, - final List inheritedContextIds, + public ParameterContext createParameterContext(final String id, final String name, final String description, + final Map parameters, final List inheritedContextIds, final ParameterProviderConfiguration parameterProviderConfiguration) { final boolean namingConflict = parameterContextManager.getParameterContexts().stream() .anyMatch(paramContext -> paramContext.getName().equals(name)); @@ -614,6 +614,7 @@ public abstract class AbstractFlowManager implements FlowManager { .parameterProviderConfiguration(parameterProviderConfiguration) .build(); parameterContext.setParameters(parameters); + parameterContext.setDescription(description); if (inheritedContextIds != null && !inheritedContextIds.isEmpty()) { if (!withParameterContextResolution.get()) { diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/flow/synchronization/StandardVersionedComponentSynchronizer.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/flow/synchronization/StandardVersionedComponentSynchronizer.java index df837ac17e..3a2a5f76fc 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/flow/synchronization/StandardVersionedComponentSynchronizer.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/flow/synchronization/StandardVersionedComponentSynchronizer.java @@ -1990,7 +1990,8 @@ public class StandardVersionedComponentSynchronizer implements VersionedComponen parameters.put(versionedParameter.getName(), parameter); } - return context.getFlowManager().createParameterContext(parameterContextId, versionedParameterContext.getName(), parameters, Collections.emptyList(), null); + return context.getFlowManager().createParameterContext(parameterContextId, versionedParameterContext.getName(), versionedParameterContext.getDescription(), + parameters, Collections.emptyList(), null); } private ParameterProviderConfiguration getParameterProviderConfiguration(final VersionedParameterContext context) { @@ -2013,7 +2014,8 @@ public class StandardVersionedComponentSynchronizer implements VersionedComponen final AtomicReference contextReference = new AtomicReference<>(); context.getFlowManager().withParameterContextResolution(() -> { - final ParameterContext created = context.getFlowManager().createParameterContext(parameterContextId, versionedParameterContext.getName(), parameters, parameterContextRefs, + final ParameterContext created = context.getFlowManager().createParameterContext(parameterContextId, versionedParameterContext.getName(), + versionedParameterContext.getDescription(), parameters, parameterContextRefs, getParameterProviderConfiguration(versionedParameterContext)); contextReference.set(created); }); diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/flow/synchronization/StandardVersionedComponentSynchronizerTest.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/flow/synchronization/StandardVersionedComponentSynchronizerTest.java index 66f8eb2ed7..0f508004a3 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/flow/synchronization/StandardVersionedComponentSynchronizerTest.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/flow/synchronization/StandardVersionedComponentSynchronizerTest.java @@ -181,10 +181,14 @@ public class StandardVersionedComponentSynchronizerTest { .parameterReferenceManager(parameterReferenceManager) .build(); - final Map parameterMap = invocation.getArgument(2, Map.class); + final String description = invocation.getArgument(2, String.class); + parameterContext.setDescription(description); + + final Map parameterMap = invocation.getArgument(3, Map.class); parameterContext.setParameters(parameterMap); - final List inheritedContextIds = invocation.getArgument(3, List.class); + + final List inheritedContextIds = invocation.getArgument(4, List.class); final List inheritedContexts = inheritedContextIds.stream() .map(parameterContextManager::getParameterContext) .collect(Collectors.toList()); @@ -193,7 +197,7 @@ public class StandardVersionedComponentSynchronizerTest { parameterContextManager.addParameterContext(parameterContext); return parameterContext; - }).when(flowManager).createParameterContext(anyString(), anyString(), anyMap(), anyList(), or(any(ParameterProviderConfiguration.class), isNull())); + }).when(flowManager).createParameterContext(anyString(), anyString(), anyString(), anyMap(), anyList(), or(any(ParameterProviderConfiguration.class), isNull())); final VersionedFlowSynchronizationContext context = new VersionedFlowSynchronizationContext.Builder() .componentIdGenerator(componentIdGenerator) diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/controller/flow/FlowManager.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/controller/flow/FlowManager.java index d045cb598c..a7fb472b4a 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/controller/flow/FlowManager.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/controller/flow/FlowManager.java @@ -360,6 +360,7 @@ public interface FlowManager extends ParameterProviderLookup { * * @param id The unique id * @param name The ParameterContext name + * @param description The ParameterContext description * @param parameters The Parameters * @param inheritedContextIds The identifiers of any Parameter Contexts that the newly created Parameter Context should inherit from. The order of the identifiers in the List determines the * order in which parameters with conflicting names are resolved. I.e., the Parameter Context whose ID comes first in the List is preferred. @@ -368,8 +369,8 @@ public interface FlowManager extends ParameterProviderLookup { * @throws IllegalStateException If parameterContexts is not empty and this method is called without being wrapped * by {@link FlowManager#withParameterContextResolution(Runnable)} */ - ParameterContext createParameterContext(String id, String name, Map parameters, List inheritedContextIds, - ParameterProviderConfiguration parameterProviderConfiguration); + ParameterContext createParameterContext(String id, String name, String description, Map parameters, + List inheritedContextIds, ParameterProviderConfiguration parameterProviderConfiguration); /** * Performs the given ParameterContext-related action, and then resolves all inherited ParameterContext references. diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/serialization/VersionedFlowSynchronizer.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/serialization/VersionedFlowSynchronizer.java index bbfddb10ec..5db7190bf1 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/serialization/VersionedFlowSynchronizer.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/serialization/VersionedFlowSynchronizer.java @@ -815,8 +815,8 @@ public class VersionedFlowSynchronizer implements FlowSynchronizer { parameterProviderConfiguration = new StandardParameterProviderConfiguration(versionedParameterContext.getParameterProvider(), versionedParameterContext.getParameterGroupName(), versionedParameterContext.isSynchronized()); } - flowManager.createParameterContext(versionedParameterContext.getInstanceIdentifier(), versionedParameterContext.getName(), parameters, referenceIds, - parameterProviderConfiguration); + flowManager.createParameterContext(versionedParameterContext.getInstanceIdentifier(), versionedParameterContext.getName(), versionedParameterContext.getDescription(), + parameters, referenceIds, parameterProviderConfiguration); logger.info("Added Parameter Context {}", versionedParameterContext.getName()); } diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/TestFlowController.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/TestFlowController.java index 290f9cfc2f..f4b504e774 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/TestFlowController.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/TestFlowController.java @@ -118,6 +118,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -478,7 +479,7 @@ public class TestFlowController { parameters.put("param", new Parameter(new ParameterDescriptor.Builder().name("param").build(), "value")); // No problem since there are no inherited parameter contexts - controller.getFlowManager().createParameterContext("id", "name", parameters, Collections.emptyList(), null); + controller.getFlowManager().createParameterContext("id", "name", "description", parameters, Collections.emptyList(), null); final ParameterContext existingParameterContext = controller.getFlowManager().getParameterContextManager().getParameterContext("context"); final ParameterContextReferenceDTO dto = new ParameterContextReferenceDTO(); @@ -487,17 +488,40 @@ public class TestFlowController { // This is not wrapped in FlowManager#withParameterContextResolution(Runnable), so it will throw an exception assertThrows(IllegalStateException.class, () -> - controller.getFlowManager().createParameterContext("id", "name", parameters, Collections.singletonList(existingParameterContext.getIdentifier()), null)); + controller.getFlowManager().createParameterContext("id", "name", "description", parameters, Collections.singletonList(existingParameterContext.getIdentifier()), null)); // Instead, this is how it should be called controller.getFlowManager().withParameterContextResolution(() -> controller - .getFlowManager().createParameterContext("id2", "name2", parameters, Collections.singletonList(existingParameterContext.getIdentifier()), null)); + .getFlowManager().createParameterContext("id2", "name2", "description2", parameters, Collections.singletonList(existingParameterContext.getIdentifier()), null)); } finally { purgeFlow(); } } + @Test + public void testCreateParameterContextLoadsDescription() throws IOException { + final String authFingerprint = authorizer.getFingerprint(); + final File flowFile = new File("src/test/resources/conf/parameter-context-flow-description.json"); + final String flow = IOUtils.toString(new FileInputStream(flowFile), StandardCharsets.UTF_8); + final DataFlow proposedDataFlow = new StandardDataFlow(flow.getBytes(StandardCharsets.UTF_8), null, authFingerprint.getBytes(StandardCharsets.UTF_8), Collections.emptySet()); + + try { + controller.synchronize(flowSynchronizer, proposedDataFlow, mock(FlowService.class), BundleUpdateStrategy.IGNORE_BUNDLE); + controller.initializeFlow(); + + ParameterContext parameterContext = controller.getFlowManager().getParameterContextManager().getParameterContext("context"); + assertNotNull(parameterContext); + assertNull(parameterContext.getDescription()); + + ParameterContext parameterContext2 = controller.getFlowManager().getParameterContextManager().getParameterContext("context2"); + assertNotNull(parameterContext2); + assertEquals("description", parameterContext2.getDescription()); + } finally { + purgeFlow(); + } + } + private void purgeFlow() { final ProcessGroup processGroup = controller.getFlowManager().getRootGroup(); for (final ProcessorNode procNode : processGroup.getProcessors()) { diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/conf/parameter-context-flow-description.json b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/conf/parameter-context-flow-description.json new file mode 100644 index 0000000000..358172701a --- /dev/null +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/resources/conf/parameter-context-flow-description.json @@ -0,0 +1,60 @@ +{ + "encodingVersion": { + "majorVersion": 2, + "minorVersion": 0 + }, + "maxTimerDrivenThreadCount": 10, + "registries": [], + "parameterContexts": [ + { + "identifier": "e5033705-0219-3aa5-88d4-542cd7f1c13d", + "instanceIdentifier": "context", + "name": "context", + "parameters": [], + "inheritedParameterContexts": [], + "componentType": "PARAMETER_CONTEXT" + }, + { + "identifier": "8304c86e-2662-3f0b-9b54-153015055f25", + "instanceIdentifier": "context2", + "name": "context2", + "parameters": [], + "inheritedParameterContexts": [], + "description": "description", + "componentType": "PARAMETER_CONTEXT" + } + ], + "parameterProviders": [], + "controllerServices": [], + "reportingTasks": [], + "flowAnalysisRules": [], + "rootGroup": { + "identifier": "55cf3437-cecb-3f77-806a-b742995a79b9", + "instanceIdentifier": "e6bf1066-018a-1000-97f3-ca4c6fe9e05c", + "name": "NiFi Flow", + "comments": "", + "position": { + "x": 0.0, + "y": 0.0 + }, + "processGroups": [], + "remoteProcessGroups": [], + "processors": [], + "inputPorts": [], + "outputPorts": [], + "connections": [], + "labels": [], + "funnels": [], + "controllerServices": [], + "defaultFlowFileExpiration": "0 sec", + "defaultBackPressureObjectThreshold": 10000, + "defaultBackPressureDataSizeThreshold": "1 GB", + "scheduledState": "ENABLED", + "executionEngine": "INHERITED", + "maxConcurrentTasks": 1, + "statelessFlowTimeout": "1 min", + "componentType": "PROCESS_GROUP", + "flowFileOutboundPolicy": "STREAM_WHEN_AVAILABLE", + "flowFileConcurrency": "UNBOUNDED" + } +} \ No newline at end of file diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/impl/StandardParameterContextDAO.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/impl/StandardParameterContextDAO.java index 883e5de787..da039f0b65 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/impl/StandardParameterContextDAO.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/impl/StandardParameterContextDAO.java @@ -99,7 +99,7 @@ public class StandardParameterContextDAO implements ParameterContextDAO { final ParameterProviderConfiguration parameterProviderConfiguration = createParameterProviderConfiguration(parameterProviderConfigurationEntity); final ParameterContext parameterContext = flowManager.createParameterContext(parameterContextDto.getId(), parameterContextDto.getName(), - parameters, referencedIds, parameterProviderConfiguration); + parameterContextDto.getDescription(), parameters, referencedIds, parameterProviderConfiguration); if (parameterContextDto.getDescription() != null) { parameterContext.setDescription(parameterContextDto.getDescription()); }