-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathapp_status.sh
More file actions
executable file
·227 lines (190 loc) · 7.29 KB
/
Copy pathapp_status.sh
File metadata and controls
executable file
·227 lines (190 loc) · 7.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#!/bin/bash
# Check the status of the Databricks App
# Usage: ./app_status.sh [--verbose]
set -e
# Parse command line arguments
VERBOSE=false
if [[ "$1" == "--verbose" ]]; then
VERBOSE=true
echo "🔍 Verbose mode enabled"
fi
# Load environment variables from .env.local if it exists
if [ -f .env.local ]; then
set -a
source .env.local
set +a
fi
# Validate required configuration
if [ -z "$DATABRICKS_APP_NAME" ]; then
echo "❌ DATABRICKS_APP_NAME is not set. Please run ./setup.sh first."
exit 1
fi
if [ -z "$DATABRICKS_AUTH_TYPE" ]; then
echo "❌ DATABRICKS_AUTH_TYPE is not set. Please run ./setup.sh first."
exit 1
fi
if [ "$VERBOSE" = true ] && [ -z "$DBA_SOURCE_CODE_PATH" ]; then
echo "❌ DBA_SOURCE_CODE_PATH is not set. Please run ./setup.sh first."
exit 1
fi
# Handle authentication based on type
echo "🔐 Authenticating with Databricks..."
if [ "$DATABRICKS_AUTH_TYPE" = "pat" ]; then
# PAT Authentication
if [ -z "$DATABRICKS_HOST" ] || [ -z "$DATABRICKS_TOKEN" ]; then
echo "❌ PAT authentication requires DATABRICKS_HOST and DATABRICKS_TOKEN. Please run ./setup.sh first."
exit 1
fi
export DATABRICKS_HOST="$DATABRICKS_HOST"
export DATABRICKS_TOKEN="$DATABRICKS_TOKEN"
# Test connection
if ! databricks current-user me >/dev/null 2>&1; then
echo "❌ PAT authentication failed. Please check your credentials."
exit 1
fi
elif [ "$DATABRICKS_AUTH_TYPE" = "databricks-cli" ]; then
# Profile Authentication
if [ -z "$DATABRICKS_CONFIG_PROFILE" ]; then
echo "❌ Profile authentication requires DATABRICKS_CONFIG_PROFILE. Please run ./setup.sh first."
exit 1
fi
# Test connection
if ! databricks current-user me --profile "$DATABRICKS_CONFIG_PROFILE" >/dev/null 2>&1; then
echo "❌ Profile authentication failed. Please check your profile configuration."
exit 1
fi
else
echo "❌ Invalid DATABRICKS_AUTH_TYPE: $DATABRICKS_AUTH_TYPE. Must be 'pat' or 'databricks-cli'."
exit 1
fi
echo "✅ Databricks authentication successful"
echo ""
# Function to format JSON nicely
format_json() {
python3 -c "
import json, sys
try:
data = json.load(sys.stdin)
print(json.dumps(data, indent=2))
except json.JSONDecodeError:
print('Invalid JSON received')
sys.exit(1)
except Exception as e:
print(f'Error formatting JSON: {e}')
sys.exit(1)
"
}
# Function to extract and display status info
display_status() {
python3 -c "
import json, sys
try:
data = json.load(sys.stdin)
print('📱 App Name: ${DATABRICKS_APP_NAME}')
print('🌐 App URL: ' + data.get('url', 'Not available'))
print('👤 Service Principal: ' + data.get('service_principal_name', 'Not available'))
print('')
# App Status
app_status = data.get('app_status', {})
app_state = app_status.get('state', 'Unknown')
app_message = app_status.get('message', 'No message')
if app_state == 'RUNNING':
print('✅ App Status: RUNNING')
elif app_state == 'UNAVAILABLE':
print('❌ App Status: UNAVAILABLE')
elif app_state == 'STARTING':
print('⏳ App Status: STARTING')
else:
print(f'❓ App Status: {app_state}')
print(f' Message: {app_message}')
print('')
# Compute Status
compute_status = data.get('compute_status', {})
compute_state = compute_status.get('state', 'Unknown')
compute_message = compute_status.get('message', 'No message')
if compute_state == 'ACTIVE':
print('✅ Compute Status: ACTIVE')
elif compute_state == 'INACTIVE':
print('❌ Compute Status: INACTIVE')
elif compute_state == 'STARTING':
print('⏳ Compute Status: STARTING')
else:
print(f'❓ Compute Status: {compute_state}')
print(f' Message: {compute_message}')
print('')
# Additional info
print('ℹ️ Additional Info:')
print(f' Created: {data.get(\"create_time\", \"Unknown\")}')
print(f' Updated: {data.get(\"update_time\", \"Unknown\")}')
print(f' Creator: {data.get(\"creator\", \"Unknown\")}')
print('')
# Verbose mode additional details
if '${VERBOSE}' == 'true':
print('🔍 Verbose Details:')
print(f' Service Principal ID: {data.get(\"service_principal_id\", \"Not available\")}')
print(f' Service Principal Client ID: {data.get(\"service_principal_client_id\", \"Not available\")}')
print(f' OAuth2 App Client ID: {data.get(\"oauth2_app_client_id\", \"Not available\")}')
print(f' OAuth2 App Integration ID: {data.get(\"oauth2_app_integration_id\", \"Not available\")}')
print(f' Budget Policy ID: {data.get(\"effective_budget_policy_id\", \"Not available\")}')
print(f' Default Source Code Path: {data.get(\"default_source_code_path\", \"Not available\")}')
print(f' Updater: {data.get(\"updater\", \"Not available\")}')
# Active deployment info
active_deployment = data.get('active_deployment', {})
if active_deployment:
print(f' Deployment ID: {active_deployment.get(\"deployment_id\", \"Not available\")}')
print(f' Deployment Mode: {active_deployment.get(\"mode\", \"Not available\")}')
deployment_artifacts = active_deployment.get('deployment_artifacts', {})
if deployment_artifacts:
print(f' Deployment Artifacts Path: {deployment_artifacts.get(\"source_code_path\", \"Not available\")}')
print('')
except Exception as e:
print(f'Error parsing app status: {e}')
sys.exit(1)
"
}
# Get app status
echo "🔍 Getting app status for '$DATABRICKS_APP_NAME'..."
echo ""
if [ "$DATABRICKS_AUTH_TYPE" = "databricks-cli" ]; then
APP_JSON=$(databricks apps get "$DATABRICKS_APP_NAME" --profile "$DATABRICKS_CONFIG_PROFILE" --output json 2>/dev/null)
else
APP_JSON=$(databricks apps get "$DATABRICKS_APP_NAME" --output json 2>/dev/null)
fi
if [ $? -ne 0 ] || [ -z "$APP_JSON" ]; then
echo "❌ Failed to get app status for '$DATABRICKS_APP_NAME'"
echo "💡 Make sure the app exists by running: databricks apps list"
exit 1
fi
# Display formatted status
echo "$APP_JSON" | display_status
# Show full JSON and workspace files if verbose
if [ "$VERBOSE" = true ]; then
echo "📄 Full JSON Response:"
echo "$APP_JSON" | format_json
echo ""
echo "📂 Workspace Files ($DBA_SOURCE_CODE_PATH):"
echo ""
if [ "$DATABRICKS_AUTH_TYPE" = "databricks-cli" ]; then
WORKSPACE_LIST=$(databricks workspace list "$DBA_SOURCE_CODE_PATH" --profile "$DATABRICKS_CONFIG_PROFILE" 2>/dev/null)
else
WORKSPACE_LIST=$(databricks workspace list "$DBA_SOURCE_CODE_PATH" 2>/dev/null)
fi
if [ $? -ne 0 ] || [ -z "$WORKSPACE_LIST" ]; then
echo "❌ Failed to list workspace files at '$DBA_SOURCE_CODE_PATH'"
echo "💡 Make sure the path exists and you have access"
else
echo "$WORKSPACE_LIST"
fi
echo ""
fi
# Show helpful commands
echo "💡 Useful commands:"
if [ "$DATABRICKS_AUTH_TYPE" = "databricks-cli" ]; then
echo " List all apps: databricks apps list --profile $DATABRICKS_CONFIG_PROFILE"
echo " View logs: Visit ${DATABRICKS_APP_NAME} URL + /logz in browser"
else
echo " List all apps: databricks apps list"
echo " View logs: Visit ${DATABRICKS_APP_NAME} URL + /logz in browser"
fi
echo " Deploy app: ./deploy.sh"
echo " Create app: ./deploy.sh --create"