@@ -18,41 +18,60 @@ private val CircularSpinner: EnvironmentStateIcons = EnvironmentStateIcons.Conne
1818 * WorkspaceAndAgentStatus represents the combined status of a single agent and
1919 * its workspace (or just the workspace if there are no agents).
2020 */
21- enum class WorkspaceAndAgentStatus (val label : String , val description : String ) {
21+ sealed class WorkspaceAndAgentStatus (
22+ val label : String ,
23+ val workspace : Workspace
24+ ) {
2225 // Workspace states.
23- QUEUED (" Queued" , " The workspace is queueing to start." ),
24- STARTING (" Starting" , " The workspace is starting." ),
25- FAILED (" Failed" , " The workspace has failed to start." ),
26- DELETING (" Deleting" , " The workspace is being deleted." ),
27- DELETED (" Deleted" , " The workspace has been deleted." ),
28- STOPPING (" Stopping" , " The workspace is stopping." ),
29- STOPPED (" Stopped" , " The workspace has stopped." ),
30- CANCELING (" Canceling action" , " The workspace is being canceled." ),
31- CANCELED (" Canceled action" , " The workspace has been canceled." ),
32- RUNNING (" Running" , " The workspace is running, waiting for agents." ),
26+ class Queued (workspace : Workspace ) : WorkspaceAndAgentStatus(" Queued" , workspace)
27+
28+ class Starting (workspace : Workspace ) : WorkspaceAndAgentStatus(" Starting" , workspace)
29+
30+ class Failed (workspace : Workspace ) : WorkspaceAndAgentStatus(" Failed" , workspace)
31+
32+ class Deleting (workspace : Workspace ) : WorkspaceAndAgentStatus(" Deleting" , workspace)
33+
34+ class Deleted (workspace : Workspace ) :
35+ WorkspaceAndAgentStatus (" Deleted" , workspace)
36+
37+ class Stopping (workspace : Workspace ) : WorkspaceAndAgentStatus(" Stopping" , workspace)
38+
39+ class Stopped (workspace : Workspace ) : WorkspaceAndAgentStatus(" Stopped" , workspace)
40+
41+ class Canceling (workspace : Workspace ) : WorkspaceAndAgentStatus(" Canceling action" , workspace)
42+
43+ class Canceled (workspace : Workspace ) : WorkspaceAndAgentStatus(" Canceled action" , workspace)
44+
45+ class Running (workspace : Workspace ) : WorkspaceAndAgentStatus(" Running" , workspace)
3346
3447 // Agent states.
35- CONNECTING (" Connecting" , " The agent is connecting." ),
36- DISCONNECTED (" Disconnected" , " The agent has disconnected." ),
37- TIMEOUT (" Timeout" , " The agent is taking longer than expected to connect." ),
38- AGENT_STARTING (" Starting" , " The startup script is running." ),
39- AGENT_STARTING_READY (
40- " Starting" ,
41- " The startup script is still running but the agent is ready to accept connections." ,
42- ),
43- CREATED (" Created" , " The agent has been created." ),
44- START_ERROR (" Started with error" , " The agent is ready but the startup script errored." ),
45- START_TIMEOUT (" Starting" , " The startup script is taking longer than expected." ),
46- START_TIMEOUT_READY (
47- " Starting" ,
48- " The startup script is taking longer than expected but the agent is ready to accept connections." ,
49- ),
50- SHUTTING_DOWN (" Shutting down" , " The agent is shutting down." ),
51- SHUTDOWN_ERROR (" Shutdown with error" , " The agent shut down but the shutdown script errored." ),
52- SHUTDOWN_TIMEOUT (" Shutting down" , " The shutdown script is taking longer than expected." ),
53- OFF (" Off" , " The agent has shut down." ),
54- READY (" Ready" , " The agent is ready to accept connections." ),
55- ;
48+ class Connecting (workspace : Workspace ) : WorkspaceAndAgentStatus(" Connecting" , workspace)
49+
50+ class Disconnected (workspace : Workspace ) : WorkspaceAndAgentStatus(" Disconnected" , workspace)
51+
52+ class Timeout (workspace : Workspace ) : WorkspaceAndAgentStatus(" Timeout" , workspace)
53+
54+ class AgentStarting (workspace : Workspace ) : WorkspaceAndAgentStatus(" Starting" , workspace)
55+
56+ class AgentStartingReady (workspace : Workspace ) : WorkspaceAndAgentStatus(" Starting" , workspace)
57+
58+ class Created (workspace : Workspace ) : WorkspaceAndAgentStatus(" Created" , workspace)
59+
60+ class StartError (workspace : Workspace ) : WorkspaceAndAgentStatus(" Started with error" , workspace)
61+
62+ class StartTimeout (workspace : Workspace ) : WorkspaceAndAgentStatus(" Starting" , workspace)
63+
64+ class StartTimeoutReady (workspace : Workspace ) : WorkspaceAndAgentStatus(" Starting" , workspace)
65+
66+ class ShuttingDown (workspace : Workspace ) : WorkspaceAndAgentStatus(" Shutting down" , workspace)
67+
68+ class ShutdownError (workspace : Workspace ) : WorkspaceAndAgentStatus(" Shutdown with error" , workspace)
69+
70+ class ShutdownTimeout (workspace : Workspace ) : WorkspaceAndAgentStatus(" Shutting down" , workspace)
71+
72+ class Off (workspace : Workspace ) : WorkspaceAndAgentStatus(" Off" , workspace)
73+
74+ class Ready (workspace : Workspace ) : WorkspaceAndAgentStatus(" Ready" , workspace)
5675
5776 /* *
5877 * Return the environment state for Toolbox, which tells it the label, color
@@ -63,29 +82,29 @@ enum class WorkspaceAndAgentStatus(val label: String, val description: String) {
6382 */
6483 fun toRemoteEnvironmentState (context : CoderToolboxContext ): CustomRemoteEnvironmentStateV2 {
6584 return CustomRemoteEnvironmentStateV2 (
66- context.i18n.pnotr(label),
85+ label = context.i18n.pnotr(label),
6786 color = getStateColor(context),
68- isReachable = ready() || unhealthy() ,
87+ isReachable = this .workspace.latestBuild.status == WorkspaceStatus . RUNNING ,
6988 // TODO@JB: How does this work? Would like a spinner for pending states.
7089 iconId = getStateIcon().id,
7190 isPriorityShow = true
7291 )
7392 }
7493
7594 private fun getStateColor (context : CoderToolboxContext ): StateColor {
76- return if (this == FAILED ) context.envStateColorPalette.getColor(StandardRemoteEnvironmentState .FailedToStart )
77- else if (this == DELETING ) context.envStateColorPalette.getColor(StandardRemoteEnvironmentState .Deleting )
78- else if (this == DELETED ) context.envStateColorPalette.getColor(StandardRemoteEnvironmentState .Deleted )
95+ return if (this is Failed ) context.envStateColorPalette.getColor(StandardRemoteEnvironmentState .FailedToStart )
96+ else if (this is Deleting ) context.envStateColorPalette.getColor(StandardRemoteEnvironmentState .Deleting )
97+ else if (this is Deleted ) context.envStateColorPalette.getColor(StandardRemoteEnvironmentState .Deleted )
7998 else if (ready()) context.envStateColorPalette.getColor(StandardRemoteEnvironmentState .Active )
8099 else if (unhealthy()) context.envStateColorPalette.getColor(StandardRemoteEnvironmentState .Unhealthy )
81- else if (canStart() || this == STOPPING ) context.envStateColorPalette.getColor(StandardRemoteEnvironmentState .Hibernating )
100+ else if (canStart() || this is Stopping ) context.envStateColorPalette.getColor(StandardRemoteEnvironmentState .Hibernating )
82101 else if (pending()) context.envStateColorPalette.getColor(StandardRemoteEnvironmentState .Activating )
83102 else context.envStateColorPalette.getColor(StandardRemoteEnvironmentState .Unreachable )
84103 }
85104
86105 private fun getStateIcon (): EnvironmentStateIcons {
87- return if (this == FAILED ) EnvironmentStateIcons .Error
88- else if (pending() || this == DELETING || this == DELETED || this == STOPPING ) CircularSpinner
106+ return if (this is Failed ) EnvironmentStateIcons .Error
107+ else if (pending() || this is Deleting || this is Deleted || this is Stopping ) CircularSpinner
89108 else if (ready() || unhealthy()) EnvironmentStateIcons .Active
90109 else if (canStart()) EnvironmentStateIcons .Offline
91110 else EnvironmentStateIcons .NoIcon
@@ -94,27 +113,24 @@ enum class WorkspaceAndAgentStatus(val label: String, val description: String) {
94113 /* *
95114 * Return true if the agent is in a connectable state.
96115 */
97- fun ready (): Boolean = this == READY
116+ fun ready (): Boolean = this is Ready
98117
99118 fun unhealthy (): Boolean {
100- return listOf (START_ERROR , START_TIMEOUT_READY )
101- .contains(this )
119+ return this is StartError || this is StartTimeoutReady
102120 }
103121
104122 /* *
105123 * Return true if the agent might soon be in a connectable state.
106124 */
107125 fun pending (): Boolean {
108126 // See ready() for why `CREATED` is not in this list.
109- return listOf (CREATED , CONNECTING , TIMEOUT , AGENT_STARTING , START_TIMEOUT , QUEUED , STARTING )
110- .contains(this )
127+ return this is Created || this is Connecting || this is Timeout || this is AgentStarting || this is StartTimeout || this is Queued || this is Starting
111128 }
112129
113130 /* *
114131 * Return true if the workspace can be started.
115132 */
116- fun canStart (): Boolean = listOf (STOPPED , FAILED , CANCELED )
117- .contains(this )
133+ fun canStart (): Boolean = this is Stopped || this is Failed || this is Canceled
118134
119135 /* *
120136 * Return true if the workspace can be stopped.
@@ -140,36 +156,42 @@ enum class WorkspaceAndAgentStatus(val label: String, val description: String) {
140156 workspace : Workspace ,
141157 agent : WorkspaceAgent ? = null,
142158 ) = when (workspace.latestBuild.status) {
143- WorkspaceStatus .PENDING -> QUEUED
144- WorkspaceStatus .STARTING -> STARTING
159+ WorkspaceStatus .PENDING -> Queued (workspace)
160+ WorkspaceStatus .STARTING -> Starting (workspace)
145161 WorkspaceStatus .RUNNING ->
146162 when (agent?.status) {
147163 WorkspaceAgentStatus .CONNECTED ->
148164 when (agent.lifecycleState) {
149- WorkspaceAgentLifecycleState .CREATED -> CREATED
150- WorkspaceAgentLifecycleState .STARTING -> if (agent.loginBeforeReady == true ) AGENT_STARTING_READY else AGENT_STARTING
151- WorkspaceAgentLifecycleState .START_TIMEOUT -> if (agent.loginBeforeReady == true ) START_TIMEOUT_READY else START_TIMEOUT
152- WorkspaceAgentLifecycleState .START_ERROR -> START_ERROR
153- WorkspaceAgentLifecycleState .READY -> READY
154- WorkspaceAgentLifecycleState .SHUTTING_DOWN -> SHUTTING_DOWN
155- WorkspaceAgentLifecycleState .SHUTDOWN_TIMEOUT -> SHUTDOWN_TIMEOUT
156- WorkspaceAgentLifecycleState .SHUTDOWN_ERROR -> SHUTDOWN_ERROR
157- WorkspaceAgentLifecycleState .OFF -> OFF
165+ WorkspaceAgentLifecycleState .CREATED -> Created (workspace)
166+ WorkspaceAgentLifecycleState .STARTING -> if (agent.loginBeforeReady == true ) AgentStartingReady (
167+ workspace
168+ ) else AgentStarting (workspace)
169+
170+ WorkspaceAgentLifecycleState .START_TIMEOUT -> if (agent.loginBeforeReady == true ) StartTimeoutReady (
171+ workspace
172+ ) else StartTimeout (workspace)
173+
174+ WorkspaceAgentLifecycleState .START_ERROR -> StartError (workspace)
175+ WorkspaceAgentLifecycleState .READY -> Ready (workspace)
176+ WorkspaceAgentLifecycleState .SHUTTING_DOWN -> ShuttingDown (workspace)
177+ WorkspaceAgentLifecycleState .SHUTDOWN_TIMEOUT -> ShutdownTimeout (workspace)
178+ WorkspaceAgentLifecycleState .SHUTDOWN_ERROR -> ShutdownError (workspace)
179+ WorkspaceAgentLifecycleState .OFF -> Off (workspace)
158180 }
159181
160- WorkspaceAgentStatus .DISCONNECTED -> DISCONNECTED
161- WorkspaceAgentStatus .TIMEOUT -> TIMEOUT
162- WorkspaceAgentStatus .CONNECTING -> CONNECTING
163- else -> RUNNING
182+ WorkspaceAgentStatus .DISCONNECTED -> Disconnected (workspace)
183+ WorkspaceAgentStatus .TIMEOUT -> Timeout (workspace)
184+ WorkspaceAgentStatus .CONNECTING -> Connecting (workspace)
185+ else -> Running (workspace)
164186 }
165187
166- WorkspaceStatus .STOPPING -> STOPPING
167- WorkspaceStatus .STOPPED -> STOPPED
168- WorkspaceStatus .FAILED -> FAILED
169- WorkspaceStatus .CANCELING -> CANCELING
170- WorkspaceStatus .CANCELED -> CANCELED
171- WorkspaceStatus .DELETING -> DELETING
172- WorkspaceStatus .DELETED -> DELETED
188+ WorkspaceStatus .STOPPING -> Stopping (workspace)
189+ WorkspaceStatus .STOPPED -> Stopped (workspace)
190+ WorkspaceStatus .FAILED -> Failed (workspace)
191+ WorkspaceStatus .CANCELING -> Canceling (workspace)
192+ WorkspaceStatus .CANCELED -> Canceled (workspace)
193+ WorkspaceStatus .DELETING -> Deleting (workspace)
194+ WorkspaceStatus .DELETED -> Deleted (workspace)
173195 }
174196 }
175197}
0 commit comments