Coverage for src/commands/warehouse.py: 39%

18 statements  

« prev     ^ index     » next       coverage.py v7.8.0, created at 2025-06-05 22:56 -0700

1""" 

2Command for showing details of a specific SQL warehouse in Databricks. 

3""" 

4 

5from typing import Optional, Any 

6from src.clients.databricks import DatabricksAPIClient 

7from src.commands.base import CommandResult 

8from src.command_registry import CommandDefinition 

9import logging 

10 

11 

12def handle_command( 

13 client: Optional[DatabricksAPIClient], **kwargs: Any 

14) -> CommandResult: 

15 """ 

16 Fetch and return details of a specific SQL warehouse in the Databricks workspace. 

17 

18 Args: 

19 client: DatabricksAPIClient instance for API calls 

20 **kwargs: Command parameters 

21 - warehouse_id: ID of the warehouse to get details for 

22 

23 Returns: 

24 CommandResult with warehouse details if successful 

25 """ 

26 if not client: 

27 return CommandResult( 

28 False, 

29 message="No Databricks client available. Please set up your workspace first.", 

30 ) 

31 

32 warehouse_id = kwargs.get("warehouse_id") 

33 

34 try: 

35 # Fetch the warehouse details 

36 warehouse = client.get_warehouse(warehouse_id) 

37 

38 if not warehouse: 

39 return CommandResult( 

40 False, message=f"Warehouse with ID '{warehouse_id}' not found." 

41 ) 

42 

43 # Return the full warehouse details 

44 return CommandResult( 

45 True, 

46 data=warehouse, 

47 message=f"Found details for warehouse '{warehouse.get('name')}' (ID: {warehouse_id}).", 

48 ) 

49 except Exception as e: 

50 logging.error(f"Error fetching warehouse details: {str(e)}") 

51 return CommandResult( 

52 False, message=f"Failed to fetch warehouse details: {str(e)}", error=e 

53 ) 

54 

55 

56DEFINITION = CommandDefinition( 

57 name="warehouse", 

58 description="Show details of a specific SQL warehouse in the Databricks workspace.", 

59 handler=handle_command, 

60 parameters={ 

61 "warehouse_id": { 

62 "type": "string", 

63 "description": "ID of the warehouse to get details for.", 

64 } 

65 }, 

66 required_params=["warehouse_id"], 

67 tui_aliases=["/warehouse", "/warehouse-details"], 

68 needs_api_client=True, 

69 visible_to_user=True, 

70 visible_to_agent=True, 

71 usage_hint="Usage: /warehouse --warehouse_id <warehouse_id>", 

72)