-
Notifications
You must be signed in to change notification settings - Fork 206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[KOGITO-9145] Create an implementation of the Service Discovery catal… #3166
Changes from 1 commit
455b2a3
c409a15
045b847
fe2978d
f4a0473
bfe03c7
f94e0ea
623dab7
459e5a7
70b8e9d
ffe57f6
46bb068
5619273
70e5115
ecc5e52
ef27a2f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.kie.kogito</groupId> | ||
<artifactId>kogito-addons-quarkus-microprofile-config-service-catalog-parent</artifactId> | ||
<version>2.0.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>kogito-addons-quarkus-microprofile-config-service-catalog-deployment</artifactId> | ||
<name>Kogito Add-On MicroProfile Config Service Catalog - Deployment</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.kie.kogito</groupId> | ||
<artifactId>kogito-addons-quarkus-microprofile-config-service-catalog</artifactId> | ||
<version>2.0.0-SNAPSHOT</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-kubernetes-client-deployment</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-openshift-client-deployment</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<annotationProcessorPaths> | ||
<path> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-extension-processor</artifactId> | ||
<version>${version.io.quarkus}</version> | ||
</path> | ||
</annotationProcessorPaths> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.kie.kogito</groupId> | ||
<artifactId>kogito-addons-quarkus-parent</artifactId> | ||
<version>2.0.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>kogito-addons-quarkus-microprofile-config-service-catalog-parent</artifactId> | ||
<name>Kogito Add-On MicroProfile Config Service Catalog - Parent</name> | ||
<packaging>pom</packaging> | ||
|
||
<modules> | ||
<module>deployment</module> | ||
<module>runtime</module> | ||
</modules> | ||
</project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.kie.kogito</groupId> | ||
<artifactId>kogito-addons-quarkus-microprofile-config-service-catalog-parent</artifactId> | ||
<version>2.0.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>kogito-addons-quarkus-microprofile-config-service-catalog</artifactId> | ||
<name>Kogito Add-On MicroProfile Config Service Catalog</name> | ||
<properties> | ||
<!-- Other properties --> | ||
<version.io.quarkus>2.16.8.Final</version.io.quarkus> | ||
<!-- Other properties --> | ||
</properties> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.kie.kogito</groupId> | ||
<artifactId>kogito-addons-kubernetes-service-catalog</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-kubernetes-client</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-openshift-client</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-junit5</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.github.tomakehurst</groupId> | ||
<artifactId>wiremock-jre8</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.assertj</groupId> | ||
<artifactId>assertj-core</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>javax.enterprise</groupId> | ||
<artifactId>cdi-api</artifactId> | ||
<version>2.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.microprofile.config</groupId> | ||
<artifactId>microprofile-config-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.kie.kogito</groupId> | ||
<artifactId>kogito-addons-kubernetes-service-catalog</artifactId> | ||
<version>${project.version}</version> | ||
<type>test-jar</type> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-test-kubernetes-client</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-test-openshift-client</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-core</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mockito</groupId> | ||
<artifactId>mockito-junit-jupiter</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-inline</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-bootstrap-maven-plugin</artifactId> | ||
<version>${version.io.quarkus}</version> | ||
<executions> | ||
<execution> | ||
<phase>compile</phase> | ||
<goals> | ||
<goal>extension-descriptor</goal> | ||
</goals> | ||
<configuration> | ||
<deployment>${project.groupId}:${project.artifactId}-deployment:${project.version} | ||
</deployment> | ||
<capabilities> | ||
<provides>org.kie.kogito.addons.quarkus.microprofile.config.service.catalog</provides> | ||
</capabilities> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<annotationProcessorPaths> | ||
<path> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-extension-processor</artifactId> | ||
<version>${version.io.quarkus}</version> | ||
</path> | ||
</annotationProcessorPaths> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright 2023 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed 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.addons.quarkus.microprofile.config.service.catalog; | ||
|
||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
|
||
import org.eclipse.microprofile.config.Config; | ||
import org.eclipse.microprofile.config.ConfigProvider; | ||
import org.kie.kogito.addons.k8s.resource.catalog.KubernetesServiceCatalog; | ||
import org.kie.kogito.addons.k8s.resource.catalog.KubernetesServiceCatalogKey; | ||
|
||
@ApplicationScoped | ||
public class MicroProfileConfigServiceCatalog implements KubernetesServiceCatalog { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I would rewrite this class as: @ApplicationScoped
public class MicroProfileConfigServiceCatalog implements KubernetesServiceCatalog {
@Inject
Config config;
@Override
public Optional<URI> getServiceAddress(KubernetesServiceCatalogKey key) {
return config.getOptionalValue(key.getProtocol().getValue() + ":" + key.getCoordinates(), String.class)
.map(value -> {
try {
return new URI(value);
} catch (URISyntaxException e) {
// TODO: handle
throw new RuntimeException(e);
}
});
}
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @hbelmiro Thank you for the suggestions. I will test it after making necessary changes. |
||
|
||
private final Map<KubernetesServiceCatalogKey, URI> services = new ConcurrentHashMap<>(); | ||
|
||
@Override | ||
public Optional<URI> getServiceAddress(KubernetesServiceCatalogKey key) { | ||
URI serviceUrl = services.get(key); | ||
|
||
if (serviceUrl == null) { | ||
serviceUrl = fetchServiceAddressFromConfig(key); | ||
services.put(key, serviceUrl); | ||
} | ||
|
||
return Optional.ofNullable(serviceUrl); | ||
} | ||
|
||
private URI fetchServiceAddressFromConfig(KubernetesServiceCatalogKey key) { | ||
try { | ||
Config config = ConfigProvider.getConfig(); | ||
String configValue = config.getValue(key.getProtocol().getValue() + ":" + key.getCoordinates(), String.class); | ||
return new URI(configValue); | ||
} catch (URISyntaxException e) { | ||
e.printStackTrace(); | ||
return null; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright 2023 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed 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.addons.quarkus.microprofile.config.service.catalog; | ||
|
||
import org.kie.kogito.addons.k8s.resource.catalog.KubernetesServiceCatalog; | ||
import org.kie.kogito.addons.k8s.resource.catalog.KubernetesServiceCatalogProvider; | ||
|
||
public class MicroProfileConfigServiceCatalogProvider implements KubernetesServiceCatalogProvider { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't forget to create the ServiceLoader file. Like https://github.com/kiegroup/kogito-runtimes/blob/1c99c7bbe2ec21eba5ac79e4e053c02bd5345a88/quarkus/addons/fabric8-kubernetes-service-catalog/runtime/src/main/resources/META-INF/services/org.kie.kogito.addons.k8s.resource.catalog.KubernetesServiceCatalogProvider. |
||
|
||
@Override | ||
public KubernetesServiceCatalog create() { | ||
return new MicroProfileConfigServiceCatalog(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright 2023 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed 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.addons.quarkus.microprofile.config.service.catalog; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.eclipse.microprofile.config.Config; | ||
import org.eclipse.microprofile.config.ConfigProvider; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.kie.kogito.addons.k8s.resource.catalog.KubernetesServiceCatalogTest; | ||
import org.mockito.MockedStatic; | ||
import org.mockito.Mockito; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import io.quarkus.test.junit.QuarkusTest; | ||
|
||
import static org.kie.kogito.addons.k8s.resource.catalog.KubernetesProtocol.KNATIVE; | ||
import static org.kie.kogito.addons.k8s.resource.catalog.KubernetesProtocol.KUBERNETES; | ||
import static org.kie.kogito.addons.k8s.resource.catalog.KubernetesProtocol.OPENSHIFT; | ||
import static org.mockito.ArgumentMatchers.eq; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
@QuarkusTest | ||
@ExtendWith(MockitoExtension.class) | ||
public class MicroProfileConfigServiceCatalogTest extends KubernetesServiceCatalogTest { | ||
|
||
private static final String KNATIVE_URI = "http://serverless-workflow-greeting-quarkus.test.10.99.154.147.sslip.io"; | ||
private static final String KUBERNETES_URI = "http://serverless-workflow-greeting-quarkus-kubernetes.test.10.99.154.147.sslip.io"; | ||
private static final String OPENSHIFT_URI = "http://serverless-workflow-greeting-quarkus-openshift.test.10.99.154.147.sslip.io"; | ||
|
||
@Inject | ||
private Config config; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
config = mock(Config.class); | ||
try (MockedStatic<ConfigProvider> mockConfigProvider = Mockito.mockStatic(ConfigProvider.class)) { | ||
mockConfigProvider.when(ConfigProvider::getConfig).thenReturn(config); | ||
when(config.getValue(eq(KNATIVE + ":" + getNamespace() + "/" + getKnativeServiceName()), eq(String.class))) | ||
.thenReturn(KNATIVE_URI); | ||
when(config.getValue(eq(KUBERNETES + ":" + getNamespace() + "/" + getKubernetesServiceName()), eq(String.class))) | ||
.thenReturn(KUBERNETES_URI); | ||
when(config.getValue(eq(OPENSHIFT + ":" + getNamespace() + "/" + getKubernetesServiceName()), eq(String.class))) | ||
.thenReturn(OPENSHIFT_URI); | ||
|
||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't need to mock anything. Quarkus will inject the config from |
||
|
||
@Inject | ||
MicroProfileConfigServiceCatalogTest(MicroProfileConfigServiceCatalog configServiceCatalog) { | ||
super(configServiceCatalog); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# | ||
# Copyright 2023 Red Hat, Inc. and/or its affiliates. | ||
# | ||
# Licensed 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. | ||
# | ||
|
||
knative:test/serverless-workflow-greeting-quarkus = http://serverless-workflow-greeting-quarkus.test.10.99.154.147.sslip.io | ||
kubernetes:test/serverless-workflow-greeting-quarkus-kubernetes = http://serverless-workflow-greeting-quarkus-kubernetes.test.10.99.154.147.sslip.io | ||
openshift:test/serverless-workflow-greeting-quarkus-openshift = http://serverless-workflow-greeting-quarkus-openshift.test.10.99.154.147.sslip.io | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Two points to consider:
org.kie.kogito.addons.microprofile-config-service-catalog.catalog.knative\:test\/serverless-workflow-greeting-quarkus = http://serverless-workflow-greeting-quarkus.test.10.99.154.147.sslip.io But they might be too long for env. @ricardozanini WDYT? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's too long, but we won't use envs, but config props. I recommend:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to register these modules in the kogito-bom. Take a look at https://github.com/kiegroup/kogito-runtimes/blob/e37b961eb5fec25b4545a7937b5f067fee331ade/kogito-bom/pom.xml#L318 to use the Fabric8 implementation as a reference.