Skip to content

Commit e45d290

Browse files
committed
feat(FR-777): use resource limit of resource group
1 parent e8f798c commit e45d290

4 files changed

Lines changed: 213 additions & 36 deletions

File tree

react/data/schema.graphql

Lines changed: 183 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,37 @@ type Queries {
99
"""The ID of the object"""
1010
id: ID!
1111
): Node
12+
13+
"""Added in 25.6.0."""
14+
audit_log_schema: AuditLogSchema
15+
16+
"""Added in 25.6.0."""
17+
audit_log_nodes(
18+
"""
19+
Specifies the criteria used to narrow down the query results based on certain conditions.
20+
"""
21+
filter: String
22+
23+
"""Specifies the sorting order of the query result."""
24+
order: String
25+
26+
"""Specifies how many items to skip before beginning to return result."""
27+
offset: Int
28+
29+
"""If this value is provided, the query will be limited to that value."""
30+
before: String
31+
32+
"""Queries the `last` number of results from the query result from last."""
33+
after: String
34+
35+
"""
36+
Queries the `first` number of results from the query result from first.
37+
"""
38+
first: Int
39+
40+
"""If the given value is provided, the query will start from that value."""
41+
last: Int
42+
): AuditLogConnection
1243
agent(agent_id: String!): Agent
1344
agent_list(limit: Int!, offset: Int!, filter: String, order: String, scaling_group: String, status: String): AgentList
1445
agents(scaling_group: String, status: String): [Agent]
@@ -245,6 +276,23 @@ type Queries {
245276
compute_container_list(limit: Int!, offset: Int!, filter: String, order: String, session_id: ID!, role: String): ComputeContainerList
246277
legacy_compute_session_list(limit: Int!, offset: Int!, order_key: String, order_asc: Boolean, domain_name: String, group_id: String, access_key: String, status: String): LegacyComputeSessionList
247278
legacy_compute_session(sess_id: String!, domain_name: String, access_key: String): LegacyComputeSession
279+
280+
"""Added in 25.5.0."""
281+
total_resource_slot(
282+
"""
283+
`statuses` argument is an array of session statuses. Only sessions with the specified statuses will be queried to calculate the sum of total resource slots. The argument should be an array of the following valid status values: ['PENDING', 'SCHEDULED', 'PREPARING', 'PULLING', 'PREPARED', 'CREATING', 'RUNNING', 'RESTARTING', 'RUNNING_DEGRADED', 'TERMINATING', 'TERMINATED', 'ERROR', 'CANCELLED'].
284+
Default value is null.
285+
"""
286+
statuses: [String] = null
287+
288+
"""
289+
`filter` argument is a string that is parsed into query conditions. It works in the same way as the `filter` argument in the `compute_session` query schema, meaning the values are parsed into an identical SQL query expression.
290+
Default value is `null`.
291+
"""
292+
filter: String
293+
domain_name: String
294+
resource_group_name: String
295+
): TotalResourceSlot
248296
vfolder_host_permissions: PredefinedAtomicPermission
249297
endpoint(endpoint_id: UUID!): Endpoint
250298
endpoint_list(limit: Int!, offset: Int!, filter: String, order: String, domain_name: String, group_id: String, user_uuid: String, project: UUID): EndpointList
@@ -290,6 +338,108 @@ interface Node {
290338
id: ID!
291339
}
292340

341+
"""
342+
A schema that contains metadata related to the AuditLogNode.
343+
It provides a list of values, such as entity_type and status, that can be used in the AuditLog, allowing clients to retrieve them.
344+
345+
Added in 25.6.0.
346+
"""
347+
type AuditLogSchema {
348+
"""
349+
Possible values of "AuditLogNode.entity_type"
350+
"""
351+
entity_type_variants: [String]
352+
353+
"""
354+
Possible values of "AuditLogNode.status"
355+
"""
356+
status_variants: [String]
357+
}
358+
359+
"""Added in 25.6.0."""
360+
type AuditLogConnection {
361+
"""Pagination data for this connection."""
362+
pageInfo: PageInfo!
363+
364+
"""Contains the nodes in this connection."""
365+
edges: [AuditLogEdge]!
366+
367+
"""Total count of the GQL nodes of the query."""
368+
count: Int
369+
}
370+
371+
"""
372+
The Relay compliant `PageInfo` type, containing data necessary to paginate this connection.
373+
"""
374+
type PageInfo {
375+
"""When paginating forwards, are there more items?"""
376+
hasNextPage: Boolean!
377+
378+
"""When paginating backwards, are there more items?"""
379+
hasPreviousPage: Boolean!
380+
381+
"""When paginating backwards, the cursor to continue."""
382+
startCursor: String
383+
384+
"""When paginating forwards, the cursor to continue."""
385+
endCursor: String
386+
}
387+
388+
"""Added in 25.6.0. A Relay edge containing a `AuditLog` and its cursor."""
389+
type AuditLogEdge {
390+
"""The item at the end of the edge"""
391+
node: AuditLogNode
392+
393+
"""A cursor for use in pagination"""
394+
cursor: String!
395+
}
396+
397+
"""Added in 25.6.0."""
398+
type AuditLogNode implements Node {
399+
"""The ID of the object"""
400+
id: ID!
401+
402+
"""UUID of the audit log row"""
403+
row_id: UUID!
404+
405+
"""Entity ID of the AuditLog"""
406+
entity_type: String!
407+
408+
"""Entity type of the AuditLog"""
409+
operation: String!
410+
411+
"""Operation type of the AuditLog"""
412+
entity_id: String!
413+
414+
"""The time the AuditLog was reported"""
415+
created_at: DateTime!
416+
417+
"""RequestID of the AuditLog"""
418+
request_id: UUID!
419+
420+
"""Description of the AuditLog"""
421+
description: String!
422+
423+
"""Duration taken to perform the operation"""
424+
duration: String!
425+
426+
"""Status of the AuditLog"""
427+
status: String!
428+
}
429+
430+
"""
431+
Leverages the internal Python implementation of UUID (uuid.UUID) to provide native UUID objects
432+
in fields, resolvers and input.
433+
"""
434+
scalar UUID
435+
436+
"""
437+
The `DateTime` scalar type represents a DateTime
438+
value as specified by
439+
[iso8601](https://en.wikipedia.org/wiki/ISO_8601).
440+
"""
441+
scalar DateTime
442+
293443
type Agent implements Item {
294444
id: ID
295445
status: String
@@ -330,13 +480,6 @@ interface Item {
330480
id: ID
331481
}
332482

333-
"""
334-
The `DateTime` scalar type represents a DateTime
335-
value as specified by
336-
[iso8601](https://en.wikipedia.org/wiki/ISO_8601).
337-
"""
338-
scalar DateTime
339-
340483
"""
341484
Allows use of a JSON String for input / output from the GraphQL schema.
342485
@@ -391,12 +534,6 @@ type ComputeContainer implements Item {
391534
preopen_ports: [Int]
392535
}
393536

394-
"""
395-
Leverages the internal Python implementation of UUID (uuid.UUID) to provide native UUID objects
396-
in fields, resolvers and input.
397-
"""
398-
scalar UUID
399-
400537
type ImageNode implements Node {
401538
"""The ID of the object"""
402539
id: ID!
@@ -522,23 +659,6 @@ type ScalinGroupConnection {
522659
count: Int
523660
}
524661

525-
"""
526-
The Relay compliant `PageInfo` type, containing data necessary to paginate this connection.
527-
"""
528-
type PageInfo {
529-
"""When paginating forwards, are there more items?"""
530-
hasNextPage: Boolean!
531-
532-
"""When paginating backwards, are there more items?"""
533-
hasPreviousPage: Boolean!
534-
535-
"""When paginating backwards, the cursor to continue."""
536-
startCursor: String
537-
538-
"""When paginating forwards, the cursor to continue."""
539-
endCursor: String
540-
}
541-
542662
"""
543663
Added in 24.12.0. A Relay edge containing a `ScalinGroup` and its cursor.
544664
"""
@@ -836,6 +956,9 @@ type UserNode implements Node {
836956
Added in 25.2.0. Supplementary group IDs assigned to processes running inside the container.
837957
"""
838958
container_gids: [Int]
959+
960+
"""Added in 25.5.0."""
961+
project_nodes(filter: String, order: String, offset: Int, before: String, after: String, first: Int, last: Int): GroupConnection
839962
}
840963

841964
"""Added in 24.03.0"""
@@ -1245,6 +1368,9 @@ type ScalingGroup {
12451368
status: String = "ALIVE"
12461369
): JSONString
12471370

1371+
"""Added in 25.6.0. The resource slot hard-limit of the resource group."""
1372+
resource_slot_limit: JSONString
1373+
12481374
"""
12491375
Added in 25.4.0. The sum of occupied slots across compute sessions that occupying agent's resources. Only includes sessions owned by the user.
12501376
"""
@@ -1515,6 +1641,13 @@ type LegacyComputeSession implements Item {
15151641
io_cur_scratch_size: BigInt
15161642
}
15171643

1644+
"""Added in 25.5.0."""
1645+
type TotalResourceSlot implements Item {
1646+
id: ID
1647+
occupied_slots: JSONString
1648+
requested_slots: JSONString
1649+
}
1650+
15181651
type PredefinedAtomicPermission {
15191652
vfolder_host_permission_list: [String]
15201653
}
@@ -1992,7 +2125,7 @@ type Mutations {
19922125
clear_images(registry: String): ClearImages
19932126

19942127
"""Added in 25.4.0"""
1995-
purge_images(agent_id: String!, images: [ImageRefType]!): PurgeImages
2128+
purge_images(keys: [PurgeImagesKey]!, options: PurgeImagesOptions = {force: false, noprune: false}): PurgeImagesPayload
19962129

19972130
"""Added in 24.09.0."""
19982131
modify_compute_session(input: ModifyComputeSessionInput!): ModifyComputeSessionPayload
@@ -2592,17 +2725,34 @@ type ClearImages {
25922725
msg: String
25932726
}
25942727

2595-
"""Added in 25.4.0."""
2596-
type PurgeImages {
2728+
"""Added in 25.6.0."""
2729+
type PurgeImagesPayload {
25972730
task_id: String
25982731
}
25992732

2733+
"""Added in 25.6.0."""
2734+
input PurgeImagesKey {
2735+
agent_id: String!
2736+
images: [ImageRefType]!
2737+
}
2738+
26002739
input ImageRefType {
26012740
name: String!
26022741
registry: String
26032742
architecture: String
26042743
}
26052744

2745+
"""Added in 25.6.0."""
2746+
input PurgeImagesOptions {
2747+
"""
2748+
Remove the images even if it is being used by stopped containers or has other tags, Added in 25.6.0.
2749+
"""
2750+
force: Boolean = false
2751+
2752+
"""Don't delete untagged parent images, Added in 25.6.0."""
2753+
noprune: Boolean = false
2754+
}
2755+
26062756
"""Added in 24.09.0."""
26072757
type ModifyComputeSessionPayload {
26082758
item: ComputeSessionNode

react/src/components/DynamicUnitInputNumberWithSlider.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { compareNumberWithUnits, convertBinarySizeUnit } from '../helper';
1+
import {
2+
compareNumberWithUnits,
3+
convertBinarySizeUnit,
4+
toFixedFloorWithoutTrailingZeros,
5+
} from '../helper';
26
import { useUpdatableState } from '../hooks';
37
import useControllableState from '../hooks/useControllableState';
48
import DynamicUnitInputNumber, {
@@ -222,8 +226,12 @@ const DynamicUnitInputNumberWithSlider: React.FC<
222226
maxGiB.number === 0
223227
? maxGiB.number
224228
: maxGiB.number >= 1
225-
? maxGiB.number + 'g'
226-
: maxGiB.number * 1024 + 'm',
229+
? toFixedFloorWithoutTrailingZeros(maxGiB.number, 2) +
230+
'g'
231+
: toFixedFloorWithoutTrailingZeros(
232+
maxGiB.number * 1024,
233+
2,
234+
) + 'm',
227235
},
228236
}),
229237
})}

