ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dmitriu...@apache.org
Subject [1/2] ambari git commit: AMBARI-22679. RU: Service action failed with NullPointer on Downgrade after RU (dgrinenko via dlysnichenko)
Date Fri, 22 Dec 2017 17:30:44 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-2.6 953e59af1 -> 2c761d3d5
  refs/heads/trunk 32092da83 -> 55f095abb


AMBARI-22679. RU: Service action failed with NullPointer on Downgrade after RU (dgrinenko
via dlysnichenko)


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

Branch: refs/heads/branch-2.6
Commit: 2c761d3d515945dbdb8a840b2b476a0efc95386a
Parents: 953e59a
Author: Lisnichenko Dmitro <dlysnichenko@hortonworks.com>
Authored: Fri Dec 22 19:25:55 2017 +0200
Committer: Lisnichenko Dmitro <dlysnichenko@hortonworks.com>
Committed: Fri Dec 22 19:26:30 2017 +0200

----------------------------------------------------------------------
 .../internal/UpgradeResourceProvider.java       | 31 +++++++--------
 .../ambari/server/state/UpgradeContext.java     | 14 +++++++
 .../state/stack/ConfigUpgradeValidityTest.java  | 42 ++++++++++++++++++--
 3 files changed, 68 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/2c761d3d/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 5cfe4f3..14e311e 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
@@ -17,8 +17,6 @@
  */
 package org.apache.ambari.server.controller.internal;
 
-import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.HOOKS_FOLDER;
-import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.SERVICE_PACKAGE_FOLDER;
 
 import java.text.MessageFormat;
 import java.util.ArrayList;
@@ -82,9 +80,7 @@ import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.ConfigHelper;
 import org.apache.ambari.server.state.Service;
 import org.apache.ambari.server.state.ServiceComponent;
-import org.apache.ambari.server.state.ServiceInfo;
 import org.apache.ambari.server.state.StackId;
-import org.apache.ambari.server.state.StackInfo;
 import org.apache.ambari.server.state.UpgradeContext;
 import org.apache.ambari.server.state.UpgradeContextFactory;
 import org.apache.ambari.server.state.UpgradeHelper;
@@ -762,16 +758,12 @@ public class UpgradeResourceProvider extends AbstractControllerResourceProvider
       s_upgradeHelper.updateDesiredRepositoriesAndConfigs(upgradeContext);
     }
 
