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 2017/05/12 13:54:59 UTC

[1/3] ambari git commit: AMBARI-20997. Ambari upgrade failed (dgrinenko via dlysnichenko)

Repository: ambari
Updated Branches:
  refs/heads/branch-2.5 57a6d15f6 -> c4691de8e
  refs/heads/trunk 08dd15bd3 -> 48c9b3402


AMBARI-20997. Ambari upgrade failed (dgrinenko via dlysnichenko)


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

Branch: refs/heads/branch-2.5
Commit: e18e41229d79a86bdcbb1d6555e8a4356816fcef
Parents: 57a6d15
Author: Lisnichenko Dmitro <dl...@hortonworks.com>
Authored: Fri May 12 16:50:47 2017 +0300
Committer: Lisnichenko Dmitro <dl...@hortonworks.com>
Committed: Fri May 12 16:50:47 2017 +0300

----------------------------------------------------------------------
 .../apache/ambari/server/orm/DBAccessor.java    | 24 +++++++++++
 .../ambari/server/orm/DBAccessorImpl.java       | 44 ++++++++++++++++++++
 .../server/orm/helpers/dbms/DbmsHelper.java     | 21 ++++++++++
 .../orm/helpers/dbms/GenericDbmsHelper.java     |  8 ++++
 .../server/orm/helpers/dbms/MySqlHelper.java    | 12 ++++++
 .../server/orm/helpers/dbms/OracleHelper.java   | 12 ++++++
 .../server/orm/helpers/dbms/PostgresHelper.java | 12 ++++++
 .../server/upgrade/UpgradeCatalog251.java       | 15 ++-----
 8 files changed, 137 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/e18e4122/ambari-server/src/main/java/org/apache/ambari/server/orm/DBAccessor.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/DBAccessor.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/DBAccessor.java
