forked from apache/incubator-kie-kogito-runtimes
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from rgdoliveira/sync_main
Sync main branch with Apache main branch
- Loading branch information
Showing
38 changed files
with
1,235 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
quarkus/addons/common/kogito-addons-quarkus-common-health/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
59 changes: 59 additions & 0 deletions
59
quarkus/addons/common/kogito-addons-quarkus-common-health/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.kie.kogito</groupId> | ||
<artifactId>kogito-addons-quarkus-common-parent</artifactId> | ||
<version>999-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>kogito-addons-quarkus-common-health</artifactId> | ||
<name>kogito-addons-quarkus-common-health</name> | ||
<properties> | ||
<java.module.name>org.kie.kogito.addons.quarkus.common.health</java.module.name> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.eclipse.microprofile.config</groupId> | ||
<artifactId>microprofile-config-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.microprofile.health</groupId> | ||
<artifactId>microprofile-health-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.smallrye.config</groupId> | ||
<artifactId>smallrye-config-core</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.smallrye.reactive</groupId> | ||
<artifactId>smallrye-mutiny-vertx-web-client</artifactId> | ||
</dependency> | ||
<!-- Testing dependencies --> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-api</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-engine</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mockito</groupId> | ||
<artifactId>mockito-core</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mockito</groupId> | ||
<artifactId>mockito-junit-jupiter</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.assertj</groupId> | ||
<artifactId>assertj-core</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
56 changes: 56 additions & 0 deletions
56
...h/src/main/java/org/kie/kogito/addon/quarkus/common/config/AbstractAliasConfigSource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String> propertyNames = new HashSet<>(); | ||
|
||
public AbstractAliasConfigSource(Set<String> 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<String> getPropertyNames() { | ||
return propertyNames; | ||
} | ||
|
||
@Override | ||
public String getValue(String propertyName) { | ||
return propertyNames.contains(propertyName) ? configValue : null; | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...ain/java/org/kie/kogito/addon/quarkus/common/config/AbstractAliasConfigSourceFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<T extends AbstractAliasConfigSource> implements ConfigSourceFactory { | ||
|
||
protected T configSource; | ||
|
||
public AbstractAliasConfigSourceFactory(T configSource) { | ||
this.configSource = configSource; | ||
} | ||
|
||
@Override | ||
public Iterable<ConfigSource> 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); | ||
} | ||
} | ||
} |
113 changes: 113 additions & 0 deletions
113
...main/java/org/kie/kogito/addon/quarkus/common/health/AbstractAvailabilityHealthCheck.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Buffer> 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(); | ||
} | ||
} |
Oops, something went wrong.