Skip to content

Commit

Permalink
feat: migrate to Quarkus
Browse files Browse the repository at this point in the history
  • Loading branch information
tadayosi committed Jul 29, 2021
1 parent 0429362 commit 1805266
Show file tree
Hide file tree
Showing 9 changed files with 210 additions and 88 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@ build:

deploy:
mkdir -p $(KERNEL_PATH)
cp target/icamel-0.4-SNAPSHOT.jar $(KERNEL_PATH)/
cp target/icamel-0.4-SNAPSHOT-runner.jar $(KERNEL_PATH)/
./bin/deploy-kernel-json.sh

test-run:
java -jar target/icamel-0.4-SNAPSHOT-runner.jar
16 changes: 8 additions & 8 deletions bin/deploy-kernel-json.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ cat <<EOF > $KERNEL_PATH/kernel.json
{
"argv": [
"java",
"-Dorg.slf4j.simpleLogger.logFile=System.out",
"-Dorg.slf4j.simpleLogger.showDateTime=true",
"-Dorg.slf4j.simpleLogger.dateTimeFormat=HH:mm:ss.SSS",
"-Dorg.slf4j.simpleLogger.defaultLogLevel=INFO",
"-Dorg.slf4j.simpleLogger.log.io.github.tadayosi.icamel=DEBUG",
"-Dorg.slf4j.simpleLogger.log.org.apache.camel=WARN",
"-Dorg.slf4j.simpleLogger.log.com.github.cameltooling.lsp=WARN",
"-Dquarkus.log.console.enable=true",
"-Dquarkus.log.console.color=true",
"-Dquarkus.log.level=INFO",
"-Dquarkus.log.category.\"io.quarkus\".level=WARN",
"-Dquarkus.log.category.\"org.apache.camel\".level=WARN",
"-Dquarkus.log.category.\"com.github.cameltooling.lsp\".level=WARN",
"-Dquarkus.log.category.\"io.github.tadayosi.icamel\".level=DEBUG",
"-jar",
"$KERNEL_PATH/icamel-0.4-SNAPSHOT.jar",
"$KERNEL_PATH/icamel-0.4-SNAPSHOT-runner.jar",
"{connection_file}"
],
"display_name": "Camel",
Expand Down
14 changes: 7 additions & 7 deletions kernel.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"argv": [
"java",
"-Dorg.slf4j.simpleLogger.logFile=System.out",
"-Dorg.slf4j.simpleLogger.showDateTime=true",
"-Dorg.slf4j.simpleLogger.dateTimeFormat=HH:mm:ss.SSS",
"-Dorg.slf4j.simpleLogger.defaultLogLevel=INFO",
"-Dorg.slf4j.simpleLogger.log.io.github.tadayosi.icamel=INFO",
"-Dorg.slf4j.simpleLogger.log.org.apache.camel=WARN",
"-Dorg.slf4j.simpleLogger.log.com.github.cameltooling.lsp=WARN",
"-Dquarkus.log.console.enable=true",
"-Dquarkus.log.console.color=true",
"-Dquarkus.log.level=INFO",
"-Dquarkus.log.category.\"io.quarkus\".level=WARN",
"-Dquarkus.log.category.\"org.apache.camel\".level=WARN",
"-Dquarkus.log.category.\"com.github.cameltooling.lsp\".level=WARN",
"-Dquarkus.log.category.\"io.github.tadayosi.icamel\".level=DEBUG",
"-jar",
"<your-camel-kernel-dir>/icamel-0.x.jar",
"{connection_file}"
Expand Down
95 changes: 31 additions & 64 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<quarkus.package.type>uber-jar</quarkus.package.type>

<camel.version>3.11.0</camel.version>
<camel.k.version>1.5.0</camel.k.version>
<camel.lsp.version>1.1.0</camel.lsp.version>
<jupyter.jvm.basekernel.version>2.3.0</jupyter.jvm.basekernel.version>
<quarkus.platform.version>2.0.3.Final</quarkus.platform.version>
</properties>

<dependencyManagement>
Expand All @@ -53,15 +55,35 @@
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-universe-bom</artifactId>
<version>${quarkus.platform.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc</artifactId>
</dependency>

<!--
<dependency>
<groupId>io.github.spencerpark</groupId>
<artifactId>jupyter-jvm-basekernel</artifactId>
<version>${jupyter.jvm.basekernel.version}</version>
</dependency>
-->
<!-- jitpack icamel branch -->
<dependency>
<groupId>com.github.tadayosi</groupId>
<artifactId>jupyter-jvm-basekernel</artifactId>
<version>${jupyter.jvm.basekernel.version}-icamel</version>
</dependency>

<!-- Camel -->
<dependency>
Expand Down Expand Up @@ -136,11 +158,13 @@
</dependency>

<!-- logging -->
<!--
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.31</version>
</dependency>
-->

<!-- testing -->
<dependency>
Expand Down Expand Up @@ -170,75 +194,18 @@
</resource>
</resources>
<plugins>
<!--
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<appendAssemblyId>false</appendAssemblyId>
<archive>
<manifest>
<mainClass>io.github.tadayosi.icamel.ICamel</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<version>${quarkus.platform.version}</version>
<extensions>true</extensions>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
<goal>build</goal>
<goal>generate-code</goal>
<goal>generate-code-tests</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>io.github.tadayosi.icamel.ICamel</mainClass>
<manifestEntries>
<Multi-Release>true</Multi-Release>
</manifestEntries>
</transformer>
</transformers>
<filters>
<filter>
<artifact>org.apache.camel.k:camel-k-runtime-main</artifact>
<excludes>
<exclude>log4j2.properties</exclude>
</excludes>
</filter>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>**/Log4j2Plugins.dat</exclude>
</excludes>
</filter>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
</execution>
</executions>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,4 @@ public CamelKernelRuntime() {
public CamelContext getCamelContext() {
return context;
}

@Override
public void setPropertiesLocations(Collection<String> locations) {
}
}
20 changes: 16 additions & 4 deletions src/main/java/io/github/tadayosi/icamel/ICamel.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,35 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.logging.Level;
import java.util.logging.LogManager;

import io.github.spencerpark.jupyter.channels.JupyterConnection;
import io.github.spencerpark.jupyter.kernel.KernelConnectionProperties;
import io.quarkus.runtime.QuarkusApplication;
import io.quarkus.runtime.annotations.QuarkusMain;

import static io.github.spencerpark.jupyter.channels.JupyterSocket.JUPYTER_LOGGER;

public class ICamel {
@QuarkusMain
public class ICamel implements QuarkusApplication {

public static void main(String[] args) throws Exception {
static {
// LogManager for using jupyter-jvm-basekernel with Quarkus
System.setProperty("java.util.logging.manager", "io.github.tadayosi.icamel.quarkus.JBossLogManager");
}

@Override
public int run(String... args) throws Exception {
if (args.length < 1) {
System.out.println(
String.format("ICamel %s - Apache Camel kernel for Jupyter notebook\n"
+ "\n"
+ "Usage:\n"
+ " java -jar icamel-%s.jar [connection_file]\n"
+ " java -jar icamel-%s-runner.jar [connection_file]\n"
+ "\n"
+ "For more info, see: https://github.com/tadayosi/icamel/",
CamelKernel.VERSION, CamelKernel.VERSION));
return;
return 0;
}

Path connectionFile = Paths.get(args[0]);
Expand All @@ -43,5 +53,7 @@ public static void main(String[] args) throws Exception {

connection.connect();
connection.waitUntilClose();

return 0;
}
}
129 changes: 129 additions & 0 deletions src/main/java/io/github/tadayosi/icamel/quarkus/JBossLogManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
package io.github.tadayosi.icamel.quarkus;

import java.beans.PropertyChangeListener;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Proxy;
import java.util.Enumeration;
import java.util.logging.LogManager;

import org.jboss.logmanager.LogContext;
import org.jboss.logmanager.Logger;

/**
* Customised JBoss LogManager. Mostly copied from {@link org.jboss.logmanager.LogManager}.
* Not used right now.
*
* Simplified log manager. Designed to work around the (many) design flaws of the JDK platform log manager.
*/
public class JBossLogManager extends LogManager {

private Logger heartbeatChannelLogger;

/**
* Construct a new logmanager instance. Attempts to plug a known memory leak in {@link java.util.logging.Level} as
* well.
*/
public JBossLogManager() {
}

// Configuration

/**
* Configure the log manager one time.
*/
public void readConfiguration() throws IOException, SecurityException {
}

/**
* Configure the log manager.
*
* @param inputStream the input stream from which the logmanager should be configured
*/
public void readConfiguration(InputStream inputStream) throws IOException, SecurityException {
}

/**
* Do nothing. Properties and their listeners are not supported.
*
* @param l ignored
*/
public void addPropertyChangeListener(PropertyChangeListener l) {
// no operation - properties are never changed
}

/**
* Do nothing. Properties and their listeners are not supported.
*
* @param l ignored
*/
public void removePropertyChangeListener(PropertyChangeListener l) {
// no operation - properties are never changed
}

/**
* Does nothing. Properties are not supported.
*
* @param name ignored
* @return {@code null}
*/
public String getProperty(String name) {
// no properties
return null;
}

/**
* Does nothing. This method only causes trouble.
*/
public void reset() {
// no operation!
}

@Override
public Enumeration<String> getLoggerNames() {
return LogContext.getInstance().getLoggerNames();
}

/**
* Do nothing. Loggers are only added/acquired via {@link #getLogger(String)}.
*
* @param logger ignored
* @return {@code false}
*/
public boolean addLogger(java.util.logging.Logger logger) {
return false;
}

/**
* Get or create a logger with the given name.
*
* @param name the logger name
* @return the corresponding logger
*/
public Logger getLogger(String name) {
Logger logger = LogContext.getInstance().getLogger(name);

// Hack for using jupyter-jvm-basekernel with Quarkus
if ("HeartbeatChannel".equals(name)) {
if (heartbeatChannelLogger == null) {
heartbeatChannelLogger = createSetParentableProxy(logger);
}
return heartbeatChannelLogger;
}
return logger;
}

private Logger createSetParentableProxy(Logger logger) {
return (Logger) Proxy.newProxyInstance(
getClass().getClassLoader(),
new Class[] { Logger.class },
(proxy, method, args) -> {
if ("setParent".equals(method.getName())) {
// Invoking setParent(...) on JBoss Logger causes SecurityException
return null;
}
return method.invoke(logger, args);
}
);
}
}
9 changes: 9 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
quarkus.banner.path=banner.txt

quarkus.log.console.enable=true
quarkus.log.console.color=true
quarkus.log.level=INFO
quarkus.log.category."io.quarkus".level=WARN
quarkus.log.category."org.apache.camel".level=WARN
quarkus.log.category."com.github.cameltooling.lsp".level=WARN
quarkus.log.category."io.github.tadayosi.icamel".level=DEBUG
Loading

0 comments on commit 1805266

Please sign in to comment.