index c132a3d..fac524c 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/DBAccessor.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/DBAccessor.java
@@ -623,6 +623,30 @@ public interface DBAccessor {
    */
   void addDefaultConstraint(String tableName, DBColumnInfo column) throws SQLException;
 
+  /**
+   * Move column data from {@code sourceTableName} to {@code targetTableName} using {@code sourceIDFieldName} and
+   * {@code targetIDFieldName} keys to match right rows
+   *
+   * @param sourceTableName
+   *          the source table name
+   * @param sourceColumn
+   *          the source column name
+   * @param sourceIDFieldName
+   *          the source id key filed name matched with {@code targetIDFieldName}
+   * @param targetTableName
+   *          the target table name
+   * @param targetColumn
+   *          the target column name
+   * @param targetIDFieldName
+   *          the target id key name matched with {@code sourceIDFieldName}
+   * @param isColumnNullable
+   *          should be target column nullable or not
+   *
+   * @throws SQLException
+   */
+  void moveColumnToAnotherTable(String sourceTableName, DBColumnInfo sourceColumn, String sourceIDFieldName,
+       String targetTableName, DBColumnInfo targetColumn, String targetIDFieldName, boolean isColumnNullable) throws SQLException;
+
   enum DbType {
     ORACLE,
     MYSQL,

http://git-wip-us.apache.org/repos/asf/ambari/blob/e18e4122/ambari-server/src/main/java/org/apache/ambari/server/orm/DBAccessorImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/DBAccessorImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/DBAccessorImpl.java
index a399558..c5b116c 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/DBAccessorImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/DBAccessorImpl.java
@@ -1298,4 +1298,48 @@ public class DBAccessorImpl implements DBAccessor {
 
     return valueString;
   }
+
+  /**
+   * Move column data from {@code sourceTableName} to {@code targetTableName} using {@code sourceIDFieldName} and
+   * {@code targetIDFieldName} keys to match right rows
+   *
+   * @param sourceTableName
+   *          the source table name
+   * @param sourceColumn
+   *          the source column name
+   * @param sourceIDFieldName
+   *          the source id key filed name matched with {@code targetIDFieldName}
+   * @param targetTableName
+   *          the target table name
+   * @param targetColumn
+   *          the target column name
+   * @param targetIDFieldName
+   *          the target id key name matched with {@code sourceIDFieldName}
+   * @param isColumnNullable
+   *          should be target column nullable or not
+   *
+   * @throws SQLException
+   */
+  @Override
+  public void moveColumnToAnotherTable(String sourceTableName, DBColumnInfo sourceColumn, String sourceIDFieldName,
+              String targetTableName, DBColumnInfo targetColumn, String targetIDFieldName,  boolean isColumnNullable) throws SQLException {
+
+    if (this.tableHasColumn(sourceTableName, sourceIDFieldName)) {
+
+      final String moveSQL = dbmsHelper.getCopyColumnToAnotherTableStatement(sourceTableName, sourceColumn.getName(),
+        sourceIDFieldName, targetTableName, targetColumn.getName(),targetIDFieldName);
+
+      targetColumn.setNullable(true);  // setting column nullable by default
+
+      this.addColumn(targetTableName, targetColumn);
+      this.executeUpdate(moveSQL, false);
+
+      if (!isColumnNullable) {
+        // this can will trigger exception if some record is null
+        // ToDo: add default option
+        this.setColumnNullable(targetTableName, targetColumn.getName(), false);
+      }
+      this.dropColumn(sourceTableName, sourceColumn.getName());
+    }
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/e18e4122/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/DbmsHelper.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/DbmsHelper.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/DbmsHelper.java
index c2778d3..fa9814a 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/DbmsHelper.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/DbmsHelper.java
@@ -128,6 +128,27 @@ public interface DbmsHelper {
   String getSetNullableStatement(String tableName, DBAccessor.DBColumnInfo columnInfo, boolean nullable);
 
   /**
+   * Get's the {@code UPDATE} statement for {@code sourceTable} for copy column from {@code targetTable} by matching
+   * table keys {@code sourceIDColumnName} and {@code targetIDColumnName}
+   *
+   * @param sourceTable
+   *          the source table name
+   * @param sourceColumnName
+   *          the source column name
+   * @param sourceIDColumnName
+   *          source key id column which would be used to math right rows for {@code targetTable}
+   * @param targetTable
+   *          the destination table name
+   * @param targetColumnName
+   *          the destination column name
+   * @param targetIDColumnName
+   *          destination key id column name which should math {@code sourceIDColumnName}
+   * @return
+   */
+  String getCopyColumnToAnotherTableStatement(String sourceTable, String sourceColumnName, String sourceIDColumnName,
+                                              String targetTable, String targetColumnName, String targetIDColumnName);
+
+  /**
    * Gets whether the database platform supports adding contraints after the
    * {@code NULL} constraint. Some database, such as Oracle, don't allow this.
    * Unfortunately, EclipsLink hard codes the order of constraints.

http://git-wip-us.apache.org/repos/asf/ambari/blob/e18e4122/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/GenericDbmsHelper.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/GenericDbmsHelper.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/GenericDbmsHelper.java
index 36fab83..2a0bb93 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/GenericDbmsHelper.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/GenericDbmsHelper.java
@@ -78,6 +78,14 @@ public class GenericDbmsHelper implements DbmsHelper {
     return stringBuilder.toString();
   }
 
+  /**
+   {@inheritDoc}
+   */
+  @Override
+  public String getCopyColumnToAnotherTableStatement(String sourceTable, String sourceColumnName, String sourceIDColumnName, String targetTable, String targetColumnName, String targetIDColumnName) {
+    throw new UnsupportedOperationException("Column copy is not supported for generic DB");
+  }
+
   public StringBuilder writeAlterTableClause(StringBuilder builder, String tableName) {
     builder.append("ALTER TABLE ").append(tableName).append(" ");
     return builder;

http://git-wip-us.apache.org/repos/asf/ambari/blob/e18e4122/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/MySqlHelper.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/MySqlHelper.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/MySqlHelper.java
index 8a83c90..ad26520 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/MySqlHelper.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/MySqlHelper.java
@@ -93,4 +93,16 @@ public class MySqlHelper extends GenericDbmsHelper {
     }
     return defaultWriter;
   }
+
+  /**
+   {@inheritDoc}
+   */
+  @Override
+  public String getCopyColumnToAnotherTableStatement(String sourceTable, String sourceColumnName,
+         String sourceIDColumnName, String targetTable, String targetColumnName, String targetIDColumnName) {
+
+    return String.format("UPDATE %1$s AS a INNER JOIN %2$s AS b ON a.%5$s = b.%6$s SET a.%3$s = b.%4$s",
+      targetTable, sourceTable, targetColumnName, sourceColumnName, targetIDColumnName, sourceIDColumnName);
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/e18e4122/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/OracleHelper.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/OracleHelper.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/OracleHelper.java
index b5955b4..73356d1 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/OracleHelper.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/OracleHelper.java
@@ -79,4 +79,16 @@ public class OracleHelper extends GenericDbmsHelper {
   public boolean isConstraintSupportedAfterNullability() {
     return false;
   }
+
+  /**
+   {@inheritDoc}
+   */
+  @Override
+  public String getCopyColumnToAnotherTableStatement(String sourceTable, String sourceColumnName,
+         String sourceIDColumnName, String targetTable, String targetColumnName, String targetIDColumnName) {
+
+    // sub-query should return only one value, ROWNUM is safe-guard for this
+    return String.format("UPDATE %1$s a SET (a.%3$s) = (SELECT b.%4$s FROM %2$s b WHERE b.%6$s = a.%5$s and ROWNUM < 2)",
+      targetTable, sourceTable, targetColumnName, sourceColumnName, targetIDColumnName, sourceIDColumnName);
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/e18e4122/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/PostgresHelper.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/PostgresHelper.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/PostgresHelper.java
index ad18428..46d7315 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/PostgresHelper.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/helpers/dbms/PostgresHelper.java
@@ -44,6 +44,18 @@ public class PostgresHelper extends GenericDbmsHelper {
     return builder;
   }
 
+  /**
+   {@inheritDoc}
+   */
+  @Override
+  public String getCopyColumnToAnotherTableStatement(String sourceTable, String sourceColumnName,
+         String sourceIDColumnName, String targetTable, String targetColumnName, String targetIDColumnName) {
+
+    return String.format("UPDATE %1$s AS a SET %3$s = b.%4$s FROM %2$s AS b WHERE a.%5$s = b.%6$s",
+      targetTable, sourceTable, targetColumnName, sourceColumnName, targetIDColumnName, sourceIDColumnName);
+  }
+
+
   @Override
   public StringBuilder writeSetNullableString(StringBuilder builder,
       String tableName, DBAccessor.DBColumnInfo columnInfo, boolean nullable) {

http://git-wip-us.apache.org/repos/asf/ambari/blob/e18e4122/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog251.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog251.java b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog251.java
index c4f198f..146520f 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog251.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog251.java
@@ -114,17 +114,10 @@ public class UpgradeCatalog251 extends AbstractUpgradeCatalog {
    * @throws SQLException
    */
   private void moveClusterHostColumnFromStageToRequest() throws SQLException {
-    if (dbAccessor.tableHasColumn(STAGE_TABLE, CLUSTER_HOST_INFO_COLUMN)){
+    DBColumnInfo sourceColumn = new DBColumnInfo(CLUSTER_HOST_INFO_COLUMN, byte[].class, null, null, false);
+    DBColumnInfo targetColumn = new DBColumnInfo(CLUSTER_HOST_INFO_COLUMN, byte[].class, null, null, false);
 
-      dbAccessor.addColumn(REQUEST_TABLE, new DBColumnInfo(CLUSTER_HOST_INFO_COLUMN, byte[].class, null, null, true));
-
-      // Native query currently is best way to move data, in future move this functionality to dbAccessor
-      final String moveSQL = String.format("UPDATE %1$s AS a SET %3$s = b.%3$s FROM %2$s AS b WHERE a.%4$s = b.%4$s;",
-        REQUEST_TABLE, STAGE_TABLE, CLUSTER_HOST_INFO_COLUMN, REQUEST_ID_COLUMN);
-
-      dbAccessor.executeUpdate(moveSQL, false);
-      dbAccessor.alterColumn(REQUEST_TABLE, new DBColumnInfo(CLUSTER_HOST_INFO_COLUMN, byte[].class, null, null, false));
-      dbAccessor.dropColumn(STAGE_TABLE, CLUSTER_HOST_INFO_COLUMN);
-    }
+    dbAccessor.moveColumnToAnotherTable(STAGE_TABLE, sourceColumn, REQUEST_ID_COLUMN, REQUEST_TABLE, targetColumn,
+      REQUEST_ID_COLUMN, false);
   }
 }


[3/3] ambari git commit: AMBARI-21002. RU/EU: Restart Zookeeper step failed (dgrinenko via dlysnichenko)

Posted by dm...@apache.org.
AMBARI-21002. RU/EU: Restart Zookeeper step failed (dgrinenko via dlysnichenko)


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

Branch: refs/heads/trunk
Commit: 48c9b3402610614603ae9aefa034a08a9a90c75b
Parents: 08dd15b
Author: Lisnichenko Dmitro <dl...@hortonworks.com>
Authored: Fri May 12 16:53:07 2017 +0300
Committer: Lisnichenko Dmitro <dl...@hortonworks.com>
Committed: Fri May 12 16:53:56 2017 +0300

----------------------------------------------------------------------
 .../server/controller/internal/UpgradeResourceProvider.java | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/48c9b340/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeResourceProvider.java
index 623851a..c7f7980 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeResourceProvider.java
@@ -120,6 +120,7 @@ import org.apache.ambari.server.state.stack.upgrade.UpdateStackGrouping;
 import org.apache.ambari.server.state.stack.upgrade.UpgradeScope;
 import org.apache.ambari.server.state.stack.upgrade.UpgradeType;
 import org.apache.ambari.server.state.svccomphost.ServiceComponentHostServerActionEvent;
+import org.apache.ambari.server.utils.StageUtils;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang.StringUtils;
 import org.slf4j.Logger;
@@ -818,7 +819,7 @@ public class UpgradeResourceProvider extends AbstractControllerResourceProvider
     }
 
     List<UpgradeGroupEntity> groupEntities = new ArrayList<>();
-    RequestStageContainer req = createRequest(direction, version);
+    RequestStageContainer req = createRequest(cluster, direction, version);
 
     // the upgrade context calculated these for us based on direction
     StackId sourceStackId = upgradeContext.getOriginalStackId();
@@ -1264,13 +1265,17 @@ public class UpgradeResourceProvider extends AbstractControllerResourceProvider
     }
   }
 
-  private RequestStageContainer createRequest(Direction direction, String version) {
+  private RequestStageContainer createRequest(Cluster cluster, Direction direction, String version) throws AmbariException {
     ActionManager actionManager = getManagementController().getActionManager();
 
     RequestStageContainer requestStages = new RequestStageContainer(
         actionManager.getNextRequestId(), null, s_requestFactory.get(), actionManager);
     requestStages.setRequestContext(String.format("%s to %s", direction.getVerb(true), version));
 
+    Map<String, Set<String>> clusterHostInfo = StageUtils.getClusterHostInfo(cluster);
+    String clusterHostInfoJson = StageUtils.getGson().toJson(clusterHostInfo);
+    requestStages.setClusterHostInfo(clusterHostInfoJson);
+
     return requestStages;
   }
 


[2/3] ambari git commit: AMBARI-21002. RU/EU: Restart Zookeeper step failed (dgrinenko via dlysnichenko)

Posted by dm...@apache.org.
AMBARI-21002. RU/EU: Restart Zookeeper step failed (dgrinenko via dlysnichenko)


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

Branch: refs/heads/branch-2.5
Commit: c4691de8e4355c372f335fce425f91b6ca2ac8e6
Parents: e18e412
Author: Lisnichenko Dmitro <dl...@hortonworks.com>
Authored: Fri May 12 16:53:07 2017 +0300
Committer: Lisnichenko Dmitro <dl...@hortonworks.com>
Committed: Fri May 12 16:53:07 2017 +0300

----------------------------------------------------------------------
 .../server/controller/internal/UpgradeResourceProvider.java | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/c4691de8/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeResourceProvider.java
index 7fced97..dd0086a 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeResourceProvider.java
@@ -118,6 +118,7 @@ import org.apache.ambari.server.state.stack.upgrade.UpdateStackGrouping;
 import org.apache.ambari.server.state.stack.upgrade.UpgradeScope;
 import org.apache.ambari.server.state.stack.upgrade.UpgradeType;
 import org.apache.ambari.server.state.svccomphost.ServiceComponentHostServerActionEvent;
+import org.apache.ambari.server.utils.StageUtils;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang.StringUtils;
 import org.slf4j.Logger;
@@ -779,7 +780,7 @@ public class UpgradeResourceProvider extends AbstractControllerResourceProvider
     }
 
     List<UpgradeGroupEntity> groupEntities = new ArrayList<>();
-    RequestStageContainer req = createRequest(direction, version);
+    RequestStageContainer req = createRequest(cluster, direction, version);
 
     // the upgrade context calculated these for us based on direction
     StackId sourceStackId = upgradeContext.getOriginalStackId();
@@ -1210,13 +1211,17 @@ public class UpgradeResourceProvider extends AbstractControllerResourceProvider
     }
   }
 
-  private RequestStageContainer createRequest(Direction direction, String version) {
+  private RequestStageContainer createRequest(Cluster cluster, Direction direction, String version) throws AmbariException {
     ActionManager actionManager = getManagementController().getActionManager();
 
     RequestStageContainer requestStages = new RequestStageContainer(
         actionManager.getNextRequestId(), null, s_requestFactory.get(), actionManager);
     requestStages.setRequestContext(String.format("%s to %s", direction.getVerb(true), version));
 
+    Map<String, Set<String>> clusterHostInfo = StageUtils.getClusterHostInfo(cluster);
+    String clusterHostInfoJson = StageUtils.getGson().toJson(clusterHostInfo);
+    requestStages.setClusterHostInfo(clusterHostInfoJson);
+
     return requestStages;
   }