@@ -4,6 +4,11 @@ import com.coder.gateway.CoderGatewayBundle
44import com.coder.gateway.icons.CoderIcons
55import com.coder.gateway.models.CoderWorkspacesWizardModel
66import 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
712import com.coder.gateway.sdk.Arch
813import com.coder.gateway.sdk.CoderCLIManager
914import com.coder.gateway.sdk.CoderRestClientService
@@ -78,7 +83,7 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
7883
7984 setSelectionMode(ListSelectionModel .SINGLE_SELECTION )
8085 selectionModel.addListSelectionListener {
81- enableNextButtonCallback(selectedObject != null )
86+ enableNextButtonCallback(selectedObject != null && selectedObject?.agentStatus == RUNNING )
8287 }
8388 }
8489
@@ -221,26 +226,55 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
221226 }
222227
223228 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} "
230264 WorkspaceAgentModel (
231265 workspaceName,
232- workspace.templateName,
233- workspace.latestBuild.job.status,
234- workspace.latestBuild.workspaceTransition,
266+ this .templateName,
267+ WorkspaceAgentStatus .from(this ),
235268 OS .from(agent.operatingSystem),
236269 Arch .from(agent.architecture),
237270 agent.directory
238271 )
239272 }
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()
243274 }
275+ } catch (e: Exception ) {
276+ logger.error(" Skipping workspace ${this .name} because we could not retrieve the agent(s). Reason: $e " )
277+ emptyList()
244278 }
245279 }
246280
@@ -322,7 +356,7 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
322356
323357 private class WorkspaceStatusColumnInfo (columnName : String ) : ColumnInfo<WorkspaceAgentModel, String>(columnName) {
324358 override fun valueOf (workspace : WorkspaceAgentModel ? ): String? {
325- return workspace?.statusLabel()
359+ return workspace?.agentStatus?.label
326360 }
327361
328362 override fun getRenderer (item : WorkspaceAgentModel ? ): TableCellRenderer {
@@ -339,31 +373,9 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
339373 }
340374 }
341375
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
367379 else -> Color .RED
368380 }
369381 }
0 commit comments