Skip to content

Commit

Permalink
implement internal wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
DinoMarlir committed May 21, 2024
1 parent cb016be commit 7275693
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 3 deletions.
1 change: 1 addition & 0 deletions node/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ repositories {
dependencies {
implementation(project(":api"))
implementation(project(":common"))
implementation(project(":wrapper")) // TODO
implementation(libs.kotlinxSerializationJson)
implementation(libs.guice)
implementation(libs.mordant)
Expand Down
29 changes: 28 additions & 1 deletion node/src/main/kotlin/me/blueamethyst/bluecloud/node/Node.kt
Original file line number Diff line number Diff line change
@@ -1,34 +1,43 @@
package me.blueamethyst.bluecloud.node

import me.blueamethyst.bluecloud.api.annontations.InternalBlueCloudApi
import me.blueamethyst.bluecloud.common.internal.AbstractSystemPart
import me.blueamethyst.bluecloud.common.internal.types.InternalSystemPartType
import me.blueamethyst.bluecloud.common.terminal.Logger
import me.blueamethyst.bluecloud.common.terminal.Terminal
import me.blueamethyst.bluecloud.common.utils.LoggingUtils
import me.blueamethyst.bluecloud.node.models.NodeConfigModel
import me.blueamethyst.bluecloud.node.utils.json
import me.blueamethyst.bluecloud.wrapper.Wrapper
import java.io.File

@InternalBlueCloudApi
class Node: AbstractSystemPart(InternalSystemPartType.NODE) {
val terminal = Terminal()
override val logger = LoggingUtils.getLogger("NODE", terminal.terminal)

companion object {
lateinit var logger: Logger
lateinit var config: NodeConfigModel
}

override fun startup() {
Companion.logger = logger
initialize()
postStart()
}

override fun shutdown() {
}

private fun initialize() {
setupFileStructure()
provideConfigFile()
}

private fun postStart() {

if (config.internalWrapperEnabled) provideWrapper()
blockMainThread()
}

private fun setupFileStructure() {
Expand All @@ -43,6 +52,7 @@ class Node: AbstractSystemPart(InternalSystemPartType.NODE) {
NodeConfigModel(
id = "",
name = "",
internalWrapperEnabled = false,
otherNodes = emptyList()
)
}
Expand All @@ -55,4 +65,21 @@ class Node: AbstractSystemPart(InternalSystemPartType.NODE) {
}
}
}

private fun provideConfigFile() {
config = json.decodeFromString(
File("node.json").readText(Charsets.UTF_8)
)
}

// TODO
private fun provideWrapper() {
Wrapper().startup()
}

private fun blockMainThread() {
while (true) {
Thread.sleep(50000)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ import kotlinx.serialization.Serializable
data class NodeConfigModel(
val id: String,
val name: String,
val internalWrapperEnabled: Boolean,
val otherNodes: List<String>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package me.blueamethyst.bluecloud.node.utils

import kotlinx.serialization.json.Json

val json = Json {
prettyPrint = true
ignoreUnknownKeys = true
}
2 changes: 2 additions & 0 deletions node/src/test/java/NodeTest.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import me.blueamethyst.bluecloud.api.annontations.InternalBlueCloudApi
import me.blueamethyst.bluecloud.node.Node

@OptIn(InternalBlueCloudApi::class)
fun main() {
Node().startup()
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ import me.blueamethyst.bluecloud.wrapper.utils.promptIntToValid
import java.io.File
import kotlin.reflect.KClass

class Wrapper: AbstractSystemPart(InternalSystemPartType.WRAPPER) {
class Wrapper(
private val blockMainThread: Boolean = false
): AbstractSystemPart(InternalSystemPartType.WRAPPER) {

val terminal = Terminal()
override val logger = LoggingUtils.getLogger("WRAPPER", terminal.terminal)
Expand Down Expand Up @@ -60,7 +62,7 @@ class Wrapper: AbstractSystemPart(InternalSystemPartType.WRAPPER) {
private fun postStart() {
logger.info("Starting Wrapper...")
WrapperWatcher.instance.initialize()
blockMainThread()
if (blockMainThread) blockMainThread()
}

@InternalBlueCloudApi
Expand Down Expand Up @@ -89,6 +91,7 @@ class Wrapper: AbstractSystemPart(InternalSystemPartType.WRAPPER) {
File("local/wrapper.json").readText(Charsets.UTF_8)
)
}

private fun provideProcessType() {
val serviceProcess = ProcessRegistry.instance.getServiceProcess(config.serviceProcessType)
?: throw IllegalStateException("Service process type '${config.serviceProcessType}' is not registered")
Expand Down

0 comments on commit 7275693

Please sign in to comment.