Skip to content

Commit

Permalink
Move app to micronaut
Browse files Browse the repository at this point in the history
  • Loading branch information
tchiotludo committed Feb 16, 2019
1 parent d05a4cc commit a1a1eb4
Show file tree
Hide file tree
Showing 60 changed files with 845 additions and 793 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ build/*
.gradletasknamecache

### Assets
public/static
src/main/resources/static
node_modules
node/

Expand All @@ -36,7 +36,7 @@ out/*
logs/*

### Kafka HQ ###
conf/*.dev.conf
src/**/*-dev.yml

## Docker
.env
Expand Down
92 changes: 72 additions & 20 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
buildscript {
ext {
micronautVersion = "1.1.0.M1"
joobyVersion = "1.5.+"
confluentVersion = "5.1.0"
kafkaVersion = "2.1.+"
Expand All @@ -12,20 +13,33 @@ buildscript {
}

dependencies {
// jooby
classpath "com.google.gradle:osdetector-gradle-plugin:1.4.0"
classpath "io.spring.gradle:dependency-management-plugin:1.0.3.RELEASE"
classpath "org.jooby:jooby-gradle-plugin:$joobyVersion"

// kafkahq
classpath "com.commercehub.gradle.plugin:gradle-avro-plugin:0.16.0"
}
}

plugins {
// micronaut
id "io.spring.dependency-management" version "1.0.6.RELEASE"
id "com.github.johnrengelman.shadow" version "4.0.2"
id "application"
id "java"
id "net.ltgt.apt-eclipse" version "0.20"
id "net.ltgt.apt-idea" version "0.20"

// kafkahq
id "com.moowork.node" version "1.2.0"
id 'io.franzbecker.gradle-lombok' version '1.14'
id 'com.adarshr.test-logger' version '1.6.0'
id 'com.github.psxpaul.execfork' version '0.1.9'
}

// jooby
apply plugin: "io.spring.dependency-management"
apply plugin: "com.google.osdetector"
apply plugin: "application"
Expand All @@ -43,6 +57,7 @@ repositories {
mavenCentral()
maven { url 'http://packages.confluent.io/maven/' }
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
maven { url "https://jcenter.bintray.com" }
}

lombok {
Expand Down Expand Up @@ -71,23 +86,15 @@ configurations {
dependencyManagement {
imports {
mavenBom "org.jooby:jooby-bom:$joobyVersion"
mavenBom "io.micronaut:micronaut-bom:$micronautVersion"
}
}

joobyRun {
includes = ["**/*.class", "**/*.conf", "**/*.properties", "**/*.ftl", "**/*.xml"]
}

sourceSets.main.resources {
srcDirs = ["conf", "public"]
// micronaut
configurations {
developmentOnly
}

gradle.taskGraph.whenReady { graph ->
if (graph.hasTask(joobyRun)) {
webpack.enabled = false
npmInstall.enabled = false
}
}

/**********************************************************************************************************************\
* Dependencies
Expand Down Expand Up @@ -127,6 +134,41 @@ dependencies {
testCompile group: 'org.apache.kafka', name: 'kafka-streams', version: kafkaVersion
testCompile group: "io.confluent", name: "kafka-streams-avro-serde", version: confluentVersion
testCompile group: 'org.slf4j', name: 'jul-to-slf4j', version: '1.7.25'

// micronaut
annotationProcessor "io.micronaut:micronaut-inject-java"
annotationProcessor "io.micronaut:micronaut-validation"
compile "io.micronaut:micronaut-http-client"
compile "io.micronaut:micronaut-http-server-netty"
compile "io.micronaut:micronaut-inject"
compile "io.micronaut:micronaut-validation"
compile 'io.micronaut:micronaut-views'
compile "io.micronaut:micronaut-runtime"
runtime "ch.qos.logback:logback-classic:1.2.3"
runtime 'org.freemarker:freemarker:2.3.28'

// micronaut test
testAnnotationProcessor "io.micronaut:micronaut-inject-java"
testCompile "org.junit.jupiter:junit-jupiter-api"
testCompile "io.micronaut.test:micronaut-test-junit5"
testRuntime "org.junit.jupiter:junit-jupiter-engine"
}

/**********************************************************************************************************************\
* Compile & run (micronaut)
**********************************************************************************************************************/
run.classpath += configurations.developmentOnly
test.classpath += configurations.developmentOnly
run.jvmArgs('-noverify', '-XX:TieredStopAtLevel=1')

// use JUnit 5 platform
test {
useJUnitPlatform()
}

tasks.withType(JavaCompile){
options.encoding = "UTF-8"
options.compilerArgs.add('-parameters')
}

/**********************************************************************************************************************\
Expand Down Expand Up @@ -189,24 +231,34 @@ task webpack(type: NodeTask, dependsOn: "npmInstall") {
group = 'build'
description = 'Build with webpack assets'
script = project.file("node_modules/.bin/webpack")
outputs.dir("public/static")
outputs.dir("src/main/resources/static")
args = ["-p", "--mode production"]
}

jar.dependsOn "webpack"
processResources.dependsOn 'webpack'

clean.delete << file("public/static")
clean.delete << file("src/main/resources/static")

/**********************************************************************************************************************\
* Jar
**********************************************************************************************************************/
jar {
manifest {
attributes "Main-Class": mainClassName
}
shadowJar {
mergeServiceFiles()
}

from {
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
/**********************************************************************************************************************\
* Tmp
**********************************************************************************************************************/
task micronaut(type: JavaExec) {
classpath = sourceSets.main.runtimeClasspath
main = 'org.kafkahq.App'
jvmArgs = ['-Dmicronaut.environments=dev']
}

gradle.taskGraph.whenReady { graph ->
if (graph.hasTask(micronaut)) {
webpack.enabled = false
npmInstall.enabled = false
}
}
5 changes: 5 additions & 0 deletions micronaut-cli.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
profile: service
defaultPackage: org.kafkahq
---
testFramework: junit
sourceLanguage: java
75 changes: 7 additions & 68 deletions src/main/java/org/kafkahq/App.java
Original file line number Diff line number Diff line change
@@ -1,91 +1,30 @@
package org.kafkahq;

import com.typesafe.config.Config;
import org.jooby.FlashScope;
import org.jooby.Jooby;
import org.jooby.RequestLogger;
import org.jooby.assets.Assets;
import org.jooby.ftl.Ftl;
import org.jooby.json.Jackson;
import org.jooby.livereload.LiveReload;
import org.jooby.whoops.Whoops;
import org.kafkahq.controllers.*;
import org.kafkahq.modules.KafkaModule;
import org.kafkahq.modules.KafkaWrapper;
import org.kafkahq.repositories.AbstractRepository;
import io.micronaut.runtime.Micronaut;

import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Optional;

public class App extends Jooby {
// module
public class App {
// route
{
use(new FlashScope());
/*
use(new Whoops());
use("*", new RequestLogger()
.latency()
.extended()
);
use(new Jackson());

on("dev", () -> {
Path basedir = Paths.get(System.getProperty("user.dir"));
use(new Whoops());
use(new LiveReload()
.register(basedir.resolve("public"),
"**/*.ftl"
)
.register(basedir.resolve("target"),
"**/*.class",
"**/*.conf",
"**/*.properties")
.register(basedir.resolve("build"),
"**/*.class",
"**/*.conf",
"**/*.properties")
);
});
on("prod", () -> {
use(new Assets());
});
assets("/favicon.ico");
use(new Ftl("/", ".ftl"));
use(KafkaModule.class);

// @RequestScoped hack
use("*", "/{cluster}/**", (req, rsp, chain) -> {
Optional<String> cluster = req.param("cluster").toOptional();
cluster.ifPresent(clusterId ->
AbstractRepository.setWrapper(new KafkaWrapper(this.require(KafkaModule.class), clusterId))
);

chain.next(req, rsp);
});
}

// route
{
use("*", "/", (req, rsp, chain) -> {
rsp.redirect("/" + this.require(KafkaModule.class).getClustersList().get(0) + "/topic");
});
use("*", "/{cluster}", (req, rsp, chain) -> {
rsp.redirect("/" + req.param("cluster").value() + "/topic");
});
use(NodeController.class);
use(SchemaController.class);
use(TopicController.class);
use(GroupController.class);
sse("/{cluster}/topic/{topic}/search/{search}", new DataSseController());
}

public static String getBasePath(Config config) {
return config.getString("application.path").replaceAll("/$","");
*/
}

public static void main(String[] args) {
run(App::new, args);
Micronaut.run(App.class);
}
}
20 changes: 20 additions & 0 deletions src/main/java/org/kafkahq/configs/AbstractProperties.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.kafkahq.configs;

import io.micronaut.context.annotation.Parameter;
import io.micronaut.core.convert.format.MapFormat;
import lombok.Getter;

import java.util.Map;

@Getter
abstract public class AbstractProperties {
private final String name;

@MapFormat(transformation = MapFormat.MapTransformation.FLAT)
Map<String, String> properties;

public AbstractProperties(@Parameter String name) {
this.name = name;
}
}

19 changes: 19 additions & 0 deletions src/main/java/org/kafkahq/configs/Connection.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.kafkahq.configs;

import io.micronaut.context.annotation.EachProperty;
import io.micronaut.context.annotation.Parameter;
import lombok.Getter;

import java.net.URL;
import java.util.Optional;

@EachProperty("kafka.connections")
@Getter
public class Connection extends AbstractProperties {
Optional<URL> registry = Optional.empty();

public Connection(@Parameter String name) {
super(name);
}
}

14 changes: 14 additions & 0 deletions src/main/java/org/kafkahq/configs/Default.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.kafkahq.configs;

import io.micronaut.context.annotation.EachProperty;
import io.micronaut.context.annotation.Parameter;
import lombok.Getter;

@EachProperty("kafka.defaults")
@Getter
public class Default extends AbstractProperties {
public Default(@Parameter String name) {
super(name);
}
}

Loading

0 comments on commit a1a1eb4

Please sign in to comment.