Skip to content

Commit 8636fe7

Browse files
committed
Impl: action to update workspace to the latest template version
- resolves #52
1 parent 2a9a5ba commit 8636fe7

File tree

7 files changed

+50
-1
lines changed

7 files changed

+50
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
## [Unreleased]
66
### Added
77
- support for displaying workspace version
8-
- support for managing the lifecycle of a workspace, i.e. start and stop
8+
- support for managing the lifecycle of a workspace, i.e. start and stop and update workspace to the latest template version
99

1010
### Changed
1111
- workspace panel is now updated every 5 seconds

src/main/kotlin/com/coder/gateway/icons/CoderIcons.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ object CoderIcons {
1111

1212
val RUN = IconLoader.getIcon("run.svg", javaClass)
1313
val STOP = IconLoader.getIcon("stop.svg", javaClass)
14+
val UPDATE = IconLoader.getIcon("update.svg", javaClass)
1415

1516
val WINDOWS = IconLoader.getIcon("windows.svg", javaClass)
1617
val MACOS = IconLoader.getIcon("macOS.svg", javaClass)

src/main/kotlin/com/coder/gateway/models/WorkspaceAgentModel.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ data class WorkspaceAgentModel(
88
val workspaceID: UUID,
99
val workspaceName: String,
1010
val name: String,
11+
val templateID: UUID,
1112
val templateName: String,
1213
val status: WorkspaceVersionStatus,
1314
val agentStatus: WorkspaceAgentStatus,
15+
val lastBuildTransition: String,
1416
val agentOS: OS?,
1517
val agentArch: Arch?,
1618
val homeDirectory: String?

src/main/kotlin/com/coder/gateway/views/steps/CoderWorkspacesStepView.kt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import com.coder.gateway.sdk.CoderCLIManager
1717
import com.coder.gateway.sdk.CoderRestClientService
1818
import com.coder.gateway.sdk.OS
1919
import com.coder.gateway.sdk.ex.AuthenticationResponseException
20+
import com.coder.gateway.sdk.ex.TemplateResponseException
2021
import com.coder.gateway.sdk.ex.WorkspaceResponseException
2122
import com.coder.gateway.sdk.getOS
2223
import com.coder.gateway.sdk.toURL
@@ -107,13 +108,15 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
107108

108109
private val startWorkspaceAction = StartWorkspaceAction()
109110
private val stopWorkspaceAction = StopWorkspaceAction()
111+
private val updateWorkspaceTemplateAction = UpdateWorkspaceTemplateAction()
110112

111113
private val toolbar = ToolbarDecorator.createDecorator(tableOfWorkspaces)
112114
.disableAddAction()
113115
.disableRemoveAction()
114116
.disableUpDownActions()
115117
.addExtraAction(startWorkspaceAction)
116118
.addExtraAction(stopWorkspaceAction)
119+
.addExtraAction(updateWorkspaceTemplateAction)
117120

118121
private var poller: Job? = null
119122

@@ -175,6 +178,26 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
175178
}
176179
}
177180

