kirklund commented on a change in pull request #6610:
URL: https://github.com/apache/geode/pull/6610#discussion_r665580177



##########
File path: 
geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/functions/UndeployFunction.java
##########
@@ -62,14 +57,33 @@ public void execute(FunctionContext<Object[]> context) {
         memberId = member.getName();
       }
 
-      List<DeploymentInfo> undeployedJars = new LinkedList<>();
+      List<String> jarNamesToUndeploy;
       if (ArrayUtils.isNotEmpty(jarFilenameList)) {
-        undeployedJars.addAll(undeployByFileNames(memberId, jarFilenameList));
-      } else if (ArrayUtils.isNotEmpty(deploymentNameList)) {
-        undeployedJars.addAll(undeployByDeploymentName(memberId, 
deploymentNameList));
+        jarNamesToUndeploy = 
Arrays.stream(jarFilenameList).collect(Collectors.toList());
       } else {
-        // With no jars or deployments specified, all the deployed jars need 
to be removed
-        undeployedJars.addAll(undeployAll(memberId));
+        final List<Deployment> jarClassLoaders =
+            
ClassPathLoader.getLatest().getJarDeploymentService().listDeployed();
+        jarNamesToUndeploy =
+            jarClassLoaders.stream().map(Deployment::getFileName)
+                .collect(Collectors.toList());
+      }
+
+      Map<String, String> undeployedJars = new HashMap<>();
+      for (String jarName : jarNamesToUndeploy) {
+        String jarLocation;
+        try {
+          ServiceResult<Deployment> deploymentServiceResult =
+              
ClassPathLoader.getLatest().getJarDeploymentService().undeployByFileName(jarName);
+          if (deploymentServiceResult.isSuccessful()) {
+            jarLocation = deploymentServiceResult.getMessage().getFilePath();
+          } else {
+            throw new 
IllegalArgumentException(deploymentServiceResult.getErrorMessage());
+          }
+        } catch (IllegalArgumentException iaex) {
+          // It's okay for it to have have been undeployed from this server
+          jarLocation = iaex.getMessage();
+        }

Review comment:
       Catching the `IllegalArgumentException` that was thrown from inside the 
try-catch is an example of using exceptions for normal code flow which should 
be avoided.
   
   How about simplifying it to:
   ```
   Map<String, String> undeployedJars = new HashMap<>();
   for (String jarName : jarNamesToUndeploy) {
     String jarLocation;
     ServiceResult<Deployment> deploymentServiceResult =
         
ClassPathLoader.getLatest().getJarDeploymentService().undeployByFileName(jarName);
     if (deploymentServiceResult.isSuccessful()) {
       jarLocation = deploymentServiceResult.getMessage().getFilePath();
     } else {
       jarLocation = deploymentServiceResult.getErrorMessage();
     }
     undeployedJars.put(jarName, jarLocation);
   }
   ```




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