You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by rl...@apache.org on 2017/11/27 20:24:32 UTC

[22/49] ambari git commit: AMBARI-22469. Ambari upgrade failed (dlysnichenko)

AMBARI-22469. Ambari upgrade failed (dlysnichenko)


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

Branch: refs/heads/branch-feature-AMBARI-20859
Commit: b1acd1dfe214f1d381af6cdb54300daa78cbd37f
Parents: 5dd334c
Author: Lisnichenko Dmitro <dl...@hortonworks.com>
Authored: Wed Nov 22 17:04:42 2017 +0200
Committer: Lisnichenko Dmitro <dl...@hortonworks.com>
Committed: Wed Nov 22 17:06:30 2017 +0200

----------------------------------------------------------------------
 .../server/upgrade/UpgradeCatalog260.java       | 41 +++++++++++++++-----
 1 file changed, 31 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/b1acd1df/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog260.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog260.java b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog260.java
index 11f79fe..25635b6 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog260.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog260.java
@@ -17,8 +17,6 @@
  */
 package org.apache.ambari.server.upgrade;
 
-import static org.apache.ambari.server.view.ViewContextImpl.CORE_SITE;
-
 import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -134,9 +132,9 @@ public class UpgradeCatalog260 extends AbstractUpgradeCatalog {
   public static final String HOST_COMPONENT_DESIRED_STATE = "hostcomponentdesiredstate";
   public static final String HOST_COMPONENT_STATE = "hostcomponentstate";
 
+  private static final String CORE_SITE = "core-site";
   public static final String AMS_SSL_CLIENT = "ams-ssl-client";
   public static final String METRIC_TRUSTSTORE_ALIAS = "ssl.client.truststore.alias";
-
   /**
    * Logger.
    */
@@ -193,7 +191,7 @@ public class UpgradeCatalog260 extends AbstractUpgradeCatalog {
    */
   @Override
   protected void executeDDLUpdates() throws AmbariException, SQLException {
-    int currentVersionID = getCurrentVersionID();
+    Integer currentVersionID = getCurrentVersionID();
     dropBrokenFK();
     updateServiceComponentDesiredStateTable(currentVersionID);
     updateServiceDesiredStateTable(currentVersionID);
@@ -360,10 +358,13 @@ public class UpgradeCatalog260 extends AbstractUpgradeCatalog {
    * Removes {@value #FK_SDS_DESIRED_STACK_ID} foreign key.
    * adds {@value #FK_REPO_VERSION_ID} foreign key.
    *
+   * @param currentRepoID id of current repo_version. Can be null if there are no cluster repo versions
+   *                      (in this case {@value #SERVICE_DESIRED_STATE_TABLE} table must be empty)
+   *
    * @throws java.sql.SQLException
    */
-  private void updateServiceDesiredStateTable(int currentRepoID) throws SQLException {
-
+  private void updateServiceDesiredStateTable(Integer currentRepoID) throws SQLException {
+    //in case if currentRepoID is null {@value #SERVICE_DESIRED_STATE_TABLE} table must be empty and null defaultValue is ok for non-nullable column
     dbAccessor.addColumn(SERVICE_DESIRED_STATE_TABLE,
         new DBAccessor.DBColumnInfo(DESIRED_REPO_VERSION_ID_COLUMN, Long.class, null, currentRepoID, false));
     dbAccessor.alterColumn(SERVICE_DESIRED_STATE_TABLE,
@@ -413,9 +414,13 @@ public class UpgradeCatalog260 extends AbstractUpgradeCatalog {
    * Removes {@value #FK_SCDS_DESIRED_STACK_ID} foreign key.
    * adds {@value #FK_SCDS_DESIRED_REPO_ID} foreign key.
    *
+   * @param currentRepoID id of current repo_version. Can be null if there are no cluster repo versions
+   *                      (in this case {@value #SERVICE_DESIRED_STATE_TABLE} table must be empty)
+   *
    * @throws java.sql.SQLException
    */
-  private void updateServiceComponentDesiredStateTable(int currentRepoID) throws SQLException {
+  private void updateServiceComponentDesiredStateTable(Integer currentRepoID) throws SQLException {
+    //in case if currentRepoID is null {@value #SERVICE_DESIRED_STATE_TABLE} table must be empty and null defaultValue is ok for non-nullable column
     dbAccessor.addColumn(SERVICE_COMPONENT_DESIRED_STATE_TABLE,
         new DBAccessor.DBColumnInfo(DESIRED_REPO_VERSION_ID_COLUMN, Long.class, null, currentRepoID, false));
     dbAccessor.alterColumn(SERVICE_COMPONENT_DESIRED_STATE_TABLE,
@@ -496,11 +501,27 @@ public class UpgradeCatalog260 extends AbstractUpgradeCatalog {
     updateExistingRepositoriesToBeResolved();
   }
 
-  public int getCurrentVersionID() throws AmbariException, SQLException {
+  /**
+   * get {@value #REPO_VERSION_ID_COLUMN} value from {@value #CLUSTER_VERSION_TABLE}
+   * where {@value #STATE_COLUMN} = {@value #CURRENT}
+   * and validate it
+   *
+   * @return current version ID or null if no cluster versions do exist
+   * @throws AmbariException if cluster versions are present, but current is not selected
+   * @throws SQLException
+   */
+  public Integer getCurrentVersionID() throws AmbariException, SQLException {
     List<Integer> currentVersionList = dbAccessor.getIntColumnValues(CLUSTER_VERSION_TABLE, REPO_VERSION_ID_COLUMN,
         new String[]{STATE_COLUMN}, new String[]{CURRENT}, false);
-    if (currentVersionList.size() != 1) {
-      throw new AmbariException("Can't get current version id");
+    if (currentVersionList.isEmpty()) {
+      List<Integer> allVersionList = dbAccessor.getIntColumnValues(CLUSTER_VERSION_TABLE, REPO_VERSION_ID_COLUMN, null, null,false);
+      if (allVersionList.isEmpty()){
+        return null;
+      } else {
+        throw new AmbariException("Unable to find any CURRENT repositories.");
+      }
+    } else if (currentVersionList.size() != 1) {
+      throw new AmbariException("The following repositories were found to be CURRENT: ".concat(StringUtils.join(currentVersionList, ",")));
     }
     return currentVersionList.get(0);
   }