pvillard31 commented on code in PR #10238:
URL: https://github.com/apache/nifi/pull/10238#discussion_r2328643632


##########
nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/dao/impl/StandardComponentStateDAO.java:
##########
@@ -42,38 +46,98 @@ private StateMap getState(final String componentId, final 
Scope scope) {
         try {
             final StateManager manager = 
stateManagerProvider.getStateManager(componentId);
             if (manager == null) {
-                throw new ResourceNotFoundException(String.format("State for 
the specified component %s could not be found.", componentId));
+                throw new ResourceNotFoundException("State for the specified 
component %s could not be found.".formatted(componentId));
             }
 
             return manager.getState(scope);
         } catch (final IOException ioe) {
-            throw new IllegalStateException(String.format("Unable to get the 
state for the specified component %s: %s", componentId, ioe), ioe);
+            throw new IllegalStateException("Unable to get the state for the 
specified component %s: %s".formatted(componentId, ioe), ioe);
         }
     }
 
-    private void clearState(final String componentId) {
+    private void clearState(final String componentId, ComponentStateDTO 
componentStateDTO) {
         try {
             final StateManager manager = 
stateManagerProvider.getStateManager(componentId);
             if (manager == null) {
-                throw new ResourceNotFoundException(String.format("State for 
the specified component %s could not be found.", componentId));
+                throw new ResourceNotFoundException("State for the specified 
component %s could not be found.".formatted(componentId));
             }
 
-            // clear both state's at the same time
-            manager.clear(Scope.CLUSTER);
-            manager.clear(Scope.LOCAL);
+            if (componentStateDTO == null) {
+                // clear both state's at the same time
+                manager.clear(Scope.CLUSTER);
+                manager.clear(Scope.LOCAL);
+            } else if (manager.getState(Scope.LOCAL) != null && 
!manager.getState(Scope.LOCAL).toMap().isEmpty() && 
!stateManagerProvider.isClusterProviderEnabled()) {

Review Comment:
   Pushed a commit with an alternative that is easier to read. It has 
intermediary returns though. Happy to go back to a full if/else branches 
approach that would be a bit simplified as you suggested.



-- 
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]

Reply via email to