You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by as...@apache.org on 2019/11/04 16:10:33 UTC
[camel-k] 09/38: fix(quarkus): Catalog exact matching logic should
take runtime provider into account
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit c4f37cf7ae4f7e81ccc1ae0e45410eb691674adc
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Wed Oct 23 10:41:12 2019 +0200
fix(quarkus): Catalog exact matching logic should take runtime provider into account
---
pkg/apis/camel/v1alpha1/camelcatalog_types.go | 2 +-
pkg/apis/camel/v1alpha1/common_types.go | 4 ++--
pkg/metadata/metadata_dependencies_test.go | 26 ++++++++++++++++++++++++++
pkg/util/camel/camel_util.go | 10 ++++++++--
pkg/util/camel/catalog.go | 14 +++++++++++++-
5 files changed, 50 insertions(+), 6 deletions(-)
diff --git a/pkg/apis/camel/v1alpha1/camelcatalog_types.go b/pkg/apis/camel/v1alpha1/camelcatalog_types.go
index 65a1d65..3ae6999 100644
--- a/pkg/apis/camel/v1alpha1/camelcatalog_types.go
+++ b/pkg/apis/camel/v1alpha1/camelcatalog_types.go
@@ -55,7 +55,7 @@ type CamelArtifact struct {
type CamelCatalogSpec struct {
Version string `json:"version" yaml:"version"`
RuntimeVersion string `json:"runtimeVersion" yaml:"runtimeVersion"`
- RuntimeProvider *RuntimeProvider `json:"runtimeProvider,omitempty"`
+ RuntimeProvider *RuntimeProvider `json:"runtimeProvider,omitempty" yaml:"runtimeProvider"`
Artifacts map[string]CamelArtifact `json:"artifacts" yaml:"artifacts"`
}
diff --git a/pkg/apis/camel/v1alpha1/common_types.go b/pkg/apis/camel/v1alpha1/common_types.go
index abf366f..2833890 100644
--- a/pkg/apis/camel/v1alpha1/common_types.go
+++ b/pkg/apis/camel/v1alpha1/common_types.go
@@ -29,8 +29,8 @@ type RuntimeProvider struct {
// QuarkusRuntimeProvider --
type QuarkusRuntimeProvider struct {
- CamelQuarkusVersion string `json:"camelQuarkusVersion,omitempty"`
- QuarkusVersion string `json:"quarkusVersion,omitempty"`
+ CamelQuarkusVersion string `json:"camelQuarkusVersion,omitempty" yaml:"camelQuarkusVersion"`
+ QuarkusVersion string `json:"quarkusVersion,omitempty" yaml:"quarkusVersion"`
}
// ConfigurationSpec --
diff --git a/pkg/metadata/metadata_dependencies_test.go b/pkg/metadata/metadata_dependencies_test.go
index d0919b5..bd1ceea 100644
--- a/pkg/metadata/metadata_dependencies_test.go
+++ b/pkg/metadata/metadata_dependencies_test.go
@@ -116,6 +116,32 @@ func TestDependencies(t *testing.T) {
assert.ElementsMatch(t, []string{"camel:http", "camel:log", "camel:mock", "camel:twitter"}, meta.Dependencies.List())
}
+func TestDependenciesQuarkus(t *testing.T) {
+ code := v1alpha1.SourceSpec{
+ DataSpec: v1alpha1.DataSpec{
+ Name: "Request.java",
+ Content: `
+ from("http:test").to("log:end");
+ from("https4:test").to("log:end");
+ from("twitter-timeline:test").to("mock:end");
+ `,
+ },
+ Language: v1alpha1.LanguageJavaSource,
+ }
+
+ catalog, err := camel.QuarkusCatalog()
+ assert.Nil(t, err)
+
+ meta := Extract(catalog, code)
+
+ assert.ElementsMatch(t,
+ []string{
+ "mvn:org.apache.camel.quarkus:camel-quarkus-log:",
+ "mvn:org.apache.camel.quarkus:camel-quarkus-twitter:",
+ },
+ meta.Dependencies.List())
+}
+
func TestJacksonDependency(t *testing.T) {
code := v1alpha1.SourceSpec{
DataSpec: v1alpha1.DataSpec{
diff --git a/pkg/util/camel/camel_util.go b/pkg/util/camel/camel_util.go
index 6aecdfe..a368284 100644
--- a/pkg/util/camel/camel_util.go
+++ b/pkg/util/camel/camel_util.go
@@ -27,10 +27,16 @@ import (
)
func findBestMatch(catalogs []v1alpha1.CamelCatalog, camelVersion string, runtimeVersion string, provider interface{}) (*RuntimeCatalog, error) {
- // FIXME: take the provider into account for exact match
+ // TODO: generic exact matching logic independent of the runtime provider
for _, catalog := range catalogs {
if catalog.Spec.Version == camelVersion && catalog.Spec.RuntimeVersion == runtimeVersion {
- return NewRuntimeCatalog(catalog.Spec), nil
+ if provider == nil && catalog.Spec.RuntimeProvider == nil {
+ return NewRuntimeCatalog(catalog.Spec), nil
+ } else if provider, ok := provider.(v1alpha1.QuarkusRuntimeProvider); ok &&
+ catalog.Spec.RuntimeProvider != nil && catalog.Spec.RuntimeProvider.Quarkus != nil &&
+ provider == *catalog.Spec.RuntimeProvider.Quarkus {
+ return NewRuntimeCatalog(catalog.Spec), nil
+ }
}
}
diff --git a/pkg/util/camel/catalog.go b/pkg/util/camel/catalog.go
index a5a6d1e..e4442c9 100644
--- a/pkg/util/camel/catalog.go
+++ b/pkg/util/camel/catalog.go
@@ -29,6 +29,18 @@ import (
// DefaultCatalog --
func DefaultCatalog() (*RuntimeCatalog, error) {
+ return catalogForRuntimeProvider(nil)
+}
+
+// QuarkusCatalog --
+func QuarkusCatalog() (*RuntimeCatalog, error) {
+ return catalogForRuntimeProvider(v1alpha1.QuarkusRuntimeProvider{
+ CamelQuarkusVersion: "0.2.0",
+ QuarkusVersion: "0.21.2",
+ })
+}
+
+func catalogForRuntimeProvider(provider interface{}) (*RuntimeCatalog, error) {
catalogs := make([]v1alpha1.CamelCatalog, 0)
for name, content := range deploy.Resources {
@@ -42,5 +54,5 @@ func DefaultCatalog() (*RuntimeCatalog, error) {
}
}
- return findBestMatch(catalogs, defaults.DefaultCamelVersion, defaults.DefaultRuntimeVersion, nil)
+ return findBestMatch(catalogs, defaults.DefaultCamelVersion, defaults.DefaultRuntimeVersion, provider)
}