-    @Experimental(feature = ExperimentalFeature.PATCH_UPGRADES, comment = "This is SO VERY
wrong")
-    StackId configurationPackSourceStackId = upgradeContext.getSourceVersions().values().iterator().next().getStackId();
-
     // resolve or build a proper config upgrade pack - always start out with the config pack
     // for the current stack and merge into that
     //
     // HDP 2.2 to 2.3 should start with the config-upgrade.xml from HDP 2.2
     // HDP 2.2 to 2.4 should start with HDP 2.2 and merge in HDP 2.3's config-upgrade.xml
-    ConfigUpgradePack configUpgradePack = ConfigurationPackBuilder.build(pack,
-        configurationPackSourceStackId);
+    ConfigUpgradePack configUpgradePack = ConfigurationPackBuilder.build(upgradeContext);
 
     // create the upgrade and request
     for (UpgradeGroupHolder group : groups) {
@@ -1569,17 +1561,24 @@ public class UpgradeResourceProvider extends AbstractControllerResourceProvider
      * Builds the configurations to use for the specified upgrade and source
      * stack.
      *
-     * @param upgradePack
-     *          the upgrade pack (not {@code null}).
-     * @param sourceStackId
-     *          the source stack (not {@code null}).
+     * @param cx
+     *          the upgrade context(not {@code null}).
      * @return the {@link ConfigUpgradePack} which contains all of the necessary
      *         configuration definitions for the upgrade.
      */
-    public static ConfigUpgradePack build(UpgradePack upgradePack, StackId sourceStackId)
{
+    public static ConfigUpgradePack build(UpgradeContext cx) {
+      final UpgradePack upgradePack = cx.getUpgradePack();
+      final StackId stackId;
+
+      if (cx.getDirection() == Direction.UPGRADE) {
+        stackId = cx.getStackIdFromVersions(cx.getSourceVersions());
+      } else {
+        stackId = cx.getStackIdFromVersions(cx.getTargetVersions());
+      }
+
       List<UpgradePack.IntermediateStack> intermediateStacks = upgradePack.getIntermediateStacks();
       ConfigUpgradePack configUpgradePack = s_metaProvider.get().getConfigUpgradePack(
-          sourceStackId.getStackName(), sourceStackId.getStackVersion());
+        stackId.getStackName(), stackId.getStackVersion());
 
       // merge in any intermediate stacks
       if (null != intermediateStacks) {
@@ -1589,7 +1588,7 @@ public class UpgradeResourceProvider extends AbstractControllerResourceProvider
 
         for (UpgradePack.IntermediateStack intermediateStack : intermediateStacks) {
           ConfigUpgradePack intermediateConfigUpgradePack = s_metaProvider.get().getConfigUpgradePack(
-              sourceStackId.getStackName(), intermediateStack.version);
+            stackId.getStackName(), intermediateStack.version);
 
           configPacksToMerge.add(intermediateConfigUpgradePack);
         }

http://git-wip-us.apache.org/repos/asf/ambari/blob/2c761d3d/ambari-server/src/main/java/org/apache/ambari/server/state/UpgradeContext.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/UpgradeContext.java
b/ambari-server/src/main/java/org/apache/ambari/server/state/UpgradeContext.java
index 13459c4..dbdc091 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/UpgradeContext.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/UpgradeContext.java
@@ -521,6 +521,20 @@ public class UpgradeContext {
   }
 
   /**
+   * Getting stackId from the set of versions. Is is possible until we upgrading components
on the same stack.
+   *
+   * Note: Function should be modified for cross-stack upgrade.
+   *
+   * @param version {@link Set} of services repository versions
+   * @return
+   * {@link StackId} based on provided versions
+   */
+  @Experimental(feature = ExperimentalFeature.PATCH_UPGRADES, comment="This is wrong")
+  public StackId getStackIdFromVersions(Map<String, RepositoryVersionEntity> version)
{
+    return version.values().iterator().next().getStackId();
+  }
+
+  /**
    * Gets the upgrade pack for this upgrade.
    *
    * @return the upgrade pack

http://git-wip-us.apache.org/repos/asf/ambari/blob/2c761d3d/ambari-server/src/test/java/org/apache/ambari/server/state/stack/ConfigUpgradeValidityTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/stack/ConfigUpgradeValidityTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/state/stack/ConfigUpgradeValidityTest.java
index d81f420..02dafe4 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/stack/ConfigUpgradeValidityTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/stack/ConfigUpgradeValidityTest.java
@@ -31,9 +31,17 @@ import org.apache.ambari.server.configuration.Configuration;
 import org.apache.ambari.server.controller.internal.UpgradeResourceProvider.ConfigurationPackBuilder;
 import org.apache.ambari.server.orm.GuiceJpaInitializer;
 import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
+import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
+import org.apache.ambari.server.orm.entities.StackEntity;
+import org.apache.ambari.server.orm.entities.UpgradeEntity;
+import org.apache.ambari.server.orm.entities.UpgradeHistoryEntity;
 import org.apache.ambari.server.stack.ModuleFileUnmarshaller;
+import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.state.StackInfo;
+import org.apache.ambari.server.state.UpgradeContext;
+import org.apache.ambari.server.state.UpgradeContextFactory;
+import org.apache.ambari.server.state.cluster.ClusterImpl;
 import org.apache.ambari.server.state.stack.UpgradePack.ProcessingComponent;
 import org.apache.ambari.server.state.stack.upgrade.ClusterGrouping;
 import org.apache.ambari.server.state.stack.upgrade.ClusterGrouping.ExecuteStage;
@@ -46,6 +54,7 @@ import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.filefilter.FileFilterUtils;
 import org.apache.commons.io.filefilter.IOFileFilter;
 import org.apache.commons.lang.StringUtils;
+import org.easymock.EasyMock;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -70,6 +79,7 @@ public class ConfigUpgradeValidityTest {
 
   private Injector injector;
   private AmbariMetaInfo ambariMetaInfo;
+  private UpgradeContextFactory upgradeContextFactory;
 
   private int validatedConfigCount = 0;
 
@@ -86,6 +96,7 @@ public class ConfigUpgradeValidityTest {
     injector.getInstance(GuiceJpaInitializer.class);
 
     ambariMetaInfo = injector.getInstance(AmbariMetaInfo.class);
+    upgradeContextFactory = injector.getInstance(UpgradeContextFactory.class);
   }
 
   @After
@@ -104,6 +115,8 @@ public class ConfigUpgradeValidityTest {
     Collection<StackInfo> stacks = ambariMetaInfo.getStacks();
     Assert.assertFalse(stacks.isEmpty());
 
+    Cluster cluster = EasyMock.createNiceMock(Cluster.class);
+
     for( StackInfo stack : stacks ){
       if (!stack.isActive()) {
         LOG.info("Skipping configuration validity test for {}", new StackId(stack));
@@ -113,10 +126,33 @@ public class ConfigUpgradeValidityTest {
       Map<String, UpgradePack> upgradePacks = ambariMetaInfo.getUpgradePacks(stack.getName(),
stack.getVersion());
       for (String key : upgradePacks.keySet()) {
         UpgradePack upgradePack = upgradePacks.get(key);
-        StackId sourceStack = new StackId(stack);
+        final StackId sourceStack = new StackId(stack);
+
+        final RepositoryVersionEntity rve = new RepositoryVersionEntity() {{
+          setStack(new StackEntity(){{
+            setStackName(sourceStack.getStackName());
+            setStackVersion(sourceStack.getStackVersion());
+          }});
+        }};
+
+        final UpgradeEntity upgradeEntity = new UpgradeEntity();
+
+        UpgradeHistoryEntity upgradeHistoryEntity = new UpgradeHistoryEntity(){{
+          setServiceName("TEST");
+          setComponentName("TEST");
+          setFromRepositoryVersion(rve);
+          setUpgrade(upgradeEntity);
+        }};
+
+        upgradeEntity.setDirection(Direction.UPGRADE);
+        upgradeEntity.addHistory(upgradeHistoryEntity);
+        upgradeEntity.setRepositoryVersion(rve);
+
+        UpgradeContext cx = upgradeContextFactory.create(cluster, upgradeEntity);
+
+        cx.setUpgradePack(upgradePack);
 
-        ConfigUpgradePack configUpgradePack = ConfigurationPackBuilder.build(upgradePack,
-            sourceStack);
+        ConfigUpgradePack configUpgradePack = ConfigurationPackBuilder.build(cx);
 
         // do configure tasks in the group section
         List<Grouping> groups = upgradePack.getGroups(Direction.UPGRADE);


Mime
View raw message