Skip to content

Commit 082028a

Browse files
Add:progress indicator during SageMaker space connection process
1 parent d7bbf39 commit 082028a

File tree

2 files changed

+61
-22
lines changed

2 files changed

+61
-22
lines changed

packages/core/src/awsService/sagemaker/commands.ts

Lines changed: 58 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -191,32 +191,69 @@ export async function openRemoteConnect(
191191
void vscode.window.showErrorMessage(ConnectFromRemoteWorkspaceMessage)
192192
return
193193
}
194-
await tryRefreshNode(node)
195-
if (node.getStatus() === 'Stopped') {
196-
// In case of SMUS, we pass in a SM Client and for SM AI, it creates a new SM Client.
197-
const client = sageMakerClient ? sageMakerClient : new SagemakerClient(node.regionCode)
198-
199-
try {
200-
await client.startSpace(node.spaceApp.SpaceName!, node.spaceApp.DomainId!)
201-
await tryRefreshNode(node)
202-
const appType = node.spaceApp.SpaceSettingsSummary?.AppType
203-
if (!appType) {
204-
throw new ToolkitError('AppType is undefined for the selected space. Cannot start remote connection.', {
205-
code: 'undefinedAppType',
206-
})
207-
}
208-
await client.waitForAppInService(node.spaceApp.DomainId!, node.spaceApp.SpaceName!, appType)
209-
await tryRemoteConnection(node, ctx)
210-
} catch (err: any) {
211-
// Ignore InstanceTypeError since it means the user decided not to use an instanceType with more memory
212-
if (err.code !== InstanceTypeError) {
194+
195+
const spaceName = node.spaceApp.SpaceName!
196+
197+
try {
198+
await tryRefreshNode(node)
199+
200+
// for Stopped SM spaces - check instance type before showing progress
201+
if (node.getStatus() === 'Stopped') {
202+
// In case of SMUS, we pass in a SM Client and for SM AI, it creates a new SM Client.
203+
const client = sageMakerClient ? sageMakerClient : new SagemakerClient(node.regionCode)
204+
205+
try {
206+
await client.startSpace(spaceName, node.spaceApp.DomainId!)
207+
await tryRefreshNode(node)
208+
const appType = node.spaceApp.SpaceSettingsSummary?.AppType
209+
if (!appType) {
210+
throw new ToolkitError(
211+
'AppType is undefined for the selected space. Cannot start remote connection.',
212+
{
213+
code: 'undefinedAppType',
214+
}
215+
)
216+
}
217+
218+
// Only start showing progress after instance type validation
219+
return await vscode.window.withProgress(
220+
{
221+
location: vscode.ProgressLocation.Notification,
222+
cancellable: false,
223+
title: `Connecting to ${spaceName}`,
224+
},
225+
async (progress) => {
226+
progress.report({ message: 'Starting the space. This can take around 2 minutes.' })
227+
await client.waitForAppInService(node.spaceApp.DomainId!, spaceName, appType)
228+
await tryRemoteConnection(node, ctx, progress)
229+
}
230+
)
231+
} catch (err: any) {
232+
// Ignore InstanceTypeError since it means the user decided not to use an instanceType with more memory
233+
// just return without showing progress
234+
if (err.code === InstanceTypeError) {
235+
return
236+
}
213237
throw new ToolkitError(`Remote connection failed: ${(err as Error).message}`, {
214238
cause: err as Error,
215239
code: err.code,
216240
})
217241
}
242+
} else if (node.getStatus() === 'Running') {
243+
// For running spaces, show progress
244+
return await vscode.window.withProgress(
245+
{
246+
location: vscode.ProgressLocation.Notification,
247+
cancellable: false,
248+
title: `Connecting to ${spaceName}`,
249+
},
250+
async (progress) => {
251+
await tryRemoteConnection(node, ctx, progress)
252+
}
253+
)
218254
}
219-
} else if (node.getStatus() === 'Running') {
220-
await tryRemoteConnection(node, ctx)
255+
} catch (err: any) {
256+
getLogger().error(`sm:openRemoteConnect: ${err}`)
257+
throw err
221258
}
222259
}

packages/core/src/awsService/sagemaker/model.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@ const logger = getLogger('sagemaker')
2727

2828
export async function tryRemoteConnection(
2929
node: SagemakerSpaceNode | SagemakerUnifiedStudioSpaceNode,
30-
ctx: vscode.ExtensionContext
30+
ctx: vscode.ExtensionContext,
31+
progress: vscode.Progress<{ message?: string; increment?: number }>
3132
) {
3233
const spaceArn = (await node.getSpaceArn()) as string
3334
const isSMUS = node instanceof SagemakerUnifiedStudioSpaceNode
3435
const remoteEnv = await prepareDevEnvConnection(spaceArn, ctx, 'sm_lc', isSMUS, node)
3536
try {
37+
progress.report({ message: 'Opening remote session' })
3638
await startVscodeRemote(
3739
remoteEnv.SessionProcess,
3840
remoteEnv.hostname,

0 commit comments

Comments
 (0)