diff --git a/kogito-bom/pom.xml b/kogito-bom/pom.xml index 9f2b682d33b..e523f44f1ad 100755 --- a/kogito-bom/pom.xml +++ b/kogito-bom/pom.xml @@ -334,6 +334,25 @@ pom + + org.kie.kogito + kogito-addons-quarkus-microprofile-config-service-catalog + ${project.version} + + + org.kie.kogito + kogito-addons-quarkus-microprofile-config-service-catalog + ${project.version} + sources + + + + org.kie.kogito + kogito-addons-quarkus-microprofile-config-service-catalog-deployment + ${project.version} + pom + + org.kie.kogito kogito-addons-quarkus-common-deployment diff --git a/quarkus/addons/microprofile-config-service-catalog/deployment/pom.xml b/quarkus/addons/microprofile-config-service-catalog/deployment/pom.xml new file mode 100644 index 00000000000..472a2b496c9 --- /dev/null +++ b/quarkus/addons/microprofile-config-service-catalog/deployment/pom.xml @@ -0,0 +1,43 @@ + + + 4.0.0 + + org.kie.kogito + kogito-addons-quarkus-microprofile-config-service-catalog-parent + 2.0.0-SNAPSHOT + + + kogito-addons-quarkus-microprofile-config-service-catalog-deployment + Kogito Add-On MicroProfile Config Service Catalog - Deployment + + + + org.kie.kogito + kogito-addons-quarkus-microprofile-config-service-catalog + 2.0.0-SNAPSHOT + + + io.quarkus + quarkus-arc-deployment + + + + + + + maven-compiler-plugin + + + + io.quarkus + quarkus-extension-processor + ${version.io.quarkus} + + + + + + + \ No newline at end of file diff --git a/quarkus/addons/microprofile-config-service-catalog/integration-tests/pom.xml b/quarkus/addons/microprofile-config-service-catalog/integration-tests/pom.xml new file mode 100644 index 00000000000..8994a810e0b --- /dev/null +++ b/quarkus/addons/microprofile-config-service-catalog/integration-tests/pom.xml @@ -0,0 +1,136 @@ + + + 4.0.0 + + org.kie.kogito + kogito-addons-quarkus-microprofile-config-service-catalog-parent + 2.0.0-SNAPSHOT + + + kogito-addons-quarkus-microprofile-config-service-catalog-integration-tests + Kogito Add-On Microprofile Config Service Catalog - Integration Tests + Microprofile Config Service Catalog Kogito Add-On Integration Tests. + + + + + org.kie.kogito + kogito-quarkus-bom + ${project.version} + pom + import + + + + + + + io.quarkus + quarkus-smallrye-openapi + + + org.kie.kogito + kogito-quarkus-serverless-workflow + + + + io.quarkus + quarkus-resteasy + + + io.quarkus + quarkus-resteasy-jackson + + + org.kie.kogito + kogito-addons-quarkus-knative-serving + + + org.kie.kogito + kogito-addons-quarkus-kubernetes + + + org.kie.kogito + kogito-addons-quarkus-fabric8-kubernetes-service-catalog + + + io.quarkus + quarkus-kubernetes + + + + + org.assertj + assertj-core + test + + + io.quarkus + quarkus-junit5 + test + + + io.rest-assured + rest-assured + test + + + com.github.tomakehurst + wiremock-jre8 + test + + + io.quarkus + quarkus-test-kubernetes-client + test + + + org.kie.kogito + kogito-addons-quarkus-fabric8-kubernetes-service-catalog-test-utils + test + + + + + + + + io.quarkus + quarkus-maven-plugin + + true + ${skipTests} + + + + + + + io.quarkus + quarkus-maven-plugin + + + + build + + + + + + + + + native + + + native + + + + native + + + + \ No newline at end of file diff --git a/quarkus/addons/microprofile-config-service-catalog/integration-tests/src/test/java/org/kie/kogito/addons/quarkus/microprofile/config/service/catalog/it/MicroProfileConfigServiceAddonIT.java b/quarkus/addons/microprofile-config-service-catalog/integration-tests/src/test/java/org/kie/kogito/addons/quarkus/microprofile/config/service/catalog/it/MicroProfileConfigServiceAddonIT.java new file mode 100644 index 00000000000..3459d1216ea --- /dev/null +++ b/quarkus/addons/microprofile-config-service-catalog/integration-tests/src/test/java/org/kie/kogito/addons/quarkus/microprofile/config/service/catalog/it/MicroProfileConfigServiceAddonIT.java @@ -0,0 +1,104 @@ +/* + * 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.it; + +import java.net.HttpURLConnection; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import com.fasterxml.jackson.databind.node.JsonNodeFactory; +import com.github.tomakehurst.wiremock.WireMockServer; +import com.github.tomakehurst.wiremock.core.WireMockConfiguration; + +import io.fabric8.kubernetes.client.server.mock.KubernetesServer; +import io.quarkus.test.junit.QuarkusTest; +import io.quarkus.test.kubernetes.client.KubernetesTestServer; +import io.quarkus.test.kubernetes.client.WithKubernetesTestServer; +import io.restassured.http.ContentType; + +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.post; +import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; +import static io.restassured.RestAssured.given; +import static org.hamcrest.CoreMatchers.is; +import static org.kie.kogito.addons.quarkus.k8s.test.utils.KnativeResourceDiscoveryTestUtil.createServiceIfNotExists; + +@QuarkusTest +@WithKubernetesTestServer +class MicroProfileConfigServiceAddonIT { + + private static final String NAMESPACE = "default"; + + private static final String SERVICENAME = "serverless-workflow-greeting-quarkus"; + + private static WireMockServer wireMockServer; + + private static String remoteServiceUrl; + + @KubernetesTestServer + KubernetesServer mockServer; + + @BeforeAll + static void beforeAll() { + createWiremockServer(); + } + + @BeforeEach + void beforeEach() { + createServiceIfNotExists(mockServer, "knative/quarkus-greeting.yaml", NAMESPACE, SERVICENAME, remoteServiceUrl); + } + + @AfterAll + static void afterAll() { + if (wireMockServer != null) { + wireMockServer.stop(); + } + } + + @Test + void executeWithEmptyParameters() { + mockExecuteWithEmptyParametersEndpoint(); + + given() + .contentType(ContentType.JSON) + .accept(ContentType.JSON) + .body("{\"workflowdata\":{}}").when() + .post("/emptyParamsKnativeFunction") + .then() + .statusCode(HttpURLConnection.HTTP_CREATED) + .body("workflowdata.org", is("Acme")) + .body("workflowdata.project", is("Kogito")); + } + + private void mockExecuteWithEmptyParametersEndpoint() { + wireMockServer.stubFor(post(urlEqualTo("/emptyParamsKnativeFunction")) + .willReturn(aResponse() + .withStatus(HttpURLConnection.HTTP_OK) + .withHeader("Content-Type", "application/json") + .withJsonBody(JsonNodeFactory.instance.objectNode() + .put("org", "Acme") + .put("project", "Kogito")))); + } + + private static void createWiremockServer() { + wireMockServer = new WireMockServer(WireMockConfiguration.wireMockConfig().dynamicPort()); + wireMockServer.start(); + remoteServiceUrl = wireMockServer.baseUrl(); + } +} diff --git a/quarkus/addons/microprofile-config-service-catalog/integration-tests/src/test/resources/knative/quarkus-greeting.yaml b/quarkus/addons/microprofile-config-service-catalog/integration-tests/src/test/resources/knative/quarkus-greeting.yaml new file mode 100644 index 00000000000..712d182b28e --- /dev/null +++ b/quarkus/addons/microprofile-config-service-catalog/integration-tests/src/test/resources/knative/quarkus-greeting.yaml @@ -0,0 +1,54 @@ +apiVersion: serving.knative.dev/v1 +kind: Service +metadata: + annotations: + serving.knative.dev/creator: minikube-user + serving.knative.dev/lastModifier: minikube-user + creationTimestamp: '2022-08-17T13:58:53Z' + generation: 1 + name: serverless-workflow-greeting-quarkus + resourceVersion: '43817' + uid: 98530cb6-3274-4d0c-b654-a82645cda058 +spec: + template: + metadata: + annotations: + client.knative.dev/updateTimestamp: '2022-08-17T13:58:53Z' + client.knative.dev/user-image: kiegroup/serverless-workflow-greeting-quarkus:1.0 + creationTimestamp: + spec: + containerConcurrency: 0 + containers: + - image: kiegroup/serverless-workflow-greeting-quarkus:1.0 + name: user-container + readinessProbe: + successThreshold: 1 + tcpSocket: + port: 0 + resources: { } + enableServiceLinks: false + timeoutSeconds: 300 + traffic: + - latestRevision: true + percent: 100 +status: + address: + url: http://serverless-workflow-greeting-quarkus.test.svc.cluster.local + conditions: + - lastTransitionTime: '2022-08-17T13:59:00Z' + status: 'True' + type: ConfigurationsReady + - lastTransitionTime: '2022-08-17T13:59:00Z' + status: 'True' + type: Ready + - lastTransitionTime: '2022-08-17T13:59:00Z' + status: 'True' + type: RoutesReady + latestCreatedRevisionName: serverless-workflow-greeting-quarkus-00001 + latestReadyRevisionName: serverless-workflow-greeting-quarkus-00001 + observedGeneration: 1 + traffic: + - latestRevision: true + percent: 100 + revisionName: serverless-workflow-greeting-quarkus-00001 + url: http://serverless-workflow-greeting-quarkus.test.10.99.154.147.sslip.io diff --git a/quarkus/addons/microprofile-config-service-catalog/pom.xml b/quarkus/addons/microprofile-config-service-catalog/pom.xml new file mode 100644 index 00000000000..8c7f49f1fb9 --- /dev/null +++ b/quarkus/addons/microprofile-config-service-catalog/pom.xml @@ -0,0 +1,21 @@ + + + 4.0.0 + + org.kie.kogito + kogito-addons-quarkus-parent + 2.0.0-SNAPSHOT + + + kogito-addons-quarkus-microprofile-config-service-catalog-parent + Kogito Add-On MicroProfile Config Service Catalog - Parent + pom + + + deployment + runtime + integration-tests + + \ No newline at end of file diff --git a/quarkus/addons/microprofile-config-service-catalog/runtime/pom.xml b/quarkus/addons/microprofile-config-service-catalog/runtime/pom.xml new file mode 100644 index 00000000000..0de7a857aaa --- /dev/null +++ b/quarkus/addons/microprofile-config-service-catalog/runtime/pom.xml @@ -0,0 +1,82 @@ + + + 4.0.0 + + org.kie.kogito + kogito-addons-quarkus-microprofile-config-service-catalog-parent + 2.0.0-SNAPSHOT + + + kogito-addons-quarkus-microprofile-config-service-catalog + Kogito Add-On MicroProfile Config Service Catalog + + + org.kie.kogito + kogito-addons-kubernetes-service-catalog + + + io.quarkus + quarkus-arc + + + io.quarkus + quarkus-junit5 + test + + + org.assertj + assertj-core + test + + + org.eclipse.microprofile.config + microprofile-config-api + + + org.kie.kogito + kogito-addons-kubernetes-service-catalog + ${project.version} + test-jar + test + + + + + + + io.quarkus + quarkus-bootstrap-maven-plugin + ${version.io.quarkus} + + + compile + + extension-descriptor + + + ${project.groupId}:${project.artifactId}-deployment:${project.version} + + + org.kie.kogito.addons.quarkus.microprofile.config.service.catalog + + + + + + + maven-compiler-plugin + + + + io.quarkus + quarkus-extension-processor + ${version.io.quarkus} + + + + + + + \ No newline at end of file diff --git a/quarkus/addons/microprofile-config-service-catalog/runtime/src/main/java/org/kie/kogito/addons/quarkus/microprofile/config/service/catalog/MicroProfileConfigServiceCatalog.java b/quarkus/addons/microprofile-config-service-catalog/runtime/src/main/java/org/kie/kogito/addons/quarkus/microprofile/config/service/catalog/MicroProfileConfigServiceCatalog.java new file mode 100644 index 00000000000..a8f9b350b10 --- /dev/null +++ b/quarkus/addons/microprofile-config-service-catalog/runtime/src/main/java/org/kie/kogito/addons/quarkus/microprofile/config/service/catalog/MicroProfileConfigServiceCatalog.java @@ -0,0 +1,40 @@ +/* + * 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.util.Optional; + +import javax.enterprise.context.ApplicationScoped; +import javax.inject.Inject; + +import org.eclipse.microprofile.config.Config; +import org.kie.kogito.addons.k8s.resource.catalog.KubernetesServiceCatalog; +import org.kie.kogito.addons.k8s.resource.catalog.KubernetesServiceCatalogKey; + +@ApplicationScoped +public class MicroProfileConfigServiceCatalog implements KubernetesServiceCatalog { + + @Inject + Config config; + + @Override + public Optional getServiceAddress(KubernetesServiceCatalogKey key) { + + return config.getOptionalValue(key.getProtocol().getValue() + ":" + key.getCoordinates(), String.class) + .map(URI::create); + } +} diff --git a/quarkus/addons/microprofile-config-service-catalog/runtime/src/main/java/org/kie/kogito/addons/quarkus/microprofile/config/service/catalog/MicroProfileConfigServiceCatalogProvider.java b/quarkus/addons/microprofile-config-service-catalog/runtime/src/main/java/org/kie/kogito/addons/quarkus/microprofile/config/service/catalog/MicroProfileConfigServiceCatalogProvider.java new file mode 100644 index 00000000000..cfc9cfa5678 --- /dev/null +++ b/quarkus/addons/microprofile-config-service-catalog/runtime/src/main/java/org/kie/kogito/addons/quarkus/microprofile/config/service/catalog/MicroProfileConfigServiceCatalogProvider.java @@ -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 { + + @Override + public KubernetesServiceCatalog create() { + return new MicroProfileConfigServiceCatalog(); + } +} \ No newline at end of file diff --git a/quarkus/addons/microprofile-config-service-catalog/runtime/src/main/resources/META-INF/beans.xml b/quarkus/addons/microprofile-config-service-catalog/runtime/src/main/resources/META-INF/beans.xml new file mode 100644 index 00000000000..e69de29bb2d diff --git a/quarkus/addons/microprofile-config-service-catalog/runtime/src/main/resources/META-INF/services/org.kie.kogito.addons.k8s.resource.catalog.KubernetesServiceCatalogProvider b/quarkus/addons/microprofile-config-service-catalog/runtime/src/main/resources/META-INF/services/org.kie.kogito.addons.k8s.resource.catalog.KubernetesServiceCatalogProvider new file mode 100644 index 00000000000..30a60027222 --- /dev/null +++ b/quarkus/addons/microprofile-config-service-catalog/runtime/src/main/resources/META-INF/services/org.kie.kogito.addons.k8s.resource.catalog.KubernetesServiceCatalogProvider @@ -0,0 +1 @@ +org.kie.kogito.addons.quarkus.microprofile.config.service.catalog.MicroProfileConfigServiceCatalogProvider \ No newline at end of file diff --git a/quarkus/addons/microprofile-config-service-catalog/runtime/src/test/java/org/kie/kogito/addons/quarkus/microprofile/config/service/catalog/MicroProfileConfigServiceCatalogTest.java b/quarkus/addons/microprofile-config-service-catalog/runtime/src/test/java/org/kie/kogito/addons/quarkus/microprofile/config/service/catalog/MicroProfileConfigServiceCatalogTest.java new file mode 100644 index 00000000000..28f7abe736e --- /dev/null +++ b/quarkus/addons/microprofile-config-service-catalog/runtime/src/test/java/org/kie/kogito/addons/quarkus/microprofile/config/service/catalog/MicroProfileConfigServiceCatalogTest.java @@ -0,0 +1,32 @@ +/* + * 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.kie.kogito.addons.k8s.resource.catalog.KubernetesServiceCatalogTest; + +import io.quarkus.test.junit.QuarkusTest; + +@QuarkusTest +public class MicroProfileConfigServiceCatalogTest extends KubernetesServiceCatalogTest { + + @Inject + MicroProfileConfigServiceCatalogTest(MicroProfileConfigServiceCatalog configServiceCatalog) { + super(configServiceCatalog); + } + +} diff --git a/quarkus/addons/microprofile-config-service-catalog/runtime/src/test/resources/application.properties b/quarkus/addons/microprofile-config-service-catalog/runtime/src/test/resources/application.properties new file mode 100644 index 00000000000..a578fc6c5f6 --- /dev/null +++ b/quarkus/addons/microprofile-config-service-catalog/runtime/src/test/resources/application.properties @@ -0,0 +1,26 @@ +# +# 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\:serverless-workflow-greeting-quarkus = http\:\/\/serverless-workflow-greeting-quarkus.test.10.99.154.147.sslip.io +knative\:test\/serverless-workflow-greeting-quarkus = http\:\/\/serverless-workflow-greeting-quarkus.test.10.99.154.147.sslip.io +knative\:services.v1.serving.knative.dev\/serverless-workflow-greeting-quarkus = http\:\/\/serverless-workflow-greeting-quarkus.test.10.99.154.147.sslip.io +knative\:services.v1.serving.knative.dev\/test\/serverless-workflow-greeting-quarkus = http\:\/\/serverless-workflow-greeting-quarkus.test.10.99.154.147.sslip.io + +kubernetes\:services.v1.serving.knative.dev\/serverless-workflow-greeting-quarkus-kubernetes = http\:\/\/serverless-workflow-greeting-quarkus-kubernetes.test.10.99.154.147.sslip.io +kubernetes\:services.v1.serving.knative.dev\/test\/serverless-workflow-greeting-quarkus-kubernetes = http\:\/\/serverless-workflow-greeting-quarkus-kubernetes.test.10.99.154.147.sslip.io + +openshift\:services.v1.serving.knative.dev\/serverless-workflow-greeting-quarkus-openshift = http\:\/\/serverless-workflow-greeting-quarkus-openshift.test.10.99.154.147.sslip.io +openshift\:services.v1.serving.knative.dev\/test\/serverless-workflow-greeting-quarkus-openshift = http\:\/\/serverless-workflow-greeting-quarkus-openshift.test.10.99.154.147.sslip.io diff --git a/quarkus/addons/pom.xml b/quarkus/addons/pom.xml index e125737dff6..8091fa6b789 100644 --- a/quarkus/addons/pom.xml +++ b/quarkus/addons/pom.xml @@ -27,6 +27,7 @@ events camel fabric8-kubernetes-service-catalog + microprofile-config-service-catalog jobs