From 14233ee7fd8586a284d926c3194eff774cce49f6 Mon Sep 17 00:00:00 2001 From: Ioan Faur Date: Wed, 10 Aug 2022 10:06:00 +0300 Subject: [PATCH 1/4] Remove unused service --- .../kotlin/com/coder/gateway/CoderGatewayConnectionProvider.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/kotlin/com/coder/gateway/CoderGatewayConnectionProvider.kt b/src/main/kotlin/com/coder/gateway/CoderGatewayConnectionProvider.kt index e963a3fd..3587e053 100644 --- a/src/main/kotlin/com/coder/gateway/CoderGatewayConnectionProvider.kt +++ b/src/main/kotlin/com/coder/gateway/CoderGatewayConnectionProvider.kt @@ -30,7 +30,6 @@ import java.time.format.DateTimeFormatter class CoderGatewayConnectionProvider : GatewayConnectionProvider { private val recentConnectionsService = service() - private val sshConfigService = service() private val connections = mutableSetOf() private val localTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MMM-dd HH:mm") From 242a4263b6e9c272529c2c48daa10b119cbd4a2f Mon Sep 17 00:00:00 2001 From: Ioan Faur Date: Wed, 10 Aug 2022 23:04:59 +0300 Subject: [PATCH 2/4] Impl: show working and non-working workspaces --- CHANGELOG.md | 5 +- .../gateway/models/WorkspaceAgentModel.kt | 5 +- .../gateway/models/WorkspaceAgentStatus.kt | 32 +++++++ .../views/steps/CoderWorkspacesStepView.kt | 90 +++++++++++-------- 4 files changed, 87 insertions(+), 45 deletions(-) create mode 100644 src/main/kotlin/com/coder/gateway/models/WorkspaceAgentStatus.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index c008ab25..b3c1f069 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,9 @@ # coder-gateway Changelog ## [Unreleased] +### Added +- support for displaying working and non-working workspaces + ### Fixed - left panel is no longer visible when a new connection is triggered from Coder's "Recent Workspaces" panel. @@ -31,8 +34,6 @@ ### Added - support for Gateway 2022.2 - - ### Changed - Java 17 is now required to run the plugin - adapted the code to the new SSH API provided by Gateway diff --git a/src/main/kotlin/com/coder/gateway/models/WorkspaceAgentModel.kt b/src/main/kotlin/com/coder/gateway/models/WorkspaceAgentModel.kt index 890146bd..8979f73d 100644 --- a/src/main/kotlin/com/coder/gateway/models/WorkspaceAgentModel.kt +++ b/src/main/kotlin/com/coder/gateway/models/WorkspaceAgentModel.kt @@ -8,10 +8,7 @@ import com.coder.gateway.sdk.v2.models.WorkspaceBuildTransition data class WorkspaceAgentModel( val name: String, val templateName: String, - - val jobStatus: ProvisionerJobStatus, - val buildTransition: WorkspaceBuildTransition, - + val agentStatus: WorkspaceAgentStatus, val agentOS: OS?, val agentArch: Arch?, val homeDirectory: String? diff --git a/src/main/kotlin/com/coder/gateway/models/WorkspaceAgentStatus.kt b/src/main/kotlin/com/coder/gateway/models/WorkspaceAgentStatus.kt new file mode 100644 index 00000000..6a8246c3 --- /dev/null +++ b/src/main/kotlin/com/coder/gateway/models/WorkspaceAgentStatus.kt @@ -0,0 +1,32 @@ +package com.coder.gateway.models + +import com.coder.gateway.sdk.v2.models.ProvisionerJobStatus +import com.coder.gateway.sdk.v2.models.Workspace +import com.coder.gateway.sdk.v2.models.WorkspaceBuildTransition + +enum class WorkspaceAgentStatus(val label: String) { + QUEUED("◍ Queued"), STARTING("⦿ Starting"), STOPPING("◍ Stopping"), DELETING("⦸ Deleting"), + RUNNING("⦿ Running"), STOPPED("◍ Stopped"), DELETED("⦸ Deleted"), + CANCELING("◍ Canceling action"), CANCELED("◍ Canceled action"), FAILED("ⓧ Failed"); + + companion object { + fun from(workspace: Workspace) = when (workspace.latestBuild.job.status) { + ProvisionerJobStatus.PENDING -> QUEUED + ProvisionerJobStatus.RUNNING -> when (workspace.latestBuild.workspaceTransition) { + WorkspaceBuildTransition.START -> STARTING + WorkspaceBuildTransition.STOP -> STOPPING + WorkspaceBuildTransition.DELETE -> DELETING + } + + ProvisionerJobStatus.SUCCEEDED -> when (workspace.latestBuild.workspaceTransition) { + WorkspaceBuildTransition.START -> RUNNING + WorkspaceBuildTransition.STOP -> STOPPED + WorkspaceBuildTransition.DELETE -> DELETED + } + + ProvisionerJobStatus.CANCELING -> CANCELING + ProvisionerJobStatus.CANCELED -> CANCELED + ProvisionerJobStatus.FAILED -> FAILED + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/coder/gateway/views/steps/CoderWorkspacesStepView.kt b/src/main/kotlin/com/coder/gateway/views/steps/CoderWorkspacesStepView.kt index 3599175c..069f7ed8 100644 --- a/src/main/kotlin/com/coder/gateway/views/steps/CoderWorkspacesStepView.kt +++ b/src/main/kotlin/com/coder/gateway/views/steps/CoderWorkspacesStepView.kt @@ -4,6 +4,11 @@ import com.coder.gateway.CoderGatewayBundle import com.coder.gateway.icons.CoderIcons import com.coder.gateway.models.CoderWorkspacesWizardModel import com.coder.gateway.models.WorkspaceAgentModel +import com.coder.gateway.models.WorkspaceAgentStatus +import com.coder.gateway.models.WorkspaceAgentStatus.DELETING +import com.coder.gateway.models.WorkspaceAgentStatus.RUNNING +import com.coder.gateway.models.WorkspaceAgentStatus.STARTING +import com.coder.gateway.models.WorkspaceAgentStatus.STOPPING import com.coder.gateway.sdk.Arch import com.coder.gateway.sdk.CoderCLIManager import com.coder.gateway.sdk.CoderRestClientService @@ -78,7 +83,7 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) : setSelectionMode(ListSelectionModel.SINGLE_SELECTION) selectionModel.addListSelectionListener { - enableNextButtonCallback(selectedObject != null) + enableNextButtonCallback(selectedObject != null && selectedObject?.agentStatus == RUNNING) } } @@ -221,26 +226,55 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) : } private fun List.collectAgents(): List { - return this.flatMap { workspace -> - try { - val agents = coderClient.workspaceAgents(workspace) - val shouldContainAgentName = agents.size > 1 - return@flatMap agents.map { agent -> - val workspaceName = if (shouldContainAgentName) "${workspace.name}.${agent.name}" else workspace.name + return this.flatMap { it.agentModels() }.toList() + } + + private fun Workspace.agentModels(): List { + return try { + val agents = coderClient.workspaceAgents(this) + when (agents.size) { + 0 -> { + listOf( + WorkspaceAgentModel( + this.name, + this.templateName, + WorkspaceAgentStatus.from(this), + null, + null, + null + ) + ) + } + + 1 -> { + listOf( + WorkspaceAgentModel( + this.name, + this.templateName, + WorkspaceAgentStatus.from(this), + OS.from(agents[0].operatingSystem), + Arch.from(agents[0].architecture), + agents[0].directory + ) + ) + } + + else -> agents.map { agent -> + val workspaceName = "${this.name}.${agent.name}" WorkspaceAgentModel( workspaceName, - workspace.templateName, - workspace.latestBuild.job.status, - workspace.latestBuild.workspaceTransition, + this.templateName, + WorkspaceAgentStatus.from(this), OS.from(agent.operatingSystem), Arch.from(agent.architecture), agent.directory ) } - } catch (e: Exception) { - logger.error("Skipping workspace ${workspace.name} because we could not retrieve the agent(s). Reason: $e") - emptyList() + .toList() } + } catch (e: Exception) { + logger.error("Skipping workspace ${this.name} because we could not retrieve the agent(s). Reason: $e") + emptyList() } } @@ -322,7 +356,7 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) : private class WorkspaceStatusColumnInfo(columnName: String) : ColumnInfo(columnName) { override fun valueOf(workspace: WorkspaceAgentModel?): String? { - return workspace?.statusLabel() + return workspace?.agentStatus?.label } override fun getRenderer(item: WorkspaceAgentModel?): TableCellRenderer { @@ -339,31 +373,9 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) : } } - private fun WorkspaceAgentModel.statusLabel() = when (this.jobStatus) { - ProvisionerJobStatus.PENDING -> "◍ Queued" - ProvisionerJobStatus.RUNNING -> when (this.buildTransition) { - WorkspaceBuildTransition.START -> "⦿ Starting" - WorkspaceBuildTransition.STOP -> "◍ Stopping" - WorkspaceBuildTransition.DELETE -> "⦸ Deleting" - } - - ProvisionerJobStatus.SUCCEEDED -> when (this.buildTransition) { - WorkspaceBuildTransition.START -> "⦿ Running" - WorkspaceBuildTransition.STOP -> "◍ Stopped" - WorkspaceBuildTransition.DELETE -> "⦸ Deleted" - } - - ProvisionerJobStatus.CANCELING -> "◍ Canceling action" - ProvisionerJobStatus.CANCELED -> "◍ Canceled action" - ProvisionerJobStatus.FAILED -> "ⓧ Failed" - } - - private fun WorkspaceAgentModel.statusColor() = when (this.jobStatus) { - ProvisionerJobStatus.SUCCEEDED -> if (this.buildTransition == WorkspaceBuildTransition.START) Color.GREEN else Color.RED - ProvisionerJobStatus.RUNNING -> when (this.buildTransition) { - WorkspaceBuildTransition.START, WorkspaceBuildTransition.STOP, WorkspaceBuildTransition.DELETE -> Color.GRAY - } - + private fun WorkspaceAgentModel.statusColor() = when (this.agentStatus) { + RUNNING -> Color.GREEN + STARTING, STOPPING, DELETING -> Color.GRAY else -> Color.RED } } From 888044b2a2d9ac9f6a3ad8c2de734e684b9eea73 Mon Sep 17 00:00:00 2001 From: Ioan Faur Date: Thu, 11 Aug 2022 00:36:00 +0300 Subject: [PATCH 3/4] Fix support for Dark&Light themes in the Status column - the existing colors don't play well with both themes --- CHANGELOG.md | 1 + .../coder/gateway/views/steps/CoderWorkspacesStepView.kt | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b3c1f069..58769e98 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ## [Unreleased] ### Added - support for displaying working and non-working workspaces +- better support for Light and Dark themes in the "Status" column ### Fixed diff --git a/src/main/kotlin/com/coder/gateway/views/steps/CoderWorkspacesStepView.kt b/src/main/kotlin/com/coder/gateway/views/steps/CoderWorkspacesStepView.kt index 069f7ed8..6888b690 100644 --- a/src/main/kotlin/com/coder/gateway/views/steps/CoderWorkspacesStepView.kt +++ b/src/main/kotlin/com/coder/gateway/views/steps/CoderWorkspacesStepView.kt @@ -33,6 +33,7 @@ import com.intellij.openapi.progress.Task import com.intellij.openapi.ui.panel.ComponentPanelBuilder import com.intellij.openapi.wm.impl.welcomeScreen.WelcomeScreenUIManager import com.intellij.ui.AppIcon +import com.intellij.ui.JBColor import com.intellij.ui.components.JBTextField import com.intellij.ui.components.dialog import com.intellij.ui.dsl.builder.BottomGap @@ -374,9 +375,9 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) : } private fun WorkspaceAgentModel.statusColor() = when (this.agentStatus) { - RUNNING -> Color.GREEN - STARTING, STOPPING, DELETING -> Color.GRAY - else -> Color.RED + RUNNING -> JBColor.GREEN + STARTING, STOPPING, DELETING -> if (JBColor.isBright()) JBColor.LIGHT_GRAY else JBColor.DARK_GRAY + else -> JBColor.RED } } From 9ec08585d99e4d6dd4a69700b15ca1ade958abe0 Mon Sep 17 00:00:00 2001 From: Ioan Faur Date: Thu, 11 Aug 2022 00:38:06 +0300 Subject: [PATCH 4/4] Next version is 2.0.2 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 91f67785..90e0c3ec 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ pluginGroup=com.coder.gateway pluginName=coder-gateway # SemVer format -> https://semver.org -pluginVersion=2.0.1 +pluginVersion=2.0.2 # See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html # for insight into build numbers and IntelliJ Platform versions. pluginSinceBuild=222.3739.24