Skip to content

Commit

Permalink
cloudevents & knative
Browse files Browse the repository at this point in the history
  • Loading branch information
lburgazzoli committed Oct 27, 2018
1 parent 043836a commit 4b0910a
Show file tree
Hide file tree
Showing 14 changed files with 1,270 additions and 0 deletions.
10 changes: 10 additions & 0 deletions runtime/camel-knative/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
target

*.iml

.idea
.project
.metadata
.settings
.factorypath
.classpath
130 changes: 130 additions & 0 deletions runtime/camel-knative/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<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">
<parent>
<groupId>org.apache.camel.k</groupId>
<artifactId>camel-k-runtime-parent</artifactId>
<version>0.0.5-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>camel-knative</artifactId>

<dependencies>

<!-- ****************************** -->
<!-- -->
<!-- RUNTIME -->
<!-- -->
<!-- ****************************** -->

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>

<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-undertow</artifactId>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jdk8</artifactId>
<version>${jackson.version}</version>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>${commons-collections4.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons-lang.version}</version>
</dependency>

<!-- ****************************** -->
<!-- -->
<!-- TESTS -->
<!-- -->
<!-- ****************************** -->

<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-test</artifactId>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertj.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j2.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>${log4j2.version}</version>
<scope>test</scope>
</dependency>

</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* 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.apache.camel.component.knative;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;

public final class Knative {
public static final ObjectMapper MAPPER = new ObjectMapper().registerModule(new Jdk8Module());

public static final String HTTP_COMPONENT = "undertow";
public static final String KNATIVE_PROTOCOL = "knative.protocol";
public static final String KNATIVE_TYPE = "knative.type";
public static final String KNATIVE_EVENT_TYPE = "knative.event.type";
public static final String CONTENT_TYPE = "content.type";
public static final String MIME_STRUCTURED_CONTENT_MODE = "application/cloudevents+json";

private Knative() {
}

public enum Type {
endpoint,
channel
}

public enum Protocol {
http,
https
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/**
* 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.apache.camel.component.knative;

import java.util.Map;

import org.apache.camel.CamelContext;
import org.apache.camel.Endpoint;
import org.apache.camel.impl.DefaultComponent;
import org.apache.camel.util.IntrospectionSupport;
import org.apache.camel.util.ObjectHelper;
import org.apache.camel.util.StringHelper;

public class KnativeComponent extends DefaultComponent {
private final KnativeConfiguration configuration;
private String environmentPath;

public KnativeComponent() {
this(null);
}

public KnativeComponent(CamelContext context) {
super(context);

this.configuration = new KnativeConfiguration();
}

// ************************
//
// Properties
//
// ************************

public String getEnvironmentPath() {
return environmentPath;
}

/**
* The path ot the environment definition
*/
public void setEnvironmentPath(String environmentPath) {
this.environmentPath = environmentPath;
}

public KnativeConfiguration getConfiguration() {
return configuration;
}

public KnativeEnvironment getEnvironment() {
return configuration.getEnvironment();
}

/**
* The environment
*/
public void setEnvironment(KnativeEnvironment environment) {
configuration.setEnvironment(environment);
}

// ************************
//
//
//
// ************************

@Override
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
final String type = StringHelper.before(remaining, "/");
final String target = StringHelper.after(remaining, "/");
final KnativeConfiguration conf = getKnativeConfiguration();

// set properties from the endpoint uri
IntrospectionSupport.setProperties(getCamelContext().getTypeConverter(), conf, parameters);

return new KnativeEndpoint(uri, this, Knative.Type.valueOf(type), target, conf);
}

// ************************
//
// Helpers
//
// ************************

private KnativeConfiguration getKnativeConfiguration() throws Exception {
KnativeConfiguration conf = configuration.copy();

if (conf.getEnvironment() == null) {
ObjectHelper.notNull(environmentPath, "Environment Path");

conf.setEnvironment(
KnativeEnvironment.mandatoryLoadFromResource(getCamelContext(), this.environmentPath)
);
}

return conf;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* 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.apache.camel.component.knative;

import org.apache.camel.RuntimeCamelException;
import org.apache.camel.spi.Metadata;
import org.apache.camel.spi.UriParam;

public class KnativeConfiguration implements Cloneable {
@UriParam
@Metadata(required = "true")
private KnativeEnvironment environment;

public KnativeConfiguration() {
}

// ************************
//
// Properties
//
// ************************

public KnativeEnvironment getEnvironment() {
return environment;
}

/**
* The environment
*/
public void setEnvironment(KnativeEnvironment environment) {
this.environment = environment;
}

// ************************
//
// Cloneable
//
// ************************

public KnativeConfiguration copy() {
try {
return (KnativeConfiguration)super.clone();
} catch (CloneNotSupportedException e) {
throw new RuntimeCamelException(e);
}
}
}
Loading

0 comments on commit 4b0910a

Please sign in to comment.