ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jonathanhur...@apache.org
Subject ambari git commit: AMBARI-20991 - Cluster Repository State Is Not Calculated Correctly For Service/Patch Repos (jonathanhurley)
Date Thu, 11 May 2017 15:35:18 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-feature-AMBARI-12556 8938ea219 -> b8cb5d486


AMBARI-20991 - Cluster Repository State Is Not Calculated Correctly For Service/Patch Repos
(jonathanhurley)


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

Branch: refs/heads/branch-feature-AMBARI-12556
Commit: b8cb5d4863c73a1cd76a4b47fe792e650c2f67a2
Parents: 8938ea2
Author: Jonathan Hurley <jhurley@hortonworks.com>
Authored: Thu May 11 11:30:31 2017 -0400
Committer: Jonathan Hurley <jhurley@hortonworks.com>
Committed: Thu May 11 11:32:39 2017 -0400

----------------------------------------------------------------------
 .../ClusterStackVersionResourceProvider.java    | 38 +++++---------------
 1 file changed, 9 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/b8cb5d48/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterStackVersionResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterStackVersionResourceProvider.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterStackVersionResourceProvider.java
index 1e49eb2..9ca8ddc 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterStackVersionResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterStackVersionResourceProvider.java
@@ -77,7 +77,6 @@ import org.apache.ambari.server.state.repository.VersionDefinitionXml;
 import org.apache.ambari.server.state.stack.upgrade.RepositoryVersionHelper;
 import org.apache.ambari.server.utils.StageUtils;
 import org.apache.ambari.server.utils.VersionUtils;
-import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.lang.math.NumberUtils;
 
@@ -240,6 +239,7 @@ public class ClusterStackVersionResourceProvider extends AbstractControllerResou
 
       RepositoryVersionEntity repositoryVersion = repositoryVersionDAO.findByPK(repositoryVersionId);
 
+      final List<RepositoryVersionState> allStates = new ArrayList<>();
       final Map<RepositoryVersionState, List<String>> hostStates = new HashMap<>();
       for (RepositoryVersionState state: RepositoryVersionState.values()) {
         hostStates.put(state, new ArrayList<String>());
@@ -248,10 +248,13 @@ public class ClusterStackVersionResourceProvider extends AbstractControllerResou
       StackEntity repoVersionStackEntity = repositoryVersion.getStack();
       StackId repoVersionStackId = new StackId(repoVersionStackEntity);
 
-      for (HostVersionEntity hostVersionEntity : hostVersionDAO.findByClusterStackAndVersion(
-          clusterName, repoVersionStackId, repositoryVersion.getVersion())) {
+      List<HostVersionEntity> hostVersionsForRepository = hostVersionDAO.findHostVersionByClusterAndRepository(
+          cluster.getClusterId(), repositoryVersion);
 
+      // create the in-memory structures
+      for (HostVersionEntity hostVersionEntity : hostVersionsForRepository) {
         hostStates.get(hostVersionEntity.getState()).add(hostVersionEntity.getHostName());
+        allStates.add(hostVersionEntity.getState());
       }
 
       setResourceProperty(resource, CLUSTER_STACK_VERSION_CLUSTER_NAME_PROPERTY_ID, clusterName,
requestedIds);
@@ -259,35 +262,12 @@ public class ClusterStackVersionResourceProvider extends AbstractControllerResou
       setResourceProperty(resource, CLUSTER_STACK_VERSION_ID_PROPERTY_ID, repositoryVersion.getId(),
requestedIds);
       setResourceProperty(resource, CLUSTER_STACK_VERSION_STACK_PROPERTY_ID, repoVersionStackId.getStackName(),
requestedIds);
       setResourceProperty(resource, CLUSTER_STACK_VERSION_VERSION_PROPERTY_ID, repoVersionStackId.getStackVersion(),
requestedIds);
-
+      setResourceProperty(resource, CLUSTER_STACK_VERSION_REPOSITORY_VERSION_PROPERTY_ID,
repositoryVersion.getId(), requestedIds);
 
       @Experimental(feature = ExperimentalFeature.PATCH_UPGRADES,
           comment = "this is a fake status until the UI can handle services that are on their
own")
-      RepositoryVersionState finalState = null;
-
-      for (RepositoryVersionState state : EnumSet.of(RepositoryVersionState.INSTALLING,
-          RepositoryVersionState.INSTALL_FAILED, RepositoryVersionState.OUT_OF_SYNC)) {
-
-        if (CollectionUtils.isNotEmpty(hostStates.get(state))) {
-          finalState = state;
-          break;
-        }
-      }
-
-      if (null == finalState) {
-        int count = cluster.getClusterSize();
-
-        for (RepositoryVersionState state : EnumSet.of(RepositoryVersionState.INSTALLED,
RepositoryVersionState.CURRENT)) {
-          if (count == CollectionUtils.size(hostStates.get(state))) {
-            finalState = state;
-            break;
-          }
-        }
-      }
-      // !!! end ExperimentalFeature
-
-      setResourceProperty(resource, CLUSTER_STACK_VERSION_STATE_PROPERTY_ID, finalState,
requestedIds);
-      setResourceProperty(resource, CLUSTER_STACK_VERSION_REPOSITORY_VERSION_PROPERTY_ID,
repositoryVersion.getId(), requestedIds);
+      RepositoryVersionState aggregateState = RepositoryVersionState.getAggregateState(allStates);
+      setResourceProperty(resource, CLUSTER_STACK_VERSION_STATE_PROPERTY_ID, aggregateState,
requestedIds);
 
       if (predicate == null || predicate.evaluate(resource)) {
         resources.add(resource);


Mime
View raw message