ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jonathanhur...@apache.org
Subject [24/50] [abbrv] ambari git commit: AMBARI-14772. Added ability to set rack information in the add host template (Laszlo Puskas via rlevas)
Date Tue, 16 Feb 2016 18:30:29 GMT
AMBARI-14772. Added ability to set rack information in the add host template  (Laszlo Puskas
via rlevas)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/9d8675ad
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/9d8675ad
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/9d8675ad

Branch: refs/heads/branch-dev-patch-upgrade
Commit: 9d8675ade510fa9617a48fa761cd7a829c40ef0b
Parents: 0a9a3aa
Author: Laszlo Puskas <lpuskas@hortonworks.com>
Authored: Fri Feb 12 11:35:32 2016 -0500
Committer: Robert Levas <rlevas@hortonworks.com>
Committed: Fri Feb 12 11:35:44 2016 -0500

----------------------------------------------------------------------
 .../internal/HostResourceProvider.java          | 12 ++++-
 .../internal/ScaleClusterRequest.java           | 28 +++++++++--
 .../server/topology/ClusterTopologyImpl.java    | 51 +++++++++++++-------
 3 files changed, 67 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/9d8675ad/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostResourceProvider.java
----------------------------------------------------------------------
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 da73f15..6251f07 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
@@ -145,6 +145,11 @@ public class HostResourceProvider extends AbstractControllerResourceProvider
{
   public static final String HOST_PREDICATE_PROPERTY_ID =
       PropertyHelper.getPropertyId(null, "host_predicate");
 
+  //todo use the same json structure for cluster host addition (cluster template and upscale)
+  public static final String HOST_RACK_INFO_NO_CATEGORY_PROPERTY_ID =
+      PropertyHelper.getPropertyId(null, "rack_info");
+
+
   private static Set<String> pkPropertyIds =
       new HashSet<String>(Arrays.asList(new String[]{
           HOST_NAME_PROPERTY_ID}));
@@ -354,6 +359,7 @@ public class HostResourceProvider extends AbstractControllerResourceProvider
{
     //todo: constants
     baseUnsupported.remove(HOST_COUNT_PROPERTY_ID);
     baseUnsupported.remove(HOST_PREDICATE_PROPERTY_ID);
+    baseUnsupported.remove(HOST_RACK_INFO_NO_CATEGORY_PROPERTY_ID);
 
     return checkConfigPropertyIds(baseUnsupported, "Hosts");
   }
@@ -406,7 +412,11 @@ public class HostResourceProvider extends AbstractControllerResourceProvider
{
         (String) properties.get(HOST_CLUSTER_NAME_PROPERTY_ID),
         null);
     hostRequest.setPublicHostName((String) properties.get(HOST_PUBLIC_NAME_PROPERTY_ID));
-    hostRequest.setRackInfo((String) properties.get(HOST_RACK_INFO_PROPERTY_ID));
+
+    String rackInfo = (String) ((null != properties.get(HOST_RACK_INFO_PROPERTY_ID))? properties.get(HOST_RACK_INFO_PROPERTY_ID):
+            properties.get(HOST_RACK_INFO_NO_CATEGORY_PROPERTY_ID));
+
+    hostRequest.setRackInfo(rackInfo);
     hostRequest.setBlueprintName((String) properties.get(BLUEPRINT_PROPERTY_ID));
     hostRequest.setHostGroupName((String) properties.get(HOSTGROUP_PROPERTY_ID));
     

http://git-wip-us.apache.org/repos/asf/ambari/blob/9d8675ad/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ScaleClusterRequest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ScaleClusterRequest.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ScaleClusterRequest.java
index d784f1d..b5d2f9d 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ScaleClusterRequest.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ScaleClusterRequest.java
@@ -19,6 +19,11 @@
 
 package org.apache.ambari.server.controller.internal;
 
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
 import org.apache.ambari.server.api.predicate.InvalidQueryException;
 import org.apache.ambari.server.stack.NoSuchStackException;
 import org.apache.ambari.server.topology.Blueprint;
@@ -26,17 +31,16 @@ import org.apache.ambari.server.topology.Configuration;
 import org.apache.ambari.server.topology.HostGroupInfo;
 import org.apache.ambari.server.topology.InvalidTopologyTemplateException;
 import org.apache.ambari.server.topology.TopologyValidator;
-
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * A request for a scaling an existing cluster.
  */
 public class ScaleClusterRequest extends BaseClusterRequest {
 
+  private static final Logger LOGGER = LoggerFactory.getLogger(ScaleClusterRequest.class);
+
   /**
    * cluster name
    */
@@ -175,9 +179,23 @@ public class ScaleClusterRequest extends BaseClusterRequest {
         throw new InvalidTopologyTemplateException("Invalid host group specified in request:
" + hgName);
       }
       hostGroupInfo.addHost(hostName);
+      hostGroupInfo.addHostRackInfo(hostName, processRackInfo(properties));
+    }
+  }
+
+  private String processRackInfo(Map<String, Object> properties) {
+    String rackInfo = null;
+    if (properties.containsKey(HostResourceProvider.HOST_RACK_INFO_PROPERTY_ID)) {
+      rackInfo = (String) properties.get(HostResourceProvider.HOST_RACK_INFO_PROPERTY_ID);
+    } else if (properties.containsKey(HostResourceProvider.HOST_RACK_INFO_NO_CATEGORY_PROPERTY_ID))
{
+      rackInfo = (String) properties.get(HostResourceProvider.HOST_RACK_INFO_NO_CATEGORY_PROPERTY_ID);
+    } else {
+      LOGGER.debug("No rack info provided");
     }
+    return rackInfo;
   }
 
+
   /**
    * Parse blueprint.
    *

http://git-wip-us.apache.org/repos/asf/ambari/blob/9d8675ad/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterTopologyImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterTopologyImpl.java
b/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterTopologyImpl.java
index 05dc504..af716a0 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterTopologyImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterTopologyImpl.java
@@ -19,12 +19,6 @@
 
 package org.apache.ambari.server.topology;
 
-import org.apache.ambari.server.AmbariException;
-import org.apache.ambari.server.controller.RequestStatusResponse;
-import org.apache.ambari.server.controller.internal.ProvisionAction;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
@@ -33,6 +27,12 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.controller.RequestStatusResponse;
+import org.apache.ambari.server.controller.internal.ProvisionAction;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 /**
  * Represents a cluster topology.
  * Topology includes the the associated blueprint, cluster configuration and hostgroup ->
host mapping.
@@ -280,40 +280,44 @@ public class ClusterTopologyImpl implements ClusterTopology {
     return ambariContext;
   }
 
-  private void registerHostGroupInfo(Map<String, HostGroupInfo> groupInfoMap) throws
InvalidTopologyException {
-    checkForDuplicateHosts(groupInfoMap);
-    for (HostGroupInfo hostGroupInfo : groupInfoMap.values() ) {
-      String hostGroupName = hostGroupInfo.getHostGroupName();
+  private void registerHostGroupInfo(Map<String, HostGroupInfo> requestedHostGroupInfoMap)
throws InvalidTopologyException {
+    LOG.debug("Registering requested host group information for {} hostgroups", requestedHostGroupInfoMap.size());
+    checkForDuplicateHosts(requestedHostGroupInfoMap);
+
+    for (HostGroupInfo requestedHostGroupInfo : requestedHostGroupInfoMap.values()) {
+      String hostGroupName = requestedHostGroupInfo.getHostGroupName();
+
       //todo: doesn't support using a different blueprint for update (scaling)
       HostGroup baseHostGroup = getBlueprint().getHostGroup(hostGroupName);
+
       if (baseHostGroup == null) {
         throw new IllegalArgumentException("Invalid host_group specified: " + hostGroupName
+
             ".  All request host groups must have a corresponding host group in the specified
blueprint");
       }
       //todo: split into two methods
-      HostGroupInfo existingHostGroupInfo = hostGroupInfoMap.get(hostGroupName);
-      if (existingHostGroupInfo == null) {
+      HostGroupInfo currentHostGroupInfo = hostGroupInfoMap.get(hostGroupName);
+      if (currentHostGroupInfo == null) {
         // blueprint host group config
         Configuration bpHostGroupConfig = baseHostGroup.getConfiguration();
         // parent config is BP host group config but with parent set to topology cluster
scoped config
         Configuration parentConfiguration = new Configuration(bpHostGroupConfig.getProperties(),
             bpHostGroupConfig.getAttributes(), getConfiguration());
 
-        hostGroupInfo.getConfiguration().setParentConfiguration(parentConfiguration);
-        hostGroupInfoMap.put(hostGroupName, hostGroupInfo);
+        requestedHostGroupInfo.getConfiguration().setParentConfiguration(parentConfiguration);
+        hostGroupInfoMap.put(hostGroupName, requestedHostGroupInfo);
       } else {
         // Update.  Either add hosts or increment request count
-        if (! hostGroupInfo.getHostNames().isEmpty()) {
+        if (!requestedHostGroupInfo.getHostNames().isEmpty()) {
           try {
             // this validates that hosts aren't already registered with groups
-            addHostsToTopology(hostGroupInfo);
+            addHostsToTopology(requestedHostGroupInfo);
           } catch (NoSuchHostGroupException e) {
             //todo
             throw new InvalidTopologyException("Attempted to add hosts to unknown host group:
" + hostGroupName);
           }
         } else {
-          existingHostGroupInfo.setRequestedCount(
-              existingHostGroupInfo.getRequestedHostCount() + hostGroupInfo.getRequestedHostCount());
+          currentHostGroupInfo.setRequestedCount(
+              currentHostGroupInfo.getRequestedHostCount() + requestedHostGroupInfo.getRequestedHostCount());
         }
         //todo: throw exception in case where request attempts to modify HG configuration
in scaling operation
       }
@@ -322,10 +326,21 @@ public class ClusterTopologyImpl implements ClusterTopology {
 
   private void addHostsToTopology(HostGroupInfo hostGroupInfo) throws InvalidTopologyException,
NoSuchHostGroupException {
     for (String host: hostGroupInfo.getHostNames()) {
+      registerRackInfo(hostGroupInfo, host);
       addHostToTopology(hostGroupInfo.getHostGroupName(), host);
     }
   }
 
+  private void registerRackInfo(HostGroupInfo hostGroupInfo, String host) {
+    synchronized (hostGroupInfoMap) {
+      HostGroupInfo cachedHGI = hostGroupInfoMap.get(hostGroupInfo.getHostGroupName());
+      if (null != cachedHGI) {
+        cachedHGI.addHostRackInfo(host, hostGroupInfo.getHostRackInfo().get(host));
+      }
+    }
+  }
+
+
   private void checkForDuplicateHosts(Map<String, HostGroupInfo> groupInfoMap) throws
InvalidTopologyException {
     Set<String> hosts = new HashSet<String>();
     Set<String> duplicates = new HashSet<String>();


Mime
View raw message