Skip to content

Commit

Permalink
Log runtime version when starting apache#512
Browse files Browse the repository at this point in the history
  • Loading branch information
lburgazzoli committed Sep 30, 2020
1 parent b1a78a8 commit 99511ad
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.k.CompositeClassloader;
import org.apache.camel.k.Runtime;
import org.apache.camel.k.support.RuntimeSupport;
import org.apache.camel.main.BaseMainSupport;
import org.apache.camel.main.MainSupport;
import org.apache.camel.main.RoutesCollector;
Expand Down Expand Up @@ -57,6 +58,7 @@ public ApplicationRuntime() {
this.main = new MainAdapter();
this.main.configure().setXmlRoutes("false");
this.main.configure().setXmlRests("false");
this.main.configure().setXmlRouteTemplates("false");
this.main.setDefaultPropertyPlaceholderLocation("false");
this.main.setRoutesCollector(new NoRoutesCollector());
this.main.addMainListener(new MainListenerAdapter());
Expand All @@ -68,6 +70,7 @@ public CamelContext getCamelContext() {
}

public void run() throws Exception {
LOGGER.info("Apache Camel K Runtime {}", RuntimeSupport.getCamelVersion());
this.main.run();
}

Expand Down Expand Up @@ -119,6 +122,7 @@ public void addListener(Phase phase, ThrowingConsumer<Runtime, Exception> consum
private final class MainListenerAdapter implements org.apache.camel.main.MainListener {
@Override
public void beforeInitialize(BaseMainSupport main) {
invokeListeners(Phase.Initializing);
invokeListeners(Phase.ConfigureProperties);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.apache.camel.k.Runtime;
import org.apache.camel.k.quarkus.ApplicationProducers;
import org.apache.camel.k.quarkus.ApplicationRecorder;
import org.apache.camel.k.support.RuntimeSupport;
import org.apache.camel.quarkus.core.deployment.spi.CamelRuntimeTaskBuildItem;
import org.apache.camel.quarkus.main.deployment.spi.CamelMainBuildItem;
import org.apache.camel.quarkus.main.deployment.spi.CamelMainListenerBuildItem;
Expand Down Expand Up @@ -60,6 +61,7 @@ CamelRuntimeTaskBuildItem registerRuntime(
BeanContainerBuildItem beanContainer) {

recorder.publishRuntime(camelMain.getInstance(), beanContainer.getValue());
recorder.version(RuntimeSupport.getCamelVersion());

return new CamelRuntimeTaskBuildItem("camel-k-runtime");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public ListenerAdapter(List<org.apache.camel.k.Runtime.Listener> listeners) {

@Override
public void beforeInitialize(BaseMainSupport main) {
invokeListeners(org.apache.camel.k.Runtime.Phase.Initializing);
invokeListeners(org.apache.camel.k.Runtime.Phase.ConfigureProperties);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,14 @@
import org.apache.camel.main.MainListener;
import org.apache.camel.main.RoutesCollector;
import org.apache.camel.quarkus.main.CamelMain;
import org.slf4j.LoggerFactory;

@Recorder
public class ApplicationRecorder {
public void version(String version) {
LoggerFactory.getLogger(Runtime.class).info("Apache Camel K Runtime {}", version);
}

public RuntimeValue<MainListener> createMainListener(List<Runtime.Listener> listeners) {
return new RuntimeValue<>(new Application.ListenerAdapter(listeners));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,11 @@ default void close() throws Exception {
}

enum Phase {
Starting,
Initializing,
ConfigureProperties,
ConfigureContext,
ConfigureRoutes,
Starting,
Started,
Stopping,
Stopped
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Properties;
import java.util.Set;
import java.util.TreeSet;
Expand All @@ -30,6 +31,7 @@
import org.apache.camel.ExtendedCamelContext;
import org.apache.camel.k.Constants;
import org.apache.camel.k.ContextCustomizer;
import org.apache.camel.k.Runtime;
import org.apache.camel.k.Source;
import org.apache.camel.k.SourceLoader;
import org.apache.camel.spi.HasCamelContext;
Expand Down Expand Up @@ -247,4 +249,24 @@ public static List<SourceLoader.Interceptor> loadInterceptors(CamelContext conte
return answer;
}

// *********************************
//
// Helpers - Misc
//
// *********************************

public static String getCamelVersion() {
String version = null;

Package aPackage = Runtime.class.getPackage();
if (aPackage != null) {
version = aPackage.getImplementationVersion();
if (version == null) {
version = aPackage.getSpecificationVersion();
}
}

return Objects.requireNonNull(version, "Could not determine Camel K Runtime version");
}

}

0 comments on commit 99511ad

Please sign in to comment.