UpgradeCatalog200 extends AbstractUpgradeCatalog { @Override protected void executeDDLUpdates() throws AmbariException, SQLException { prepareRollingUpgradesDDL(); executeAlertDDLUpdates(); createArtifactTable(); createKerberosPrincipalTables(); dbAccessor.addColumn("viewparameter", new DBColumnInfo("label", String.class, 255, null, true)); dbAccessor.addColumn("viewparameter", new DBColumnInfo("placeholder", String.class, 255, null, true)); dbAccessor.addColumn("viewparameter", new DBColumnInfo("default_value", String.class, 2000, null, true)); dbAccessor.addColumn("clusters", new DBColumnInfo( "security_type", String.class, 32, SecurityType.NONE.toString(), false)); dbAccessor.addColumn("hostcomponentdesiredstate", new DBColumnInfo( "security_state", String.class, 32, SecurityState.UNSECURED.toString(), false)); dbAccessor.addColumn("hostcomponentstate", new DBColumnInfo( "security_state", String.class, 32, SecurityState.UNSECURED.toString(), false)); dbAccessor.addColumn("servicedesiredstate", new DBColumnInfo( "security_state", String.class, 32, SecurityState.UNSECURED.toString(), false)); dbAccessor.alterColumn("viewinstanceproperty", new DBColumnInfo("value", String.class, 2000, null, true)); dbAccessor.alterColumn("viewinstancedata", new DBColumnInfo("value", String.class, 2000, null, true)); } @Inject  UpgradeCatalog200(Injector injector); @Override String getTargetVersion(); @Override void executePreDMLUpdates();  }
@Test public void testExecuteDDLUpdates() throws Exception { final DBAccessor dbAccessor = createNiceMock(DBAccessor.class); Configuration configuration = createNiceMock(Configuration.class); Connection connection = createNiceMock(Connection.class); Statement statement = createNiceMock(Statement.class); ResultSet resultSet = createNiceMock(ResultSet.class); expect(configuration.getDatabaseUrl()).andReturn(Configuration.JDBC_IN_MEMORY_URL).anyTimes(); Capture<DBAccessor.DBColumnInfo> alertDefinitionIgnoreColumnCapture = EasyMock.newCapture(); Capture<DBAccessor.DBColumnInfo> alertDefinitionDescriptionColumnCapture = EasyMock.newCapture(); Capture<DBAccessor.DBColumnInfo> alertTargetGlobalColumnCapture = EasyMock.newCapture(); Capture<DBAccessor.DBColumnInfo> hostComponentStateColumnCapture = EasyMock.newCapture(); Capture<DBAccessor.DBColumnInfo> hostComponentVersionColumnCapture = EasyMock.newCapture(); Capture<DBAccessor.DBColumnInfo> clustersSecurityTypeColumnCapture = EasyMock.newCapture(); Capture<DBAccessor.DBColumnInfo> hostComponentStateSecurityStateColumnCapture = EasyMock.newCapture(); Capture<DBAccessor.DBColumnInfo> hostComponentDesiredStateSecurityStateColumnCapture = EasyMock.newCapture(); Capture<DBAccessor.DBColumnInfo> hostRoleCommandRetryColumnCapture = EasyMock.newCapture(); Capture<DBAccessor.DBColumnInfo> stageSkippableColumnCapture = EasyMock.newCapture(); Capture<DBAccessor.DBColumnInfo> viewparameterLabelColumnCapture = EasyMock.newCapture(); Capture<DBAccessor.DBColumnInfo> viewparameterPlaceholderColumnCapture = EasyMock.newCapture(); Capture<DBAccessor.DBColumnInfo> viewparameterDefaultValueColumnCapture = EasyMock.newCapture(); Capture<DBAccessor.DBColumnInfo> serviceDesiredStateSecurityStateColumnCapture = EasyMock.newCapture(); Capture<List<DBAccessor.DBColumnInfo>> clusterVersionCapture = EasyMock.newCapture(); Capture<List<DBAccessor.DBColumnInfo>> hostVersionCapture = EasyMock.newCapture(); Capture<DBAccessor.DBColumnInfo> valueColumnCapture = EasyMock.newCapture(); Capture<DBAccessor.DBColumnInfo> dataValueColumnCapture = EasyMock.newCapture(); Capture<List<DBAccessor.DBColumnInfo>> alertTargetStatesCapture = EasyMock.newCapture(); Capture<List<DBAccessor.DBColumnInfo>> artifactCapture = EasyMock.newCapture(); Capture<List<DBAccessor.DBColumnInfo>> kerberosPrincipalCapture = EasyMock.newCapture(); Capture<List<DBAccessor.DBColumnInfo>> kerberosPrincipalHostCapture = EasyMock.newCapture(); Capture<List<DBAccessor.DBColumnInfo>> upgradeCapture = EasyMock.newCapture(); Capture<List<DBAccessor.DBColumnInfo>> upgradeGroupCapture = EasyMock.newCapture(); Capture<List<DBAccessor.DBColumnInfo>> upgradeItemCapture = EasyMock.newCapture(); dbAccessor.addColumn(eq("alert_definition"), capture(alertDefinitionIgnoreColumnCapture)); dbAccessor.addColumn(eq("alert_definition"), capture(alertDefinitionDescriptionColumnCapture)); dbAccessor.createTable(eq("alert_target_states"), capture(alertTargetStatesCapture)); dbAccessor.addColumn(eq("alert_target"), capture(alertTargetGlobalColumnCapture)); dbAccessor.addColumn(eq("hostcomponentstate"), capture(hostComponentStateColumnCapture)); dbAccessor.addColumn(eq("hostcomponentstate"), capture(hostComponentVersionColumnCapture)); dbAccessor.addColumn(eq("host_role_command"), capture(hostRoleCommandRetryColumnCapture)); dbAccessor.addColumn(eq("stage"), capture(stageSkippableColumnCapture)); dbAccessor.addColumn(eq("clusters"), capture(clustersSecurityTypeColumnCapture)); dbAccessor.addColumn(eq("hostcomponentstate"), capture(hostComponentStateSecurityStateColumnCapture)); dbAccessor.addColumn(eq("hostcomponentdesiredstate"), capture(hostComponentDesiredStateSecurityStateColumnCapture)); dbAccessor.addColumn(eq("viewparameter"), capture(viewparameterLabelColumnCapture)); dbAccessor.addColumn(eq("viewparameter"), capture(viewparameterPlaceholderColumnCapture)); dbAccessor.addColumn(eq("viewparameter"), capture(viewparameterDefaultValueColumnCapture)); dbAccessor.addColumn(eq("servicedesiredstate"), capture(serviceDesiredStateSecurityStateColumnCapture)); dbAccessor.createTable(eq("cluster_version"), capture(clusterVersionCapture), eq("id")); dbAccessor.createTable(eq("host_version"), capture(hostVersionCapture), eq("id")); dbAccessor.createTable(eq("upgrade"), capture(upgradeCapture), eq("upgrade_id")); dbAccessor.createTable(eq("upgrade_group"), capture(upgradeGroupCapture), eq("upgrade_group_id")); dbAccessor.createTable(eq("upgrade_item"), capture(upgradeItemCapture), eq("upgrade_item_id")); dbAccessor.createTable(eq("artifact"), capture(artifactCapture), eq("artifact_name"), eq("foreign_keys")); dbAccessor.createTable(eq("kerberos_principal"), capture(kerberosPrincipalCapture), eq("principal_name")); dbAccessor.createTable(eq("kerberos_principal_host"), capture(kerberosPrincipalHostCapture), eq("principal_name"), eq("host_name")); expect(dbAccessor.tableHasColumn("kerberos_principal_host", "host_name")).andReturn(true).atLeastOnce(); dbAccessor.addFKConstraint(eq("kerberos_principal_host"), eq("FK_krb_pr_host_hostname"), eq("host_name"), eq("hosts"), eq("host_name"), eq(true), eq(false)); dbAccessor.addFKConstraint(eq("kerberos_principal_host"), eq("FK_krb_pr_host_principalname"), eq("principal_name"), eq("kerberos_principal"), eq("principal_name"), eq(true), eq(false)); setViewInstancePropertyExpectations(dbAccessor, valueColumnCapture); setViewInstanceDataExpectations(dbAccessor, dataValueColumnCapture); dbAccessor.getConnection(); expectLastCall().andReturn(connection).anyTimes(); connection.createStatement(); expectLastCall().andReturn(statement).anyTimes(); statement.executeQuery(anyObject(String.class)); expectLastCall().andReturn(resultSet).anyTimes(); replay(dbAccessor, configuration, resultSet, statement, connection); AbstractUpgradeCatalog upgradeCatalog = getUpgradeCatalog(dbAccessor); Class<?> c = AbstractUpgradeCatalog.class; Field f = c.getDeclaredField("configuration"); f.setAccessible(true); f.set(upgradeCatalog, configuration); upgradeCatalog.executeDDLUpdates(); verify(dbAccessor, configuration, resultSet, statement, connection); verifyAlertDefinitionIgnoreColumn(alertDefinitionIgnoreColumnCapture); verifyAlertDefinitionDescriptionColumn(alertDefinitionDescriptionColumnCapture); verifyAlertTargetGlobal(alertTargetGlobalColumnCapture); verifyAlertTargetStatesTable(alertTargetStatesCapture); DBAccessor.DBColumnInfo upgradeStateColumn = hostComponentStateColumnCapture.getValue(); assertEquals("upgrade_state", upgradeStateColumn.getName()); assertEquals(32, (int) upgradeStateColumn.getLength()); assertEquals(String.class, upgradeStateColumn.getType()); assertEquals("NONE", upgradeStateColumn.getDefaultValue()); assertFalse(upgradeStateColumn.isNullable()); DBAccessor.DBColumnInfo upgradeVersionColumn = hostComponentVersionColumnCapture.getValue(); assertEquals("version", upgradeVersionColumn.getName()); assertEquals(32, (int) upgradeVersionColumn.getLength()); assertEquals(String.class, upgradeVersionColumn.getType()); assertEquals("UNKNOWN", upgradeVersionColumn.getDefaultValue()); assertFalse(upgradeVersionColumn.isNullable()); DBAccessor.DBColumnInfo upgradeRetryColumn = hostRoleCommandRetryColumnCapture.getValue(); assertEquals("retry_allowed", upgradeRetryColumn.getName()); assertEquals(1, (int) upgradeRetryColumn.getLength()); assertEquals(Integer.class, upgradeRetryColumn.getType()); assertEquals(0, upgradeRetryColumn.getDefaultValue()); assertFalse(upgradeRetryColumn.isNullable()); DBAccessor.DBColumnInfo upgradeSkippableColumn = stageSkippableColumnCapture.getValue(); assertEquals("skippable", upgradeSkippableColumn.getName()); assertEquals(1, (int) upgradeSkippableColumn.getLength()); assertEquals(Integer.class, upgradeSkippableColumn.getType()); assertEquals(0, upgradeSkippableColumn.getDefaultValue()); assertFalse(upgradeSkippableColumn.isNullable()); verifyClustersSecurityType(clustersSecurityTypeColumnCapture); verifyComponentSecurityStateColumn(hostComponentStateSecurityStateColumnCapture); verifyComponentSecurityStateColumn(hostComponentDesiredStateSecurityStateColumnCapture); verifyServiceSecurityStateColumn(serviceDesiredStateSecurityStateColumnCapture); verifyViewParameterColumns(viewparameterLabelColumnCapture, viewparameterPlaceholderColumnCapture, viewparameterDefaultValueColumnCapture); List<DBAccessor.DBColumnInfo> artifactColumns = artifactCapture.getValue(); testCreateArtifactTable(artifactColumns); testCreateKerberosPrincipalTable(kerberosPrincipalCapture.getValue()); testCreateKerberosPrincipalHostTable(kerberosPrincipalHostCapture.getValue()); assertEquals(7, clusterVersionCapture.getValue().size()); assertEquals(4, hostVersionCapture.getValue().size()); assertViewInstancePropertyColumns(valueColumnCapture); assertViewInstanceDataColumns(dataValueColumnCapture); assertEquals(6, upgradeCapture.getValue().size()); assertEquals(4, upgradeGroupCapture.getValue().size()); assertEquals(7, upgradeItemCapture.getValue().size()); }