Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit00d7321

Browse files
committed
Implement custom environment state
This way, we can show our status labels.
1 parentd6f9709 commit00d7321

File tree

2 files changed

+37
-24
lines changed

2 files changed

+37
-24
lines changed

‎src/main/kotlin/com/coder/gateway/CoderRemoteEnvironment.kt‎

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
packagecom.coder.gateway
22

3+
importcom.coder.gateway.models.WorkspaceAndAgentStatus
34
importcom.coder.gateway.sdk.CoderRestClient
45
importcom.coder.gateway.sdk.v2.models.Workspace
56
importcom.coder.gateway.sdk.v2.models.WorkspaceAgent
6-
importcom.coder.gateway.sdk.v2.models.WorkspaceAgentStatus
7-
importcom.coder.gateway.sdk.v2.models.WorkspaceStatus
87
importcom.coder.gateway.views.EnvironmentView
98
importcom.jetbrains.toolbox.gateway.AbstractRemoteProviderEnvironment
109
importcom.jetbrains.toolbox.gateway.EnvironmentVisibilityState
1110
importcom.jetbrains.toolbox.gateway.environments.EnvironmentContentsView
1211
importcom.jetbrains.toolbox.gateway.states.EnvironmentStateConsumer
13-
importcom.jetbrains.toolbox.gateway.states.StandardRemoteEnvironmentState
1412
importcom.jetbrains.toolbox.gateway.ui.ObservablePropertiesFactory
1513
importjava.util.concurrent.CompletableFuture
1614

@@ -27,28 +25,11 @@ class CoderRemoteEnvironment(
2725
) : AbstractRemoteProviderEnvironment(observablePropertiesFactory) {
2826
overridefungetId():String="${workspace.name}.${agent.name}"
2927
overridefungetName():String="${workspace.name}.${agent.name}"
28+
privateval status=WorkspaceAndAgentStatus.from(workspace, agent)
3029

31-
// Active (and unhealthy) here indicate that the workspace is in a state
32-
// where a connection can be attempted, not that the workspace is up and
33-
// running. Once a connection is actually initiated, the CLI will then
34-
// start the workspace if it is off.
35-
privatevar state=when (workspace.latestBuild.status) {
36-
WorkspaceStatus.PENDING->StandardRemoteEnvironmentState.Active
37-
WorkspaceStatus.STARTING->StandardRemoteEnvironmentState.Active
38-
WorkspaceStatus.RUNNING->when (agent.status) {
39-
WorkspaceAgentStatus.CONNECTED->StandardRemoteEnvironmentState.Active
40-
WorkspaceAgentStatus.DISCONNECTED->StandardRemoteEnvironmentState.Unreachable
41-
WorkspaceAgentStatus.TIMEOUT->StandardRemoteEnvironmentState.Unhealthy
42-
WorkspaceAgentStatus.CONNECTING->StandardRemoteEnvironmentState.Active
43-
}
44-
WorkspaceStatus.STOPPING->StandardRemoteEnvironmentState.Initializing
45-
WorkspaceStatus.STOPPED->StandardRemoteEnvironmentState.Active
46-
WorkspaceStatus.FAILED->StandardRemoteEnvironmentState.Unhealthy
47-
WorkspaceStatus.CANCELING->StandardRemoteEnvironmentState.Initializing
48-
WorkspaceStatus.CANCELED->StandardRemoteEnvironmentState.Active
49-
WorkspaceStatus.DELETING->StandardRemoteEnvironmentState.Deleting
50-
WorkspaceStatus.DELETED->StandardRemoteEnvironmentState.Deleted
51-
}
30+
31+
// Map each state to whether a connection can be attempted.
32+
privatevar state= status.toRemoteEnvironmentState()
5233

5334
/**
5435
* The contents are provided by the SSH view provided by Toolbox, all we

‎src/main/kotlin/com/coder/gateway/models/WorkspaceAndAgentStatus.kt‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import com.coder.gateway.sdk.v2.models.WorkspaceAgent
55
importcom.coder.gateway.sdk.v2.models.WorkspaceAgentLifecycleState
66
importcom.coder.gateway.sdk.v2.models.WorkspaceAgentStatus
77
importcom.coder.gateway.sdk.v2.models.WorkspaceStatus
8+
importcom.jetbrains.toolbox.gateway.states.Color
9+
importcom.jetbrains.toolbox.gateway.states.CustomRemoteEnvironmentState
810

911
/**
1012
* WorkspaceAndAgentStatus represents the combined status of a single agent and
@@ -46,6 +48,30 @@ enum class WorkspaceAndAgentStatus(val label: String, val description: String) {
4648
READY("Ready","The agent is ready to accept connections."),
4749
;
4850

51+
/**
52+
* Return the environment state for Toolbox, which tells it the label, color
53+
* and whether the environment is reachable.
54+
*
55+
* We mark all ready and pending states as reachable since if the workspace
56+
* is pending the cli will wait for it anyway.
57+
*
58+
* Additionally, terminal states like stopped are also marked as reachable,
59+
* since the cli will start them.
60+
*/
61+
funtoRemoteEnvironmentState():CustomRemoteEnvironmentState {
62+
// Use comments; no named arguments for non-Kotlin functions.
63+
// TODO@JB: Is there a set of default colors we could use?
64+
returnCustomRemoteEnvironmentState(
65+
label,
66+
Color(200,200,200,200),// darkThemeColor
67+
Color(104,112,128,255),// lightThemeColor
68+
Color(224,224,240,26),// darkThemeBackgroundColor
69+
Color(224,224,245,250),// lightThemeBackgroundColor
70+
ready()|| pending()|| canStart(),// reachable
71+
null,// iconId
72+
)
73+
}
74+
4975
/**
5076
* Return true if the agent is in a connectable state.
5177
*/
@@ -68,6 +94,12 @@ enum class WorkspaceAndAgentStatus(val label: String, val description: String) {
6894
.contains(this)
6995
}
7096

97+
/**
98+
* Return true if the workspace can be started.
99+
*/
100+
funcanStart():Boolean=listOf(STOPPED,FAILED,CANCELED)
101+
.contains(this)
102+
71103
// We want to check that the workspace is `running`, the agent is
72104
// `connected`, and the agent lifecycle state is `ready` to ensure the best
73105
// possible scenario for attempting a connection.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp