summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLisnichenko Dmitro <dlysnichenko@hortonworks.com>2018-07-05 19:09:36 +0300
committerLisnichenko Dmitro <dlysnichenko@hortonworks.com>2018-07-05 19:11:14 +0300
commit214f7ce9dae42224ff60629905cd56c3654ef7f4 (patch)
tree484e7acc3161376d756ea613d159da8e5ea7c4c3
parent37cd6ef4db9532ddb1d3994e4c5de97a617e40ff (diff)
AMBARI-24251. Ambari Schema Upgrade is failing after creating views (dlysnichenko)
-rw-r--r--ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog270.java12
-rw-r--r--ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog270Test.java12
2 files changed, 24 insertions, 0 deletions
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog270.java b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog270.java
index d77a1dc6aa..dd742b6a0b 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog270.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog270.java
@@ -253,6 +253,11 @@ public class UpgradeCatalog270 extends AbstractUpgradeCatalog {
public static final String AMBARI_INFRA_OLD_NAME = "AMBARI_INFRA";
public static final String AMBARI_INFRA_NEW_NAME = "AMBARI_INFRA_SOLR";
+ // Broken constraints added by Views
+ public static final String FK_HOSTCOMPONENTDESIREDSTATE_COMPONENT_NAME = "fk_hostcomponentdesiredstate_component_name";
+ public static final String FK_HOSTCOMPONENTSTATE_COMPONENT_NAME = "fk_hostcomponentstate_component_name";
+ public static final String FK_SERVICECOMPONENTDESIREDSTATE_SERVICE_NAME = "fk_servicecomponentdesiredstate_service_name";
+
static final String YARN_SERVICE = "YARN";
@Inject
@@ -297,6 +302,7 @@ public class UpgradeCatalog270 extends AbstractUpgradeCatalog {
*/
@Override
protected void executeDDLUpdates() throws AmbariException, SQLException {
+ dropBrokenFKs();
updateStageTable();
updateRequestTable();
addOpsDisplayNameColumnToHostRoleCommand();
@@ -941,6 +947,12 @@ public class UpgradeCatalog270 extends AbstractUpgradeCatalog {
dbAccessor.dropTable(temporaryTable);
}
+ private void dropBrokenFKs() throws SQLException {
+ dbAccessor.dropFKConstraint(COMPONENT_DESIRED_STATE_TABLE, FK_HOSTCOMPONENTDESIREDSTATE_COMPONENT_NAME);
+ dbAccessor.dropFKConstraint(COMPONENT_STATE_TABLE, FK_HOSTCOMPONENTSTATE_COMPONENT_NAME);
+ dbAccessor.dropFKConstraint(SERVICE_COMPONENT_DESIRED_STATE_TABLE, FK_SERVICECOMPONENTDESIREDSTATE_SERVICE_NAME);
+ }
+
protected void updateStageTable() throws SQLException {
dbAccessor.addColumn(STAGE_TABLE,
new DBAccessor.DBColumnInfo(STAGE_STATUS_COLUMN, String.class, 255, HostRoleStatus.PENDING, false));
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog270Test.java b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog270Test.java
index 402ff3cb4d..68c6b1fd9c 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog270Test.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog270Test.java
@@ -34,10 +34,13 @@ import static org.apache.ambari.server.upgrade.UpgradeCatalog270.AMBARI_SEQUENCE
import static org.apache.ambari.server.upgrade.UpgradeCatalog270.COMPONENT_DESIRED_STATE_TABLE;
import static org.apache.ambari.server.upgrade.UpgradeCatalog270.COMPONENT_NAME_COLUMN;
import static org.apache.ambari.server.upgrade.UpgradeCatalog270.COMPONENT_STATE_TABLE;
+import static org.apache.ambari.server.upgrade.UpgradeCatalog270.FK_HOSTCOMPONENTDESIREDSTATE_COMPONENT_NAME;
+import static org.apache.ambari.server.upgrade.UpgradeCatalog270.FK_HOSTCOMPONENTSTATE_COMPONENT_NAME;
import static org.apache.ambari.server.upgrade.UpgradeCatalog270.FK_KKP_HOST_ID;
import static org.apache.ambari.server.upgrade.UpgradeCatalog270.FK_KKP_KEYTAB_PATH;
import static org.apache.ambari.server.upgrade.UpgradeCatalog270.FK_KKP_PRINCIPAL_NAME;
import static org.apache.ambari.server.upgrade.UpgradeCatalog270.FK_KKP_SERVICE_PRINCIPAL;
+import static org.apache.ambari.server.upgrade.UpgradeCatalog270.FK_SERVICECOMPONENTDESIREDSTATE_SERVICE_NAME;
import static org.apache.ambari.server.upgrade.UpgradeCatalog270.HOSTS_TABLE;
import static org.apache.ambari.server.upgrade.UpgradeCatalog270.HOST_ID_COLUMN;
import static org.apache.ambari.server.upgrade.UpgradeCatalog270.KERBEROS_KEYTAB_PRINCIPAL_TABLE;
@@ -88,6 +91,7 @@ import static org.apache.ambari.server.upgrade.UpgradeCatalog270.REQUEST_DISPLAY
import static org.apache.ambari.server.upgrade.UpgradeCatalog270.REQUEST_TABLE;
import static org.apache.ambari.server.upgrade.UpgradeCatalog270.REQUEST_USER_NAME_COLUMN;
import static org.apache.ambari.server.upgrade.UpgradeCatalog270.SECURITY_STATE_COLUMN;
+import static org.apache.ambari.server.upgrade.UpgradeCatalog270.SERVICE_COMPONENT_DESIRED_STATE_TABLE;
import static org.apache.ambari.server.upgrade.UpgradeCatalog270.SERVICE_DESIRED_STATE_TABLE;
import static org.apache.ambari.server.upgrade.UpgradeCatalog270.SERVICE_NAME_COLUMN;
import static org.apache.ambari.server.upgrade.UpgradeCatalog270.STAGE_DISPLAY_STATUS_COLUMN;
@@ -394,6 +398,14 @@ public class UpgradeCatalog270Test {
@Test
public void testExecuteDDLUpdates() throws Exception {
+ // dropBrokenFKs
+ dbAccessor.dropFKConstraint(COMPONENT_DESIRED_STATE_TABLE, FK_HOSTCOMPONENTDESIREDSTATE_COMPONENT_NAME);
+ expectLastCall().once();
+ dbAccessor.dropFKConstraint(COMPONENT_STATE_TABLE, FK_HOSTCOMPONENTSTATE_COMPONENT_NAME);
+ expectLastCall().once();
+ dbAccessor.dropFKConstraint(SERVICE_COMPONENT_DESIRED_STATE_TABLE, FK_SERVICECOMPONENTDESIREDSTATE_SERVICE_NAME);
+ expectLastCall().once();
+
// updateStageTable
Capture<DBAccessor.DBColumnInfo> updateStageTableCaptures = newCapture(CaptureType.ALL);
dbAccessor.addColumn(eq(STAGE_TABLE), capture(updateStageTableCaptures));