Explorar o código

AMBARI-15122: Auto-start services - Add upgrade support for changes to servicecomponentdesiredstate table

Nahappan Somasundaram %!s(int64=9) %!d(string=hai) anos
pai
achega
6044f0c829

+ 13 - 0
ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog240.java

@@ -77,6 +77,8 @@ public class UpgradeCatalog240 extends AbstractUpgradeCatalog {
   private static final String ID = "id";
   private static final String SETTING_TABLE = "setting";
 
+  protected static final String SERVICE_COMPONENT_DESIRED_STATE_TABLE = "servicecomponentdesiredstate";
+  protected static final String RECOVERY_ENABLED_COL = "recovery_enabled";
 
   // ----- Constructors ------------------------------------------------------
 
@@ -115,6 +117,7 @@ public class UpgradeCatalog240 extends AbstractUpgradeCatalog {
   @Override
   protected void executeDDLUpdates() throws AmbariException, SQLException {
     updateAdminPermissionTable();
+    updateServiceComponentDesiredStateTable();
     createSettingTable();
   }
 
@@ -391,4 +394,14 @@ public class UpgradeCatalog240 extends AbstractUpgradeCatalog {
         7, PermissionEntity.VIEW_USER_PERMISSION_NAME));
   }
 
+  /**
+   * Alter servicecomponentdesiredstate table to add recovery_enabled column.
+   * @throws SQLException
+   */
+  private void updateServiceComponentDesiredStateTable() throws SQLException {
+    // ALTER TABLE servicecomponentdesiredstate ADD COLUMN
+    // recovery_enabled SMALLINT DEFAULT 0 NOT NULL
+    dbAccessor.addColumn(SERVICE_COMPONENT_DESIRED_STATE_TABLE,
+            new DBAccessor.DBColumnInfo(RECOVERY_ENABLED_COL, Short.class, null, 0, false));
+  }
 }

+ 1 - 1
ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql

@@ -177,7 +177,7 @@ CREATE TABLE servicecomponentdesiredstate (
   desired_stack_id BIGINT NOT NULL,
   desired_state VARCHAR(255) NOT NULL,
   service_name VARCHAR(100) NOT NULL,
-  recovery_enabled TINYINT(1) NOT NULL DEFAULT 0,
+  recovery_enabled SMALLINT NOT NULL DEFAULT 0,
   PRIMARY KEY (component_name, cluster_id, service_name)
 );
 

+ 1 - 1
ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql

@@ -167,7 +167,7 @@ CREATE TABLE servicecomponentdesiredstate (
   desired_stack_id NUMBER(19) NOT NULL,
   desired_state VARCHAR2(255) NOT NULL,
   service_name VARCHAR2(255) NOT NULL,
-  recovery_enabled NUMBER(1) DEFAULT 0 NOT NULL,
+  recovery_enabled SMALLINT DEFAULT 0 NOT NULL,
   PRIMARY KEY (component_name, cluster_id, service_name)
 );
 

+ 1 - 1
ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql

@@ -166,7 +166,7 @@ CREATE TABLE servicecomponentdesiredstate (
   desired_stack_id NUMERIC(19) NOT NULL,
   desired_state VARCHAR(255) NOT NULL,
   service_name VARCHAR(255) NOT NULL,
-  recovery_enabled BIT NOT NULL DEFAULT 0,
+  recovery_enabled SMALLINT NOT NULL DEFAULT 0,
   PRIMARY KEY (component_name, cluster_id, service_name)
 );
 

+ 1 - 1
ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql

@@ -186,7 +186,7 @@ CREATE TABLE servicecomponentdesiredstate (
   desired_stack_id BIGINT NOT NULL,
   desired_state VARCHAR(255) NOT NULL,
   service_name VARCHAR(255) NOT NULL,
-  recovery_enabled BIT NOT NULL DEFAULT 0,
+  recovery_enabled SMALLINT NOT NULL DEFAULT 0,
   PRIMARY KEY CLUSTERED (component_name, cluster_id, service_name)
   );
 

+ 12 - 0
ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog240Test.java

@@ -100,6 +100,7 @@ public class UpgradeCatalog240Test {
   @Test
   public void testExecuteDDLUpdates() throws SQLException, AmbariException {
     Capture<DBAccessor.DBColumnInfo> capturedColumnInfo = newCapture();
+    Capture<DBAccessor.DBColumnInfo> capturedScColumnInfo = newCapture();
     final DBAccessor dbAccessor = createStrictMock(DBAccessor.class);
     Configuration configuration = createNiceMock(Configuration.class);
     Connection connection = createNiceMock(Connection.class);
@@ -108,6 +109,8 @@ public class UpgradeCatalog240Test {
     Capture<List<DBAccessor.DBColumnInfo>> capturedSettingColumns = EasyMock.newCapture();
 
     dbAccessor.addColumn(eq("adminpermission"), capture(capturedColumnInfo));
+    dbAccessor.addColumn(eq(UpgradeCatalog240.SERVICE_COMPONENT_DESIRED_STATE_TABLE), capture(capturedScColumnInfo));
+
     dbAccessor.createTable(eq("setting"), capture(capturedSettingColumns), eq("id"));
     expect(configuration.getDatabaseUrl()).andReturn(Configuration.JDBC_IN_MEMORY_URL).anyTimes();
     expect(dbAccessor.getConnection()).andReturn(connection);
@@ -136,6 +139,15 @@ public class UpgradeCatalog240Test {
     Assert.assertEquals(1, columnInfo.getDefaultValue());
     Assert.assertEquals(false, columnInfo.isNullable());
 
+    // Verify if recovery_enabled column was added to servicecomponentdesiredstate table
+    DBAccessor.DBColumnInfo columnScInfo = capturedScColumnInfo.getValue();
+    Assert.assertNotNull(columnScInfo);
+    Assert.assertEquals(UpgradeCatalog240.RECOVERY_ENABLED_COL, columnScInfo.getName());
+    Assert.assertEquals(null, columnScInfo.getLength());
+    Assert.assertEquals(Short.class, columnScInfo.getType());
+    Assert.assertEquals(0, columnScInfo.getDefaultValue());
+    Assert.assertEquals(false, columnScInfo.isNullable());
+
     Map<String, Class> expectedCaptures = new HashMap<>();
     expectedCaptures.put("id", Long.class);
     expectedCaptures.put("name", String.class);