Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class DevSpacesConnection(private val devSpacesContext: DevSpacesContext) {
if (devSpacesContext.isConnected)
throw IOException(String.format("Already connected to %s", devSpacesContext.devWorkspace.metadata.name))

devSpacesContext.isConnected = true
try {
devSpacesContext.isConnected = true
return doConnection(onConnected, onDevWorkspaceStopped, onDisconnected)
} catch (e: Exception) {
devSpacesContext.isConnected = false
Expand All @@ -51,33 +51,35 @@ class DevSpacesConnection(private val devSpacesContext: DevSpacesContext) {
startAndWaitDevWorkspace()

val remoteIdeServer = RemoteIDEServer(devSpacesContext)
val remoteIdeServerStatus = remoteIdeServer.getStatus()
val joinLink = remoteIdeServer.getStatus().joinLink
?: throw IOException("Could not connect: no join link present")

val client = LinkedClientManager
.getInstance()
.startNewClient(
Lifetime.Eternal,
URI(remoteIdeServerStatus.joinLink),
URI(joinLink),
"",
onConnected,
false
)

val forwarder = Pods(devSpacesContext.client).forward(remoteIdeServer.pod, 5990, 5990)
val forwarder = Pods(devSpacesContext.client)
.forward(remoteIdeServer.pod, 5990, 5990)

client.run {
lifetime.onTermination { forwarder.close() }
lifetime.onTermination {
forwarder.close()
if (remoteIdeServer.waitServerTerminated())
DevWorkspaces(devSpacesContext.client)
.stop(
devSpacesContext.devWorkspace.metadata.namespace,
devSpacesContext.devWorkspace.metadata.name
)
.also { onDevWorkspaceStopped() }
devSpacesContext.isConnected = false
onDisconnected.invoke()
}
lifetime.onTermination { devSpacesContext.isConnected = false }
lifetime.onTermination(onDisconnected)
}

return client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class DevSpacesConnectionProvider : GatewayConnectionProvider {
parameters: Map<String, String>,
requestor: ConnectionRequestor,
indicator: ProgressIndicator? = null
): GatewayConnectionHandle? {
): GatewayConnectionHandle {
thisLogger().debug("Launched Dev Spaces connection provider", parameters)

indicator?.text2 = "Preparing connection environment…"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import java.io.IOException
import java.io.InputStream
import java.io.OutputStream
import java.net.InetAddress
import java.net.InetSocketAddress
import java.net.ServerSocket
import java.net.Socket
import java.util.concurrent.TimeUnit
Expand Down Expand Up @@ -99,16 +100,15 @@ class Pods(private val client: ApiClient) {
// https://github.com/kubernetes-client/java/blob/master/examples/examples-release-latest/src/main/java/io/kubernetes/client/examples/PortForwardExample.java
@Throws(IOException::class)
fun forward(pod: V1Pod, localPort: Int, remotePort: Int): Closeable {
val serverSocket = ServerSocket(localPort, 50, InetAddress.getLoopbackAddress())

val serverSocket = ServerSocket()
serverSocket.bind(InetSocketAddress(InetAddress.getLoopbackAddress(), localPort))
val scope = CoroutineScope(Dispatchers.IO)
scope.launch {
supervisorScope {
launch {
val clientSocket = serverSocket.accept()
val forwardResult = PortForward(client).forward(pod, listOf(remotePort))

try {
val forwardResult = PortForward(client).forward(pod, listOf(remotePort))
copyStreams(clientSocket, forwardResult, remotePort)
} catch (e: IOException) {
if (coroutineContext.isActive) throw e
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
package com.redhat.devtools.gateway.server

data class RemoteIDEServerStatus(
val joinLink: String,
val joinLink: String?,
val httpLink: String,
val gatewayLink: String,
val appVersion: String,
Expand Down
Loading