-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSetup-DevmodeResources.ps1
More file actions
186 lines (154 loc) Β· 5.48 KB
/
Setup-DevmodeResources.ps1
File metadata and controls
186 lines (154 loc) Β· 5.48 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
<#
.SYNOPSIS
Pre-DEVMODE Resource Setup Script for FLT Testing
.DESCRIPTION
This script creates workspace and lakehouse resources via EDOG metadata API
BEFORE starting DEVMODE. Once resources are created, start DEVMODE and run tests.
.NOTES
Run this BEFORE starting DEVMODE (flt-edog-devmode)
.EXAMPLE
.\Setup-DevmodeResources.ps1 -CreateWorkspace -CreateLakehouse
#>
param(
[switch]$CreateWorkspace,
[switch]$CreateLakehouse,
[string]$WorkspaceName = "devmode-test-ws-$(Get-Date -Format 'yyyyMMdd-HHmmss')",
[string]$LakehouseName = "devmode-test-lh-$(Get-Date -Format 'yyyyMMdd-HHmmss')",
[string]$ConfigPath = "$PSScriptRoot\edog-config.json"
)
$ErrorActionPreference = "Stop"
# EDOG Configuration
$EdogEndpoint = "https://edog.pbidedicated.windows-int.net"
$TokenCachePath = "$PSScriptRoot\.edog-token-cache"
function Get-EdogToken {
if (-not (Test-Path $TokenCachePath)) {
throw "Token cache not found at $TokenCachePath. Run the edog authentication first."
}
$encoded = Get-Content $TokenCachePath -Raw
$decoded = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($encoded))
$parts = $decoded -split '\|'
return $parts[1]
}
function Get-EdogConfig {
if (-not (Test-Path $ConfigPath)) {
throw "Config not found at $ConfigPath"
}
return Get-Content $ConfigPath | ConvertFrom-Json
}
function Test-DevmodeRunning {
# Check if DEVMODE might be intercepting traffic by testing a metadata endpoint
$token = Get-EdogToken
$headers = @{
"Authorization" = "Bearer $token"
"Content-Type" = "application/json"
}
try {
# This endpoint should return something if DEVMODE is NOT running
# If DEVMODE is running, it will return 404
$response = Invoke-RestMethod -Uri "$EdogEndpoint/metadata/folders" -Headers $headers -Method Get -ErrorAction Stop
return $false # Metadata works, DEVMODE not intercepting
} catch {
if ($_.Exception.Response.StatusCode -eq 'NotFound') {
return $true # 404 means DEVMODE is intercepting
}
# Other errors might be auth issues
return $false
}
}
function New-Workspace {
param(
[string]$Name,
[string]$CapacityId
)
$token = Get-EdogToken
$headers = @{
"Authorization" = "Bearer $token"
"Content-Type" = "application/json"
}
$body = @{
capacityObjectId = $CapacityId
displayName = $Name
description = "Auto-created workspace for DEVMODE testing"
isServiceApp = $false
datasetStorageMode = 1
} | ConvertTo-Json
Write-Host "Creating workspace '$Name' on capacity $CapacityId..."
$response = Invoke-RestMethod -Uri "$EdogEndpoint/metadata/folders" -Headers $headers -Method Post -Body $body -ErrorAction Stop
Write-Host " β
Workspace created: $($response.objectId)"
return $response.objectId
}
function New-Lakehouse {
param(
[string]$Name,
[string]$WorkspaceId
)
$token = Get-EdogToken
$headers = @{
"Authorization" = "Bearer $token"
"Content-Type" = "application/json"
}
$body = @{
displayName = $Name
description = "Auto-created lakehouse for DEVMODE testing"
workloadPayload = '{"enableSchemas":true}'
} | ConvertTo-Json
Write-Host "Creating lakehouse '$Name' in workspace $WorkspaceId..."
$url = "$EdogEndpoint/metadata/workspaces/$WorkspaceId/artifacts?artifactType=Lakehouse"
$response = Invoke-RestMethod -Uri $url -Headers $headers -Method Post -Body $body -ErrorAction Stop
Write-Host " β
Lakehouse created: $($response.objectId)"
return $response.objectId
}
# Main execution
Write-Host "=" * 60
Write-Host "DEVMODE Resource Setup Script"
Write-Host "=" * 60
Write-Host ""
# Check if DEVMODE is running
Write-Host "Checking if DEVMODE is running..."
if (Test-DevmodeRunning) {
Write-Host " β οΈ WARNING: DEVMODE appears to be running!"
Write-Host " Metadata API calls will fail."
Write-Host " Please STOP DEVMODE first, then run this script."
Write-Host ""
$continue = Read-Host "Continue anyway? (y/N)"
if ($continue -ne 'y') {
exit 1
}
} else {
Write-Host " β
DEVMODE not detected - metadata API accessible"
}
Write-Host ""
# Load config
$config = Get-EdogConfig
Write-Host "Loaded config:"
Write-Host " FLT Repo: $($config.flt_repo_path)"
Write-Host " Capacity: $($config.capacity_id)"
Write-Host " Current Workspace: $($config.workspace_id)"
Write-Host " Current Lakehouse: $($config.artifact_id)"
Write-Host ""
$newWorkspaceId = $null
$newLakehouseId = $null
if ($CreateWorkspace) {
$newWorkspaceId = New-Workspace -Name $WorkspaceName -CapacityId $config.capacity_id
}
if ($CreateLakehouse) {
$targetWorkspaceId = if ($newWorkspaceId) { $newWorkspaceId } else { $config.workspace_id }
$newLakehouseId = New-Lakehouse -Name $LakehouseName -WorkspaceId $targetWorkspaceId
}
# Output results
Write-Host ""
Write-Host "=" * 60
Write-Host "Setup Complete!"
Write-Host "=" * 60
Write-Host ""
if ($newWorkspaceId) {
Write-Host "New Workspace ID: $newWorkspaceId"
}
if ($newLakehouseId) {
Write-Host "New Lakehouse ID: $newLakehouseId"
}
Write-Host ""
Write-Host "Next steps:"
Write-Host "1. Update edog-config.json with new IDs (if needed)"
Write-Host "2. Start DEVMODE: .\start-edog.ps1"
Write-Host "3. Run tests against the new resources"