You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by lb...@apache.org on 2020/02/14 08:12:47 UTC

[camel-k-runtime] branch master updated: Fix #241: add master helper component

This is an automated email from the ASF dual-hosted git repository.

lburgazzoli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k-runtime.git


The following commit(s) were added to refs/heads/master by this push:
     new a7fa2dd  Fix #241: add master helper component
a7fa2dd is described below

commit a7fa2ddf43f0f1177da3dbdc0e93be5e36051c93
Author: Nicola Ferraro <ni...@gmail.com>
AuthorDate: Fri Feb 14 01:09:49 2020 +0100

    Fix #241: add master helper component
---
 camel-k-runtime-bom/pom.xml                        |   5 +
 camel-k-runtime-master/pom.xml                     | 134 +++++++++++++++++++++
 .../camel/k/master/MasterContextCustomizer.java    |  78 ++++++++++++
 .../services/org/apache/camel/k/customizer/master  |  18 +++
 .../camel/k/master/MasterCustomizerTest.java       |  37 ++++++
 .../src/test/resources/log4j2-test.xml             |  37 ++++++
 pom.xml                                            |   6 +-
 7 files changed, 313 insertions(+), 2 deletions(-)

diff --git a/camel-k-runtime-bom/pom.xml b/camel-k-runtime-bom/pom.xml
index 1b0c878..cbff077 100644
--- a/camel-k-runtime-bom/pom.xml
+++ b/camel-k-runtime-bom/pom.xml
@@ -153,6 +153,11 @@
                 <artifactId>camel-k-runtime-cron</artifactId>
                 <version>${project.version}</version>
             </dependency>
+            <dependency>
+                <groupId>org.apache.camel.k</groupId>
+                <artifactId>camel-k-runtime-master</artifactId>
+                <version>${project.version}</version>
+            </dependency>
 
             <!-- runtime - quarkus -->
             <dependency>
