Skip to content

Commit

Permalink
Embed camel catalog #93
Browse files Browse the repository at this point in the history
  • Loading branch information
lburgazzoli authored and nicolaferraro committed Sep 19, 2018
1 parent 1a40993 commit dd1d0f5
Show file tree
Hide file tree
Showing 10 changed files with 4,737 additions and 5 deletions.
2,252 changes: 2,252 additions & 0 deletions deploy/camel-catalog.yaml

Large diffs are not rendered by default.

2,256 changes: 2,256 additions & 0 deletions deploy/resources.go

Large diffs are not rendered by default.

40 changes: 37 additions & 3 deletions pkg/client/cmd/completion_bash.go
Expand Up @@ -20,6 +20,8 @@ package cmd
import (
"os"

"github.com/apache/camel-k/pkg/util/camel"

"github.com/spf13/cobra"
)

Expand All @@ -40,10 +42,28 @@ To configure your bash shell to load completions for each session add to your ba
. <(kamel completion bash)
`

const bashCompletionFunction = `
var bashCompletionFunction = `
__kamel_dependency_type() {
COMPREPLY=( $( compgen -W "camel: mvn: file:" -- "$cur") )
compopt -o nospace
case ${cur} in
c*)
local type_list="` + computeCamelDependencies() + `"
COMPREPLY=( $( compgen -W "${type_list}" -- "$cur") )
;;
m*)
local type_list="mvn:""
COMPREPLY=( $( compgen -W "${type_list}" -- "$cur") )
compopt -o nospace
;;
f*)
local type_list="file:""
COMPREPLY=( $( compgen -W "${type_list}" -- "$cur") )
compopt -o nospace
;;
*)
local type_list="camel: mvn: file:"
COMPREPLY=( $( compgen -W "camel mvn: file:" -- "$cur") )
compopt -o nospace
esac
}
__kamel_kubectl_get_configmap() {
Expand Down Expand Up @@ -105,3 +125,17 @@ func configureKnownBashCompletions(command *cobra.Command) {
cobra.BashCompCustom: {"__kamel_kubectl_get_secret"},
}
}

func computeCamelDependencies() string {
result := ""

for _, v := range catalog.Runtime.Components {
if result != "" {
result = result + " " + v.Dependency.ArtifactID
} else {
result = v.Dependency.ArtifactID
}
}

return result
}
13 changes: 12 additions & 1 deletion pkg/client/cmd/context_create.go
Expand Up @@ -21,6 +21,7 @@ import (
"errors"
"fmt"
"strconv"
"strings"

"github.com/operator-framework/operator-sdk/pkg/sdk"

Expand Down Expand Up @@ -90,10 +91,20 @@ func (command *contextCreateCommand) run(cmd *cobra.Command, args []string) erro
"camel.apache.org/context.type": "user",
}
ctx.Spec = v1alpha1.IntegrationContextSpec{
Dependencies: command.dependencies,
Dependencies: make([]string, 0, len(command.dependencies)),
Configuration: make([]v1alpha1.ConfigurationSpec, 0),
}

for _, item := range command.dependencies {
if strings.HasPrefix(item, "mvn:") {
ctx.Spec.Dependencies = append(ctx.Spec.Dependencies, item)
} else if strings.HasPrefix(item, "file:") {
ctx.Spec.Dependencies = append(ctx.Spec.Dependencies, item)
} else if strings.HasPrefix(item, "camel-") {
ctx.Spec.Dependencies = append(ctx.Spec.Dependencies, "camel:"+strings.TrimPrefix(item, "camel-"))
}
}

for _, item := range command.properties {
ctx.Spec.Configuration = append(ctx.Spec.Configuration, v1alpha1.ConfigurationSpec{
Type: "property",
Expand Down
12 changes: 11 additions & 1 deletion pkg/client/cmd/run.go
Expand Up @@ -248,12 +248,22 @@ func (o *runCmdOptions) updateIntegrationCode(filename string) (*v1alpha1.Integr
Content: code,
Language: o.Language,
},
Dependencies: o.Dependencies,
Dependencies: make([]string, 0, len(o.Dependencies)),
Context: o.IntegrationContext,
Configuration: make([]v1alpha1.ConfigurationSpec, 0),
},
}

for _, item := range o.Dependencies {
if strings.HasPrefix(item, "mvn:") {
integration.Spec.Dependencies = append(integration.Spec.Dependencies, item)
} else if strings.HasPrefix(item, "file:") {
integration.Spec.Dependencies = append(integration.Spec.Dependencies, item)
} else if strings.HasPrefix(item, "camel-") {
integration.Spec.Dependencies = append(integration.Spec.Dependencies, "camel:"+strings.TrimPrefix(item, "camel-"))
}
}

for _, item := range o.Properties {
integration.Spec.Configuration = append(integration.Spec.Configuration, v1alpha1.ConfigurationSpec{
Type: "property",
Expand Down
52 changes: 52 additions & 0 deletions pkg/util/camel/catalog.go
@@ -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 catalog

import (
"github.com/apache/camel-k/deploy"
"gopkg.in/yaml.v2"
)

// Catalog --
type Catalog struct {
Version string `yaml:"version"`
Components map[string]Component `yaml:"components"`
}

// Dependency --
type Dependency struct {
GroupID string `yaml:"groupId"`
ArtifactID string `yaml:"artifactId"`
Version string `yaml:"version"`
}

// Component --
type Component struct {
Dependency Dependency `yaml:"dependency"`
Schemes []string `yaml:"schemes"`
}

func init() {
data := deploy.Resources["camel-catalog.yaml"]
if err := yaml.Unmarshal([]byte(data), &Runtime); err != nil {
panic(err)
}
}

// Runtime --
var Runtime Catalog
10 changes: 10 additions & 0 deletions runtime/catalog-builder/.gitignore
@@ -0,0 +1,10 @@
target

*.iml

.idea
.project
.metadata
.settings
.factorypath
.classpath
69 changes: 69 additions & 0 deletions runtime/catalog-builder/pom.xml
@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="UTF-8"?>
<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.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>camel-k-runtime-catalog-builder</artifactId>

<build>
<plugins>
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>get-syndesis-version</id>
<phase>initialize</phase>
<goals>
<goal>execute</goal>
</goals>
</execution>
</executions>
<configuration>
<properties>
<property>
<name>catalogOutputFile</name>
<value>${project.basedir}/../../deploy/camel-catalog.yaml</value>
</property>
</properties>
<scripts>
<script>file:///${project.basedir}/src/main/resources/catalogbuilder.groovy</script>
</scripts>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>${groovy.version}</version>
<scope>runtime</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>${camel.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-catalog</artifactId>
<version>${camel.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>${snakeyaml.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
36 changes: 36 additions & 0 deletions runtime/catalog-builder/src/main/resources/catalogbuilder.groovy
@@ -0,0 +1,36 @@
import groovy.json.JsonSlurper
import org.apache.camel.catalog.DefaultCamelCatalog
import org.yaml.snakeyaml.Yaml
import org.yaml.snakeyaml.DumperOptions

def slurper = new JsonSlurper()
def catalog = new DefaultCamelCatalog()


def output = new TreeMap()
output['version'] = catalog.loadedVersion
output['components'] = [:]

catalog.findComponentNames().sort().each { name ->
def json = slurper.parseText(catalog.componentJSonSchema(name))

output['components'][name] = [:]
output['components'][name]['dependency'] = [:]
output['components'][name]['dependency']['groupId'] = json.component.groupId
output['components'][name]['dependency']['artifactId'] = json.component.artifactId
output['components'][name]['dependency']['version'] = json.component.version
output['components'][name]['schemes'] = [ json.component.scheme.trim() ]
if (json.component.alternativeSchemes) {
json.component.alternativeSchemes.split(',').each {
scheme -> output['components'][name]['schemes'] << scheme.trim()
}
}
}

def options = new DumperOptions()
options.indent = 2
options.defaultFlowStyle = DumperOptions.FlowStyle.BLOCK

new File(catalogOutputFile).newWriter().withWriter {
w -> w << new Yaml(options).dump(output)
}
2 changes: 2 additions & 0 deletions runtime/pom.xml
Expand Up @@ -24,6 +24,7 @@
<log4j2.version>2.11.0</log4j2.version>
<slf4j.version>1.7.25</slf4j.version>
<groovy.version>2.5.2</groovy.version>
<snakeyaml.version>1.23</snakeyaml.version>

<fabric8-maven-plugin.version>3.5.40</fabric8-maven-plugin.version>
</properties>
Expand Down Expand Up @@ -54,6 +55,7 @@

<modules>
<module>jvm</module>
<module>catalog-builder</module>
</modules>

</project>

0 comments on commit dd1d0f5

Please sign in to comment.