ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dmitriu...@apache.org
Subject ambari git commit: AMBARI-15183. column "upgrade_id" does not exist upgrading to Ambari 2.4.0 (dlysnichenko)
Date Thu, 25 Feb 2016 19:25:19 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 1621a53dc -> 1df953d68


AMBARI-15183. column "upgrade_id" does not exist upgrading to Ambari 2.4.0 (dlysnichenko)


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

Branch: refs/heads/trunk
Commit: 1df953d68aea7bc33d0fa01f5500c8e896c3abe7
Parents: 1621a53
Author: Lisnichenko Dmitro <dlysnichenko@hortonworks.com>
Authored: Thu Feb 25 21:23:34 2016 +0200
Committer: Lisnichenko Dmitro <dlysnichenko@hortonworks.com>
Committed: Thu Feb 25 21:23:34 2016 +0200

----------------------------------------------------------------------
 .../server/upgrade/UpgradeCatalog240.java       | 17 ++++++++++++
 .../server/upgrade/UpgradeCatalog240Test.java   | 27 ++++++++++++++++++++
 2 files changed, 44 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/1df953d6/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 a3316c0..2f509b4 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
@@ -32,6 +32,7 @@ import java.util.concurrent.atomic.AtomicLong;
 
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.controller.AmbariManagementController;
+import org.apache.ambari.server.orm.DBAccessor;
 import org.apache.ambari.server.orm.DBAccessor.DBColumnInfo;
 import org.apache.ambari.server.orm.dao.AlertDefinitionDAO;
 import org.apache.ambari.server.orm.dao.PermissionDAO;
