@serve.zone/interfaces 32.33.0 → 32.35.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -29,6 +29,12 @@ import { isClusterNodeId } from '../private/nodeidentifier.js';
29
29
  * answers the plan (`ICorestoreLegacyResourceAdoptionPlanEntry[]`).
30
30
  * 3. The operator stops Corestore and runs its `legacy-resource-adoption` migration with that plan.
31
31
  * Until then Corestore refuses the binding, which reports `legacy-adoption-pending`.
32
+ *
33
+ * A resource is adopted by a binding of the service that owns it, or, when the selection names a
34
+ * `successorServiceId`, by a binding of that successor: a fresh service of the same organization
35
+ * that replaces the legacy one and takes over its data. The successor's binding records the legacy
36
+ * owner as `corestoreLegacyAdoption.legacyServiceId`, and the plan entry carries the successor, so
37
+ * Corestore moves the resource from the legacy owner's manifest entry to the successor's binding.
32
38
  */
33
39
 
34
40
  export type TCorestoreLegacyCapability = 'database' | 'objectstorage';
@@ -100,21 +106,30 @@ export type TClusterCorestoreLegacyResourceInventory =
100
106
  errorCode: 'CORESTORE_ENDPOINT_UNKNOWN' | 'CORESTORE_UNREACHABLE';
101
107
  };
102
108
 
103
- /** One resource an administrator selects for adoption. */
109
+ /**
110
+ * One resource an administrator selects for adoption: the legacy resource `serviceId` owns of
111
+ * `capability`. Without `successorServiceId` a binding of `serviceId` adopts it; with it, a binding of
112
+ * that other service does, which must be a greenfield service of the same organization.
113
+ */
104
114
  export interface ICorestoreLegacyResourceSelection {
105
115
  serviceId: string;
106
116
  capability: TCorestoreLegacyCapability;
117
+ /** The service whose binding adopts the resource, when it is not `serviceId`; never `serviceId`. */
118
+ successorServiceId?: string;
107
119
  }
108
120
 
109
121
  /**
110
122
  * One entry of Corestore's offline adoption plan, exactly the object its
111
- * `legacy-resource-adoption` migration reads: the service, the capability and the binding that may
112
- * adopt its legacy resource. The legacy identity is Corestore's own and is not restated here.
123
+ * `legacy-resource-adoption` migration reads: the service that owns the legacy resource, the
124
+ * capability, the binding that may adopt it and, when that binding belongs to another service, that
125
+ * successor service. The legacy identity is Corestore's own and is not restated here.
113
126
  */
114
127
  export interface ICorestoreLegacyResourceAdoptionPlanEntry {
115
128
  serviceId: string;
116
129
  capability: TCorestoreLegacyCapability;
117
130
  bindingId: string;
131
+ /** The service `bindingId` belongs to, when it is not `serviceId`; never `serviceId`. */
132
+ successorServiceId?: string;
118
133
  }
119
134
 
120
135
  /**
@@ -126,9 +141,17 @@ export interface ICorestoreLegacyResourceAdoptionPlanEntry {
126
141
  * - `legacy-resource-blocked`: a selected resource is unadopted with a blocker;
127
142
  * - `legacy-resource-authorized-elsewhere`: a selected resource is authorized for a binding Cloudly
128
143
  * does not hold as that resource's adoption;
129
- * - `service-absent`: Cloudly has no such service;
130
- * - `binding-exists`: the service already has a binding of that capability that adopts nothing,
131
- * or adopts another resource.
144
+ * - `legacy-resource-adopted-elsewhere`: Cloudly already holds a binding of another service as a
145
+ * selected resource's adoption;
146
+ * - `service-absent`: Cloudly has no such service, legacy owner or successor;
147
+ * - `binding-exists`: the adopting service already has a binding of that capability that adopts
148
+ * nothing, or adopts another resource;
149
+ * - `successor-organization-mismatch`: the successor belongs to another organization than the
150
+ * legacy owner, or either names none;
151
+ * - `successor-not-greenfield`: the successor is not an immutable-deployment service (it deploys on
152
+ * push, or does not require an immutable image);
153
+ * - `successor-owns-legacy-resource`: the successor owns a legacy resource of that capability
154
+ * itself, which Corestore would keep beside the adopted one.
132
155
  */