react/src/components/ResourceAllocationFormItems.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ const ResourceAllocationFormItems: React.FC<
128128
accelerator_quantum_size
129129
name
130130
is_active
131+
...useResourceLimitAndRemainingFragment
131132
}
132133
}
133134
`,
@@ -164,6 +165,7 @@ const ResourceAllocationFormItems: React.FC<
164165
useResourceLimitAndRemaining({
165166
currentProjectName: currentProject.name,
166167
currentResourceGroup: currentResourceGroupInForm || undefined, // global currentResourceGroup can be null
168+
currentResourceGroupFrgmt: currentResourceGroupInfo,
167169
currentImage: currentImage,
168170
});
169171

react/src/hooks/useResourceLimitAndRemaining.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@ import { Image } from '../components/ImageEnvironmentSelectFormItems';
33
import { AUTOMATIC_DEFAULT_SHMEM } from '../components/ResourceAllocationFormItems';
44
import { addNumberWithUnits, convertBinarySizeUnit } from '../helper';
55
import { ResourceSlotName, useResourceSlots } from '../hooks/backendai';
6+
import { useResourceLimitAndRemainingFragment$key } from './__generated__/useResourceLimitAndRemainingFragment.graphql';
67
import { useSuspenseTanQuery } from './reactQueryAlias';
78
import { useResourceGroupsForCurrentProject } from './useCurrentProject';
9+
import graphql from 'babel-plugin-relay/macro';
810
import _ from 'lodash';
911
import { useMemo } from 'react';
12+
import { useFragment } from 'react-relay';
1013

1114
const maxPerContainerRegex = /^max([A-Za-z0-9]+)PerContainer$/;
1215

@@ -96,6 +99,7 @@ interface Props {
9699
currentProjectName: string;
97100
currentImage?: Image;
98101
currentResourceGroup?: string;
102+
currentResourceGroupFrgmt?: useResourceLimitAndRemainingFragment$key | null;
99103
ignorePerContainerConfig?: boolean;
100104
fetchKey?: string;
101105
}
@@ -104,6 +108,7 @@ interface Props {
104108
export const useResourceLimitAndRemaining = ({
105109
currentImage,
106110
currentResourceGroup = '',
111+
currentResourceGroupFrgmt = null,
107112
currentProjectName,
108113
ignorePerContainerConfig = false,
109114
fetchKey,
@@ -113,6 +118,18 @@ export const useResourceLimitAndRemaining = ({
113118
const acceleratorSlots = _.omit(resourceSlots, ['cpu', 'mem', 'shmem']);
114119
const { resourceGroups } = useResourceGroupsForCurrentProject();
115120

121+
const currentResourceGroupInfo = useFragment(
122+
graphql`
123+
fragment useResourceLimitAndRemainingFragment on ScalingGroup {
124+
name
125+
max_available_slots_for_each_resource
126+
min_available_slots_for_each_resource
127+
}
128+
`,
129+
currentResourceGroupFrgmt,
130+
);
131+
132+
console.log('#', currentResourceGroupInfo);
116133
const {
117134
data: checkPresetInfo,
118135
refetch,

0 commit comments

Comments
 (0)