Skip to content

Commit 13b57d7

Browse files
committed
Drop Broker.scope; read directly from server-config.
Now that ServerConfig itself carries the scope, the Broker class doesn't need its own field/getter — it's just indirection. Internal call sites read server-config.scope directly. Also tightens the FleetFile reader's legacy-format path to attach scope to every server entry (not just the broker's), so migrating-from brokers and the very-legacy no-broker-entry fallback are consistent in memory. Both still mutate broker configs in place; same TODO as init() about cloning with-scope as the proper fix.
1 parent e7f5e72 commit 13b57d7

2 files changed

Lines changed: 33 additions & 37 deletions

File tree

src/cli/broker.toit

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,6 @@ Manages devices that have an Artemis service running on them.
6767
*/
6868
class Broker:
6969
fleet-id/Uuid
70-
/**
71-
The $Scope to use when talking to this broker.
72-
73-
Carried over from the fleet file's per-server scope entry.
74-
*/
75-
scope/Scope
7670
server-config/ServerConfig
7771
cli_/Cli
7872
network_/net.Client? := null
@@ -88,7 +82,6 @@ class Broker:
8882

8983
constructor
9084
--.fleet-id/Uuid
91-
--.scope/Scope
9285
--.server-config
9386
--cli/Cli
9487
--tmp-directory/string
@@ -137,7 +130,8 @@ class Broker:
137130
return error.contains "duplicate key value" or error.contains "already exists"
138131

139132
/**
140-
Uploads the given $pod to the broker for the given $fleet-id under $scope.
133+
Uploads the given $pod to the broker for the given $fleet-id under the
134+
broker's configured scope.
141135
142136
Also uploads the trivial patches.
143137
*/
@@ -149,25 +143,25 @@ class Broker:
149143
// Only upload if we don't have it in our cache.
150144
key := cache-key-pod-parts
151145
--broker-config=server-config
152-
--scope=scope
146+
--scope=server-config.scope
153147
--part-id=id
154148
cli_.cache.get-file-path key: | store/FileStore |
155149
broker-connection_.pod-registry-upload-pod-part contents --part-id=id
156-
--scope=scope
150+
--scope=server-config.scope
157151
store.save contents
158152
key := cache-key-pod-manifest
159153
--broker-config=server-config
160-
--scope=scope
154+
--scope=server-config.scope
161155
--pod-id=pod.id
162156
cli_.cache.get-file-path key: | store/FileStore |
163157
encoded := ubjson.encode manifest
164158
broker-connection_.pod-registry-upload-pod-manifest encoded --pod-id=pod.id
165-
--scope=scope
159+
--scope=server-config.scope
166160
store.save encoded
167161

168162
description-ids := broker-connection_.pod-registry-descriptions
169163
--fleet-id=fleet-id
170-
--scope=scope
164+
--scope=server-config.scope
171165
--names=[pod.name]
172166
--create-if-absent
173167

@@ -210,7 +204,7 @@ class Broker:
210204
upload-patch_ it
211205

212206
/**
213-
Uploads the given $patch to the broker under the configured $scope.
207+
Uploads the given $patch to the broker.
214208
*/
215209
upload-patch_ patch/FirmwarePatch:
216210
diff-and-upload_ patch
@@ -223,12 +217,12 @@ class Broker:
223217
trivial-id := id_ --to=patch.to_
224218
cache-key := cache-key-patch
225219
--broker-config=server-config
226-
--scope=scope
220+
--scope=server-config.scope
227221
--patch-id=trivial-id
228222
cli_.cache.get cache-key: | store/FileStore |
229223
trivial := build-trivial-patch patch.bits_
230224
broker-connection_.upload-firmware trivial
231-
--scope=scope
225+
--scope=server-config.scope
232226
--firmware-id=trivial-id
233227
store.save-via-writer: | writer/io.Writer |
234228
trivial.do: writer.write it
@@ -240,12 +234,12 @@ class Broker:
240234
old-id := id_ --to=patch.from_
241235
cache-key = cache-key-patch
242236
--broker-config=server-config
243-
--scope=scope
237+
--scope=server-config.scope
244238
--patch-id=old-id
245239
trivial-old := cli_.cache.get cache-key: | store/FileStore |
246240
downloaded := null
247241
catch: downloaded = broker-connection_.download-firmware
248-
--scope=scope
242+
--scope=server-config.scope
249243
--id=old-id
250244
if not downloaded:
251245
cli_.ui.emit --warning "Failed to download old firmware for patch $old-id -> $trivial-id."
@@ -269,7 +263,7 @@ class Broker:
269263
diff-id := id_ --from=patch.from_ --to=patch.to_
270264
cache-key = cache-key-patch
271265
--broker-config=server-config
272-
--scope=scope
266+
--scope=server-config.scope
273267
--patch-id=diff-id
274268
cli_.cache.get cache-key: | store/FileStore |
275269
// Build the diff and verify that we can apply it and get the
@@ -284,7 +278,7 @@ class Broker:
284278
to64 := base64.encode patch.to_ --url-mode
285279
cli_.ui.emit --info "Uploading patch $from64 -> $to64 ($diff-size)."
286280
broker-connection_.upload-firmware diff
287-
--scope=scope
281+
--scope=server-config.scope
288282
--firmware-id=diff-id
289283
store.save-via-writer: | writer/io.Writer |
290284
diff.do: writer.write it
@@ -307,19 +301,19 @@ class Broker:
307301
is-cached --pod-id/Uuid -> bool:
308302
manifest-key := cache-key-pod-manifest
309303
--broker-config=server-config
310-
--scope=scope
304+
--scope=server-config.scope
311305
--pod-id=pod-id
312306
return cli_.cache.contains manifest-key
313307

