|
21 | 21 |
|
22 | 22 |
|
23 | 23 | from databricks.labs.lakebridge.assessments.configure_assessment import create_assessment_configurator |
24 | | -from databricks.labs.lakebridge.assessments import PROFILER_SOURCE_SYSTEM |
| 24 | +from databricks.labs.lakebridge.assessments import PROFILER_SOURCE_SYSTEM, PRODUCT_NAME |
| 25 | +from databricks.labs.lakebridge.assessments.profiler import Profiler |
25 | 26 |
|
26 | 27 | from databricks.labs.lakebridge.config import TranspileConfig, LSPConfigOptionV1 |
27 | 28 | from databricks.labs.lakebridge.contexts.application import ApplicationContext |
| 29 | +from databricks.labs.lakebridge.connections.credential_manager import cred_file |
28 | 30 | from databricks.labs.lakebridge.helpers.recon_config_utils import ReconConfigPrompts |
29 | 31 | from databricks.labs.lakebridge.helpers.telemetry_utils import make_alphanum_or_semver |
30 | 32 | from databricks.labs.lakebridge.install import installer |
@@ -711,18 +713,19 @@ def configure_secrets(*, w: WorkspaceClient) -> None: |
711 | 713 | recon_conf.prompt_and_save_connection_details() |
712 | 714 |
|
713 | 715 |
|
714 | | -@lakebridge.command(is_unauthenticated=True) |
715 | | -def configure_database_profiler() -> None: |
716 | | - """[Experimental] Install the lakebridge Assessment package""" |
717 | | - prompts = Prompts() |
718 | | - |
719 | | - # Prompt for source system |
720 | | - source_system = str( |
721 | | - prompts.choice("Please select the source system you want to configure", PROFILER_SOURCE_SYSTEM) |
722 | | - ).lower() |
| 716 | +@lakebridge.command |
| 717 | +def configure_database_profiler(w: WorkspaceClient) -> None: |
| 718 | + """[Experimental] Installs and runs the Lakebridge Assessment package for database profiling""" |
| 719 | + ctx = ApplicationContext(w) |
| 720 | + ctx.add_user_agent_extra("cmd", "configure-profiler") |
| 721 | + prompts = ctx.prompts |
| 722 | + source_tech = prompts.choice("Select the source technology", PROFILER_SOURCE_SYSTEM).lower() |
| 723 | + ctx.add_user_agent_extra("profiler_source_tech", make_alphanum_or_semver(source_tech)) |
| 724 | + user = ctx.current_user |
| 725 | + logger.debug(f"User: {user}") |
723 | 726 |
|
724 | 727 | # Create appropriate assessment configurator |
725 | | - assessment = create_assessment_configurator(source_system=source_system, product_name="lakebridge", prompts=prompts) |
| 728 | + assessment = create_assessment_configurator(source_system=source_tech, product_name="lakebridge", prompts=prompts) |
726 | 729 | assessment.run() |
727 | 730 |
|
728 | 731 |
|
@@ -960,6 +963,36 @@ def llm_transpile( |
960 | 963 | ) |
961 | 964 |
|
962 | 965 |
|
| 966 | +@lakebridge.command() |
| 967 | +def execute_database_profiler(w: WorkspaceClient, source_tech: str | None = None) -> None: |
| 968 | + """Execute the Profiler Extraction for the given source technology""" |
| 969 | + ctx = ApplicationContext(w) |
| 970 | + ctx.add_user_agent_extra("cmd", "execute-profiler") |
| 971 | + prompts = ctx.prompts |
| 972 | + if source_tech is None: |
| 973 | + source_tech = prompts.choice("Select the source technology", PROFILER_SOURCE_SYSTEM) |
| 974 | + source_tech = source_tech.lower() |
| 975 | + |
| 976 | + if source_tech not in PROFILER_SOURCE_SYSTEM: |
| 977 | + logger.error(f"Only the following source systems are supported: {PROFILER_SOURCE_SYSTEM}") |
| 978 | + raise_validation_exception(f"Invalid source technology {source_tech}") |
| 979 | + |
| 980 | + ctx.add_user_agent_extra("profiler_source_tech", make_alphanum_or_semver(source_tech)) |
| 981 | + user = ctx.current_user |
| 982 | + logger.debug(f"User: {user}") |
| 983 | + # check if cred_file is present which has the connection details before running the profiler |
| 984 | + file = cred_file(PRODUCT_NAME) |
| 985 | + if not file.exists(): |
| 986 | + raise_validation_exception( |
| 987 | + f"Connection details not found. Please run `databricks labs lakebridge configure-database-profiler` " |
| 988 | + f"to set up connection details for {source_tech}." |
| 989 | + ) |
| 990 | + profiler = Profiler.create(source_tech) |
| 991 | + |
| 992 | + # TODO: Add extractor logic to ApplicationContext instead of creating inside the Profiler class |
| 993 | + profiler.profile() |
| 994 | + |
| 995 | + |
963 | 996 | @lakebridge.command() |
964 | 997 | def create_profiler_dashboard( |
965 | 998 | *, |
|
0 commit comments