Skip to content

Commit

Permalink
knative: support configuring the knative environment using properties a…
Browse files Browse the repository at this point in the history
  • Loading branch information
lburgazzoli committed Nov 13, 2020
1 parent 076d44d commit 467410e
Show file tree
Hide file tree
Showing 38 changed files with 624 additions and 251 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.camel.component.knative.KnativeComponent;
import org.apache.camel.component.knative.KnativeConstants;
import org.apache.camel.component.knative.spi.KnativeEnvironment;
import org.apache.camel.component.knative.spi.KnativeResource;
import org.apache.camel.k.quarkus.knative.KnativeRecorder;
import org.apache.camel.quarkus.core.deployment.spi.CamelRuntimeBeanBuildItem;
import org.apache.camel.quarkus.core.deployment.spi.CamelServiceFilter;
Expand All @@ -43,7 +44,7 @@ List<UnremovableBeanBuildItem> unremovableBeans() {
List<ReflectiveClassBuildItem> reflectiveClasses() {
return List.of(
new ReflectiveClassBuildItem(true, false, KnativeEnvironment.class),
new ReflectiveClassBuildItem(true, false, KnativeEnvironment.KnativeResource.class)
new ReflectiveClassBuildItem(true, false, KnativeResource.class)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.camel.CamelContext;
import org.apache.camel.component.knative.spi.Knative;
import org.apache.camel.component.knative.spi.KnativeEnvironment;
import org.apache.camel.component.knative.spi.KnativeResource;
import org.apache.camel.k.ContextCustomizer;
import org.apache.camel.k.annotation.Customizer;
import org.apache.camel.spi.Configurer;
Expand All @@ -36,11 +37,8 @@
public class KnativeSinkBindingContextCustomizer implements ContextCustomizer {

private String name;

private Knative.Type type;

private String kind;

private String apiVersion;

@Override
Expand All @@ -51,7 +49,7 @@ public void apply(CamelContext camelContext) {
});
}

private Optional<KnativeEnvironment.KnativeResource> createSyntheticDefinition(
private Optional<KnativeResource> createSyntheticDefinition(
CamelContext camelContext,
String sinkName) {

Expand All @@ -61,16 +59,10 @@ private Optional<KnativeEnvironment.KnativeResource> createSyntheticDefinition(
if (ObjectHelper.isNotEmpty(kSinkUrl)) {
// create a synthetic service definition to target the K_SINK url
var serviceBuilder = KnativeEnvironment.serviceBuilder(type, sinkName)
.withMeta(Knative.CAMEL_ENDPOINT_KIND, Knative.EndpointKind.sink)
.withMeta(Knative.SERVICE_META_URL, kSinkUrl);

if (ObjectHelper.isNotEmpty(kind)) {
serviceBuilder = serviceBuilder.withMeta(Knative.KNATIVE_KIND, kind);
}

if (ObjectHelper.isNotEmpty(apiVersion)) {
serviceBuilder = serviceBuilder.withMeta(Knative.KNATIVE_API_VERSION, apiVersion);
}
.withEndpointKind(Knative.EndpointKind.sink)
.withUrl(kSinkUrl)
.withMeta(Knative.KNATIVE_KIND, kind)
.withMeta(Knative.KNATIVE_API_VERSION, apiVersion);

if (ObjectHelper.isNotEmpty(kCeOverride)) {
try (Reader reader = new StringReader(kCeOverride)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/* Generated by camel build tools - do NOT edit this file! */
package org.apache.camel.component.knative.spi;

import java.util.Map;

import org.apache.camel.CamelContext;
import org.apache.camel.spi.GeneratedPropertyConfigurer;
import org.apache.camel.spi.PropertyConfigurerGetter;
import org.apache.camel.util.CaseInsensitiveMap;
import org.apache.camel.component.knative.spi.KnativeEnvironment;

/**
* Generated by camel build tools - do NOT edit this file!
*/
@SuppressWarnings("unchecked")
public class KnativeEnvironmentConfigurer extends org.apache.camel.support.component.PropertyConfigurerSupport implements GeneratedPropertyConfigurer, PropertyConfigurerGetter {

private static final Map<String, Object> ALL_OPTIONS;
static {
Map<String, Object> map = new CaseInsensitiveMap();
map.put("Resources", java.util.List.class);
ALL_OPTIONS = map;
}

@Override
public boolean configure(CamelContext camelContext, Object obj, String name, Object value, boolean ignoreCase) {
org.apache.camel.component.knative.spi.KnativeEnvironment target = (org.apache.camel.component.knative.spi.KnativeEnvironment) obj;
switch (ignoreCase ? name.toLowerCase() : name) {
case "resources":
case "Resources": target.setResources(property(camelContext, java.util.List.class, value)); return true;
default: return false;
}
}

@Override
public Map<String, Object> getAllOptions(Object target) {
return ALL_OPTIONS;
}

@Override
public Object getOptionValue(Object obj, String name, boolean ignoreCase) {
org.apache.camel.component.knative.spi.KnativeEnvironment target = (org.apache.camel.component.knative.spi.KnativeEnvironment) obj;
switch (ignoreCase ? name.toLowerCase() : name) {
case "resources":
case "Resources": return target.getResources();
default: return null;
}
}

@Override
public Object getCollectionValueType(Object target, String name, boolean ignoreCase) {
switch (ignoreCase ? name.toLowerCase() : name) {
case "resources":
case "Resources": return org.apache.camel.component.knative.spi.KnativeResource.class;
default: return null;
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/* Generated by camel build tools - do NOT edit this file! */
package org.apache.camel.component.knative.spi;

import java.util.Map;

import org.apache.camel.CamelContext;
import org.apache.camel.spi.GeneratedPropertyConfigurer;
import org.apache.camel.spi.PropertyConfigurerGetter;
import org.apache.camel.util.CaseInsensitiveMap;
import org.apache.camel.component.knative.spi.KnativeResource;

/**
* Generated by camel build tools - do NOT edit this file!
*/
@SuppressWarnings("unchecked")
public class KnativeResourceConfigurer extends org.apache.camel.support.component.PropertyConfigurerSupport implements GeneratedPropertyConfigurer, PropertyConfigurerGetter {

private static final Map<String, Object> ALL_OPTIONS;
static {
Map<String, Object> map = new CaseInsensitiveMap();
map.put("CeOverrides", java.util.Map.class);
map.put("EndpointKind", org.apache.camel.component.knative.spi.Knative.EndpointKind.class);
map.put("Filters", java.util.Map.class);
map.put("Metadata", java.util.Map.class);
map.put("Name", java.lang.String.class);
map.put("Type", org.apache.camel.component.knative.spi.Knative.Type.class);
map.put("Url", java.lang.String.class);
ALL_OPTIONS = map;
}

@Override
public boolean configure(CamelContext camelContext, Object obj, String name, Object value, boolean ignoreCase) {
org.apache.camel.component.knative.spi.KnativeResource target = (org.apache.camel.component.knative.spi.KnativeResource) obj;
switch (ignoreCase ? name.toLowerCase() : name) {
case "ceoverrides":
case "CeOverrides": target.setCeOverrides(property(camelContext, java.util.Map.class, value)); return true;
case "endpointkind":
case "EndpointKind": target.setEndpointKind(property(camelContext, org.apache.camel.component.knative.spi.Knative.EndpointKind.class, value)); return true;
case "filters":
case "Filters": target.setFilters(property(camelContext, java.util.Map.class, value)); return true;
case "metadata":
case "Metadata": target.setMetadata(property(camelContext, java.util.Map.class, value)); return true;
case "name":
case "Name": target.setName(property(camelContext, java.lang.String.class, value)); return true;
case "type":
case "Type": target.setType(property(camelContext, org.apache.camel.component.knative.spi.Knative.Type.class, value)); return true;
case "url":
case "Url": target.setUrl(property(camelContext, java.lang.String.class, value)); return true;
default: return false;
}
}

@Override
public Map<String, Object> getAllOptions(Object target) {
return ALL_OPTIONS;
}

@Override
public Object getOptionValue(Object obj, String name, boolean ignoreCase) {
org.apache.camel.component.knative.spi.KnativeResource target = (org.apache.camel.component.knative.spi.KnativeResource) obj;
switch (ignoreCase ? name.toLowerCase() : name) {
case "ceoverrides":
case "CeOverrides": return target.getCeOverrides();
case "endpointkind":
case "EndpointKind": return target.getEndpointKind();
case "filters":
case "Filters": return target.getFilters();
case "metadata":
case "Metadata": return target.getMetadata();
case "name":
case "Name": return target.getName();
case "type":
case "Type": return target.getType();
case "url":
case "Url": return target.getUrl();
default: return null;
}
}

@Override
public Object getCollectionValueType(Object target, String name, boolean ignoreCase) {
switch (ignoreCase ? name.toLowerCase() : name) {
case "ceoverrides":
case "CeOverrides": return java.lang.String.class;
case "filters":
case "Filters": return java.lang.String.class;
case "metadata":
case "Metadata": return java.lang.String.class;
default: return null;
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Generated by camel build tools - do NOT edit this file!
class=org.apache.camel.component.knative.spi.KnativeEnvironmentConfigurer
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Generated by camel build tools - do NOT edit this file!
class=org.apache.camel.component.knative.spi.KnativeResourceConfigurer
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ public final class Knative {
public static final String MIME_BATCH_CONTENT_MODE = "application/cloudevents-batch+json";
public static final String CAMEL_ENDPOINT_KIND = "camel.endpoint.kind";

public static final String SERVICE_META_HOST = "service.host";
public static final String SERVICE_META_ZONE = "service.zone";
public static final String SERVICE_META_PATH = "service.path";
public static final String SERVICE_META_URL = "service.url";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ public interface KnativeConsumerFactory extends Service {
Consumer createConsumer(
Endpoint endpoint,
KnativeTransportConfiguration configuration,
KnativeEnvironment.KnativeResource service, Processor processor);
KnativeResource service, Processor processor);
}
Loading

0 comments on commit 467410e

Please sign in to comment.