From 21e7eef660fd7caabbb89c75c56ce8bfd72658fb Mon Sep 17 00:00:00 2001 From: Pierre Villard Date: Thu, 14 Nov 2024 04:19:32 +0100 Subject: [PATCH] NIFI-13990 Fixed CLI pg-enable-services failing if parent PG has disabled CS (#9504) Signed-off-by: David Handermann --- .../command/nifi/pg/cs/ControllerServiceUtil.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/command/nifi/pg/cs/ControllerServiceUtil.java b/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/command/nifi/pg/cs/ControllerServiceUtil.java index e44f235413..8603338271 100644 --- a/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/command/nifi/pg/cs/ControllerServiceUtil.java +++ b/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/command/nifi/pg/cs/ControllerServiceUtil.java @@ -22,6 +22,7 @@ import org.apache.nifi.web.api.entity.ControllerServiceEntity; import org.apache.nifi.web.api.entity.ControllerServicesEntity; import java.io.IOException; +import java.util.List; /** * Utility methods for controller service commands. @@ -31,18 +32,22 @@ public class ControllerServiceUtil { public static ControllerServiceStateCounts getControllerServiceStates(final FlowClient flowClient, final String pgId) throws NiFiClientException, IOException { final ControllerServicesEntity servicesEntity = flowClient.getControllerServices(pgId); - return getControllerServiceStates(servicesEntity); + if (servicesEntity == null || servicesEntity.getControllerServices() == null) { + return new ControllerServiceStateCounts(); + } + final List pgCs = servicesEntity.getControllerServices().stream().filter(c -> c.getParentGroupId().equals(pgId)).toList(); + return getControllerServiceStates(pgCs); } - public static ControllerServiceStateCounts getControllerServiceStates(final ControllerServicesEntity servicesEntity) + private static ControllerServiceStateCounts getControllerServiceStates(final List pgCs) throws NiFiClientException { final ControllerServiceStateCounts states = new ControllerServiceStateCounts(); - if (servicesEntity == null || servicesEntity.getControllerServices() == null || servicesEntity.getControllerServices().isEmpty()) { + if (pgCs.isEmpty()) { return states; } - for (final ControllerServiceEntity serviceEntity : servicesEntity.getControllerServices()) { + for (final ControllerServiceEntity serviceEntity : pgCs) { final String state = serviceEntity.getComponent().getState(); switch (state) { case ControllerServiceStates.STATE_ENABLED: