ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dmitriu...@apache.org
Subject [2/2] ambari git commit: AMBARI-12222. Added Hive Service after Installing Bits and Cluster Version did not transition to OUT_OF_SYNC (dlysnichenko)
Date Tue, 30 Jun 2015 18:00:25 GMT
AMBARI-12222. Added Hive Service after Installing Bits and Cluster Version did not transition
to OUT_OF_SYNC (dlysnichenko)


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

Branch: refs/heads/branch-2.1
Commit: 58fdd3715bf5bdaa2b4c9ce658a53c9bf6280bed
Parents: e01774a
Author: Lisnichenko Dmitro <dlysnichenko@hortonworks.com>
Authored: Tue Jun 30 20:41:58 2015 +0300
Committer: Lisnichenko Dmitro <dlysnichenko@hortonworks.com>
Committed: Tue Jun 30 20:59:59 2015 +0300

----------------------------------------------------------------------
 .../upgrade/HostVersionOutOfSyncListener.java   | 41 +++++++--------
 .../HostVersionOutOfSyncListenerTest.java       | 53 ++++++++++++++++----
 2 files changed, 59 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/58fdd371/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/upgrade/HostVersionOutOfSyncListener.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/upgrade/HostVersionOutOfSyncListener.java
b/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/upgrade/HostVersionOutOfSyncListener.java
index b850774..9a72012 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/upgrade/HostVersionOutOfSyncListener.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/upgrade/HostVersionOutOfSyncListener.java
@@ -37,6 +37,7 @@ import org.apache.ambari.server.orm.dao.HostVersionDAO;
 import org.apache.ambari.server.orm.entities.ClusterVersionEntity;
 import org.apache.ambari.server.orm.entities.HostEntity;
 import org.apache.ambari.server.orm.entities.HostVersionEntity;
+import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
 import org.apache.ambari.server.orm.entities.StackEntity;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
