@serve.zone/interfaces 32.71.0 → 32.73.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.
- package/changelog.md +20 -0
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/data/backuprestorerefusal.d.ts +17 -2
- package/dist_ts/data/backuprestorerefusal.js +20 -1
- package/dist_ts/data/cloudlyconfig.d.ts +6 -0
- package/dist_ts/data/clusternode.d.ts +7 -0
- package/dist_ts/data/clusternode.js +1 -1
- package/dist_ts/data/index.d.ts +1 -0
- package/dist_ts/data/index.js +2 -1
- package/dist_ts/data/location.d.ts +137 -0
- package/dist_ts/data/location.js +160 -0
- package/dist_ts/requests/baremetal.d.ts +12 -0
- package/dist_ts/requests/cluster.d.ts +20 -0
- package/dist_ts/requests/cluster.js +1 -1
- package/dist_ts/requests/index.d.ts +2 -1
- package/dist_ts/requests/index.js +3 -2
- package/dist_ts/requests/location.d.ts +88 -0
- package/dist_ts/requests/location.js +2 -0
- package/dist_ts/requests/node.d.ts +16 -0
- package/package.json +2 -2
- package/readme.md +50 -0
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/data/backuprestorerefusal.ts +31 -1
- package/ts/data/cloudlyconfig.ts +6 -0
- package/ts/data/clusternode.ts +9 -1
- package/ts/data/index.ts +1 -0
- package/ts/data/location.ts +259 -0
- package/ts/requests/baremetal.ts +12 -0
- package/ts/requests/cluster.ts +20 -0
- package/ts/requests/index.ts +2 -0
- package/ts/requests/location.ts +119 -0
- package/ts/requests/node.ts +16 -0
package/readme.md
CHANGED
|
@@ -3768,6 +3768,56 @@ const ingressReasons = data.validateClusterIngressRegistration({
|
|
|
3768
3768
|
}); // []
|
|
3769
3769
|
```
|
|
3770
3770
|
|
|
3771
|
+
### Locations
|
|
3772
|
+
|
|
3773
|
+
A location (`data.ILocation`) is a room Cloudly's physical objects stand in: one record with a
|
|
3774
|
+
fixed `id`, which every reference uses, and one unique, renamable `name`, one lowercase RFC 1123
|
|
3775
|
+
label (`data.isLocationName`). Every Cloudly database holds exactly one initial location
|
|
3776
|
+
(`data.initialLocationId`, created as `data.initialLocationName`, `initial`); it receives every
|
|
3777
|
+
create that names no location for a cluster without nodes, and `getLocations` marks it
|
|
3778
|
+
`receivesUnnamedCreates`.
|
|
3779
|
+
|
|
3780
|
+
- A node carries its location in `IClusterNode.data.locationId`, optional here because a
|
|
3781
|
+
controller without locations leaves it out; a Cloudly with locations sets it on every node.
|
|
3782
|
+
- A cluster stands where its nodes stand: `data.getClusterLocationId(cluster)` reads the cluster's
|
|
3783
|
+
`data.nodes` copies, answers `undefined` for a cluster without nodes (or one whose copies name no
|
|
3784
|
+
location) and throws `data.ClusterSpansLocationsError` when the copies disagree, a state Cloudly
|
|
3785
|
+
never writes. A cluster moves only whole (`setClusterLocation`), which writes every node to the
|
|
3786
|
+
target in one transaction and so also repairs a cluster that spans locations; it never answers
|
|
3787
|
+
`cluster-spans-locations`.
|
|
3788
|
+
- A BareMetal server stands where the node whose `data.baremetalId` names it stands;
|
|
3789
|
+
`IBareMetal.data.location` stays the provider's datacenter.
|
|
3790
|
+
- The member kinds are the stored kinds `data.locationMemberKinds` (`edge`, `gateway`, `node`,
|
|
3791
|
+
`oneboxHost`); `getLocations` answers which of them the Cloudly records
|
|
3792
|
+
(`recordedMemberKinds`). A cluster is no member and no part of the digest: `getClusters` with a
|
|
3793
|
+
`locationScope` lists the clusters standing in a location.
|
|
3794
|
+
- `data.initialLocationId` (`location-initial`) is fixed; Cloudly generates every other location id
|
|
3795
|
+
with a generator that can never produce it.
|
|
3796
|
+
|
|
3797
|
+
An administrator confirms a location's membership with the digest of the view they read
|
|
3798
|
+
(`confirmLocationMembership`). The location stores the confirmed digest; it is confirmed while that
|
|
3799
|
+
equals the current one (`data.isLocationMembershipConfirmed`), so nothing rewrites it when membership
|
|
3800
|
+
changes, and a confirmation of a stale digest is refused `membership-changed`.
|
|
3801
|
+
`data.computeLocationMembershipDigest(members, recordedKinds)` is `sha256:<hex>` (Web Crypto) of the
|
|
3802
|
+
canonical JSON of the sorted `[kind, id]` pairs and the recorded kinds
|
|
3803
|
+
(`data.createLocationMembershipDigestInput`), independent of the order either is listed in.
|
|
3804
|
+
|
|
3805
|
+
The requests (`requests.location`) are administrator-only, admitted by no delegated-admin scope:
|
|
3806
|
+
`createLocation`, `renameLocation`, `getLocations`, `setClusterLocation` (answers
|
|
3807
|
+
`data.setClusterLocationOutcomes`: `moved`, `unchanged`, or `cluster-empty` for a cluster without
|
|
3808
|
+
nodes) and `confirmLocationMembership`. Every refusal is one of `data.locationRefusals`.
|
|
3809
|
+
`createCluster` and `createNodeJumpCommand` take an optional `locationId`; for a cluster with nodes
|
|
3810
|
+
a named location must be the cluster's (`location-mismatch`). A `createCluster` that names a
|
|
3811
|
+
location but creates no node (`setupMode` `manual` or absent) is refused `location-needs-node`,
|
|
3812
|
+
checked before `location-not-found`: name the location on `createNodeJumpCommand` instead.
|
|
3813
|
+
`getClusters`, `getNodes` and `getBaremetalServers` take an optional `locationScope` and echo it as `appliedLocationScope`: a
|
|
3814
|
+
response without the echo comes from a Cloudly that ignored the scope and is not scoped.
|
|
3815
|
+
|
|
3816
|
+
Cloudly's 0.39.0 → 0.40.0 data step writes one transaction per cluster (the cluster document and
|
|
3817
|
+
all its node documents, setting `locationId` only where it is missing, so a rerun is safe) and one
|
|
3818
|
+
transaction per node whose `clusterId` names no existing cluster. It never calls
|
|
3819
|
+
`data.getClusterLocationId`, which throws for node copies that disagree.
|
|
3820
|
+
|
|
3771
3821
|
### Node Uplink Address
|
|
3772
3822
|
|
|
3773
3823
|
A route to a node's published host ports needs the address that node answers on, and only the
|
package/ts/00_commitinfo_data.ts
CHANGED
|
@@ -20,6 +20,13 @@ import { compareReleaseVersions, parseReleaseVersion } from './releaseversion.js
|
|
|
20
20
|
* that carries the restore check, so Cloudly does not dispatch the restore; the relay states
|
|
21
21
|
* `relayInterfacesVersion` (`null` when it stated none) and the restore needs
|
|
22
22
|
* `minimumInterfacesVersion`.
|
|
23
|
+
* - `restore-operation-unavailable`: Cloudly refuses every in-place restore because a restore is not
|
|
24
|
+
* yet an operation the node owns: a restore relayed as one request is cut at the transport
|
|
25
|
+
* timeout, so Cloudly cannot learn whether it finished. It names the missing capability, not a
|
|
26
|
+
* version, and stays in this contract permanently because stored restore events carry it.
|
|
27
|
+
* Cloudly is its only producer and reads its own restore history, so it carries this reader
|
|
28
|
+
* itself: readers of restore events upgrade before Cloudly, and Cloudly is not rolled back below
|
|
29
|
+
* a release that stored it.
|
|
23
30
|
*
|
|
24
31
|
* It travels as `TypedResponseError.errorData` of a refused restore and is recorded as the
|
|
25
32
|
* `refusal` of the backup's `refused` restore event (`IBackupRestoreEvent`). Each refusal is
|
|
@@ -30,6 +37,7 @@ export const backupRestoreRefusalNames = Object.freeze([
|
|
|
30
37
|
'restore-snapshot-unavailable',
|
|
31
38
|
'restore-preflight-unsupported',
|
|
32
39
|
'restore-relay-contract-behind',
|
|
40
|
+
'restore-operation-unavailable',
|
|
33
41
|
] as const);
|
|
34
42
|
|
|
35
43
|
export type TBackupRestoreRefusalName = typeof backupRestoreRefusalNames[number];
|
|
@@ -68,11 +76,16 @@ export interface IBackupRestoreRelayContractBehindRefusal {
|
|
|
68
76
|
minimumInterfacesVersion: string;
|
|
69
77
|
}
|
|
70
78
|
|
|
79
|
+
export interface IBackupRestoreOperationUnavailableRefusal {
|
|
80
|
+
name: 'restore-operation-unavailable';
|
|
81
|
+
}
|
|
82
|
+
|
|
71
83
|
/** A refused restore, discriminated by `name` (`backupRestoreRefusalNames`). */
|
|
72
84
|
export type TBackupRestoreRefusal =
|
|
73
85
|
| IBackupRestoreSnapshotUnavailableRefusal
|
|
74
86
|
| IBackupRestorePreflightUnsupportedRefusal
|
|
75
|
-
| IBackupRestoreRelayContractBehindRefusal
|
|
87
|
+
| IBackupRestoreRelayContractBehindRefusal
|
|
88
|
+
| IBackupRestoreOperationUnavailableRefusal;
|
|
76
89
|
|
|
77
90
|
/** Every resource type, keyed so a new `TBackupResourceType` member fails to compile here. */
|
|
78
91
|
const backupResourceTypeKeys: Readonly<Record<TBackupResourceType, true>> = Object.freeze({
|
|
@@ -169,6 +182,7 @@ const refusalKeys: Readonly<Record<TBackupRestoreRefusalName, readonly string[]>
|
|
|
169
182
|
'restore-relay-contract-behind': Object.freeze([
|
|
170
183
|
'name', 'relayInterfacesVersion', 'minimumInterfacesVersion',
|
|
171
184
|
]),
|
|
185
|
+
'restore-operation-unavailable': Object.freeze(['name']),
|
|
172
186
|
});
|
|
173
187
|
|
|
174
188
|
/** Validates one restore refusal against its exact schema and names every reason it is refused. */
|
|
@@ -191,6 +205,8 @@ export const validateBackupRestoreRefusal = (
|
|
|
191
205
|
return [];
|
|
192
206
|
case 'restore-relay-contract-behind':
|
|
193
207
|
return validateRelayContractBehind(refusal, pathArg);
|
|
208
|
+
case 'restore-operation-unavailable':
|
|
209
|
+
return [];
|
|
194
210
|
}
|
|
195
211
|
};
|
|
196
212
|
|
|
@@ -227,6 +243,10 @@ const copyRelayContractBehindRefusal = (
|
|
|
227
243
|
minimumInterfacesVersion: refusalArg.minimumInterfacesVersion,
|
|
228
244
|
});
|
|
229
245
|
|
|
246
|
+
const copyOperationUnavailableRefusal = (
|
|
247
|
+
refusalArg: IBackupRestoreOperationUnavailableRefusal,
|
|
248
|
+
): IBackupRestoreOperationUnavailableRefusal => Object.freeze({ name: refusalArg.name });
|
|
249
|
+
|
|
230
250
|
/** An inert frozen copy of a refusal that passed `validateBackupRestoreRefusal`. */
|
|
231
251
|
const copyRefusal = (refusalArg: TBackupRestoreRefusal): TBackupRestoreRefusal => {
|
|
232
252
|
switch (refusalArg.name) {
|
|
@@ -236,6 +256,8 @@ const copyRefusal = (refusalArg: TBackupRestoreRefusal): TBackupRestoreRefusal =
|
|
|
236
256
|
return copyPreflightUnsupportedRefusal(refusalArg);
|
|
237
257
|
case 'restore-relay-contract-behind':
|
|
238
258
|
return copyRelayContractBehindRefusal(refusalArg);
|
|
259
|
+
case 'restore-operation-unavailable':
|
|
260
|
+
return copyOperationUnavailableRefusal(refusalArg);
|
|
239
261
|
}
|
|
240
262
|
};
|
|
241
263
|
|
|
@@ -287,6 +309,14 @@ export const buildBackupRestoreRelayContractBehindRefusal = (
|
|
|
287
309
|
minimumInterfacesVersion: minimumInterfacesVersionArg,
|
|
288
310
|
}));
|
|
289
311
|
|
|
312
|
+
/**
|
|
313
|
+
* `restore-operation-unavailable`: Cloudly refuses the in-place restore because a restore is not
|
|
314
|
+
* yet a node-owned operation.
|
|
315
|
+
*/
|
|
316
|
+
export const buildBackupRestoreOperationUnavailableRefusal = (): IBackupRestoreOperationUnavailableRefusal => (
|
|
317
|
+
copyOperationUnavailableRefusal(requireRefusal({ name: 'restore-operation-unavailable' }))
|
|
318
|
+
);
|
|
319
|
+
|
|
290
320
|
const restoreEventStatuses: readonly IBackupRestoreEvent['status'][] = Object.freeze([
|
|
291
321
|
'restored', 'failed', 'refused',
|
|
292
322
|
]);
|
package/ts/data/cloudlyconfig.ts
CHANGED
|
@@ -16,5 +16,11 @@ export interface ICloudlyConfig {
|
|
|
16
16
|
*/
|
|
17
17
|
listenPort?: string;
|
|
18
18
|
sslMode?: 'none' | 'letsencrypt' | 'external';
|
|
19
|
+
/**
|
|
20
|
+
* @deprecated Human sign-in moves into Cloudly itself (AGL-1179): idp.global, Cloudly's own
|
|
21
|
+
* passkeys, and `cloudly login-token` minted inside the Cloudly container for the first admin and
|
|
22
|
+
* break-glass. Cloudly 34.0.0 no longer reads this key, and the next major of this package
|
|
23
|
+
* removes it.
|
|
24
|
+
*/
|
|
19
25
|
servezoneAdminaccount?: string;
|
|
20
26
|
}
|
package/ts/data/clusternode.ts
CHANGED
|
@@ -1734,7 +1734,15 @@ export interface IClusterNode {
|
|
|
1734
1734
|
* Reference to the cluster this node belongs to
|
|
1735
1735
|
*/
|
|
1736
1736
|
clusterId: string;
|
|
1737
|
-
|
|
1737
|
+
|
|
1738
|
+
/**
|
|
1739
|
+
* The location the node stands in (`ILocation.id`). Every Cloudly with locations sets it on
|
|
1740
|
+
* every node it stores and moves it only with the node's whole cluster
|
|
1741
|
+
* (`setClusterLocation`); only a controller without locations leaves it out. The cluster's
|
|
1742
|
+
* copies of its nodes carry it too, which `getClusterLocationId` reads.
|
|
1743
|
+
*/
|
|
1744
|
+
locationId?: string;
|
|
1745
|
+
|
|
1738
1746
|
/**
|
|
1739
1747
|
* Reference to the physical server (if applicable)
|
|
1740
1748
|
*/
|
package/ts/data/index.ts
CHANGED
|
@@ -90,6 +90,7 @@ export * from './serviceplatformownership.js';
|
|
|
90
90
|
export * from './serviceports.js';
|
|
91
91
|
export * from './serviceruntime.js';
|
|
92
92
|
export * from './launchersecretowner.js';
|
|
93
|
+
export * from './location.js';
|
|
93
94
|
export * from './servicevolumeinitialization.js';
|
|
94
95
|
export * from './status.js';
|
|
95
96
|
export * from './taskexecution.js';
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
import { canonicalizeStrictJson, compareWireTokens, createCanonicalJsonSha256Hex } from '../private/canonicaljson.js';
|
|
2
|
+
import type { ICluster } from './cluster.js';
|
|
3
|
+
import type { TSha256Digest } from './immutableimage.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Locations: the rooms Cloudly's physical objects stand in.
|
|
7
|
+
*
|
|
8
|
+
* A location is a record of its own, referenced by its `id` and named by one unique, renamable
|
|
9
|
+
* `name`. Objects carry the id: a cluster node in `IClusterNode.data.locationId`, the records later
|
|
10
|
+
* lanes add (gateway, edge, Onebox host) in a required `locationId` of their own. A cluster has no
|
|
11
|
+
* stored location: it stands where its nodes stand (`getClusterLocationId`), and an empty cluster
|
|
12
|
+
* stands nowhere. A BareMetal server stands where the node whose `data.baremetalId` names it
|
|
13
|
+
* stands; its `data.location` stays the provider's datacenter.
|
|
14
|
+
*
|
|
15
|
+
* Every Cloudly database holds exactly one initial location (`initialLocationId`, named
|
|
16
|
+
* `initialLocationName` until an administrator renames it). It receives every create that names no
|
|
17
|
+
* location for a cluster without nodes; a create for a cluster with nodes takes the cluster's.
|
|
18
|
+
*/
|
|
19
|
+
export const locationContract = Object.freeze({
|
|
20
|
+
/** One lowercase RFC 1123 label. */
|
|
21
|
+
maximumNameLength: 63,
|
|
22
|
+
digestDomain: 'serve.zone/location-membership',
|
|
23
|
+
} as const);
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The id of the one location every Cloudly database holds; it never changes. Cloudly generates
|
|
27
|
+
* every other location's id with a generator that can never produce this one.
|
|
28
|
+
*/
|
|
29
|
+
export const initialLocationId = 'location-initial';
|
|
30
|
+
|
|
31
|
+
/** The name the initial location is created with; an administrator may rename it. */
|
|
32
|
+
export const initialLocationName = 'initial';
|
|
33
|
+
|
|
34
|
+
const locationNameLabel = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/;
|
|
35
|
+
|
|
36
|
+
/** True for a location name: one lowercase RFC 1123 label of 1 to 63 characters. */
|
|
37
|
+
export const isLocationName = (valueArg: unknown): valueArg is string => (
|
|
38
|
+
typeof valueArg === 'string'
|
|
39
|
+
&& valueArg.length <= locationContract.maximumNameLength
|
|
40
|
+
&& locationNameLabel.test(valueArg)
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Every kind of stored object a location can hold, in canonical (`compareWireTokens`) order. A
|
|
45
|
+
* Cloudly records only some of them (`IReq_Any_Cloudly_GetLocations` answers which); a kind it does
|
|
46
|
+
* not record has no members anywhere. A cluster is no member: it stores no location and stands
|
|
47
|
+
* where its nodes stand (`getClusterLocationId`); `getClusters` lists a location's clusters through
|
|
48
|
+
* its `locationScope`.
|
|
49
|
+
*/
|
|
50
|
+
export const locationMemberKinds = Object.freeze([
|
|
51
|
+
'edge', 'gateway', 'node', 'oneboxHost',
|
|
52
|
+
] as const);
|
|
53
|
+
|
|
54
|
+
export type TLocationMemberKind = typeof locationMemberKinds[number];
|
|
55
|
+
|
|
56
|
+
/** True for one of `locationMemberKinds`. */
|
|
57
|
+
export const isLocationMemberKind = (valueArg: unknown): valueArg is TLocationMemberKind => (
|
|
58
|
+
(locationMemberKinds as readonly unknown[]).includes(valueArg)
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
/** One object a location holds: its kind and its id within that kind. */
|
|
62
|
+
export interface ILocationMember {
|
|
63
|
+
kind: TLocationMemberKind;
|
|
64
|
+
id: string;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* The membership an administrator confirmed complete for one location.
|
|
69
|
+
*
|
|
70
|
+
* Cloudly never rewrites it when membership changes: the location's membership is confirmed while
|
|
71
|
+
* `membershipDigest` equals the digest of its current membership (`isLocationMembershipConfirmed`).
|
|
72
|
+
*/
|
|
73
|
+
export interface ILocationMembershipConfirmation {
|
|
74
|
+
/** `computeLocationMembershipDigest` of the membership the administrator saw. */
|
|
75
|
+
membershipDigest: TSha256Digest;
|
|
76
|
+
/** Unix milliseconds on Cloudly's clock when Cloudly accepted the confirmation. */
|
|
77
|
+
confirmedAt: number;
|
|
78
|
+
/** The confirming administrator's user id. */
|
|
79
|
+
confirmedBy: string;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** A location as Cloudly stores it. */
|
|
83
|
+
export interface ILocation {
|
|
84
|
+
/** Fixed for the location's life; every reference uses it. */
|
|
85
|
+
id: string;
|
|
86
|
+
data: {
|
|
87
|
+
/** Unique among locations; `isLocationName`. */
|
|
88
|
+
name: string;
|
|
89
|
+
/** Unix milliseconds on Cloudly's clock. */
|
|
90
|
+
createdAt: number;
|
|
91
|
+
/** The creating administrator's user id; absent for the initial location Cloudly created itself. */
|
|
92
|
+
createdBy?: string;
|
|
93
|
+
/** Absent until an administrator first confirms the location's membership. */
|
|
94
|
+
membershipConfirmation?: ILocationMembershipConfirmation;
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** A location with what it holds now, as `getLocations` answers it. */
|
|
99
|
+
export interface ILocationView {
|
|
100
|
+
location: ILocation;
|
|
101
|
+
/** Every stored member of a kind this Cloudly records, sorted by kind and then id. */
|
|
102
|
+
members: ILocationMember[];
|
|
103
|
+
/** `computeLocationMembershipDigest(members, <the kinds this Cloudly records>)`. */
|
|
104
|
+
membershipDigest: TSha256Digest;
|
|
105
|
+
/** `isLocationMembershipConfirmed(location, membershipDigest)`. */
|
|
106
|
+
membershipConfirmed: boolean;
|
|
107
|
+
/**
|
|
108
|
+
* True for exactly one location: the one a create naming no location places the first node of
|
|
109
|
+
* an empty cluster in (the initial location).
|
|
110
|
+
*/
|
|
111
|
+
receivesUnnamedCreates: boolean;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Narrows a list request to the rows of one location. A Cloudly that applied it echoes it as the
|
|
116
|
+
* response's `appliedLocationScope`; a response without the echo comes from a Cloudly that ignored
|
|
117
|
+
* it, and its list must not be shown as scoped.
|
|
118
|
+
*/
|
|
119
|
+
export interface ILocationScope {
|
|
120
|
+
locationId: string;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Every reason Cloudly answers instead of a location request or a create that names a location.
|
|
125
|
+
* Each travels by name as a `TypedResponseError`, and a refused request changes nothing.
|
|
126
|
+
*/
|
|
127
|
+
export const locationRefusals = Object.freeze([
|
|
128
|
+
/**
|
|
129
|
+
* A create named a location but creates no node to stand in it (`createCluster` with `setupMode`
|
|
130
|
+
* `manual` or absent); name the location on `createNodeJumpCommand` instead. Checked before
|
|
131
|
+
* `location-not-found`.
|
|
132
|
+
*/
|
|
133
|
+
'location-needs-node',
|
|
134
|
+
/** No location of that id exists. */
|
|
135
|
+
'location-not-found',
|
|
136
|
+
/** The name is not one lowercase RFC 1123 label (`isLocationName`). */
|
|
137
|
+
'location-name-invalid',
|
|
138
|
+
/** Another location carries that name. */
|
|
139
|
+
'location-name-taken',
|
|
140
|
+
/** No cluster of that id exists (`setClusterLocation`). */
|
|
141
|
+
'cluster-not-found',
|
|
142
|
+
/**
|
|
143
|
+
* A create for a cluster with nodes named a location other than the cluster's:
|
|
144
|
+
* `createNodeJumpCommand` when it is asked, and the jump-code claim when the cluster gained nodes
|
|
145
|
+
* in another location after the code was made.
|
|
146
|
+
*/
|
|
147
|
+
'location-mismatch',
|
|
148
|
+
/**
|
|
149
|
+
* A create or a jump-code claim for a cluster whose nodes already stand in more than one
|
|
150
|
+
* location: a state Cloudly never writes, which `getClusterLocationId` reports by throwing
|
|
151
|
+
* `ClusterSpansLocationsError`. `setClusterLocation` never answers it: it writes every node of the
|
|
152
|
+
* cluster to the target location in one transaction, which also repairs a spanning cluster.
|
|
153
|
+
*/
|
|
154
|
+
'cluster-spans-locations',
|
|
155
|
+
/**
|
|
156
|
+
* The digest a confirmation states is not the location's current membership digest: read the
|
|
157
|
+
* location again and confirm what it holds now.
|
|
158
|
+
*/
|
|
159
|
+
'membership-changed',
|
|
160
|
+
/** A concurrent change to the same records won; nothing changed. Read again and retry. */
|
|
161
|
+
'conflict',
|
|
162
|
+
] as const);
|
|
163
|
+
|
|
164
|
+
/** One of the reasons Cloudly answers instead of a location request. */
|
|
165
|
+
export type TLocationRefusal = typeof locationRefusals[number];
|
|
166
|
+
|
|
167
|
+
/** What a `setClusterLocation` did; every outcome is a success. */
|
|
168
|
+
export const setClusterLocationOutcomes = Object.freeze([
|
|
169
|
+
/** Every node of the cluster, and the cluster's copy of each, now names the location. */
|
|
170
|
+
'moved',
|
|
171
|
+
/** Every node already stood in the location; nothing was written. */
|
|
172
|
+
'unchanged',
|
|
173
|
+
/** The cluster has no nodes, so it stands nowhere and nothing was moved. */
|
|
174
|
+
'cluster-empty',
|
|
175
|
+
] as const);
|
|
176
|
+
|
|
177
|
+
export type TSetClusterLocationOutcome = typeof setClusterLocationOutcomes[number];
|
|
178
|
+
|
|
179
|
+
/** Thrown by `getClusterLocationId` for a cluster whose node copies disagree. */
|
|
180
|
+
export class ClusterSpansLocationsError extends Error {
|
|
181
|
+
public readonly refusal: TLocationRefusal = 'cluster-spans-locations';
|
|
182
|
+
public readonly clusterId: string;
|
|
183
|
+
|
|
184
|
+
public constructor(clusterIdArg: string) {
|
|
185
|
+
super(`Cluster ${clusterIdArg} spans locations.`);
|
|
186
|
+
this.name = 'ClusterSpansLocationsError';
|
|
187
|
+
this.clusterId = clusterIdArg;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* The location a cluster stands in, read from its own `data.nodes` copies.
|
|
193
|
+
*
|
|
194
|
+
* `undefined` when the cluster has no nodes, or when no copy names a location (the cluster came
|
|
195
|
+
* from a controller without locations); such a cluster drops out of every location scope. Throws
|
|
196
|
+
* `ClusterSpansLocationsError` when the copies name different locations, or some name one and
|
|
197
|
+
* others none: Cloudly never writes that state, and no single answer would be true for it.
|
|
198
|
+
*/
|
|
199
|
+
export const getClusterLocationId = (clusterArg: ICluster): string | undefined => {
|
|
200
|
+
const locationIds = new Set(clusterArg.data.nodes.map((nodeArg) => nodeArg.data.locationId));
|
|
201
|
+
if (locationIds.size > 1) {
|
|
202
|
+
throw new ClusterSpansLocationsError(clusterArg.id);
|
|
203
|
+
}
|
|
204
|
+
const [locationId] = locationIds;
|
|
205
|
+
return locationId;
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
/** True while the location's confirmed digest equals its current membership digest. */
|
|
209
|
+
export const isLocationMembershipConfirmed = (
|
|
210
|
+
locationArg: ILocation,
|
|
211
|
+
membershipDigestArg: TSha256Digest,
|
|
212
|
+
): boolean => locationArg.data.membershipConfirmation?.membershipDigest === membershipDigestArg;
|
|
213
|
+
|
|
214
|
+
const fail = (reasonArg: string): never => {
|
|
215
|
+
throw new Error(`Location membership digest input rejected: ${reasonArg}.`);
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
const compareMembers = (leftArg: ILocationMember, rightArg: ILocationMember): number => (
|
|
219
|
+
compareWireTokens(leftArg.kind, rightArg.kind) || compareWireTokens(leftArg.id, rightArg.id)
|
|
220
|
+
);
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* The canonical JSON a membership digest hashes: the digest domain, the recorded kinds in
|
|
224
|
+
* canonical order and the members as `[kind, id]` pairs sorted by kind and then id. The order the
|
|
225
|
+
* caller lists either in does not matter. Throws for an unknown or repeated kind, a member of a
|
|
226
|
+
* kind not recorded, an empty id or a repeated member.
|
|
227
|
+
*/
|
|
228
|
+
export const createLocationMembershipDigestInput = (
|
|
229
|
+
membersArg: readonly ILocationMember[],
|
|
230
|
+
recordedKindsArg: readonly TLocationMemberKind[],
|
|
231
|
+
): string => {
|
|
232
|
+
const recordedKinds = [...recordedKindsArg].sort(compareWireTokens);
|
|
233
|
+
recordedKinds.forEach((kindArg, indexArg) => {
|
|
234
|
+
if (!isLocationMemberKind(kindArg)) fail('unknown member kind');
|
|
235
|
+
if (indexArg > 0 && kindArg === recordedKinds[indexArg - 1]) fail('repeated member kind');
|
|
236
|
+
});
|
|
237
|
+
const members = [...membersArg].sort(compareMembers);
|
|
238
|
+
members.forEach((memberArg, indexArg) => {
|
|
239
|
+
if (!recordedKinds.includes(memberArg.kind)) fail('member of a kind not recorded');
|
|
240
|
+
if (typeof memberArg.id !== 'string' || memberArg.id.length === 0) fail('member id empty');
|
|
241
|
+
if (indexArg > 0 && compareMembers(memberArg, members[indexArg - 1]) === 0) fail('repeated member');
|
|
242
|
+
});
|
|
243
|
+
return canonicalizeStrictJson({
|
|
244
|
+
domain: locationContract.digestDomain,
|
|
245
|
+
recordedKinds,
|
|
246
|
+
members: members.map((memberArg) => [memberArg.kind, memberArg.id]),
|
|
247
|
+
}, fail, 'location membership');
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* `sha256:<hex>` of `createLocationMembershipDigestInput`, through Web Crypto, so Cloudly and a
|
|
252
|
+
* browser client compute the same value.
|
|
253
|
+
*/
|
|
254
|
+
export const computeLocationMembershipDigest = async (
|
|
255
|
+
membersArg: readonly ILocationMember[],
|
|
256
|
+
recordedKindsArg: readonly TLocationMemberKind[],
|
|
257
|
+
): Promise<TSha256Digest> => `sha256:${await createCanonicalJsonSha256Hex(
|
|
258
|
+
createLocationMembershipDigestInput(membersArg, recordedKindsArg), fail,
|
|
259
|
+
)}`;
|
package/ts/requests/baremetal.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as plugins from '../plugins.js';
|
|
2
2
|
import type { IBareMetal } from '../data/baremetal.js';
|
|
3
|
+
import type { ILocationScope } from '../data/location.js';
|
|
3
4
|
import type { IIdentity } from '../data/user.js';
|
|
4
5
|
|
|
5
6
|
export interface IRequest_Any_Cloudly_GetBaremetalServers
|
|
@@ -10,9 +11,20 @@ extends plugins.typedrequestInterfaces.implementsTR<
|
|
|
10
11
|
method: 'getBaremetalServers';
|
|
11
12
|
request: {
|
|
12
13
|
identity: IIdentity;
|
|
14
|
+
/**
|
|
15
|
+
* Only the servers standing in this location: those a node of the location names in its
|
|
16
|
+
* `data.baremetalId`. A server no node names stands nowhere and is never in a scoped answer;
|
|
17
|
+
* `IBareMetal.data.location` (the provider's datacenter) plays no part.
|
|
18
|
+
*/
|
|
19
|
+
locationScope?: ILocationScope;
|
|
13
20
|
};
|
|
14
21
|
response: {
|
|
15
22
|
baremetals: IBareMetal[];
|
|
23
|
+
/**
|
|
24
|
+
* The scope Cloudly applied, echoing `locationScope`. Absent from a Cloudly that ignored the
|
|
25
|
+
* scope (one without locations): its list is unscoped and must not be shown as scoped.
|
|
26
|
+
*/
|
|
27
|
+
appliedLocationScope?: ILocationScope;
|
|
16
28
|
};
|
|
17
29
|
}
|
|
18
30
|
|
package/ts/requests/cluster.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as userInterfaces from '../data/user.js';
|
|
2
2
|
import * as clusterInterfaces from '../data/cluster.js';
|
|
3
|
+
import type * as locationInterfaces from '../data/location.js';
|
|
3
4
|
import type * as relayCredentialInterfaces from '../data/clusterrelaycredential.js';
|
|
4
5
|
import type * as clusterVpnInterfaces from '../data/clustervpn.js';
|
|
5
6
|
import type { IClusterRuntime, TClusterRuntimeBlocker } from '../data/clusterruntime.js';
|
|
@@ -17,9 +18,19 @@ export interface IReq_Any_Cloudly_GetClusters extends plugins.typedrequestInterf
|
|
|
17
18
|
method: 'getClusters';
|
|
18
19
|
request: {
|
|
19
20
|
identity: userInterfaces.IIdentity;
|
|
21
|
+
/**
|
|
22
|
+
* Only the clusters standing in this location (`data.getClusterLocationId`); a cluster without
|
|
23
|
+
* nodes stands nowhere and is never in a scoped answer.
|
|
24
|
+
*/
|
|
25
|
+
locationScope?: locationInterfaces.ILocationScope;
|
|
20
26
|
};
|
|
21
27
|
response: {
|
|
22
28
|
clusters: clusterInterfaces.ICluster[];
|
|
29
|
+
/**
|
|
30
|
+
* The scope Cloudly applied, echoing `locationScope`. Absent from a Cloudly that ignored the
|
|
31
|
+
* scope (one without locations): its list is unscoped and must not be shown as scoped.
|
|
32
|
+
*/
|
|
33
|
+
appliedLocationScope?: locationInterfaces.ILocationScope;
|
|
23
34
|
};
|
|
24
35
|
}
|
|
25
36
|
|
|
@@ -47,6 +58,15 @@ export interface IRequest_CreateCluster extends plugins.typedrequestInterfaces.i
|
|
|
47
58
|
identity: userInterfaces.IIdentity;
|
|
48
59
|
clusterName: string;
|
|
49
60
|
setupMode?: 'manual' | 'hetzner' | 'aws' | 'digitalocean';
|
|
61
|
+
/**
|
|
62
|
+
* The location the node a provisioning setup mode creates stands in. Refused
|
|
63
|
+
* `location-needs-node` when the create makes no node to stand in it (`setupMode` `manual` or
|
|
64
|
+
* absent; name the location on `createNodeJumpCommand` instead), checked before
|
|
65
|
+
* `location-not-found`, which answers a location that does not exist. Absent, the created node
|
|
66
|
+
* stands in the location that receives unnamed creates (the initial location); a create that
|
|
67
|
+
* makes no node leaves the cluster empty, standing nowhere.
|
|
68
|
+
*/
|
|
69
|
+
locationId?: string;
|
|
50
70
|
};
|
|
51
71
|
response: {
|
|
52
72
|
cluster: clusterInterfaces.ICluster;
|
package/ts/requests/index.ts
CHANGED
|
@@ -23,6 +23,7 @@ import * as hostedAppRequests from './hostedapp.js';
|
|
|
23
23
|
import * as identityRequests from './identity.js';
|
|
24
24
|
import * as imageRequests from './image.js';
|
|
25
25
|
import * as informRequests from './inform.js';
|
|
26
|
+
import * as locationRequests from './location.js';
|
|
26
27
|
import * as logRequests from './log.js';
|
|
27
28
|
import * as mailRequests from './mail.js';
|
|
28
29
|
import * as migrationRequests from './migration.js';
|
|
@@ -64,6 +65,7 @@ export {
|
|
|
64
65
|
identityRequests as identity,
|
|
65
66
|
imageRequests as image,
|
|
66
67
|
informRequests as inform,
|
|
68
|
+
locationRequests as location,
|
|
67
69
|
logRequests as log,
|
|
68
70
|
mailRequests as mail,
|
|
69
71
|
migrationRequests as migration,
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import * as plugins from '../plugins.js';
|
|
2
|
+
import type { ICluster } from '../data/cluster.js';
|
|
3
|
+
import type { TSha256Digest } from '../data/immutableimage.js';
|
|
4
|
+
import type {
|
|
5
|
+
ILocation,
|
|
6
|
+
ILocationView,
|
|
7
|
+
TLocationMemberKind,
|
|
8
|
+
TSetClusterLocationOutcome,
|
|
9
|
+
} from '../data/location.js';
|
|
10
|
+
import type { IIdentity } from '../data/user.js';
|
|
11
|
+
|
|
12
|
+
/*
|
|
13
|
+
* Location administration. Every request here is an administrator's alone: no delegated-admin
|
|
14
|
+
* scope admits one (`data.delegatedAdminTokenScopeRequests`). Every refusal is one of
|
|
15
|
+
* `data.locationRefusals` and changes nothing.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/** An administrator creates a location; refused `location-name-invalid` or `location-name-taken`. */
|
|
19
|
+
export interface IReq_Any_Cloudly_CreateLocation extends plugins.typedrequestInterfaces.implementsTR<
|
|
20
|
+
plugins.typedrequestInterfaces.ITypedRequest,
|
|
21
|
+
IReq_Any_Cloudly_CreateLocation
|
|
22
|
+
> {
|
|
23
|
+
method: 'createLocation';
|
|
24
|
+
request: {
|
|
25
|
+
identity: IIdentity;
|
|
26
|
+
/** `data.isLocationName`, unique among locations. */
|
|
27
|
+
name: string;
|
|
28
|
+
};
|
|
29
|
+
response: {
|
|
30
|
+
location: ILocation;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* An administrator renames a location; its id and every reference stay. Renaming to the name it
|
|
36
|
+
* carries changes nothing. Refused `location-not-found`, `location-name-invalid` or
|
|
37
|
+
* `location-name-taken`.
|
|
38
|
+
*/
|
|
39
|
+
export interface IReq_Any_Cloudly_RenameLocation extends plugins.typedrequestInterfaces.implementsTR<
|
|
40
|
+
plugins.typedrequestInterfaces.ITypedRequest,
|
|
41
|
+
IReq_Any_Cloudly_RenameLocation
|
|
42
|
+
> {
|
|
43
|
+
method: 'renameLocation';
|
|
44
|
+
request: {
|
|
45
|
+
identity: IIdentity;
|
|
46
|
+
locationId: string;
|
|
47
|
+
/** `data.isLocationName`, unique among locations. */
|
|
48
|
+
name: string;
|
|
49
|
+
};
|
|
50
|
+
response: {
|
|
51
|
+
location: ILocation;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Every location with its members, its membership digest and whether that membership is confirmed. */
|
|
56
|
+
export interface IReq_Any_Cloudly_GetLocations extends plugins.typedrequestInterfaces.implementsTR<
|
|
57
|
+
plugins.typedrequestInterfaces.ITypedRequest,
|
|
58
|
+
IReq_Any_Cloudly_GetLocations
|
|
59
|
+
> {
|
|
60
|
+
method: 'getLocations';
|
|
61
|
+
request: {
|
|
62
|
+
identity: IIdentity;
|
|
63
|
+
};
|
|
64
|
+
response: {
|
|
65
|
+
/** Sorted by location id; exactly one has `receivesUnnamedCreates`. */
|
|
66
|
+
locations: ILocationView[];
|
|
67
|
+
/**
|
|
68
|
+
* The member kinds this Cloudly records, in `data.locationMemberKinds` order; every view's
|
|
69
|
+
* digest covers them. A kind missing here has no members anywhere yet, so a confirmation
|
|
70
|
+
* cannot vouch for it.
|
|
71
|
+
*/
|
|
72
|
+
recordedMemberKinds: TLocationMemberKind[];
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* An administrator moves a whole cluster to a location: every node of the cluster and the
|
|
78
|
+
* cluster's copy of each, in one transaction. A cluster without nodes stands nowhere, so the call
|
|
79
|
+
* moves nothing and answers `cluster-empty`. Refused `cluster-not-found`, `location-not-found` or
|
|
80
|
+
* `conflict`; never `cluster-spans-locations`, since the move also repairs a cluster whose nodes
|
|
81
|
+
* stand in more than one location.
|
|
82
|
+
*/
|
|
83
|
+
export interface IReq_Any_Cloudly_SetClusterLocation extends plugins.typedrequestInterfaces.implementsTR<
|
|
84
|
+
plugins.typedrequestInterfaces.ITypedRequest,
|
|
85
|
+
IReq_Any_Cloudly_SetClusterLocation
|
|
86
|
+
> {
|
|
87
|
+
method: 'setClusterLocation';
|
|
88
|
+
request: {
|
|
89
|
+
identity: IIdentity;
|
|
90
|
+
clusterId: string;
|
|
91
|
+
locationId: string;
|
|
92
|
+
};
|
|
93
|
+
response: {
|
|
94
|
+
outcome: TSetClusterLocationOutcome;
|
|
95
|
+
/** The cluster as it now stands. */
|
|
96
|
+
cluster: ICluster;
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* An administrator confirms that a location holds everything it should, stating the
|
|
102
|
+
* `membershipDigest` of the view they read. Refused `membership-changed` when the location's
|
|
103
|
+
* membership is no longer that one, and `location-not-found`. The confirmation holds until the
|
|
104
|
+
* membership changes; nothing rewrites it then.
|
|
105
|
+
*/
|
|
106
|
+
export interface IReq_Any_Cloudly_ConfirmLocationMembership extends plugins.typedrequestInterfaces.implementsTR<
|
|
107
|
+
plugins.typedrequestInterfaces.ITypedRequest,
|
|
108
|
+
IReq_Any_Cloudly_ConfirmLocationMembership
|
|
109
|
+
> {
|
|
110
|
+
method: 'confirmLocationMembership';
|
|
111
|
+
request: {
|
|
112
|
+
identity: IIdentity;
|
|
113
|
+
locationId: string;
|
|
114
|
+
membershipDigest: TSha256Digest;
|
|
115
|
+
};
|
|
116
|
+
response: {
|
|
117
|
+
location: ILocationView;
|
|
118
|
+
};
|
|
119
|
+
}
|