You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ha...@apache.org on 2018/06/21 13:05:44 UTC

[ambari] branch trunk updated: [AMBARI-24160] Inaccurate error message showed during service removal in some circumstances (dgrinenko)

This is an automated email from the ASF dual-hosted git repository.

hapylestat pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ambari.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 303ba2e  [AMBARI-24160] Inaccurate error message showed during service removal in some circumstances (dgrinenko)
303ba2e is described below

commit 303ba2e18eebcb3aa7d89104a1b2ecff702b44b4
Author: Dmitry Grinenko <ha...@gmail.com>
AuthorDate: Thu Jun 21 09:14:36 2018 +0300

    [AMBARI-24160] Inaccurate error message showed during service removal in some circumstances (dgrinenko)
---
 .../internal/ServiceResourceProvider.java          | 29 ++++++++++------------
 1 file changed, 13 insertions(+), 16 deletions(-)

diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceResourceProvider.java
index 4e080fc..4946f33 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceResourceProvider.java
@@ -28,6 +28,7 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.stream.Collectors;
 
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.ClusterNotFoundException;
@@ -937,24 +938,20 @@ public class ServiceResourceProvider extends AbstractControllerResourceProvider
         // Run through the list of service component hosts. If all host components are in removable state,
         // the service can be deleted, irrespective of it's state.
         //
-        boolean isServiceRemovable = true;
-
-        for (ServiceComponent sc : service.getServiceComponents().values()) {
-          Map<String, ServiceComponentHost> schHostMap = sc.getServiceComponentHosts();
-
-          for (Map.Entry<String, ServiceComponentHost> entry : schHostMap.entrySet()) {
-            ServiceComponentHost sch = entry.getValue();
-            if (!sch.canBeRemoved()) {
-              String msg = "Cannot remove " + serviceRequest.getClusterName() + "/" + serviceRequest.getServiceName() +
-                      ". " + sch.getServiceComponentName() + "on " + sch.getHost() + " is in " +
-                      String.valueOf(sch.getDesiredState()) + " state.";
-              LOG.error(msg);
-              isServiceRemovable = false;
-            }
+        List<ServiceComponentHost> nonRemovableComponents =  service.getServiceComponents().values().stream()
+          .flatMap(sch -> sch.getServiceComponentHosts().values().stream())
+          .filter(sch -> !sch.canBeRemoved())
+          .collect(Collectors.toList());
+
+        if (!nonRemovableComponents.isEmpty()) {
+          for (ServiceComponentHost sch: nonRemovableComponents){
+            String msg = String.format("Cannot remove %s/%s. %s on %s is in %s state.",
+              serviceRequest.getClusterName(), serviceRequest.getServiceName(), sch.getServiceComponentName(),
+              sch.getHost(), String.valueOf(sch.getState()));
+
+            LOG.error(msg);
           }
-        }
 
-        if (!isServiceRemovable) {
           throw new AmbariException ("Cannot remove " +
                   serviceRequest.getClusterName() + "/" + serviceRequest.getServiceName() +
                     ". " + "One or more host components are in a non-removable state.");