Skip to content

Upgrade GW platform to latest EAP, i.e 2022.x #34

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 13 commits into from
Aug 1, 2022
Prev Previous commit
Next Next commit
Fix: migrate to new API
- the host executor and it's utilities like `guessOs` are now under
  a `host accessor`
- ssh context is also changed - all params are now grouped under
  a `host deploy inputs` wrapper.
  • Loading branch information
fioan89 committed Jul 12, 2022
commit 9651a17dbbbcd69e4c85e21978ff712116dfb0ac
79 changes: 37 additions & 42 deletions src/main/kotlin/com/coder/gateway/CoderGatewayConnectionProvider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,34 @@ package com.coder.gateway

import com.coder.gateway.models.RecentWorkspaceConnection
import com.coder.gateway.services.CoderRecentWorkspaceConnectionsService
import com.coder.gateway.views.CoderGatewayConnectionComponent
import com.intellij.openapi.components.service
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.rd.util.launchUnderBackgroundProgress
import com.intellij.remote.AuthType
import com.intellij.remote.RemoteCredentialsHolder
import com.intellij.ssh.config.unified.SshConfig
import com.intellij.ssh.config.unified.SshConfigManager
import com.jetbrains.gateway.api.ConnectionRequestor
import com.jetbrains.gateway.api.GatewayConnectionHandle
import com.jetbrains.gateway.api.GatewayConnectionProvider
import com.jetbrains.gateway.ssh.Download
import com.jetbrains.gateway.ssh.HighLevelHostAccessor
import com.jetbrains.gateway.ssh.HostDeployInputs
import com.jetbrains.gateway.ssh.IdeInfo
import com.jetbrains.gateway.ssh.IntelliJPlatformProduct
import com.jetbrains.gateway.ssh.SshCommandsExecutor
import com.jetbrains.gateway.ssh.SshDeployFlowUtil
import com.jetbrains.gateway.ssh.SshMultistagePanelContext
import com.jetbrains.gateway.ssh.deploy.DeployTargetInfo.DeployWithDownload
import com.jetbrains.rd.util.lifetime.LifetimeDefinition
import kotlinx.coroutines.launch
import java.net.URI
import java.time.Duration
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import javax.swing.JComponent

