11module AzManagers
22
3- using AzSessions, Base64, CodecZlib, Dates, Distributed, HTTP, JSON, JSONWebTokens , LibCURL, LibGit2, Logging, Pkg, Printf, Random, Serialization, Sockets, TOML
3+ using AzSessions, Base64, CodecZlib, Dates, Distributed, HTTP, JSON, JWTs , LibCURL, LibGit2, Logging, Pkg, Printf, Random, Serialization, Sockets, TOML
44
55function logerror (e, loglevel= Logging. Info)
66 io = IOBuffer ()
@@ -37,7 +37,7 @@ function write_manifest(;
3737 manifest = Dict (" resourcegroup" => resourcegroup, " subscriptionid" => subscriptionid, " ssh_user" => ssh_user, " ssh_private_key_file" => ssh_private_key_file, " ssh_public_key_file" => ssh_public_key_file)
3838 try
3939 isdir (manifestpath ()) || mkdir (manifestpath (); mode= 0o700 )
40- write (manifestfile (), json (manifest, 1 ))
40+ write (manifestfile (), JSON . json (manifest, 1 ))
4141 chmod (manifestfile (), 0o600 )
4242 catch e
4343 @error " Failed to write manifest file, $(AzManagers. manifestfile ()) "
866866function Distributed. addprocs (template:: AbstractString , n:: Int ; kwargs... )
867867 isfile (templates_filename_scaleset ()) || error (" scale-set template file does not exist. See `AzManagers.save_template_scaleset`" )
868868
869- templates_scaleset = JSON. parse (read (templates_filename_scaleset (), String))
869+ templates_scaleset = JSON. parse (read (templates_filename_scaleset (), String); dicttype = Dict )
870870 haskey (templates_scaleset, template) || error (" scale-set template file does not contain a template with name: $template . See `AzManagers.save_template_scaleset`" )
871871
872872 addprocs (templates_scaleset[template], n; kwargs... )
@@ -1313,7 +1313,7 @@ function azure_worker_init(cookie, master_address, master_port, ppi, exeflags, m
13131313 " mpi_size" => mpi_size,
13141314 " physical_hostname" => azure_physical_name ()))
13151315
1316- _vm = base64encode (json (vm))
1316+ _vm = base64encode (JSON . json (vm))
13171317
13181318 nbytes_written = write (c, _vm* " \n " )
13191319 nbytes_written == length (_vm)+ 1 || error (" wrote wrong number of bytes" )
@@ -2235,7 +2235,7 @@ function resourcegraphrequest(manager, body)
22352235 manager. verbose,
22362236 " https://management.azure.com/providers/Microsoft.ResourceGraph/resources?api-version=2021-03-01" ,
22372237 [" Authorization" => " Bearer $(token (manager. session)) " , " Content-Type" => " application/json" ],
2238- json (body)
2238+ JSON . json (body)
22392239 )
22402240 r = JSON. parse (String (_r. body))
22412241 data = [data;get (r, " data" , [])]
@@ -2345,7 +2345,7 @@ function scaleset_capacity!(manager::AzManager, subscriptionid, resourcegroup, s
23452345 verbose,
23462346 " https://management.azure.com/subscriptions/$subscriptionid /resourceGroups/$resourcegroup /providers/Microsoft.Compute/virtualMachineScaleSets/$scalesetname ?api-version=2023-03-01" ,
23472347 [" Authorization" => " Bearer $(token (manager. session)) " , " Content-Type" => " application/json" ],
2348- json (Dict (" sku" => Dict (" capacity" => capacity))))
2348+ JSON . json (Dict (" sku" => Dict (" capacity" => capacity))))
23492349end
23502350
23512351function scaleset_create_or_update (manager:: AzManager , user, subscriptionid, resourcegroup, scalesetname, sigimagename, sigimageversion,
@@ -2373,8 +2373,7 @@ function scaleset_create_or_update(manager::AzManager, user, subscriptionid, res
23732373 _template[" properties" ][" virtualMachineProfile" ][" storageProfile" ][" osDisk" ][" diskSizeGB" ] = osdisksize
23742374
23752375 _t = token (manager. session)
2376- _e = JSONWebTokens. None ()
2377- _decoded = JSONWebTokens. decode (_e, _t)
2376+ _decoded = claims (JWT (;jwt= _t))
23782377 if haskey (_decoded, " unique_name" )
23792378 _user = _decoded[" unique_name" ]
23802379
@@ -2469,7 +2468,7 @@ function scaleset_create_or_update(manager::AzManager, user, subscriptionid, res
24692468 verbose,
24702469 " https://management.azure.com/subscriptions/$subscriptionid /resourceGroups/$resourcegroup /providers/Microsoft.Compute/virtualMachineScaleSets/$scalesetname ?api-version=2023-03-01" ,
24712470 [" Content-type" => " application/json" , " Authorization" => " Bearer $(token (manager. session)) " ],
2472- String (json (_template)))
2471+ String (JSON . json (_template)))
24732472
24742473 if manager. show_quota
24752474 @info " Quota after requesting that the scale-set is created or grows" remaining_resource (_r)
@@ -2485,7 +2484,7 @@ function delete_vms(manager::AzManager, subscriptionid, resourcegroup, scalesetn
24852484 verbose,
24862485 " https://management.azure.com/subscriptions/$subscriptionid /resourceGroups/$resourcegroup /providers/Microsoft.Compute/virtualMachineScaleSets/$scalesetname /delete?forceDeletion=True&api-version=2023-07-01" ,
24872486 [" Content-Type" => " application/json" , " Authorization" => " Bearer $(token (manager. session)) " ],
2488- json (body))
2487+ JSON . json (body))
24892488
24902489 if manager. show_quota
24912490 @info " Quota after requesting deletion of $(length (ids)) virtual machines" remaining_resource (_r)
@@ -2627,7 +2626,7 @@ function detachedrun(request::HTTP.Request)
26272626 r = JSON. parse (String (HTTP. payload (request)))
26282627
26292628 if ! haskey (r, " code" )
2630- return HTTP. Response (400 , [" Content-Type" => " application/json" ], json (Dict (" error" => " Malformed body: JSON body must contain the key: code" )); request)
2629+ return HTTP. Response (400 , [" Content-Type" => " application/json" ], JSON . json (Dict (" error" => " Malformed body: JSON body must contain the key: code" )); request)
26312630 end
26322631
26332632 exename = get (r, " exename" , " julia" )
@@ -2652,7 +2651,7 @@ function detachedrun(request::HTTP.Request)
26522651 end
26532652 end
26542653 if length (codelines) == 0
2655- return HTTP. Response (400 , [" Content-Type" => " application/json" ], json (Dict (" error" => " No code to execute, missing end?" , " code" => code)); request)
2654+ return HTTP. Response (400 , [" Content-Type" => " application/json" ], JSON . json (Dict (" error" => " No code to execute, missing end?" , " code" => code)); request)
26562655 end
26572656
26582657 code = join (codelines, " \n " )
@@ -2712,7 +2711,7 @@ function detachedrun(request::HTTP.Request)
27122711 catch e
27132712 io = IOBuffer ()
27142713 logerror (e, Logging. Warn)
2715- return HTTP. Response (500 , [" Content-Type" => " application/json" ], json (Dict (" error" => String (take! (io)))); request)
2714+ return HTTP. Response (500 , [" Content-Type" => " application/json" ], JSON . json (Dict (" error" => String (take! (io)))); request)
27162715 end
27172716
27182717 Threads. @spawn begin
@@ -2725,7 +2724,7 @@ function detachedrun(request::HTTP.Request)
27252724 rmproc (vm; session= sessionbundle (:management ))
27262725 end
27272726 end
2728- HTTP. Response (200 , [" Content-Type" => " application/json" ], json (Dict (" id" => id, " pid" => pid)); request)
2727+ HTTP. Response (200 , [" Content-Type" => " application/json" ], JSON . json (Dict (" id" => id, " pid" => pid)); request)
27292728end
27302729
27312730function detachedkill (request:: HTTP.Request )
@@ -2778,9 +2777,9 @@ function detachedstatus(request::HTTP.Request)
27782777 status = " starting"
27792778 end
27802779 catch e
2781- return HTTP. Response (500 , [" Content-Type" => " application/json" ], json (Dict (" error" => show (e), " trace" => show (stacktrace ()))); request)
2780+ return HTTP. Response (500 , [" Content-Type" => " application/json" ], JSON . json (Dict (" error" => show (e), " trace" => show (stacktrace ()))); request)
27822781 end
2783- HTTP. Response (200 , [" Content-Type" => " application/json" ], json (Dict (" id" => id, " status" => status)); request)
2782+ HTTP. Response (200 , [" Content-Type" => " application/json" ], JSON . json (Dict (" id" => id, " status" => status)); request)
27842783end
27852784
27862785function detachedstdout (request:: HTTP.Request )
@@ -2857,7 +2856,7 @@ function detachedwait(request::HTTP.Request)
28572856 end
28582857 write (io, " \n " )
28592858
2860- return HTTP. Response (400 , [" Content-Type" => " application/json" ], json (Dict (" error" => String (take! (io)))); request)
2859+ return HTTP. Response (400 , [" Content-Type" => " application/json" ], JSON . json (Dict (" error" => String (take! (io)))); request)
28612860 end
28622861 HTTP. Response (200 , [" Content-Type" => " application/text" ], " OK, job $id is finished" ; request)
28632862end
@@ -2867,7 +2866,7 @@ function detachedping(request::HTTP.Request)
28672866end
28682867
28692868function detachedvminfo (request:: HTTP.Request )
2870- HTTP. Response (200 , [" Content-Type" => " application/json" ], json (AzManagers. DETACHED_VM[]); request)
2869+ HTTP. Response (200 , [" Content-Type" => " application/json" ], JSON . json (AzManagers. DETACHED_VM[]); request)
28712870end
28722871
28732872#
@@ -2974,7 +2973,7 @@ function addproc(vm_template::Dict, nic_template=nothing;
29742973 verbose,
29752974 " https://management.azure.com/subscriptions/$subscriptionid /resourceGroups/$resourcegroup /providers/Microsoft.Network/networkInterfaces/$nicname ?api-version=2022-09-01" ,
29762975 [" Content-Type" => " application/json" , " Authorization" => " Bearer $(token (session)) " ],
2977- String (json (nic_template)))
2976+ String (JSON . json (nic_template)))
29782977
29792978 sleep (5 )
29802979
@@ -3077,7 +3076,7 @@ function addproc(vm_template::Dict, nic_template=nothing;
30773076 verbose,
30783077 " https://management.azure.com/subscriptions/$subscriptionid /resourceGroups/$resourcegroup /providers/Microsoft.Compute/virtualMachines/$vmname ?api-version=2023-09-01" ,
30793078 [" Content-Type" => " application/json" , " Authorization" => " Bearer $(token (session)) " ],
3080- String (json (vm_template[" value" ])))
3079+ String (JSON . json (vm_template[" value" ])))
30813080
30823081 spincount = 1
30833082 starttime = tic = time ()
@@ -3137,7 +3136,7 @@ end
31373136
31383137function addproc (vm_template:: AbstractString , nic_template= nothing ; kwargs... )
31393138 isfile (templates_filename_vm ()) || error (" if vm_template is a string, then the file $(templates_filename_vm ()) must exist. See AzManagers.save_template_vm." )
3140- vm_templates = JSON. parse (read (templates_filename_vm (), String))
3139+ vm_templates = JSON. parse (read (templates_filename_vm (), String); dicttype = Dict )
31413140 vm_template = vm_templates[vm_template]
31423141
31433142 addproc (vm_template, nic_template; kwargs... )
@@ -3398,7 +3397,7 @@ function detached_run(code, ip::String="", port=detached_port();
33983397 " POST" ,
33993398 " http://$(vm[" ip" ]) :$(vm[" port" ]) /cofii/detached/run" ,
34003399 [" Content-Type" => " application/json" ],
3401- json (body))
3400+ JSON . json (body))
34023401 r = JSON. parse (String (_r. body))
34033402
34043403 @info " detached job id is $(r[" id" ]) at $(vm[" name" ]) ,$(vm[" ip" ]) :$(vm[" port" ]) "
0 commit comments