This is an automated email from the ASF dual-hosted git repository.
lburgazzoli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git
The following commit(s) were added to refs/heads/master by this push:
new 9095ec8 Support for new yaml dsl #781
9095ec8 is described below
commit 9095ec8faad2df20fcc335d4293028b7fe88e108
Author: lburgazzoli <[email protected]>
AuthorDate: Wed Jul 3 16:10:13 2019 +0200
Support for new yaml dsl #781
---
examples/routes.flow | 5 -
examples/routes.yaml | 11 +++
pkg/apis/camel/v1alpha1/common_types.go | 14 ---
pkg/apis/camel/v1alpha1/common_types_support.go | 11 ---
pkg/apis/camel/v1alpha1/integration_types.go | 6 +-
.../v1alpha1/integration_types_support_test.go | 2 +-
pkg/apis/camel/v1alpha1/zz_generated.deepcopy.go | 59 ------------
pkg/metadata/metadata_uri_test.go | 28 ++++--
pkg/trait/dependencies.go | 2 +-
pkg/util/source/inspector.go | 5 +-
pkg/util/source/inspector_yaml.go | 107 +++++++++++++++++++++
pkg/util/source/inspector_yaml_flow.go | 53 ----------
12 files changed, 144 insertions(+), 159 deletions(-)
diff --git a/examples/routes.flow b/examples/routes.flow
deleted file mode 100644
index ea69305..0000000
--- a/examples/routes.flow
+++ /dev/null
@@ -1,5 +0,0 @@
-- steps:
- - kind: "endpoint"
- uri: "timer:tick?period=5s"
- - kind: "endpoint"
- uri: "log:info"
diff --git a/examples/routes.yaml b/examples/routes.yaml
new file mode 100644
index 0000000..48b9211
--- /dev/null
+++ b/examples/routes.yaml
@@ -0,0 +1,11 @@
+- id: "yaml"
+ from:
+ uri: "timer:tick"
+ parameters:
+ period: "5s"
+ steps:
+ - set-body:
+ constant: "Hello Yaml !!!"
+ - transform:
+ simple: "${body.toUpperCase()}"
+ - to: "log:info"
diff --git a/pkg/apis/camel/v1alpha1/common_types.go
b/pkg/apis/camel/v1alpha1/common_types.go
index 00a45d1..1c57c62 100644
--- a/pkg/apis/camel/v1alpha1/common_types.go
+++ b/pkg/apis/camel/v1alpha1/common_types.go
@@ -35,20 +35,6 @@ type Artifact struct {
Target string `json:"target,omitempty" yaml:"target,omitempty"`
}
-// Flow --
-type Flow struct {
- Steps []Step `json:"steps"`
-}
-
-// Flows are collections of Flow
-type Flows []Flow
-
-// Step --
-type Step struct {
- Kind string `json:"kind"`
- URI string `json:"uri"`
-}
-
// Failure --
type Failure struct {
Reason string `json:"reason"`
diff --git a/pkg/apis/camel/v1alpha1/common_types_support.go
b/pkg/apis/camel/v1alpha1/common_types_support.go
index 364150e..09cf835 100644
--- a/pkg/apis/camel/v1alpha1/common_types_support.go
+++ b/pkg/apis/camel/v1alpha1/common_types_support.go
@@ -19,8 +19,6 @@ package v1alpha1
import (
"fmt"
-
- yaml2 "gopkg.in/yaml.v2"
)
func (in *Artifact) String() string {
@@ -30,12 +28,3 @@ func (in *Artifact) String() string {
func (spec ConfigurationSpec) String() string {
return fmt.Sprintf("%s=%s", spec.Type, spec.Value)
}
-
-// Serialize serializes a Flow
-func (flows Flows) Serialize() (string, error) {
- res, err := yaml2.Marshal(flows)
- if err != nil {
- return "", err
- }
- return string(res), nil
-}
diff --git a/pkg/apis/camel/v1alpha1/integration_types.go
b/pkg/apis/camel/v1alpha1/integration_types.go
index a1bcb75..9127432 100644
--- a/pkg/apis/camel/v1alpha1/integration_types.go
+++ b/pkg/apis/camel/v1alpha1/integration_types.go
@@ -120,8 +120,8 @@ const (
LanguageXML Language = "xml"
// LanguageKotlin --
LanguageKotlin Language = "kts"
- // LanguageYamlFlow --
- LanguageYamlFlow Language = "flow"
+ // LanguageYaml --
+ LanguageYaml Language = "yaml"
)
// Languages is the list of all supported languages
@@ -132,7 +132,7 @@ var Languages = []Language{
LanguageJavaScript,
LanguageXML,
LanguageKotlin,
- LanguageYamlFlow,
+ LanguageYaml,
}
// IntegrationPhase --
diff --git a/pkg/apis/camel/v1alpha1/integration_types_support_test.go
b/pkg/apis/camel/v1alpha1/integration_types_support_test.go
index 8269c30..0911c59 100644
--- a/pkg/apis/camel/v1alpha1/integration_types_support_test.go
+++ b/pkg/apis/camel/v1alpha1/integration_types_support_test.go
@@ -31,7 +31,7 @@ func TestAllLanguages(t *testing.T) {
assert.Contains(t, Languages, LanguageGroovy)
assert.Contains(t, Languages, LanguageKotlin)
assert.Contains(t, Languages, LanguageXML)
- assert.Contains(t, Languages, LanguageYamlFlow)
+ assert.Contains(t, Languages, LanguageYaml)
}
func TestLanguageFromName(t *testing.T) {
diff --git a/pkg/apis/camel/v1alpha1/zz_generated.deepcopy.go
b/pkg/apis/camel/v1alpha1/zz_generated.deepcopy.go
index a0f5962..43e14e8 100644
--- a/pkg/apis/camel/v1alpha1/zz_generated.deepcopy.go
+++ b/pkg/apis/camel/v1alpha1/zz_generated.deepcopy.go
@@ -411,49 +411,6 @@ func (in *FailureRecovery) DeepCopy() *FailureRecovery {
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver,
writing into out. in must be non-nil.
-func (in *Flow) DeepCopyInto(out *Flow) {
- *out = *in
- if in.Steps != nil {
- in, out := &in.Steps, &out.Steps
- *out = make([]Step, len(*in))
- copy(*out, *in)
- }
- return
-}
-
-// DeepCopy is an autogenerated deepcopy function, copying the receiver,
creating a new Flow.
-func (in *Flow) DeepCopy() *Flow {
- if in == nil {
- return nil
- }
- out := new(Flow)
- in.DeepCopyInto(out)
- return out
-}
-
-// DeepCopyInto is an autogenerated deepcopy function, copying the receiver,
writing into out. in must be non-nil.
-func (in Flows) DeepCopyInto(out *Flows) {
- {
- in := &in
- *out = make(Flows, len(*in))
- for i := range *in {
- (*in)[i].DeepCopyInto(&(*out)[i])
- }
- return
- }
-}
-
-// DeepCopy is an autogenerated deepcopy function, copying the receiver,
creating a new Flows.
-func (in Flows) DeepCopy() Flows {
- if in == nil {
- return nil
- }
- out := new(Flows)
- in.DeepCopyInto(out)
- return *out
-}
-
-// DeepCopyInto is an autogenerated deepcopy function, copying the receiver,
writing into out. in must be non-nil.
func (in *Integration) DeepCopyInto(out *Integration) {
*out = *in
out.TypeMeta = in.TypeMeta
@@ -951,22 +908,6 @@ func (in *SourceSpec) DeepCopy() *SourceSpec {
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver,
writing into out. in must be non-nil.
-func (in *Step) DeepCopyInto(out *Step) {
- *out = *in
- return
-}
-
-// DeepCopy is an autogenerated deepcopy function, copying the receiver,
creating a new Step.
-func (in *Step) DeepCopy() *Step {
- if in == nil {
- return nil
- }
- out := new(Step)
- in.DeepCopyInto(out)
- return out
-}
-
-// DeepCopyInto is an autogenerated deepcopy function, copying the receiver,
writing into out. in must be non-nil.
func (in *TraitSpec) DeepCopyInto(out *TraitSpec) {
*out = *in
if in.Configuration != nil {
diff --git a/pkg/metadata/metadata_uri_test.go
b/pkg/metadata/metadata_uri_test.go
index 3f5b8db..74d6133 100644
--- a/pkg/metadata/metadata_uri_test.go
+++ b/pkg/metadata/metadata_uri_test.go
@@ -258,21 +258,27 @@ func TestJavascript1(t *testing.T) {
assert.Len(t, metadata.ToURIs, 4)
}
-const yamlFlow = `
-- steps:
- - kind: "endpoint"
+const yaml = `
+- from:
uri: "timer:tick"
- - kind: "endpoint"
- uri: "log:info"
+ steps:
+ - to: "log:info1"
+ - to:
+ uri: "log:info2"
+ - split:
+ tokenizer: 't'
+ steps:
+ - to: "log:info3"
+
`
-func TestJYamlFlow(t *testing.T) {
+func TestJYaml(t *testing.T) {
source := v1alpha1.SourceSpec{
DataSpec: v1alpha1.DataSpec{
Name: "test",
- Content: yamlFlow,
+ Content: yaml,
},
- Language: v1alpha1.LanguageYamlFlow,
+ Language: v1alpha1.LanguageYaml,
}
catalog, err := test.DefaultCatalog()
@@ -285,6 +291,8 @@ func TestJYamlFlow(t *testing.T) {
assert.Len(t, metadata.FromURIs, 1)
assert.NotEmpty(t, metadata.ToURIs)
- assert.Contains(t, metadata.ToURIs, "log:info")
- assert.Len(t, metadata.ToURIs, 1)
+ assert.Contains(t, metadata.ToURIs, "log:info1")
+ assert.Contains(t, metadata.ToURIs, "log:info2")
+ assert.Contains(t, metadata.ToURIs, "log:info3")
+ assert.Len(t, metadata.ToURIs, 3)
}
diff --git a/pkg/trait/dependencies.go b/pkg/trait/dependencies.go
index 12853f3..5a0ad25 100644
--- a/pkg/trait/dependencies.go
+++ b/pkg/trait/dependencies.go
@@ -58,7 +58,7 @@ func (t *dependenciesTrait) Apply(e *Environment) error {
util.StringSliceUniqueAdd(&dependencies,
"runtime:groovy")
case v1alpha1.LanguageKotlin:
util.StringSliceUniqueAdd(&dependencies,
"runtime:kotlin")
- case v1alpha1.LanguageYamlFlow:
+ case v1alpha1.LanguageYaml:
util.StringSliceUniqueAdd(&dependencies, "runtime:yaml")
}
diff --git a/pkg/util/source/inspector.go b/pkg/util/source/inspector.go
index c321101..261a7f8 100644
--- a/pkg/util/source/inspector.go
+++ b/pkg/util/source/inspector.go
@@ -83,8 +83,8 @@ func InspectorForLanguage(catalog *camel.RuntimeCatalog,
language v1alpha1.Langu
catalog: catalog,
},
}
- case v1alpha1.LanguageYamlFlow:
- return &YAMLFlowInspector{
+ case v1alpha1.LanguageYaml:
+ return &YAMLInspector{
baseInspector: baseInspector{
catalog: catalog,
},
@@ -105,6 +105,7 @@ func (i baseInspector) Extract(v1alpha1.SourceSpec,
*Metadata) error {
func (i *baseInspector) discoverDependencies(source v1alpha1.SourceSpec, meta
*Metadata) []string {
uris := util.StringSliceJoin(meta.FromURIs, meta.ToURIs)
candidates := strset.New()
+ candidates.Add(meta.Dependencies...)
for _, uri := range uris {
candidateComp := i.decodeComponent(uri)
diff --git a/pkg/util/source/inspector_yaml.go
b/pkg/util/source/inspector_yaml.go
new file mode 100644
index 0000000..282bc5c
--- /dev/null
+++ b/pkg/util/source/inspector_yaml.go
@@ -0,0 +1,107 @@
+/*
+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 source
+
+import (
+ "fmt"
+
+ "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
+ yaml2 "gopkg.in/yaml.v2"
+)
+
+// YAMLInspector --
+type YAMLInspector struct {
+ baseInspector
+}
+
+// Extract --
+func (inspector YAMLInspector) Extract(source v1alpha1.SourceSpec, meta
*Metadata) error {
+ definitions := make([]map[string]interface{}, 0)
+
+ if err := yaml2.Unmarshal([]byte(source.Content), &definitions); err !=
nil {
+ return err
+ }
+
+ for i := range definitions {
+ definition := definitions[i]
+
+ if len(definition) != 1 {
+ return fmt.Errorf("unable to parse step: %s",
definition)
+ }
+
+ for k, v := range definition {
+ if err := inspector.parseStep(k, v, meta); err != nil {
+ return err
+ }
+ }
+ }
+
+ meta.Dependencies = inspector.discoverDependencies(source, meta)
+
+ return nil
+}
+
+func (inspector YAMLInspector) parseStep(key string, content interface{}, meta
*Metadata) error {
+ var maybeURI string
+
+ switch t := content.(type) {
+ case string:
+ maybeURI = t
+ case map[interface{}]interface{}:
+ if u, ok := t["uri"]; ok {
+ maybeURI = u.(string)
+ }
+ if u, ok := t["steps"]; ok {
+ steps := u.([]interface{})
+
+ for i := range steps {
+ step := steps[i].(map[interface{}]interface{})
+
+ if len(step) != 1 {
+ return fmt.Errorf("unable to parse
step: %v", step)
+ }
+
+ for k, v := range step {
+ switch kt := k.(type) {
+ case fmt.Stringer:
+ if err :=
inspector.parseStep(kt.String(), v, meta); err != nil {
+ return err
+ }
+ case string:
+ if err :=
inspector.parseStep(kt, v, meta); err != nil {
+ return err
+ }
+ default:
+ return fmt.Errorf("unknown key
type: %v, step: %v", k, step)
+ }
+ }
+ }
+ }
+ }
+
+ if maybeURI != "" {
+ switch key {
+ case "from":
+ meta.FromURIs = append(meta.FromURIs, maybeURI)
+ case "to":
+ meta.ToURIs = append(meta.ToURIs, maybeURI)
+ }
+ }
+
+ return nil
+}
diff --git a/pkg/util/source/inspector_yaml_flow.go
b/pkg/util/source/inspector_yaml_flow.go
deleted file mode 100644
index cca6089..0000000
--- a/pkg/util/source/inspector_yaml_flow.go
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
-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 source
-
-import (
- "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
- yaml2 "gopkg.in/yaml.v2"
-)
-
-// YAMLFlowInspector --
-type YAMLFlowInspector struct {
- baseInspector
-}
-
-// Extract --
-func (i YAMLFlowInspector) Extract(source v1alpha1.SourceSpec, meta *Metadata)
error {
- var flows []v1alpha1.Flow
-
- if err := yaml2.Unmarshal([]byte(source.Content), &flows); err != nil {
- return nil
- }
-
- for _, flow := range flows {
- if flow.Steps[0].URI != "" {
- meta.FromURIs = append(meta.FromURIs, flow.Steps[0].URI)
- }
-
- for i := 1; i < len(flow.Steps); i++ {
- if flow.Steps[i].URI != "" {
- meta.ToURIs = append(meta.ToURIs,
flow.Steps[i].URI)
- }
- }
- }
-
- meta.Dependencies = i.discoverDependencies(source, meta)
-
- return nil
-}