You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2021/12/30 12:04:21 UTC
[camel] 05/30: CAMEL-17384: Developer Console SPI
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch console
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 4fe4d7f624f0adfb00f4b06e600225e01f8d9e2a
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Dec 27 11:30:46 2021 +0100
CAMEL-17384: Developer Console SPI
---
.../apache/camel/spi/annotations/DevConsole.java | 39 +++++++++++++++++
.../java/org/apache/camel/console/DevConsole.java | 8 ++--
.../services/org/apache/camel/dev-console/context | 2 +
.../camel/impl/console/AbstractDevConsole.java | 14 +++---
.../camel/impl/console/ContextDevConsole.java | 51 ++++++++++++++++++++++
.../camel/impl/health/ContextHealthCheck.java | 23 +++-------
.../apache/camel/spi/annotations/DevConsole.java | 39 +++++++++++++++++
7 files changed, 148 insertions(+), 28 deletions(-)
diff --git a/core/camel-api/src/generated/java/org/apache/camel/spi/annotations/DevConsole.java b/core/camel-api/src/generated/java/org/apache/camel/spi/annotations/DevConsole.java
new file mode 100644
index 0000000..f504ea0
--- /dev/null
+++ b/core/camel-api/src/generated/java/org/apache/camel/spi/annotations/DevConsole.java
@@ -0,0 +1,39 @@
+/*
+ * 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.spi.annotations;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Marks a class as a custom developer console.
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Documented
+@Target({ ElementType.TYPE })
+@ServiceFactory("dev-console")
+public @interface DevConsole {
+
+ /**
+ * The ID of the dev console.
+ */
+ String value();
+
+}
diff --git a/core/camel-api/src/main/java/org/apache/camel/console/DevConsole.java b/core/camel-api/src/main/java/org/apache/camel/console/DevConsole.java
index 87f6f49..f5dd0e9 100644
--- a/core/camel-api/src/main/java/org/apache/camel/console/DevConsole.java
+++ b/core/camel-api/src/main/java/org/apache/camel/console/DevConsole.java
@@ -33,14 +33,14 @@ public interface DevConsole {
}
/**
- * The ID of this console.
+ * The group of this console.
*/
- String getId();
+ String getGroup();
/**
- * The group of this console.
+ * The ID of this console.
*/
- String getGroup();
+ String getId();
/**
* Whether this console supports the given media type.
diff --git a/core/camel-console/src/generated/resources/META-INF/services/org/apache/camel/dev-console/context b/core/camel-console/src/generated/resources/META-INF/services/org/apache/camel/dev-console/context
new file mode 100644
index 0000000..ed3afd7
--- /dev/null
+++ b/core/camel-console/src/generated/resources/META-INF/services/org/apache/camel/dev-console/context
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+class=org.apache.camel.impl.console.ContextDevConsole
diff --git a/core/camel-console/src/main/java/org/apache/camel/impl/console/AbstractDevConsole.java b/core/camel-console/src/main/java/org/apache/camel/impl/console/AbstractDevConsole.java
index cfbde35..cba5830 100644
--- a/core/camel-console/src/main/java/org/apache/camel/impl/console/AbstractDevConsole.java
+++ b/core/camel-console/src/main/java/org/apache/camel/impl/console/AbstractDevConsole.java
@@ -29,13 +29,13 @@ public abstract class AbstractDevConsole implements DevConsole, CamelContextAwar
private CamelContext camelContext;
private final Object lock;
- private final String id;
private final String group;
+ private final String id;
- public AbstractDevConsole(String id, String group) {
+ public AbstractDevConsole(String group, String id) {
this.lock = new Object();
- this.id = id;
this.group = group;
+ this.id = id;
}
@Override
@@ -54,13 +54,13 @@ public abstract class AbstractDevConsole implements DevConsole, CamelContextAwar
}
@Override
- public String getId() {
- return id;
+ public String getGroup() {
+ return group;
}
@Override
- public String getGroup() {
- return group;
+ public String getId() {
+ return id;
}
@Override
diff --git a/core/camel-console/src/main/java/org/apache/camel/impl/console/ContextDevConsole.java b/core/camel-console/src/main/java/org/apache/camel/impl/console/ContextDevConsole.java
new file mode 100644
index 0000000..b8ec2a6
--- /dev/null
+++ b/core/camel-console/src/main/java/org/apache/camel/impl/console/ContextDevConsole.java
@@ -0,0 +1,51 @@
+/*
+ * 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.impl.console;
+
+import java.util.Map;
+
+import org.apache.camel.api.management.ManagedCamelContext;
+import org.apache.camel.api.management.mbean.ManagedCamelContextMBean;
+import org.apache.camel.spi.annotations.DevConsole;
+
+@DevConsole("context")
+public class ContextDevConsole extends AbstractDevConsole {
+
+ public ContextDevConsole() {
+ super("camel", "context");
+ }
+
+ @Override
+ protected Object doCall(MediaType mediaType, Map<String, Object> options) {
+ // only text is supported
+ StringBuilder sb = new StringBuilder();
+
+ sb.append(String.format("Apache Camel %s (%s) uptime %s", getCamelContext().getVersion(), getCamelContext().getName(),
+ getCamelContext().getUptime()));
+ sb.append("\n");
+ ManagedCamelContext mcc = getCamelContext().getExtension(ManagedCamelContext.class);
+ if (mcc != null) {
+ ManagedCamelContextMBean mb = mcc.getManagedCamelContext();
+ sb.append(String.format("\n Total: %s", mb.getExchangesTotal()));
+ sb.append(String.format("\n Failed: %s", mb.getExchangesFailed()));
+ sb.append(String.format("\n Inflight: %s", mb.getExchangesInflight()));
+ sb.append("\n");
+ }
+
+ return sb.toString();
+ }
+}
diff --git a/core/camel-health/src/main/java/org/apache/camel/impl/health/ContextHealthCheck.java b/core/camel-health/src/main/java/org/apache/camel/impl/health/ContextHealthCheck.java
index 622451b..11e3729 100644
--- a/core/camel-health/src/main/java/org/apache/camel/impl/health/ContextHealthCheck.java
+++ b/core/camel-health/src/main/java/org/apache/camel/impl/health/ContextHealthCheck.java
@@ -27,23 +27,12 @@ import org.apache.camel.health.HealthCheckResultBuilder;
*/
@org.apache.camel.spi.annotations.HealthCheck("context-check")
public final class ContextHealthCheck extends AbstractHealthCheck {
- private CamelContext camelContext;
public ContextHealthCheck() {
super("camel", "context");
}
@Override
- public CamelContext getCamelContext() {
- return camelContext;
- }
-
- @Override
- public void setCamelContext(CamelContext camelContext) {
- this.camelContext = camelContext;
- }
-
- @Override
public boolean isLiveness() {
// this check is only for readiness
return false;
@@ -53,14 +42,14 @@ public final class ContextHealthCheck extends AbstractHealthCheck {
protected void doCall(HealthCheckResultBuilder builder, Map<String, Object> options) {
builder.unknown();
- if (camelContext != null) {
- builder.detail("context.name", camelContext.getName());
- builder.detail("context.version", camelContext.getVersion());
- builder.detail("context.status", camelContext.getStatus().name());
+ if (getCamelContext() != null) {
+ builder.detail("context.name", getCamelContext().getName());
+ builder.detail("context.version", getCamelContext().getVersion());
+ builder.detail("context.status", getCamelContext().getStatus().name());
- if (camelContext.getStatus().isStarted()) {
+ if (getCamelContext().getStatus().isStarted()) {
builder.up();
- } else if (camelContext.getStatus().isStopped()) {
+ } else if (getCamelContext().getStatus().isStopped()) {
builder.down();
}
}
diff --git a/tooling/spi-annotations/src/main/java/org/apache/camel/spi/annotations/DevConsole.java b/tooling/spi-annotations/src/main/java/org/apache/camel/spi/annotations/DevConsole.java
new file mode 100644
index 0000000..f504ea0
--- /dev/null
+++ b/tooling/spi-annotations/src/main/java/org/apache/camel/spi/annotations/DevConsole.java
@@ -0,0 +1,39 @@
+/*
+ * 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.spi.annotations;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Marks a class as a custom developer console.
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Documented
+@Target({ ElementType.TYPE })
+@ServiceFactory("dev-console")
+public @interface DevConsole {
+
+ /**
+ * The ID of the dev console.
+ */
+ String value();
+
+}