Skip to content

Commit c863619

Browse files
authored
Add ACL migration to migrate-tables workflow (#1135)
## Changes - Add ACL migration strategy as a user configuration - Pass this strategy to `migrate-tables` workflow ### Functionality - [x] modified existing workflow: `migrate-tables` ### Tests <!-- How is this tested? Please see the checklist below and also describe any other relevant tests --> - [x] manually tested - [ ] verified on staging environment (screenshot attached)
1 parent e4a8354 commit c863619

File tree

4 files changed

+13
-16
lines changed

4 files changed

+13
-16
lines changed

src/databricks/labs/ucx/hive_metastore/table_migrate.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -80,25 +80,22 @@ def for_cli(cls, ws: WorkspaceClient, product='ucx'):
8080
def index(self):
8181
return self._migration_status_refresher.index()
8282

83-
def migrate_tables(self, *, what: What | None = None, acl_strategy: AclMigrationWhat | None = None):
83+
def migrate_tables(self, *, what: What | None = None, acl_strategy: list[AclMigrationWhat] | None = None):
8484
self._init_seen_tables()
8585
tables_to_migrate = self._tm.get_tables_to_migrate(self._tc)
86+
tasks = []
87+
grants = []
8688
if acl_strategy is not None:
8789
grants_to_migrate = self._gc.snapshot()
8890
migrated_groups = self._group.snapshot()
89-
tasks = []
91+
else:
92+
acl_strategy = []
9093
for table in tables_to_migrate:
9194
if what is not None and table.src.what != what:
9295
continue
93-
match acl_strategy:
94-
case None:
95-
tasks.append(partial(self._migrate_table, table.src, table.rule))
96-
case AclMigrationWhat.LEGACY_TACL:
97-
grants = self._match_grants(table.src, grants_to_migrate, migrated_groups)
98-
tasks.append(partial(self._migrate_table, table.src, table.rule, grants))
99-
case AclMigrationWhat.PRINCIPAL:
100-
# TODO: Implement principal-based ACL migration
101-
pass
96+
if AclMigrationWhat.LEGACY_TACL in acl_strategy:
97+
grants.extend(self._match_grants(table.src, grants_to_migrate, migrated_groups))
98+
tasks.append(partial(self._migrate_table, table.src, table.rule, grants))
10299
Threads.strict("migrate tables", tasks)
103100

104101
def _migrate_table(self, src_table: Table, rule: Rule, grants: list[Grant] | None = None):

src/databricks/labs/ucx/runtime.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
TablesMigrate,
2626
)
2727
from databricks.labs.ucx.hive_metastore.table_size import TableSizeCrawler
28-
from databricks.labs.ucx.hive_metastore.tables import What
28+
from databricks.labs.ucx.hive_metastore.tables import AclMigrationWhat, What
2929
from databricks.labs.ucx.hive_metastore.udfs import UdfsCrawler
3030
from databricks.labs.ucx.hive_metastore.verification import VerifyHasMetastore
3131
from databricks.labs.ucx.workspace_access.generic import WorkspaceListing
@@ -439,7 +439,7 @@ def migrate_external_tables_sync(
439439
group_manager = GroupManager(sql_backend, ws, cfg.inventory_database)
440440
TablesMigrate(
441441
table_crawler, grant_crawler, ws, sql_backend, table_mapping, group_manager, migration_status_refresher
442-
).migrate_tables(what=What.EXTERNAL_SYNC)
442+
).migrate_tables(what=What.EXTERNAL_SYNC, acl_strategy=[AclMigrationWhat.LEGACY_TACL])
443443

444444

445445
@task("migrate-tables", job_cluster="table_migration")
@@ -459,7 +459,7 @@ def migrate_dbfs_root_delta_tables(
459459
group_manager = GroupManager(sql_backend, ws, cfg.inventory_database)
460460
TablesMigrate(
461461
table_crawler, grant_crawler, ws, sql_backend, table_mapping, group_manager, migration_status_refresher
462-
).migrate_tables(what=What.DBFS_ROOT_DELTA)
462+
).migrate_tables(what=What.DBFS_ROOT_DELTA, acl_strategy=[AclMigrationWhat.LEGACY_TACL])
463463

464464

465465
@task("migrate-groups-experimental", depends_on=[crawl_groups])

tests/integration/hive_metastore/test_migrate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ def test_migrate_managed_tables_with_acl(
486486
table_crawler, grant_crawler, ws, sql_backend, table_mapping, group_manager, migration_status_refresher
487487
)
488488

489-
table_migrate.migrate_tables(acl_strategy=AclMigrationWhat.LEGACY_TACL)
489+
table_migrate.migrate_tables(acl_strategy=[AclMigrationWhat.LEGACY_TACL])
490490

491491
target_tables = list(sql_backend.fetch(f"SHOW TABLES IN {dst_schema.full_name}"))
492492
assert len(target_tables) == 1

tests/unit/hive_metastore/test_table_migrate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ def test_migrate_acls_should_produce_proper_queries(ws, caplog):
628628
table_migrate = TablesMigrate(
629629
table_crawler, grant_crawler, ws, backend, table_mapping, group_manager, migration_status_refresher
630630
)
631-
table_migrate.migrate_tables(acl_strategy=AclMigrationWhat.LEGACY_TACL)
631+
table_migrate.migrate_tables(acl_strategy=[AclMigrationWhat.LEGACY_TACL])
632632

633633
assert "GRANT SELECT ON TABLE ucx_default.db1_dst.managed_dbfs TO `account group`" in backend.queries
634634
assert "GRANT MODIFY ON TABLE ucx_default.db1_dst.managed_mnt TO `account group`" in backend.queries

0 commit comments

Comments
 (0)