From 2d422a7c5776ab9266e4b37024bd2a870811816b Mon Sep 17 00:00:00 2001 From: Luca Burgazzoli Date: Mon, 26 Oct 2020 12:28:55 +0100 Subject: [PATCH] Can't set Knative broker name #535 --- .../camel/component/knative/spi/Knative.java | 1 + .../knative/http/KnativeHttpTest.java | 43 +++++++++++++++---- .../knative/KnativeComponentConfigurer.java | 13 +++--- .../knative/KnativeEndpointConfigurer.java | 10 ++--- .../camel/component/knative/knative.json | 11 ++--- .../knative/KnativeConfiguration.java | 23 +++++++--- .../component/knative/KnativeEndpoint.java | 23 ++++++---- .../ce/AbstractCloudEventProcessor.java | 6 +-- 8 files changed, 88 insertions(+), 42 deletions(-) diff --git a/components/camel-knative/camel-knative-api/src/main/java/org/apache/camel/component/knative/spi/Knative.java b/components/camel-knative/camel-knative-api/src/main/java/org/apache/camel/component/knative/spi/Knative.java index dea93d9bf..18248aff7 100644 --- a/components/camel-knative/camel-knative-api/src/main/java/org/apache/camel/component/knative/spi/Knative.java +++ b/components/camel-knative/camel-knative-api/src/main/java/org/apache/camel/component/knative/spi/Knative.java @@ -28,6 +28,7 @@ public final class Knative { public static final String KNATIVE_TYPE = "knative.type"; public static final String KNATIVE_EVENT_TYPE = "knative.event.type"; public static final String KNATIVE_KIND = "knative.kind"; + public static final String KNATIVE_NAME = "knative.name"; public static final String KNATIVE_API_VERSION = "knative.apiVersion"; public static final String KNATIVE_REPLY = "knative.reply"; public static final String CONTENT_TYPE = "content.type"; diff --git a/components/camel-knative/camel-knative-http/src/test/java/org/apache/camel/component/knative/http/KnativeHttpTest.java b/components/camel-knative/camel-knative-http/src/test/java/org/apache/camel/component/knative/http/KnativeHttpTest.java index 8b1a1638a..fbb276cf1 100644 --- a/components/camel-knative/camel-knative-http/src/test/java/org/apache/camel/component/knative/http/KnativeHttpTest.java +++ b/components/camel-knative/camel-knative-http/src/test/java/org/apache/camel/component/knative/http/KnativeHttpTest.java @@ -38,6 +38,7 @@ import org.apache.camel.RuntimeCamelException; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.knative.KnativeComponent; +import org.apache.camel.component.knative.KnativeEndpoint; import org.apache.camel.component.knative.spi.CloudEvent; import org.apache.camel.component.knative.spi.CloudEvents; import org.apache.camel.component.knative.spi.Knative; @@ -1061,7 +1062,7 @@ void testEvents(CloudEvent ce) throws Exception { @ParameterizedTest @EnumSource(CloudEvents.class) - void testEventsWithTypeAndVersion(CloudEvent ce) throws Exception { + void testEventsWithResourceRef(CloudEvent ce) throws Exception { configureKnativeComponent( context, ce, @@ -1073,7 +1074,8 @@ void testEventsWithTypeAndVersion(CloudEvent ce) throws Exception { Knative.KNATIVE_EVENT_TYPE, "org.apache.camel.event", Knative.CONTENT_TYPE, "text/plain", Knative.KNATIVE_KIND, "MyObject", - Knative.KNATIVE_API_VERSION, "v1" + Knative.KNATIVE_API_VERSION, "v1", + Knative.KNATIVE_NAME, "myName1" )), sourceEvent( "default", @@ -1081,19 +1083,33 @@ void testEventsWithTypeAndVersion(CloudEvent ce) throws Exception { Knative.KNATIVE_EVENT_TYPE, "org.apache.camel.event", Knative.CONTENT_TYPE, "text/plain", Knative.KNATIVE_KIND, "MyOtherObject", - Knative.KNATIVE_API_VERSION, "v2" + Knative.KNATIVE_API_VERSION, "v2", + Knative.KNATIVE_NAME, "myName2" )) ); RouteBuilder.addRoutes(context, b -> { b.from("direct:source") - .to("knative:event/myEvent?kind=MyObject&apiVersion=v1"); - b.from("knative:event/myEvent?kind=MyOtherObject&apiVersion=v2") + .to("knative:event/myEvent?kind=MyObject&apiVersion=v1&name=myName1"); + b.from("knative:event/myEvent?kind=MyOtherObject&apiVersion=v2&name=myName2") .to("mock:ce"); }); context.start(); + assertThat(context.getEndpoint("knative:event/myEvent?kind=MyObject&apiVersion=v1&name=myName1", KnativeEndpoint.class)).satisfies(e -> { + assertThat(e.getType()).isEqualTo(Knative.Type.event); + assertThat(e.getTypeId()).isEqualTo("myEvent"); + assertThat(e.getConfiguration().getTypeId()).isEqualTo("myEvent"); + assertThat(e.getConfiguration().getName()).isEqualTo("myName1"); + }); + assertThat(context.getEndpoint("knative:event/myEvent?kind=MyOtherObject&apiVersion=v2&name=myName2", KnativeEndpoint.class)).satisfies(e -> { + assertThat(e.getType()).isEqualTo(Knative.Type.event); + assertThat(e.getTypeId()).isEqualTo("myEvent"); + assertThat(e.getConfiguration().getTypeId()).isEqualTo("myEvent"); + assertThat(e.getConfiguration().getName()).isEqualTo("myName2"); + }); + MockEndpoint mock = context.getEndpoint("mock:ce", MockEndpoint.class); mock.expectedHeaderReceived(CloudEvent.CAMEL_CLOUD_EVENT_VERSION, ce.version()); mock.expectedHeaderReceived(CloudEvent.CAMEL_CLOUD_EVENT_TYPE, "myEvent"); @@ -1110,7 +1126,7 @@ void testEventsWithTypeAndVersion(CloudEvent ce) throws Exception { @ParameterizedTest @EnumSource(CloudEvents.class) - void testConsumeContentWithTypeAndVersion(CloudEvent ce) throws Exception { + void testConsumeContentWithResourceRef(CloudEvent ce) throws Exception { configureKnativeComponent( context, ce, @@ -1120,7 +1136,8 @@ void testConsumeContentWithTypeAndVersion(CloudEvent ce) throws Exception { Knative.KNATIVE_EVENT_TYPE, "org.apache.camel.event", Knative.CONTENT_TYPE, "text/plain", Knative.KNATIVE_KIND, "MyObject", - Knative.KNATIVE_API_VERSION, "v1" + Knative.KNATIVE_API_VERSION, "v1", + Knative.KNATIVE_NAME, "myName1" )), sourceEndpoint( "myEndpoint", @@ -1128,17 +1145,25 @@ void testConsumeContentWithTypeAndVersion(CloudEvent ce) throws Exception { Knative.KNATIVE_EVENT_TYPE, "org.apache.camel.event", Knative.CONTENT_TYPE, "text/plain", Knative.KNATIVE_KIND, "MyObject", - Knative.KNATIVE_API_VERSION, "v2" + Knative.KNATIVE_API_VERSION, "v2", + Knative.KNATIVE_NAME, "myName2" )) ); RouteBuilder.addRoutes(context, b -> { - b.from("knative:endpoint/myEndpoint?kind=MyObject&apiVersion=v2") + b.from("knative:endpoint/myEndpoint?kind=MyObject&apiVersion=v2&name=myName2") .to("mock:ce"); }); context.start(); + assertThat(context.getEndpoint("knative:endpoint/myEndpoint?kind=MyObject&apiVersion=v2&name=myName2", KnativeEndpoint.class)).satisfies(e -> { + assertThat(e.getType()).isEqualTo(Knative.Type.endpoint); + assertThat(e.getTypeId()).isEqualTo("myEndpoint"); + assertThat(e.getConfiguration().getTypeId()).isEqualTo("myEndpoint"); + assertThat(e.getConfiguration().getName()).isEqualTo("myName2"); + }); + MockEndpoint mock = context.getEndpoint("mock:ce", MockEndpoint.class); mock.expectedHeaderReceived(CloudEvent.CAMEL_CLOUD_EVENT_VERSION, ce.version()); mock.expectedHeaderReceived(CloudEvent.CAMEL_CLOUD_EVENT_TYPE, "org.apache.camel.event"); diff --git a/components/camel-knative/camel-knative/src/generated/java/org/apache/camel/component/knative/KnativeComponentConfigurer.java b/components/camel-knative/camel-knative/src/generated/java/org/apache/camel/component/knative/KnativeComponentConfigurer.java index cd042ced6..b64e4821f 100644 --- a/components/camel-knative/camel-knative/src/generated/java/org/apache/camel/component/knative/KnativeComponentConfigurer.java +++ b/components/camel-knative/camel-knative/src/generated/java/org/apache/camel/component/knative/KnativeComponentConfigurer.java @@ -25,9 +25,9 @@ public class KnativeComponentConfigurer extends PropertyConfigurerSupport implem map.put("environment", org.apache.camel.component.knative.spi.KnativeEnvironment.class); map.put("environmentPath", java.lang.String.class); map.put("filters", java.util.Map.class); - map.put("serviceName", java.lang.String.class); map.put("transport", org.apache.camel.component.knative.spi.KnativeTransport.class); map.put("transportOptions", java.util.Map.class); + map.put("typeId", java.lang.String.class); map.put("bridgeErrorHandler", boolean.class); map.put("replyWithCloudEvent", boolean.class); map.put("reply", java.lang.Boolean.class); @@ -35,6 +35,7 @@ public class KnativeComponentConfigurer extends PropertyConfigurerSupport implem map.put("apiVersion", java.lang.String.class); map.put("basicPropertyBinding", boolean.class); map.put("kind", java.lang.String.class); + map.put("name", java.lang.String.class); ALL_OPTIONS = map; } @@ -69,14 +70,15 @@ public boolean configure(CamelContext camelContext, Object obj, String name, Obj case "kind": getOrCreateConfiguration(target).setKind(property(camelContext, java.lang.String.class, value)); return true; case "lazystartproducer": case "lazyStartProducer": target.setLazyStartProducer(property(camelContext, boolean.class, value)); return true; + case "name": getOrCreateConfiguration(target).setName(property(camelContext, java.lang.String.class, value)); return true; case "reply": getOrCreateConfiguration(target).setReply(property(camelContext, java.lang.Boolean.class, value)); return true; case "replywithcloudevent": case "replyWithCloudEvent": getOrCreateConfiguration(target).setReplyWithCloudEvent(property(camelContext, boolean.class, value)); return true; - case "servicename": - case "serviceName": getOrCreateConfiguration(target).setServiceName(property(camelContext, java.lang.String.class, value)); return true; case "transport": target.setTransport(property(camelContext, org.apache.camel.component.knative.spi.KnativeTransport.class, value)); return true; case "transportoptions": case "transportOptions": getOrCreateConfiguration(target).setTransportOptions(property(camelContext, java.util.Map.class, value)); return true; + case "typeid": + case "typeId": getOrCreateConfiguration(target).setTypeId(property(camelContext, java.lang.String.class, value)); return true; default: return false; } } @@ -110,14 +112,15 @@ public Object getOptionValue(Object obj, String name, boolean ignoreCase) { case "kind": return getOrCreateConfiguration(target).getKind(); case "lazystartproducer": case "lazyStartProducer": return target.isLazyStartProducer(); + case "name": return getOrCreateConfiguration(target).getName(); case "reply": return getOrCreateConfiguration(target).getReply(); case "replywithcloudevent": case "replyWithCloudEvent": return getOrCreateConfiguration(target).isReplyWithCloudEvent(); - case "servicename": - case "serviceName": return getOrCreateConfiguration(target).getServiceName(); case "transport": return target.getTransport(); case "transportoptions": case "transportOptions": return getOrCreateConfiguration(target).getTransportOptions(); + case "typeid": + case "typeId": return getOrCreateConfiguration(target).getTypeId(); default: return null; } } diff --git a/components/camel-knative/camel-knative/src/generated/java/org/apache/camel/component/knative/KnativeEndpointConfigurer.java b/components/camel-knative/camel-knative/src/generated/java/org/apache/camel/component/knative/KnativeEndpointConfigurer.java index 0e2d5be31..c0cfe9b84 100644 --- a/components/camel-knative/camel-knative/src/generated/java/org/apache/camel/component/knative/KnativeEndpointConfigurer.java +++ b/components/camel-knative/camel-knative/src/generated/java/org/apache/camel/component/knative/KnativeEndpointConfigurer.java @@ -19,13 +19,12 @@ public class KnativeEndpointConfigurer extends PropertyConfigurerSupport impleme static { Map map = new CaseInsensitiveMap(); map.put("type", org.apache.camel.component.knative.spi.Knative.Type.class); - map.put("name", java.lang.String.class); + map.put("typeId", java.lang.String.class); map.put("ceOverride", java.util.Map.class); map.put("cloudEventsSpecVersion", java.lang.String.class); map.put("cloudEventsType", java.lang.String.class); map.put("environment", org.apache.camel.component.knative.spi.KnativeEnvironment.class); map.put("filters", java.util.Map.class); - map.put("serviceName", java.lang.String.class); map.put("transportOptions", java.util.Map.class); map.put("bridgeErrorHandler", boolean.class); map.put("replyWithCloudEvent", boolean.class); @@ -36,6 +35,7 @@ public class KnativeEndpointConfigurer extends PropertyConfigurerSupport impleme map.put("apiVersion", java.lang.String.class); map.put("basicPropertyBinding", boolean.class); map.put("kind", java.lang.String.class); + map.put("name", java.lang.String.class); map.put("synchronous", boolean.class); ALL_OPTIONS = map; } @@ -65,11 +65,10 @@ public boolean configure(CamelContext camelContext, Object obj, String name, Obj case "kind": target.getConfiguration().setKind(property(camelContext, java.lang.String.class, value)); return true; case "lazystartproducer": case "lazyStartProducer": target.setLazyStartProducer(property(camelContext, boolean.class, value)); return true; + case "name": target.getConfiguration().setName(property(camelContext, java.lang.String.class, value)); return true; case "reply": target.getConfiguration().setReply(property(camelContext, java.lang.Boolean.class, value)); return true; case "replywithcloudevent": case "replyWithCloudEvent": target.getConfiguration().setReplyWithCloudEvent(property(camelContext, boolean.class, value)); return true; - case "servicename": - case "serviceName": target.getConfiguration().setServiceName(property(camelContext, java.lang.String.class, value)); return true; case "synchronous": target.setSynchronous(property(camelContext, boolean.class, value)); return true; case "transportoptions": case "transportOptions": target.getConfiguration().setTransportOptions(property(camelContext, java.util.Map.class, value)); return true; @@ -107,11 +106,10 @@ public Object getOptionValue(Object obj, String name, boolean ignoreCase) { case "kind": return target.getConfiguration().getKind(); case "lazystartproducer": case "lazyStartProducer": return target.isLazyStartProducer(); + case "name": return target.getConfiguration().getName(); case "reply": return target.getConfiguration().getReply(); case "replywithcloudevent": case "replyWithCloudEvent": return target.getConfiguration().isReplyWithCloudEvent(); - case "servicename": - case "serviceName": return target.getConfiguration().getServiceName(); case "synchronous": return target.isSynchronous(); case "transportoptions": case "transportOptions": return target.getConfiguration().getTransportOptions(); diff --git a/components/camel-knative/camel-knative/src/generated/resources/org/apache/camel/component/knative/knative.json b/components/camel-knative/camel-knative/src/generated/resources/org/apache/camel/component/knative/knative.json index c859f0b95..5793530a4 100644 --- a/components/camel-knative/camel-knative/src/generated/resources/org/apache/camel/component/knative/knative.json +++ b/components/camel-knative/camel-knative/src/generated/resources/org/apache/camel/component/knative/knative.json @@ -14,7 +14,7 @@ "version": "1.6.0-SNAPSHOT", "scheme": "knative", "extendsScheme": "", - "syntax": "knative:type\/name", + "syntax": "knative:type\/typeId", "async": false, "api": false, "consumerOnly": false, @@ -29,26 +29,26 @@ "environment": { "kind": "property", "displayName": "Environment", "group": "common", "label": "", "required": false, "type": "object", "javaType": "org.apache.camel.component.knative.spi.KnativeEnvironment", "deprecated": false, "secret": false, "configurationClass": "org.apache.camel.component.knative.KnativeConfiguration", "configurationField": "configuration", "description": "The environment" }, "environmentPath": { "kind": "property", "displayName": "Environment Path", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "secret": false, "description": "The path ot the environment definition" }, "filters": { "kind": "property", "displayName": "Filters", "group": "common", "label": "", "required": false, "type": "object", "javaType": "java.util.Map", "prefix": "filter.", "deprecated": false, "secret": false, "configurationClass": "org.apache.camel.component.knative.KnativeConfiguration", "configurationField": "configuration", "description": "Set the filters." }, - "serviceName": { "kind": "property", "displayName": "Service Name", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "secret": false, "configurationClass": "org.apache.camel.component.knative.KnativeConfiguration", "configurationField": "configuration", "description": "The name of the service to lookup from the KnativeEnvironment." }, "transport": { "kind": "property", "displayName": "Transport", "group": "common", "label": "", "required": false, "type": "object", "javaType": "org.apache.camel.component.knative.spi.KnativeTransport", "deprecated": false, "secret": false, "description": "The transport implementation." }, "transportOptions": { "kind": "property", "displayName": "Transport Options", "group": "common", "label": "", "required": false, "type": "object", "javaType": "java.util.Map", "prefix": "transport.", "deprecated": false, "secret": false, "configurationClass": "org.apache.camel.component.knative.KnativeConfiguration", "configurationField": "configuration", "description": "Set the transport options." }, + "typeId": { "kind": "property", "displayName": "Type Id", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "secret": false, "configurationClass": "org.apache.camel.component.knative.KnativeConfiguration", "configurationField": "configuration", "description": "The name of the service to lookup from the KnativeEnvironment." }, "bridgeErrorHandler": { "kind": "property", "displayName": "Bridge Error Handler", "group": "consumer", "label": "consumer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, "defaultValue": false, "description": "Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored." }, "replyWithCloudEvent": { "kind": "property", "displayName": "Reply With Cloud Event", "group": "consumer", "label": "consumer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.knative.KnativeConfiguration", "configurationField": "configuration", "description": "Transforms the reply into a cloud event that will be processed by the caller. When listening to events from a Knative Broker, if this flag is enabled, replies will be published to the same Broker where the request comes from (beware that if you don't change the type of the received message, you may create a loop and receive your same reply). When this flag is disabled, CloudEvent headers are removed from the reply." }, "reply": { "kind": "property", "displayName": "Reply", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "secret": false, "defaultValue": "true", "configurationClass": "org.apache.camel.component.knative.KnativeConfiguration", "configurationField": "configuration", "description": "If the consumer should construct a full reply to knative request." }, "lazyStartProducer": { "kind": "property", "displayName": "Lazy Start Producer", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel's routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing." }, "apiVersion": { "kind": "property", "displayName": "Api Version", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "secret": false, "configurationClass": "org.apache.camel.component.knative.KnativeConfiguration", "configurationField": "configuration", "description": "The version of the k8s resource referenced by the endpoint." }, "basicPropertyBinding": { "kind": "property", "displayName": "Basic Property Binding", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": true, "secret": false, "defaultValue": false, "description": "Whether the component should use basic property binding (Camel 2.x) or the newer property binding with additional capabilities" }, - "kind": { "kind": "property", "displayName": "Kind", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "secret": false, "configurationClass": "org.apache.camel.component.knative.KnativeConfiguration", "configurationField": "configuration", "description": "The type of the k8s resource referenced by the endpoint." } + "kind": { "kind": "property", "displayName": "Kind", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "secret": false, "configurationClass": "org.apache.camel.component.knative.KnativeConfiguration", "configurationField": "configuration", "description": "The type of the k8s resource referenced by the endpoint." }, + "name": { "kind": "property", "displayName": "Name", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "secret": false, "configurationClass": "org.apache.camel.component.knative.KnativeConfiguration", "configurationField": "configuration", "description": "The name of the k8s resource referenced by the endpoint." } }, "properties": { "type": { "kind": "path", "displayName": "Type", "group": "common", "label": "", "required": false, "type": "object", "javaType": "org.apache.camel.component.knative.spi.Knative.Type", "enum": [ "endpoint", "channel", "event" ], "deprecated": false, "secret": false, "description": "The Knative resource type" }, - "name": { "kind": "path", "displayName": "Name", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "secret": false, "description": "The name that identifies the Knative resource" }, + "typeId": { "kind": "path", "displayName": "Type Id", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "secret": false, "description": "The identifier of the Knative resource" }, "ceOverride": { "kind": "parameter", "displayName": "Ce Override", "group": "common", "label": "", "required": false, "type": "object", "javaType": "java.util.Map", "prefix": "ce.override.", "deprecated": false, "secret": false, "configurationClass": "org.apache.camel.component.knative.KnativeConfiguration", "configurationField": "configuration", "description": "CloudEvent headers to override" }, "cloudEventsSpecVersion": { "kind": "parameter", "displayName": "Cloud Events Spec Version", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "enum": [ "0.1", "0.2", "0.3", "1.0" ], "deprecated": false, "secret": false, "defaultValue": "1.0", "configurationClass": "org.apache.camel.component.knative.KnativeConfiguration", "configurationField": "configuration", "description": "Set the version of the cloudevents spec." }, "cloudEventsType": { "kind": "parameter", "displayName": "Cloud Events Type", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "secret": false, "defaultValue": "org.apache.camel.event", "configurationClass": "org.apache.camel.component.knative.KnativeConfiguration", "configurationField": "configuration", "description": "Set the event-type information of the produced events." }, "environment": { "kind": "parameter", "displayName": "Environment", "group": "common", "label": "", "required": false, "type": "object", "javaType": "org.apache.camel.component.knative.spi.KnativeEnvironment", "deprecated": false, "secret": false, "configurationClass": "org.apache.camel.component.knative.KnativeConfiguration", "configurationField": "configuration", "description": "The environment" }, "filters": { "kind": "parameter", "displayName": "Filters", "group": "common", "label": "", "required": false, "type": "object", "javaType": "java.util.Map", "prefix": "filter.", "deprecated": false, "secret": false, "configurationClass": "org.apache.camel.component.knative.KnativeConfiguration", "configurationField": "configuration", "description": "Set the filters." }, - "serviceName": { "kind": "parameter", "displayName": "Service Name", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "secret": false, "configurationClass": "org.apache.camel.component.knative.KnativeConfiguration", "configurationField": "configuration", "description": "The name of the service to lookup from the KnativeEnvironment." }, "transportOptions": { "kind": "parameter", "displayName": "Transport Options", "group": "common", "label": "", "required": false, "type": "object", "javaType": "java.util.Map", "prefix": "transport.", "deprecated": false, "secret": false, "configurationClass": "org.apache.camel.component.knative.KnativeConfiguration", "configurationField": "configuration", "description": "Set the transport options." }, "bridgeErrorHandler": { "kind": "parameter", "displayName": "Bridge Error Handler", "group": "consumer", "label": "consumer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, "defaultValue": false, "description": "Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored." }, "replyWithCloudEvent": { "kind": "parameter", "displayName": "Reply With Cloud Event", "group": "consumer", "label": "consumer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.knative.KnativeConfiguration", "configurationField": "configuration", "description": "Transforms the reply into a cloud event that will be processed by the caller. When listening to events from a Knative Broker, if this flag is enabled, replies will be published to the same Broker where the request comes from (beware that if you don't change the type of the received message, you may create a loop and receive your same reply). When this flag is disabled, CloudEvent headers are removed from the reply." }, @@ -59,6 +59,7 @@ "apiVersion": { "kind": "parameter", "displayName": "Api Version", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "secret": false, "configurationClass": "org.apache.camel.component.knative.KnativeConfiguration", "configurationField": "configuration", "description": "The version of the k8s resource referenced by the endpoint." }, "basicPropertyBinding": { "kind": "parameter", "displayName": "Basic Property Binding", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, "defaultValue": false, "description": "Whether the endpoint should use basic property binding (Camel 2.x) or the newer property binding with additional capabilities" }, "kind": { "kind": "parameter", "displayName": "Kind", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "secret": false, "configurationClass": "org.apache.camel.component.knative.KnativeConfiguration", "configurationField": "configuration", "description": "The type of the k8s resource referenced by the endpoint." }, + "name": { "kind": "parameter", "displayName": "Name", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "secret": false, "configurationClass": "org.apache.camel.component.knative.KnativeConfiguration", "configurationField": "configuration", "description": "The name of the k8s resource referenced by the endpoint." }, "synchronous": { "kind": "parameter", "displayName": "Synchronous", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, "defaultValue": false, "description": "Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported)." } } } diff --git a/components/camel-knative/camel-knative/src/main/java/org/apache/camel/component/knative/KnativeConfiguration.java b/components/camel-knative/camel-knative/src/main/java/org/apache/camel/component/knative/KnativeConfiguration.java index 30547ba9e..ab2496adc 100644 --- a/components/camel-knative/camel-knative/src/main/java/org/apache/camel/component/knative/KnativeConfiguration.java +++ b/components/camel-knative/camel-knative/src/main/java/org/apache/camel/component/knative/KnativeConfiguration.java @@ -30,7 +30,7 @@ public class KnativeConfiguration implements Cloneable { @UriParam private KnativeEnvironment environment; @UriParam - private String serviceName; + private String typeId; @UriParam(defaultValue = "1.0", enums = "0.1,0.2,0.3,1.0") private String cloudEventsSpecVersion = CloudEvents.v1_0.version(); @UriParam(defaultValue = "org.apache.camel.event") @@ -45,6 +45,8 @@ public class KnativeConfiguration implements Cloneable { private String apiVersion; @UriParam(label = "advanced") private String kind; + @UriParam(label = "advanced") + private String name; @UriParam(label = "consumer", defaultValue = "false") private boolean replyWithCloudEvent; @UriParam(label = "consumer,advanced", defaultValue = "true") @@ -67,15 +69,15 @@ public void setEnvironment(KnativeEnvironment environment) { this.environment = environment; } - public String getServiceName() { - return serviceName; + public String getTypeId() { + return typeId; } /** * The name of the service to lookup from the {@link KnativeEnvironment}. */ - public void setServiceName(String serviceName) { - this.serviceName = serviceName; + public void setTypeId(String typeId) { + this.typeId = typeId; } public boolean isReplyWithCloudEvent() { @@ -183,6 +185,17 @@ public void setKind(String kind) { this.kind = kind; } + public String getName() { + return name; + } + + /** + * The name of the k8s resource referenced by the endpoint. + */ + public void setName(String name) { + this.name = name; + } + public Boolean getReply() { return reply; } diff --git a/components/camel-knative/camel-knative/src/main/java/org/apache/camel/component/knative/KnativeEndpoint.java b/components/camel-knative/camel-knative/src/main/java/org/apache/camel/component/knative/KnativeEndpoint.java index 0d0f69e08..0b4025770 100644 --- a/components/camel-knative/camel-knative/src/main/java/org/apache/camel/component/knative/KnativeEndpoint.java +++ b/components/camel-knative/camel-knative/src/main/java/org/apache/camel/component/knative/KnativeEndpoint.java @@ -46,14 +46,14 @@ @UriEndpoint( firstVersion = "3.0.0", scheme = "knative", - syntax = "knative:type/name", + syntax = "knative:type/typeId", title = "Knative", label = "cloud,eventing") public class KnativeEndpoint extends DefaultEndpoint { @UriPath(description = "The Knative resource type") private final Knative.Type type; - @UriPath(description = "The name that identifies the Knative resource") - private final String name; + @UriPath(description = "The identifier of the Knative resource") + private final String typeId; private final CloudEventProcessor cloudEvent; @UriParam private KnativeConfiguration configuration; @@ -62,7 +62,7 @@ public KnativeEndpoint(String uri, KnativeComponent component, Knative.Type type super(uri, component); this.type = type; - this.name = name; + this.typeId = name; this.configuration = configuration; this.cloudEvent = CloudEventProcessors.fromSpecVersion(configuration.getCloudEventsSpecVersion()); } @@ -117,8 +117,8 @@ public Knative.Type getType() { return type; } - public String getName() { - return name; + public String getTypeId() { + return typeId; } public KnativeConfiguration getConfiguration() { @@ -131,13 +131,13 @@ public void setConfiguration(KnativeConfiguration configuration) { @Override protected void doInit() throws Exception { - if (ObjectHelper.isEmpty(this.configuration .getServiceName())) { - this.configuration .setServiceName(this.name); + if (ObjectHelper.isEmpty(this.configuration.getTypeId())) { + this.configuration.setTypeId(this.typeId); } } KnativeEnvironment.KnativeResource lookupServiceDefinition(Knative.EndpointKind endpointKind) { - String serviceName = configuration.getServiceName(); + String serviceName = configuration.getTypeId(); // // look-up service definition by service name first then if not found try to look it up by using @@ -232,6 +232,11 @@ private Predicate serviceFilter(Knative.Endp return false; } + final String name = s.getMetadata(Knative.KNATIVE_NAME); + if (configuration.getName() != null && !Objects.equals(name, configuration.getName())) { + return false; + } + return true; }; } diff --git a/components/camel-knative/camel-knative/src/main/java/org/apache/camel/component/knative/ce/AbstractCloudEventProcessor.java b/components/camel-knative/camel-knative/src/main/java/org/apache/camel/component/knative/ce/AbstractCloudEventProcessor.java index b24bfcbe3..61082a663 100644 --- a/components/camel-knative/camel-knative/src/main/java/org/apache/camel/component/knative/ce/AbstractCloudEventProcessor.java +++ b/components/camel-knative/camel-knative/src/main/java/org/apache/camel/component/knative/ce/AbstractCloudEventProcessor.java @@ -96,16 +96,16 @@ public Processor producer(KnativeEndpoint endpoint, KnativeEnvironment.KnativeRe // in case of events, if the type of the event is defined as URI param so we need // to override it to avoid the event type be overridden by Messages's headers // - if (endpoint.getType() == Knative.Type.event && endpoint.getName() != null) { + if (endpoint.getType() == Knative.Type.event && endpoint.getTypeId() != null) { final Object eventType = headers.get(CloudEvent.CAMEL_CLOUD_EVENT_TYPE); if (eventType != null) { logger.debug("Detected the presence of {} header with value {}: it will be ignored and replaced by value set as uri parameter {}", CloudEvent.CAMEL_CLOUD_EVENT_TYPE, eventType, - endpoint.getName()); + endpoint.getTypeId()); } - headers.put(cloudEvent().mandatoryAttribute(CloudEvent.CAMEL_CLOUD_EVENT_TYPE).http(), endpoint.getName()); + headers.put(cloudEvent().mandatoryAttribute(CloudEvent.CAMEL_CLOUD_EVENT_TYPE).http(), endpoint.getTypeId()); } else { setCloudEventHeader(headers, CloudEvent.CAMEL_CLOUD_EVENT_TYPE, () -> { return service.getMetadata().getOrDefault(