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

amagyar pushed a commit to branch branch-2.7
in repository https://gitbox.apache.org/repos/asf/ambari.git


The following commit(s) were added to refs/heads/branch-2.7 by this push:
     new 57f13ae  [AMBARI-25297] : Host names array to string conversion 
improvement (Backport to branch-2.7) (#3004)
57f13ae is described below

commit 57f13ae1a21c623eaec8a7727ca01bd74cdef7d3
Author: virajjasani <34790606+virajjas...@users.noreply.github.com>
AuthorDate: Fri Jun 14 14:30:29 2019 +0530

    [AMBARI-25297] : Host names array to string conversion improvement 
(Backport to branch-2.7) (#3004)
    
    * [AMBARI-25297] : Host names array to string conversion improvement 
(Backport to branch-2.7)
    
    * minor changes
---
 .../apache/ambari/server/bootstrap/BSRunner.java   | 14 ++---------
 .../controller/AmbariManagementControllerImpl.java | 10 +-------
 .../ambari/server/controller/ClusterRequest.java   | 16 ++++---------
 .../controller/internal/HostResourceProvider.java  | 27 ++++------------------
 4 files changed, 11 insertions(+), 56 deletions(-)

diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/bootstrap/BSRunner.java 
b/ambari-server/src/main/java/org/apache/ambari/server/bootstrap/BSRunner.java
index c7976ee..28929d4 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/bootstrap/BSRunner.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/bootstrap/BSRunner.java
@@ -32,6 +32,7 @@ import java.util.concurrent.TimeUnit;
 
 import org.apache.ambari.server.bootstrap.BootStrapStatus.BSStat;
 import org.apache.commons.io.FileUtils;
+import org.apache.commons.lang.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -107,18 +108,7 @@ class BSRunner extends Thread {
   }
 
   private String createHostString(List<String> list) {
-    StringBuilder ret = new StringBuilder();
-    if (list == null) {
-      return "";
-    }
-
-    int i = 0;
-    for (String host: list) {
-      ret.append(host);
-      if (i++ != list.size()-1)
-        ret.append(",");
-    }
-    return ret.toString();
+    return list != null ? String.join(",", list) : StringUtils.EMPTY;
   }
 
   /** Create request id dir for each bootstrap call **/
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
index a98891f..38a8436 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
@@ -692,15 +692,7 @@ public class AmbariManagementControllerImpl implements 
AmbariManagementControlle
     }
 
     if (!duplicates.isEmpty()) {
-      StringBuilder names = new StringBuilder();
-      boolean first = true;
-      for (String hName : duplicates) {
-        if (!first) {
-          names.append(",");
-        }
-        first = false;
-        names.append(hName);
-      }
+      final String names = String.join(",", duplicates);
       String msg;
       if (duplicates.size() == 1) {
         msg = "Attempted to create a host_component which already exists: ";
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/ClusterRequest.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/ClusterRequest.java
index 12d50b0..82c64f2 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/ClusterRequest.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/ClusterRequest.java
@@ -24,6 +24,7 @@ import java.util.Set;
 
 import org.apache.ambari.server.controller.internal.ClusterResourceProvider;
 import org.apache.ambari.server.state.SecurityType;
+import org.apache.commons.lang.StringUtils;
 
 import io.swagger.annotations.ApiModelProperty;
 
@@ -144,18 +145,9 @@ public class ClusterRequest {
         .append(", securityType=").append(securityType)
         .append(", stackVersion=").append(stackVersion)
         .append(", desired_scv=").append(serviceConfigVersionRequest)
-        .append(", hosts=[");
-    if (hostNames != null) {
-      int i = 0;
-      for (String hostName : hostNames) {
-        if (i != 0) {
-          sb.append(",");
-        }
-        ++i;
-        sb.append(hostName);
-      }
-    }
-    sb.append("] }");
+        .append(", hosts=[")
+        .append(hostNames != null ? String.join(",", hostNames) : 
StringUtils.EMPTY)
+        .append("] }");
     return sb.toString();
   }
 
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostResourceProvider.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostResourceProvider.java
index 941297c..9fd135d 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostResourceProvider.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostResourceProvider.java
@@ -510,33 +510,14 @@ public class HostResourceProvider extends 
AbstractControllerResourceProvider {
     }
 
     if (!duplicates.isEmpty()) {
-      StringBuilder names = new StringBuilder();
-      boolean first = true;
-      for (String hName : duplicates) {
-        if (!first) {
-          names.append(",");
-        }
-        first = false;
-        names.append(hName);
-      }
-      throw new IllegalArgumentException("Invalid request contains"
-          + " duplicate hostnames"
-          + ", hostnames=" + names);
+      throw new IllegalArgumentException("Invalid request contains duplicate 
hostnames"
+              + ", hostnames=" + String.join(",", duplicates));
     }
 
     if (!unknowns.isEmpty()) {
-      StringBuilder names = new StringBuilder();
-      boolean first = true;
-      for (String hName : unknowns) {
-        if (!first) {
-          names.append(",");
-        }
-        first = false;
-        names.append(hName);
-      }
-
       throw new IllegalArgumentException("Attempted to add unknown hosts to a 
cluster.  " +
-          "These hosts have not been registered with the server: " + names);
+              "These hosts have not been registered with the server: " +
+              String.join(",", unknowns));
     }
 
     Map<String, Set<String>> hostClustersMap = new HashMap<>();

Reply via email to