class CoderGatewayConnectionProvider : GatewayConnectionProvider {
private val recentConnectionsService = service<CoderRecentWorkspaceConnectionsService>()
private val sshConfigService = service<SshConfigManager>()

private val connections = mutableSetOf<CoderConnectionMetadata>()
private val localTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MMM-dd HH:mm")

Expand All @@ -46,62 +49,54 @@ class CoderGatewayConnectionProvider : GatewayConnectionProvider {
logger.warn("There is already a connection started on ${connection.workspaceHostname}")
return null
}
val clientLifetime = LifetimeDefinition()

val credentials = RemoteCredentialsHolder().apply {
setHost(coderWorkspaceHostname)
userName = "coder"
authType = AuthType.OPEN_SSH
}

val sshConfiguration = SshConfig(true).apply {
setHost(coderWorkspaceHostname)
setUsername("coder")
port = 22
authType = AuthType.OPEN_SSH
}

val ideConfig = IdeInfo(
product = IntelliJPlatformProduct.fromProductCode(ideProductCode)!!,
buildNumber = ideBuildNumber
)

val clientLifetime = LifetimeDefinition()
clientLifetime.launchUnderBackgroundProgress("Coder Gateway Deploy", canBeCancelled = true, isIndeterminate = true, project = null) {
val context = SshMultistagePanelContext().apply {
deploy = true
sshConfig = sshConfiguration
remoteProjectPath = projectPath
remoteCommandsExecutor = SshCommandsExecutor.Companion.create(credentials)
download = Download.fromJson(ideDownloadLink)
ide = ideConfig
}
val context = SshMultistagePanelContext(
HostDeployInputs.FullySpecified(
remoteProjectPath = projectPath,
deployTarget = DeployWithDownload(
URI(ideDownloadLink),
null,
IdeInfo(
product = IntelliJPlatformProduct.fromProductCode(ideProductCode)!!,
buildNumber = ideBuildNumber
)
),
remoteInfo = HostDeployInputs.WithDeployedWorker(
HighLevelHostAccessor.create(
RemoteCredentialsHolder().apply {
setHost(coderWorkspaceHostname)
userName = "coder"
port = 22
authType = AuthType.OPEN_SSH
},
true
),
HostDeployInputs.WithHostInfo(sshConfiguration)
)
)
)
launch {
@Suppress("UnstableApiUsage")
SshDeployFlowUtil.fullDeployCycle(
clientLifetime,
context,
Duration.ofMinutes(10)
@Suppress("UnstableApiUsage") SshDeployFlowUtil.fullDeployCycle(
clientLifetime, context, Duration.ofMinutes(10)
)
}
}

recentConnectionsService.addRecentConnection(
RecentWorkspaceConnection(
coderWorkspaceHostname,
projectPath,
localTimeFormatter.format(LocalDateTime.now()),
ideProductCode,
ideBuildNumber,
ideDownloadLink,
webTerminalLink,
coderWorkspaceHostname, projectPath, localTimeFormatter.format(LocalDateTime.now()), ideProductCode, ideBuildNumber, ideDownloadLink, webTerminalLink
)
)

return object : GatewayConnectionHandle(clientLifetime) {
@Deprecated("Implement customComponentProvider instead to provide better UI/UX without default controls")
override fun createComponent(): JComponent {
return CoderGatewayConnectionComponent(clientLifetime, coderWorkspaceHostname)
}

override fun getTitle(): String {
return "Connection to Coder Workspaces"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ import com.jetbrains.gateway.ssh.CachingProductsJsonWrapper
import com.jetbrains.gateway.ssh.DeployTargetOS
import com.jetbrains.gateway.ssh.DeployTargetOS.OSArch
import com.jetbrains.gateway.ssh.DeployTargetOS.OSKind
import com.jetbrains.gateway.ssh.HighLevelHostAccessor
import com.jetbrains.gateway.ssh.IdeStatus
import com.jetbrains.gateway.ssh.IdeWithStatus
import com.jetbrains.gateway.ssh.IntelliJPlatformProduct
import com.jetbrains.gateway.ssh.SshCommandsExecutor
import com.jetbrains.gateway.ssh.deploy.guessOs
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.cancel
Expand Down Expand Up @@ -121,7 +122,10 @@ class CoderLocateRemoteProjectStepView(private val disableNextAction: () -> Unit
userName = "coder"
authType = AuthType.OPEN_SSH
}
SshCommandsExecutor.Companion.create(credentialsHolder).guessOs()
HighLevelHostAccessor.create(
credentialsHolder,
true
).hostCommandExecutor.guessOs()
} catch (e: Exception) {
logger.error("Could not resolve any IDE for workspace ${selectedWorkspace.name}. Reason: $e")
null
Expand Down Expand Up @@ -159,20 +163,20 @@ class CoderLocateRemoteProjectStepView(private val disableNextAction: () -> Unit
return when (os) {
OS.LINUX -> when (arch) {
Arch.AMD64 -> DeployTargetOS(OSKind.Linux, OSArch.X86_64)
Arch.ARM64 -> DeployTargetOS(OSKind.Linux, OSArch.Aarch64)
Arch.ARMV7 -> DeployTargetOS(OSKind.Linux, OSArch.Unknown)
Arch.ARM64 -> DeployTargetOS(OSKind.Linux, OSArch.ARM_64)
Arch.ARMV7 -> DeployTargetOS(OSKind.Linux, OSArch.UNKNOWN)
}

OS.WINDOWS -> when (arch) {
Arch.AMD64 -> DeployTargetOS(OSKind.Windows, OSArch.X86_64)
Arch.ARM64 -> DeployTargetOS(OSKind.Windows, OSArch.Aarch64)
Arch.ARMV7 -> DeployTargetOS(OSKind.Windows, OSArch.Unknown)
Arch.ARM64 -> DeployTargetOS(OSKind.Windows, OSArch.ARM_64)
Arch.ARMV7 -> DeployTargetOS(OSKind.Windows, OSArch.UNKNOWN)
}

OS.MAC -> when (arch) {
Arch.AMD64 -> DeployTargetOS(OSKind.MacOs, OSArch.X86_64)
Arch.ARM64 -> DeployTargetOS(OSKind.MacOs, OSArch.Aarch64)
Arch.ARMV7 -> DeployTargetOS(OSKind.MacOs, OSArch.Unknown)
Arch.ARM64 -> DeployTargetOS(OSKind.MacOs, OSArch.ARM_64)
Arch.ARMV7 -> DeployTargetOS(OSKind.MacOs, OSArch.UNKNOWN)
}
}
}
Expand All @@ -188,7 +192,7 @@ class CoderLocateRemoteProjectStepView(private val disableNextAction: () -> Unit
"project_path" to tfProject.text,
"ide_product_code" to selectedIDE.product.productCode,
"ide_build_number" to selectedIDE.buildNumber,
"ide_download_link" to selectedIDE.download!!.toJson(),
"ide_download_link" to selectedIDE.download!!.link,
"web_terminal_link" to "${terminalLink.url}"
)
)
Expand Down