You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by dm...@apache.org on 2016/04/21 16:49:56 UTC
ambari git commit: AMBARI-15995 ambari upgrade fail (upgrade of
ambari packages ... not hdp (eu/standard) upgrade)
Repository: ambari
Updated Branches:
refs/heads/trunk 6e46135ba -> 8416c0df8
AMBARI-15995 ambari upgrade fail (upgrade of ambari packages ... not hdp (eu/standard) upgrade)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/8416c0df
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/8416c0df
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/8416c0df
Branch: refs/heads/trunk
Commit: 8416c0df87282329be143cca13b5bbfc62e630c8
Parents: 6e46135
Author: Lisnichenko Dmitro <dl...@hortonworks.com>
Authored: Thu Apr 21 17:48:27 2016 +0300
Committer: Lisnichenko Dmitro <dl...@hortonworks.com>
Committed: Thu Apr 21 17:48:27 2016 +0300
----------------------------------------------------------------------
.../server/upgrade/UpgradeCatalog240.java | 50 ++++++++++++++++++++
.../server/upgrade/UpgradeCatalog240Test.java | 3 ++
2 files changed, 53 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/8416c0df/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog240.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog240.java b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog240.java
index d4d47bf..e377cc0 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog240.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog240.java
@@ -100,6 +100,8 @@ public class UpgradeCatalog240 extends AbstractUpgradeCatalog {
public static final String BLUEPRINT_TABLE = "blueprint";
public static final String VIEWINSTANCE_TABLE = "viewinstance";
public static final String SHORT_URL_COLUMN = "short_url";
+ protected static final String CLUSTER_VERSION_TABLE = "cluster_version";
+ protected static final String HOST_VERSION_TABLE = "host_version";
private static final String OOZIE_ENV_CONFIG = "oozie-env";
private static final String HIVE_ENV_CONFIG = "hive-env";
@@ -205,6 +207,7 @@ public class UpgradeCatalog240 extends AbstractUpgradeCatalog {
updateKerberosConfigs();
updateYarnEnv();
removeHiveOozieDBConnectionConfigs();
+ updateClustersAndHostsVersionStateTableDML();
}
private void createSettingTable() throws SQLException {
@@ -1213,6 +1216,53 @@ public class UpgradeCatalog240 extends AbstractUpgradeCatalog {
}
/**
+ * Update Clusters and Hosts Version State from UPGRADING, UPGRADE_FAILED to INSTALLED
+ * and UPGRADED to CURRENT if repo_version_id from cluster_version equals repo_version_id of Clusters and Hosts Version State
+ *
+ * @throws SQLException
+ */
+
+ @Transactional
+ protected void updateClustersAndHostsVersionStateTableDML() throws SQLException, AmbariException {
+
+ dbAccessor.executeQuery("UPDATE " + HOST_VERSION_TABLE + " SET state = 'INSTALLED' WHERE state IN ('UPGRADING', 'UPGRADE_FAILED', 'UPGRADED')");
+ dbAccessor.executeQuery("UPDATE " + CLUSTER_VERSION_TABLE + " SET state = 'INSTALLED' WHERE state IN ('UPGRADING', 'UPGRADE_FAILED', 'UPGRADED')");
+
+ Statement statement = null;
+ ResultSet resultSet = null;
+ try {
+ statement = dbAccessor.getConnection().createStatement();
+ if (statement != null) {
+ String selectSQL = String.format("SELECT repo_version_id, cluster_id FROM %s WHERE state = 'CURRENT'",
+ CLUSTER_VERSION_TABLE);
+
+ resultSet = statement.executeQuery(selectSQL);
+ Set<Long> clusterIds = new HashSet<>();
+ while (null != resultSet && resultSet.next()) {
+ Long clusterId = resultSet.getLong("cluster_id");
+ if (clusterIds.contains(clusterId)) {
+ throw new AmbariException(String.format("Database is in a bad state. Cluster %s contains multiple CURRENT version", clusterId));
+ }
+ clusterIds.add(clusterId);
+ Long repoVersionId = resultSet.getLong("repo_version_id");
+
+ String updateHostVersionSQL = String.format(
+ "UPDATE %s SET state = 'CURRENT' WHERE repo_version_id = %s", HOST_VERSION_TABLE, repoVersionId);
+ String updateClusterVersionSQL = String.format(
+ "UPDATE %s SET state = 'CURRENT' WHERE repo_version_id = %s", CLUSTER_VERSION_TABLE, repoVersionId);
+
+ dbAccessor.executeQuery(updateHostVersionSQL);
+ dbAccessor.executeQuery(updateClusterVersionSQL);
+ }
+ }
+
+ } finally {
+ JdbcUtils.closeResultSet(resultSet);
+ JdbcUtils.closeStatement(statement);
+ }
+ }
+
+ /**
* In hdfs-site, set dfs.client.retry.policy.enabled=false
* This is needed for Rolling/Express upgrade so that clients don't keep retrying, which exhausts the retries and
* doesn't allow for a graceful failover, which is expected.
http://git-wip-us.apache.org/repos/asf/ambari/blob/8416c0df/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog240Test.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog240Test.java b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog240Test.java
index c091262..6b7d71a 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog240Test.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog240Test.java
@@ -378,6 +378,7 @@ public class UpgradeCatalog240Test {
Method updateKerberosEnv = UpgradeCatalog240.class.getDeclaredMethod("updateKerberosConfigs");
Method updateYarnEnv = UpgradeCatalog240.class.getDeclaredMethod("updateYarnEnv");
Method removeHiveOozieDBConnectionConfigs = UpgradeCatalog240.class.getDeclaredMethod("removeHiveOozieDBConnectionConfigs");
+ Method updateClustersAndHostsVersionStateTableDML = UpgradeCatalog240.class.getDeclaredMethod("updateClustersAndHostsVersionStateTableDML");
Capture<String> capturedStatements = newCapture(CaptureType.ALL);
@@ -396,6 +397,7 @@ public class UpgradeCatalog240Test {
.addMockedMethod(updateKerberosEnv)
.addMockedMethod(updateYarnEnv)
.addMockedMethod(removeHiveOozieDBConnectionConfigs)
+ .addMockedMethod(updateClustersAndHostsVersionStateTableDML)
.createMock();
Field field = AbstractUpgradeCatalog.class.getDeclaredField("dbAccessor");
@@ -412,6 +414,7 @@ public class UpgradeCatalog240Test {
upgradeCatalog240.updateKerberosConfigs();
upgradeCatalog240.updateYarnEnv();
upgradeCatalog240.removeHiveOozieDBConnectionConfigs();
+ upgradeCatalog240.updateClustersAndHostsVersionStateTableDML();
replay(upgradeCatalog240, dbAccessor);