Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add runtime health endpoint #22

Merged
merged 1 commit into from
Mar 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,21 @@ public void process(MavenProject project, CamelCatalog catalog, Map<String, Came
artifacts.put(artifact.getArtifactId(), artifact);
}

// ************************
//
// camel-k-runtime-health
//
// ************************

{
CamelArtifact artifact = new CamelArtifact();
artifact.setGroupId("org.apache.camel.k");
artifact.setArtifactId("camel-k-runtime-health");
artifact.addDependency("org.apache.camel", "camel-netty4-http");

artifacts.put(artifact.getArtifactId(), artifact);
}

// ************************
//
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,21 @@ public void process(MavenProject project, CamelCatalog catalog, Map<String, Came
artifacts.put(artifact.getArtifactId(), artifact);
}

// ************************
//
// camel-k-runtime-health
//
// ************************

{
CamelArtifact artifact = new CamelArtifact();
artifact.setGroupId("org.apache.camel.k");
artifact.setArtifactId("camel-k-runtime-health");
artifact.addDependency("org.apache.camel", "camel-netty4-http");

artifacts.put(artifact.getArtifactId(), artifact);
}

// ************************
//
//
Expand Down
11 changes: 8 additions & 3 deletions camel-k-runtime-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<artifactId>camel-k-runtime-bom</artifactId>
<version>0.3.1-SNAPSHOT</version>
<packaging>pom</packaging>

<developers>
<developer>
<name>The Apache Camel Team</name>
Expand All @@ -43,12 +43,12 @@
</properties>
</developer>
</developers>

<issueManagement>
<system>github</system>
<url>https://github.com/apache/camel-k-runtime/issues</url>
</issueManagement>

<scm>
<connection>scm:git:http://gitbox.apache.org/repos/asf/camel-k-runtime.git</connection>
<developerConnection>scm:git:https://gitbox.apache.org/repos/asf/camel-k-runtime.git</developerConnection>
Expand Down Expand Up @@ -125,6 +125,11 @@
<artifactId>camel-k-runtime-spring-boot-layout</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel.k</groupId>
<artifactId>camel-k-runtime-health</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel.k</groupId>
<artifactId>camel-knative</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ enum Phase {
Starting,
ConfigureContext,
ConfigureRoutes,
Started
Started,
Stopping,
Stopped
}

@FunctionalInterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,21 @@ public RoutesConfigurer() {

@Override
protected void accept(Runtime runtime) {
final String routes = System.getenv(Constants.ENV_CAMEL_K_ROUTES);
final String routes = System.getenv().getOrDefault(Constants.ENV_CAMEL_K_ROUTES, "");

if (ObjectHelper.isEmpty(routes)) {
LOGGER.warn("No valid routes found in {} environment variable", Constants.ENV_CAMEL_K_ROUTES);
LOGGER.warn("No routes found in {} environment variable", Constants.ENV_CAMEL_K_ROUTES);
}

load(runtime, routes.split(",", -1));
}

protected void load(Runtime runtime, String[] routes) {
for (String route: routes) {
if (ObjectHelper.isEmpty(route)) {
continue;
}

final Source source;
final RoutesLoader loader;
final RouteBuilder builder;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

org.apache.camel.k.listener.ContextConfigurer
org.apache.camel.k.listener.ContextLifecycleConfigurer
org.apache.camel.k.listener.RoutesConfigurer
org.apache.camel.k.listener.RoutesDumper
135 changes: 135 additions & 0 deletions camel-k-runtime-health/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.apache.camel.k</groupId>
<artifactId>camel-k-runtime-parent</artifactId>
<version>0.3.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>camel-k-runtime-health</artifactId>

<dependencies>

<!-- ****************************** -->
<!-- -->
<!-- RUNTIME -->
<!-- -->
<!-- ****************************** -->

<dependency>
<groupId>org.apache.camel.k</groupId>
<artifactId>camel-k-runtime-core</artifactId>
</dependency>

<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-netty4-http</artifactId>
<scope>provided</scope>
</dependency>

<!-- ****************************** -->
<!-- -->
<!-- TESTS -->
<!-- -->
<!-- ****************************** -->

<dependency>
<groupId>org.apache.camel.k</groupId>
<artifactId>camel-k-runtime-jvm</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertj.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j2.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>${log4j2.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<profiles>
<profile>
<id>camel3</id>
<activation>
<property>
<name>camel3</name>
</property>
</activation>
<dependencies>
<!-- runtime -->
<dependency>
<groupId>org.apache.camel.k</groupId>
<artifactId>camel-k-adapter-camel-3</artifactId>
<scope>provided</scope>
</dependency>
<!-- test -->
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-properties</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
<profile>
<id>camel2</id>
<activation>
<property>
<name>!camel3</name>
</property>
</activation>
<dependencies>
<!-- runtime -->
<dependency>
<groupId>org.apache.camel.k</groupId>
<artifactId>camel-k-adapter-camel-2</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
</profile>
</profiles>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.k.health;

import org.apache.camel.k.Runtime;
import org.apache.camel.spi.HasId;

public class HealthConfigurer implements Runtime.Listener, HasId {
public static final String ID = "endpoint.health";
public static final String DEFAULT_BIND_HOST = "0.0.0.0";
public static final int DEFAULT_BIND_PORT = 8081;
public static final String DEFAULT_PATH = "/health";

private HealthEndpoint endpoint;

private String bindHost;
private int bindPort;
private String path;

public HealthConfigurer() {
this.bindHost = DEFAULT_BIND_HOST;
this.bindPort = DEFAULT_BIND_PORT;
this.path = DEFAULT_PATH;
}

public String getBindHost() {
return bindHost;
}

public void setBindHost(String bindHost) {
this.bindHost = bindHost;
}

public int getBindPort() {
return bindPort;
}

public void setBindPort(int bindPort) {
this.bindPort = bindPort;
}

public String getPath() {
return path;
}

public void setPath(String path) {
this.path = path;
}

@Override
public void accept(Runtime.Phase phase, Runtime runtime) {
try {
if (phase == Runtime.Phase.Starting) {
endpoint = new HealthEndpoint(runtime.getContext(), bindHost, bindPort, path);
endpoint.start();
} else if (phase == Runtime.Phase.Stopping) {
if (endpoint != null) {
endpoint.stop();
}
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}

@Override
public String getId() {
return ID;
}
}
Loading