ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nc...@apache.org
Subject ambari git commit: AMBARI-10005. RU: desired stack must be cascaded during upgrade (ncole)
Date Thu, 23 Apr 2015 20:46:24 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk d8bff0381 -> aa3bd6e2b


AMBARI-10005. RU: desired stack must be cascaded during upgrade (ncole)


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

Branch: refs/heads/trunk
Commit: aa3bd6e2b4e19182cc99d870c0f30648738e16b6
Parents: d8bff03
Author: Nate Cole <ncole@hortonworks.com>
Authored: Thu Apr 23 14:30:20 2015 -0400
Committer: Nate Cole <ncole@hortonworks.com>
Committed: Thu Apr 23 16:45:53 2015 -0400

----------------------------------------------------------------------
 .../ambari/server/agent/HeartBeatHandler.java   |  1 +
 .../internal/UpgradeResourceProvider.java       | 76 +++++++++++---------
 .../upgrades/FinalizeUpgradeAction.java         |  8 ++-
 .../org/apache/ambari/server/state/Cluster.java | 12 +++-
 .../server/state/cluster/ClusterImpl.java       | 21 ++++++
 .../internal/UpgradeResourceProviderTest.java   | 52 +++++++++++---
 6 files changed, 126 insertions(+), 44 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/aa3bd6e2/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java
