ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nc...@apache.org
Subject [14/19] ambari git commit: AMBARI-18467. Ambari server does not come up after restart if cluster install fails. (Balazs Bence Sari via stoader)
Date Wed, 28 Sep 2016 17:28:11 GMT
AMBARI-18467. Ambari server does not come up after restart if cluster install fails. (Balazs
Bence Sari via stoader)


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

Branch: refs/heads/branch-dev-patch-upgrade
Commit: 2700bd125f2f9bbae2ebfcc0831ec881097b4cff
Parents: a0fff84
Author: Balazs Bence Sari <bsari@hortonworks.com>
Authored: Wed Sep 28 13:42:59 2016 +0200
Committer: Toader, Sebastian <stoader@hortonworks.com>
Committed: Wed Sep 28 13:42:59 2016 +0200

----------------------------------------------------------------------
 .../stack/UpdateActiveRepoVersionOnStartup.java |  9 +++++--
 .../UpdateActiveRepoVersionOnStartupTest.java   | 28 +++++++++++++-------
 2 files changed, 26 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/2700bd12/ambari-server/src/main/java/org/apache/ambari/server/stack/UpdateActiveRepoVersionOnStartup.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/stack/UpdateActiveRepoVersionOnStartup.java
b/ambari-server/src/main/java/org/apache/ambari/server/stack/UpdateActiveRepoVersionOnStartup.java
index 1413c66..8a32a42 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/stack/UpdateActiveRepoVersionOnStartup.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/stack/UpdateActiveRepoVersionOnStartup.java
@@ -94,9 +94,14 @@ public class UpdateActiveRepoVersionOnStartup {
         LOG.info("Updating existing repo versions for cluster {} on stack {}-{}",
             cluster.getClusterName(), stack.getName(), stack.getVersion());
         ClusterVersionEntity clusterVersion = clusterVersionDao.findByClusterAndStateCurrent(cluster.getClusterName());
+        if (null != clusterVersion) {
           RepositoryVersionEntity repoVersion = clusterVersion.getRepositoryVersion();
-        updateRepoVersion(stack, repoVersion);
-        repositoryVersionDao.merge(repoVersion);
+          updateRepoVersion(stack, repoVersion);
+          repositoryVersionDao.merge(repoVersion);
+        }
+        else {
+          LOG.warn("Missing cluster version for cluster {}", cluster.getClusterName());
+        }
       }
     }
     catch(Exception ex) {

http://git-wip-us.apache.org/repos/asf/ambari/blob/2700bd12/ambari-server/src/test/java/org/apache/ambari/server/stack/UpdateActiveRepoVersionOnStartupTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/stack/UpdateActiveRepoVersionOnStartupTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/stack/UpdateActiveRepoVersionOnStartupTest.java
index 9c54a88..24ab0e8 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/stack/UpdateActiveRepoVersionOnStartupTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/stack/UpdateActiveRepoVersionOnStartupTest.java
@@ -37,7 +37,6 @@ import org.apache.ambari.server.state.RepositoryInfo;
 import org.apache.ambari.server.state.StackInfo;
 import org.apache.ambari.server.state.stack.upgrade.RepositoryVersionHelper;
 import org.junit.Assert;
-import org.junit.Before;
 import org.junit.Test;
 
 import com.google.common.base.Charsets;
@@ -61,10 +60,17 @@ public class UpdateActiveRepoVersionOnStartupTest {
 
   @Test
   public void addAServiceRepoToExistingRepoVersion() throws Exception {
+    init(true);
     activeRepoUpdater.process();
     verifyRepoIsAdded();
   }
 
+  @Test
+  public void missingClusterVersionShouldNotCauseException() throws Exception {
+    init(false);
+    activeRepoUpdater.process();
+  }
+
   /**
    * Verifies if the add-on service repo is added to the repo version entity, both json and
xml representations.
    *
@@ -84,8 +90,7 @@ public class UpdateActiveRepoVersionOnStartupTest {
     Assert.assertTrue(ADD_ON_REPO_ID + " is add-on repo was not added to JSON representation",
serviceRepoAddedToJson);
   }
 
-  @Before
-  public void init() throws Exception {
+  public void init(boolean addClusterVersion) throws Exception {
     ClusterDAO clusterDao = mock(ClusterDAO.class);
     ClusterVersionDAO clusterVersionDAO = mock(ClusterVersionDAO.class);
     repositoryVersionDao = mock(RepositoryVersionDAO.class);
@@ -125,17 +130,22 @@ public class UpdateActiveRepoVersionOnStartupTest {
       }
     };
     Injector injector = Guice.createInjector(testModule);
-    repoVersion = new RepositoryVersionEntity();
-    repoVersion.setStack(stackEntity);
-    repoVersion.setOperatingSystems(resourceAsString("org/apache/ambari/server/stack/UpdateActiveRepoVersionOnStartupTest_initialRepos.json"));
-    ClusterVersionEntity clusterVersion = new ClusterVersionEntity();
-    clusterVersion.setRepositoryVersion(repoVersion);
-    when(clusterVersionDAO.findByClusterAndStateCurrent(CLUSTER_NAME)).thenReturn(clusterVersion);
+    if (addClusterVersion) {
+      repoVersion = new RepositoryVersionEntity();
+      repoVersion.setStack(stackEntity);
+      repoVersion.setOperatingSystems(resourceAsString("org/apache/ambari/server/stack/UpdateActiveRepoVersionOnStartupTest_initialRepos.json"));
+      ClusterVersionEntity clusterVersion = new ClusterVersionEntity();
+      clusterVersion.setRepositoryVersion(repoVersion);
+      when(clusterVersionDAO.findByClusterAndStateCurrent(CLUSTER_NAME)).thenReturn(clusterVersion);
+
+    }
 
     activeRepoUpdater = new UpdateActiveRepoVersionOnStartup(clusterDao,
         clusterVersionDAO, repositoryVersionDao, repositoryVersionHelper, metaInfo);
   }
 
+
+
   private static String resourceAsString(String resourceName) throws IOException {
     return Resources.toString(Resources.getResource(resourceName), Charsets.UTF_8);
   }


Mime
View raw message