Skip to content

Minor fixes #135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions src/main/kotlin/com/coder/gateway/sdk/CoderRestClientService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ package com.coder.gateway.sdk
import com.coder.gateway.sdk.convertors.InstantConverter
import com.coder.gateway.sdk.ex.AuthenticationResponseException
import com.coder.gateway.sdk.ex.TemplateResponseException
import com.coder.gateway.sdk.ex.WorkspaceResourcesResponseException
import com.coder.gateway.sdk.ex.WorkspaceResponseException
import com.coder.gateway.sdk.v2.CoderV2RestFacade
import com.coder.gateway.sdk.v2.models.BuildInfo
import com.coder.gateway.sdk.v2.models.CreateWorkspaceBuildRequest
import com.coder.gateway.sdk.v2.models.Template
import com.coder.gateway.sdk.v2.models.User
import com.coder.gateway.sdk.v2.models.Workspace
import com.coder.gateway.sdk.v2.models.WorkspaceAgent
import com.coder.gateway.sdk.v2.models.WorkspaceBuild
import com.coder.gateway.sdk.v2.models.WorkspaceTransition
import com.google.gson.Gson
Expand Down Expand Up @@ -91,21 +89,6 @@ class CoderRestClientService {
return buildInfoResponse.body()!!
}

/**
* Retrieves the workspace agents a template declares.
* A workspace is a collection of objects like, VMs, containers, cloud DBs, etc...Agents run on compute hosts like VMs or containers.
*
* @throws WorkspaceResourcesResponseException if workspace resources could not be retrieved.
*/
fun workspaceAgentsByTemplate(workspace: Workspace): List<WorkspaceAgent> {
val workspaceResourcesResponse = retroRestClient.templateVersionResources(workspace.latestBuild.templateVersionID).execute()
if (!workspaceResourcesResponse.isSuccessful) {
throw WorkspaceResourcesResponseException("Could not retrieve agents for ${workspace.name} workspace :${workspaceResourcesResponse.code()}, reason: ${workspaceResourcesResponse.message()}")
}

return workspaceResourcesResponse.body()!!.flatMap { it.agents ?: emptyList() }
}

private fun template(templateID: UUID): Template {
val templateResponse = retroRestClient.template(templateID).execute()
if (!templateResponse.isSuccessful) {
Expand Down
10 changes: 5 additions & 5 deletions src/main/kotlin/com/coder/gateway/sdk/TemplateIconDownloader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,28 @@ class TemplateIconDownloader {
private val coderClient: CoderRestClientService = service()
private val cache = mutableMapOf<Pair<String, String>, Icon>()

fun load(path: String, templateName: String): Icon {
fun load(path: String, workspaceName: String): Icon {
var url: URL? = null
if (path.startsWith("http")) {
url = path.toURL()
} else if (path.contains(coderClient.coderURL.host)) {
} else if (!path.contains(":") && !path.contains("//")) {
url = coderClient.coderURL.withPath(path)
}

if (url != null) {
val cachedIcon = cache[Pair(templateName, path)]
val cachedIcon = cache[Pair(workspaceName, path)]
if (cachedIcon != null) {
return cachedIcon
}
var img = ImageLoader.loadFromUrl(url)
if (img != null) {
val icon = IconUtil.toRetinaAwareIcon(Scalr.resize(ImageUtil.toBufferedImage(img), Scalr.Method.ULTRA_QUALITY, 32))
cache[Pair(templateName, path)] = icon
cache[Pair(workspaceName, path)] = icon
return icon
}
}

return iconForChar(templateName.lowercase().first())
return iconForChar(workspaceName.lowercase().first())
}

private fun iconForChar(c: Char) = when (c) {
Expand Down
4 changes: 0 additions & 4 deletions src/main/kotlin/com/coder/gateway/sdk/v2/CoderV2RestFacade.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import com.coder.gateway.sdk.v2.models.CreateWorkspaceBuildRequest
import com.coder.gateway.sdk.v2.models.Template
import com.coder.gateway.sdk.v2.models.User
import com.coder.gateway.sdk.v2.models.WorkspaceBuild
import com.coder.gateway.sdk.v2.models.WorkspaceResource
import com.coder.gateway.sdk.v2.models.WorkspacesResponse
import retrofit2.Call
import retrofit2.http.Body
Expand All @@ -32,9 +31,6 @@ interface CoderV2RestFacade {
@GET("api/v2/buildinfo")
fun buildInfo(): Call<BuildInfo>

@GET("api/v2/templateversions/{templateID}/resources")
fun templateVersionResources(@Path("templateID") templateID: UUID): Call<List<WorkspaceResource>>

/**
* Queues a new build to occur for a workspace.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
maxWidth = JBUI.scale(52)
minWidth = JBUI.scale(52)
}

rowHeight = 48
setSelectionMode(ListSelectionModel.SINGLE_SELECTION)
selectionModel.addListSelectionListener {
enableNextButtonCallback(selectedObject != null && selectedObject?.agentStatus == RUNNING && selectedObject?.agentOS == OS.LINUX)
Expand Down Expand Up @@ -523,7 +523,7 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
null
)
cs.launch(Dispatchers.IO) {
wm.templateIcon = iconDownloader.load(wm.templateIconPath, wm.templateName)
wm.templateIcon = iconDownloader.load(wm.templateIconPath, wm.name)
withContext(Dispatchers.Main) {
tableOfWorkspaces.updateUI()
}
Expand All @@ -550,7 +550,7 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
agent.directory
)
cs.launch(Dispatchers.IO) {
wm.templateIcon = iconDownloader.load(wm.templateIconPath, wm.templateName)
wm.templateIcon = iconDownloader.load(wm.templateIconPath, wm.name)
withContext(Dispatchers.Main) {
tableOfWorkspaces.updateUI()
}
Expand All @@ -575,7 +575,7 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
null
)
cs.launch(Dispatchers.IO) {
wm.templateIcon = iconDownloader.load(wm.templateIconPath, wm.templateName)
wm.templateIcon = iconDownloader.load(wm.templateIconPath, wm.name)
withContext(Dispatchers.Main) {
tableOfWorkspaces.updateUI()
}
Expand Down