b/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java
index 596525b..9bdc4b7 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java
@@ -772,6 +772,7 @@ public class HeartBeatHandler {
       final String previousVersion = scHost.getVersion();
       if (!StringUtils.equals(previousVersion, newVersion)) {
         scHost.setVersion(newVersion);
+        scHost.setStackVersion(cluster.getDesiredStackVersion());
         if (previousVersion != null && !previousVersion.equalsIgnoreCase(State.UNKNOWN.toString()))
{
           scHost.setUpgradeState(UpgradeState.COMPLETE);
         }

http://git-wip-us.apache.org/repos/asf/ambari/blob/aa3bd6e2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeResourceProvider.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeResourceProvider.java
index 82b7307..730fba5 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeResourceProvider.java
@@ -581,7 +581,7 @@ public class UpgradeResourceProvider extends AbstractControllerResourceProvider
     entity.setRequestId(req.getId());
 
     // !!! in case persist() starts creating tasks right away, square away the configs
-    createConfigs(cluster, version);
+    createConfigs(cluster, version, direction);
 
     req.persist();
 
@@ -597,7 +597,7 @@ public class UpgradeResourceProvider extends AbstractControllerResourceProvider
    * @param version the version
    * @throws AmbariException
    */
-  private void createConfigs(Cluster cluster, String version) throws AmbariException {
+  private void createConfigs(Cluster cluster, String version, Direction direction) throws
AmbariException {
     RepositoryVersionEntity targetRve = s_repoVersionDAO.findMaxByVersion(version);
     if (null == targetRve) {
       LOG.info("Could not find version entity for {}; not setting new configs",
@@ -614,29 +614,16 @@ public class UpgradeResourceProvider extends AbstractControllerResourceProvider
 
     ConfigHelper configHelper = getManagementController().getConfigHelper();
 
-    Map<String, Map<String, String>> clusterConfigs = new HashMap<String,
Map<String, String>>();
+    Map<String, Map<String, String>> clusterConfigs = null;
 
-    // !!! stack
-    Set<org.apache.ambari.server.state.PropertyInfo> pi = s_metaProvider.get().getStackProperties(newStack.getStackName(),
-        newStack.getStackVersion());
+    if (direction == Direction.UPGRADE) {
 
-    for (PropertyInfo stackProperty : pi) {
-      String type = ConfigHelper.fileNameToConfigType(stackProperty.getFilename());
+      clusterConfigs = new HashMap<String, Map<String, String>>();
 
-      if (!clusterConfigs.containsKey(type)) {
-        clusterConfigs.put(type, new HashMap<String, String>());
-      }
-
-      clusterConfigs.get(type).put(stackProperty.getName(),
-          stackProperty.getValue());
-    }
-
-    // !!! by service
-    for (String serviceName : cluster.getServices().keySet()) {
-      pi = s_metaProvider.get().getServiceProperties(newStack.getStackName(),
-          newStack.getStackVersion(), serviceName);
+      // !!! stack
+      Set<org.apache.ambari.server.state.PropertyInfo> pi = s_metaProvider.get().getStackProperties(newStack.getStackName(),
+          newStack.getStackVersion());
 
-      // !!! use new stack as the basis
       for (PropertyInfo stackProperty : pi) {
         String type = ConfigHelper.fileNameToConfigType(stackProperty.getFilename());
 
@@ -647,23 +634,46 @@ public class UpgradeResourceProvider extends AbstractControllerResourceProvider
         clusterConfigs.get(type).put(stackProperty.getName(),
             stackProperty.getValue());
       }
-    }
 
-    // !!! upgrading the stack
-    cluster.setDesiredStackVersion(
-        new StackId(newStack.getStackName(), newStack.getStackVersion()));
+      // !!! by service
+      for (String serviceName : cluster.getServices().keySet()) {
+        pi = s_metaProvider.get().getServiceProperties(newStack.getStackName(),
+            newStack.getStackVersion(), serviceName);
+
+        // !!! use new stack as the basis
+        for (PropertyInfo stackProperty : pi) {
+          String type = ConfigHelper.fileNameToConfigType(stackProperty.getFilename());
+
+          if (!clusterConfigs.containsKey(type)) {
+            clusterConfigs.put(type, new HashMap<String, String>());
+          }
+
+          clusterConfigs.get(type).put(stackProperty.getName(),
+              stackProperty.getValue());
+        }
+      }
 
-    // !!! overlay the currently defined values per type
-    for (Map.Entry<String, Map<String, String>> entry : clusterConfigs.entrySet())
{
-      Config config = cluster.getDesiredConfigByType(entry.getKey());
-      if (null != config) {
-        entry.getValue().putAll(config.getProperties());
+      // !!! overlay the currently defined values per type
+      for (Map.Entry<String, Map<String, String>> entry : clusterConfigs.entrySet())
{
+        Config config = cluster.getDesiredConfigByType(entry.getKey());
+        if (null != config) {
+          entry.getValue().putAll(config.getProperties());
+        }
       }
+    } else {
+      // !!! remove configs
     }
 
-    configHelper.createConfigTypes(cluster, getManagementController(),
-        clusterConfigs, getManagementController().getAuthName(),
-        "Configuration created for Upgrade");
+    // !!! update the stack
+    cluster.setDesiredStackVersion(
+        new StackId(newStack.getStackName(), newStack.getStackVersion()), true);
+
+    // !!! configs must be created after setting the stack version
+    if (null != clusterConfigs) {
+      configHelper.createConfigTypes(cluster, getManagementController(),
+          clusterConfigs, getManagementController().getAuthName(),
+          "Configuration created for Upgrade");
+    }
 
   }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/aa3bd6e2/ambari-server/src/main/java/org/apache/ambari/server/serveraction/upgrades/FinalizeUpgradeAction.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/upgrades/FinalizeUpgradeAction.java
b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/upgrades/FinalizeUpgradeAction.java
index d97ad61..49e241f 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/upgrades/FinalizeUpgradeAction.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/upgrades/FinalizeUpgradeAction.java
@@ -356,7 +356,13 @@ public class FinalizeUpgradeAction extends AbstractServerAction {
           ComponentInfo componentInfo = ambariMetaInfo.getComponent(targetStackId.getStackName(),
                   targetStackId.getStackVersion(), service.getName(), serviceComponent.getName());
 
-          if (componentInfo.isVersionAdvertised()
+          if (!componentInfo.isVersionAdvertised()) {
+            StackId desired = serviceComponentHost.getDesiredStackVersion();
+            StackId actual = serviceComponentHost.getStackVersion();
+            if (!desired.equals(actual)) {
+              serviceComponentHost.setStackVersion(desired);
+            }
+          } else if (componentInfo.isVersionAdvertised()
               && !serviceComponentHost.getVersion().equals(desiredVersion)) {
             errors.add(new InfoTuple(
                     service.getName(), serviceComponent.getName(), serviceComponentHost.getHostName()));

http://git-wip-us.apache.org/repos/asf/ambari/blob/aa3bd6e2/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java b/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java
index 64fe765..855bb3f 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java
@@ -122,6 +122,15 @@ public interface Cluster {
   public void setDesiredStackVersion(StackId stackVersion) throws AmbariException;
 
   /**
+   * Sets the desired stack version, optionally setting all owned services,
+   * components, and host components
+   * @param stackId the stack id
+   * @param cascade {@code true} to cascade the desired version
+   */
+  public void setDesiredStackVersion(StackId stackId, boolean cascade) throws AmbariException;
+
+
+  /**
    * Get current stack version
    * @return
    */
@@ -200,7 +209,7 @@ public interface Cluster {
 
   /**
    * Transition an existing cluster version from one state to another.
-   * 
+   *
    * @param stackId
    *          Stack ID
    * @param version
@@ -510,4 +519,5 @@ public interface Cluster {
    * @return the map of session attributes for this cluster; never null
    */
   public Map<String, Object> getSessionAttributes();
+
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/aa3bd6e2/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
b/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
index f62e3f3..2558de8 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
@@ -891,6 +891,11 @@ public class ClusterImpl implements Cluster {
 
   @Override
   public void setDesiredStackVersion(StackId stackId) throws AmbariException {
+    setDesiredStackVersion(stackId, false);
+  }
+
+  @Override
+  public void setDesiredStackVersion(StackId stackId, boolean cascade) throws AmbariException
{
     clusterGlobalLock.writeLock().lock();
     try {
       if (LOG.isDebugEnabled()) {
@@ -906,12 +911,28 @@ public class ClusterImpl implements Cluster {
 
       clusterEntity.setDesiredStack(stackEntity);
       clusterDAO.merge(clusterEntity);
+
+      if (cascade) {
+        for (Service service : getServices().values()) {
+          service.setDesiredStackVersion(stackId);
+
+          for (ServiceComponent sc : service.getServiceComponents().values()) {
+            sc.setDesiredStackVersion(stackId);
+
+            for (ServiceComponentHost sch : sc.getServiceComponentHosts().values()) {
+              sch.setDesiredStackVersion(stackId);
+            }
+          }
+        }
+      }
+
       loadServiceConfigTypes();
     } finally {
       clusterGlobalLock.writeLock().unlock();
     }
   }
 
+
   @Override
   public StackId getCurrentStackVersion() {
     clusterGlobalLock.readLock().lock();

http://git-wip-us.apache.org/repos/asf/ambari/blob/aa3bd6e2/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java
index 5de2eac..d79f809 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java
@@ -21,6 +21,7 @@ import static org.easymock.EasyMock.createNiceMock;
 import static org.easymock.EasyMock.expect;
 import static org.easymock.EasyMock.replay;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
@@ -145,7 +146,7 @@ public class UpgradeResourceProviderTest {
     repoVersionEntity.setOperatingSystems("");
     repoVersionEntity.setStack(stackEntity);
     repoVersionEntity.setUpgradePackage("upgrade_test");
-    repoVersionEntity.setVersion("2.2.2.1");
+    repoVersionEntity.setVersion("2.1.1.0");
     repoVersionDao.create(repoVersionEntity);
 
     repoVersionEntity = new RepositoryVersionEntity();
@@ -153,7 +154,7 @@ public class UpgradeResourceProviderTest {
     repoVersionEntity.setOperatingSystems("");
     repoVersionEntity.setStack(stackEntity);
     repoVersionEntity.setUpgradePackage("upgrade_test");
-    repoVersionEntity.setVersion("2.2.2.2");
+    repoVersionEntity.setVersion("2.1.1.1");
     repoVersionDao.create(repoVersionEntity);
 
     repoVersionEntity = new RepositoryVersionEntity();
@@ -192,11 +193,11 @@ public class UpgradeResourceProviderTest {
 
     ServiceComponent component = service.addServiceComponent("ZOOKEEPER_SERVER");
     ServiceComponentHost sch = component.addServiceComponentHost("h1");
-    sch.setVersion("2.2.2.1");
+    sch.setVersion("2.1.1.0");
 
     component = service.addServiceComponent("ZOOKEEPER_CLIENT");
     sch = component.addServiceComponentHost("h1");
-    sch.setVersion("2.2.2.1");
+    sch.setVersion("2.1.1.0");
   }
 
   @After
@@ -214,7 +215,7 @@ public class UpgradeResourceProviderTest {
 
     Map<String, Object> requestProps = new HashMap<String, Object>();
     requestProps.put(UpgradeResourceProvider.UPGRADE_CLUSTER_NAME, "c1");
-    requestProps.put(UpgradeResourceProvider.UPGRADE_VERSION, "2.2.2.1");
+    requestProps.put(UpgradeResourceProvider.UPGRADE_VERSION, "2.1.1.1");
 
     ResourceProvider upgradeResourceProvider = createProvider(amc);
 
@@ -402,7 +403,7 @@ public class UpgradeResourceProviderTest {
 
     Map<String, Object> requestProps = new HashMap<String, Object>();
     requestProps.put(UpgradeResourceProvider.UPGRADE_CLUSTER_NAME, "c1");
-    requestProps.put(UpgradeResourceProvider.UPGRADE_VERSION, "2.2.2.1");
+    requestProps.put(UpgradeResourceProvider.UPGRADE_VERSION, "2.1.1.1");
 
     Map<String, String> requestInfoProperties = new HashMap<String, String>();
     requestInfoProperties.put(UpgradeResourceDefinition.DOWNGRADE_DIRECTIVE, "true");
@@ -424,7 +425,7 @@ public class UpgradeResourceProviderTest {
 
     UpgradeGroupEntity group = upgradeGroups.get(1);
     assertEquals("ZOOKEEPER", group.getName());
-    assertEquals(3, group.getItems().size());
+    assertEquals(4, group.getItems().size());
 
   }
 
@@ -435,7 +436,7 @@ public class UpgradeResourceProviderTest {
 
     Map<String, Object> requestProps = new HashMap<String, Object>();
     requestProps.put(UpgradeResourceProvider.UPGRADE_CLUSTER_NAME, "c1");
-    requestProps.put(UpgradeResourceProvider.UPGRADE_VERSION, "2.2.2.1");
+    requestProps.put(UpgradeResourceProvider.UPGRADE_VERSION, "2.1.1.1");
 
     ResourceProvider upgradeResourceProvider = createProvider(amc);
 
@@ -458,7 +459,7 @@ public class UpgradeResourceProviderTest {
 
     requestProps.put(UpgradeResourceProvider.UPGRADE_CLUSTER_NAME, "c1");
     requestProps.put(UpgradeResourceProvider.UPGRADE_VERSION, "2.2");
-    requestProps.put(UpgradeResourceProvider.UPGRADE_FROM_VERSION, "2.2.2.1");
+    requestProps.put(UpgradeResourceProvider.UPGRADE_FROM_VERSION, "2.1.1.0");
 
     Map<String, String> requestInfoProperties = new HashMap<String, String>();
     requestInfoProperties.put(UpgradeResourceDefinition.DOWNGRADE_DIRECTIVE, "true");
@@ -619,6 +620,20 @@ public class UpgradeResourceProviderTest {
   @Test
   public void testCreateCrossStackUpgrade() throws Exception {
     Cluster cluster = clusters.getCluster("c1");
+    StackId oldStack = cluster.getDesiredStackVersion();
+
+    for (Service s : cluster.getServices().values()) {
+      assertEquals(oldStack, s.getDesiredStackVersion());
+
+      for (ServiceComponent sc : s.getServiceComponents().values()) {
+        assertEquals(oldStack, sc.getDesiredStackVersion());
+
+        for (ServiceComponentHost sch : sc.getServiceComponentHosts().values()) {
+          assertEquals(oldStack, sch.getDesiredStackVersion());
+        }
+      }
+    }
+
 
     Config config = new ConfigImpl("zoo.cfg");
     config.setProperties(new HashMap<String, String>() {{
@@ -655,6 +670,25 @@ public class UpgradeResourceProviderTest {
         "Foo", item.getText());
 
     assertTrue(cluster.getDesiredConfigs().containsKey("zoo.cfg"));
+
+    StackId newStack = cluster.getDesiredStackVersion();
+
+    assertFalse(oldStack.equals(newStack));
+
+    for (Service s : cluster.getServices().values()) {
+      assertEquals(newStack, s.getDesiredStackVersion());
+
+      for (ServiceComponent sc : s.getServiceComponents().values()) {
+        assertEquals(newStack, sc.getDesiredStackVersion());
+
+        for (ServiceComponentHost sch : sc.getServiceComponentHosts().values()) {
+          assertEquals(newStack, sch.getDesiredStackVersion());
+        }
+      }
+    }
+
+
+
   }
 
   /**


Mime
View raw message