|
@@ -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 {
|
|
@@ -1212,6 +1215,53 @@ public class UpgradeCatalog240 extends AbstractUpgradeCatalog {
|
|
|
dbAccessor.setColumnNullable(HOST_ROLE_COMMAND_TABLE, columnName, false);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 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
|