Skip to content

Commit 4cc5c83

Browse files
authored
improve type hints (#2966)
## Changes Add type hints ### Linked issues None ### Functionality None ### Tests - [x] ran unit tests --------- Co-authored-by: Eric Vergnaud <[email protected]>
1 parent 82642a8 commit 4cc5c83

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/databricks/labs/ucx/assessment/azure.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def _get_relevant_service_principals(self) -> list[AzureServicePrincipalInfo]:
7373

7474
# list all relevant service principals in jobs
7575
all_jobs = list(self._ws.jobs.list(expand_tasks=True))
76-
all_clusters_by_id = {c.cluster_id: c for c in self._ws.clusters.list()}
76+
all_clusters_by_id = {c.cluster_id: c for c in self._ws.clusters.list() if c.cluster_id}
7777
for _job, cluster_config in self._get_cluster_configs_from_all_jobs(all_jobs, all_clusters_by_id):
7878
set_service_principals.update(self._get_azure_spn_from_cluster_config(cluster_config))
7979

src/databricks/labs/ucx/assessment/jobs.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from databricks.labs.lsql.backends import SqlBackend
99
from databricks.sdk import WorkspaceClient
1010
from databricks.sdk.service import compute
11-
from databricks.sdk.service.compute import ClusterDetails
11+
from databricks.sdk.service.compute import ClusterDetails, ClusterSpec
1212
from databricks.sdk.service.jobs import (
1313
BaseJob,
1414
BaseRun,
@@ -43,7 +43,7 @@ class JobInfo:
4343

4444
class JobsMixin:
4545
@classmethod
46-
def _get_cluster_configs_from_all_jobs(cls, all_jobs, all_clusters_by_id):
46+
def _get_cluster_configs_from_all_jobs(cls, all_jobs: list[BaseJob], all_clusters_by_id: dict[str, ClusterDetails]):
4747
for job in all_jobs:
4848
if job.settings is None:
4949
continue
@@ -54,7 +54,11 @@ def _get_cluster_configs_from_all_jobs(cls, all_jobs, all_clusters_by_id):
5454
yield from cls._task_clusters(job, all_clusters_by_id)
5555

5656
@classmethod
57-
def _task_clusters(cls, job, all_clusters_by_id):
57+
def _task_clusters(
58+
cls, job: BaseJob, all_clusters_by_id: dict[str, ClusterDetails]
59+
) -> Iterable[tuple[BaseJob, ClusterDetails | ClusterSpec]]:
60+
if not job.settings or not job.settings.tasks:
61+
return
5862
for task in job.settings.tasks:
5963
if task.existing_cluster_id is not None:
6064
interactive_cluster = all_clusters_by_id.get(task.existing_cluster_id, None)
@@ -65,7 +69,9 @@ def _task_clusters(cls, job, all_clusters_by_id):
6569
yield job, task.new_cluster
6670

6771
@staticmethod
68-
def _job_clusters(job):
72+
def _job_clusters(job: BaseJob) -> Iterable[tuple[BaseJob, ClusterSpec]]:
73+
if not job.settings or not job.settings.job_clusters:
74+
return
6975
for job_cluster in job.settings.job_clusters:
7076
if job_cluster.new_cluster is None:
7177
continue
@@ -79,7 +85,7 @@ def __init__(self, ws: WorkspaceClient, sbe: SqlBackend, schema):
7985

8086
def _crawl(self) -> Iterable[JobInfo]:
8187
all_jobs = list(self._ws.jobs.list(expand_tasks=True))
82-
all_clusters = {c.cluster_id: c for c in self._ws.clusters.list()}
88+
all_clusters = {c.cluster_id: c for c in self._ws.clusters.list() if c.cluster_id}
8389
return self._assess_jobs(all_jobs, all_clusters)
8490

8591
def _assess_jobs(self, all_jobs: list[BaseJob], all_clusters_by_id) -> Iterable[JobInfo]:

0 commit comments

Comments
 (0)