Skip to content

Commit b2ad530

Browse files
committed
feat(FR-1004): use server provided session resource setting in launching session
1 parent 72f49f9 commit b2ad530

File tree

6 files changed

+40
-45
lines changed

6 files changed

+40
-45
lines changed

react/src/components/ComputeSessionNodeItems/SessionActionButtons.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ interface SessionActionButtonsProps {
5454
}
5555

5656
const isActive = (session: SessionActionButtonsFragment$data) => {
57+
if (session?.type === 'system') {
58+
return session?.status === 'RUNNING';
59+
}
5760
return !['TERMINATED', 'CANCELLED', 'TERMINATING'].includes(
5861
session?.status || '',
5962
);
@@ -283,9 +286,7 @@ const SessionActionButtons: React.FC<SessionActionButtonsProps> = ({
283286
<Tooltip title={t('data.explorer.RunSSH/SFTPserver')}>
284287
<Button
285288
type="primary"
286-
disabled={
287-
!isAppSupported(session) || !isActive(session) || !isOwner
288-
}
289+
disabled={!isActive(session) || !isOwner}
289290
size={size}
290291
icon={<BAISftpIcon />}
291292
onClick={() => {

react/src/components/FileBrowserButton.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ const FileBrowserButton: React.FC<FileBrowserButtonProps> = ({
102102
return;
103103
}
104104
const fileBrowserFormValue: StartSessionWithDefaultValue = {
105+
// If the resource setting is not included when the session is created,
106+
// it is created with the value determined by the server.
105107
sessionName: `filebrowser-${vfolder.row_id}`,
106108
sessionType: 'interactive',
107109
// use default file browser image if configured and allowed
@@ -112,10 +114,6 @@ const FileBrowserButton: React.FC<FileBrowserButtonProps> = ({
112114
cluster_mode: 'single-node',
113115
cluster_size: 1,
114116
mount_ids: [vfolder.row_id?.replaceAll('-', '') || ''],
115-
resource: {
116-
cpu: 1,
117-
mem: '0.5g',
118-
},
119117
};
120118

121119
await startSessionWithDefault(fileBrowserFormValue)

react/src/components/SFTPServerButton.tsx

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ const SFTPServerButton: React.FC<SFTPServerButtonProps> = ({
5555
useStartSession();
5656
const { upsertNotification } = useSetBAINotification();
5757

58-
const { systemSSHImage, systemSSHImageInfo } =
59-
useDefaultSystemSSHImageWithFallback();
58+
const { systemSSHImage } = useDefaultSystemSSHImageWithFallback();
6059

6160
const vfolder = useFragment(
6261
graphql`
@@ -110,18 +109,9 @@ const SFTPServerButton: React.FC<SFTPServerButtonProps> = ({
110109
/>
111110
}
112111
action={async () => {
113-
const resource: StartSessionWithDefaultValue['resource'] = {
114-
cpu:
115-
_.toNumber(
116-
_.find(systemSSHImageInfo?.resource_limits, { key: 'cpu' })
117-
?.min,
118-
) || 2,
119-
mem:
120-
_.find(systemSSHImageInfo?.resource_limits, { key: 'mem' })
121-
?.min || '0.5g',
122-
};
123-
124112
const sftpSessionConf: StartSessionWithDefaultValue = {
113+
// If the resource setting is not included when the session is created,
114+
// it is created with the value determined by the server.
125115
sessionName: `sftp-${vfolder?.row_id}`,
126116
sessionType: 'system',
127117
// use default system SSH image if configured and allowed
@@ -142,10 +132,6 @@ const SFTPServerButton: React.FC<SFTPServerButtonProps> = ({
142132
cluster_size: 1,
143133
mount_ids: [vfolder?.row_id?.replaceAll('-', '') || ''],
144134
resourceGroup: sftpScalingGroupByCurrentProject?.[0],
145-
resource: {
146-
cpu: resource.cpu < 2 ? 2 : resource.cpu,
147-
mem: resource.mem,
148-
},
149135
};
150136

151137
await startSessionWithDefault(sftpSessionConf)

react/src/components/SessionFormItems/ResourceAllocationFormItems.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ const ResourceAllocationFormItems: React.FC<
138138
accessible_scaling_groups,
139139
(group) => group?.name === currentResourceGroupInForm,
140140
);
141+
const currentResourceValue = Form.useWatch(['resource']);
141142
const currentImage = Form.useWatch(['environments', 'image'], {
142143
form,
143144
preserve: true,
@@ -205,14 +206,19 @@ const ResourceAllocationFormItems: React.FC<
205206
}, [currentImage, acceleratorSlotsInRG, currentEnvironmentManual]);
206207

207208
useEffect(() => {
209+
if (!currentResourceValue) {
210+
form.setFieldsValue({
211+
allocationPreset: 'auto-select',
212+
});
213+
}
208214
if (supportedAcceleratorTypesInRGByImage?.length === 0) {
209215
form.setFieldsValue({
210216
resource: {
211217
accelerator: 0,
212218
},
213219
});
214220
}
215-
}, [supportedAcceleratorTypesInRGByImage, form]);
221+
}, [supportedAcceleratorTypesInRGByImage, form, currentResourceValue]);
216222

217223
const sessionSliderLimitAndRemaining = {
218224
min: 1,

react/src/hooks/useStartSession.tsx

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ export const useStartSession = () => {
136136
baiClient._config.default_session_environment,
137137
),
138138
}),
139-
...RESOURCE_ALLOCATION_INITIAL_FORM_VALUES,
139+
..._.omit(RESOURCE_ALLOCATION_INITIAL_FORM_VALUES, ['resource']),
140140
resourceGroup: currentGlobalResourceGroup || undefined,
141141
};
142142

@@ -214,26 +214,30 @@ export const useStartSession = () => {
214214

215215
config: {
216216
// Resource allocation
217-
resources: {
218-
cpu: values.resource.cpu,
219-
mem: values.resource.mem,
220-
// Add accelerator only if specified
221-
...(values.resource?.acceleratorType &&
222-
values.resource?.accelerator &&
223-
values.resource?.accelerator > 0
224-
? {
225-
[values.resource.acceleratorType]:
226-
values.resource.accelerator,
227-
}
228-
: undefined),
229-
},
217+
...(values?.resource && {
218+
resources: {
219+
cpu: values?.resource?.cpu,
220+
mem: values?.resource?.mem,
221+
// Add accelerator only if specified
222+
...(values.resource?.acceleratorType &&
223+
values.resource?.accelerator &&
224+
values.resource?.accelerator > 0
225+
? {
226+
[values.resource.acceleratorType]:
227+
values.resource.accelerator,
228+
}
229+
: undefined),
230+
},
231+
}),
230232
scaling_group: values.owner?.enabled
231233
? values.owner.project
232234
: values.resourceGroup,
233-
resource_opts: {
234-
shmem: values.resource.shmem,
235-
// allow_fractional_resource_fragmentation can be added here if needed
236-
},
235+
...(values?.resource && {
236+
resource_opts: {
237+
shmem: values?.resource?.shmem,
238+
// allow_fractional_resource_fragmentation can be added here if needed
239+
},
240+
}),
237241

238242
// Storage configuration
239243
[supportsMountById ? 'mount_ids' : 'mounts']: values.mount_ids,
@@ -277,7 +281,7 @@ export const useStartSession = () => {
277281
.createIfNotExists(
278282
sessionInfo.kernelName,
279283
formattedSessionName,
280-
sessionInfo.resources,
284+
sessionInfo?.resources,
281285
undefined,
282286
sessionInfo.architecture,
283287
)

react/src/pages/SessionLauncherPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ const SessionLauncherPage = () => {
277277
// eslint-disable-next-line react-hooks/exhaustive-deps
278278
}, []);
279279

280-
const mergedInitialValues = useMemo(() => {
280+
const mergedInitialValues: SessionLauncherFormValue = useMemo(() => {
281281
return _.merge({}, defaultFormValues, formValuesFromQueryParams);
282282
}, [defaultFormValues, formValuesFromQueryParams]);
283283

0 commit comments

Comments
 (0)