Explorar o código

AMBARI-12145 ambari-server upgrade from Ambari 2.0.1 failed (dsen)

Dmytro Sen %!s(int64=10) %!d(string=hai) anos
pai
achega
bf07a96710

+ 17 - 0
ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog210.java

@@ -766,6 +766,23 @@ public class UpgradeCatalog210 extends AbstractUpgradeCatalog {
             }
           }
         }
+        String UPDATE_CURRENT_STACK_ID_IF_NULL_TEMPLATE =
+          "UPDATE hostcomponentstate " +
+          "SET current_stack_id={0} " +
+          "WHERE current_stack_id IS NULL " +
+          "AND cluster_id={1} ";
+        rs = statement.executeQuery("SELECT cluster_id, current_stack_id FROM clusterstate");
+        if (rs != null) {
+          while (rs.next()) {
+            // if hostcomponentstate.current_stack_id is null,
+            // set to cluster's current_stack_id
+            long clusterId = rs.getLong("cluster_id");
+            long currentStackId = rs.getLong("current_stack_id");
+            String hostComponentStateSQL = MessageFormat.format(
+              UPDATE_CURRENT_STACK_ID_IF_NULL_TEMPLATE, currentStackId, clusterId);
+            dbAccessor.executeUpdate(hostComponentStateSQL, false);
+          }
+        }
       } finally {
         if (rs != null) {
           rs.close();