Skip to content

Address Jetbrains backend plugin issues #6280

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 1 commit into from
Oct 27, 2021
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
16 changes: 14 additions & 2 deletions components/ide/jetbrains/backend-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,16 @@ repositories {
}

dependencies {
implementation(project(":supervisor-api"))
implementation(project(":gitpod-protocol"))
implementation(project(":supervisor-api")) {
artifact {
type = "jar"
}
}
implementation(project(":gitpod-protocol")) {
artifact {
type = "jar"
}
}
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-guava:1.5.2")
implementation("io.ktor:ktor-client-core:1.6.3")
Expand Down Expand Up @@ -82,6 +90,10 @@ tasks {
jvmTarget = "11"
}

buildSearchableOptions {
enabled = false
}

test {
useJUnitPlatform()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) 2021 Gitpod GmbH. All rights reserved.
// Licensed under the GNU Affero General Public License (AGPL).
// See License-AGPL.txt in the project root for license information.

package io.gitpod.ide.jetbrains.backend.listeners

import com.intellij.ide.ApplicationInitializedListener
import com.intellij.openapi.application.ApplicationActivationListener
import com.intellij.openapi.components.ServiceManager
import io.gitpod.ide.jetbrains.backend.services.HeartbeatService
import com.intellij.openapi.wm.IdeFrame
import com.intellij.openapi.components.service

internal class MyApplicationActivationListener : ApplicationActivationListener {
override fun applicationActivated(ideFrame: IdeFrame) {
service<HeartbeatService>() // Services are not loaded if not referenced
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import io.ktor.client.HttpClient
import io.ktor.client.features.HttpTimeout
import io.ktor.client.features.json.JsonFeature
import io.ktor.client.request.get
import io.ktor.client.features.json.JacksonSerializer

class ControllerStatusProvider {
private val logger = logger<ControllerStatusProvider>()
Expand All @@ -19,7 +20,9 @@ class ControllerStatusProvider {
@Suppress("MagicNumber")
requestTimeoutMillis = 2000
}
install(JsonFeature)
install(JsonFeature) {
serializer = JacksonSerializer()
}
}
private val cwmToken = System.getenv("CWM_HOST_STATUS_OVER_HTTP_TOKEN")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ import java.util.concurrent.atomic.AtomicBoolean
import java.util.concurrent.atomic.AtomicReference
import kotlin.concurrent.thread
import kotlin.random.Random.Default.nextInt
import java.lang.Thread

@Service
class HeartbeatService(
private val fetchToken: suspend () -> String = { AuthTokenService.fetchToken() },
private val controllerStatusProvider: ControllerStatusProvider = ControllerStatusProvider(),
) : Disposable {
class HeartbeatService() : Disposable {
private val logger = logger<HeartbeatService>()
private val fetchToken: suspend () -> String = { AuthTokenService.fetchToken() }
private val controllerStatusProvider = ControllerStatusProvider()

@Suppress("MagicNumber")
private val intervalInSeconds = 30
Expand All @@ -44,8 +44,10 @@ class HeartbeatService(
private val closed = AtomicBoolean(false)

init {
logger.info("Service initiated")

@Suppress("MagicNumber")
thread(name = "gitpod-heartbeat") {
thread(name = "gitpod-heartbeat", contextClassLoader = this.javaClass.classLoader) {
runBlocking {
while (!closed.get()) {
checkActivity(intervalInSeconds + nextInt(5, 15))
Expand All @@ -56,7 +58,7 @@ class HeartbeatService(
}

private suspend fun checkActivity(maxIntervalInSeconds: Int) {
logger.debug("Checking activity")
logger.info("Checking activity")
val status = controllerStatusProvider.fetch()
val previousStatus = this.status.getAndSet(status)

Expand Down Expand Up @@ -85,7 +87,7 @@ class HeartbeatService(
try {
val s = server.get()!!
s.sendHeartBeat(SendHeartBeatOptions(instanceId, wasClosed)).await()
logger.debug("Heartbeat sent with wasClosed=$wasClosed")
logger.info("Heartbeat sent with wasClosed=$wasClosed")
} catch (e: Exception) {
// If connection fails for some reason,
// remove the reference to the existing server.
Expand All @@ -98,10 +100,10 @@ class HeartbeatService(
/**
* @throws DeploymentException
* @throws IOException
* @throw IllegalStateException
* @throws IllegalStateException
*/
private suspend fun createServer(): GitpodServer {
logger.debug("Creating GitpodServer")
logger.info("Creating GitpodServer")
val token = fetchToken()
val server = ConnectionHelper().connect(uri, origin, token).server()
return server
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,9 @@
<!-- Product and plugin compatibility requirements -->
<!-- https://plugins.jetbrains.com/docs/intellij/plugin-compatibility.html -->
<depends>com.intellij.modules.platform</depends>

<applicationListeners>
<listener class="io.gitpod.ide.jetbrains.backend.listeners.MyApplicationActivationListener"
topic="com.intellij.openapi.application.ApplicationActivationListener" />
</applicationListeners>
</idea-plugin>