@Test public void testExecuteDDLUpdates() throws Exception { final DBAccessor dbAccessor = injector.getInstance(DBAccessor.class); Configuration configuration = createNiceMock(Configuration.class); expect(configuration.getDatabaseUrl()).andReturn(Configuration.JDBC_IN_MEMORY_URL).anyTimes(); Capture<DBAccessor.DBColumnInfo> columnCapture = EasyMock.newCapture(); Capture<DBAccessor.DBColumnInfo> columnCaptureUserType = EasyMock.newCapture(); Capture<DBAccessor.DBColumnInfo> columnCapturePermissionLabel = EasyMock.newCapture(); Capture<List<DBAccessor.DBColumnInfo>> columnsCaptureRoleAuthorization = EasyMock.newCapture(); Capture<List<DBAccessor.DBColumnInfo>> columnsCapturePermissionRoleAuthorization = EasyMock.newCapture(); dbAccessor.alterColumn(eq("host_role_command"), capture(columnCapture)); expectLastCall(); dbAccessor.executeQuery("UPDATE users SET user_type='LDAP' WHERE ldap_user=1"); expectLastCall(); dbAccessor.addUniqueConstraint("users", "UNQ_users_0", "user_name", "user_type"); expectLastCall(); dbAccessor.addColumn(eq("users"), capture(columnCaptureUserType)); expectLastCall(); dbAccessor.addColumn(eq("adminpermission"), capture(columnCapturePermissionLabel)); expectLastCall(); dbAccessor.createTable(eq("roleauthorization"), capture(columnsCaptureRoleAuthorization), eq("authorization_id")); expectLastCall(); dbAccessor.createTable(eq("permission_roleauthorization"), capture(columnsCapturePermissionRoleAuthorization), eq("permission_id"), eq("authorization_id")); expectLastCall(); dbAccessor.addFKConstraint("permission_roleauthorization", "FK_permission_roleauth_pid", "permission_id", "adminpermission", "permission_id", false); expectLastCall(); dbAccessor.addFKConstraint("permission_roleauthorization", "FK_permission_roleauth_aid", "authorization_id", "roleauthorization", "authorization_id", false); expectLastCall(); replayAll(); AbstractUpgradeCatalog upgradeCatalog = injector.getInstance(UpgradeCatalog230.class); Class<?> c = AbstractUpgradeCatalog.class; Field f = c.getDeclaredField("configuration"); f.setAccessible(true); f.set(upgradeCatalog, configuration); upgradeCatalog.executeDDLUpdates(); verifyAll(); assertTrue(columnCapture.getValue().isNullable()); assertEquals(columnCaptureUserType.getValue().getName(), "user_type"); assertEquals(columnCaptureUserType.getValue().getType(), String.class); assertEquals(columnCaptureUserType.getValue().getLength(), null); assertEquals(columnCaptureUserType.getValue().getDefaultValue(), "LOCAL"); assertEquals(columnCaptureUserType.getValue().isNullable(), true); assertEquals(columnCapturePermissionLabel.getValue().getName(), "permission_label"); assertEquals(columnCapturePermissionLabel.getValue().getType(), String.class); assertEquals(columnCapturePermissionLabel.getValue().getLength(), Integer.valueOf(255)); assertEquals(columnCapturePermissionLabel.getValue().isNullable(), true); List<DBAccessor.DBColumnInfo> columnInfos; DBAccessor.DBColumnInfo columnInfo; columnInfos = columnsCaptureRoleAuthorization.getValue(); assertEquals(2, columnInfos.size()); columnInfo = columnInfos.get(0); assertEquals("authorization_id", columnInfo.getName()); assertEquals(String.class, columnInfo.getType()); assertEquals(Integer.valueOf(100), columnInfo.getLength()); columnInfo = columnInfos.get(1); assertEquals("authorization_name", columnInfo.getName()); assertEquals(String.class, columnInfo.getType()); assertEquals(Integer.valueOf(255), columnInfo.getLength()); columnInfos = columnsCapturePermissionRoleAuthorization.getValue(); assertEquals(2, columnInfos.size()); columnInfo = columnInfos.get(0); assertEquals("permission_id", columnInfo.getName()); assertEquals(Long.class, columnInfo.getType()); assertEquals(null, columnInfo.getLength()); columnInfo = columnInfos.get(1); assertEquals("authorization_id", columnInfo.getName()); assertEquals(String.class, columnInfo.getType()); assertEquals(Integer.valueOf(100), columnInfo.getLength()); }
@Override protected void executeDDLUpdates() throws AmbariException, SQLException { dbAccessor.alterColumn(HOST_ROLE_COMMAND_TABLE, new DBColumnInfo(HOST_ID_COL, Long.class, null, null, true)); dbAccessor.addColumn(USERS_TABLE, new DBColumnInfo(USER_TYPE_COL, String.class, null, "LOCAL", true)); dbAccessor.executeQuery("UPDATE users SET user_type='LDAP' WHERE ldap_user=1"); dbAccessor.addUniqueConstraint(USERS_TABLE, "UNQ_users_0", "user_name", "user_type"); updateAdminPermissionTable(); createRoleAuthorizationTables(); }
UpgradeCatalog230 extends AbstractUpgradeCatalog { @Override protected void executeDDLUpdates() throws AmbariException, SQLException { dbAccessor.alterColumn(HOST_ROLE_COMMAND_TABLE, new DBColumnInfo(HOST_ID_COL, Long.class, null, null, true)); dbAccessor.addColumn(USERS_TABLE, new DBColumnInfo(USER_TYPE_COL, String.class, null, "LOCAL", true)); dbAccessor.executeQuery("UPDATE users SET user_type='LDAP' WHERE ldap_user=1"); dbAccessor.addUniqueConstraint(USERS_TABLE, "UNQ_users_0", "user_name", "user_type"); updateAdminPermissionTable(); createRoleAuthorizationTables(); } }
UpgradeCatalog230 extends AbstractUpgradeCatalog { @Override protected void executeDDLUpdates() throws AmbariException, SQLException { dbAccessor.alterColumn(HOST_ROLE_COMMAND_TABLE, new DBColumnInfo(HOST_ID_COL, Long.class, null, null, true)); dbAccessor.addColumn(USERS_TABLE, new DBColumnInfo(USER_TYPE_COL, String.class, null, "LOCAL", true)); dbAccessor.executeQuery("UPDATE users SET user_type='LDAP' WHERE ldap_user=1"); dbAccessor.addUniqueConstraint(USERS_TABLE, "UNQ_users_0", "user_name", "user_type"); updateAdminPermissionTable(); createRoleAuthorizationTables(); } @Inject  UpgradeCatalog230(Injector injector); }
UpgradeCatalog230 extends AbstractUpgradeCatalog { @Override protected void executeDDLUpdates() throws AmbariException, SQLException { dbAccessor.alterColumn(HOST_ROLE_COMMAND_TABLE, new DBColumnInfo(HOST_ID_COL, Long.class, null, null, true)); dbAccessor.addColumn(USERS_TABLE, new DBColumnInfo(USER_TYPE_COL, String.class, null, "LOCAL", true)); dbAccessor.executeQuery("UPDATE users SET user_type='LDAP' WHERE ldap_user=1"); dbAccessor.addUniqueConstraint(USERS_TABLE, "UNQ_users_0", "user_name", "user_type"); updateAdminPermissionTable(); createRoleAuthorizationTables(); } @Inject  UpgradeCatalog230(Injector injector); @Override String getSourceVersion(); @Override String getTargetVersion(); }
UpgradeCatalog230 extends AbstractUpgradeCatalog { @Override protected void executeDDLUpdates() throws AmbariException, SQLException { dbAccessor.alterColumn(HOST_ROLE_COMMAND_TABLE, new DBColumnInfo(HOST_ID_COL, Long.class, null, null, true)); dbAccessor.addColumn(USERS_TABLE, new DBColumnInfo(USER_TYPE_COL, String.class, null, "LOCAL", true)); dbAccessor.executeQuery("UPDATE users SET user_type='LDAP' WHERE ldap_user=1"); dbAccessor.addUniqueConstraint(USERS_TABLE, "UNQ_users_0", "user_name", "user_type"); updateAdminPermissionTable(); createRoleAuthorizationTables(); } @Inject  UpgradeCatalog230(Injector injector); @Override String getSourceVersion(); @Override String getTargetVersion();  }