Skip to content

Commit c502ec0

Browse files
committed
update space before creating new app if space setting is changed
1 parent d93cf4d commit c502ec0

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

packages/core/src/shared/clients/sagemaker.ts

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -181,16 +181,31 @@ export class SagemakerClient extends ClientWrapper<SageMakerClient> {
181181
instanceType = InstanceTypeMinimum
182182
}
183183

184-
// Get remote access flag
185-
if (!spaceDetails.SpaceSettings?.RemoteAccess || spaceDetails.SpaceSettings?.RemoteAccess === 'DISABLED') {
184+
// First, update the space if needed
185+
const needsRemoteAccess =
186+
!spaceDetails.SpaceSettings?.RemoteAccess || spaceDetails.SpaceSettings?.RemoteAccess === 'DISABLED'
187+
const instanceTypeChanged = requestedResourceSpec?.InstanceType !== instanceType
188+
189+
if (needsRemoteAccess || instanceTypeChanged) {
190+
const settingsPropName = appType === 'JupyterLab' ? 'JupyterLabAppSettings' : 'CodeEditorAppSettings'
191+
const updateSpaceRequest: UpdateSpaceCommandInput = {
192+
DomainId: domainId,
193+
SpaceName: spaceName,
194+
SpaceSettings: {
195+
...(needsRemoteAccess && { RemoteAccess: 'ENABLED' }),
196+
...(instanceTypeChanged && {
197+
[settingsPropName]: {
198+
DefaultResourceSpec: {
199+
InstanceType: instanceType,
200+
},
201+
},
202+
}),
203+
},
204+
}
205+
186206
try {
187-
await this.updateSpace({
188-
DomainId: domainId,
189-
SpaceName: spaceName,
190-
SpaceSettings: {
191-
RemoteAccess: 'ENABLED',
192-
},
193-
})
207+
getLogger().debug('SagemakerClient: Updating space: domainId=%s, spaceName=%s', domainId, spaceName)
208+
await this.updateSpace(updateSpaceRequest)
194209
await this.waitForSpaceInService(spaceName, domainId)
195210
} catch (err) {
196211
throw this.handleStartSpaceError(err)
@@ -214,6 +229,7 @@ export class SagemakerClient extends ClientWrapper<SageMakerClient> {
214229
? { ...resourceSpec, EnvironmentArn: undefined, EnvironmentVersionArn: undefined }
215230
: resourceSpec
216231

232+
// Second, create the App
217233
const createAppRequest: CreateAppCommandInput = {
218234
DomainId: domainId,
219235
SpaceName: spaceName,
@@ -223,6 +239,7 @@ export class SagemakerClient extends ClientWrapper<SageMakerClient> {
223239
}
224240

225241
try {
242+
getLogger().debug('SagemakerClient: Creating app: domainId=%s, spaceName=%s', domainId, spaceName)
226243
await this.createApp(createAppRequest)
227244
} catch (err) {
228245
throw this.handleStartSpaceError(err)

packages/core/src/test/shared/clients/sagemakerClient.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ describe('SagemakerClient.startSpace', function () {
360360
getTestWindow().getFirstMessage().selectItem('Yes')
361361

362362
await promise
363+
sinon.assert.calledOnce(updateSpaceStub)
363364
sinon.assert.calledOnce(createAppStub)
364365
})
365366

0 commit comments

Comments
 (0)