This is an automated email from the ASF dual-hosted git repository.
wmedvedeo pushed a commit to branch main
in repository
https://gitbox.apache.org/repos/asf/incubator-kie-kogito-runtimes.git
The following commit(s) were added to refs/heads/main by this push:
new 6322ddd0ea Microprofile Config Service Catalog Addon throws exception
at address resolution (#3278)
6322ddd0ea is described below
commit 6322ddd0ea6eff54185c815b79c1e87ac7b4a915
Author: Walter Medvedeo <[email protected]>
AuthorDate: Wed Nov 8 18:47:35 2023 +0100
Microprofile Config Service Catalog Addon throws exception at address
resolution (#3278)
* kie-issues_680: Microprofile Config Service Catalog Addon throws
exception at address resolution
* Code review suggetions 1
---
.../kie/kogito/internal/utils/ConversionUtils.java | 55 +++++++++++++++++++---
.../canonical/descriptors/ExpressionUtils.java | 2 +-
quarkus/addons/knative/serving/deployment/pom.xml | 17 +++++++
.../KogitoAddonKnativeServingProcessor.java | 52 ++++++++++++++++++++
.../KogitoAddonKnativeServingProcessorTest.java | 45 ++++++++++++++++++
.../resources/application.properties | 0
.../it/MicroProfileConfigServiceAddonIT.java | 4 +-
.../catalog/MicroProfileConfigServiceCatalog.java | 11 ++---
8 files changed, 168 insertions(+), 18 deletions(-)
diff --git
a/api/kogito-api/src/main/java/org/kie/kogito/internal/utils/ConversionUtils.java
b/api/kogito-api/src/main/java/org/kie/kogito/internal/utils/ConversionUtils.java
index ef750c4120..42a1eb7cb0 100644
---
a/api/kogito-api/src/main/java/org/kie/kogito/internal/utils/ConversionUtils.java
+++
b/api/kogito-api/src/main/java/org/kie/kogito/internal/utils/ConversionUtils.java
@@ -43,7 +43,7 @@ public class ConversionUtils {
/**
* Converts a string into a list of objects using `,` as a separator
- *
+ *
* @param <T>
* @param value object to be converted into list
* @param clazz the item target class
@@ -55,7 +55,7 @@ public class ConversionUtils {
/**
* Converts a string into a list of objects
- *
+ *
* @param <T>
* @param value object to be converted into list
* @param clazz the item target class
@@ -71,7 +71,7 @@ public class ConversionUtils {
/**
* Converts an object to an instance of the provided class
- *
+ *
* @param <T>
* @param value
* @param clazz
@@ -81,6 +81,8 @@ public class ConversionUtils {
public static <T> T convert(Object value, Class<T> clazz, Function<Object,
String> stringConverter) {
if (value == null || clazz.isAssignableFrom(value.getClass())) {
return clazz.cast(value);
+ } else if (isConvertibleFromStringJavaBaseType(clazz)) {
+ return convertFromStringJavaBaseType(clazz,
stringConverter.apply(value));
} else {
Method convert = getConvertMethod(clazz);
if (convert != null) {
@@ -114,9 +116,48 @@ public class ConversionUtils {
return null;
}
+ /**
+ * @return true if the given type corresponds to a java base type that has
the method valueOf(String value).
+ */
+ private static boolean isConvertibleFromStringJavaBaseType(Class<?> clazz)
{
+ return clazz == Short.class || clazz == Integer.class || clazz ==
Long.class || clazz == Byte.class ||
+ clazz == Float.class || clazz == Double.class ||
+ clazz == Boolean.class;
+ }
+
+ /**
+ * @return the value created by applying the static method valueOf(String)
on the given class. We use this method on
+ * these base java types to ensure conversion continues working on
code generated by the quarkus native build,
+ * since it was detected that valueOf is not discovered by
reflection on these classes after the native build.
+ */
+ private static <T> T convertFromStringJavaBaseType(Class<T> clazz, String
value) throws NumberFormatException {
+ if (clazz == Short.class) {
+ return (T) Short.valueOf(value);
+ }
+ if (clazz == Integer.class) {
+ return (T) Integer.valueOf(value);
+ }
+ if (clazz == Long.class) {
+ return (T) Long.valueOf(value);
+ }
+ if (clazz == Byte.class) {
+ return (T) Byte.valueOf(value);
+ }
+ if (clazz == Float.class) {
+ return (T) Float.valueOf(value);
+ }
+ if (clazz == Double.class) {
+ return (T) Double.valueOf(value);
+ }
+ if (clazz == Boolean.class) {
+ return (T) Boolean.valueOf(value);
+ }
+ throw new IllegalArgumentException("This method can not be applied to
this class: " + clazz);
+ }
+
/**
* Convert to camel case
- *
+ *
* @param text
* @return
*/
@@ -147,7 +188,7 @@ public class ConversionUtils {
/**
* Concatenate two paths using / as separator
- *
+ *
* @param onePath
* @param anotherPath
* @return
@@ -158,7 +199,7 @@ public class ConversionUtils {
/**
* Concatenate two paths using a separator
- *
+ *
* @param onePath
* @param anotherPath
* @param concatChars separator to use
@@ -182,7 +223,7 @@ public class ConversionUtils {
/**
* Check empty string
- *
+ *
* @param value
* @return
*/
diff --git
a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/descriptors/ExpressionUtils.java
b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/descriptors/ExpressionUtils.java
index 163e6d005f..f810334326 100644
---
a/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/descriptors/ExpressionUtils.java
+++
b/jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/descriptors/ExpressionUtils.java
@@ -108,7 +108,7 @@ public class ExpressionUtils {
} else if (object instanceof Character) {
return new CharLiteralExpr(((Character) object));
} else if (object instanceof Long) {
- return new LongLiteralExpr(object.toString());
+ return new LongLiteralExpr(object + "L");
} else if (object instanceof Integer || object instanceof Short) {
return new IntegerLiteralExpr(object.toString());
} else if (object instanceof BigInteger) {
diff --git a/quarkus/addons/knative/serving/deployment/pom.xml
b/quarkus/addons/knative/serving/deployment/pom.xml
index 129e5bcf3c..576dea893b 100644
--- a/quarkus/addons/knative/serving/deployment/pom.xml
+++ b/quarkus/addons/knative/serving/deployment/pom.xml
@@ -53,6 +53,23 @@
<groupId>org.kie.kogito</groupId>
<artifactId>kogito-serverless-workflow-rest-parser</artifactId>
</dependency>
+
+ <!-- Testing dependencies -->
+ <dependency>
+ <groupId>org.assertj</groupId>
+ <artifactId>assertj-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <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>
</dependencies>
<build>
diff --git
a/quarkus/addons/knative/serving/deployment/src/main/java/org/kie/kogito/addons/quarkus/knative/serving/deployment/KogitoAddonKnativeServingProcessor.java
b/quarkus/addons/knative/serving/deployment/src/main/java/org/kie/kogito/addons/quarkus/knative/serving/deployment/KogitoAddonKnativeServingProcessor.java
new file mode 100644
index 0000000000..f11134f5bd
--- /dev/null
+++
b/quarkus/addons/knative/serving/deployment/src/main/java/org/kie/kogito/addons/quarkus/knative/serving/deployment/KogitoAddonKnativeServingProcessor.java
@@ -0,0 +1,52 @@
+/*
+ * 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.addons.quarkus.knative.serving.deployment;
+
+import
org.kie.kogito.addons.quarkus.knative.serving.customfunctions.CloudEventKnativeParamsDecorator;
+import
org.kie.kogito.addons.quarkus.knative.serving.customfunctions.PlainJsonKnativeParamsDecorator;
+import org.kie.kogito.quarkus.addons.common.deployment.KogitoCapability;
+import
org.kie.kogito.quarkus.addons.common.deployment.OneOfCapabilityKogitoAddOnProcessor;
+
+import io.quarkus.deployment.annotations.BuildStep;
+import io.quarkus.deployment.builditem.FeatureBuildItem;
+import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
+
+public class KogitoAddonKnativeServingProcessor extends
OneOfCapabilityKogitoAddOnProcessor {
+
+ static final String FEATURE = "kogito-addons-quarkus-knative-serving";
+
+ @BuildStep
+ FeatureBuildItem feature() {
+ return new FeatureBuildItem(FEATURE);
+ }
+
+ KogitoAddonKnativeServingProcessor() {
+ super(KogitoCapability.SERVERLESS_WORKFLOW);
+ }
+
+ @BuildStep
+ public ReflectiveClassBuildItem reflectiveClasses() {
+ return new ReflectiveClassBuildItem(true,
+ true,
+ true,
+ CloudEventKnativeParamsDecorator.class,
PlainJsonKnativeParamsDecorator.class);
+ }
+
+}
diff --git
a/quarkus/addons/knative/serving/deployment/src/test/java/org/kie/kogito/addons/quarkus/knative/serving/deployment/KogitoAddonKnativeServingProcessorTest.java
b/quarkus/addons/knative/serving/deployment/src/test/java/org/kie/kogito/addons/quarkus/knative/serving/deployment/KogitoAddonKnativeServingProcessorTest.java
new file mode 100644
index 0000000000..f76c2d3edd
--- /dev/null
+++
b/quarkus/addons/knative/serving/deployment/src/test/java/org/kie/kogito/addons/quarkus/knative/serving/deployment/KogitoAddonKnativeServingProcessorTest.java
@@ -0,0 +1,45 @@
+/*
+ * 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.addons.quarkus.knative.serving.deployment;
+
+import org.junit.jupiter.api.Test;
+import
org.kie.kogito.addons.quarkus.knative.serving.customfunctions.CloudEventKnativeParamsDecorator;
+import
org.kie.kogito.addons.quarkus.knative.serving.customfunctions.PlainJsonKnativeParamsDecorator;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+class KogitoAddonKnativeServingProcessorTest {
+
+ private final KogitoAddonKnativeServingProcessor processor = new
KogitoAddonKnativeServingProcessor();
+
+ @Test
+ void feature() {
+ assertThat(processor.feature()).isNotNull();
+
assertThat(processor.feature().getName()).isEqualTo(KogitoAddonKnativeServingProcessor.FEATURE);
+ }
+
+ @Test
+ void reflectiveClasses() {
+ assertThat(processor.reflectiveClasses()).isNotNull();
+ assertThat(processor.reflectiveClasses().getClassNames())
+
.containsExactlyInAnyOrder(CloudEventKnativeParamsDecorator.class.getName(),
+ PlainJsonKnativeParamsDecorator.class.getName());
+ }
+}
diff --git
a/quarkus/addons/microprofile-config-service-catalog/integration-tests/src/test/resources/application.properties
b/quarkus/addons/microprofile-config-service-catalog/integration-tests/src/main/resources/application.properties
similarity index 100%
rename from
quarkus/addons/microprofile-config-service-catalog/integration-tests/src/test/resources/application.properties
rename to
quarkus/addons/microprofile-config-service-catalog/integration-tests/src/main/resources/application.properties
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
index 40ad0aa825..5a4b5bc4d7 100644
---
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
@@ -23,13 +23,13 @@ import java.net.HttpURLConnection;
import org.junit.jupiter.api.Test;
import io.quarkus.test.common.QuarkusTestResource;
-import io.quarkus.test.junit.QuarkusTest;
+import io.quarkus.test.junit.QuarkusIntegrationTest;
import io.restassured.http.ContentType;
import static io.restassured.RestAssured.given;
import static org.hamcrest.CoreMatchers.is;
-@QuarkusTest
+@QuarkusIntegrationTest
@QuarkusTestResource(ServiceMock.class)
class MicroProfileConfigServiceAddonIT {
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
index dcfd4eb51f..362a3fcd16 100644
---
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
@@ -22,9 +22,8 @@ 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.eclipse.microprofile.config.ConfigProvider;
import org.kie.kogito.addons.k8s.resource.catalog.KubernetesServiceCatalog;
import org.kie.kogito.addons.k8s.resource.catalog.KubernetesServiceCatalogKey;
@@ -33,13 +32,9 @@ public class MicroProfileConfigServiceCatalog implements
KubernetesServiceCatalo
private static final String CONFIG_PREFIX =
"org.kie.kogito.addons.discovery.";
- @Inject
- Config config;
-
@Override
public Optional<URI> getServiceAddress(KubernetesServiceCatalogKey key) {
-
- return config.getOptionalValue(CONFIG_PREFIX +
key.getProtocol().getValue() + ":" + key.getCoordinates(), String.class)
- .map(URI::create);
+ return ConfigProvider.getConfig()
+ .getOptionalValue(CONFIG_PREFIX + key.getProtocol().getValue()
+ ":" + key.getCoordinates(), String.class).map(URI::create);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]