diff --git a/incubator/java-openliberty/README.md b/incubator/java-openliberty/README.md index a595a23ee..e845d2f05 100644 --- a/incubator/java-openliberty/README.md +++ b/incubator/java-openliberty/README.md @@ -65,10 +65,6 @@ OpenAPI endpoints: The default template uses JUnit 5. You may be used to JUnit 4, but here are some great reasons to make the switch https://developer.ibm.com/dwblog/2017/top-five-reasons-to-use-junit-5-java/ -### Kafka template - -The kafka template allows you to develop applications that connect to Kafka using MicroProfile Reactive Messaging. For more information, see the [kafka readme](templates/kafka/README.md). - ## Getting Started 1. Create a new folder in your local directory and initialize it using the Appsody CLI, e.g.: diff --git a/incubator/java-openliberty/stack.yaml b/incubator/java-openliberty/stack.yaml index 6ed37f8ee..3e6a104e0 100644 --- a/incubator/java-openliberty/stack.yaml +++ b/incubator/java-openliberty/stack.yaml @@ -1,5 +1,5 @@ name: Open Liberty -version: 0.2.19 +version: 0.2.20 description: Eclipse MicroProfile & Jakarta EE on Open Liberty & OpenJ9 using Maven license: Apache-2.0 language: java diff --git a/incubator/java-openliberty/templates/kafka/.gitignore b/incubator/java-openliberty/templates/kafka/.gitignore deleted file mode 100644 index 4b24eb3d2..000000000 --- a/incubator/java-openliberty/templates/kafka/.gitignore +++ /dev/null @@ -1,29 +0,0 @@ -!.keep - -target/ - -### STS ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache - -### IntelliJ IDEA ### -.idea -*.iws -*.iml -*.ipr - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ -/build/ - -### VS Code ### -.vscode/ diff --git a/incubator/java-openliberty/templates/kafka/.vscode/launch.json b/incubator/java-openliberty/templates/kafka/.vscode/launch.json deleted file mode 100644 index 25fa61fc3..000000000 --- a/incubator/java-openliberty/templates/kafka/.vscode/launch.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "version": "0.2.0", - "configurations": [ - { - "name": "Appsody: Attach java debugger", - "type": "java", - "request": "attach", - "hostName": "localhost", - "port": 7777 - } - ] -} diff --git a/incubator/java-openliberty/templates/kafka/.vscode/tasks.json b/incubator/java-openliberty/templates/kafka/.vscode/tasks.json deleted file mode 100644 index 0959f421e..000000000 --- a/incubator/java-openliberty/templates/kafka/.vscode/tasks.json +++ /dev/null @@ -1,47 +0,0 @@ -{ - "version": "2.0.0", - "tasks": [ - { - "label": "Appsody: run", - "type": "shell", - "command": "appsody run", - "group": "build", - "problemMatcher": [] - }, - { - "label": "Appsody: debug", - "type": "shell", - "command": "appsody debug", - "group": "build", - "problemMatcher": [] - }, - { - "label": "Appsody: test", - "type": "shell", - "command": "appsody test", - "group": "test", - "problemMatcher": [] - }, - { - "label": "Appsody: build", - "type": "shell", - "command": "appsody build", - "group": "build", - "problemMatcher": [] - }, - { - "label": "Appsody: deploy", - "type": "shell", - "command": "appsody deploy", - "group": "build", - "problemMatcher": [] - }, - { - "label": "Appsody: stop", - "type": "shell", - "command": "appsody stop", - "group": "build", - "problemMatcher": [] - } - ] -} diff --git a/incubator/java-openliberty/templates/kafka/README.md b/incubator/java-openliberty/templates/kafka/README.md deleted file mode 100644 index f9e49ca38..000000000 --- a/incubator/java-openliberty/templates/kafka/README.md +++ /dev/null @@ -1,84 +0,0 @@ -# Kafka template for Open Liberty - -This template can be used to develop Liberty applications that connect to Kafka by using MicroProfile Reactive messaging. A simple `StarterApplication` is included that enables basic production and consumption of events. - - -## Getting Started with the StarterApplication. - -### 1. Create a new folder and initialize it using appsody init: - - -``` -mkdir test-appsody-kafka -cd test-appsody-kafka -appsody init java-openliberty kafka -``` - -### 2. Start Kafka and ZooKeeper - -In order to run the `StarterApplication` you must start Kafka and ZooKeeper containers. ZooKeeper is a dependency of Kafka. Use the `docker-compose.yaml` that is provided in the template to start both containers. - - -Start docker compose with the following command: - -```docker-compose up``` - -If you run `docker network list`, you should see a new network with the name of your project directory and the word `_default` appended. For example, `test-appsody-kafka_default`. - -### 3. Run the Appsody application in the new network - -Your Appsody application must be run in the same network as Kafka. You must also supply the host and port number of the Kafka broker as an environment variable. - -Run the application using the following command: - -```appsody run --network test-appsody-kafka_default --docker-options "--env MP_MESSAGING_CONNECTOR_LIBERTY_KAFKA_BOOTSTRAP_SERVERS=kafka:9092"``` - -Alternatively, edit `src/main/resources/META-INF/microprofile-config.properties` as follows: - -``` -mp.messaging.connector.liberty-kafka.bootstrap.servers=kafka:9092 -``` - -(this value is provided in the sample file, commented out) - -### 4. Produce a message to a topic - -Run another container in the same network: - -```docker run -it --network test-appsody-kafka_default strimzi/kafka:0.16.0-kafka-2.4.0 /bin/bash``` - -The next step is to produce a message. Use the following command to start a Kafka Producer that writes to `incomingTopic1`: - -```bin/kafka-console-producer.sh --broker-list kafka:9092 --topic incomingTopic1``` - -Enter text at the prompt to produce a message. - -### 5. Consume a message from a topic - -To view the messages, you can either look at the console log from the Appsody application or you can create a Kafka console consumer using the following command: - -```bin/kafka-console-consumer.sh --bootstrap-server kafka:9092 --topic incomingTopic1 --from-beginning``` - -## Deploying to Kubernetes - -When deploying to a Kubernetes environment, you must configure your application to connect to the Kafka broker. You can use the [Strimzi Kafka operator](https://strimzi.io/docs/quickstart/latest/) to deploy a Kafka broker in a Kubernetes cluster. - -To configure the connection, first run the following command: - -```appsody build``` - -This command generates `app-deploy.yaml` file. -Edit the file to override the bootstrap server configuration by setting an enviornment variable as follows: - -``` -spec: - env: - - name: MP_MESSAGING_CONNECTOR_LIBERTY_KAFKA_BOOTSTRAP_SERVERS - value: :9092 -``` - -Then run the following command to deploy your application: - -``` -appsody deploy --no-build -``` diff --git a/incubator/java-openliberty/templates/kafka/docker-compose.yaml b/incubator/java-openliberty/templates/kafka/docker-compose.yaml deleted file mode 100644 index b706996af..000000000 --- a/incubator/java-openliberty/templates/kafka/docker-compose.yaml +++ /dev/null @@ -1,34 +0,0 @@ -version: '2' -services: - zookeeper: - image: strimzi/kafka:0.17.0-kafka-2.4.0 - command: [ - "sh", "-c", - "bin/zookeeper-server-start.sh config/zookeeper.properties" - ] - ports: - - "2181:2181" - environment: - LOG_DIR: /tmp/logs - - kafka: - image: strimzi/kafka:0.17.0-kafka-2.4.0 - command: [ - "sh", "-c", - "bin/kafka-server-start.sh config/server.properties --override listeners=$${KAFKA_LISTENERS} --override advertised.listeners=$${KAFKA_ADVERTISED_LISTENERS} --override listener.security.protocol.map=$${KAFKA_LISTENER_SECURITY_PROTOCOL_MAP} --override inter.broker.listener.name=$${KAFKA_INTER_BROKER_LISTENER_NAME} --override zookeeper.connect=$${KAFKA_ZOOKEEPER_CONNECT}" - ] - depends_on: - - zookeeper - ports: - - "9092:9092" - - "9093:9093" - expose: - - "9092" - - "9093" - environment: - LOG_DIR: "/tmp/logs" - KAFKA_ADVERTISED_LISTENERS: INSIDE://kafka:9092,OUTSIDE://localhost:9093 - KAFKA_LISTENERS: INSIDE://:9092,OUTSIDE://:9093 - KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: INSIDE:PLAINTEXT,OUTSIDE:PLAINTEXT - KAFKA_INTER_BROKER_LISTENER_NAME: INSIDE - KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181 diff --git a/incubator/java-openliberty/templates/kafka/pom.xml b/incubator/java-openliberty/templates/kafka/pom.xml deleted file mode 100755 index 5149736f1..000000000 --- a/incubator/java-openliberty/templates/kafka/pom.xml +++ /dev/null @@ -1,193 +0,0 @@ - - - - 4.0.0 - - - dev.appsody - java-openliberty - {{.stack.parentpomrange}} - - - - dev.appsody.starter.java-openliberty - starter-app - 1.0-SNAPSHOT - war - - - - - org.apache.kafka - kafka-clients - 2.3.0 - - - org.slf4j - slf4j-log4j12 - 1.7.25 - - - org.eclipse.microprofile.reactive.messaging - microprofile-reactive-messaging-api - 1.0 - provided - - - - - org.eclipse.microprofile - microprofile - 3.2 - pom - provided - - - - jakarta.platform - jakarta.jakartaee-api - 8.0.0 - provided - - - - - org.junit.jupiter - junit-jupiter - 5.6.0 - test - - - org.apache.cxf - cxf-rt-rs-client - 3.2.6 - test - - - org.apache.cxf - cxf-rt-rs-extension-providers - 3.2.6 - test - - - org.glassfish - javax.json - 1.0.4 - test - - - - javax.xml.bind - jaxb-api - 2.3.1 - test - - - com.sun.xml.bind - jaxb-core - 2.3.0.1 - test - - - com.sun.xml.bind - jaxb-impl - 2.3.2 - test - - - javax.activation - activation - 1.1.1 - test - - - - - ${project.artifactId} - - - org.apache.maven.plugins - maven-war-plugin - ${version.maven-war-plugin} - - false - pom.xml - - - - - io.openliberty.tools - liberty-maven-plugin - - true - 120 - - ${http.port} - ${https.port} - ${app.name} - - - - - - org.apache.maven.plugins - maven-surefire-plugin - ${version.maven-surefire-plugin} - - - test - default-test - - - **/it/** - - - ${project.build.directory}/test-reports/unit - - - - - - - - org.apache.maven.plugins - maven-failsafe-plugin - ${version.maven-failsafe-plugin} - - - integration-test - default-cli - - integration-test - - - - **/it/** - - - ${http.port} - ${app.name} - - - - - verify-results - - verify - - - - - - ${project.build.directory}/test-reports/it/failsafe-summary.xml - - - ${project.build.directory}/test-reports/it - - - - - - diff --git a/incubator/java-openliberty/templates/kafka/src/main/java/dev/appsody/starter/StarterApplication.java b/incubator/java-openliberty/templates/kafka/src/main/java/dev/appsody/starter/StarterApplication.java deleted file mode 100755 index 2793e6ea0..000000000 --- a/incubator/java-openliberty/templates/kafka/src/main/java/dev/appsody/starter/StarterApplication.java +++ /dev/null @@ -1,42 +0,0 @@ -package dev.appsody.starter; - - -import org.eclipse.microprofile.reactive.messaging.Incoming; -import org.eclipse.microprofile.reactive.messaging.Outgoing; -import javax.enterprise.context.ApplicationScoped; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -@ApplicationScoped -public class StarterApplication { - private static Logger logger = LoggerFactory.getLogger(StarterApplication.class); - private String receivedMessage; - - /** - * Process an event from one topic and emit a result to another. - * @param message - * @return - */ - @Incoming("incomingTopic1") - @Outgoing("outgoingTopic1") - public String processMessage(String message) { - String completeMessage = "Hello " + message; - logger.info("Message " + completeMessage); - return completeMessage; - } - - /** - * Receive an event. This could be used to do something else with the data - * such as writing it to a database. - * @param message - */ - @Incoming("incomingTopic2") - public void receiveMessage(String message) { - receivedMessage = message; - logger.info("Message " + message); - } - - public String getReceivedMessage() { - return receivedMessage; - } -} diff --git a/incubator/java-openliberty/templates/kafka/src/main/java/dev/appsody/starter/health/StarterLivenessCheck.java b/incubator/java-openliberty/templates/kafka/src/main/java/dev/appsody/starter/health/StarterLivenessCheck.java deleted file mode 100644 index 1a6a76d9d..000000000 --- a/incubator/java-openliberty/templates/kafka/src/main/java/dev/appsody/starter/health/StarterLivenessCheck.java +++ /dev/null @@ -1,25 +0,0 @@ -package dev.appsody.starter.health; - -import javax.enterprise.context.ApplicationScoped; - -import org.eclipse.microprofile.health.HealthCheck; -import org.eclipse.microprofile.health.HealthCheckResponse; -import org.eclipse.microprofile.health.Liveness; - -@Liveness -@ApplicationScoped -public class StarterLivenessCheck implements HealthCheck { - - private boolean isAlive() { - // perform health checks here - - return true; - } - - @Override - public HealthCheckResponse call() { - boolean up = isAlive(); - return HealthCheckResponse.named(this.getClass().getSimpleName()).state(up).build(); - } - -} diff --git a/incubator/java-openliberty/templates/kafka/src/main/java/dev/appsody/starter/health/StarterReadinessCheck.java b/incubator/java-openliberty/templates/kafka/src/main/java/dev/appsody/starter/health/StarterReadinessCheck.java deleted file mode 100644 index b736fa2ec..000000000 --- a/incubator/java-openliberty/templates/kafka/src/main/java/dev/appsody/starter/health/StarterReadinessCheck.java +++ /dev/null @@ -1,25 +0,0 @@ -package dev.appsody.starter.health; - -import javax.enterprise.context.ApplicationScoped; - -import org.eclipse.microprofile.health.HealthCheck; -import org.eclipse.microprofile.health.HealthCheckResponse; -import org.eclipse.microprofile.health.Readiness; - -@Readiness -@ApplicationScoped -public class StarterReadinessCheck implements HealthCheck { - - private boolean isReady() { - // perform readiness checks, e.g. database connection, etc. - - return true; - } - - @Override - public HealthCheckResponse call() { - boolean up = isReady(); - return HealthCheckResponse.named(this.getClass().getSimpleName()).state(up).build(); - } - -} diff --git a/incubator/java-openliberty/templates/kafka/src/main/liberty/config/configDropins/defaults/quick-start-security.xml b/incubator/java-openliberty/templates/kafka/src/main/liberty/config/configDropins/defaults/quick-start-security.xml deleted file mode 100644 index 08a3415af..000000000 --- a/incubator/java-openliberty/templates/kafka/src/main/liberty/config/configDropins/defaults/quick-start-security.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/incubator/java-openliberty/templates/kafka/src/main/liberty/config/server.xml b/incubator/java-openliberty/templates/kafka/src/main/liberty/config/server.xml deleted file mode 100755 index 8da2ae666..000000000 --- a/incubator/java-openliberty/templates/kafka/src/main/liberty/config/server.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - microProfile-3.2 - mpReactiveMessaging-1.0 - - - - - - diff --git a/incubator/java-openliberty/templates/kafka/src/main/resources/META-INF/microprofile-config.properties b/incubator/java-openliberty/templates/kafka/src/main/resources/META-INF/microprofile-config.properties deleted file mode 100644 index 4e5e02615..000000000 --- a/incubator/java-openliberty/templates/kafka/src/main/resources/META-INF/microprofile-config.properties +++ /dev/null @@ -1,17 +0,0 @@ -mp.messaging.connector.liberty-kafka.bootstrap.servers=localhost:9093 -## mp.messaging.connector.liberty-kafka.bootstrap.servers=kafka:9092 - -## incomingTopic1 topic -mp.messaging.incoming.incomingTopic1.connector=liberty-kafka -mp.messaging.incoming.incomingTopic1.topic=incomingTopic1 -mp.messaging.incoming.incomingTopic1.group.id=starter - -## outgoingTopic1 topic -mp.messaging.outgoing.outgoingTopic1.connector=liberty-kafka -mp.messaging.outgoing.outgoingTopic1.value.serializer=org.apache.kafka.common.serialization.StringSerializer -mp.messaging.outgoing.outgoingTopic1.key.serializer=org.apache.kafka.common.serialization.StringSerializer - -## incomingTopic2 topic -mp.messaging.incoming.incomingTopic2.connector=liberty-kafka -mp.messaging.incoming.incomingTopic2.topic=incomingTopic2 -mp.messaging.incoming.incomingTopic2.group.id=starter \ No newline at end of file diff --git a/incubator/java-openliberty/templates/kafka/src/main/resources/log4j.properties b/incubator/java-openliberty/templates/kafka/src/main/resources/log4j.properties deleted file mode 100644 index 393e0877e..000000000 --- a/incubator/java-openliberty/templates/kafka/src/main/resources/log4j.properties +++ /dev/null @@ -1,8 +0,0 @@ -# Root logger option -log4j.rootLogger=INFO, stdout - -# Direct log messages to stdout -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.Target=System.out -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n \ No newline at end of file diff --git a/incubator/java-openliberty/templates/kafka/src/test/java/dev/appsody/starter/StarterApplicationTest.java b/incubator/java-openliberty/templates/kafka/src/test/java/dev/appsody/starter/StarterApplicationTest.java deleted file mode 100644 index e3c8dc68f..000000000 --- a/incubator/java-openliberty/templates/kafka/src/test/java/dev/appsody/starter/StarterApplicationTest.java +++ /dev/null @@ -1,29 +0,0 @@ -package dev.appsody.starter; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import org.junit.jupiter.api.Test; - -public class StarterApplicationTest { - - - @Test - public void testProcessMessage() { - StarterApplication app = new StarterApplication(); - - String result = app.processMessage("World"); - - assertEquals("Hello World", result); - } - - @Test - public void testReceiveMessage() { - StarterApplication app = new StarterApplication(); - - app.receiveMessage("Banana"); - - assertEquals("Banana", app.getReceivedMessage()); - - } - -} \ No newline at end of file diff --git a/incubator/java-openliberty/templates/kafka/src/test/java/it/dev/appsody/starter/HealthEndpointTest.java b/incubator/java-openliberty/templates/kafka/src/test/java/it/dev/appsody/starter/HealthEndpointTest.java deleted file mode 100644 index ff0e17d2e..000000000 --- a/incubator/java-openliberty/templates/kafka/src/test/java/it/dev/appsody/starter/HealthEndpointTest.java +++ /dev/null @@ -1,99 +0,0 @@ -package it.dev.appsody.starter; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import javax.json.JsonObject; -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.core.Response; - -import org.apache.cxf.jaxrs.provider.jsrjsonp.JsrJsonpProvider; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; - -public class HealthEndpointTest { - - private static String baseUrl; - private static final String LIVENESS_ENDPOINT = "/health/live"; - private static final String READINESS_ENDPOINT = "/health/ready"; - private Client client; - private Response response; - - @BeforeAll - public static void oneTimeSetup() { - // Get test port property defined in pom.xml - String port = System.getProperty("liberty.test.port"); - baseUrl = "http://localhost:" + port; - } - - @BeforeEach - public void setup() { - response = null; - client = ClientBuilder.newClient(); - client.register(JsrJsonpProvider.class); - } - - @AfterEach - public void teardown() { - response.close(); - client.close(); - } - - @Test - public void testLivenessEndpoint() { - checkHealthEndpoint(LIVENESS_ENDPOINT, "alive"); - - } - - @Test - public void testReadinessEndpoint() { - checkHealthEndpoint(READINESS_ENDPOINT, "ready"); - - } - - private void checkHealthEndpoint(String endpoint, String state) { - String healthURL = baseUrl + endpoint; - response = this.getResponse(healthURL); - this.assertResponse(healthURL, response); - - JsonObject healthJson = response.readEntity(JsonObject.class); - - String expectedOutcome = "UP"; - String actualOutcome = healthJson.getString("status"); - assertEquals(expectedOutcome, actualOutcome, "Application should be " + state); - - actualOutcome = healthJson.getJsonArray("checks").getJsonObject(0).getString("status"); - assertEquals(expectedOutcome, actualOutcome, "First array element was expected to be SystemResource and it wasn't healthy"); - - } - - /** - *

- * Returns response information from the specified URL. - *

- * - * @param url - * - target URL. - * @return Response object with the response from the specified URL. - */ - private Response getResponse(String url) { - return client.target(url).request().get(); - } - - /** - *

- * Asserts that the given URL has the correct response code of 200. - *

- * - * @param url - * - target URL. - * @param response - * - response received from the target URL. - */ - private void assertResponse(String url, Response response) { - assertEquals(200, response.getStatus(), "Incorrect response code from " + url); - } - -}