NIFI-13990 Fixed CLI pg-enable-services failing if parent PG has disabled CS (#9504)

Signed-off-by: David Handermann <exceptionfactory@apache.org>
This commit is contained in:
Pierre Villard 2024-11-14 04:19:32 +01:00 committed by GitHub
parent 6fb208807e
commit 21e7eef660
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 9 additions and 4 deletions

View File

@ -22,6 +22,7 @@ import org.apache.nifi.web.api.entity.ControllerServiceEntity;
import org.apache.nifi.web.api.entity.ControllerServicesEntity; import org.apache.nifi.web.api.entity.ControllerServicesEntity;
import java.io.IOException; import java.io.IOException;
import java.util.List;
/** /**
* Utility methods for controller service commands. * Utility methods for controller service commands.
@ -31,18 +32,22 @@ public class ControllerServiceUtil {
public static ControllerServiceStateCounts getControllerServiceStates(final FlowClient flowClient, final String pgId) public static ControllerServiceStateCounts getControllerServiceStates(final FlowClient flowClient, final String pgId)
throws NiFiClientException, IOException { throws NiFiClientException, IOException {
final ControllerServicesEntity servicesEntity = flowClient.getControllerServices(pgId); final ControllerServicesEntity servicesEntity = flowClient.getControllerServices(pgId);
return getControllerServiceStates(servicesEntity); if (servicesEntity == null || servicesEntity.getControllerServices() == null) {
return new ControllerServiceStateCounts();
}
final List<ControllerServiceEntity> 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<ControllerServiceEntity> pgCs)
throws NiFiClientException { throws NiFiClientException {
final ControllerServiceStateCounts states = new ControllerServiceStateCounts(); final ControllerServiceStateCounts states = new ControllerServiceStateCounts();
if (servicesEntity == null || servicesEntity.getControllerServices() == null || servicesEntity.getControllerServices().isEmpty()) { if (pgCs.isEmpty()) {
return states; return states;
} }
for (final ControllerServiceEntity serviceEntity : servicesEntity.getControllerServices()) { for (final ControllerServiceEntity serviceEntity : pgCs) {
final String state = serviceEntity.getComponent().getState(); final String state = serviceEntity.getComponent().getState();
switch (state) { switch (state) {
case ControllerServiceStates.STATE_ENABLED: case ControllerServiceStates.STATE_ENABLED: