diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 00000000..a26100e1 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,12 @@ +version: 2 +updates: +- package-ecosystem: maven + directory: "/finish" + schedule: + interval: monthly + open-pull-requests-limit: 50 +- package-ecosystem: maven + directory: "/start" + schedule: + interval: monthly + open-pull-requests-limit: 50 diff --git a/README.adoc b/README.adoc index 7a477e22..6918dd5f 100644 --- a/README.adoc +++ b/README.adoc @@ -1,4 +1,4 @@ -// Copyright (c) 2019, 2023 IBM Corporation and others. +// Copyright (c) 2019, 2024 IBM Corporation and others. // Licensed under Creative Commons Attribution-NoDerivatives // 4.0 International (CC BY-ND 4.0) // https://creativecommons.org/licenses/by-nd/4.0/ @@ -9,13 +9,14 @@ :page-layout: guide-multipane :page-duration: 15 minutes :page-releasedate: 2019-09-13 +:page-majorupdateddate: 2024-04-04 :page-guide-category: microprofile :page-essential: false :page-description: Learn how to use MicroProfile Rest Client to invoke RESTful microservices asynchronously over HTTP. :page-seo-title: Consuming RESTful Java microservices asynchronously using Eclipse MicroProfile Rest Client :page-seo-description: A getting started tutorial and an example on how to consume RESTful Java microservices with asynchronous method calls using the CompletionStage interface and MicroProfile Rest Client. :guide-author: Open Liberty -:page-tags: ['MicroProfile'] +:page-tags: ['microprofile'] :page-permalink: /guides/{projectid} :page-related-guides: ['microprofile-reactive-messaging', 'reactive-rest-client'] :common-includes: https://raw.githubusercontent.com/OpenLiberty/guides-common/prod @@ -149,7 +150,7 @@ docker build -t inventory:1.0-SNAPSHOT inventory/. docker build -t query:1.0-SNAPSHOT query/. ``` -Next, use the provided `startContainers` script to start the application in Docker containers. The script creates containers for Kafka, Zookeeper, and all of the microservices in the project, in addition to a network for the containers to communicate with each other. The script also creates three instances of the `system` microservice. +Next, use the provided `startContainers` script to start the application in Docker containers. The script creates containers for Kafka and all of the microservices in the project, in addition to a network for the containers to communicate with each other. The script also creates three instances of the `system` microservice. include::{common-includes}/os-tabs.adoc[] @@ -171,12 +172,19 @@ include::{common-includes}/os-tabs.adoc[] // static guide instructions: ifndef::cloud-hosted[] -The services take some time to become available. You can access the application by making requests to the `query/systemLoad` endpoint by going to the http://localhost:9080/query/systemLoad[http://localhost:9080/query/systemLoad^] URL. +The services take some time to become available. Visit the http://localhost:9085/health[^] URL to confirm that the `inventory` microservice is up and running. + +You can access the application by making requests to the `query/systemLoad` endpoint by going to the http://localhost:9080/query/systemLoad[http://localhost:9080/query/systemLoad^] URL. endif::[] // cloud-hosted guide instructions: ifdef::cloud-hosted[] -The services might take several minutes to become available. You can access the application by making requests to the ***query/systemLoad*** endpoint by running the following curl command: +The services might take several minutes to become available. Run the following curl command to confirm that the ***inventory*** microservice is up and running. +```bash +curl -s http://localhost:9085/health | jq +``` + +You can access the application by making requests to the ***query/systemLoad*** endpoint by running the following curl command: ```bash curl -s http://localhost:9080/query/systemLoad | jq ``` @@ -252,10 +260,26 @@ include::finish/query/src/test/java/it/io/openliberty/guides/query/QueryServiceI ifndef::cloud-hosted[] Navigate to the `query` directory, then verify that the tests pass by using the Maven `verify` goal: +include::{common-includes}/os-tabs.adoc[] + +[.tab_content.windows_section] +-- [role='command'] -```bash +``` mvn verify ``` +-- + +[.tab_content.mac_section.linux_section] +-- +[role='command'] +``` +export TESTCONTAINERS_RYUK_DISABLED=true +mvn verify +``` + +For more information about disabling Ryuk, see the https://java.testcontainers.org/features/configuration/#disabling-ryuk[Testcontainers custom configuration^] document. +-- When the tests succeed, you see output similar to the following example: endif::[] @@ -264,10 +288,13 @@ endif::[] ifdef::cloud-hosted[] Run the following commands to navigate to the ***query*** directory and verify that the tests pass by using the Maven ***verify*** goal: ```bash +export TESTCONTAINERS_RYUK_DISABLED=true cd /home/project/guide-microprofile-rest-client-async/start/query mvn verify ``` +For more information about disabling Ryuk, see the [Testcontainers custom configuratio](https://java.testcontainers.org/features/configuration/#disabling-ryuk) document. + The tests might take a few minutes to complete. When the tests succeed, you see output similar to the following example: endif::[] diff --git a/finish/inventory/pom.xml b/finish/inventory/pom.xml index 5f54c613..f731a2f9 100644 --- a/finish/inventory/pom.xml +++ b/finish/inventory/pom.xml @@ -8,13 +8,13 @@ war - 1.8 - 1.8 + 11 + 11 UTF-8 UTF-8 - 9085 - 9448 + 9085 + 9448 @@ -22,19 +22,19 @@ jakarta.platform jakarta.jakartaee-api - 8.0.0 + 10.0.0 provided - javax.enterprise.concurrent - javax.enterprise.concurrent-api - 1.1 + jakarta.enterprise.concurrent + jakarta.enterprise.concurrent-api + 3.0.3 provided org.eclipse.microprofile microprofile - 3.3 + 6.1 pom provided @@ -42,7 +42,7 @@ org.eclipse.microprofile.reactive.messaging microprofile-reactive-messaging-api - 1.0 + 3.0 provided @@ -57,33 +57,55 @@ org.apache.kafka kafka-clients - 2.8.1 + 3.7.0 io.reactivex.rxjava3 rxjava - 3.1.2 + 3.1.8 - - org.microshed - microshed-testing-liberty - 0.9.1 - test + org.slf4j + slf4j-api + 2.0.12 + + org.slf4j + slf4j-simple + 2.0.12 + + org.testcontainers kafka - 1.16.2 + 1.19.7 test org.junit.jupiter junit-jupiter - 5.7.0 + 5.10.2 + test + + + org.testcontainers + junit-jupiter + 1.19.7 + test + + + org.jboss.resteasy + resteasy-client + 6.2.8.Final + test + + + org.jboss.resteasy + resteasy-json-binding-provider + 6.2.8.Final test @@ -94,7 +116,7 @@ org.apache.maven.plugins maven-war-plugin - 3.3.0 + 3.4.0 pom.xml @@ -104,21 +126,29 @@ io.openliberty.tools liberty-maven-plugin - 3.8.2 + 3.10.2 + + + + -e WLP_LOGGING_CONSOLE_LOGLEVEL=info + -p 9085:9085 + --network=reactive-app + + org.apache.maven.plugins maven-surefire-plugin - 2.22.2 + 3.2.5 org.apache.maven.plugins maven-failsafe-plugin - 2.22.2 + 3.2.5 diff --git a/finish/inventory/src/main/java/io/openliberty/guides/inventory/InventoryApplication.java b/finish/inventory/src/main/java/io/openliberty/guides/inventory/InventoryApplication.java index 6c276865..bd4c8dbc 100644 --- a/finish/inventory/src/main/java/io/openliberty/guides/inventory/InventoryApplication.java +++ b/finish/inventory/src/main/java/io/openliberty/guides/inventory/InventoryApplication.java @@ -1,21 +1,20 @@ // tag::copyright[] /******************************************************************************* - * Copyright (c) 2020 IBM Corporation and others. + * Copyright (c) 2020, 2024 IBM Corporation and others. * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 + * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html + * http://www.eclipse.org/legal/epl-2.0/ * - * Contributors: - * IBM Corporation - Initial implementation + * SPDX-License-Identifier: EPL-2.0 *******************************************************************************/ // end::copyright[] package io.openliberty.guides.inventory; -import javax.ws.rs.core.Application; -import javax.ws.rs.ApplicationPath; +import jakarta.ws.rs.core.Application; +import jakarta.ws.rs.ApplicationPath; @ApplicationPath("/") public class InventoryApplication extends Application { -} \ No newline at end of file +} diff --git a/finish/inventory/src/main/java/io/openliberty/guides/inventory/InventoryManager.java b/finish/inventory/src/main/java/io/openliberty/guides/inventory/InventoryManager.java index 4b0e813a..79fcc92e 100644 --- a/finish/inventory/src/main/java/io/openliberty/guides/inventory/InventoryManager.java +++ b/finish/inventory/src/main/java/io/openliberty/guides/inventory/InventoryManager.java @@ -1,13 +1,12 @@ // tag::copyright[] /******************************************************************************* - * Copyright (c) 2020 IBM Corporation and others. + * Copyright (c) 2020, 2024 IBM Corporation and others. * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 + * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html + * http://www.eclipse.org/legal/epl-2.0/ * - * Contributors: - * IBM Corporation - Initial implementation + * SPDX-License-Identifier: EPL-2.0 *******************************************************************************/ // end::copyright[] package io.openliberty.guides.inventory; @@ -20,12 +19,13 @@ import java.util.Properties; import java.util.TreeMap; -import javax.enterprise.context.ApplicationScoped; +import jakarta.enterprise.context.ApplicationScoped; @ApplicationScoped public class InventoryManager { - - private Map systems = Collections.synchronizedMap(new TreeMap()); + + private Map systems = Collections.synchronizedMap( + new TreeMap()); public void addSystem(String hostname, Double systemLoad) { if (!systems.containsKey(hostname)) { @@ -39,8 +39,9 @@ public void addSystem(String hostname, Double systemLoad) { public void updateCpuStatus(String hostname, Double systemLoad) { Optional p = getSystem(hostname); if (p.isPresent()) { - if (p.get().getProperty(hostname) == null && hostname != null) + if (p.get().getProperty(hostname) == null && hostname != null) { p.get().put("systemLoad", systemLoad); + } } } @@ -56,4 +57,4 @@ public List getSystems() { public void resetSystems() { systems.clear(); } -} \ No newline at end of file +} diff --git a/finish/inventory/src/main/java/io/openliberty/guides/inventory/InventoryResource.java b/finish/inventory/src/main/java/io/openliberty/guides/inventory/InventoryResource.java index 0435e617..bd830f45 100644 --- a/finish/inventory/src/main/java/io/openliberty/guides/inventory/InventoryResource.java +++ b/finish/inventory/src/main/java/io/openliberty/guides/inventory/InventoryResource.java @@ -1,13 +1,12 @@ // tag::copyright[] /******************************************************************************* - * Copyright (c) 2020 IBM Corporation and others. + * Copyright (c) 2020, 2024 IBM Corporation and others. * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 + * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html + * http://www.eclipse.org/legal/epl-2.0/ * - * Contributors: - * IBM Corporation - Initial implementation + * SPDX-License-Identifier: EPL-2.0 *******************************************************************************/ // end::copyright[] package io.openliberty.guides.inventory; @@ -17,15 +16,15 @@ import java.util.Properties; import java.util.logging.Logger; -import javax.enterprise.context.ApplicationScoped; -import javax.inject.Inject; -import javax.ws.rs.DELETE; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.inject.Inject; +import jakarta.ws.rs.DELETE; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.PathParam; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.Response; import org.eclipse.microprofile.reactive.messaging.Incoming; @@ -42,7 +41,7 @@ public class InventoryResource { @Inject private InventoryManager manager; - + @GET @Path("/systems") @Produces(MediaType.APPLICATION_JSON) @@ -65,9 +64,8 @@ public Properties getSystem(@PathParam("hostname") String hostname) { @Produces(MediaType.APPLICATION_JSON) public Response resetSystems() { manager.resetSystems(); - return Response - .status(Response.Status.OK) - .build(); + return Response.status(Response.Status.OK) + .build(); } @Incoming("systemLoad") diff --git a/finish/inventory/src/main/java/io/openliberty/guides/inventory/health/InventoryLivenessCheck.java b/finish/inventory/src/main/java/io/openliberty/guides/inventory/health/InventoryLivenessCheck.java index 3529f119..9ec01516 100644 --- a/finish/inventory/src/main/java/io/openliberty/guides/inventory/health/InventoryLivenessCheck.java +++ b/finish/inventory/src/main/java/io/openliberty/guides/inventory/health/InventoryLivenessCheck.java @@ -1,18 +1,17 @@ // tag::copyright[] /******************************************************************************* - * Copyright (c) 2020 IBM Corporation and others. + * Copyright (c) 2020, 2024 IBM Corporation and others. * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 + * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html + * http://www.eclipse.org/legal/epl-2.0/ * - * Contributors: - * IBM Corporation - Initial implementation + * SPDX-License-Identifier: EPL-2.0 *******************************************************************************/ // end::copyright[] package io.openliberty.guides.inventory.health; -import javax.enterprise.context.ApplicationScoped; +import jakarta.enterprise.context.ApplicationScoped; import org.eclipse.microprofile.health.HealthCheck; import org.eclipse.microprofile.health.HealthCheckResponse; @@ -29,6 +28,7 @@ private boolean isAlive() { @Override public HealthCheckResponse call() { boolean up = isAlive(); - return HealthCheckResponse.named(this.getClass().getSimpleName()).state(up).build(); + return HealthCheckResponse.named( + this.getClass().getSimpleName()).status(up).build(); } } diff --git a/finish/inventory/src/main/java/io/openliberty/guides/inventory/health/InventoryReadinessCheck.java b/finish/inventory/src/main/java/io/openliberty/guides/inventory/health/InventoryReadinessCheck.java index 45504d81..2ec48223 100644 --- a/finish/inventory/src/main/java/io/openliberty/guides/inventory/health/InventoryReadinessCheck.java +++ b/finish/inventory/src/main/java/io/openliberty/guides/inventory/health/InventoryReadinessCheck.java @@ -1,13 +1,12 @@ // tag::copyright[] /******************************************************************************* - * Copyright (c) 2020 IBM Corporation and others. + * Copyright (c) 2020, 2024 IBM Corporation and others. * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 + * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html + * http://www.eclipse.org/legal/epl-2.0/ * - * Contributors: - * IBM Corporation - Initial implementation + * SPDX-License-Identifier: EPL-2.0 *******************************************************************************/ // end::copyright[] package io.openliberty.guides.inventory.health; @@ -16,8 +15,8 @@ import java.util.Properties; import java.util.logging.Logger; -import javax.enterprise.context.ApplicationScoped; -import javax.inject.Inject; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.inject.Inject; import org.apache.kafka.clients.admin.AdminClient; import org.apache.kafka.clients.admin.ConsumerGroupListing; @@ -32,42 +31,48 @@ @ApplicationScoped public class InventoryReadinessCheck implements HealthCheck { - private static Logger logger = Logger.getLogger(InventoryReadinessCheck.class.getName()); - + private static Logger logger = Logger.getLogger( + InventoryReadinessCheck.class.getName()); + @Inject @ConfigProperty(name = "mp.messaging.connector.liberty-kafka.bootstrap.servers") String kafkaServer; - + @Inject @ConfigProperty(name = "mp.messaging.incoming.systemLoad.group.id") String groupId; - + @Override public HealthCheckResponse call() { boolean up = isReady(); - return HealthCheckResponse.named(this.getClass().getSimpleName()).state(up).build(); + return HealthCheckResponse.named( + this.getClass().getSimpleName()).status(up).build(); } private boolean isReady() { AdminClient adminClient = createAdminClient(); return checkIfBarConsumerGroupRegistered(adminClient); } - + private AdminClient createAdminClient() { Properties connectionProperties = new Properties(); connectionProperties.put("bootstrap.servers", kafkaServer); AdminClient adminClient = AdminClient.create(connectionProperties); return adminClient; } - + private boolean checkIfBarConsumerGroupRegistered(AdminClient adminClient) { ListConsumerGroupsResult groupsResult = adminClient.listConsumerGroups(); - KafkaFuture> consumerGroupsFuture = groupsResult.valid(); + KafkaFuture> consumerGroupsFuture = + groupsResult.valid(); try { - Collection consumerGroups = consumerGroupsFuture.get(); - for (ConsumerGroupListing g : consumerGroups) + Collection consumerGroups = + consumerGroupsFuture.get(); + for (ConsumerGroupListing g : consumerGroups) { logger.info("groupId: " + g.groupId()); - return consumerGroups.stream().anyMatch(group -> group.groupId().equals(groupId)); + } + return consumerGroups.stream().anyMatch( + group -> group.groupId().equals(groupId)); } catch (Exception e) { return false; } diff --git a/finish/inventory/src/main/liberty/config/server.xml b/finish/inventory/src/main/liberty/config/server.xml index f15d5e27..0220fe88 100755 --- a/finish/inventory/src/main/liberty/config/server.xml +++ b/finish/inventory/src/main/liberty/config/server.xml @@ -1,20 +1,20 @@ - jaxrs-2.1 - cdi-2.0 - concurrent-1.0 - jsonb-1.0 - mpHealth-2.2 - mpConfig-1.4 - mpReactiveMessaging-1.0 + restfulWS-3.1 + cdi-4.0 + concurrent-3.0 + jsonb-3.0 + mpHealth-4.0 + mpConfig-3.1 + mpReactiveMessaging-3.0 - - + + - + diff --git a/finish/inventory/src/main/resources/META-INF/microprofile-config.properties b/finish/inventory/src/main/resources/META-INF/microprofile-config.properties index 2c782324..36521302 100644 --- a/finish/inventory/src/main/resources/META-INF/microprofile-config.properties +++ b/finish/inventory/src/main/resources/META-INF/microprofile-config.properties @@ -1,6 +1,6 @@ # Kafka connection details # tag::kafkaConfig[] -mp.messaging.connector.liberty-kafka.bootstrap.servers=localhost:9093 +mp.messaging.connector.liberty-kafka.bootstrap.servers=kafka:9092 # end::kafkaConfig[] # systemLoad stream diff --git a/finish/inventory/src/main/webapp/index.html b/finish/inventory/src/main/webapp/index.html index 94d15c3d..816c9298 100755 --- a/finish/inventory/src/main/webapp/index.html +++ b/finish/inventory/src/main/webapp/index.html @@ -1,5 +1,5 @@ - 9080 - 9443 + 9080 + 9443 @@ -24,25 +24,25 @@ jakarta.platform jakarta.jakartaee-api - 8.0.0 + 10.0.0 provided - javax.enterprise.concurrent - javax.enterprise.concurrent-api - 1.1 + jakarta.enterprise.concurrent + jakarta.enterprise.concurrent-api + 3.0.3 provided - javax.validation - validation-api - 2.0.1.Final + jakarta.validation + jakarta.validation-api + 3.1.0-M1 provided org.eclipse.microprofile microprofile - 3.3 + 6.1 pom provided @@ -50,7 +50,7 @@ org.eclipse.microprofile.reactive.messaging microprofile-reactive-messaging-api - 1.0 + 3.0 provided @@ -64,45 +64,67 @@ org.apache.kafka kafka-clients - 2.8.1 + 3.7.0 io.reactivex.rxjava3 rxjava - 3.1.2 + 3.1.8 - - org.microshed - microshed-testing-liberty - 0.9.1 - test + org.slf4j + slf4j-api + 2.0.12 + + + org.slf4j + slf4j-simple + 2.0.12 + org.testcontainers kafka - 1.16.2 + 1.19.7 test org.testcontainers mockserver - 1.16.2 + 1.19.7 test org.mock-server mockserver-client-java - 5.11.2 + 5.15.0 test org.junit.jupiter junit-jupiter - 5.7.0 + 5.10.2 + test + + + org.testcontainers + junit-jupiter + 1.19.7 + test + + + org.jboss.resteasy + resteasy-client + 6.2.8.Final + test + + + org.jboss.resteasy + resteasy-json-binding-provider + 6.2.8.Final test @@ -113,7 +135,7 @@ org.apache.maven.plugins maven-war-plugin - 3.3.0 + 3.4.0 pom.xml @@ -123,21 +145,21 @@ io.openliberty.tools liberty-maven-plugin - 3.8.2 + 3.10.2 org.apache.maven.plugins maven-surefire-plugin - 2.22.2 + 3.2.5 org.apache.maven.plugins maven-failsafe-plugin - 2.22.2 + 3.2.5 integration-test diff --git a/finish/query/src/main/java/io/openliberty/guides/query/QueryApplication.java b/finish/query/src/main/java/io/openliberty/guides/query/QueryApplication.java index 41db190d..a6a1d2f0 100644 --- a/finish/query/src/main/java/io/openliberty/guides/query/QueryApplication.java +++ b/finish/query/src/main/java/io/openliberty/guides/query/QueryApplication.java @@ -1,24 +1,23 @@ // tag::copyright[] /******************************************************************************* - * Copyright (c) 2020 IBM Corporation and others. + * Copyright (c) 2020, 2024 IBM Corporation and others. * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 + * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html + * http://www.eclipse.org/legal/epl-2.0/ * - * Contributors: - * IBM Corporation - Initial implementation + * SPDX-License-Identifier: EPL-2.0 *******************************************************************************/ // end::copyright[] package io.openliberty.guides.query; // JAX-RS -import javax.ws.rs.ApplicationPath; -import javax.ws.rs.core.Application; +import jakarta.ws.rs.ApplicationPath; +import jakarta.ws.rs.core.Application; // tag::path1[] @ApplicationPath("/") // end::path1[] public class QueryApplication extends Application { -} \ No newline at end of file +} diff --git a/finish/query/src/main/java/io/openliberty/guides/query/QueryResource.java b/finish/query/src/main/java/io/openliberty/guides/query/QueryResource.java index 1c22f7b3..b9192320 100644 --- a/finish/query/src/main/java/io/openliberty/guides/query/QueryResource.java +++ b/finish/query/src/main/java/io/openliberty/guides/query/QueryResource.java @@ -1,13 +1,12 @@ // tag::copyright[] /******************************************************************************* - * Copyright (c) 2020 IBM Corporation and others. + * Copyright (c) 2020, 2024 IBM Corporation and others. * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 + * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html + * http://www.eclipse.org/legal/epl-2.0/ * - * Contributors: - * IBM Corporation - Initial implementation + * SPDX-License-Identifier: EPL-2.0 *******************************************************************************/ // end::copyright[] package io.openliberty.guides.query; @@ -20,12 +19,12 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; -import javax.enterprise.context.ApplicationScoped; -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 jakarta.enterprise.context.ApplicationScoped; +import jakarta.inject.Inject; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; import org.eclipse.microprofile.rest.client.inject.RestClient; @@ -34,7 +33,7 @@ @ApplicationScoped @Path("/query") public class QueryResource { - + @Inject @RestClient private InventoryClient inventoryClient; @@ -96,7 +95,7 @@ private class Holder { private volatile Map values; // end::volatile[] - public Holder() { + Holder() { // tag::concurrentHashMap[] this.values = new ConcurrentHashMap(); // end::concurrentHashMap[] @@ -126,8 +125,10 @@ private void init() { this.values.put("lowest", new Properties()); this.values.get("highest").put("hostname", "temp_max"); this.values.get("lowest").put("hostname", "temp_min"); - this.values.get("highest").put("systemLoad", new BigDecimal(Double.MIN_VALUE)); - this.values.get("lowest").put("systemLoad", new BigDecimal(Double.MAX_VALUE)); + this.values.get("highest").put( + "systemLoad", new BigDecimal(Double.MIN_VALUE)); + this.values.get("lowest").put( + "systemLoad", new BigDecimal(Double.MAX_VALUE)); } } // end::holder[] diff --git a/finish/query/src/main/java/io/openliberty/guides/query/client/InventoryClient.java b/finish/query/src/main/java/io/openliberty/guides/query/client/InventoryClient.java index aa6e2cf5..f463404f 100644 --- a/finish/query/src/main/java/io/openliberty/guides/query/client/InventoryClient.java +++ b/finish/query/src/main/java/io/openliberty/guides/query/client/InventoryClient.java @@ -1,13 +1,12 @@ // tag::copyright[] /******************************************************************************* - * Copyright (c) 2020 IBM Corporation and others. + * Copyright (c) 2020, 2024 IBM Corporation and others. * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 + * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html + * http://www.eclipse.org/legal/epl-2.0/ * - * Contributors: - * IBM Corporation - Initial implementation + * SPDX-License-Identifier: EPL-2.0 *******************************************************************************/ // end::copyright[] package io.openliberty.guides.query.client; @@ -16,11 +15,11 @@ import java.util.Properties; import java.util.concurrent.CompletionStage; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.PathParam; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; @@ -31,13 +30,14 @@ public interface InventoryClient extends AutoCloseable { @GET @Path("/systems") @Produces(MediaType.APPLICATION_JSON) - public List getSystems(); + List getSystems(); // tag::getSystem[] @GET @Path("/systems/{hostname}") @Produces(MediaType.APPLICATION_JSON) - public CompletionStage getSystem(@PathParam("hostname") String hostname); + CompletionStage getSystem( + @PathParam("hostname") String hostname); // end::getSystem[] } diff --git a/finish/query/src/main/java/io/openliberty/guides/query/health/QueryLivenessCheck.java b/finish/query/src/main/java/io/openliberty/guides/query/health/QueryLivenessCheck.java index f84674dd..69b94c2e 100644 --- a/finish/query/src/main/java/io/openliberty/guides/query/health/QueryLivenessCheck.java +++ b/finish/query/src/main/java/io/openliberty/guides/query/health/QueryLivenessCheck.java @@ -1,18 +1,17 @@ // tag::copyright[] /******************************************************************************* - * Copyright (c) 2020 IBM Corporation and others. + * Copyright (c) 2020, 2024 IBM Corporation and others. * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 + * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html + * http://www.eclipse.org/legal/epl-2.0/ * - * Contributors: - * IBM Corporation - Initial implementation + * SPDX-License-Identifier: EPL-2.0 *******************************************************************************/ // end::copyright[] package io.openliberty.guides.query.health; -import javax.enterprise.context.ApplicationScoped; +import jakarta.enterprise.context.ApplicationScoped; import org.eclipse.microprofile.health.HealthCheck; import org.eclipse.microprofile.health.HealthCheckResponse; @@ -29,6 +28,7 @@ private boolean isAlive() { @Override public HealthCheckResponse call() { boolean up = isAlive(); - return HealthCheckResponse.named(this.getClass().getSimpleName()).state(up).build(); + return HealthCheckResponse.named( + this.getClass().getSimpleName()).status(up).build(); } } diff --git a/finish/query/src/main/java/io/openliberty/guides/query/health/QueryReadinessCheck.java b/finish/query/src/main/java/io/openliberty/guides/query/health/QueryReadinessCheck.java index 58db0521..867f4a5a 100644 --- a/finish/query/src/main/java/io/openliberty/guides/query/health/QueryReadinessCheck.java +++ b/finish/query/src/main/java/io/openliberty/guides/query/health/QueryReadinessCheck.java @@ -1,18 +1,17 @@ // tag::copyright[] /******************************************************************************* - * Copyright (c) 2020 IBM Corporation and others. + * Copyright (c) 2020, 2024 IBM Corporation and others. * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 + * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html + * http://www.eclipse.org/legal/epl-2.0/ * - * Contributors: - * IBM Corporation - Initial implementation + * SPDX-License-Identifier: EPL-2.0 *******************************************************************************/ // end::copyright[] package io.openliberty.guides.query.health; -import javax.enterprise.context.ApplicationScoped; +import jakarta.enterprise.context.ApplicationScoped; import org.eclipse.microprofile.health.HealthCheck; import org.eclipse.microprofile.health.HealthCheckResponse; @@ -29,6 +28,7 @@ private boolean isAlive() { @Override public HealthCheckResponse call() { boolean up = isAlive(); - return HealthCheckResponse.named(this.getClass().getSimpleName()).state(up).build(); + return HealthCheckResponse.named( + this.getClass().getSimpleName()).status(up).build(); } } diff --git a/finish/query/src/main/liberty/config/server.xml b/finish/query/src/main/liberty/config/server.xml index 516e03bd..f640ccf3 100755 --- a/finish/query/src/main/liberty/config/server.xml +++ b/finish/query/src/main/liberty/config/server.xml @@ -1,23 +1,23 @@ - beanValidation-2.0 - jaxrs-2.1 - cdi-2.0 - concurrent-1.0 - jsonb-1.0 - mpHealth-2.2 - mpConfig-1.4 - mpOpenAPI-1.1 - mpReactiveMessaging-1.0 - mpRestClient-1.4 + beanValidation-3.0 + restfulWS-3.1 + cdi-4.0 + concurrent-3.0 + jsonb-3.0 + mpHealth-4.0 + mpConfig-3.1 + mpOpenAPI-3.1 + mpReactiveMessaging-3.0 + mpRestClient-3.0 - - + + - + diff --git a/finish/query/src/main/webapp/index.html b/finish/query/src/main/webapp/index.html index 94d15c3d..816c9298 100755 --- a/finish/query/src/main/webapp/index.html +++ b/finish/query/src/main/webapp/index.html @@ -1,5 +1,5 @@ - 9083 - 9446 + 9083 + 9446 @@ -24,13 +24,13 @@ jakarta.platform jakarta.jakartaee-api - 8.0.0 + 10.0.0 provided org.eclipse.microprofile microprofile - 3.3 + 6.1 pom provided @@ -38,7 +38,7 @@ org.eclipse.microprofile.reactive.messaging microprofile-reactive-messaging-api - 1.0 + 3.0 provided @@ -52,33 +52,43 @@ org.apache.kafka kafka-clients - 2.8.1 + 3.7.0 io.reactivex.rxjava3 rxjava - 3.1.2 + 3.1.8 - - org.microshed - microshed-testing-liberty - 0.9.1 - test + org.slf4j + slf4j-api + 2.0.12 + + + org.slf4j + slf4j-simple + 2.0.12 + org.testcontainers kafka - 1.16.2 + 1.19.7 test org.junit.jupiter junit-jupiter - 5.7.0 + 5.10.2 + test + + + org.testcontainers + junit-jupiter + 1.19.7 test @@ -89,7 +99,7 @@ org.apache.maven.plugins maven-war-plugin - 3.3.0 + 3.4.0 pom.xml @@ -99,21 +109,29 @@ io.openliberty.tools liberty-maven-plugin - 3.8.2 + 3.10.2 + + + + -e WLP_LOGGING_CONSOLE_LOGLEVEL=info + -p 9083:9083 + --network=reactive-app + + org.apache.maven.plugins maven-surefire-plugin - 2.22.2 + 3.2.5 org.apache.maven.plugins maven-failsafe-plugin - 2.22.2 + 3.2.5 integration-test diff --git a/finish/system/src/main/java/io/openliberty/guides/system/SystemService.java b/finish/system/src/main/java/io/openliberty/guides/system/SystemService.java index e6ddcb1c..a3816bce 100755 --- a/finish/system/src/main/java/io/openliberty/guides/system/SystemService.java +++ b/finish/system/src/main/java/io/openliberty/guides/system/SystemService.java @@ -1,13 +1,12 @@ // tag::copyright[] /******************************************************************************* - * Copyright (c) 2020 IBM Corporation and others. + * Copyright (c) 2020, 2024 IBM Corporation and others. * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 + * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html + * http://www.eclipse.org/legal/epl-2.0/ * - * Contributors: - * IBM Corporation - Initial implementation + * SPDX-License-Identifier: EPL-2.0 *******************************************************************************/ // end::copyright[] package io.openliberty.guides.system; @@ -18,7 +17,7 @@ import java.net.UnknownHostException; import java.util.concurrent.TimeUnit; -import javax.enterprise.context.ApplicationScoped; +import jakarta.enterprise.context.ApplicationScoped; import org.eclipse.microprofile.reactive.messaging.Outgoing; import org.reactivestreams.Publisher; @@ -29,7 +28,7 @@ @ApplicationScoped public class SystemService { - private static final OperatingSystemMXBean osMean = + private static final OperatingSystemMXBean OS_MEAN = ManagementFactory.getOperatingSystemMXBean(); private static String hostname = null; @@ -47,8 +46,8 @@ private static String getHostname() { @Outgoing("systemLoad") public Publisher sendSystemLoad() { return Flowable.interval(15, TimeUnit.SECONDS) - .map((interval -> new SystemLoad(getHostname(), - osMean.getSystemLoadAverage()))); + .map((interval -> new SystemLoad(getHostname(), + OS_MEAN.getSystemLoadAverage()))); } -} \ No newline at end of file +} diff --git a/finish/system/src/main/java/io/openliberty/guides/system/health/SystemLivenessCheck.java b/finish/system/src/main/java/io/openliberty/guides/system/health/SystemLivenessCheck.java index fecdc862..60020811 100644 --- a/finish/system/src/main/java/io/openliberty/guides/system/health/SystemLivenessCheck.java +++ b/finish/system/src/main/java/io/openliberty/guides/system/health/SystemLivenessCheck.java @@ -1,18 +1,17 @@ // tag::copyright[] /******************************************************************************* - * Copyright (c) 2020 IBM Corporation and others. + * Copyright (c) 2020, 2024 IBM Corporation and others. * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 + * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html + * http://www.eclipse.org/legal/epl-2.0/ * - * Contributors: - * IBM Corporation - Initial implementation + * SPDX-License-Identifier: EPL-2.0 *******************************************************************************/ // end::copyright[] package io.openliberty.guides.system.health; -import javax.enterprise.context.ApplicationScoped; +import jakarta.enterprise.context.ApplicationScoped; import org.eclipse.microprofile.health.HealthCheck; import org.eclipse.microprofile.health.HealthCheckResponse; @@ -29,6 +28,7 @@ private boolean isAlive() { @Override public HealthCheckResponse call() { boolean up = isAlive(); - return HealthCheckResponse.named(this.getClass().getSimpleName()).state(up).build(); + return HealthCheckResponse.named( + this.getClass().getSimpleName()).status(up).build(); } } diff --git a/finish/system/src/main/java/io/openliberty/guides/system/health/SystemReadinessCheck.java b/finish/system/src/main/java/io/openliberty/guides/system/health/SystemReadinessCheck.java index cfc91446..9a548edb 100644 --- a/finish/system/src/main/java/io/openliberty/guides/system/health/SystemReadinessCheck.java +++ b/finish/system/src/main/java/io/openliberty/guides/system/health/SystemReadinessCheck.java @@ -1,13 +1,12 @@ // tag::copyright[] /******************************************************************************* - * Copyright (c) 2020 IBM Corporation and others. + * Copyright (c) 2020, 2024 IBM Corporation and others. * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 + * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html + * http://www.eclipse.org/legal/epl-2.0/ * - * Contributors: - * IBM Corporation - Initial implementation + * SPDX-License-Identifier: EPL-2.0 *******************************************************************************/ // end::copyright[] package io.openliberty.guides.system.health; @@ -16,8 +15,8 @@ import java.util.Properties; import java.util.logging.Logger; -import javax.enterprise.context.ApplicationScoped; -import javax.inject.Inject; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.inject.Inject; import org.apache.kafka.clients.admin.AdminClient; import org.apache.kafka.clients.admin.ListTopicsResult; @@ -32,37 +31,40 @@ @ApplicationScoped public class SystemReadinessCheck implements HealthCheck { - private static Logger logger = Logger.getLogger(SystemReadinessCheck.class.getName()); - + private static Logger logger = Logger.getLogger( + SystemReadinessCheck.class.getName()); + @Inject @ConfigProperty(name = "mp.messaging.connector.liberty-kafka.bootstrap.servers") String kafkaServer; - + @Override public HealthCheckResponse call() { boolean up = isReady(); - return HealthCheckResponse.named(this.getClass().getSimpleName()).state(up).build(); + return HealthCheckResponse.named( + this.getClass().getSimpleName()).status(up).build(); } private boolean isReady() { AdminClient adminClient = createAdminClient(); return checkIfBarConsumerGroupRegistered(adminClient); } - + private AdminClient createAdminClient() { Properties connectionProperties = new Properties(); connectionProperties.put("bootstrap.servers", kafkaServer); AdminClient adminClient = AdminClient.create(connectionProperties); return adminClient; } - + private boolean checkIfBarConsumerGroupRegistered(AdminClient adminClient) { ListTopicsResult topics = adminClient.listTopics(); KafkaFuture> topicsFuture = topics.listings(); try { Collection topicList = topicsFuture.get(); - for (TopicListing t : topicList) + for (TopicListing t : topicList) { logger.info("topic: " + t.name()); + } return true; } catch (Exception e) { return false; diff --git a/finish/system/src/main/liberty/config/server.xml b/finish/system/src/main/liberty/config/server.xml index bdf1f576..10646865 100755 --- a/finish/system/src/main/liberty/config/server.xml +++ b/finish/system/src/main/liberty/config/server.xml @@ -1,21 +1,21 @@ - cdi-2.0 - concurrent-1.0 - jsonb-1.0 - mpHealth-2.2 - mpConfig-1.4 + cdi-4.0 + concurrent-3.0 + jsonb-3.0 + mpHealth-4.0 + mpConfig-3.1 - mpReactiveMessaging-1.0 + mpReactiveMessaging-3.0 - - + + - + diff --git a/finish/system/src/main/resources/META-INF/microprofile-config.properties b/finish/system/src/main/resources/META-INF/microprofile-config.properties index bd86d976..cf3debdf 100644 --- a/finish/system/src/main/resources/META-INF/microprofile-config.properties +++ b/finish/system/src/main/resources/META-INF/microprofile-config.properties @@ -1,6 +1,6 @@ # Kafka connection details # tag::kafkaConfig[] -mp.messaging.connector.liberty-kafka.bootstrap.servers=localhost:9093 +mp.messaging.connector.liberty-kafka.bootstrap.servers=kafka:9092 # end::kafkaConfig[] # systemLoad stream diff --git a/finish/system/src/main/webapp/index.html b/finish/system/src/main/webapp/index.html index 468e1895..a7c70e79 100755 --- a/finish/system/src/main/webapp/index.html +++ b/finish/system/src/main/webapp/index.html @@ -1,5 +1,5 @@ - 9085 - 9448 + 9085 + 9448 @@ -22,19 +22,19 @@ jakarta.platform jakarta.jakartaee-api - 8.0.0 + 10.0.0 provided - javax.enterprise.concurrent - javax.enterprise.concurrent-api - 1.1 + jakarta.enterprise.concurrent + jakarta.enterprise.concurrent-api + 3.0.3 provided org.eclipse.microprofile microprofile - 3.3 + 6.1 pom provided @@ -42,7 +42,7 @@ org.eclipse.microprofile.reactive.messaging microprofile-reactive-messaging-api - 1.0 + 3.0 provided @@ -57,33 +57,55 @@ org.apache.kafka kafka-clients - 2.8.1 + 3.7.0 io.reactivex.rxjava3 rxjava - 3.1.2 + 3.1.8 - - org.microshed - microshed-testing-liberty - 0.9.1 - test + org.slf4j + slf4j-api + 2.0.12 + + org.slf4j + slf4j-simple + 2.0.12 + + org.testcontainers kafka - 1.16.2 + 1.19.7 test org.junit.jupiter junit-jupiter - 5.7.0 + 5.10.2 + test + + + org.testcontainers + junit-jupiter + 1.19.7 + test + + + org.jboss.resteasy + resteasy-client + 6.2.8.Final + test + + + org.jboss.resteasy + resteasy-json-binding-provider + 6.2.8.Final test @@ -94,7 +116,7 @@ org.apache.maven.plugins maven-war-plugin - 3.3.0 + 3.4.0 pom.xml @@ -104,21 +126,29 @@ io.openliberty.tools liberty-maven-plugin - 3.8.2 + 3.10.2 + + + + -e WLP_LOGGING_CONSOLE_LOGLEVEL=info + -p 9085:9085 + --network=reactive-app + + org.apache.maven.plugins maven-surefire-plugin - 2.22.2 + 3.2.5 org.apache.maven.plugins maven-failsafe-plugin - 2.22.2 + 3.2.5 diff --git a/start/inventory/src/main/java/io/openliberty/guides/inventory/InventoryApplication.java b/start/inventory/src/main/java/io/openliberty/guides/inventory/InventoryApplication.java index 6c276865..bd4c8dbc 100644 --- a/start/inventory/src/main/java/io/openliberty/guides/inventory/InventoryApplication.java +++ b/start/inventory/src/main/java/io/openliberty/guides/inventory/InventoryApplication.java @@ -1,21 +1,20 @@ // tag::copyright[] /******************************************************************************* - * Copyright (c) 2020 IBM Corporation and others. + * Copyright (c) 2020, 2024 IBM Corporation and others. * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 + * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html + * http://www.eclipse.org/legal/epl-2.0/ * - * Contributors: - * IBM Corporation - Initial implementation + * SPDX-License-Identifier: EPL-2.0 *******************************************************************************/ // end::copyright[] package io.openliberty.guides.inventory; -import javax.ws.rs.core.Application; -import javax.ws.rs.ApplicationPath; +import jakarta.ws.rs.core.Application; +import jakarta.ws.rs.ApplicationPath; @ApplicationPath("/") public class InventoryApplication extends Application { -} \ No newline at end of file +} diff --git a/start/inventory/src/main/java/io/openliberty/guides/inventory/InventoryManager.java b/start/inventory/src/main/java/io/openliberty/guides/inventory/InventoryManager.java index 4b0e813a..79fcc92e 100644 --- a/start/inventory/src/main/java/io/openliberty/guides/inventory/InventoryManager.java +++ b/start/inventory/src/main/java/io/openliberty/guides/inventory/InventoryManager.java @@ -1,13 +1,12 @@ // tag::copyright[] /******************************************************************************* - * Copyright (c) 2020 IBM Corporation and others. + * Copyright (c) 2020, 2024 IBM Corporation and others. * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 + * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html + * http://www.eclipse.org/legal/epl-2.0/ * - * Contributors: - * IBM Corporation - Initial implementation + * SPDX-License-Identifier: EPL-2.0 *******************************************************************************/ // end::copyright[] package io.openliberty.guides.inventory; @@ -20,12 +19,13 @@ import java.util.Properties; import java.util.TreeMap; -import javax.enterprise.context.ApplicationScoped; +import jakarta.enterprise.context.ApplicationScoped; @ApplicationScoped public class InventoryManager { - - private Map systems = Collections.synchronizedMap(new TreeMap()); + + private Map systems = Collections.synchronizedMap( + new TreeMap()); public void addSystem(String hostname, Double systemLoad) { if (!systems.containsKey(hostname)) { @@ -39,8 +39,9 @@ public void addSystem(String hostname, Double systemLoad) { public void updateCpuStatus(String hostname, Double systemLoad) { Optional p = getSystem(hostname); if (p.isPresent()) { - if (p.get().getProperty(hostname) == null && hostname != null) + if (p.get().getProperty(hostname) == null && hostname != null) { p.get().put("systemLoad", systemLoad); + } } } @@ -56,4 +57,4 @@ public List getSystems() { public void resetSystems() { systems.clear(); } -} \ No newline at end of file +} diff --git a/start/inventory/src/main/java/io/openliberty/guides/inventory/InventoryResource.java b/start/inventory/src/main/java/io/openliberty/guides/inventory/InventoryResource.java index 0435e617..bd830f45 100644 --- a/start/inventory/src/main/java/io/openliberty/guides/inventory/InventoryResource.java +++ b/start/inventory/src/main/java/io/openliberty/guides/inventory/InventoryResource.java @@ -1,13 +1,12 @@ // tag::copyright[] /******************************************************************************* - * Copyright (c) 2020 IBM Corporation and others. + * Copyright (c) 2020, 2024 IBM Corporation and others. * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 + * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html + * http://www.eclipse.org/legal/epl-2.0/ * - * Contributors: - * IBM Corporation - Initial implementation + * SPDX-License-Identifier: EPL-2.0 *******************************************************************************/ // end::copyright[] package io.openliberty.guides.inventory; @@ -17,15 +16,15 @@ import java.util.Properties; import java.util.logging.Logger; -import javax.enterprise.context.ApplicationScoped; -import javax.inject.Inject; -import javax.ws.rs.DELETE; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.inject.Inject; +import jakarta.ws.rs.DELETE; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.PathParam; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.Response; import org.eclipse.microprofile.reactive.messaging.Incoming; @@ -42,7 +41,7 @@ public class InventoryResource { @Inject private InventoryManager manager; - + @GET @Path("/systems") @Produces(MediaType.APPLICATION_JSON) @@ -65,9 +64,8 @@ public Properties getSystem(@PathParam("hostname") String hostname) { @Produces(MediaType.APPLICATION_JSON) public Response resetSystems() { manager.resetSystems(); - return Response - .status(Response.Status.OK) - .build(); + return Response.status(Response.Status.OK) + .build(); } @Incoming("systemLoad") diff --git a/start/inventory/src/main/java/io/openliberty/guides/inventory/health/InventoryLivenessCheck.java b/start/inventory/src/main/java/io/openliberty/guides/inventory/health/InventoryLivenessCheck.java index 3529f119..9ec01516 100644 --- a/start/inventory/src/main/java/io/openliberty/guides/inventory/health/InventoryLivenessCheck.java +++ b/start/inventory/src/main/java/io/openliberty/guides/inventory/health/InventoryLivenessCheck.java @@ -1,18 +1,17 @@ // tag::copyright[] /******************************************************************************* - * Copyright (c) 2020 IBM Corporation and others. + * Copyright (c) 2020, 2024 IBM Corporation and others. * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 + * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html + * http://www.eclipse.org/legal/epl-2.0/ * - * Contributors: - * IBM Corporation - Initial implementation + * SPDX-License-Identifier: EPL-2.0 *******************************************************************************/ // end::copyright[] package io.openliberty.guides.inventory.health; -import javax.enterprise.context.ApplicationScoped; +import jakarta.enterprise.context.ApplicationScoped; import org.eclipse.microprofile.health.HealthCheck; import org.eclipse.microprofile.health.HealthCheckResponse; @@ -29,6 +28,7 @@ private boolean isAlive() { @Override public HealthCheckResponse call() { boolean up = isAlive(); - return HealthCheckResponse.named(this.getClass().getSimpleName()).state(up).build(); + return HealthCheckResponse.named( + this.getClass().getSimpleName()).status(up).build(); } } diff --git a/start/inventory/src/main/java/io/openliberty/guides/inventory/health/InventoryReadinessCheck.java b/start/inventory/src/main/java/io/openliberty/guides/inventory/health/InventoryReadinessCheck.java index 45504d81..48a4d6b1 100644 --- a/start/inventory/src/main/java/io/openliberty/guides/inventory/health/InventoryReadinessCheck.java +++ b/start/inventory/src/main/java/io/openliberty/guides/inventory/health/InventoryReadinessCheck.java @@ -1,13 +1,12 @@ // tag::copyright[] /******************************************************************************* - * Copyright (c) 2020 IBM Corporation and others. + * Copyright (c) 2020, 2024 IBM Corporation and others. * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 + * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html + * http://www.eclipse.org/legal/epl-2.0/ * - * Contributors: - * IBM Corporation - Initial implementation + * SPDX-License-Identifier: EPL-2.0 *******************************************************************************/ // end::copyright[] package io.openliberty.guides.inventory.health; @@ -16,8 +15,8 @@ import java.util.Properties; import java.util.logging.Logger; -import javax.enterprise.context.ApplicationScoped; -import javax.inject.Inject; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.inject.Inject; import org.apache.kafka.clients.admin.AdminClient; import org.apache.kafka.clients.admin.ConsumerGroupListing; @@ -32,44 +31,51 @@ @ApplicationScoped public class InventoryReadinessCheck implements HealthCheck { - private static Logger logger = Logger.getLogger(InventoryReadinessCheck.class.getName()); - + private static Logger logger = Logger.getLogger( + InventoryReadinessCheck.class.getName()); + @Inject @ConfigProperty(name = "mp.messaging.connector.liberty-kafka.bootstrap.servers") String kafkaServer; - + @Inject @ConfigProperty(name = "mp.messaging.incoming.systemLoad.group.id") String groupId; - + @Override public HealthCheckResponse call() { boolean up = isReady(); - return HealthCheckResponse.named(this.getClass().getSimpleName()).state(up).build(); + return HealthCheckResponse.named( + this.getClass().getSimpleName()).status(up).build(); } private boolean isReady() { AdminClient adminClient = createAdminClient(); return checkIfBarConsumerGroupRegistered(adminClient); } - + private AdminClient createAdminClient() { Properties connectionProperties = new Properties(); connectionProperties.put("bootstrap.servers", kafkaServer); AdminClient adminClient = AdminClient.create(connectionProperties); return adminClient; } - + private boolean checkIfBarConsumerGroupRegistered(AdminClient adminClient) { ListConsumerGroupsResult groupsResult = adminClient.listConsumerGroups(); - KafkaFuture> consumerGroupsFuture = groupsResult.valid(); + KafkaFuture> consumerGroupsFuture = + groupsResult.valid(); try { - Collection consumerGroups = consumerGroupsFuture.get(); - for (ConsumerGroupListing g : consumerGroups) + Collection consumerGroups = + consumerGroupsFuture.get(); + for (ConsumerGroupListing g : consumerGroups) { logger.info("groupId: " + g.groupId()); - return consumerGroups.stream().anyMatch(group -> group.groupId().equals(groupId)); + } + return consumerGroups.stream().anyMatch( + group -> group.groupId().equals(groupId)); } catch (Exception e) { return false; } } } + diff --git a/start/inventory/src/main/liberty/config/server.xml b/start/inventory/src/main/liberty/config/server.xml index f15d5e27..0220fe88 100755 --- a/start/inventory/src/main/liberty/config/server.xml +++ b/start/inventory/src/main/liberty/config/server.xml @@ -1,20 +1,20 @@ - jaxrs-2.1 - cdi-2.0 - concurrent-1.0 - jsonb-1.0 - mpHealth-2.2 - mpConfig-1.4 - mpReactiveMessaging-1.0 + restfulWS-3.1 + cdi-4.0 + concurrent-3.0 + jsonb-3.0 + mpHealth-4.0 + mpConfig-3.1 + mpReactiveMessaging-3.0 - - + + - + diff --git a/start/inventory/src/main/resources/META-INF/microprofile-config.properties b/start/inventory/src/main/resources/META-INF/microprofile-config.properties index 2c782324..36521302 100644 --- a/start/inventory/src/main/resources/META-INF/microprofile-config.properties +++ b/start/inventory/src/main/resources/META-INF/microprofile-config.properties @@ -1,6 +1,6 @@ # Kafka connection details # tag::kafkaConfig[] -mp.messaging.connector.liberty-kafka.bootstrap.servers=localhost:9093 +mp.messaging.connector.liberty-kafka.bootstrap.servers=kafka:9092 # end::kafkaConfig[] # systemLoad stream diff --git a/start/inventory/src/main/webapp/index.html b/start/inventory/src/main/webapp/index.html index 94d15c3d..816c9298 100755 --- a/start/inventory/src/main/webapp/index.html +++ b/start/inventory/src/main/webapp/index.html @@ -1,5 +1,5 @@ - 9080 - 9443 + 9080 + 9443 @@ -24,25 +24,25 @@ jakarta.platform jakarta.jakartaee-api - 8.0.0 + 10.0.0 provided - javax.enterprise.concurrent - javax.enterprise.concurrent-api - 1.1 + jakarta.enterprise.concurrent + jakarta.enterprise.concurrent-api + 3.0.3 provided - javax.validation - validation-api - 2.0.1.Final + jakarta.validation + jakarta.validation-api + 3.1.0-M1 provided org.eclipse.microprofile microprofile - 3.3 + 6.1 pom provided @@ -50,7 +50,7 @@ org.eclipse.microprofile.reactive.messaging microprofile-reactive-messaging-api - 1.0 + 3.0 provided @@ -64,45 +64,67 @@ org.apache.kafka kafka-clients - 2.8.1 + 3.7.0 io.reactivex.rxjava3 rxjava - 3.1.2 + 3.1.8 - - org.microshed - microshed-testing-liberty - 0.9.1 - test + org.slf4j + slf4j-api + 2.0.12 + + + org.slf4j + slf4j-simple + 2.0.12 + org.testcontainers kafka - 1.16.2 + 1.19.7 test org.testcontainers mockserver - 1.16.2 + 1.19.7 test org.mock-server mockserver-client-java - 5.11.2 + 5.15.0 test org.junit.jupiter junit-jupiter - 5.7.0 + 5.10.2 + test + + + org.testcontainers + junit-jupiter + 1.19.7 + test + + + org.jboss.resteasy + resteasy-client + 6.2.8.Final + test + + + org.jboss.resteasy + resteasy-json-binding-provider + 6.2.8.Final test @@ -113,7 +135,7 @@ org.apache.maven.plugins maven-war-plugin - 3.3.0 + 3.4.0 pom.xml @@ -123,21 +145,21 @@ io.openliberty.tools liberty-maven-plugin - 3.8.2 + 3.10.2 org.apache.maven.plugins maven-surefire-plugin - 2.22.2 + 3.2.5 org.apache.maven.plugins maven-failsafe-plugin - 2.22.2 + 3.2.5 integration-test diff --git a/start/query/src/main/java/io/openliberty/guides/query/QueryApplication.java b/start/query/src/main/java/io/openliberty/guides/query/QueryApplication.java index bad727c0..992d9fa5 100644 --- a/start/query/src/main/java/io/openliberty/guides/query/QueryApplication.java +++ b/start/query/src/main/java/io/openliberty/guides/query/QueryApplication.java @@ -1,22 +1,21 @@ // tag::copyright[] /******************************************************************************* - * Copyright (c) 2020 IBM Corporation and others. + * Copyright (c) 2020, 2024 IBM Corporation and others. * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 + * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html + * http://www.eclipse.org/legal/epl-2.0/ * - * Contributors: - * IBM Corporation - Initial implementation + * SPDX-License-Identifier: EPL-2.0 *******************************************************************************/ // end::copyright[] package io.openliberty.guides.query; // JAX-RS -import javax.ws.rs.ApplicationPath; -import javax.ws.rs.core.Application; +import jakarta.ws.rs.ApplicationPath; +import jakarta.ws.rs.core.Application; @ApplicationPath("/") public class QueryApplication extends Application { -} \ No newline at end of file +} diff --git a/start/query/src/main/java/io/openliberty/guides/query/QueryResource.java b/start/query/src/main/java/io/openliberty/guides/query/QueryResource.java index 973de302..4989e6f0 100644 --- a/start/query/src/main/java/io/openliberty/guides/query/QueryResource.java +++ b/start/query/src/main/java/io/openliberty/guides/query/QueryResource.java @@ -1,3 +1,14 @@ +// tag::copyright[] +/******************************************************************************* + * Copyright (c) 2020, 2024 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + *******************************************************************************/ +// end::copyright[] package io.openliberty.guides.query; import java.math.BigDecimal; @@ -6,12 +17,12 @@ import java.util.Properties; import java.util.HashMap; -import javax.enterprise.context.ApplicationScoped; -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 jakarta.enterprise.context.ApplicationScoped; +import jakarta.inject.Inject; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; import org.eclipse.microprofile.rest.client.inject.RestClient; @@ -20,7 +31,7 @@ @ApplicationScoped @Path("/query") public class QueryResource { - + @Inject @RestClient private InventoryClient inventoryClient; @@ -34,7 +45,7 @@ public Map systemLoad() { for (String system : systems) { Properties p = inventoryClient.getSystem(system); - + systemLoads.updateValues(p); } @@ -44,7 +55,7 @@ public Map systemLoad() { private class Holder { private Map values; - public Holder() { + Holder() { this.values = new HashMap(); init(); } @@ -72,8 +83,10 @@ private void init() { this.values.put("lowest", new Properties()); this.values.get("highest").put("hostname", "temp_max"); this.values.get("lowest").put("hostname", "temp_min"); - this.values.get("highest").put("systemLoad", new BigDecimal(Double.MIN_VALUE)); - this.values.get("lowest").put("systemLoad", new BigDecimal(Double.MAX_VALUE)); + this.values.get("highest").put( + "systemLoad", new BigDecimal(Double.MIN_VALUE)); + this.values.get("lowest").put( + "systemLoad", new BigDecimal(Double.MAX_VALUE)); } } } diff --git a/start/query/src/main/java/io/openliberty/guides/query/client/InventoryClient.java b/start/query/src/main/java/io/openliberty/guides/query/client/InventoryClient.java index 8d46f2f0..8fddd5d1 100644 --- a/start/query/src/main/java/io/openliberty/guides/query/client/InventoryClient.java +++ b/start/query/src/main/java/io/openliberty/guides/query/client/InventoryClient.java @@ -1,13 +1,24 @@ +// tag::copyright[] +/******************************************************************************* + * Copyright (c) 2020, 2024 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + *******************************************************************************/ +// end::copyright[] package io.openliberty.guides.query.client; import java.util.List; import java.util.Properties; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.PathParam; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; @@ -18,11 +29,11 @@ public interface InventoryClient extends AutoCloseable { @GET @Path("/systems") @Produces(MediaType.APPLICATION_JSON) - public List getSystems(); + List getSystems(); @GET @Path("/systems/{hostname}") @Produces(MediaType.APPLICATION_JSON) - public Properties getSystem(@PathParam("hostname") String hostname); + Properties getSystem(@PathParam("hostname") String hostname); } diff --git a/start/query/src/main/java/io/openliberty/guides/query/health/QueryLivenessCheck.java b/start/query/src/main/java/io/openliberty/guides/query/health/QueryLivenessCheck.java index f84674dd..69b94c2e 100644 --- a/start/query/src/main/java/io/openliberty/guides/query/health/QueryLivenessCheck.java +++ b/start/query/src/main/java/io/openliberty/guides/query/health/QueryLivenessCheck.java @@ -1,18 +1,17 @@ // tag::copyright[] /******************************************************************************* - * Copyright (c) 2020 IBM Corporation and others. + * Copyright (c) 2020, 2024 IBM Corporation and others. * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 + * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html + * http://www.eclipse.org/legal/epl-2.0/ * - * Contributors: - * IBM Corporation - Initial implementation + * SPDX-License-Identifier: EPL-2.0 *******************************************************************************/ // end::copyright[] package io.openliberty.guides.query.health; -import javax.enterprise.context.ApplicationScoped; +import jakarta.enterprise.context.ApplicationScoped; import org.eclipse.microprofile.health.HealthCheck; import org.eclipse.microprofile.health.HealthCheckResponse; @@ -29,6 +28,7 @@ private boolean isAlive() { @Override public HealthCheckResponse call() { boolean up = isAlive(); - return HealthCheckResponse.named(this.getClass().getSimpleName()).state(up).build(); + return HealthCheckResponse.named( + this.getClass().getSimpleName()).status(up).build(); } } diff --git a/start/query/src/main/java/io/openliberty/guides/query/health/QueryReadinessCheck.java b/start/query/src/main/java/io/openliberty/guides/query/health/QueryReadinessCheck.java index 58db0521..867f4a5a 100644 --- a/start/query/src/main/java/io/openliberty/guides/query/health/QueryReadinessCheck.java +++ b/start/query/src/main/java/io/openliberty/guides/query/health/QueryReadinessCheck.java @@ -1,18 +1,17 @@ // tag::copyright[] /******************************************************************************* - * Copyright (c) 2020 IBM Corporation and others. + * Copyright (c) 2020, 2024 IBM Corporation and others. * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 + * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html + * http://www.eclipse.org/legal/epl-2.0/ * - * Contributors: - * IBM Corporation - Initial implementation + * SPDX-License-Identifier: EPL-2.0 *******************************************************************************/ // end::copyright[] package io.openliberty.guides.query.health; -import javax.enterprise.context.ApplicationScoped; +import jakarta.enterprise.context.ApplicationScoped; import org.eclipse.microprofile.health.HealthCheck; import org.eclipse.microprofile.health.HealthCheckResponse; @@ -29,6 +28,7 @@ private boolean isAlive() { @Override public HealthCheckResponse call() { boolean up = isAlive(); - return HealthCheckResponse.named(this.getClass().getSimpleName()).state(up).build(); + return HealthCheckResponse.named( + this.getClass().getSimpleName()).status(up).build(); } } diff --git a/start/query/src/main/liberty/config/server.xml b/start/query/src/main/liberty/config/server.xml index 516e03bd..f640ccf3 100755 --- a/start/query/src/main/liberty/config/server.xml +++ b/start/query/src/main/liberty/config/server.xml @@ -1,23 +1,23 @@ - beanValidation-2.0 - jaxrs-2.1 - cdi-2.0 - concurrent-1.0 - jsonb-1.0 - mpHealth-2.2 - mpConfig-1.4 - mpOpenAPI-1.1 - mpReactiveMessaging-1.0 - mpRestClient-1.4 + beanValidation-3.0 + restfulWS-3.1 + cdi-4.0 + concurrent-3.0 + jsonb-3.0 + mpHealth-4.0 + mpConfig-3.1 + mpOpenAPI-3.1 + mpReactiveMessaging-3.0 + mpRestClient-3.0 - - + + - + diff --git a/start/query/src/main/webapp/index.html b/start/query/src/main/webapp/index.html index 94d15c3d..816c9298 100755 --- a/start/query/src/main/webapp/index.html +++ b/start/query/src/main/webapp/index.html @@ -1,5 +1,5 @@ - 9083 - 9446 + 9083 + 9446 @@ -24,13 +24,13 @@ jakarta.platform jakarta.jakartaee-api - 8.0.0 + 10.0.0 provided org.eclipse.microprofile microprofile - 3.3 + 6.1 pom provided @@ -38,7 +38,7 @@ org.eclipse.microprofile.reactive.messaging microprofile-reactive-messaging-api - 1.0 + 3.0 provided @@ -52,33 +52,43 @@ org.apache.kafka kafka-clients - 2.8.1 + 3.7.0 io.reactivex.rxjava3 rxjava - 3.1.2 + 3.1.8 - - org.microshed - microshed-testing-liberty - 0.9.1 - test + org.slf4j + slf4j-api + 2.0.12 + + + org.slf4j + slf4j-simple + 2.0.12 + org.testcontainers kafka - 1.16.2 + 1.19.7 test org.junit.jupiter junit-jupiter - 5.7.0 + 5.10.2 + test + + + org.testcontainers + junit-jupiter + 1.19.7 test @@ -89,7 +99,7 @@ org.apache.maven.plugins maven-war-plugin - 3.3.0 + 3.4.0 pom.xml @@ -99,21 +109,29 @@ io.openliberty.tools liberty-maven-plugin - 3.8.2 + 3.10.2 + + + + -e WLP_LOGGING_CONSOLE_LOGLEVEL=info + -p 9083:9083 + --network=reactive-app + + org.apache.maven.plugins maven-surefire-plugin - 2.22.2 + 3.2.5 org.apache.maven.plugins maven-failsafe-plugin - 2.22.2 + 3.2.5 integration-test diff --git a/start/system/src/main/java/io/openliberty/guides/system/SystemService.java b/start/system/src/main/java/io/openliberty/guides/system/SystemService.java index e6ddcb1c..a3816bce 100755 --- a/start/system/src/main/java/io/openliberty/guides/system/SystemService.java +++ b/start/system/src/main/java/io/openliberty/guides/system/SystemService.java @@ -1,13 +1,12 @@ // tag::copyright[] /******************************************************************************* - * Copyright (c) 2020 IBM Corporation and others. + * Copyright (c) 2020, 2024 IBM Corporation and others. * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 + * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html + * http://www.eclipse.org/legal/epl-2.0/ * - * Contributors: - * IBM Corporation - Initial implementation + * SPDX-License-Identifier: EPL-2.0 *******************************************************************************/ // end::copyright[] package io.openliberty.guides.system; @@ -18,7 +17,7 @@ import java.net.UnknownHostException; import java.util.concurrent.TimeUnit; -import javax.enterprise.context.ApplicationScoped; +import jakarta.enterprise.context.ApplicationScoped; import org.eclipse.microprofile.reactive.messaging.Outgoing; import org.reactivestreams.Publisher; @@ -29,7 +28,7 @@ @ApplicationScoped public class SystemService { - private static final OperatingSystemMXBean osMean = + private static final OperatingSystemMXBean OS_MEAN = ManagementFactory.getOperatingSystemMXBean(); private static String hostname = null; @@ -47,8 +46,8 @@ private static String getHostname() { @Outgoing("systemLoad") public Publisher sendSystemLoad() { return Flowable.interval(15, TimeUnit.SECONDS) - .map((interval -> new SystemLoad(getHostname(), - osMean.getSystemLoadAverage()))); + .map((interval -> new SystemLoad(getHostname(), + OS_MEAN.getSystemLoadAverage()))); } -} \ No newline at end of file +} diff --git a/start/system/src/main/java/io/openliberty/guides/system/health/SystemLivenessCheck.java b/start/system/src/main/java/io/openliberty/guides/system/health/SystemLivenessCheck.java index fecdc862..60020811 100644 --- a/start/system/src/main/java/io/openliberty/guides/system/health/SystemLivenessCheck.java +++ b/start/system/src/main/java/io/openliberty/guides/system/health/SystemLivenessCheck.java @@ -1,18 +1,17 @@ // tag::copyright[] /******************************************************************************* - * Copyright (c) 2020 IBM Corporation and others. + * Copyright (c) 2020, 2024 IBM Corporation and others. * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 + * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html + * http://www.eclipse.org/legal/epl-2.0/ * - * Contributors: - * IBM Corporation - Initial implementation + * SPDX-License-Identifier: EPL-2.0 *******************************************************************************/ // end::copyright[] package io.openliberty.guides.system.health; -import javax.enterprise.context.ApplicationScoped; +import jakarta.enterprise.context.ApplicationScoped; import org.eclipse.microprofile.health.HealthCheck; import org.eclipse.microprofile.health.HealthCheckResponse; @@ -29,6 +28,7 @@ private boolean isAlive() { @Override public HealthCheckResponse call() { boolean up = isAlive(); - return HealthCheckResponse.named(this.getClass().getSimpleName()).state(up).build(); + return HealthCheckResponse.named( + this.getClass().getSimpleName()).status(up).build(); } } diff --git a/start/system/src/main/java/io/openliberty/guides/system/health/SystemReadinessCheck.java b/start/system/src/main/java/io/openliberty/guides/system/health/SystemReadinessCheck.java index cfc91446..9a548edb 100644 --- a/start/system/src/main/java/io/openliberty/guides/system/health/SystemReadinessCheck.java +++ b/start/system/src/main/java/io/openliberty/guides/system/health/SystemReadinessCheck.java @@ -1,13 +1,12 @@ // tag::copyright[] /******************************************************************************* - * Copyright (c) 2020 IBM Corporation and others. + * Copyright (c) 2020, 2024 IBM Corporation and others. * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 + * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html + * http://www.eclipse.org/legal/epl-2.0/ * - * Contributors: - * IBM Corporation - Initial implementation + * SPDX-License-Identifier: EPL-2.0 *******************************************************************************/ // end::copyright[] package io.openliberty.guides.system.health; @@ -16,8 +15,8 @@ import java.util.Properties; import java.util.logging.Logger; -import javax.enterprise.context.ApplicationScoped; -import javax.inject.Inject; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.inject.Inject; import org.apache.kafka.clients.admin.AdminClient; import org.apache.kafka.clients.admin.ListTopicsResult; @@ -32,37 +31,40 @@ @ApplicationScoped public class SystemReadinessCheck implements HealthCheck { - private static Logger logger = Logger.getLogger(SystemReadinessCheck.class.getName()); - + private static Logger logger = Logger.getLogger( + SystemReadinessCheck.class.getName()); + @Inject @ConfigProperty(name = "mp.messaging.connector.liberty-kafka.bootstrap.servers") String kafkaServer; - + @Override public HealthCheckResponse call() { boolean up = isReady(); - return HealthCheckResponse.named(this.getClass().getSimpleName()).state(up).build(); + return HealthCheckResponse.named( + this.getClass().getSimpleName()).status(up).build(); } private boolean isReady() { AdminClient adminClient = createAdminClient(); return checkIfBarConsumerGroupRegistered(adminClient); } - + private AdminClient createAdminClient() { Properties connectionProperties = new Properties(); connectionProperties.put("bootstrap.servers", kafkaServer); AdminClient adminClient = AdminClient.create(connectionProperties); return adminClient; } - + private boolean checkIfBarConsumerGroupRegistered(AdminClient adminClient) { ListTopicsResult topics = adminClient.listTopics(); KafkaFuture> topicsFuture = topics.listings(); try { Collection topicList = topicsFuture.get(); - for (TopicListing t : topicList) + for (TopicListing t : topicList) { logger.info("topic: " + t.name()); + } return true; } catch (Exception e) { return false; diff --git a/start/system/src/main/liberty/config/server.xml b/start/system/src/main/liberty/config/server.xml index bdf1f576..10646865 100755 --- a/start/system/src/main/liberty/config/server.xml +++ b/start/system/src/main/liberty/config/server.xml @@ -1,21 +1,21 @@ - cdi-2.0 - concurrent-1.0 - jsonb-1.0 - mpHealth-2.2 - mpConfig-1.4 + cdi-4.0 + concurrent-3.0 + jsonb-3.0 + mpHealth-4.0 + mpConfig-3.1 - mpReactiveMessaging-1.0 + mpReactiveMessaging-3.0 - - + + - + diff --git a/start/system/src/main/resources/META-INF/microprofile-config.properties b/start/system/src/main/resources/META-INF/microprofile-config.properties index bd86d976..cf3debdf 100644 --- a/start/system/src/main/resources/META-INF/microprofile-config.properties +++ b/start/system/src/main/resources/META-INF/microprofile-config.properties @@ -1,6 +1,6 @@ # Kafka connection details # tag::kafkaConfig[] -mp.messaging.connector.liberty-kafka.bootstrap.servers=localhost:9093 +mp.messaging.connector.liberty-kafka.bootstrap.servers=kafka:9092 # end::kafkaConfig[] # systemLoad stream diff --git a/start/system/src/main/webapp/index.html b/start/system/src/main/webapp/index.html index 468e1895..a7c70e79 100755 --- a/start/system/src/main/webapp/index.html +++ b/start/system/src/main/webapp/index.html @@ -1,5 +1,5 @@