From 8968630353b75b99c8468716cce5637996849c1a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 25 Jan 2024 14:19:20 +0100 Subject: [PATCH 1/6] Bump com.jayway.jsonpath:json-path (#3362) Bumps [com.jayway.jsonpath:json-path](https://github.com/jayway/JsonPath) from 2.8.0 to 2.9.0. - [Release notes](https://github.com/jayway/JsonPath/releases) - [Changelog](https://github.com/json-path/JsonPath/blob/master/changelog.md) - [Commits](https://github.com/jayway/JsonPath/compare/json-path-2.8.0...json-path-2.9.0) --- updated-dependencies: - dependency-name: com.jayway.jsonpath:json-path dependency-type: direct:production ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- kogito-build/kogito-dependencies-bom/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kogito-build/kogito-dependencies-bom/pom.xml b/kogito-build/kogito-dependencies-bom/pom.xml index 6d38e1aafcc..ba2d5d04fae 100644 --- a/kogito-build/kogito-dependencies-bom/pom.xml +++ b/kogito-build/kogito-dependencies-bom/pom.xml @@ -25,7 +25,7 @@ 1.0.86 2.15.2 2.15.2 - 2.8.0 + 2.9.0 2.4.10 1.0.0-preview.20220705 2.0.1 From 579323462e62e9deb1ee6536704e732d0dc9934a Mon Sep 17 00:00:00 2001 From: Walter Medvedeo Date: Sat, 27 Jan 2024 20:18:58 +0100 Subject: [PATCH 2/6] kie-kogito-runtimes-3365: Add startup health checks to ensure data-index and jobs-service availability (#3375) * kie-kogito-runtimes-3365: Add startup health checks to ensure data-index and jobs-service availability * kie-kogito-runtimes-3365: Add startup health checks to ensure data-index and jobs-service availability - Unit tests * kie-kogito-runtimes-3365: Add startup health checks to ensure data-index and jobs-service availability - Use port 80 when no port is provided --- kogito-bom/pom.xml | 40 +++++++ .../.gitignore | 38 ++++++ .../pom.xml | 59 +++++++++ .../config/AbstractAliasConfigSource.java | 56 +++++++++ .../AbstractAliasConfigSourceFactory.java | 50 ++++++++ .../AbstractAvailabilityHealthCheck.java | 113 ++++++++++++++++++ .../AbstractAvailabilityHealthCheckTest.java | 99 +++++++++++++++ .../.gitignore | 38 ++++++ .../pom.xml | 64 ++++++++++ .../DataIndexAvailabilityHealthCheck.java | 47 ++++++++ ...exAvailabilityHealthCheckConfigSource.java | 43 +++++++ ...abilityHealthCheckConfigSourceFactory.java | 29 +++++ .../src/main/resources/META-INF/beans.xml | 20 ++++ .../io.smallrye.config.ConfigSourceFactory | 1 + ...dexServiceAvailabilityHealthCheckTest.java | 40 +++++++ .../.gitignore | 38 ++++++ .../pom.xml | 64 ++++++++++ .../JobsServiceAvailabilityHealthCheck.java | 47 ++++++++ ...ceAvailabilityHealthCheckConfigSource.java | 43 +++++++ ...abilityHealthCheckConfigSourceFactory.java | 29 +++++ .../src/main/resources/META-INF/beans.xml | 20 ++++ .../io.smallrye.config.ConfigSourceFactory | 1 + ...obsServiceAvailabilityHealthCheckTest.java | 40 +++++++ quarkus/addons/common/pom.xml | 3 + .../jobs/knative-eventing/runtime/pom.xml | 8 ++ .../src/main/resources/application.properties | 22 ++++ .../addons/knative/eventing/runtime/pom.xml | 4 + .../src/main/resources/application.properties | 22 ++++ 28 files changed, 1078 insertions(+) create mode 100644 quarkus/addons/common/kogito-addons-quarkus-common-health/.gitignore create mode 100644 quarkus/addons/common/kogito-addons-quarkus-common-health/pom.xml create mode 100644 quarkus/addons/common/kogito-addons-quarkus-common-health/src/main/java/org/kie/kogito/addon/quarkus/common/config/AbstractAliasConfigSource.java create mode 100644 quarkus/addons/common/kogito-addons-quarkus-common-health/src/main/java/org/kie/kogito/addon/quarkus/common/config/AbstractAliasConfigSourceFactory.java create mode 100644 quarkus/addons/common/kogito-addons-quarkus-common-health/src/main/java/org/kie/kogito/addon/quarkus/common/health/AbstractAvailabilityHealthCheck.java create mode 100644 quarkus/addons/common/kogito-addons-quarkus-common-health/src/test/java/org/kie/kogito/addon/quarkus/common/health/AbstractAvailabilityHealthCheckTest.java create mode 100644 quarkus/addons/common/kogito-addons-quarkus-data-index-health/.gitignore create mode 100644 quarkus/addons/common/kogito-addons-quarkus-data-index-health/pom.xml create mode 100644 quarkus/addons/common/kogito-addons-quarkus-data-index-health/src/main/java/org/kie/kogito/addon/quarkus/index/health/DataIndexAvailabilityHealthCheck.java create mode 100644 quarkus/addons/common/kogito-addons-quarkus-data-index-health/src/main/java/org/kie/kogito/addon/quarkus/index/health/DataIndexAvailabilityHealthCheckConfigSource.java create mode 100644 quarkus/addons/common/kogito-addons-quarkus-data-index-health/src/main/java/org/kie/kogito/addon/quarkus/index/health/DataIndexAvailabilityHealthCheckConfigSourceFactory.java create mode 100644 quarkus/addons/common/kogito-addons-quarkus-data-index-health/src/main/resources/META-INF/beans.xml create mode 100644 quarkus/addons/common/kogito-addons-quarkus-data-index-health/src/main/resources/META-INF/services/io.smallrye.config.ConfigSourceFactory create mode 100644 quarkus/addons/common/kogito-addons-quarkus-data-index-health/src/test/java/org/kie/kogito/addon/quarkus/index/health/DataIndexServiceAvailabilityHealthCheckTest.java create mode 100644 quarkus/addons/common/kogito-addons-quarkus-jobs-service-health/.gitignore create mode 100644 quarkus/addons/common/kogito-addons-quarkus-jobs-service-health/pom.xml create mode 100644 quarkus/addons/common/kogito-addons-quarkus-jobs-service-health/src/main/java/org/kie/kogito/addon/quarkus/jobs/health/JobsServiceAvailabilityHealthCheck.java create mode 100644 quarkus/addons/common/kogito-addons-quarkus-jobs-service-health/src/main/java/org/kie/kogito/addon/quarkus/jobs/health/JobsServiceAvailabilityHealthCheckConfigSource.java create mode 100644 quarkus/addons/common/kogito-addons-quarkus-jobs-service-health/src/main/java/org/kie/kogito/addon/quarkus/jobs/health/JobsServiceAvailabilityHealthCheckConfigSourceFactory.java create mode 100644 quarkus/addons/common/kogito-addons-quarkus-jobs-service-health/src/main/resources/META-INF/beans.xml create mode 100644 quarkus/addons/common/kogito-addons-quarkus-jobs-service-health/src/main/resources/META-INF/services/io.smallrye.config.ConfigSourceFactory create mode 100644 quarkus/addons/common/kogito-addons-quarkus-jobs-service-health/src/test/java/org/kie/kogito/addon/quarkus/jobs/health/JobsServiceAvailabilityHealthCheckTest.java create mode 100644 quarkus/addons/jobs/knative-eventing/runtime/src/main/resources/application.properties create mode 100644 quarkus/addons/knative/eventing/runtime/src/main/resources/application.properties diff --git a/kogito-bom/pom.xml b/kogito-bom/pom.xml index d916bb9eeee..64c1aeddc2b 100755 --- a/kogito-bom/pom.xml +++ b/kogito-bom/pom.xml @@ -1540,6 +1540,46 @@ ${project.version} sources + + org.kie.kogito + kogito-addons-quarkus-common-health + ${project.version} + + + org.kie.kogito + kogito-addons-quarkus-common-health + ${project.version} + sources + + + org.kie.kogito + kogito-addons-quarkus-common-health + ${project.version} + test-jar + test + + + org.kie.kogito + kogito-addons-quarkus-jobs-service-health + ${project.version} + + + org.kie.kogito + kogito-addons-quarkus-jobs-service-health + ${project.version} + sources + + + org.kie.kogito + kogito-addons-quarkus-data-index-health + ${project.version} + + + org.kie.kogito + kogito-addons-quarkus-data-index-health + ${project.version} + sources + org.kie.kogito kogito-addons-springboot-jobs-management diff --git a/quarkus/addons/common/kogito-addons-quarkus-common-health/.gitignore b/quarkus/addons/common/kogito-addons-quarkus-common-health/.gitignore new file mode 100644 index 00000000000..5ff6309b719 --- /dev/null +++ b/quarkus/addons/common/kogito-addons-quarkus-common-health/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/quarkus/addons/common/kogito-addons-quarkus-common-health/pom.xml b/quarkus/addons/common/kogito-addons-quarkus-common-health/pom.xml new file mode 100644 index 00000000000..3c26dd501cc --- /dev/null +++ b/quarkus/addons/common/kogito-addons-quarkus-common-health/pom.xml @@ -0,0 +1,59 @@ + + 4.0.0 + + org.kie.kogito + kogito-addons-quarkus-common-parent + 999-SNAPSHOT + + kogito-addons-quarkus-common-health + kogito-addons-quarkus-common-health + + org.kie.kogito.addons.quarkus.common.health + + + + + org.eclipse.microprofile.config + microprofile-config-api + + + org.eclipse.microprofile.health + microprofile-health-api + + + io.smallrye.config + smallrye-config-core + + + io.smallrye.reactive + smallrye-mutiny-vertx-web-client + + + + org.junit.jupiter + junit-jupiter-api + test + + + org.junit.jupiter + junit-jupiter-engine + test + + + org.mockito + mockito-core + test + + + org.mockito + mockito-junit-jupiter + test + + + org.assertj + assertj-core + test + + + diff --git a/quarkus/addons/common/kogito-addons-quarkus-common-health/src/main/java/org/kie/kogito/addon/quarkus/common/config/AbstractAliasConfigSource.java b/quarkus/addons/common/kogito-addons-quarkus-common-health/src/main/java/org/kie/kogito/addon/quarkus/common/config/AbstractAliasConfigSource.java new file mode 100644 index 00000000000..467519cba43 --- /dev/null +++ b/quarkus/addons/common/kogito-addons-quarkus-common-health/src/main/java/org/kie/kogito/addon/quarkus/common/config/AbstractAliasConfigSource.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.kie.kogito.addon.quarkus.common.config; + +import java.util.HashSet; +import java.util.Set; + +import org.eclipse.microprofile.config.spi.ConfigSource; + +public abstract class AbstractAliasConfigSource implements ConfigSource { + + protected int ordinal; + protected String configValue; + protected final Set propertyNames = new HashSet<>(); + + public AbstractAliasConfigSource(Set propertyNames) { + this.propertyNames.addAll(propertyNames); + } + + public void setOrdinal(int ordinal) { + this.ordinal = ordinal; + } + + public void setConfigValue(String configValue) { + this.configValue = configValue; + } + + public abstract String getConfigAlias(); + + @Override + public Set getPropertyNames() { + return propertyNames; + } + + @Override + public String getValue(String propertyName) { + return propertyNames.contains(propertyName) ? configValue : null; + } +} diff --git a/quarkus/addons/common/kogito-addons-quarkus-common-health/src/main/java/org/kie/kogito/addon/quarkus/common/config/AbstractAliasConfigSourceFactory.java b/quarkus/addons/common/kogito-addons-quarkus-common-health/src/main/java/org/kie/kogito/addon/quarkus/common/config/AbstractAliasConfigSourceFactory.java new file mode 100644 index 00000000000..7104c659af9 --- /dev/null +++ b/quarkus/addons/common/kogito-addons-quarkus-common-health/src/main/java/org/kie/kogito/addon/quarkus/common/config/AbstractAliasConfigSourceFactory.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.kie.kogito.addon.quarkus.common.config; + +import java.util.List; + +import org.eclipse.microprofile.config.spi.ConfigSource; + +import io.smallrye.config.ConfigSourceContext; +import io.smallrye.config.ConfigSourceFactory; +import io.smallrye.config.ConfigValue; + +public class AbstractAliasConfigSourceFactory implements ConfigSourceFactory { + + protected T configSource; + + public AbstractAliasConfigSourceFactory(T configSource) { + this.configSource = configSource; + } + + @Override + public Iterable getConfigSources(ConfigSourceContext context) { + ConfigValue configValue = context.getValue(configSource.getConfigAlias()); + String value = configValue.getValue(); + if (value == null || value.isEmpty()) { + return List.of(); + } else { + configSource.setConfigValue(value); + configSource.setOrdinal(configValue.getSourceOrdinal()); + return List.of(configSource); + } + } +} diff --git a/quarkus/addons/common/kogito-addons-quarkus-common-health/src/main/java/org/kie/kogito/addon/quarkus/common/health/AbstractAvailabilityHealthCheck.java b/quarkus/addons/common/kogito-addons-quarkus-common-health/src/main/java/org/kie/kogito/addon/quarkus/common/health/AbstractAvailabilityHealthCheck.java new file mode 100644 index 00000000000..ca86f96e3b2 --- /dev/null +++ b/quarkus/addons/common/kogito-addons-quarkus-common-health/src/main/java/org/kie/kogito/addon/quarkus/common/health/AbstractAvailabilityHealthCheck.java @@ -0,0 +1,113 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.kie.kogito.addon.quarkus.common.health; + +import java.net.MalformedURLException; +import java.net.URL; +import java.time.Duration; + +import org.eclipse.microprofile.health.HealthCheck; +import org.eclipse.microprofile.health.HealthCheckResponse; +import org.eclipse.microprofile.health.HealthCheckResponseBuilder; + +import io.vertx.core.http.HttpMethod; +import io.vertx.core.json.JsonObject; +import io.vertx.mutiny.core.Vertx; +import io.vertx.mutiny.core.buffer.Buffer; +import io.vertx.mutiny.ext.web.client.HttpResponse; +import io.vertx.mutiny.ext.web.client.WebClient; + +public abstract class AbstractAvailabilityHealthCheck implements HealthCheck { + + private static final Duration DEFAULT_TIMEOUT = Duration.ofMillis(500); + private static final int DEFAULT_PORT = 80; + + protected String serviceName; + + protected String serviceUrl; + + protected String healthPath; + + protected String checkType; + + protected Vertx vertx; + + protected WebClient webClient; + + protected Duration requestTimeout; + + public AbstractAvailabilityHealthCheck() { + // CDI + } + + public AbstractAvailabilityHealthCheck(String serviceName, String serviceUrl, String healthPath, String checkType, + Vertx vertx, Duration requestTimeout) { + this.serviceName = serviceName; + this.serviceUrl = serviceUrl; + this.healthPath = healthPath; + this.checkType = checkType; + this.vertx = vertx; + this.requestTimeout = requestTimeout != null ? requestTimeout : DEFAULT_TIMEOUT; + this.webClient = createClient(); + } + + /** + * facilitates tests. + */ + protected WebClient createClient() { + return WebClient.create(vertx); + } + + @Override + public HealthCheckResponse call() { + HealthCheckResponseBuilder builder = HealthCheckResponse.named(serviceName + " Availability - " + checkType).up(); + if (serviceUrl == null) { + builder.down().withData("error", serviceName + " url is not configured"); + } else { + URL url; + try { + url = new URL(serviceUrl); + HttpResponse response = webClient.request(HttpMethod.GET, + url.getPort() > 0 ? url.getPort() : DEFAULT_PORT, + url.getHost(), + healthPath) + .send() + .await() + .atMost(requestTimeout); + if (response.statusCode() != 200) { + String data = "[" + response.statusCode() + "] - " + response.statusMessage(); + builder.down().withData("error", data); + } else { + JsonObject jsonResponse = response.bodyAsJsonObject(); + if (jsonResponse == null || !HealthCheckResponse.Status.UP.name().equals(jsonResponse.getString("status"))) { + builder.down(); + } + } + } catch (Exception e) { + if (e instanceof MalformedURLException) { + builder.down().withData("error", serviceName + " url configuration error: " + e.getMessage()); + } else { + builder.down().withData("error", "[unknown] - " + e.getMessage()); + } + } + } + return builder.build(); + } +} diff --git a/quarkus/addons/common/kogito-addons-quarkus-common-health/src/test/java/org/kie/kogito/addon/quarkus/common/health/AbstractAvailabilityHealthCheckTest.java b/quarkus/addons/common/kogito-addons-quarkus-common-health/src/test/java/org/kie/kogito/addon/quarkus/common/health/AbstractAvailabilityHealthCheckTest.java new file mode 100644 index 00000000000..86d3b98b27b --- /dev/null +++ b/quarkus/addons/common/kogito-addons-quarkus-common-health/src/test/java/org/kie/kogito/addon/quarkus/common/health/AbstractAvailabilityHealthCheckTest.java @@ -0,0 +1,99 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.kie.kogito.addon.quarkus.common.health; + +import org.eclipse.microprofile.health.HealthCheckResponse; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import io.smallrye.mutiny.Uni; +import io.vertx.core.http.HttpMethod; +import io.vertx.core.json.JsonObject; +import io.vertx.mutiny.core.Vertx; +import io.vertx.mutiny.core.buffer.Buffer; +import io.vertx.mutiny.ext.web.client.HttpRequest; +import io.vertx.mutiny.ext.web.client.HttpResponse; +import io.vertx.mutiny.ext.web.client.WebClient; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.lenient; +import static org.mockito.Mockito.mock; + +@ExtendWith(MockitoExtension.class) +public abstract class AbstractAvailabilityHealthCheckTest { + + protected static final String HOST = "service-host"; + protected static final int PORT = 8080; + protected static final String SERVICE_URL = "http://" + HOST + ":" + PORT; + protected static final String HEALTH_PATH = "/q/health/ready"; + protected AbstractAvailabilityHealthCheck healthCheck; + @Mock + protected Vertx vertx; + @Mock + protected WebClient webClient; + + protected abstract AbstractAvailabilityHealthCheck createHealthCheck(String serviceUrl, Vertx vertxMock, WebClient webClientMock); + + @Test + void healthCheckUp() { + healthCheck = createHealthCheck(SERVICE_URL, vertx, webClient); + prepareCall(HOST, PORT, HEALTH_PATH, HealthCheckResponse.Status.UP, false); + HealthCheckResponse response = healthCheck.call(); + assertThat(response.getStatus()).isEqualTo(HealthCheckResponse.Status.UP); + } + + @Test + void healthCheckDown() { + healthCheck = createHealthCheck(SERVICE_URL, vertx, webClient); + prepareCall(HOST, PORT, HEALTH_PATH, HealthCheckResponse.Status.DOWN, false); + HealthCheckResponse response = healthCheck.call(); + assertThat(response.getStatus()).isEqualTo(HealthCheckResponse.Status.DOWN); + } + + @Test + void healthCheckDownServiceCallError() { + healthCheck = createHealthCheck(SERVICE_URL, vertx, webClient); + prepareCall(HOST, PORT, HEALTH_PATH, HealthCheckResponse.Status.UP, true); + HealthCheckResponse response = healthCheck.call(); + assertThat(response.getStatus()).isEqualTo(HealthCheckResponse.Status.DOWN); + assertThat(response.getData()).isPresent(); + Object error = response.getData().get().get("error"); + assertThat(error).isNotNull().hasToString("[500] - Internal server error"); + } + + protected void prepareCall(String host, int port, String path, HealthCheckResponse.Status responseStatus, boolean mockError) { + HttpRequest requestMock = mock(HttpRequest.class); + doReturn(requestMock).when(webClient).request(HttpMethod.GET, port, host, path); + + HttpResponse httpResponse = mock(HttpResponse.class); + JsonObject jsonObject = JsonObject.of("status", responseStatus.name()); + lenient().doReturn(jsonObject).when(httpResponse).bodyAsJsonObject(); + int statusCode = 200; + if (mockError) { + statusCode = 500; + doReturn("Internal server error").when(httpResponse).statusMessage(); + } + doReturn(statusCode).when(httpResponse).statusCode(); + doReturn(Uni.createFrom().item(httpResponse)).when(requestMock).send(); + } +} diff --git a/quarkus/addons/common/kogito-addons-quarkus-data-index-health/.gitignore b/quarkus/addons/common/kogito-addons-quarkus-data-index-health/.gitignore new file mode 100644 index 00000000000..5ff6309b719 --- /dev/null +++ b/quarkus/addons/common/kogito-addons-quarkus-data-index-health/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/quarkus/addons/common/kogito-addons-quarkus-data-index-health/pom.xml b/quarkus/addons/common/kogito-addons-quarkus-data-index-health/pom.xml new file mode 100644 index 00000000000..5dc9de2e827 --- /dev/null +++ b/quarkus/addons/common/kogito-addons-quarkus-data-index-health/pom.xml @@ -0,0 +1,64 @@ + + 4.0.0 + + org.kie.kogito + kogito-addons-quarkus-common-parent + 999-SNAPSHOT + + kogito-addons-quarkus-data-index-health + kogito-addons-quarkus-data-index-health + + org.kie.kogito.addons.quarkus.index.health + + + + jakarta.enterprise + jakarta.enterprise.cdi-api + + + org.eclipse.microprofile.health + microprofile-health-api + + + io.smallrye.reactive + smallrye-mutiny-vertx-web-client + + + org.kie.kogito + kogito-addons-quarkus-common-health + + + + io.quarkus + quarkus-smallrye-health + test + + + org.junit.jupiter + junit-jupiter-api + test + + + org.junit.jupiter + junit-jupiter-engine + test + + + org.mockito + mockito-junit-jupiter + test + + + org.assertj + assertj-core + test + + + org.kie.kogito + kogito-addons-quarkus-common-health + test-jar + test + + + diff --git a/quarkus/addons/common/kogito-addons-quarkus-data-index-health/src/main/java/org/kie/kogito/addon/quarkus/index/health/DataIndexAvailabilityHealthCheck.java b/quarkus/addons/common/kogito-addons-quarkus-data-index-health/src/main/java/org/kie/kogito/addon/quarkus/index/health/DataIndexAvailabilityHealthCheck.java new file mode 100644 index 00000000000..1179f01d4c8 --- /dev/null +++ b/quarkus/addons/common/kogito-addons-quarkus-data-index-health/src/main/java/org/kie/kogito/addon/quarkus/index/health/DataIndexAvailabilityHealthCheck.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.kie.kogito.addon.quarkus.index.health; + +import java.time.Duration; +import java.util.Optional; + +import org.eclipse.microprofile.config.inject.ConfigProperty; +import org.eclipse.microprofile.health.Startup; +import org.kie.kogito.addon.quarkus.common.health.AbstractAvailabilityHealthCheck; + +import io.vertx.mutiny.core.Vertx; + +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.inject.Inject; + +@Startup +@ApplicationScoped +public class DataIndexAvailabilityHealthCheck extends AbstractAvailabilityHealthCheck { + + private static final String KOGITO_DATA_INDEX_URL = "kogito.data-index.url"; + + public static final String CONFIG_ALIAS = "kogito.data-index.health-enabled"; + + @Inject + public DataIndexAvailabilityHealthCheck(@ConfigProperty(name = KOGITO_DATA_INDEX_URL) Optional dataIndexUrl, + Vertx vertx) { + super("Data Index", dataIndexUrl.orElse(null), "/q/health/ready", "startup check", vertx, Duration.ofMillis(500)); + } +} diff --git a/quarkus/addons/common/kogito-addons-quarkus-data-index-health/src/main/java/org/kie/kogito/addon/quarkus/index/health/DataIndexAvailabilityHealthCheckConfigSource.java b/quarkus/addons/common/kogito-addons-quarkus-data-index-health/src/main/java/org/kie/kogito/addon/quarkus/index/health/DataIndexAvailabilityHealthCheckConfigSource.java new file mode 100644 index 00000000000..f9f6394cb66 --- /dev/null +++ b/quarkus/addons/common/kogito-addons-quarkus-data-index-health/src/main/java/org/kie/kogito/addon/quarkus/index/health/DataIndexAvailabilityHealthCheckConfigSource.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.kie.kogito.addon.quarkus.index.health; + +import java.util.Set; + +import org.kie.kogito.addon.quarkus.common.config.AbstractAliasConfigSource; + +public class DataIndexAvailabilityHealthCheckConfigSource extends AbstractAliasConfigSource { + + public DataIndexAvailabilityHealthCheckConfigSource() { + super(Set.of( + "io.smallrye.health.check." + DataIndexAvailabilityHealthCheck.class.getName() + ".enabled", + DataIndexAvailabilityHealthCheck.CONFIG_ALIAS)); + } + + @Override + public String getConfigAlias() { + return DataIndexAvailabilityHealthCheck.CONFIG_ALIAS; + } + + @Override + public String getName() { + return DataIndexAvailabilityHealthCheckConfigSource.class.getSimpleName(); + } +} diff --git a/quarkus/addons/common/kogito-addons-quarkus-data-index-health/src/main/java/org/kie/kogito/addon/quarkus/index/health/DataIndexAvailabilityHealthCheckConfigSourceFactory.java b/quarkus/addons/common/kogito-addons-quarkus-data-index-health/src/main/java/org/kie/kogito/addon/quarkus/index/health/DataIndexAvailabilityHealthCheckConfigSourceFactory.java new file mode 100644 index 00000000000..d3f451c3e08 --- /dev/null +++ b/quarkus/addons/common/kogito-addons-quarkus-data-index-health/src/main/java/org/kie/kogito/addon/quarkus/index/health/DataIndexAvailabilityHealthCheckConfigSourceFactory.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.kie.kogito.addon.quarkus.index.health; + +import org.kie.kogito.addon.quarkus.common.config.AbstractAliasConfigSourceFactory; + +public class DataIndexAvailabilityHealthCheckConfigSourceFactory extends AbstractAliasConfigSourceFactory { + + public DataIndexAvailabilityHealthCheckConfigSourceFactory() { + super(new DataIndexAvailabilityHealthCheckConfigSource()); + } +} \ No newline at end of file diff --git a/quarkus/addons/common/kogito-addons-quarkus-data-index-health/src/main/resources/META-INF/beans.xml b/quarkus/addons/common/kogito-addons-quarkus-data-index-health/src/main/resources/META-INF/beans.xml new file mode 100644 index 00000000000..a0eb9fbf8cd --- /dev/null +++ b/quarkus/addons/common/kogito-addons-quarkus-data-index-health/src/main/resources/META-INF/beans.xml @@ -0,0 +1,20 @@ + diff --git a/quarkus/addons/common/kogito-addons-quarkus-data-index-health/src/main/resources/META-INF/services/io.smallrye.config.ConfigSourceFactory b/quarkus/addons/common/kogito-addons-quarkus-data-index-health/src/main/resources/META-INF/services/io.smallrye.config.ConfigSourceFactory new file mode 100644 index 00000000000..59a8408281b --- /dev/null +++ b/quarkus/addons/common/kogito-addons-quarkus-data-index-health/src/main/resources/META-INF/services/io.smallrye.config.ConfigSourceFactory @@ -0,0 +1 @@ +org.kie.kogito.addon.quarkus.index.health.DataIndexAvailabilityHealthCheckConfigSourceFactory \ No newline at end of file diff --git a/quarkus/addons/common/kogito-addons-quarkus-data-index-health/src/test/java/org/kie/kogito/addon/quarkus/index/health/DataIndexServiceAvailabilityHealthCheckTest.java b/quarkus/addons/common/kogito-addons-quarkus-data-index-health/src/test/java/org/kie/kogito/addon/quarkus/index/health/DataIndexServiceAvailabilityHealthCheckTest.java new file mode 100644 index 00000000000..ebba81ebf52 --- /dev/null +++ b/quarkus/addons/common/kogito-addons-quarkus-data-index-health/src/test/java/org/kie/kogito/addon/quarkus/index/health/DataIndexServiceAvailabilityHealthCheckTest.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.kie.kogito.addon.quarkus.index.health; + +import java.util.Optional; + +import org.kie.kogito.addon.quarkus.common.health.AbstractAvailabilityHealthCheck; +import org.kie.kogito.addon.quarkus.common.health.AbstractAvailabilityHealthCheckTest; + +import io.vertx.mutiny.core.Vertx; +import io.vertx.mutiny.ext.web.client.WebClient; + +class DataIndexServiceAvailabilityHealthCheckTest extends AbstractAvailabilityHealthCheckTest { + @Override + protected AbstractAvailabilityHealthCheck createHealthCheck(String serviceUrl, Vertx vertxMock, WebClient webClientMock) { + return new DataIndexAvailabilityHealthCheck(Optional.of(serviceUrl), vertxMock) { + @Override + public WebClient createClient() { + return webClientMock; + } + }; + } +} diff --git a/quarkus/addons/common/kogito-addons-quarkus-jobs-service-health/.gitignore b/quarkus/addons/common/kogito-addons-quarkus-jobs-service-health/.gitignore new file mode 100644 index 00000000000..5ff6309b719 --- /dev/null +++ b/quarkus/addons/common/kogito-addons-quarkus-jobs-service-health/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/quarkus/addons/common/kogito-addons-quarkus-jobs-service-health/pom.xml b/quarkus/addons/common/kogito-addons-quarkus-jobs-service-health/pom.xml new file mode 100644 index 00000000000..424ebdc3154 --- /dev/null +++ b/quarkus/addons/common/kogito-addons-quarkus-jobs-service-health/pom.xml @@ -0,0 +1,64 @@ + + 4.0.0 + + org.kie.kogito + kogito-addons-quarkus-common-parent + 999-SNAPSHOT + + kogito-addons-quarkus-jobs-service-health + kogito-addons-quarkus-jobs-service-health + + org.kie.kogito.addons.quarkus.jobs.health + + + + jakarta.enterprise + jakarta.enterprise.cdi-api + + + org.eclipse.microprofile.health + microprofile-health-api + + + io.smallrye.reactive + smallrye-mutiny-vertx-web-client + + + org.kie.kogito + kogito-addons-quarkus-common-health + + + + io.quarkus + quarkus-smallrye-health + test + + + org.junit.jupiter + junit-jupiter-api + test + + + org.junit.jupiter + junit-jupiter-engine + test + + + org.mockito + mockito-junit-jupiter + test + + + org.assertj + assertj-core + test + + + org.kie.kogito + kogito-addons-quarkus-common-health + test-jar + test + + + diff --git a/quarkus/addons/common/kogito-addons-quarkus-jobs-service-health/src/main/java/org/kie/kogito/addon/quarkus/jobs/health/JobsServiceAvailabilityHealthCheck.java b/quarkus/addons/common/kogito-addons-quarkus-jobs-service-health/src/main/java/org/kie/kogito/addon/quarkus/jobs/health/JobsServiceAvailabilityHealthCheck.java new file mode 100644 index 00000000000..eb210811ed1 --- /dev/null +++ b/quarkus/addons/common/kogito-addons-quarkus-jobs-service-health/src/main/java/org/kie/kogito/addon/quarkus/jobs/health/JobsServiceAvailabilityHealthCheck.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.kie.kogito.addon.quarkus.jobs.health; + +import java.time.Duration; +import java.util.Optional; + +import org.eclipse.microprofile.config.inject.ConfigProperty; +import org.eclipse.microprofile.health.Startup; +import org.kie.kogito.addon.quarkus.common.health.AbstractAvailabilityHealthCheck; + +import io.vertx.mutiny.core.Vertx; + +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.inject.Inject; + +@Startup +@ApplicationScoped +public class JobsServiceAvailabilityHealthCheck extends AbstractAvailabilityHealthCheck { + + private static final String KOGITO_JOBS_SERVICE_URL = "kogito.jobs-service.url"; + + public static final String CONFIG_ALIAS = "kogito.jobs-service.health-enabled"; + + @Inject + public JobsServiceAvailabilityHealthCheck(@ConfigProperty(name = KOGITO_JOBS_SERVICE_URL) Optional jobsServiceUrl, + Vertx vertx) { + super("Jobs Service", jobsServiceUrl.orElse(null), "/q/health/ready", "startup check", vertx, Duration.ofMillis(500)); + } +} diff --git a/quarkus/addons/common/kogito-addons-quarkus-jobs-service-health/src/main/java/org/kie/kogito/addon/quarkus/jobs/health/JobsServiceAvailabilityHealthCheckConfigSource.java b/quarkus/addons/common/kogito-addons-quarkus-jobs-service-health/src/main/java/org/kie/kogito/addon/quarkus/jobs/health/JobsServiceAvailabilityHealthCheckConfigSource.java new file mode 100644 index 00000000000..d75e68a58df --- /dev/null +++ b/quarkus/addons/common/kogito-addons-quarkus-jobs-service-health/src/main/java/org/kie/kogito/addon/quarkus/jobs/health/JobsServiceAvailabilityHealthCheckConfigSource.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.kie.kogito.addon.quarkus.jobs.health; + +import java.util.Set; + +import org.kie.kogito.addon.quarkus.common.config.AbstractAliasConfigSource; + +public class JobsServiceAvailabilityHealthCheckConfigSource extends AbstractAliasConfigSource { + + public JobsServiceAvailabilityHealthCheckConfigSource() { + super(Set.of( + "io.smallrye.health.check." + JobsServiceAvailabilityHealthCheck.class.getName() + ".enabled", + JobsServiceAvailabilityHealthCheck.CONFIG_ALIAS)); + } + + @Override + public String getConfigAlias() { + return JobsServiceAvailabilityHealthCheck.CONFIG_ALIAS; + } + + @Override + public String getName() { + return JobsServiceAvailabilityHealthCheckConfigSource.class.getSimpleName(); + } +} diff --git a/quarkus/addons/common/kogito-addons-quarkus-jobs-service-health/src/main/java/org/kie/kogito/addon/quarkus/jobs/health/JobsServiceAvailabilityHealthCheckConfigSourceFactory.java b/quarkus/addons/common/kogito-addons-quarkus-jobs-service-health/src/main/java/org/kie/kogito/addon/quarkus/jobs/health/JobsServiceAvailabilityHealthCheckConfigSourceFactory.java new file mode 100644 index 00000000000..daebd5ea55d --- /dev/null +++ b/quarkus/addons/common/kogito-addons-quarkus-jobs-service-health/src/main/java/org/kie/kogito/addon/quarkus/jobs/health/JobsServiceAvailabilityHealthCheckConfigSourceFactory.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.kie.kogito.addon.quarkus.jobs.health; + +import org.kie.kogito.addon.quarkus.common.config.AbstractAliasConfigSourceFactory; + +public class JobsServiceAvailabilityHealthCheckConfigSourceFactory extends AbstractAliasConfigSourceFactory { + + public JobsServiceAvailabilityHealthCheckConfigSourceFactory() { + super(new JobsServiceAvailabilityHealthCheckConfigSource()); + } +} diff --git a/quarkus/addons/common/kogito-addons-quarkus-jobs-service-health/src/main/resources/META-INF/beans.xml b/quarkus/addons/common/kogito-addons-quarkus-jobs-service-health/src/main/resources/META-INF/beans.xml new file mode 100644 index 00000000000..a0eb9fbf8cd --- /dev/null +++ b/quarkus/addons/common/kogito-addons-quarkus-jobs-service-health/src/main/resources/META-INF/beans.xml @@ -0,0 +1,20 @@ + diff --git a/quarkus/addons/common/kogito-addons-quarkus-jobs-service-health/src/main/resources/META-INF/services/io.smallrye.config.ConfigSourceFactory b/quarkus/addons/common/kogito-addons-quarkus-jobs-service-health/src/main/resources/META-INF/services/io.smallrye.config.ConfigSourceFactory new file mode 100644 index 00000000000..47353a9d507 --- /dev/null +++ b/quarkus/addons/common/kogito-addons-quarkus-jobs-service-health/src/main/resources/META-INF/services/io.smallrye.config.ConfigSourceFactory @@ -0,0 +1 @@ +org.kie.kogito.addon.quarkus.jobs.health.JobsServiceAvailabilityHealthCheckConfigSourceFactory diff --git a/quarkus/addons/common/kogito-addons-quarkus-jobs-service-health/src/test/java/org/kie/kogito/addon/quarkus/jobs/health/JobsServiceAvailabilityHealthCheckTest.java b/quarkus/addons/common/kogito-addons-quarkus-jobs-service-health/src/test/java/org/kie/kogito/addon/quarkus/jobs/health/JobsServiceAvailabilityHealthCheckTest.java new file mode 100644 index 00000000000..7ac3d8cf75d --- /dev/null +++ b/quarkus/addons/common/kogito-addons-quarkus-jobs-service-health/src/test/java/org/kie/kogito/addon/quarkus/jobs/health/JobsServiceAvailabilityHealthCheckTest.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.kie.kogito.addon.quarkus.jobs.health; + +import java.util.Optional; + +import org.kie.kogito.addon.quarkus.common.health.AbstractAvailabilityHealthCheck; +import org.kie.kogito.addon.quarkus.common.health.AbstractAvailabilityHealthCheckTest; + +import io.vertx.mutiny.core.Vertx; +import io.vertx.mutiny.ext.web.client.WebClient; + +class JobsServiceAvailabilityHealthCheckTest extends AbstractAvailabilityHealthCheckTest { + @Override + protected AbstractAvailabilityHealthCheck createHealthCheck(String serviceUrl, Vertx vertxMock, WebClient webClientMock) { + return new JobsServiceAvailabilityHealthCheck(Optional.of(serviceUrl), vertxMock) { + @Override + public WebClient createClient() { + return webClientMock; + } + }; + } +} diff --git a/quarkus/addons/common/pom.xml b/quarkus/addons/common/pom.xml index 2b730a748a0..db5c7b12e74 100644 --- a/quarkus/addons/common/pom.xml +++ b/quarkus/addons/common/pom.xml @@ -37,6 +37,9 @@ deployment reactive-messaging + kogito-addons-quarkus-common-health + kogito-addons-quarkus-data-index-health + kogito-addons-quarkus-jobs-service-health \ No newline at end of file diff --git a/quarkus/addons/jobs/knative-eventing/runtime/pom.xml b/quarkus/addons/jobs/knative-eventing/runtime/pom.xml index cf19132890e..d5db9510e5a 100644 --- a/quarkus/addons/jobs/knative-eventing/runtime/pom.xml +++ b/quarkus/addons/jobs/knative-eventing/runtime/pom.xml @@ -73,6 +73,14 @@ org.kie.kogito kogito-addons-quarkus-rest-callback + + org.kie.kogito + kogito-addons-quarkus-rest-callback + + + org.kie.kogito + kogito-addons-quarkus-jobs-service-health + org.mockito diff --git a/quarkus/addons/jobs/knative-eventing/runtime/src/main/resources/application.properties b/quarkus/addons/jobs/knative-eventing/runtime/src/main/resources/application.properties new file mode 100644 index 00000000000..6e5738923a6 --- /dev/null +++ b/quarkus/addons/jobs/knative-eventing/runtime/src/main/resources/application.properties @@ -0,0 +1,22 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +# Jobs service integration start check is disabled by default. +# When enabled, you must configure the property kogito.jobs-service.url. +kogito.jobs-service.health-enabled=false \ No newline at end of file diff --git a/quarkus/addons/knative/eventing/runtime/pom.xml b/quarkus/addons/knative/eventing/runtime/pom.xml index 42021e28e52..debd95b8057 100644 --- a/quarkus/addons/knative/eventing/runtime/pom.xml +++ b/quarkus/addons/knative/eventing/runtime/pom.xml @@ -56,6 +56,10 @@ quarkus-smallrye-health true + + org.kie.kogito + kogito-addons-quarkus-data-index-health + io.quarkus diff --git a/quarkus/addons/knative/eventing/runtime/src/main/resources/application.properties b/quarkus/addons/knative/eventing/runtime/src/main/resources/application.properties new file mode 100644 index 00000000000..1ccba741d9f --- /dev/null +++ b/quarkus/addons/knative/eventing/runtime/src/main/resources/application.properties @@ -0,0 +1,22 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +# Data Index integration start check is disabled by default. +# When enabled, you must configure the property kogito.data-index.url. +kogito.data-index.health-enabled=false \ No newline at end of file From ff4d8c6d95a17bbe2b25192301e51295988f5ed8 Mon Sep 17 00:00:00 2001 From: gabriel-farache Date: Tue, 30 Jan 2024 12:46:21 +0100 Subject: [PATCH 3/6] Bump openapi generator version (#3377) * Bump openapi generator version * Fix failing test * trigger GitHub actions --- kogito-build/kogito-dependencies-bom/pom.xml | 2 +- .../quarkus/it/openapi/client/ApiWithSecurityContextIT.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/kogito-build/kogito-dependencies-bom/pom.xml b/kogito-build/kogito-dependencies-bom/pom.xml index ba2d5d04fae..c70ad3fbec7 100644 --- a/kogito-build/kogito-dependencies-bom/pom.xml +++ b/kogito-build/kogito-dependencies-bom/pom.xml @@ -29,7 +29,7 @@ 2.4.10 1.0.0-preview.20220705 2.0.1 - 2.2.15 + 2.3.0 0.2.0 2.0.2 0.1.3 diff --git a/quarkus/integration-tests/integration-tests-quarkus-openapi-client/src/test/java/org/kie/kogito/quarkus/it/openapi/client/ApiWithSecurityContextIT.java b/quarkus/integration-tests/integration-tests-quarkus-openapi-client/src/test/java/org/kie/kogito/quarkus/it/openapi/client/ApiWithSecurityContextIT.java index 699401d1897..cd994233075 100644 --- a/quarkus/integration-tests/integration-tests-quarkus-openapi-client/src/test/java/org/kie/kogito/quarkus/it/openapi/client/ApiWithSecurityContextIT.java +++ b/quarkus/integration-tests/integration-tests-quarkus-openapi-client/src/test/java/org/kie/kogito/quarkus/it/openapi/client/ApiWithSecurityContextIT.java @@ -108,7 +108,7 @@ void verifyAuthHeadersOpenApi3_0() { authWithApiKeyServer3 .verify(postRequestedFor(urlEqualTo(AuthSecurityMockService.SEC_30.getPath())) - .withHeader("X-Client-Id", matching("Bearer mytoken,Bearer mytoken,Bearer")) + .withHeader("X-Client-Id", matching("Bearer mytoken,Bearer mytoken")) .withHeader("Authorization", matching("Bearer mytoken"))); } From bb35ab0d7773768e40950bd889ae755084d9a7f2 Mon Sep 17 00:00:00 2001 From: Francisco Javier Tirado Sarti <65240126+fjtirado@users.noreply.github.com> Date: Tue, 30 Jan 2024 22:20:23 +0100 Subject: [PATCH 4/6] [Fix_#3384] Including business key on process instance state event (#3385) --- .../org/kie/kogito/event/impl/ProcessInstanceEventBatch.java | 1 + 1 file changed, 1 insertion(+) diff --git a/api/kogito-events-core/src/main/java/org/kie/kogito/event/impl/ProcessInstanceEventBatch.java b/api/kogito-events-core/src/main/java/org/kie/kogito/event/impl/ProcessInstanceEventBatch.java index 96a34dba476..4f153ec5fd9 100644 --- a/api/kogito-events-core/src/main/java/org/kie/kogito/event/impl/ProcessInstanceEventBatch.java +++ b/api/kogito-events-core/src/main/java/org/kie/kogito/event/impl/ProcessInstanceEventBatch.java @@ -309,6 +309,7 @@ private ProcessInstanceStateDataEvent toProcessInstanceStateEvent(ProcessEvent e .rootProcessId(pi.getRootProcessId()) .rootProcessInstanceId(pi.getRootProcessInstanceId()) .state(event.getProcessInstance().getState()) + .businessKey(pi.getBusinessKey()) .slaDueDate(pi.getSlaDueDate()); String securityRoles = (String) event.getProcessInstance().getProcess().getMetaData().get("securityRoles"); From 5967c177c8a83c530b1deb3f2111d065cddb0278 Mon Sep 17 00:00:00 2001 From: Francisco Javier Tirado Sarti <65240126+fjtirado@users.noreply.github.com> Date: Tue, 30 Jan 2024 22:24:36 +0100 Subject: [PATCH 5/6] [Fix_#3366] Configuring exception propagation for event publishing (#3380) * [Fix_#3366] Making exception propagation for event publishing configurable * [Fix_#3366] Logging refinement --- .../events/config/EventsRuntimeConfig.java | 30 +++++++++++ .../ReactiveMessagingEventPublisher.java | 51 ++++++++++++++----- 2 files changed, 68 insertions(+), 13 deletions(-) diff --git a/quarkus/addons/events/process/runtime/src/main/java/org/kie/kogito/events/config/EventsRuntimeConfig.java b/quarkus/addons/events/process/runtime/src/main/java/org/kie/kogito/events/config/EventsRuntimeConfig.java index 18368bcd545..d89e3c9132e 100644 --- a/quarkus/addons/events/process/runtime/src/main/java/org/kie/kogito/events/config/EventsRuntimeConfig.java +++ b/quarkus/addons/events/process/runtime/src/main/java/org/kie/kogito/events/config/EventsRuntimeConfig.java @@ -31,18 +31,36 @@ public class EventsRuntimeConfig { @ConfigItem(name = "processinstances.enabled", defaultValue = "true") boolean processInstancesEventsEnabled; + /** + * Propagate errors for process instance emitter + */ + @ConfigItem(name = "processinstances.errors.propagate", defaultValue = "false") + boolean processInstancesPropagate; + /** * Enable publishing processes definition events */ @ConfigItem(name = "processdefinitions.enabled", defaultValue = "true") boolean processDefinitionEventsEnabled; + /** + * Propagate errors for process definition emitter + */ + @ConfigItem(name = "processdefinitions.errors.propagate", defaultValue = "false") + boolean processDefinitionPropagate; + /** * Enable publishing user task instances events */ @ConfigItem(name = "usertasks.enabled", defaultValue = "true") boolean userTasksEventsEnabled; + /** + * Propagate errors for user task emitter + */ + @ConfigItem(name = "usertasks.errors.propagate", defaultValue = "false") + boolean userTasksPropagate; + public boolean isProcessInstancesEventsEnabled() { return processInstancesEventsEnabled; } @@ -55,4 +73,16 @@ public boolean isUserTasksEventsEnabled() { return userTasksEventsEnabled; } + public boolean isProcessInstancesPropagateError() { + return processInstancesPropagate; + } + + public boolean isProcessDefinitionPropagateError() { + return processDefinitionPropagate; + } + + public boolean isUserTasksPropagateError() { + return userTasksPropagate; + } + } diff --git a/quarkus/addons/events/process/runtime/src/main/java/org/kie/kogito/events/process/ReactiveMessagingEventPublisher.java b/quarkus/addons/events/process/runtime/src/main/java/org/kie/kogito/events/process/ReactiveMessagingEventPublisher.java index 1b2b56ada1e..2eb517d5d81 100644 --- a/quarkus/addons/events/process/runtime/src/main/java/org/kie/kogito/events/process/ReactiveMessagingEventPublisher.java +++ b/quarkus/addons/events/process/runtime/src/main/java/org/kie/kogito/events/process/ReactiveMessagingEventPublisher.java @@ -21,6 +21,7 @@ import java.util.Collection; import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionStage; +import java.util.function.BiConsumer; import org.eclipse.microprofile.reactive.messaging.Channel; import org.eclipse.microprofile.reactive.messaging.Message; @@ -52,14 +53,17 @@ public class ReactiveMessagingEventPublisher implements EventPublisher { @Inject @Channel(PROCESS_INSTANCES_TOPIC_NAME) MutinyEmitter processInstancesEventsEmitter; + private BiConsumer, Message> processInstanceConsumer; @Inject @Channel(PROCESS_DEFINITIONS_TOPIC_NAME) MutinyEmitter processDefinitionEventsEmitter; + private BiConsumer, Message> processDefinitionConsumer; @Inject @Channel(USER_TASK_INSTANCES_TOPIC_NAME) MutinyEmitter userTasksEventsEmitter; + private BiConsumer, Message> userTaskConsumer; @Inject EventsRuntimeConfig eventsRuntimeConfig; @@ -71,6 +75,9 @@ public class ReactiveMessagingEventPublisher implements EventPublisher { @PostConstruct public void init() { decoratorProvider = decoratorProviderInstance.isResolvable() ? decoratorProviderInstance.get() : null; + processInstanceConsumer = eventsRuntimeConfig.isProcessInstancesPropagateError() ? new BlockingMessageEmitter() : new ReactiveMessageEmitter(); + processDefinitionConsumer = eventsRuntimeConfig.isProcessDefinitionPropagateError() ? new BlockingMessageEmitter() : new ReactiveMessageEmitter(); + userTaskConsumer = eventsRuntimeConfig.isUserTasksPropagateError() ? new BlockingMessageEmitter() : new ReactiveMessageEmitter(); } @Override @@ -79,7 +86,7 @@ public void publish(DataEvent event) { switch (event.getType()) { case "ProcessDefinitionEvent": if (eventsRuntimeConfig.isProcessDefinitionEventsEnabled()) { - publishToTopic(event, processDefinitionEventsEmitter, PROCESS_DEFINITIONS_TOPIC_NAME); + publishToTopic(processDefinitionConsumer, event, processDefinitionEventsEmitter, PROCESS_DEFINITIONS_TOPIC_NAME); } break; case "ProcessInstanceErrorDataEvent": @@ -88,7 +95,7 @@ public void publish(DataEvent event) { case "ProcessInstanceStateDataEvent": case "ProcessInstanceVariableDataEvent": if (eventsRuntimeConfig.isProcessInstancesEventsEnabled()) { - publishToTopic(event, processInstancesEventsEmitter, PROCESS_INSTANCES_TOPIC_NAME); + publishToTopic(processInstanceConsumer, event, processInstancesEventsEmitter, PROCESS_INSTANCES_TOPIC_NAME); } break; @@ -99,7 +106,7 @@ public void publish(DataEvent event) { case "UserTaskInstanceStateDataEvent": case "UserTaskInstanceVariableDataEvent": if (eventsRuntimeConfig.isUserTasksEventsEnabled()) { - publishToTopic(event, userTasksEventsEmitter, USER_TASK_INSTANCES_TOPIC_NAME); + publishToTopic(userTaskConsumer, event, userTasksEventsEmitter, USER_TASK_INSTANCES_TOPIC_NAME); } break; default: @@ -114,31 +121,49 @@ public void publish(Collection> events) { } } - protected void publishToTopic(DataEvent event, MutinyEmitter emitter, String topic) { + protected void publishToTopic(BiConsumer, Message> consumer, DataEvent event, MutinyEmitter emitter, String topic) { logger.debug("About to publish event {} to topic {}", event, topic); + Message message = null; try { String eventString = json.writeValueAsString(event); - Message message = decorateMessage(ContextAwareMessage.of(eventString)); - logger.debug("Event payload '{}'", eventString); - emitter.sendMessageAndAwait(message); - + message = decorateMessage(ContextAwareMessage.of(eventString)); } catch (Exception e) { - logger.error("Error while creating event to topic {} for event {}", topic, event, e); + logger.error("Error while creating event to topic {} for event {}", topic, event); + } + if (message != null) { + consumer.accept(emitter, message); } } - protected CompletionStage onAck(DataEvent event, String topic) { - logger.debug("Successfully published event {} to topic {}", event, topic); + protected CompletionStage onAck(Message message) { + logger.debug("Successfully published message {}", message.getPayload()); return CompletableFuture.completedFuture(null); } - protected CompletionStage onNack(Throwable reason, DataEvent event, String topic) { - logger.error("Error while publishing event to topic {} for event {}", topic, event, reason); + protected CompletionStage onNack(Throwable reason, Message message) { + logger.error("Error while publishing message {}", message, reason); return CompletableFuture.completedFuture(null); } protected Message decorateMessage(Message message) { return decoratorProvider != null ? decoratorProvider.decorate(message) : message; } + + private class BlockingMessageEmitter implements BiConsumer, Message> { + @Override + public void accept(MutinyEmitter emitter, Message message) { + emitter.sendMessageAndAwait(message); + logger.debug("Successfully published message {}", message.getPayload()); + } + } + + private class ReactiveMessageEmitter implements BiConsumer, Message> { + @Override + public void accept(MutinyEmitter emitter, Message message) { + emitter.sendMessageAndForget(message + .withAck(() -> onAck(message)) + .withNack(reason -> onNack(reason, message))); + } + } } From 1c5b3ff10c0e819f02c0baf8a0cce6c58a89aa3f Mon Sep 17 00:00:00 2001 From: Francisco Javier Tirado Sarti <65240126+fjtirado@users.noreply.github.com> Date: Fri, 2 Feb 2024 14:26:21 +0100 Subject: [PATCH 6/6] [Fix_3383] Adding binary cloud event support for outgoing messages (#3386) * [Fix_3383] Do not include null values on json payload * Revert "[Fix_3383] Do not include null values on json payload" This reverts commit 47b9b4d7599badd9f8bdabbec22ddf10ab7b82c7. * [Fix_#3383] Setting metadata when using binary --- .../AbstractQuarkusCloudEventEmitter.java | 30 +++++++++++++++---- .../quarkus/deployment/ChannelInfo.java | 13 ++++++-- .../deployment/ChannelMappingStrategy.java | 25 +++++++++++++++- .../quarkus/deployment/CloudEventMode.java | 24 +++++++++++++++ .../deployment/EventEmitterGenerator.java | 2 +- 5 files changed, 85 insertions(+), 9 deletions(-) create mode 100644 quarkus/addons/messaging/deployment/src/main/java/org/kie/kogito/addon/cloudevents/quarkus/deployment/CloudEventMode.java diff --git a/quarkus/addons/messaging/common/src/main/java/org/kie/kogito/addon/quarkus/messaging/common/AbstractQuarkusCloudEventEmitter.java b/quarkus/addons/messaging/common/src/main/java/org/kie/kogito/addon/quarkus/messaging/common/AbstractQuarkusCloudEventEmitter.java index 2b879347029..ceed88f4783 100644 --- a/quarkus/addons/messaging/common/src/main/java/org/kie/kogito/addon/quarkus/messaging/common/AbstractQuarkusCloudEventEmitter.java +++ b/quarkus/addons/messaging/common/src/main/java/org/kie/kogito/addon/quarkus/messaging/common/AbstractQuarkusCloudEventEmitter.java @@ -20,10 +20,12 @@ import java.io.IOException; import java.io.UncheckedIOException; +import java.util.Optional; import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionStage; import org.eclipse.microprofile.reactive.messaging.Message; +import org.eclipse.microprofile.reactive.messaging.Metadata; import org.kie.kogito.addon.quarkus.common.reactive.messaging.MessageDecoratorProvider; import org.kie.kogito.event.CloudEventMarshaller; import org.kie.kogito.event.DataEvent; @@ -32,6 +34,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import io.smallrye.reactive.messaging.ce.OutgoingCloudEventMetadata; +import io.smallrye.reactive.messaging.ce.OutgoingCloudEventMetadataBuilder; + import jakarta.inject.Inject; public abstract class AbstractQuarkusCloudEventEmitter implements EventEmitter { @@ -49,11 +54,11 @@ public abstract class AbstractQuarkusCloudEventEmitter implements EventEmitte public CompletionStage emit(DataEvent dataEvent) { logger.debug("publishing event {}", dataEvent); try { - Message message = messageDecorator.decorate(Message.of(getPayload(dataEvent)) + Message message = messageDecorator.decorate(getMessage(dataEvent)) .withNack(e -> { logger.error("Error publishing event {}", dataEvent, e); return CompletableFuture.completedFuture(null); - })); + }); emit(message); return message.getAck().get(); } catch (IOException e) { @@ -69,11 +74,26 @@ protected void setCloudEventMarshaller(CloudEventMarshaller marshaller) { this.cloudEventMarshaller = marshaller; } - private M getPayload(DataEvent event) throws IOException { + private Optional> getMetadata(DataEvent event) { + if (event.getId() == null || event.getType() == null || event.getSource() == null || event.getSpecVersion() == null) { + return Optional.empty(); + } + OutgoingCloudEventMetadataBuilder builder = OutgoingCloudEventMetadata.builder().withId(event.getId()).withSource(event.getSource()).withType(event.getType()) + .withSubject(event.getSubject()) + .withDataContentType(event.getDataContentType()).withDataSchema(event.getDataSchema()).withSpecVersion(event.getSpecVersion().name()).withTimestamp(event.getTime().toZonedDateTime()); + for (String extName : event.getExtensionNames()) { + builder.withExtension(extName, event.getExtension(extName)); + } + return Optional.of(builder.build()); + } + + private Message getMessage(DataEvent event) throws IOException { if (cloudEventMarshaller != null) { - return cloudEventMarshaller.marshall(event.asCloudEvent(cloudEventMarshaller.cloudEventDataFactory())); + return Message.of(cloudEventMarshaller.marshall(event.asCloudEvent(cloudEventMarshaller.cloudEventDataFactory()))); } else if (eventMarshaller != null) { - return eventMarshaller.marshall(event.getData()); + Optional> metadata = getMetadata(event); + M payload = eventMarshaller.marshall(event.getData()); + return metadata.isPresent() ? Message.of(payload, Metadata.of(metadata.orElseThrow())) : Message.of(payload); } else { throw new IllegalStateException("Not marshaller has been set for emitter " + this); } diff --git a/quarkus/addons/messaging/deployment/src/main/java/org/kie/kogito/addon/cloudevents/quarkus/deployment/ChannelInfo.java b/quarkus/addons/messaging/deployment/src/main/java/org/kie/kogito/addon/cloudevents/quarkus/deployment/ChannelInfo.java index 5d528da3143..4db58fae5c6 100644 --- a/quarkus/addons/messaging/deployment/src/main/java/org/kie/kogito/addon/cloudevents/quarkus/deployment/ChannelInfo.java +++ b/quarkus/addons/messaging/deployment/src/main/java/org/kie/kogito/addon/cloudevents/quarkus/deployment/ChannelInfo.java @@ -30,10 +30,13 @@ public class ChannelInfo { private final boolean isInput; private final boolean isDefault; + private final Optional cloudEventMode; + private final Optional marshaller; private final Optional onOverflow; - protected ChannelInfo(String channelName, Collection triggers, String className, boolean isInput, boolean isDefault, Optional marshaller, Optional onOverflow) { + protected ChannelInfo(String channelName, Collection triggers, String className, boolean isInput, boolean isDefault, Optional marshaller, Optional onOverflow, + Optional cloudEventMode) { this.className = className; this.channelName = channelName; this.isInput = isInput; @@ -41,6 +44,7 @@ protected ChannelInfo(String channelName, Collection triggers, String cl this.triggers = triggers; this.marshaller = marshaller; this.onOverflow = onOverflow; + this.cloudEventMode = cloudEventMode; } public Collection getTriggers() { @@ -93,9 +97,14 @@ public Optional getOnOverflow() { return onOverflow; } + public Optional getCloudEventMode() { + return cloudEventMode; + } + @Override public String toString() { return "ChannelInfo [channelName=" + channelName + ", className=" + className + ", triggers=" + triggers - + ", isInput=" + isInput + ", isDefault=" + isDefault + ", marshaller=" + marshaller + "]"; + + ", isInput=" + isInput + ", isDefault=" + isDefault + ", cloudEventMode=" + cloudEventMode + + ", marshaller=" + marshaller + ", onOverflow=" + onOverflow + "]"; } } diff --git a/quarkus/addons/messaging/deployment/src/main/java/org/kie/kogito/addon/cloudevents/quarkus/deployment/ChannelMappingStrategy.java b/quarkus/addons/messaging/deployment/src/main/java/org/kie/kogito/addon/cloudevents/quarkus/deployment/ChannelMappingStrategy.java index c62f4acfe49..485ce4749e1 100644 --- a/quarkus/addons/messaging/deployment/src/main/java/org/kie/kogito/addon/cloudevents/quarkus/deployment/ChannelMappingStrategy.java +++ b/quarkus/addons/messaging/deployment/src/main/java/org/kie/kogito/addon/cloudevents/quarkus/deployment/ChannelMappingStrategy.java @@ -47,6 +47,8 @@ private ChannelMappingStrategy() { private static final String INCOMING_DEFAULT_CHANNEL = KOGITO_INCOMING_PREFIX + "defaultName"; private static final String OUTGOING_DEFAULT_CHANNEL = KOGITO_OUTGOING_PREFIX + "defaultName"; + private static final String CLOUD_EVENT_MODE = KOGITO_OUTGOING_PREFIX + "cloudEventMode"; + private static final String MARSHALLER_PREFIX = KOGITO_MESSAGING_PREFIX + "marshaller."; private static final String UNMARSHALLLER_PREFIX = KOGITO_MESSAGING_PREFIX + "unmarshaller."; private static final String KOGITO_EMITTER_PREFIX = KOGITO_MESSAGING_PREFIX + "emitter."; @@ -96,7 +98,28 @@ private static ChannelInfo getChannelInfo(Config config, String property, String return new ChannelInfo(name, triggers.getOrDefault(name, Collections.singleton(name)), getClassName(config.getOptionalValue(getPropertyName(prefix, name, "value." + (isInput ? "deserializer" : "serializer")), String.class)), isInput, name.equals(defaultChannelName), config.getOptionalValue((isInput ? UNMARSHALLLER_PREFIX : MARSHALLER_PREFIX) + name, String.class), - isInput ? Optional.empty() : onOverflowInfo(config, name)); + isInput ? Optional.empty() : onOverflowInfo(config, name), cloudEventMode(config, name, property)); + } + + private static Optional cloudEventMode(Config config, String name, String property) { + if (!config.getOptionalValue("kogito.messaging.as-cloudevents", Boolean.class).orElse(true)) { + return Optional.empty(); + } + Optional cloudEventMode = getCloudEventMode(config, CLOUD_EVENT_MODE + "." + name); + if (cloudEventMode.isPresent()) { + return cloudEventMode; + } + cloudEventMode = getCloudEventMode(config, CLOUD_EVENT_MODE); + if (cloudEventMode.isPresent()) { + return cloudEventMode; + } + // if no config, infer default from connector type + String connector = config.getValue(property, String.class); + return Optional.of(connector.equals("quarkus-http") ? CloudEventMode.BINARY : CloudEventMode.STRUCTURED); + } + + private static Optional getCloudEventMode(Config config, String propName) { + return config.getOptionalValue(propName, String.class).map(String::toUpperCase).map(CloudEventMode::valueOf); } private static Optional onOverflowInfo(Config config, String name) { diff --git a/quarkus/addons/messaging/deployment/src/main/java/org/kie/kogito/addon/cloudevents/quarkus/deployment/CloudEventMode.java b/quarkus/addons/messaging/deployment/src/main/java/org/kie/kogito/addon/cloudevents/quarkus/deployment/CloudEventMode.java new file mode 100644 index 00000000000..bb53eaa7737 --- /dev/null +++ b/quarkus/addons/messaging/deployment/src/main/java/org/kie/kogito/addon/cloudevents/quarkus/deployment/CloudEventMode.java @@ -0,0 +1,24 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.kie.kogito.addon.cloudevents.quarkus.deployment; + +public enum CloudEventMode { + STRUCTURED, + BINARY +} diff --git a/quarkus/addons/messaging/deployment/src/main/java/org/kie/kogito/addon/cloudevents/quarkus/deployment/EventEmitterGenerator.java b/quarkus/addons/messaging/deployment/src/main/java/org/kie/kogito/addon/cloudevents/quarkus/deployment/EventEmitterGenerator.java index e2999c9bc4d..1dba1d91441 100644 --- a/quarkus/addons/messaging/deployment/src/main/java/org/kie/kogito/addon/cloudevents/quarkus/deployment/EventEmitterGenerator.java +++ b/quarkus/addons/messaging/deployment/src/main/java/org/kie/kogito/addon/cloudevents/quarkus/deployment/EventEmitterGenerator.java @@ -26,7 +26,7 @@ public class EventEmitterGenerator extends EventGenerator { public EventEmitterGenerator(KogitoBuildContext context, ChannelInfo channelInfo) { super(context, channelInfo, "EventEmitter"); - if (context.getApplicationProperty("kogito.messaging.as-cloudevents", Boolean.class).orElse(true)) { + if (channelInfo.getCloudEventMode().filter(mode -> mode == CloudEventMode.STRUCTURED).isPresent()) { generateMarshallerField("marshaller", "setCloudEventMarshaller", CloudEventMarshaller.class); } else { generateMarshallerField("marshaller", "setEventDataMarshaller", EventMarshaller.class);