@@ -43,6 +44,7 @@ import org.apache.ambari.server.orm.entities.RoleAuthorizationEntity;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.RepositoryType;
+import org.apache.ambari.server.state.State;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.jdbc.support.JdbcUtils;
@@ -72,6 +74,10 @@ public class UpgradeCatalog240 extends AbstractUpgradeCatalog {
   protected static final String SERVICE_COMPONENT_HISTORY_TABLE = "servicecomponent_history";
   protected static final String UPGRADE_TABLE = "upgrade";
   protected static final String STACK_TABLE = "stack";
+  protected static final String CLUSTER_TABLE = "clusters";
+  protected static final String CLUSTER_UPGRADE_ID_COLUMN = "upgrade_id";
+  public static final String DESIRED_VERSION_COLUMN_NAME = "desired_version";
+
 
   @Inject
   PermissionDAO permissionDAO;
@@ -132,6 +138,14 @@ public class UpgradeCatalog240 extends AbstractUpgradeCatalog {
     updateRepoVersionTableDDL();
     updateServiceComponentDesiredStateTableDDL();
     createServiceComponentHistoryTable();
+    updateClusterTableDDL();
+  }
+
+  private void updateClusterTableDDL() throws SQLException {
+    dbAccessor.addColumn(CLUSTER_TABLE, new DBColumnInfo(CLUSTER_UPGRADE_ID_COLUMN, Long.class,
null, null, true));
+
+    dbAccessor.addFKConstraint(CLUSTER_TABLE, "FK_clusters_upgrade_id",
+        CLUSTER_UPGRADE_ID_COLUMN, UPGRADE_TABLE, "upgrade_id", false);
   }
 
   @Override
@@ -562,5 +576,8 @@ public class UpgradeCatalog240 extends AbstractUpgradeCatalog {
     // recovery_enabled SMALLINT DEFAULT 0 NOT NULL
     dbAccessor.addColumn(SERVICE_COMPONENT_DESIRED_STATE_TABLE,
             new DBColumnInfo(RECOVERY_ENABLED_COL, Short.class, null, 0, false));
+
+    dbAccessor.addColumn(SERVICE_COMPONENT_DESIRED_STATE_TABLE,
+      new DBColumnInfo(DESIRED_VERSION_COLUMN_NAME, String.class, 255, State.UNKNOWN.toString(),
false));
   }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/1df953d6/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 f5fafbc..a909f84 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
@@ -104,6 +104,8 @@ public class UpgradeCatalog240Test {
   public void testExecuteDDLUpdates() throws SQLException, AmbariException {
     Capture<DBAccessor.DBColumnInfo> capturedColumnInfo = newCapture();
     Capture<DBAccessor.DBColumnInfo> capturedScColumnInfo = newCapture();
+    Capture<DBAccessor.DBColumnInfo> capturedScDesiredVersionColumnInfo = newCapture();
+
     final DBAccessor dbAccessor = createStrictMock(DBAccessor.class);
     Configuration configuration = createNiceMock(Configuration.class);
     Connection connection = createNiceMock(Connection.class);
@@ -113,6 +115,8 @@ public class UpgradeCatalog240Test {
 
     dbAccessor.addColumn(eq("adminpermission"), capture(capturedColumnInfo));
     dbAccessor.addColumn(eq(UpgradeCatalog240.SERVICE_COMPONENT_DESIRED_STATE_TABLE), capture(capturedScColumnInfo));
+    dbAccessor.addColumn(eq(UpgradeCatalog240.SERVICE_COMPONENT_DESIRED_STATE_TABLE),
+        capture(capturedScDesiredVersionColumnInfo));
 
     dbAccessor.createTable(eq("setting"), capture(capturedSettingColumns), eq("id"));
     expect(configuration.getDatabaseUrl()).andReturn(Configuration.JDBC_IN_MEMORY_URL).anyTimes();
@@ -152,10 +156,16 @@ public class UpgradeCatalog240Test {
     dbAccessor.addFKConstraint("servicecomponent_history", "FK_sc_history_to_stack_id",
         "to_stack_id", "stack", "stack_id", false);
 
+
     expect(dbAccessor.getConnection()).andReturn(connection);
     expect(connection.createStatement()).andReturn(statement);
     expect(statement.executeQuery(anyObject(String.class))).andReturn(resultSet);
 
+    Capture<DBAccessor.DBColumnInfo> capturedClusterUpgradeColumnInfo = newCapture();
+    dbAccessor.addColumn(eq(UpgradeCatalog240.CLUSTER_TABLE), capture(capturedClusterUpgradeColumnInfo));
+    dbAccessor.addFKConstraint(UpgradeCatalog240.CLUSTER_TABLE, "FK_clusters_upgrade_id",
+        UpgradeCatalog240.CLUSTER_UPGRADE_ID_COLUMN, UpgradeCatalog240.UPGRADE_TABLE, "upgrade_id",
false);
+
     replay(dbAccessor, configuration, connection, statement, resultSet);
 
     Module module = new Module() {
@@ -188,6 +198,23 @@ public class UpgradeCatalog240Test {
     Assert.assertEquals(0, columnScInfo.getDefaultValue());
     Assert.assertEquals(false, columnScInfo.isNullable());
 
+    DBAccessor.DBColumnInfo columnScDesiredVersionInfo = capturedScDesiredVersionColumnInfo.getValue();
+    Assert.assertNotNull(columnScDesiredVersionInfo);
+    Assert.assertEquals(UpgradeCatalog240.DESIRED_VERSION_COLUMN_NAME, columnScDesiredVersionInfo.getName());
+    Assert.assertEquals(Integer.valueOf(255), columnScDesiredVersionInfo.getLength());
+    Assert.assertEquals(String.class, columnScDesiredVersionInfo.getType());
+    Assert.assertEquals("UNKNOWN", columnScDesiredVersionInfo.getDefaultValue());
+    Assert.assertEquals(false, columnScDesiredVersionInfo.isNullable());
+
+    // Verify if upgrade_id column was added to clusters table
+    DBAccessor.DBColumnInfo clusterUpgradeColumnInfo = capturedClusterUpgradeColumnInfo.getValue();
+    Assert.assertNotNull(clusterUpgradeColumnInfo);
+    Assert.assertEquals(UpgradeCatalog240.CLUSTER_UPGRADE_ID_COLUMN, clusterUpgradeColumnInfo.getName());
+    Assert.assertEquals(null, clusterUpgradeColumnInfo.getLength());
+    Assert.assertEquals(Long.class, clusterUpgradeColumnInfo.getType());
+    Assert.assertEquals(null, clusterUpgradeColumnInfo.getDefaultValue());
+    Assert.assertEquals(true, clusterUpgradeColumnInfo.isNullable());
+
     Map<String, Class> expectedCaptures = new HashMap<>();
     expectedCaptures.put("id", Long.class);
     expectedCaptures.put("name", String.class);


Mime
View raw message