@@ -98,8 +99,6 @@ public class HostVersionOutOfSyncListener {
       List<HostVersionEntity> hostVersionEntities =
           hostVersionDAO.get().findByClusterAndHost(cluster.getClusterName(), event.getHostName());
 
-      StackId currentStackId = cluster.getCurrentStackVersion();
-
       for (HostVersionEntity hostVersionEntity : hostVersionEntities) {
         StackEntity hostStackEntity = hostVersionEntity.getRepositoryVersion().getStack();
         StackId hostStackId = new StackId(hostStackEntity.getStackName(), hostStackEntity.getStackVersion());
@@ -115,11 +114,10 @@ public class HostVersionOutOfSyncListener {
           continue;
         }
 
-        if (currentStackId.equals(hostStackId)
-            && hostVersionEntity.getState().equals(RepositoryVersionState.INSTALLED))
{
+        if (hostVersionEntity.getState().equals(RepositoryVersionState.INSTALLED)) {
           hostVersionEntity.setState(RepositoryVersionState.OUT_OF_SYNC);
           hostVersionDAO.get().merge(hostVersionEntity);
-          cluster.recalculateClusterVersionState(currentStackId,
+          cluster.recalculateClusterVersionState(hostStackId,
               hostVersionEntity.getRepositoryVersion().getVersion());
         }
       }
@@ -137,8 +135,7 @@ public class HostVersionOutOfSyncListener {
 
     try {
       Cluster cluster = clusters.get().getClusterById(event.getClusterId());
-      Set<String> changedRepositoryVersions = new HashSet<String>();
-      StackId currentStackId = cluster.getCurrentStackVersion();
+      Set<RepositoryVersionEntity> changedRepositoryVersions = new HashSet<RepositoryVersionEntity>();
       Map<String, ServiceComponent> serviceComponents = cluster.getService(event.getServiceName()).getServiceComponents();
       // Determine hosts that become OUT_OF_SYNC when adding components for new service
       Map<String, List<ServiceComponent>> affectedHosts =
@@ -155,9 +152,7 @@ public class HostVersionOutOfSyncListener {
         List<HostVersionEntity> hostVersionEntities =
             hostVersionDAO.get().findByClusterAndHost(cluster.getClusterName(), hostName);
         for (HostVersionEntity hostVersionEntity : hostVersionEntities) {
-          StackEntity hostStackEntity = hostVersionEntity.getRepositoryVersion().getStack();
-          StackId hostStackId = new StackId(hostStackEntity.getStackName(), hostStackEntity.getStackVersion());
-
+          RepositoryVersionEntity repositoryVersion = hostVersionEntity.getRepositoryVersion();
           // If added components do not advertise version, it makes no sense to mark version
OUT_OF_SYNC
           // We perform check per-stack version, because component may be not versionAdvertised
in current
           // stack, but become versionAdvertised in some future (installed, but not yet upgraded
to) stack
@@ -165,8 +160,8 @@ public class HostVersionOutOfSyncListener {
           String serviceName = event.getServiceName();
           for (ServiceComponent comp : affectedHosts.get(hostName)) {
             String componentName = comp.getName();
-            ComponentInfo component = ami.get().getComponent(hostStackId.getStackName(),
-                    hostStackId.getStackVersion(), serviceName, componentName);
+            ComponentInfo component = ami.get().getComponent(repositoryVersion.getStackName(),
+                    repositoryVersion.getStackVersion(), serviceName, componentName);
             if (component.isVersionAdvertised()) {
               hasChangedComponentsWithVersions = true;
             }
@@ -175,16 +170,16 @@ public class HostVersionOutOfSyncListener {
             continue;
           }
 
-          if (currentStackId.equals(hostStackId)
-              && hostVersionEntity.getState().equals(RepositoryVersionState.INSTALLED))
{
+          if (hostVersionEntity.getState().equals(RepositoryVersionState.INSTALLED)) {
             hostVersionEntity.setState(RepositoryVersionState.OUT_OF_SYNC);
             hostVersionDAO.get().merge(hostVersionEntity);
-            changedRepositoryVersions.add(hostVersionEntity.getRepositoryVersion().getVersion());
+            changedRepositoryVersions.add(repositoryVersion);
           }
         }
       }
-      for (String version : changedRepositoryVersions) {
-        cluster.recalculateClusterVersionState(currentStackId, version);
+      for (RepositoryVersionEntity repositoryVersion : changedRepositoryVersions) {
+        StackId stackId = new StackId(repositoryVersion.getStackName(), repositoryVersion.getStackVersion());
+        cluster.recalculateClusterVersionState(stackId, repositoryVersion.getVersion());
       }
     } catch (AmbariException e) {
       LOG.error("Can not update hosts about out of sync", e);
@@ -200,25 +195,23 @@ public class HostVersionOutOfSyncListener {
 
     try {
       Cluster cluster = clusters.get().getClusterById(event.getClusterId());
-      StackId currentStackId = cluster.getCurrentStackVersion();
 
-      Set<String> changedRepositoryVersions = new HashSet<String>();
       Collection<ClusterVersionEntity> allClusterVersions = cluster.getAllClusterVersions();
       for (ClusterVersionEntity clusterVersion : allClusterVersions) {
         if (clusterVersion.getState() != RepositoryVersionState.CURRENT) { // Current version
is taken care of automatically
           String hostName = event.getHostName();
           HostEntity hostEntity = hostDAO.get().findByName(hostName);
+          RepositoryVersionEntity repositoryVersion = clusterVersion.getRepositoryVersion();
           HostVersionEntity missingHostVersion = new HostVersionEntity(hostEntity,
-                  clusterVersion.getRepositoryVersion(), RepositoryVersionState.OUT_OF_SYNC);
+                  repositoryVersion, RepositoryVersionState.OUT_OF_SYNC);
           hostVersionDAO.get().create(missingHostVersion);
-          changedRepositoryVersions.add(clusterVersion.getRepositoryVersion().getVersion());
+          StackId stackId = new StackId(repositoryVersion.getStackName(), repositoryVersion.getStackVersion());
+          cluster.recalculateClusterVersionState(stackId, repositoryVersion.getVersion());
         }
       }
-      for (String version : changedRepositoryVersions) {
-        cluster.recalculateClusterVersionState(currentStackId, version);
-      }
     } catch (AmbariException e) {
       LOG.error("Can not update hosts about out of sync", e);
     }
   }
+
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/58fdd371/ambari-server/src/test/java/org/apache/ambari/server/events/listeners/upgrade/HostVersionOutOfSyncListenerTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/events/listeners/upgrade/HostVersionOutOfSyncListenerTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/events/listeners/upgrade/HostVersionOutOfSyncListenerTest.java
index 90e0b53..8cda98e 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/events/listeners/upgrade/HostVersionOutOfSyncListenerTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/events/listeners/upgrade/HostVersionOutOfSyncListenerTest.java
@@ -70,6 +70,7 @@ import com.google.inject.persist.PersistService;
 public class HostVersionOutOfSyncListenerTest {
   private static final Logger LOG = LoggerFactory.getLogger(HostVersionOutOfSyncListenerTest.class);
   private final String stackId = "HDP-2.2.0";
+  private final String yetAnotherStackId = "HDP-2.1.1";
 
   private Injector injector;
 
@@ -177,6 +178,32 @@ public class HostVersionOutOfSyncListenerTest {
     }
   }
 
+  /***
+   * Adds yet another repo version to existing cluster
+   * Shared between several test cases.
+   * @param INSTALLED_VERSION Version to add as INSTALLED
+   * @param stackId Stack Id to use
+   * @throws AmbariException
+   */
+  private void addRepoVersion(String INSTALLED_VERSION, StackId stackId) throws AmbariException
{
+    // Register and install new version
+    RepositoryVersionEntity repositoryVersionEntity = helper.getOrCreateRepositoryVersion(stackId,
+            INSTALLED_VERSION);
+    HostVersionEntity hv2 = helper.createHostVersion("h1", repositoryVersionEntity, RepositoryVersionState.INSTALLED);
+    c1.recalculateAllClusterVersionStates();
+    checkStackVersionState(stackId.getStackId(), INSTALLED_VERSION, RepositoryVersionState.INSTALLED);
+
+    // Add new host and verify that it has all host versions present
+    List<HostVersionEntity> h2Versions = hostVersionDAO.findAll();
+
+    // Check before adding service
+    for (HostVersionEntity hostVersionEntity : h2Versions) {
+      if (hostVersionEntity.getRepositoryVersion().getVersion().equals(INSTALLED_VERSION))
{
+        assertEquals(hostVersionEntity.getState(), RepositoryVersionState.INSTALLED);
+      }
+    }
+  }
+
   /**
    * When a service is added to a cluster, all non-CURRENT host versions on
    * all affected hosts (where host new components are installed)
@@ -185,9 +212,12 @@ public class HostVersionOutOfSyncListenerTest {
   @Test
   public void testOnServiceEvent() throws AmbariException {
     String INSTALLED_VERSION = "1.0-1000";
+    String INSTALLED_VERSION_2 = "2.0-2000";
     StackId stackId = new StackId(this.stackId);
+    StackId yaStackId = new StackId(this.yetAnotherStackId);
 
     createClusterAndHosts(INSTALLED_VERSION, stackId);
+    addRepoVersion(INSTALLED_VERSION_2, yaStackId);
 
 
     //Add HDFS service
@@ -209,20 +239,18 @@ public class HostVersionOutOfSyncListenerTest {
 
     List<HostVersionEntity> hostVersions = hostVersionDAO.findAll();
 
-    boolean atLeastOneOutOfSync = false;
     checkStackVersionState(stackId.getStackId(), INSTALLED_VERSION, RepositoryVersionState.INSTALLED);
+    checkStackVersionState(yaStackId.getStackId(), INSTALLED_VERSION_2, RepositoryVersionState.INSTALLED);
     for (HostVersionEntity hostVersionEntity : hostVersions) {
-      if (hostVersionEntity.getRepositoryVersion().getVersion().equals(INSTALLED_VERSION))
{
+      if (hostVersionEntity.getRepositoryVersion().getVersion().equals(INSTALLED_VERSION)
||
+              hostVersionEntity.getRepositoryVersion().getVersion().equals(INSTALLED_VERSION_2))
{
         if (changedHosts.contains(hostVersionEntity.getHostName())) {
           assertEquals(hostVersionEntity.getState(), RepositoryVersionState.OUT_OF_SYNC);
-          atLeastOneOutOfSync = true;
         } else {
           assertEquals(hostVersionEntity.getState(), RepositoryVersionState.INSTALLED);
         }
       }
     }
-
-    assertTrue(atLeastOneOutOfSync);
   }
 
 
@@ -269,14 +297,17 @@ public class HostVersionOutOfSyncListenerTest {
   /**
    * When a new service is added to a cluster with components, all INSTALLED host versions
on
    * all affected hosts (where host new components are installed)
-   * should transition to OUT_OF_SYNC state
+   * should transition to OUT_OF_SYNC state.
    */
   @Test
   public void testOnServiceComponentEvent() throws AmbariException {
     String INSTALLED_VERSION = "1.0-1000";
+    String INSTALLED_VERSION_2 = "2.0-2000";
     StackId stackId = new StackId(this.stackId);
+    StackId yaStackId = new StackId(this.yetAnotherStackId);
 
     createClusterAndHosts(INSTALLED_VERSION, stackId);
+    addRepoVersion(INSTALLED_VERSION_2, yaStackId);
 
     //Add ZOOKEEPER_CLIENT component
     List<String> hostList = new ArrayList<String>();
@@ -294,20 +325,16 @@ public class HostVersionOutOfSyncListenerTest {
     checkStackVersionState(stackId.getStackId(), INSTALLED_VERSION, RepositoryVersionState.INSTALLED);
     List<HostVersionEntity> hostVersions = hostVersionDAO.findAll();
 
-    boolean atLeastOneOutOfSync = false;
     for (HostVersionEntity hostVersionEntity : hostVersions) {
       RepositoryVersionEntity repoVersion = hostVersionEntity.getRepositoryVersion();
-      if (repoVersion.getVersion().equals(INSTALLED_VERSION)) {
+      if (repoVersion.getVersion().equals(INSTALLED_VERSION) || repoVersion.getVersion().equals(INSTALLED_VERSION_2))
{
         if (changedHosts.contains(hostVersionEntity.getHostName())) {
           assertEquals(hostVersionEntity.getState(), RepositoryVersionState.OUT_OF_SYNC);
-          atLeastOneOutOfSync = true;
         } else {
           assertEquals(hostVersionEntity.getState(), RepositoryVersionState.INSTALLED);
         }
       }
     }
-
-    assertTrue(atLeastOneOutOfSync);
   }
 
 
@@ -323,7 +350,9 @@ public class HostVersionOutOfSyncListenerTest {
     h1.setState(HostState.HEALTHY);
 
     StackId stackId = new StackId(this.stackId);
+    StackId yaStackId = new StackId(this.yetAnotherStackId);
     RepositoryVersionEntity repositoryVersionEntity = helper.getOrCreateRepositoryVersion(stackId,"1.0-1000");
+    RepositoryVersionEntity repositoryVersionEntity2 = helper.getOrCreateRepositoryVersion(stackId,"2.0-2000");
     c1.createClusterVersion(stackId, "1.0-1000", "admin", RepositoryVersionState.INSTALLING);
     c1.setCurrentStackVersion(stackId);
     c1.recalculateAllClusterVersionStates();
@@ -331,8 +360,10 @@ public class HostVersionOutOfSyncListenerTest {
     checkStackVersionState(stackId.getStackId(), "1.0-2086", RepositoryVersionState.CURRENT);
 
     HostVersionEntity hv1 = helper.createHostVersion("h1", repositoryVersionEntity, RepositoryVersionState.INSTALLED);
+    HostVersionEntity hv2 = helper.createHostVersion("h1", repositoryVersionEntity2, RepositoryVersionState.INSTALLED);
     c1.recalculateAllClusterVersionStates();
     checkStackVersionState(stackId.getStackId(), "1.0-1000", RepositoryVersionState.INSTALLED);
+    checkStackVersionState(stackId.getStackId(), "2.0-2000", RepositoryVersionState.INSTALLED);
     checkStackVersionState(stackId.getStackId(), "1.0-2086", RepositoryVersionState.CURRENT);
 
     // Add new host and verify that it has all host versions present


Mime
View raw message