diff --git a/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/parameter/StandardParameterContext.java b/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/parameter/StandardParameterContext.java index 59655ecc5108..00485d143507 100644 --- a/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/parameter/StandardParameterContext.java +++ b/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/parameter/StandardParameterContext.java @@ -880,8 +880,9 @@ private void validateReferencingComponents(final String parameterName, final Par final ControllerServiceState serviceState = serviceNode.getState(); if (serviceState != ControllerServiceState.DISABLED && enforceReferencingState) { - throw new IllegalStateException("Cannot " + action + " parameter '" + parameterName + "' because it is referenced by " - + serviceNode + ", which currently has a state of " + serviceState); + throw new IllegalStateException("Cannot " + action + " parameter '" + parameterName + "' because it is referenced by controller service '" + serviceNode.getName() + + "' (" + serviceNode.getComponentType() + ", id=" + serviceNode.getIdentifier() + "), which has state " + serviceState + + " instead of " + ControllerServiceState.DISABLED); } if (parameter != null) { diff --git a/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/parameter/TestStandardParameterContext.java b/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/parameter/TestStandardParameterContext.java index e350056e64e3..023c0eb372c4 100644 --- a/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/parameter/TestStandardParameterContext.java +++ b/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/parameter/TestStandardParameterContext.java @@ -614,6 +614,9 @@ public void testChangingParameterForEnabledControllerService() { final ParameterContext context = createStandardParameterContext(referenceManager); final ControllerServiceNode serviceNode = mock(ControllerServiceNode.class); enableControllerService(serviceNode); + when(serviceNode.getName()).thenReturn("My Service"); + when(serviceNode.getComponentType()).thenReturn("MyService"); + when(serviceNode.getIdentifier()).thenReturn("service-id"); final ParameterDescriptor abcDescriptor = new ParameterDescriptor.Builder().name("abc").sensitive(true).build(); final Map parameters = new HashMap<>(); @@ -629,24 +632,29 @@ public void testChangingParameterForEnabledControllerService() { for (final ControllerServiceState state : EnumSet.of(ControllerServiceState.ENABLED, ControllerServiceState.ENABLING, ControllerServiceState.DISABLING)) { setControllerServiceState(serviceNode, state); - try { - context.setParameters(parameters); - fail("Was able to update parameter being referenced by Controller Service that is " + state); - } catch (final IllegalStateException expected) { - } + final IllegalStateException exception = assertThrows(IllegalStateException.class, () -> context.setParameters(parameters)); + assertControllerServiceReferenceMessage(exception.getMessage(), "update", state); assertEquals("123", context.getParameter("abc").get().getValue()); } + setControllerServiceState(serviceNode, ControllerServiceState.DISABLING); parameters.clear(); - context.setParameters(parameters); + parameters.put("abc", null); + final IllegalStateException exception = assertThrows(IllegalStateException.class, () -> context.setParameters(parameters)); + assertControllerServiceReferenceMessage(exception.getMessage(), "remove", ControllerServiceState.DISABLING); + } - parameters.put("abc", createParameter(abcDescriptor, null)); - try { - context.setParameters(parameters); - fail("Was able to remove parameter being referenced by Controller Service that is DISABLING"); - } catch (final IllegalStateException expected) { - } + private static void assertControllerServiceReferenceMessage(final String message, final String action, final ControllerServiceState state) { + assertTrue(message.contains("Cannot " + action + " parameter")); + assertTrue(message.contains("abc")); + assertTrue(message.contains("controller service")); + assertTrue(message.contains("My Service")); + assertTrue(message.contains("MyService")); + assertTrue(message.contains("service-id")); + assertTrue(message.contains(state.name())); + assertTrue(message.contains(ControllerServiceState.DISABLED.name())); + assertFalse(message.contains("StandardControllerServiceNode")); } private ParameterContext createStandardParameterContext(final ParameterReferenceManager referenceManager) {