Skip to content

Commit

Permalink
Add debug JVM only extension
Browse files Browse the repository at this point in the history
Fixes #3775
  • Loading branch information
jamesnetherton committed May 23, 2022
1 parent 5631d86 commit 70e80c3
Show file tree
Hide file tree
Showing 19 changed files with 678 additions and 0 deletions.
13 changes: 13 additions & 0 deletions docs/modules/ROOT/examples/others/debug.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Do not edit directly!
# This file was generated by camel-quarkus-maven-plugin:update-extension-doc-page
cqArtifactId: camel-quarkus-debug
cqArtifactIdBase: debug
cqNativeSupported: false
cqStatus: Preview
cqDeprecated: false
cqJvmSince: 2.10.0
cqNativeSince: n/a
cqCamelPartName: debug
cqCamelPartTitle: Debug
cqCamelPartDescription: Enables Camel Route Debugging
cqExtensionPageTitle: Debug
1 change: 1 addition & 0 deletions docs/modules/ROOT/nav.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
*** xref:reference/extensions/debezium-mysql.adoc[Debezium MySQL Connector]
*** xref:reference/extensions/debezium-postgres.adoc[Debezium PostgresSQL Connector]
*** xref:reference/extensions/debezium-sqlserver.adoc[Debezium SQL Server Connector]
*** xref:reference/extensions/debug.adoc[Debug]
*** xref:reference/extensions/djl.adoc[Deep Java Library]
*** xref:reference/extensions/digitalocean.adoc[DigitalOcean]
*** xref:reference/extensions/direct.adoc[Direct]
Expand Down
35 changes: 35 additions & 0 deletions docs/modules/ROOT/pages/reference/extensions/debug.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Do not edit directly!
// This file was generated by camel-quarkus-maven-plugin:update-extension-doc-page
= Debug
:linkattrs:
:cq-artifact-id: camel-quarkus-debug
:cq-native-supported: false
:cq-status: Preview
:cq-status-deprecation: Preview
:cq-description: Enables Camel Route Debugging
:cq-deprecated: false
:cq-jvm-since: 2.10.0
:cq-native-since: n/a

[.badges]
[.badge-key]##JVM since##[.badge-supported]##2.10.0## [.badge-key]##Native##[.badge-unsupported]##unsupported##

Enables Camel Route Debugging

== What's inside

* xref:{cq-camel-components}:others:debug.adoc[Debug]

Please refer to the above link for usage and configuration details.

== Maven coordinates

[source,xml]
----
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-debug</artifactId>
</dependency>
----

Check the xref:user-guide/index.adoc[User guide] for more information about writing Camel Quarkus applications.
83 changes: 83 additions & 0 deletions extensions-jvm/debug/deployment/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-debug-parent</artifactId>
<version>2.10.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>camel-quarkus-debug-deployment</artifactId>
<name>Camel Quarkus :: Debug :: Deployment</name>

<dependencies>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-core-deployment</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-management-deployment</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-debug</artifactId>
</dependency>

<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5-internal</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extension-processor</artifactId>
<version>${quarkus.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* 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.quarkus.component.debug.deployment;

import io.quarkus.deployment.IsDevelopment;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.AllowJNDIBuildItem;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.pkg.steps.NativeBuild;
import org.apache.camel.quarkus.core.deployment.spi.CamelServiceDestination;
import org.apache.camel.quarkus.core.deployment.spi.CamelServicePatternBuildItem;

class DebugProcessor {
private static final String FEATURE = "camel-debug";

@BuildStep(onlyIf = IsDevelopment.class)
FeatureBuildItem feature() {
return new FeatureBuildItem(FEATURE);
}

@BuildStep(onlyIf = IsDevelopment.class)
AllowJNDIBuildItem allowJNDI() {
return new AllowJNDIBuildItem();
}

@BuildStep(onlyIfNot = IsDevelopment.class)
CamelServicePatternBuildItem camelDebuggerFactoryServicePattern() {
// Prevent debugging if not in dev mode. This is added as an exclusion since
// core defines an include path filter for META-INF/services/org/apache/camel/*
return new CamelServicePatternBuildItem(CamelServiceDestination.DISCOVERY, false,
"META-INF/services/org/apache/camel/debugger-factory");
}

@BuildStep(onlyIf = NativeBuild.class)
void nativeUnsupported() {
throw new RuntimeException("The " + FEATURE + " extension is not supported in native mode "
+ "as JMX is not supported on GraalVM");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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.quarkus.component.debug.deployment;

import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.apache.camel.CamelContext;
import org.apache.camel.impl.debugger.BacklogDebugger;

@Path("/debug")
public class DebugResource {
@Inject
CamelContext context;

@Path("/enabled")
@GET
@Produces(MediaType.TEXT_PLAIN)
public boolean debuggingEnabled() {
BacklogDebugger debugger = BacklogDebugger.getBacklogDebugger(context);
return debugger != null && debugger.isEnabled();
}
}
Original file line number Diff line number Diff line change
@@ -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.quarkus.component.debug.deployment;

import java.io.IOException;
import java.net.Socket;

import io.quarkus.test.QuarkusDevModeTest;
import io.restassured.RestAssured;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import static org.hamcrest.Matchers.is;

public class DebugTest {

@RegisterExtension
static final QuarkusDevModeTest TEST = new QuarkusDevModeTest()
.setArchiveProducer(() -> ShrinkWrap
.create(JavaArchive.class)
.addClass(DebugResource.class));

@Test
public void camelDebuggingEnabledInDevMode() throws IOException {
RestAssured.get("/debug/enabled")
.then()
.body(is("true"))
.statusCode(200);

try (Socket socket = new Socket("localhost", 1099)) {
Assertions.assertTrue(socket.isConnected());
}
}
}
39 changes: 39 additions & 0 deletions extensions-jvm/debug/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-extensions-jvm</artifactId>
<version>2.10.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>camel-quarkus-debug-parent</artifactId>
<name>Camel Quarkus :: Debug</name>
<packaging>pom</packaging>

<modules>
<module>deployment</module>
<module>runtime</module>
</modules>
</project>

0 comments on commit 70e80c3

Please sign in to comment.