133
156
  export type TCorestoreLegacyAdoptionRefusal =
134
157
  | 'legacy-inventory-unreachable'
@@ -136,8 +159,12 @@ export type TCorestoreLegacyAdoptionRefusal =
136
159
  | 'legacy-resource-absent'
137
160
  | 'legacy-resource-blocked'
138
161
  | 'legacy-resource-authorized-elsewhere'
162
+ | 'legacy-resource-adopted-elsewhere'
139
163
  | 'service-absent'
140
- | 'binding-exists';
164
+ | 'binding-exists'
165
+ | 'successor-organization-mismatch'
166
+ | 'successor-not-greenfield'
167
+ | 'successor-owns-legacy-resource';
141
168
 
142
169
  /** The named refusal of `adoptCorestoreLegacyResources`, sent as `TypedResponseError.errorData`. */
143
170
  export interface ICorestoreLegacyAdoptionErrorData {
@@ -327,7 +354,29 @@ export const computeClusterCorestoreLegacyResourceInventorySha256 = async (
327
354
  const selectionKey = (entryArg: { serviceId: string; capability: string }): string =>
328
355
  `${entryArg.serviceId}\u0000${entryArg.capability}`;
329
356
 
330
- /** Validates an administrator's selection: 1..4096 exact entries, sorted by service then capability. */
357
+ /** The service capability whose binding adopts the entry's resource: the successor's, or the owner's. */
358
+ const adoptingKey = (entryArg: { serviceId: string; capability: string; successorServiceId?: string }): string =>
359
+ selectionKey({ serviceId: entryArg.successorServiceId ?? entryArg.serviceId, capability: entryArg.capability });
360
+
361
+ /**
362
+ * Whether an entry has exactly `baseKeysArg`, and `successorServiceId` at most: `shape` when not,
363
+ * `successor` when its successor is not a canonical identifier other than its `serviceId`.
364
+ */
365
+ const successorShape = (
366
+ entryArg: Record<string, unknown>,
367
+ baseKeysArg: readonly string[],
368
+ ): 'exact' | 'shape' | 'successor' => {
369
+ if (!hasExactKeys(entryArg, baseKeysArg, ['successorServiceId'])) return 'shape';
370
+ return !Object.keys(entryArg).includes('successorServiceId')
371
+ || (isIdentifier(entryArg.successorServiceId) && entryArg.successorServiceId !== entryArg.serviceId)
372
+ ? 'exact'
373
+ : 'successor';
374
+ };
375
+
376
+ /**
377
+ * Validates an administrator's selection: 1..4096 exact entries, sorted by service then capability,
378
+ * and no service capability adopting twice, whether as legacy owner or as successor.
379
+ */
331
380
  export const validateCorestoreLegacyResourceSelections = (
332
381
  valueArg: unknown,
333
382
  pathArg = 'corestore legacy resource selection',
@@ -338,24 +387,36 @@ export const validateCorestoreLegacyResourceSelections = (
338
387
  }
339
388
  const errors: string[] = [];
340
389
  let previous: string | undefined;
390
+ const adopting = new Set<string>();
341
391
  for (const [index, entry] of valueArg.entries()) {
342
- if (!isPlainRecord(entry) || !hasExactKeys(entry, ['serviceId', 'capability'])
343
- || !isIdentifier(entry.serviceId) || !isCapability(entry.capability)) {
392
+ const shape = isPlainRecord(entry) ? successorShape(entry, ['serviceId', 'capability']) : 'shape';
393
+ if (shape === 'shape' || !isIdentifier((entry as Record<string, unknown>).serviceId)
394
+ || !isCapability((entry as Record<string, unknown>).capability)) {
344
395
  errors.push(`${pathArg}[${index}] must be an exact { serviceId, capability }`);
345
396
  continue;
346
397
  }
347
- const key = selectionKey(entry as unknown as ICorestoreLegacyResourceSelection);
398
+ if (shape === 'successor') {
399
+ errors.push(`${pathArg}[${index}] successorServiceId must name another service`);
400
+ continue;
401
+ }
402
+ const selection = entry as ICorestoreLegacyResourceSelection;
403
+ const key = selectionKey(selection);
348
404
  if (previous !== undefined && compareWireTokens(previous, key) >= 0) {
349
405
  errors.push(`${pathArg} must be sorted by serviceId then capability without repeats`);
350
406
  }
351
407
  previous = key;
408
+ if (adopting.has(adoptingKey(selection))) {
409
+ errors.push(`${pathArg}[${index}] adopts into a service capability another entry adopts into`);
410
+ }
411
+ adopting.add(adoptingKey(selection));
352
412
  }
353
413
  return errors;
354
414
  };
355
415
 
356
416
  /**
357
417
  * Validates an adoption plan by the rules Corestore's migration applies: a non-empty array of at
358
- * most 4096 exact `{ serviceId, capability, bindingId }` entries, canonical identifiers, and no
418
+ * most 4096 exact `{ serviceId, capability, bindingId }` entries, each with `successorServiceId`
419
+ * when it names another service, canonical identifiers, and no legacy service capability, adopting
359
420
  * service capability or binding id twice. Order is free.
360
421
  */
361
422
  export const validateCorestoreLegacyResourceAdoptionPlan = (
@@ -368,19 +429,30 @@ export const validateCorestoreLegacyResourceAdoptionPlan = (
368
429
  }
369
430
  const errors: string[] = [];
370
431
  const serviceCapabilities = new Set<string>();
432
+ const adoptingCapabilities = new Set<string>();
371
433
  const bindingIds = new Set<string>();
372
434
  for (const [index, entry] of valueArg.entries()) {
373
- if (!isPlainRecord(entry) || !hasExactKeys(entry, ['serviceId', 'capability', 'bindingId'])
374
- || !isIdentifier(entry.serviceId) || !isIdentifier(entry.bindingId) || !isCapability(entry.capability)) {
435
+ const shape = isPlainRecord(entry) ? successorShape(entry, ['serviceId', 'capability', 'bindingId']) : 'shape';
436
+ const record = entry as Record<string, unknown>;
437
+ if (shape === 'shape' || !isIdentifier(record.serviceId) || !isIdentifier(record.bindingId)
438
+ || !isCapability(record.capability)) {
375
439
  errors.push(`${pathArg} entry ${index} must be an exact { serviceId, capability, bindingId }`);
376
440
  continue;
377
441
  }
378
- const serviceCapability = selectionKey(entry as unknown as ICorestoreLegacyResourceSelection);
379
- if (serviceCapabilities.has(serviceCapability) || bindingIds.has(entry.bindingId as string)) {
442
+ if (shape === 'successor') {
443
+ errors.push(`${pathArg} entry ${index} successorServiceId must name another service`);
444
+ continue;
445
+ }
446
+ const planEntry = entry as ICorestoreLegacyResourceAdoptionPlanEntry;
447
+ const serviceCapability = selectionKey(planEntry);
448
+ const adoptingCapability = adoptingKey(planEntry);
449
+ if (serviceCapabilities.has(serviceCapability) || adoptingCapabilities.has(adoptingCapability)
450
+ || bindingIds.has(planEntry.bindingId)) {
380
451
  errors.push(`${pathArg} entry ${index} repeats a service capability or binding id`);
381
452
  }
382
453
  serviceCapabilities.add(serviceCapability);
383
- bindingIds.add(entry.bindingId as string);
454
+ adoptingCapabilities.add(adoptingCapability);
455
+ bindingIds.add(planEntry.bindingId);
384
456
  }
385
457
  return errors;
386
458
  };
@@ -392,16 +464,27 @@ export interface ICorestoreLegacyAdoptionBindingView {
392
464
  capability: string;
393
465
  objectstorageBucketName?: string;
394
466
  objectstorageRetention?: { intent: IObjectStorageRetentionIntent };
395
- corestoreLegacyAdoption?: { nodeId: string; resourceName: string; inventorySha256: string };
467
+ corestoreLegacyAdoption?: {
468
+ nodeId: string;
469
+ resourceName: string;
470
+ inventorySha256: string;
471
+ legacyServiceId?: string;
472
+ };
396
473
  }
397
474
 
475
+ /** The service that owns the legacy resource a binding adopts: its `legacyServiceId`, else its own. */
476
+ const legacyOwnerOf = (bindingArg: ICorestoreLegacyAdoptionBindingView): string =>
477
+ bindingArg.corestoreLegacyAdoption?.legacyServiceId ?? bindingArg.serviceId;
478
+
398
479
  /**
399
480
  * Content check of one adopting binding against the inventory it was adopted at, and the one rule
400
481
  * that lets a binding carry a legacy bucket name: the binding names this node, this inventory
401
- * digest and the legacy resource's name; the resource is unadopted without a blocker or authorized
402
- * for exactly this binding; an adopted bucket's `objectstorageBucketName` is the legacy bucket and
403
- * its retention intent the legacy intent exactly, absent when the legacy bucket has none; a
404
- * database binding carries neither. Whether the digest is current is the caller's to check.
482
+ * digest and the legacy resource's name; the resource belongs to `legacyServiceId` when the binding
483
+ * names one, and then its own service owns no legacy resource of the capability, otherwise to its
484
+ * own service; the resource is unadopted without a blocker or authorized for exactly this binding;
485
+ * an adopted bucket's `objectstorageBucketName` is the legacy bucket and its retention intent the
486
+ * legacy intent exactly, absent when the legacy bucket has none; a database binding carries
487
+ * neither. Whether the digest is current is the caller's to check.
405
488
  */
406
489
  export const validatePlatformBindingCorestoreLegacyAdoption = (
407
490
  bindingArg: ICorestoreLegacyAdoptionBindingView,
@@ -414,16 +497,27 @@ export const validatePlatformBindingCorestoreLegacyAdoption = (
414
497
  return [`${pathArg} needs a valid reachable inventory and its digest`];
415
498
  }
416
499
  const adoption = bindingArg.corestoreLegacyAdoption;
417
- if (!isPlainRecord(adoption) || !hasExactKeys(adoption, ['nodeId', 'resourceName', 'inventorySha256'])) {
500
+ if (!isPlainRecord(adoption)
501
+ || !hasExactKeys(adoption, ['nodeId', 'resourceName', 'inventorySha256'], ['legacyServiceId'])) {
418
502
  return [`${pathArg} must use its exact schema`];
419
503
  }
504
+ if (Object.keys(adoption).includes('legacyServiceId')
505
+ && (!isIdentifier(adoption.legacyServiceId) || adoption.legacyServiceId === bindingArg.serviceId)) {
506
+ return [`${pathArg} legacyServiceId must name another service than the binding's`];
507
+ }
420
508
  if (adoption.nodeId !== inventoryArg.nodeId || adoption.inventorySha256 !== inventorySha256Arg) {
421
509
  return [`${pathArg} must name the inventory's node and digest`];
422
510
  }
423
511
  if (!isCapability(bindingArg.capability)) return [`${pathArg} needs a database or objectstorage binding`];
424
- const resource = inventoryArg.services.find((serviceArg) => serviceArg.serviceId === bindingArg.serviceId)
512
+ const resourceOf = (serviceIdArg: string) => inventoryArg.services
513
+ .find((serviceArg) => serviceArg.serviceId === serviceIdArg)
425
514
  ?.resources.find((resourceArg) => resourceArg.capability === bindingArg.capability);
515
+ const legacyOwner = legacyOwnerOf(bindingArg);
516
+ const resource = resourceOf(legacyOwner);
426
517
  if (!resource) return [`${pathArg} names no legacy resource of the service and capability`];
518
+ if (legacyOwner !== bindingArg.serviceId && resourceOf(bindingArg.serviceId)) {
519
+ return [`${pathArg} names a successor that owns a legacy resource of the capability itself`];
520
+ }
427
521
  const errors: string[] = [];
428
522
  const legacyName = resource.capability === 'database' ? resource.databaseName : resource.bucketName;
429
523
  if (adoption.resourceName !== legacyName) errors.push(`${pathArg} resourceName must be the legacy resource's name`);
@@ -447,18 +541,27 @@ export const validatePlatformBindingCorestoreLegacyAdoption = (
447
541
  };
448
542
 
449
543
  /**
450
- * The plan for every adopting binding, sorted by service then capability, in the exact entry shape
451
- * Corestore's migration reads. Throws unless every binding adopts a legacy resource and the result
452
- * is a valid plan.
544
+ * The plan for every adopting binding, sorted by legacy service then capability, in the exact entry
545
+ * shape Corestore's migration reads: a binding adopting another service's resource names that
546
+ * service as `serviceId` and its own as `successorServiceId`. Throws unless every binding adopts a
547
+ * legacy resource and the result is a valid plan.
453
548
  */
454
549
  export const createCorestoreLegacyResourceAdoptionPlan = (
455
550
  bindingsArg: readonly ICorestoreLegacyAdoptionBindingView[],
456
551
  ): ICorestoreLegacyResourceAdoptionPlanEntry[] => {
457
- const plan = bindingsArg.map((bindingArg) => {
552
+ const plan = bindingsArg.map((bindingArg): ICorestoreLegacyResourceAdoptionPlanEntry => {
458
553
  if (bindingArg.corestoreLegacyAdoption === undefined || !isCapability(bindingArg.capability)) {
459
554
  throw new Error(`binding ${bindingArg.id} adopts no legacy Corestore resource`);
460
555
  }
461
- return { serviceId: bindingArg.serviceId, capability: bindingArg.capability, bindingId: bindingArg.id };
556
+ const legacyServiceId = bindingArg.corestoreLegacyAdoption.legacyServiceId;
557
+ return legacyServiceId === undefined
558
+ ? { serviceId: bindingArg.serviceId, capability: bindingArg.capability, bindingId: bindingArg.id }
559
+ : {
560
+ serviceId: legacyServiceId,
561
+ capability: bindingArg.capability,
562
+ bindingId: bindingArg.id,
563
+ successorServiceId: bindingArg.serviceId,
564
+ };
462
565
  }).sort((leftArg, rightArg) => compareWireTokens(selectionKey(leftArg), selectionKey(rightArg)));
463
566
  const errors = validateCorestoreLegacyResourceAdoptionPlan(plan);
464
567
  if (errors.length > 0) throw new Error(errors[0]);
@@ -4,13 +4,20 @@ import { captureNetwork, networkCounter, networkNodeId, networkRecord, networkSa
4
4
  type TEgressOwner = IRuntimeNetworkProtectedAuthority['egressAuthorities'][number];
5
5
 
6
6
  /**
7
- * One unmet condition of a node's runtime network readiness, in the order the node producer meets
8
- * them: the node joins the protected authority's egress, every egress owner reports current
9
- * protection, a handoff is reserved, the router selection carries it, the node's acknowledged
10
- * projection carries it, and the node is a managed VPN member. `protection-receipts-pending` names
11
- * the egress owners whose current receipts are still missing.
7
+ * One unmet condition of a node's runtime network readiness. The first is liveness: the node is
8
+ * observed running. The rest follow the order the node producer meets them: the node joins the
9
+ * protected authority's egress, every egress owner reports current protection, a handoff is
10
+ * reserved, the router selection carries it, the node's acknowledged projection carries it, and the
11
+ * node is a managed VPN member. `protection-receipts-pending` names the egress owners whose current
12
+ * receipts are still missing.
12
13
  */
13
14
  export type TRuntimeNetworkNodeReadinessGap =
15
+ /**
16
+ * No accepted report newer than `clusterNodeObservationFreshnessMs` shows the node running.
17
+ * `lastObservedAt` is when Cloudly accepted the node's last report, or `null` when the node's
18
+ * status is not `online`, so no report shows it running.
19
+ */
20
+ | { condition: 'node-observation-stale'; lastObservedAt: number | null }
14
21
  | { condition: 'egress-pending' | 'handoff-pending' | 'selection-pending' | 'projection-pending' | 'vpn-member-pending' }
15
22
  | { condition: 'protection-receipts-pending'; owners: [TEgressOwner, ...TEgressOwner[]] };
16
23
 
@@ -116,14 +116,18 @@ export interface IPlatformServiceEndpoint {
116
116
  * the binding, and Cloudly refuses it (and `objectstorageBucketName`) on `upsertPlatformBinding`.
117
117
  * `nodeId` is the node whose Corestore holds the resource, so the binding is placed there and
118
118
  * nowhere else; `resourceName` is the legacy database or bucket name; `inventorySha256` is the
119
- * legacy inventory the adoption was checked against. An adopted bucket's
120
- * `objectstorageBucketName` is the legacy bucket and its `objectstorageRetention.intent` the legacy
121
- * intent exactly, or absent when the legacy bucket has none.
119
+ * legacy inventory the adoption was checked against; `legacyServiceId` is the service that owned the
120
+ * legacy resource when that is not the binding's own service (a successor adopting its
121
+ * predecessor's data), absent otherwise. An adopted bucket's `objectstorageBucketName` is the legacy
122
+ * bucket and its `objectstorageRetention.intent` the legacy intent exactly, or absent when the
123
+ * legacy bucket has none.
122
124
  */
123
125
  export interface IPlatformBindingCorestoreLegacyAdoption {
124
126
  nodeId: string;
125
127
  resourceName: string;
126
128
  inventorySha256: string;
129
+ /** The legacy resource's owner, when it is another service than the binding's; never its own. */
130
+ legacyServiceId?: string;
127
131
  }
128
132
 
129
133
  export interface IPlatformBinding {
@@ -332,8 +332,12 @@ extends plugins.typedrequestInterfaces.implementsTR<
332
332
  * Cloudly reads the node's legacy inventory again, requires `expectedInventorySha256`, and for
333
333
  * each selected resource creates the adopting binding in one transaction: enabled, placed on
334
334
  * `nodeId`, with `corestoreLegacyAdoption`, and for a bucket the legacy bucket name and retention
335
- * intent (`validatePlatformBindingCorestoreLegacyAdoption`). A resource whose adopting binding
336
- * already exists is answered unchanged. The response lists the adopting bindings and the plan
335
+ * intent (`validatePlatformBindingCorestoreLegacyAdoption`). A selection naming a
336
+ * `successorServiceId` creates the binding on that successor instead, with
337
+ * `corestoreLegacyAdoption.legacyServiceId` naming the legacy owner; the successor must exist, share
338
+ * the legacy owner's organization, be an immutable-deployment service, own no legacy resource of
339
+ * that capability and hold no other binding of it. A legacy resource is adopted by one service
340
+ * only. A resource whose adopting binding already exists is answered unchanged. The response lists the adopting bindings and the plan
337
341
  * (`createCorestoreLegacyResourceAdoptionPlan`) the operator hands to Corestore's offline
338
342
  * `legacy-resource-adoption` migration. Refusals travel as `ICorestoreLegacyAdoptionErrorData`.
339
343
  */