@@ -4,6 +4,11 @@ import com.coder.gateway.CoderGatewayBundle
4
4
import com.coder.gateway.icons.CoderIcons
5
5
import com.coder.gateway.models.CoderWorkspacesWizardModel
6
6
import com.coder.gateway.models.WorkspaceAgentModel
7
+ import com.coder.gateway.models.WorkspaceAgentStatus
8
+ import com.coder.gateway.models.WorkspaceAgentStatus.DELETING
9
+ import com.coder.gateway.models.WorkspaceAgentStatus.RUNNING
10
+ import com.coder.gateway.models.WorkspaceAgentStatus.STARTING
11
+ import com.coder.gateway.models.WorkspaceAgentStatus.STOPPING
7
12
import com.coder.gateway.sdk.Arch
8
13
import com.coder.gateway.sdk.CoderCLIManager
9
14
import com.coder.gateway.sdk.CoderRestClientService
@@ -78,7 +83,7 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
78
83
79
84
setSelectionMode(ListSelectionModel .SINGLE_SELECTION )
80
85
selectionModel.addListSelectionListener {
81
- enableNextButtonCallback(selectedObject != null )
86
+ enableNextButtonCallback(selectedObject != null && selectedObject?.agentStatus == RUNNING )
82
87
}
83
88
}
84
89
@@ -221,26 +226,55 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
221
226
}
222
227
223
228
private fun List<Workspace>.collectAgents (): List <WorkspaceAgentModel > {
224
- return this .flatMap { workspace ->
225
- try {
226
- val agents = coderClient.workspaceAgents(workspace)
227
- val shouldContainAgentName = agents.size > 1
228
- return @flatMap agents.map { agent ->
229
- val workspaceName = if (shouldContainAgentName) " ${workspace.name} .${agent.name} " else workspace.name
229
+ return this .flatMap { it.agentModels() }.toList()
230
+ }
231
+
232
+ private fun Workspace.agentModels (): List <WorkspaceAgentModel > {
233
+ return try {
234
+ val agents = coderClient.workspaceAgents(this )
235
+ when (agents.size) {
236
+ 0 -> {
237
+ listOf (
238
+ WorkspaceAgentModel (
239
+ this .name,
240
+ this .templateName,
241
+ WorkspaceAgentStatus .from(this ),
242
+ null ,
243
+ null ,
244
+ null
245
+ )
246
+ )
247
+ }
248
+
249
+ 1 -> {
250
+ listOf (
251
+ WorkspaceAgentModel (
252
+ this .name,
253
+ this .templateName,
254
+ WorkspaceAgentStatus .from(this ),
255
+ OS .from(agents[0 ].operatingSystem),
256
+ Arch .from(agents[0 ].architecture),
257
+ agents[0 ].directory
258
+ )
259
+ )
260
+ }
261
+
262
+ else -> agents.map { agent ->
263
+ val workspaceName = " ${this .name} .${agent.name} "
230
264
WorkspaceAgentModel (
231
265
workspaceName,
232
- workspace.templateName,
233
- workspace.latestBuild.job.status,
234
- workspace.latestBuild.workspaceTransition,
266
+ this .templateName,
267
+ WorkspaceAgentStatus .from(this ),
235
268
OS .from(agent.operatingSystem),
236
269
Arch .from(agent.architecture),
237
270
agent.directory
238
271
)
239
272
}
240
- } catch (e: Exception ) {
241
- logger.error(" Skipping workspace ${workspace.name} because we could not retrieve the agent(s). Reason: $e " )
242
- emptyList()
273
+ .toList()
243
274
}
275
+ } catch (e: Exception ) {
276
+ logger.error(" Skipping workspace ${this .name} because we could not retrieve the agent(s). Reason: $e " )
277
+ emptyList()
244
278
}
245
279
}
246
280
@@ -322,7 +356,7 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
322
356
323
357
private class WorkspaceStatusColumnInfo (columnName : String ) : ColumnInfo<WorkspaceAgentModel, String>(columnName) {
324
358
override fun valueOf (workspace : WorkspaceAgentModel ? ): String? {
325
- return workspace?.statusLabel()
359
+ return workspace?.agentStatus?.label
326
360
}
327
361
328
362
override fun getRenderer (item : WorkspaceAgentModel ? ): TableCellRenderer {
@@ -339,31 +373,9 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
339
373
}
340
374
}
341
375
342
- private fun WorkspaceAgentModel.statusLabel () = when (this .jobStatus) {
343
- ProvisionerJobStatus .PENDING -> " ◍ Queued"
344
- ProvisionerJobStatus .RUNNING -> when (this .buildTransition) {
345
- WorkspaceBuildTransition .START -> " ⦿ Starting"
346
- WorkspaceBuildTransition .STOP -> " ◍ Stopping"
347
- WorkspaceBuildTransition .DELETE -> " ⦸ Deleting"
348
- }
349
-
350
- ProvisionerJobStatus .SUCCEEDED -> when (this .buildTransition) {
351
- WorkspaceBuildTransition .START -> " ⦿ Running"
352
- WorkspaceBuildTransition .STOP -> " ◍ Stopped"
353
- WorkspaceBuildTransition .DELETE -> " ⦸ Deleted"
354
- }
355
-
356
- ProvisionerJobStatus .CANCELING -> " ◍ Canceling action"
357
- ProvisionerJobStatus .CANCELED -> " ◍ Canceled action"
358
- ProvisionerJobStatus .FAILED -> " ⓧ Failed"
359
- }
360
-
361
- private fun WorkspaceAgentModel.statusColor () = when (this .jobStatus) {
362
- ProvisionerJobStatus .SUCCEEDED -> if (this .buildTransition == WorkspaceBuildTransition .START ) Color .GREEN else Color .RED
363
- ProvisionerJobStatus .RUNNING -> when (this .buildTransition) {
364
- WorkspaceBuildTransition .START , WorkspaceBuildTransition .STOP , WorkspaceBuildTransition .DELETE -> Color .GRAY
365
- }
366
-
376
+ private fun WorkspaceAgentModel.statusColor () = when (this .agentStatus) {
377
+ RUNNING -> Color .GREEN
378
+ STARTING , STOPPING , DELETING -> Color .GRAY
367
379
else -> Color .RED
368
380
}
369
381
}
0 commit comments