exceptionfactory commented on code in PR #11404:
URL: https://github.com/apache/nifi/pull/11404#discussion_r3573073378
##########
nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/FlowController.java:
##########
@@ -1390,24 +1390,18 @@ public void initializeFlow(final QueueProvider
queueProvider) throws IOException
}, 0L, 30L, TimeUnit.SECONDS);
final String registrySyncInterval =
nifiProperties.getProperty("nifi.flowcontroller.registry.sync.interval", "30
min");
- final long registrySyncIntervalSeconds =
FormatUtils.getTimeDuration(registrySyncInterval, TimeUnit.SECONDS);
+ final long defaultRegistrySyncIntervalSeconds =
FormatUtils.getTimeDuration(registrySyncInterval, TimeUnit.SECONDS);
- LOG.info("Scheduled Flow Registry synchronization every {}",
registrySyncInterval);
+ // The synchronization task runs on a fixed tick but synchronizes
each Flow Registry Client's Process Groups only when
+ // that client's configured interval has elapsed. The tick is
bounded so that short per-client intervals are honored
+ // reasonably closely while avoiding needlessly frequent
iterations for the typical (minutes) interval.
+ final long registrySyncTickSeconds = Math.max(1,
Math.min(defaultRegistrySyncIntervalSeconds, 30));
- // Schedule the flow registry synchronization task
- timerDrivenEngineRef.get().scheduleWithFixedDelay(() -> {
- final ProcessGroup rootGroup = flowManager.getRootGroup();
- final List<ProcessGroup> allGroups =
rootGroup.findAllProcessGroups();
- allGroups.add(rootGroup);
+ LOG.info("Scheduled Flow Registry synchronization with a default
interval of {} and a check interval of {} seconds; "
+ + "individual Flow Registry Clients may override the
interval via the Synchronization Interval property", registrySyncInterval,
registrySyncTickSeconds);
Review Comment:
Recommend removing the explanation from the log message since it is
described in documentation.
```suggestion
LOG.info("Scheduled Flow Registry with Sync Interval [{} s]
Check Interval [{} s]", registrySyncInterval, registrySyncTickSeconds);
```
##########
nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/RegistryFlowSynchronizationTaskTest.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.controller;
+
+import org.apache.nifi.controller.flow.FlowManager;
+import org.apache.nifi.registry.flow.AbstractFlowRegistryClient;
+import org.apache.nifi.registry.flow.FlowRegistryClientNode;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+class RegistryFlowSynchronizationTaskTest {
+
+ private static final long DEFAULT_INTERVAL_SECONDS = 1800L;
+
+ @Test
+ void testParseIntervalSecondsFallsBackToDefaultWhenNotConfigured() {
+ assertEquals(DEFAULT_INTERVAL_SECONDS,
RegistryFlowSynchronizationTask.parseIntervalSeconds(null,
DEFAULT_INTERVAL_SECONDS));
+ assertEquals(DEFAULT_INTERVAL_SECONDS,
RegistryFlowSynchronizationTask.parseIntervalSeconds("",
DEFAULT_INTERVAL_SECONDS));
+ assertEquals(DEFAULT_INTERVAL_SECONDS,
RegistryFlowSynchronizationTask.parseIntervalSeconds(" ",
DEFAULT_INTERVAL_SECONDS));
+ }
+
+ @Test
+ void testParseIntervalSecondsParsesConfiguredDuration() {
+ assertEquals(300L,
RegistryFlowSynchronizationTask.parseIntervalSeconds("5 min",
DEFAULT_INTERVAL_SECONDS));
+ assertEquals(45L,
RegistryFlowSynchronizationTask.parseIntervalSeconds("45 secs",
DEFAULT_INTERVAL_SECONDS));
+ assertEquals(45L,
RegistryFlowSynchronizationTask.parseIntervalSeconds(" 45 secs ",
DEFAULT_INTERVAL_SECONDS));
+ }
+
+ @Test
+ void testParseIntervalSecondsFallsBackToDefaultWhenInvalid() {
+ assertEquals(DEFAULT_INTERVAL_SECONDS,
RegistryFlowSynchronizationTask.parseIntervalSeconds("not-a-duration",
DEFAULT_INTERVAL_SECONDS));
+ }
+
+ @Test
+ void testGetEffectiveIntervalSeconds() {
+ final FlowManager flowManager = Mockito.mock(FlowManager.class);
+ final RegistryFlowSynchronizationTask task = new
RegistryFlowSynchronizationTask(flowManager, DEFAULT_INTERVAL_SECONDS);
+
+ final FlowRegistryClientNode configuredClient =
Mockito.mock(FlowRegistryClientNode.class);
+
Mockito.when(configuredClient.getEffectivePropertyValue(AbstractFlowRegistryClient.SYNCHRONIZATION_INTERVAL)).thenReturn("10
min");
Review Comment:
The `Mockito.when` and `Mockito.mock` calls can replaced with a static
import and use of `when` and `mock`
--
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]