314308
download --pod-id/Uuid -> Pod:
315309
manifest-key := cache-key-pod-manifest
316310
--broker-config=server-config
317-
--scope=scope
311+
--scope=server-config.scope
318312
--pod-id=pod-id
319313
encoded-manifest := cli_.cache.get manifest-key: | store/FileStore |
320314
bytes := broker-connection_.pod-registry-download-pod-manifest
321315
--pod-id=pod-id
322-
--scope=scope
316+
--scope=server-config.scope
323317
store.save bytes
324318
manifest := ubjson.decode encoded-manifest
325319
return Pod.from-manifest
@@ -328,12 +322,12 @@ class Broker:
328322
--download=: | part-id/string |
329323
key := cache-key-pod-parts
330324
--broker-config=server-config
331-
--scope=scope
325+
--scope=server-config.scope
332326
--part-id=part-id
333327
cli_.cache.get key: | store/FileStore |
334328
bytes := broker-connection_.pod-registry-download-pod-part
335329
part-id
336-
--scope=scope
330+
--scope=server-config.scope
337331
store.save bytes
338332

339333
list-pods --names/List -> Map:
@@ -343,7 +337,7 @@ class Broker:
343337
else:
344338
descriptions = broker-connection_.pod-registry-descriptions
345339
--fleet-id=fleet-id
346-
--scope=scope
340+
--scope=server-config.scope
347341
--names=names
348342
--no-create-if-absent
349343
result := {:}
@@ -355,7 +349,7 @@ class Broker:
355349
delete --description-names/List:
356350
descriptions := broker-connection_.pod-registry-descriptions
357351
--fleet-id=fleet-id
358-
--scope=scope
352+
--scope=server-config.scope
359353
--names=description-names
360354
--no-create-if-absent
361355
unknown-pod-descriptions := []
@@ -424,7 +418,7 @@ class Broker:
424418

425419
descriptions := broker-connection_.pod-registry-descriptions
426420
--fleet-id=fleet-id
427-
--scope=scope
421+
--scope=server-config.scope
428422
--names=names.to-list
429423
--no-create-if-absent
430424

src/cli/fleet.toit

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,12 @@ class FleetFile:
200200
ui.abort "Fleet file '$path' is missing 'scope' on broker server '$broker-name'."
201201
organization-id = broker-server.scope.as-uuid
202202
else:
203-
// Legacy format: pin the top-level organization-id onto the
204-
// broker server entry so the new in-memory shape is consistent.
205-
broker-server.scope = Scope.from-organization-id organization-id
203+
// Legacy format: the top-level organization-id was the same for
204+
// every server. Pin it onto every entry so the new in-memory
205+
// shape is consistent.
206+
legacy-scope := Scope.from-organization-id organization-id
207+
servers.do --values: | server-config/ServerConfig |
208+
server-config.scope = legacy-scope
206209

207210
if migrating-from-entry:
208211
if migrating-from-entry is not List:
@@ -217,6 +220,11 @@ class FleetFile:
217220
if migrating-from-entry or servers-entry:
218221
ui.abort "Fleet file '$path' has invalid format for 'broker', 'migrating-from' and 'servers'."
219222
broker-name = default-broker-config.name
223+
// Very-legacy fleet file with no broker/servers entry. Attach the
224+
// legacy top-level organization-id to the default broker config.
225+
// TODO: avoid mutating the default broker config (shared with the
226+
// global CLI config); clone with scope set instead.
227+
default-broker-config.scope = Scope.from-organization-id organization-id
220228
servers = {
221229
default-broker-config.name: default-broker-config,
222230
}
@@ -415,7 +423,6 @@ class Fleet:
415423
broker = Broker
416424
--server-config=fleet-file.broker-config
417425
--fleet-id=id
418-
--scope=broker-scope
419426
--tmp-directory=artemis.tmp-directory
420427
--short-strings=short-strings
421428
--cli=cli
@@ -770,7 +777,6 @@ class FleetWithDevices extends Fleet:
770777
--server-config=server-config
771778
--short-strings=device-short-strings_
772779
--fleet-id=id
773-
--scope=broker-scope
774780
--tmp-directory=artemis.tmp-directory
775781
--cli=cli_
776782
old-broker.update --device-id=device-id --pod=pod
@@ -814,7 +820,6 @@ class FleetWithDevices extends Fleet:
814820
--server-config=server-config
815821
--short-strings=device-short-strings_
816822
--fleet-id=id
817-
--scope=broker-scope
818823
--tmp-directory=artemis.tmp-directory
819824
--cli=cli_
820825
// We could filter out devices that were already known in the new broker, but
@@ -908,7 +913,6 @@ class FleetWithDevices extends Fleet:
908913
Broker
909914
--server-config=config
910915
--fleet-id=id
911-
--scope=broker-scope
912916
--short-strings=device-short-strings_
913917
--cli=cli_
914918
--tmp-directory=artemis.tmp-directory
@@ -1132,7 +1136,6 @@ class FleetWithDevices extends Fleet:
11321136
--server-config=new-broker-config
11331137
--short-strings=device-short-strings_
11341138
--fleet-id=id
1135-
--scope=broker-scope
11361139
--tmp-directory=artemis.tmp-directory
11371140
--cli=cli_
11381141

@@ -1187,7 +1190,6 @@ class FleetWithDevices extends Fleet:
11871190
--server-config=fleet-file.servers[name]
11881191
--short-strings=device-short-strings_
11891192
--fleet-id=id
1190-
--scope=broker-scope
11911193
--tmp-directory=artemis.tmp-directory
11921194
--cli=cli_
11931195
current-detailed-devices := current-broker.get-devices --device-ids=device-ids

0 commit comments

Comments
 (0)