Skip to content

Commit e742fcc

Browse files
authored
feat(rdb): add apply maintenance (#1200)
1 parent dbc4c9a commit e742fcc

File tree

10 files changed

+129
-36
lines changed

10 files changed

+129
-36
lines changed

packages/clients/src/api/document_db/v1beta1/api.gen.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import {
5656
unmarshalListPrivilegesResponse,
5757
unmarshalListSnapshotsResponse,
5858
unmarshalListUsersResponse,
59+
unmarshalMaintenance,
5960
unmarshalPrivilege,
6061
unmarshalReadReplica,
6162
unmarshalSetInstanceACLRulesResponse,
@@ -68,6 +69,7 @@ import type {
6869
AddInstanceACLRulesResponse,
6970
AddInstanceSettingsRequest,
7071
AddInstanceSettingsResponse,
72+
ApplyInstanceMaintenanceRequest,
7173
CloneInstanceRequest,
7274
CreateDatabaseRequest,
7375
CreateEndpointRequest,
@@ -119,6 +121,7 @@ import type {
119121
ListSnapshotsResponse,
120122
ListUsersRequest,
121123
ListUsersResponse,
124+
Maintenance,
122125
MigrateEndpointRequest,
123126
Privilege,
124127
PromoteReadReplicaRequest,
@@ -1292,4 +1295,24 @@ export class API extends ParentAPI {
12921295
},
12931296
unmarshalEndpoint,
12941297
)
1298+
1299+
/**
1300+
* Apply an instance maintenance. Apply a pending instance maintenance on your
1301+
* instance. This action can generate some service interruption.
1302+
*
1303+
* @param request - The request {@link ApplyInstanceMaintenanceRequest}
1304+
* @returns A Promise of Maintenance
1305+
*/
1306+
applyInstanceMaintenance = (
1307+
request: Readonly<ApplyInstanceMaintenanceRequest>,
1308+
) =>
1309+
this.client.fetch<Maintenance>(
1310+
{
1311+
body: '{}',
1312+
headers: jsonContentHeaders,
1313+
method: 'POST',
1314+
path: `/document-db/v1beta1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/instances/${validatePathParam('instanceId', request.instanceId)}/apply-maintenance`,
1315+
},
1316+
unmarshalMaintenance,
1317+
)
12951318
}

packages/clients/src/api/document_db/v1beta1/content.gen.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ export const INSTANCE_TRANSIENT_STATUSES: InstanceStatus[] = [
2424
]
2525

2626
/** Lists transient statutes of the enum {@link MaintenanceStatus}. */
27-
export const MAINTENANCE_TRANSIENT_STATUSES: MaintenanceStatus[] = ['pending']
27+
export const MAINTENANCE_TRANSIENT_STATUSES: MaintenanceStatus[] = [
28+
'pending',
29+
'ongoing',
30+
]
2831

2932
/** Lists transient statutes of the enum {@link ReadReplicaStatus}. */
3033
export const READ_REPLICA_TRANSIENT_STATUSES: ReadReplicaStatus[] = [

packages/clients/src/api/document_db/v1beta1/index.gen.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export type {
1212
AddInstanceACLRulesResponse,
1313
AddInstanceSettingsRequest,
1414
AddInstanceSettingsResponse,
15+
ApplyInstanceMaintenanceRequest,
1516
BackupSchedule,
1617
CloneInstanceRequest,
1718
CreateDatabaseRequest,

packages/clients/src/api/document_db/v1beta1/marshalling.gen.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,23 @@ export const unmarshalEndpoint = (data: unknown): Endpoint => {
152152
} as Endpoint
153153
}
154154

155+
export const unmarshalMaintenance = (data: unknown): Maintenance => {
156+
if (!isJSONObject(data)) {
157+
throw new TypeError(
158+
`Unmarshalling the type 'Maintenance' failed as data isn't a dictionary.`,
159+
)
160+
}
161+
162+
return {
163+
closedAt: unmarshalDate(data.closed_at),
164+
forcedAt: unmarshalDate(data.forced_at),
165+
reason: data.reason,
166+
startsAt: unmarshalDate(data.starts_at),
167+
status: data.status,
168+
stopsAt: unmarshalDate(data.stops_at),
169+
} as Maintenance
170+
}
171+
155172
export const unmarshalReadReplica = (data: unknown): ReadReplica => {
156173
if (!isJSONObject(data)) {
157174
throw new TypeError(
@@ -242,22 +259,6 @@ const unmarshalLogsPolicy = (data: unknown): LogsPolicy => {
242259
} as LogsPolicy
243260
}
244261

245-
const unmarshalMaintenance = (data: unknown): Maintenance => {
246-
if (!isJSONObject(data)) {
247-
throw new TypeError(
248-
`Unmarshalling the type 'Maintenance' failed as data isn't a dictionary.`,
249-
)
250-
}
251-
252-
return {
253-
closedAt: unmarshalDate(data.closed_at),
254-
reason: data.reason,
255-
startsAt: unmarshalDate(data.starts_at),
256-
status: data.status,
257-
stopsAt: unmarshalDate(data.stops_at),
258-
} as Maintenance
259-
}
260-
261262
const unmarshalUpgradableVersion = (data: unknown): UpgradableVersion => {
262263
if (!isJSONObject(data)) {
263264
throw new TypeError(

packages/clients/src/api/document_db/v1beta1/types.gen.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,12 @@ export type ListUsersRequestOrderBy =
6666
| 'is_admin_asc'
6767
| 'is_admin_desc'
6868

69-
export type MaintenanceStatus = 'unknown' | 'pending' | 'done' | 'canceled'
69+
export type MaintenanceStatus =
70+
| 'unknown'
71+
| 'pending'
72+
| 'done'
73+
| 'canceled'
74+
| 'ongoing'
7075

7176
export type NodeTypeGeneration =
7277
| 'unknown_generation'
@@ -290,6 +295,8 @@ export interface Maintenance {
290295
reason: string
291296
/** Status of the maintenance. */
292297
status: MaintenanceStatus
298+
/** Time when Scaleway-side maintenance will be applied. */
299+
forcedAt?: Date
293300
}
294301

295302
export interface ReadReplica {
@@ -623,6 +630,16 @@ export interface AddInstanceSettingsResponse {
623630
settings: InstanceSetting[]
624631
}
625632

633+
export type ApplyInstanceMaintenanceRequest = {
634+
/**
635+
* Region to target. If none is passed will use default region from the
636+
* config.
637+
*/
638+
region?: Region
639+
/** UUID of the Database Instance to which you want to apply maintenance. */
640+
instanceId: string
641+
}
642+
626643
export type CloneInstanceRequest = {
627644
/**
628645
* Region to target. If none is passed will use default region from the

packages/clients/src/api/rdb/v1/api.gen.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ import {
6363
unmarshalListPrivilegesResponse,
6464
unmarshalListSnapshotsResponse,
6565
unmarshalListUsersResponse,
66+
unmarshalMaintenance,
6667
unmarshalPrepareInstanceLogsResponse,
6768
unmarshalPrivilege,
6869
unmarshalReadReplica,
@@ -76,6 +77,7 @@ import type {
7677
AddInstanceACLRulesResponse,
7778
AddInstanceSettingsRequest,
7879
AddInstanceSettingsResponse,
80+
ApplyInstanceMaintenanceRequest,
7981
CloneInstanceRequest,
8082
CreateDatabaseBackupRequest,
8183
CreateDatabaseRequest,
@@ -134,6 +136,7 @@ import type {
134136
ListSnapshotsResponse,
135137
ListUsersRequest,
136138
ListUsersResponse,
139+
Maintenance,
137140
MigrateEndpointRequest,
138141
PrepareInstanceLogsRequest,
139142
PrepareInstanceLogsResponse,
@@ -1509,4 +1512,27 @@ export class API extends ParentAPI {
15091512
},
15101513
unmarshalEndpoint,
15111514
)
1515+
1516+
/**
1517+
* Apply Database Instance maintenance. Apply maintenance tasks to your
1518+
* Database Instance. This will trigger pending maintenance tasks to start in
1519+
* your Database Instance and can generate service interruption. Maintenance
1520+
* tasks can be applied between `starts_at` and `stops_at` times, and are run
1521+
* directly by Scaleway at `forced_at` timestamp.
1522+
*
1523+
* @param request - The request {@link ApplyInstanceMaintenanceRequest}
1524+
* @returns A Promise of Maintenance
1525+
*/
1526+
applyInstanceMaintenance = (
1527+
request: Readonly<ApplyInstanceMaintenanceRequest>,
1528+
) =>
1529+
this.client.fetch<Maintenance>(
1530+
{
1531+
body: '{}',
1532+
headers: jsonContentHeaders,
1533+
method: 'POST',
1534+
path: `/rdb/v1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/instances/${validatePathParam('instanceId', request.instanceId)}/apply-maintenance`,
1535+
},
1536+
unmarshalMaintenance,
1537+
)
15121538
}

packages/clients/src/api/rdb/v1/content.gen.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ export const INSTANCE_TRANSIENT_STATUSES: InstanceStatus[] = [
3333
]
3434

3535
/** Lists transient statutes of the enum {@link MaintenanceStatus}. */
36-
export const MAINTENANCE_TRANSIENT_STATUSES: MaintenanceStatus[] = ['pending']
36+
export const MAINTENANCE_TRANSIENT_STATUSES: MaintenanceStatus[] = [
37+
'pending',
38+
'ongoing',
39+
]
3740

3841
/** Lists transient statutes of the enum {@link ReadReplicaStatus}. */
3942
export const READ_REPLICA_TRANSIENT_STATUSES: ReadReplicaStatus[] = [

packages/clients/src/api/rdb/v1/index.gen.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export type {
1212
AddInstanceACLRulesResponse,
1313
AddInstanceSettingsRequest,
1414
AddInstanceSettingsResponse,
15+
ApplyInstanceMaintenanceRequest,
1516
BackupSchedule,
1617
CloneInstanceRequest,
1718
CreateDatabaseBackupRequest,

packages/clients/src/api/rdb/v1/marshalling.gen.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,23 @@ export const unmarshalEndpoint = (data: unknown): Endpoint => {
159159
} as Endpoint
160160
}
161161

162+
export const unmarshalMaintenance = (data: unknown): Maintenance => {
163+
if (!isJSONObject(data)) {
164+
throw new TypeError(
165+
`Unmarshalling the type 'Maintenance' failed as data isn't a dictionary.`,
166+
)
167+
}
168+
169+
return {
170+
closedAt: unmarshalDate(data.closed_at),
171+
forcedAt: unmarshalDate(data.forced_at),
172+
reason: data.reason,
173+
startsAt: unmarshalDate(data.starts_at),
174+
status: data.status,
175+
stopsAt: unmarshalDate(data.stops_at),
176+
} as Maintenance
177+
}
178+
162179
export const unmarshalReadReplica = (data: unknown): ReadReplica => {
163180
if (!isJSONObject(data)) {
164181
throw new TypeError(
@@ -275,22 +292,6 @@ const unmarshalLogsPolicy = (data: unknown): LogsPolicy => {
275292
} as LogsPolicy
276293
}
277294

278-
const unmarshalMaintenance = (data: unknown): Maintenance => {
279-
if (!isJSONObject(data)) {
280-
throw new TypeError(
281-
`Unmarshalling the type 'Maintenance' failed as data isn't a dictionary.`,
282-
)
283-
}
284-
285-
return {
286-
closedAt: unmarshalDate(data.closed_at),
287-
reason: data.reason,
288-
startsAt: unmarshalDate(data.starts_at),
289-
status: data.status,
290-
stopsAt: unmarshalDate(data.stops_at),
291-
} as Maintenance
292-
}
293-
294295
const unmarshalUpgradableVersion = (data: unknown): UpgradableVersion => {
295296
if (!isJSONObject(data)) {
296297
throw new TypeError(

packages/clients/src/api/rdb/v1/types.gen.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,12 @@ export type ListUsersRequestOrderBy =
8484
| 'is_admin_asc'
8585
| 'is_admin_desc'
8686

87-
export type MaintenanceStatus = 'unknown' | 'pending' | 'done' | 'canceled'
87+
export type MaintenanceStatus =
88+
| 'unknown'
89+
| 'pending'
90+
| 'done'
91+
| 'canceled'
92+
| 'ongoing'
8893

8994
export type NodeTypeGeneration =
9095
| 'unknown_generation'
@@ -308,6 +313,8 @@ export interface Maintenance {
308313
reason: string
309314
/** Status of the maintenance. */
310315
status: MaintenanceStatus
316+
/** Time when Scaleway-side maintenance will be applied. */
317+
forcedAt?: Date
311318
}
312319

313320
export interface ReadReplica {
@@ -674,6 +681,16 @@ export interface AddInstanceSettingsResponse {
674681
settings: InstanceSetting[]
675682
}
676683

684+
export type ApplyInstanceMaintenanceRequest = {
685+
/**
686+
* Region to target. If none is passed will use default region from the
687+
* config.
688+
*/
689+
region?: Region
690+
/** UUID of the Database Instance you want to apply maintenance. */
691+
instanceId: string
692+
}
693+
677694
export type CloneInstanceRequest = {
678695
/**
679696
* Region to target. If none is passed will use default region from the

0 commit comments

Comments
 (0)