Skip to content

Commit

Permalink
Merge pull request #68 from industrial-data-space/fix-watcher-loading
Browse files Browse the repository at this point in the history
Fix watcher loading
  • Loading branch information
milux authored Jul 2, 2021
2 parents 0014698 + 7bcc4bd commit a3ed9db
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 55 deletions.
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ plugins {
id("com.google.protobuf") version "0.8.12" apply false

// Kotlin specific
kotlin("jvm") version "1.4.32" apply false
kotlin("plugin.spring") version "1.4.32" apply false
kotlin("jvm") version "1.5.20" apply false
kotlin("plugin.spring") version "1.5.20" apply false

id("com.diffplug.spotless") version "5.11.0"
id("com.github.jk1.dependency-license-report") version "1.16"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,13 @@
*/
package de.fhg.aisec.ids

import org.apache.camel.support.jsse.KeyManagersParameters
import org.apache.camel.support.jsse.KeyStoreParameters
import org.apache.camel.support.jsse.SSLContextParameters
import org.apache.camel.support.jsse.TrustManagersParameters
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
import java.nio.file.FileSystems

@SpringBootApplication
open class ExampleConnector : TrustedConnector() {
Expand All @@ -30,5 +35,23 @@ open class ExampleConnector : TrustedConnector() {
fun main(args: Array<String>) {
runApplication<ExampleConnector>(*args)
}

fun getSslContext(): SSLContextParameters {
return SSLContextParameters().apply {
certAlias = "1.0.1"
keyManagers = KeyManagersParameters().apply {
keyStore = KeyStoreParameters().apply {
resource = FileSystems.getDefault().getPath("etc", "consumer-keystore.p12").toFile().path
password = "password"
}
}
trustManagers = TrustManagersParameters().apply {
keyStore = KeyStoreParameters().apply {
resource = FileSystems.getDefault().getPath("etc", "truststore.p12").toFile().path
password = "password"
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,14 @@ package de.fhg.aisec.ids

import org.apache.camel.RoutesBuilder
import org.apache.camel.builder.RouteBuilder
import org.apache.camel.support.jsse.KeyManagersParameters
import org.apache.camel.support.jsse.KeyStoreParameters
import org.apache.camel.support.jsse.SSLContextParameters
import org.apache.camel.support.jsse.TrustManagersParameters
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import java.nio.file.FileSystems

@Configuration
open class ExampleIdscpClient {

@Bean("clientSslContext")
open fun createSSLContext(): SSLContextParameters {
val ctx = SSLContextParameters()
ctx.certAlias = "1.0.1"
ctx.keyManagers = KeyManagersParameters()
ctx.keyManagers.keyStore = KeyStoreParameters()
ctx.keyManagers.keyStore.resource =
FileSystems.getDefault().getPath("etc", "provider-keystore.p12").toFile().path
ctx.keyManagers.keyStore.password = "password"
ctx.trustManagers = TrustManagersParameters()
ctx.trustManagers.keyStore = KeyStoreParameters()
ctx.trustManagers.keyStore.resource =
FileSystems.getDefault().getPath("etc", "truststore.p12").toFile().path
ctx.trustManagers.keyStore.password = "password"

return ctx
}
open fun createSSLContext() = ExampleConnector.getSslContext()

@Bean
open fun client(): RoutesBuilder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,14 @@ package de.fhg.aisec.ids

import org.apache.camel.RoutesBuilder
import org.apache.camel.builder.RouteBuilder
import org.apache.camel.support.jsse.KeyManagersParameters
import org.apache.camel.support.jsse.KeyStoreParameters
import org.apache.camel.support.jsse.SSLContextParameters
import org.apache.camel.support.jsse.TrustManagersParameters
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import java.nio.file.FileSystems

@Configuration
open class ExampleIdscpServer {

@Bean("serverSslContext")
open fun createSSLContext(): SSLContextParameters {
val ctx = SSLContextParameters()
ctx.certAlias = "1.0.1"
ctx.keyManagers = KeyManagersParameters()
ctx.keyManagers.keyStore = KeyStoreParameters()
ctx.keyManagers.keyStore.resource =
FileSystems.getDefault().getPath("etc", "consumer-keystore.p12").toFile().path
ctx.keyManagers.keyStore.password = "password"
ctx.trustManagers = TrustManagersParameters()
ctx.trustManagers.keyStore = KeyStoreParameters()
ctx.trustManagers.keyStore.resource =
FileSystems.getDefault().getPath("etc", "truststore.p12").toFile().path
ctx.trustManagers.keyStore.password = "password"

return ctx
}
open fun createSSLContext() = ExampleConnector.getSslContext()

@Bean
open fun server(): RoutesBuilder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class ConnectorConfiguration {
}

@Bean
fun listBeans(ctx: ApplicationContext): CommandLineRunner? {
fun listBeans(ctx: ApplicationContext): CommandLineRunner {
return CommandLineRunner {
val beans: Array<String> = ctx.beanDefinitionNames

Expand All @@ -71,7 +71,7 @@ class ConnectorConfiguration {
}

@Bean
fun listContainers(ctx: ApplicationContext): CommandLineRunner? {
fun listContainers(ctx: ApplicationContext): CommandLineRunner {
return CommandLineRunner {
val containers = cml?.list(false)

Expand All @@ -82,7 +82,7 @@ class ConnectorConfiguration {
}

@Bean
fun showConnectorProfile(ctx: ApplicationContext): CommandLineRunner? {
fun showConnectorProfile(ctx: ApplicationContext): CommandLineRunner {
return CommandLineRunner {
val connector = im.connector

Expand All @@ -95,7 +95,7 @@ class ConnectorConfiguration {
}

@Bean
fun showCamelInfo(ctx: ApplicationContext): CommandLineRunner? {
fun showCamelInfo(ctx: ApplicationContext): CommandLineRunner {
return CommandLineRunner {
val routes = rm.routes

Expand Down
3 changes: 3 additions & 0 deletions ids-connector/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ logging:
level:
ROOT: INFO
de.fhg.aisec: DEBUG
# Use for IDSCP2 debugging
# de.fhg.aisec.ids.idscp2: TRACE
# de.fhg.aisec.ids.camel.idscp2: TRACE

spring:
resources:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,14 @@ class DockerCM : ContainerManager {
for (unit in PERIOD_UNITS) {
val elapsed = period[unit]
if (elapsed > 0) {
units.add(elapsed.toString() + " " + unit.toString().toLowerCase())
units.add(elapsed.toString() + " " + unit.toString().lowercase())
}
}
for (unit in DURATION_UNITS) {
val unitDuration = unit.duration.toSeconds()
val elapsed = duration / unitDuration
if (elapsed > 0) {
units.add(elapsed.toString() + " " + unit.toString().toLowerCase())
units.add(elapsed.toString() + " " + unit.toString().lowercase())
}
duration %= unitDuration
}
Expand Down Expand Up @@ -211,7 +211,7 @@ class DockerCM : ContainerManager {
"${humanReadableByteCount((c["SizeRw"] ?: 0).toString().toLong())} RW (data), " +
"${humanReadableByteCount((c["SizeRootFs"] ?: 0).toString().toLong())} RO (layers)"
app.created = info.getString("Created")
app.status = ContainerStatus.valueOf(state.getString("Status").toUpperCase())
app.status = ContainerStatus.valueOf(state.getString("Status").uppercase())
app.ports =
ports
.entries
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,16 @@ class XmlDeployWatcher : ApplicationContextAware {
LOG.warn("XML watcher stopped by interrupt")
break
}
// Remember newly created XML files
val createdPaths = mutableSetOf<String>()
// Poll the events that happened since last iteration
for (watchEvent in key.pollEvents()) {
try {
val xmlPath = deployPath.resolve(watchEvent.context() as Path)
val xmlPathString = xmlPath.toString()
when (watchEvent.kind()) {
StandardWatchEventKinds.ENTRY_CREATE -> {
createdPaths += xmlPathString
// Must check whether the path represents a valid XML file
if (Files.isRegularFile(xmlPath) || xmlPathString.endsWith(".xml")) {
startXmlApplicationContext(xmlPathString)
Expand All @@ -119,7 +122,10 @@ class XmlDeployWatcher : ApplicationContextAware {
stopXmlApplicationContext(xmlPathString)
}
StandardWatchEventKinds.ENTRY_MODIFY -> {
restartXmlApplicationContext(xmlPathString)
// Ignore MODIFY events for newly created XML files
if (xmlPathString !in createdPaths) {
restartXmlApplicationContext(xmlPathString)
}
}
else -> {
LOG.warn("Unhandled WatchEvent: {}", watchEvent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ class NodeData(var id: String, node: Any?, imagePrefix: String) {
url =
(
"http://camel.apache.org/" +
nodeType!!.toLowerCase(Locale.ENGLISH).replace(' ', '-') +
nodeType!!.lowercase(Locale.ENGLISH).replace(' ', '-') +
".html"
)
}
Expand Down
4 changes: 2 additions & 2 deletions libraryVersions.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
idscp2: "0.4.3"
idscp2: "0.4.4"
ktlint: "0.41.0"

# Pinning
okhttp: "4.9.1"

# Kotlin library/compiler version
kotlin: "1.4.32"
kotlin: "1.5.20"
kotlinxCoroutines: "1.4.3"
# basically, the first requirement, all other libraries depend on this version
karaf: "4.2.10"
Expand Down

0 comments on commit a3ed9db

Please sign in to comment.