Skip to content

Commit

Permalink
..
Browse files Browse the repository at this point in the history
  • Loading branch information
nfx committed Nov 7, 2023
1 parent 556ef44 commit 458a2d2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 26 deletions.
20 changes: 6 additions & 14 deletions labs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,12 @@ install_hook: src/databricks/labs/ucx/install.py
entrypoint: src/databricks/labs/ucx/cli.py
min_python: 3.10
commands:
- name: me
description: dummy

- name: open-remote-config
description: Opens remote configuration in the browser

- name: jobs
description: Show current jobs

- name: logs
description: Display debug logs from the run
flags:
- name: step
description: name of the step
- name: run-id
default: latest
description: job run ID
- name: workflows
description: Show deployed workflows and their state
table_template: |-
Step\tState\tStarted
{{range .}}{{.step}}\t{{.state}}\t{{.started}}
{{end}}
14 changes: 4 additions & 10 deletions src/databricks/labs/ucx/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@

from databricks.labs.ucx.install import WorkspaceInstaller

logger = logging.getLogger('databricks.labs.ucx')


def jobs():
ws = WorkspaceClient()
installer = WorkspaceInstaller(ws)
for step, job_id in installer.deployed_steps().items():
print(step, job_id)
logger.info('Fetching deployed jobs...')
print(json.dumps(installer.latest_job_status()))


def open_remote_config():
Expand All @@ -22,17 +24,9 @@ def open_remote_config():
webbrowser.open(ws_file_url)


def me():
ws = WorkspaceClient()
my_user = ws.current_user.me()
greeting = input("How to greet you? ")
print(f'{greeting}, {my_user.user_name}!')


MAPPING = {
'open-remote-config': open_remote_config,
'jobs': jobs,
'me': me,
}


Expand Down
13 changes: 11 additions & 2 deletions src/databricks/labs/ucx/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,6 @@ def _configure(self):
try:
self._ws.workspace.get_status(self.config_file)
logger.info(f"UCX is already configured. See {ws_file_url}")
if self._prompts and self._question("Open config file in the browser", default="yes") == "yes":
webbrowser.open(ws_file_url)
return
except DatabricksError as err:
if err.error_code != "RESOURCE_DOES_NOT_EXIST":
Expand Down Expand Up @@ -820,6 +818,17 @@ def _get_ext_hms_conf_from_policy(cluster_policy):
spark_conf_dict[key[11:]] = cluster_policy[key]["value"]
return instance_profile, spark_conf_dict

def latest_job_status(self) -> list[dict]:
latest_status = []
for step, job_id in self.deployed_steps().items():
job_runs = list(self._ws.jobs.list_runs(job_id=job_id, limit=1))
latest_status.append({
'step': step,
'state': 'UNKNOWN' if not job_runs else str(job_runs[0].state.result_state),
'started': '' if not job_runs else job_runs[0].start_time
})
return latest_status


if __name__ == "__main__":
ws = WorkspaceClient(product="ucx", product_version=__version__)
Expand Down

0 comments on commit 458a2d2

Please sign in to comment.