181+
private inner class UpdateWorkspaceTemplateAction : AnActionButton(CoderGatewayBundle.message("gateway.connector.view.coder.workspaces.update.text"), CoderGatewayBundle.message("gateway.connector.view.coder.workspaces.update.text"), CoderIcons.UPDATE) {
182+
override fun actionPerformed(p0: AnActionEvent) {
183+
if (tableOfWorkspaces.selectedObject != null) {
184+
val workspace = tableOfWorkspaces.selectedObject as WorkspaceAgentModel
185+
cs.launch {
186+
withContext(Dispatchers.IO) {
187+
try {
188+
coderClient.updateWorkspace(workspace.workspaceID, workspace.workspaceName, workspace.lastBuildTransition, workspace.templateID)
189+
loadWorkspaces()
190+
} catch (e: WorkspaceResponseException) {
191+
logger.warn("Could not update workspace ${workspace.name}, reason: $e")
192+
} catch (e: TemplateResponseException) {
193+
logger.warn("Could not update workspace ${workspace.name}, reason: $e")
194+
}
195+
}
196+
}
197+
}
198+
}
199+
}
200+
178201
private inner class StopWorkspaceAction : AnActionButton(CoderGatewayBundle.message("gateway.connector.view.coder.workspaces.stop.text"), CoderGatewayBundle.message("gateway.connector.view.coder.workspaces.stop.text"), CoderIcons.STOP) {
179202
override fun actionPerformed(p0: AnActionEvent) {
180203
if (tableOfWorkspaces.selectedObject != null) {
@@ -203,16 +226,26 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
203226
RUNNING -> {
204227
startWorkspaceAction.isEnabled = false
205228
stopWorkspaceAction.isEnabled = true
229+
when (tableOfWorkspaces.selectedObject?.status) {
230+
WorkspaceVersionStatus.OUTDATED -> updateWorkspaceTemplateAction.isEnabled = true
231+
else -> updateWorkspaceTemplateAction.isEnabled = false
232+
}
233+
206234
}
207235

208236
STOPPED, FAILED -> {
209237
startWorkspaceAction.isEnabled = true
210238
stopWorkspaceAction.isEnabled = false
239+
when (tableOfWorkspaces.selectedObject?.status) {
240+
WorkspaceVersionStatus.OUTDATED -> updateWorkspaceTemplateAction.isEnabled = true
241+
else -> updateWorkspaceTemplateAction.isEnabled = false
242+
}
211243
}
212244

213245
else -> {
214246
startWorkspaceAction.isEnabled = false
215247
stopWorkspaceAction.isEnabled = false
248+
updateWorkspaceTemplateAction.isEnabled = false
216249
}
217250
}
218251
ActivityTracker.getInstance().inc()
@@ -342,9 +375,11 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
342375
this.id,
343376
this.name,
344377
this.name,
378+
this.templateID,
345379
this.templateName,
346380
WorkspaceVersionStatus.from(this),
347381
WorkspaceAgentStatus.from(this),
382+
this.latestBuild.workspaceTransition.name.toLowerCase(),
348383
null,
349384
null,
350385
null
@@ -358,9 +393,11 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
358393
this.id,
359394
this.name,
360395
workspaceWithAgentName,
396+
this.templateID,
361397
this.templateName,
362398
WorkspaceVersionStatus.from(this),
363399
WorkspaceAgentStatus.from(this),
400+
this.latestBuild.workspaceTransition.name.toLowerCase(),
364401
OS.from(agent.operatingSystem),
365402
Arch.from(agent.architecture),
366403
agent.directory
@@ -374,9 +411,11 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
374411
this.id,
375412
this.name,
376413
this.name,
414+
this.templateID,
377415
this.templateName,
378416
WorkspaceVersionStatus.from(this),
379417
WorkspaceAgentStatus.from(this),
418+
this.latestBuild.workspaceTransition.name.toLowerCase(),
380419
null,
381420
null,
382421
null

src/main/resources/messages/CoderGatewayBundle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ gateway.connector.view.coder.workspaces.cli.downloader.dialog.title=Authenticate
1212
gateway.connector.view.coder.workspaces.next.text=Select IDE and Project
1313
gateway.connector.view.coder.workspaces.start.text=Start Workspace
1414
gateway.connector.view.coder.workspaces.stop.text=Stop Workspace
15+
gateway.connector.view.coder.workspaces.update.text=Update Workspace Template
1516
gateway.connector.view.coder.remoteproject.loading.text=Retrieving products...
1617
gateway.connector.view.coder.remoteproject.ide.error.text=Could not retrieve any IDE for workspace {0} because an error was encountered
1718
gateway.connector.view.coder.remoteproject.next.text=Start IDE and Connect

src/main/resources/update.svg

Lines changed: 3 additions & 0 deletions
Loading

src/main/resources/update_dark.svg

Lines changed: 3 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)