浏览代码

Revert "AMBARI-14520. BE: Install packages call takes more than 3 minutes on 900 node cluster (dlysnichenko)"

This reverts commit 09b55dfe70776a6ae1dc8d79b31ec739ee5400c7 due to UT failures.
Yusaku Sako 9 年之前
父节点
当前提交
5d8a97cfb4

+ 3 - 0
ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariActionExecutionHelper.java

@@ -433,6 +433,9 @@ public class AmbariActionExecutionHelper {
       }
 
       if (null != cluster) {
+        // Generate cluster host info
+        execCmd.setClusterHostInfo(
+          StageUtils.getClusterHostInfo(cluster));
         // Generate localComponents
         for (ServiceComponentHost sch : cluster.getServiceComponentHosts(hostName)) {
           execCmd.getLocalComponents().add(sch.getServiceComponentName());

+ 4 - 14
ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterStackVersionResourceProvider.java

@@ -367,15 +367,6 @@ public class ClusterStackVersionResourceProvider extends AbstractControllerResou
     hostLevelParams.put(JDK_LOCATION, getManagementController().getJdkResourceUrl());
     String hostParamsJson = StageUtils.getGson().toJson(hostLevelParams);
 
-    // Generate cluster host info
-    String clusterHostInfoJson;
-    try {
-      clusterHostInfoJson = StageUtils.getGson().toJson(
-        StageUtils.getClusterHostInfo(cluster));
-    } catch (AmbariException e) {
-      throw new SystemException("Could not build cluster topology", e);
-    }
-
     int maxTasks = configuration.getAgentPackageParallelCommandsLimit();
     int hostCount = hosts.size();
     int batchCount = (int) (Math.ceil((double)hostCount / maxTasks));
@@ -399,7 +390,7 @@ public class ClusterStackVersionResourceProvider extends AbstractControllerResou
       }
 
       Stage stage = stageFactory.createNew(req.getId(), "/tmp/ambari", cluster.getClusterName(),
-          cluster.getClusterId(), stageName, clusterHostInfoJson, "{}", hostParamsJson);
+          cluster.getClusterId(), stageName, "{}", "{}", hostParamsJson);
 
       // if you have 1000 hosts (10 stages with 100 installs), we want to ensure
       // that a single failure doesn't cause all other stages to abort; set the
@@ -476,12 +467,11 @@ public class ClusterStackVersionResourceProvider extends AbstractControllerResou
       final StackId stackId, Map<String, List<RepositoryEntity>> perOsRepos, Stage stage, Host host)
           throws SystemException {
     // Determine repositories for host
-    String osFamily = host.getOsFamily();
-    final List<RepositoryEntity> repoInfo = perOsRepos.get(osFamily);
+    final List<RepositoryEntity> repoInfo = perOsRepos.get(host.getOsFamily());
     if (repoInfo == null) {
       throw new SystemException(String.format("Repositories for os type %s are " +
                       "not defined. Repo version=%s, stackId=%s",
-        osFamily, desiredRepoVersion, stackId));
+              host.getOsFamily(), desiredRepoVersion, stackId));
     }
 
     // determine packages for all services that are installed on host
@@ -502,7 +492,7 @@ public class ClusterStackVersionResourceProvider extends AbstractControllerResou
 
       List<ServiceOsSpecific.Package> packagesForService = managementController.getPackagesForServiceHost(info,
               new HashMap<String, String>(), // Contents are ignored
-        osFamily);
+              host.getOsFamily());
       for (ServiceOsSpecific.Package aPackage : packagesForService) {
         if (! aPackage.getSkipUpgrade()) {
           boolean blacklisted = false;

+ 4 - 14
ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostStackVersionResourceProvider.java

@@ -354,12 +354,11 @@ public class HostStackVersionResourceProvider extends AbstractControllerResource
     }
 
     // Determine repositories for host
-    String osFamily = host.getOsFamily();
-    final List<RepositoryEntity> repoInfo = perOsRepos.get(osFamily);
+    final List<RepositoryEntity> repoInfo = perOsRepos.get(host.getOsFamily());
     if (repoInfo == null) {
       throw new SystemException(String.format("Repositories for os type %s are " +
                       "not defined. Repo version=%s, stackId=%s",
-        osFamily, desiredRepoVersion, stackId));
+              host.getOsFamily(), desiredRepoVersion, stackId));
     }
     // For every host at cluster, determine packages for all installed services
     List<ServiceOsSpecific.Package> packages = new ArrayList<ServiceOsSpecific.Package>();
