Cleanup in build files.

Handle errors in http route.
Some steps towards influx in collector.
This commit is contained in:
Mark Nellemann 2021-05-04 17:54:47 +02:00
parent 9b99e22b8b
commit 94eb0d17f9
8 changed files with 53 additions and 46 deletions

View file

@ -1,34 +1,21 @@
plugins { plugins {
id 'groovy'
id 'application' id 'application'
} }
repositories {
// Use Maven Central for resolving dependencies.
mavenCentral()
}
dependencies { dependencies {
testImplementation 'org.codehaus.groovy:groovy:3.0.7'
testImplementation 'org.spockframework:spock-core:2.0-M4-groovy-3.0'
testImplementation 'junit:junit:4.13.1'
testImplementation "org.slf4j:slf4j-api:${slf4jVersion}"
testImplementation project(':shared') testImplementation project(':shared')
implementation project(':shared') implementation project(':shared')
implementation "org.slf4j:slf4j-api:${slf4jVersion}"
implementation "org.slf4j:slf4j-simple:${slf4jVersion}"
annotationProcessor(group: 'org.pf4j', name: 'pf4j', version: "${pf4jVersion}") annotationProcessor(group: 'org.pf4j', name: 'pf4j', version: "${pf4jVersion}")
implementation group: 'org.pf4j', name: 'pf4j', version: "${pf4jVersion}" implementation group: 'org.pf4j', name: 'pf4j', version: "${pf4jVersion}"
implementation group: 'org.apache.camel', name: 'camel-core', version: '3.7.3' implementation group: 'org.apache.camel', name: 'camel-core', version: camelVersion
implementation group: 'org.apache.camel', name: 'camel-main', version: '3.7.3' implementation group: 'org.apache.camel', name: 'camel-main', version: camelVersion
implementation group: 'org.apache.camel', name: 'camel-http', version: '3.7.3' implementation group: 'org.apache.camel', name: 'camel-http', version: camelVersion
implementation group: 'org.apache.camel', name: 'camel-jackson', version: '3.7.3' implementation group: 'org.apache.camel', name: 'camel-jackson', version: camelVersion
implementation group: 'org.apache.camel', name: 'camel-bean', version: '3.7.3' implementation group: 'org.apache.camel', name: 'camel-bean', version: camelVersion
implementation group: 'org.apache.camel', name: 'camel-timer', version: '3.7.3' implementation group: 'org.apache.camel', name: 'camel-timer', version: camelVersion
implementation group: 'org.apache.camel', name: 'camel-stream', version: '3.7.3' implementation group: 'org.apache.camel', name: 'camel-stream', version: camelVersion
} }
application { application {

View file

@ -78,7 +78,11 @@ public class MyRouteBuilder extends RouteBuilder {
.process(new MetricProcessor()) .process(new MetricProcessor())
.marshal().json() .marshal().json()
.setHeader(Exchange.HTTP_METHOD, constant("POST")) .setHeader(Exchange.HTTP_METHOD, constant("POST"))
.to("http://127.0.0.1:9925/metrics"); .doTry()
.to("http://127.0.0.1:9925/metrics")
.doCatch(Exception.class)
.log("Error sending metric to collector.")
.end();

View file

@ -1,14 +1,20 @@
subprojects { subprojects {
apply plugin: 'java' apply plugin: 'java'
apply plugin: 'groovy'
dependencies { dependencies {
testImplementation project(':shared') testImplementation 'org.spockframework:spock-core:2.0-M5-groovy-3.0'
testImplementation "org.slf4j:slf4j-api:${slf4jVersion}"
implementation "org.slf4j:slf4j-api:${slf4jVersion}"
implementation "org.slf4j:slf4j-simple:${slf4jVersion}"
} }
repositories { repositories {
mavenLocal() mavenLocal()
mavenCentral() mavenCentral()
} }
sourceCompatibility = 1.8
targetCompatibility = 1.8
} }

View file

@ -1,29 +1,22 @@
plugins { plugins {
id 'groovy'
id 'application' id 'application'
} }
repositories {
// Use Maven Central for resolving dependencies.
mavenCentral()
}
dependencies { dependencies {
testImplementation project(':shared')
implementation project(':shared') implementation project(':shared')
implementation "org.slf4j:slf4j-api:${slf4jVersion}"
implementation "org.slf4j:slf4j-simple:${slf4jVersion}"
implementation group: 'org.apache.camel', name: 'camel-core', version: '3.7.3' implementation group: 'org.apache.camel', name: 'camel-core', version: camelVersion
implementation group: 'org.apache.camel', name: 'camel-rest', version: '3.7.3' implementation group: 'org.apache.camel', name: 'camel-rest', version: camelVersion
implementation group: 'org.apache.camel', name: 'camel-jetty', version: '3.7.3' implementation group: 'org.apache.camel', name: 'camel-jetty', version: camelVersion
implementation group: 'org.apache.camel', name: 'camel-jackson', version: '3.7.3' implementation group: 'org.apache.camel', name: 'camel-jackson', version: camelVersion
implementation group: 'org.apache.camel', name: 'camel-main', version: '3.7.3' implementation group: 'org.apache.camel', name: 'camel-main', version: camelVersion
implementation group: 'org.apache.camel', name: 'camel-bean', version: '3.7.3' implementation group: 'org.apache.camel', name: 'camel-bean', version: camelVersion
implementation group: 'org.apache.camel', name: 'camel-timer', version: '3.7.3' implementation group: 'org.apache.camel', name: 'camel-timer', version: camelVersion
implementation group: 'org.apache.camel', name: 'camel-stream', version: '3.7.3' implementation group: 'org.apache.camel', name: 'camel-stream', version: camelVersion
implementation group: 'org.apache.camel', name: 'camel-influxdb', version: camelVersion
} }
application { application {
// Define the main class for the application. // Define the main class for the application.
mainClassName = 'org.sysmon.collector.Application' mainClassName = 'org.sysmon.collector.Application'

View file

@ -1,13 +1,21 @@
package org.sysmon.collector; package org.sysmon.collector;
import org.apache.camel.main.Main; import org.apache.camel.main.Main;
import org.apache.camel.support.SimpleRegistry;
import org.influxdb.InfluxDB;
import org.influxdb.InfluxDBFactory;
public class Application { public class Application {
public static void main(String[] args) { public static void main(String[] args) {
InfluxDB influxConnectionBean = InfluxDBFactory.connect("http://localhost:8086", "root", "");
Main main = new Main(); Main main = new Main();
main.bind("myInfluxConnection", influxConnectionBean);
main.configure().addRoutesBuilder(CollectorRouteBuilder.class); main.configure().addRoutesBuilder(CollectorRouteBuilder.class);
// now keep the application running until the JVM is terminated (ctrl + c or sigterm) // now keep the application running until the JVM is terminated (ctrl + c or sigterm)
try { try {
main.run(args); main.run(args);
@ -16,4 +24,5 @@ public class Application {
} }
} }
} }

View file

@ -1,6 +1,5 @@
package org.sysmon.collector; package org.sysmon.collector;
import org.apache.camel.builder.RouteBuilder; import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.model.rest.RestBindingMode; import org.apache.camel.model.rest.RestBindingMode;
import org.sysmon.shared.dto.MetricMessageDTO; import org.sysmon.shared.dto.MetricMessageDTO;
@ -9,6 +8,7 @@ public class CollectorRouteBuilder extends RouteBuilder {
@Override @Override
public void configure() throws Exception { public void configure() throws Exception {
restConfiguration().component("jetty") restConfiguration().component("jetty")
.bindingMode(RestBindingMode.auto) .bindingMode(RestBindingMode.auto)
.host("127.0.0.1") .host("127.0.0.1")
@ -28,7 +28,16 @@ public class CollectorRouteBuilder extends RouteBuilder {
.type(MetricMessageDTO.class) .type(MetricMessageDTO.class)
.route() .route()
.to("bean:incomingMetricProcessor") .to("bean:incomingMetricProcessor")
.to("seda:inbound")
.endRest(); .endRest();
/*
from("seda:inbound")
.to("influxdb://myInfluxConnection?databaseName=sysmon");
*/
} }
} }

View file

@ -1,2 +1,3 @@
pf4jVersion=3.6.0 pf4jVersion=3.6.0
slf4jVersion=1.7.30 slf4jVersion=1.7.30
camelVersion=3.7.3

View file

@ -3,8 +3,7 @@ subprojects {
apply plugin: 'groovy' apply plugin: 'groovy'
dependencies { dependencies {
testImplementation 'org.spockframework:spock-core:2.0-M5-groovy-3.0'
testImplementation 'org.spockframework:spock-core:2.0-M4-groovy-3.0'
testImplementation "org.slf4j:slf4j-api:${slf4jVersion}" testImplementation "org.slf4j:slf4j-api:${slf4jVersion}"
testImplementation project(':shared') testImplementation project(':shared')
@ -14,7 +13,6 @@ subprojects {
} }
annotationProcessor(group: 'org.pf4j', name: 'pf4j', version: "${pf4jVersion}") annotationProcessor(group: 'org.pf4j', name: 'pf4j', version: "${pf4jVersion}")
implementation "org.slf4j:slf4j-api:${slf4jVersion}" implementation "org.slf4j:slf4j-api:${slf4jVersion}"
} }
jar { jar {