diff --git a/camel-k-runtime-master/pom.xml b/camel-k-runtime-master/pom.xml
new file mode 100644
index 0000000..befd5e9
--- /dev/null
+++ b/camel-k-runtime-master/pom.xml
@@ -0,0 +1,134 @@
+<?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>1.1.0-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>camel-k-runtime-master</artifactId>
+
+    <dependencies>
+
+        <!-- ****************************** -->
+        <!--                                -->
+        <!-- RUNTIME                        -->
+        <!--                                -->
+        <!-- ****************************** -->
+
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-core-engine</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-kubernetes</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel.k</groupId>
+            <artifactId>camel-k-runtime-core</artifactId>
+        </dependency>
+
+        <!-- ****************************** -->
+        <!--                                -->
+        <!-- TESTS                          -->
+        <!--                                -->
+        <!-- ****************************** -->
+
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-test</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-master</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-main</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel.k</groupId>
+            <artifactId>camel-k-runtime-main</artifactId>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.junit.jupiter</groupId>
+            <artifactId>junit-jupiter-api</artifactId>
+            <version>${junit.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.junit.jupiter</groupId>
+            <artifactId>junit-jupiter-engine</artifactId>
+            <version>${junit.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.junit.jupiter</groupId>
+            <artifactId>junit-jupiter-params</artifactId>
+            <version>${junit.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>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.jboss.jandex</groupId>
+                <artifactId>jandex-maven-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>make-index</id>
+                        <goals>
+                            <goal>jandex</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>
diff --git a/camel-k-runtime-master/src/main/java/org/apache/camel/k/master/MasterContextCustomizer.java b/camel-k-runtime-master/src/main/java/org/apache/camel/k/master/MasterContextCustomizer.java
new file mode 100644
index 0000000..4669b75
--- /dev/null
+++ b/camel-k-runtime-master/src/main/java/org/apache/camel/k/master/MasterContextCustomizer.java
@@ -0,0 +1,78 @@
+/*
+ * 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.master;
+
+import java.util.Collections;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.component.kubernetes.cluster.KubernetesClusterService;
+import org.apache.camel.k.ContextCustomizer;
+import org.apache.camel.util.ObjectHelper;
+
+public class MasterContextCustomizer implements ContextCustomizer {
+
+    private String configMapName;
+
+    private String labelKey;
+
+    private String labelValue;
+
+    public MasterContextCustomizer() {
+    }
+
+    @Override
+    public void apply(CamelContext camelContext) {
+        try {
+            KubernetesClusterService clusterService = new KubernetesClusterService();
+            if (ObjectHelper.isNotEmpty(configMapName)) {
+                clusterService.setConfigMapName(this.configMapName);
+            }
+            if (ObjectHelper.isNotEmpty(this.labelKey) && ObjectHelper.isNotEmpty(this.labelValue)) {
+                clusterService.setClusterLabels(Collections.singletonMap(this.labelKey, this.labelValue));
+            }
+            camelContext.addService(clusterService);
+        } catch (Exception ex) {
+            throw new RuntimeCamelException(ex);
+        }
+    }
+
+    public String getConfigMapName() {
+        return configMapName;
+    }
+
+    public void setConfigMapName(String configMapName) {
+        this.configMapName = configMapName;
+    }
+
+    public String getLabelKey() {
+        return labelKey;
+    }
+
+    public void setLabelKey(String labelKey) {
+        this.labelKey = labelKey;
+    }
+
+    public String getLabelValue() {
+        return labelValue;
+    }
+
+    public void setLabelValue(String labelValue) {
+        this.labelValue = labelValue;
+    }
+
+}
diff --git a/camel-k-runtime-master/src/main/resources/META-INF/services/org/apache/camel/k/customizer/master b/camel-k-runtime-master/src/main/resources/META-INF/services/org/apache/camel/k/customizer/master
new file mode 100644
index 0000000..0b002fb
--- /dev/null
+++ b/camel-k-runtime-master/src/main/resources/META-INF/services/org/apache/camel/k/customizer/master
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+class=org.apache.camel.k.master.MasterContextCustomizer
diff --git a/camel-k-runtime-master/src/test/java/org/apache/camel/k/master/MasterCustomizerTest.java b/camel-k-runtime-master/src/test/java/org/apache/camel/k/master/MasterCustomizerTest.java
new file mode 100644
index 0000000..066c655
--- /dev/null
+++ b/camel-k-runtime-master/src/test/java/org/apache/camel/k/master/MasterCustomizerTest.java
@@ -0,0 +1,37 @@
+/*
+ * 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.master;
+
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.k.Runtime;
+import org.apache.camel.support.cluster.ClusterServiceHelper;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
+
+public class MasterCustomizerTest {
+
+    @Test
+    public void testMasterCustomizer() {
+        Runtime runtime = Runtime.on(new DefaultCamelContext());
+
+        MasterContextCustomizer masterCustomizer = new MasterContextCustomizer();
+        masterCustomizer.apply(runtime.getCamelContext());
+
+        assertThat(ClusterServiceHelper.lookupService(runtime.getCamelContext())).isNotEmpty();
+    }
+}
diff --git a/camel-k-runtime-master/src/test/resources/log4j2-test.xml b/camel-k-runtime-master/src/test/resources/log4j2-test.xml
new file mode 100644
index 0000000..3784c66
--- /dev/null
+++ b/camel-k-runtime-master/src/test/resources/log4j2-test.xml
@@ -0,0 +1,37 @@
+<?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.
+
+-->
+<Configuration status="INFO">
+  <Appenders>
+    <Console name="STDOUT" target="SYSTEM_OUT">
+      <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS}|%-5level|%t|%c - %msg%n"/>
+    </Console>
+    <Null name="NONE"/>
+  </Appenders>
+
+  <Loggers>
+    <Logger name="io.netty" level="INFO"/>
+    <Logger name="io.netty.handler.logging" level="DEBUG"/>
+    <Root level="INFO">
+      <!--<AppenderRef ref="STDOUT"/>-->
+      <AppenderRef ref="NONE"/>
+    </Root>
+  </Loggers>
+
+</Configuration>
diff --git a/pom.xml b/pom.xml
index 3f0ea4f..2130831 100644
--- a/pom.xml
+++ b/pom.xml
@@ -216,12 +216,14 @@
         <module>camel-k-loader-java</module>
         <module>camel-k-loader-knative</module>
 
+        <module>camel-k-runtime-bom</module>
+
         <module>camel-k-runtime-cron</module>
         <module>camel-k-runtime-health</module>
-        <module>camel-k-runtime-servlet</module>
         <module>camel-k-runtime-knative</module>
+        <module>camel-k-runtime-master</module>
+        <module>camel-k-runtime-servlet</module>
         <module>camel-k-runtime-webhook</module>
-        <module>camel-k-runtime-bom</module>
 
         <module>examples</module>
         <module>distribution</module>