@@ -378,7 +377,7 @@ public class HostStackVersionResourceProvider extends AbstractControllerResource
       }
       List<ServiceOsSpecific.Package> packagesForService = managementController.getPackagesForServiceHost(info,
               new HashMap<String, String>(), // Contents are ignored
-        osFamily);
+              host.getOsFamily());
       for (ServiceOsSpecific.Package aPackage : packagesForService) {
         if (! aPackage.getSkipUpgrade()) {
           boolean blacklisted = false;
@@ -420,21 +419,12 @@ public class HostStackVersionResourceProvider extends AbstractControllerResource
     Map<String, String> hostLevelParams = new HashMap<String, String>();
     hostLevelParams.put(JDK_LOCATION, getManagementController().getJdkResourceUrl());
 
-    // Generate cluster host info
-    String clusterHostInfoJson;
-    try {
-      clusterHostInfoJson = StageUtils.getGson().toJson(
-        StageUtils.getClusterHostInfo(cluster));
-    } catch (AmbariException e) {
-      throw new SystemException("Could not build cluster topology", e);
-    }
-
     Stage stage = stageFactory.createNew(req.getId(),
             "/tmp/ambari",
             cluster.getClusterName(),
             cluster.getClusterId(),
             caption,
-            clusterHostInfoJson,
+            "{}",
             "{}",
             StageUtils.getGson().toJson(hostLevelParams));
 

+ 23 - 48
ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java

@@ -1208,56 +1208,31 @@ public class ClusterImpl implements Cluster {
       Sets.SetView<String> hostsMissingRepoVersion = Sets.difference(
         hosts.keySet(), existingHostsWithClusterStackAndVersion);
 
-      createOrUpdateHostVersionToState(sourceClusterVersion, hosts,
-        existingHostStackVersions, hostsMissingRepoVersion,
-        RepositoryVersionState.INSTALLING);
-    } finally {
-      clusterGlobalLock.writeLock().unlock();
-    }
-  }
-
-  /**
-   * Moved out to a separate method due to performance reasons
-   * Iterates over all hosts and creates or transitions existing host versions
-   * to a given state. If host version for desired stack/version does not exist,
-   * host version is created and initialized to a given state. Otherwise, existing
-   * host version state is updated
-   * Hosts in maintenance mode are auto skipped.
-   *
-   * @param sourceClusterVersion cluster version to be queried for a stack
-   *                             name/version info when creating a new host version
-   * @param hosts list of all hosts
-   * @param existingHostStackVersions map of existing host versions to be updated
-   * @param hostsMissingRepoVersion set of hostnames of hosts that have no desired host version
-   * @param newState target host version state for transition
-   */
-  @Transactional
-  void createOrUpdateHostVersionToState(ClusterVersionEntity sourceClusterVersion, Map<String, Host> hosts,
-                                        HashMap<String, HostVersionEntity> existingHostStackVersions,
-                                        Sets.SetView<String> hostsMissingRepoVersion,
-                                                RepositoryVersionState newState) {
-    for (String hostname : hosts.keySet()) {
-      // if the host is in maintenance mode, that's an explicit marker which
-      // indicates that it should not be transitioned to newState; these
-      // hosts are excluded from being transitioned into newState
-      Host host = hosts.get(hostname);
-      if (host.getMaintenanceState(getClusterId()) != MaintenanceState.OFF) {
-        continue;
-      }
+      for (String hostname : hosts.keySet()) {
+        // if the host is in maintenance mode, that's an explicit marker which
+        // indicates that it should not be transitioned to INSTALLING; these
+        // hosts are excluded from being transitioned into INSTALLING
+        Host host = hosts.get(hostname);
+        if (host.getMaintenanceState(getClusterId()) != MaintenanceState.OFF) {
+          continue;
+        }
 
-      if (hostsMissingRepoVersion.contains(hostname)) {
-        // Create new host stack version
-        HostEntity hostEntity = hostDAO.findByName(hostname);
-        HostVersionEntity hostVersionEntity = new HostVersionEntity(hostEntity,
-            sourceClusterVersion.getRepositoryVersion(),
-          newState);
-        hostVersionDAO.create(hostVersionEntity);
-      } else {
-        // Update existing host stack version
-        HostVersionEntity hostVersionEntity = existingHostStackVersions.get(hostname);
-        hostVersionEntity.setState(newState);
-        hostVersionDAO.merge(hostVersionEntity);
+        if (hostsMissingRepoVersion.contains(hostname)) {
+          // Create new host stack version
+          HostEntity hostEntity = hostDAO.findByName(hostname);
+          HostVersionEntity hostVersionEntity = new HostVersionEntity(hostEntity,
+              sourceClusterVersion.getRepositoryVersion(),
+              RepositoryVersionState.INSTALLING);
+          hostVersionDAO.create(hostVersionEntity);
+        } else {
+          // Update existing host stack version
+          HostVersionEntity hostVersionEntity = existingHostStackVersions.get(hostname);
+          hostVersionEntity.setState(RepositoryVersionState.INSTALLING);
+          hostVersionDAO.merge(hostVersionEntity);
+        }
       }
+    } finally {
+      clusterGlobalLock.writeLock().unlock();
     }
   }
 

+ 2 - 3
ambari-server/src/main/java/org/apache/ambari/server/state/host/HostImpl.java

@@ -869,9 +869,8 @@ public class HostImpl implements Host {
 
   @Override
   public String getOsFamily() {
-    Map<String, String> hostAttributes = getHostAttributes();
-    String majorVersion = hostAttributes.get(OS_RELEASE_VERSION).split("\\.")[0];
-	  return hostAttributes.get(OSFAMILY) + majorVersion;
+	  String majorVersion = getHostAttributes().get(OS_RELEASE_VERSION).split("\\.")[0];
+	  return getHostAttributes().get(OSFAMILY) + majorVersion;
   }
 
   @Override