You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by nf...@apache.org on 2018/11/22 13:50:31 UTC

[camel-k] 02/02: fix findings

This is an automated email from the ASF dual-hosted git repository.

nferraro pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit 3e9d907fec2e08ea00d923a7d120e287bf0373d8
Author: lburgazzoli <lb...@gmail.com>
AuthorDate: Thu Nov 22 14:24:11 2018 +0100

    fix findings
---
 pkg/client/cmd/run.go                                  | 11 +++++------
 pkg/metadata/metadata.go                               | 11 +++++++++++
 pkg/trait/deployment.go                                |  8 ++++----
 pkg/trait/knative.go                                   | 18 +++++++++---------
 .../main/java/org/apache/camel/k/jvm/URIResolver.java  |  2 +-
 5 files changed, 30 insertions(+), 20 deletions(-)

diff --git a/pkg/client/cmd/run.go b/pkg/client/cmd/run.go
index bfc0445..490adfe 100644
--- a/pkg/client/cmd/run.go
+++ b/pkg/client/cmd/run.go
@@ -115,7 +115,7 @@ func (o *runCmdOptions) validateArgs(cmd *cobra.Command, args []string) error {
 		return errors.New("accepts at least 1 arg, received 0")
 	}
 	if len(args) > 1 && o.IntegrationName == "" {
-		return errors.New("integration name is mandatory when loading multiple integrations")
+		return errors.New("integration name is mandatory when using multiple sources")
 	}
 
 	for _, fileName := range args {
@@ -258,11 +258,10 @@ func (o *runCmdOptions) updateIntegrationCode(sources []string) (*v1alpha1.Integ
 		name = kubernetes.SanitizeName(name)
 	} else if len(sources) == 1 {
 		name = kubernetes.SanitizeName(sources[0])
-		if name == "" {
-			name = "integration"
-		}
-	} else {
-		return nil, errors.New("invalid argument combination")
+	}
+
+	if name == "" {
+		return nil, errors.New("unable to determine integration name")
 	}
 
 	integration := v1alpha1.Integration{
diff --git a/pkg/metadata/metadata.go b/pkg/metadata/metadata.go
index 46a7aef..6e43b0b 100644
--- a/pkg/metadata/metadata.go
+++ b/pkg/metadata/metadata.go
@@ -34,3 +34,14 @@ func Extract(source v1alpha1.SourceSpec) IntegrationMetadata {
 		Dependencies: dependencies,
 	}
 }
+
+// Each --
+func Each(sources []v1alpha1.SourceSpec, consumer func(int, IntegrationMetadata) bool) {
+	for i, s := range sources {
+		meta := Extract(s)
+
+		if !consumer(i, meta) {
+			break
+		}
+	}
+}
diff --git a/pkg/trait/deployment.go b/pkg/trait/deployment.go
index cc16ef1..bc3f121 100644
--- a/pkg/trait/deployment.go
+++ b/pkg/trait/deployment.go
@@ -43,8 +43,8 @@ func (d *deploymentTrait) appliesTo(e *Environment) bool {
 }
 
 func (d *deploymentTrait) apply(e *Environment) error {
-	e.Resources.AddAll(d.getConfigMapFor(e))
-	e.Resources.Add(d.getDeploymentFor(e))
+	e.Resources.AddAll(getConfigMapsFor(e))
+	e.Resources.Add(getDeploymentFor(e))
 	return nil
 }
 
@@ -54,7 +54,7 @@ func (d *deploymentTrait) apply(e *Environment) error {
 //
 // **********************************
 
-func (*deploymentTrait) getConfigMapFor(e *Environment) []runtime.Object {
+func getConfigMapsFor(e *Environment) []runtime.Object {
 	maps := make([]runtime.Object, 0, len(e.Integration.Spec.Sources)+1)
 
 	// combine properties of integration with context, integration
@@ -116,7 +116,7 @@ func (*deploymentTrait) getConfigMapFor(e *Environment) []runtime.Object {
 //
 // **********************************
 
-func (*deploymentTrait) getDeploymentFor(e *Environment) *appsv1.Deployment {
+func getDeploymentFor(e *Environment) *appsv1.Deployment {
 	sources := make([]string, 0, len(e.Integration.Spec.Sources))
 	for i, s := range e.Integration.Spec.Sources {
 		src := fmt.Sprintf("file:/etc/camel/integrations/%03d/%s", i, strings.TrimPrefix(s.Name, "/"))
diff --git a/pkg/trait/knative.go b/pkg/trait/knative.go
index 0b93d87..e463746 100644
--- a/pkg/trait/knative.go
+++ b/pkg/trait/knative.go
@@ -50,7 +50,7 @@ func (t *knativeTrait) appliesTo(e *Environment) bool {
 
 func (t *knativeTrait) autoconfigure(e *Environment) error {
 	if t.Sources == "" {
-		channels := t.getSourceChannels(e)
+		channels := getSourceChannels(e)
 		t.Sources = strings.Join(channels, ",")
 	}
 	return nil
@@ -139,7 +139,7 @@ func (t *knativeTrait) getServiceFor(e *Environment) *serving.Service {
 }
 
 func (t *knativeTrait) getSubscriptionsFor(e *Environment) []*eventing.Subscription {
-	channels := t.getConfiguredSourceChannels()
+	channels := getConfiguredSourceChannels(t.Sources)
 	subs := make([]*eventing.Subscription, 0)
 	for _, ch := range channels {
 		subs = append(subs, t.getSubscriptionFor(e, ch))
@@ -185,7 +185,7 @@ func (t *knativeTrait) getConfigurationSerialized(e *Environment) string {
 }
 
 func (t *knativeTrait) getConfiguration(e *Environment) knativeutil.CamelEnvironment {
-	sourceChannels := t.getConfiguredSourceChannels()
+	sourceChannels := getConfiguredSourceChannels(t.Sources)
 	env := knativeutil.NewCamelEnvironment()
 	for _, ch := range sourceChannels {
 		svc := knativeutil.CamelServiceDefinition{
@@ -215,9 +215,9 @@ func (t *knativeTrait) getConfiguration(e *Environment) knativeutil.CamelEnviron
 	return env
 }
 
-func (t *knativeTrait) getConfiguredSourceChannels() []string {
+func getConfiguredSourceChannels(sources string) []string {
 	channels := make([]string, 0)
-	for _, ch := range strings.Split(t.Sources, ",") {
+	for _, ch := range strings.Split(sources, ",") {
 		cht := strings.Trim(ch, " \t\"")
 		if cht != "" {
 			channels = append(channels, cht)
@@ -226,13 +226,13 @@ func (t *knativeTrait) getConfiguredSourceChannels() []string {
 	return channels
 }
 
-func (*knativeTrait) getSourceChannels(e *Environment) []string {
+func getSourceChannels(e *Environment) []string {
 	channels := make([]string, 0)
 
-	for _, s := range e.Integration.Spec.Sources {
-		meta := metadata.Extract(s)
+	metadata.Each(e.Integration.Spec.Sources, func(_ int, meta metadata.IntegrationMetadata) bool {
 		channels = append(channels, knativeutil.ExtractChannelNames(meta.FromURIs)...)
-	}
+		return true
+	})
 
 	return channels
 }
diff --git a/runtime/jvm/src/main/java/org/apache/camel/k/jvm/URIResolver.java b/runtime/jvm/src/main/java/org/apache/camel/k/jvm/URIResolver.java
index 12ade89..69fb640 100644
--- a/runtime/jvm/src/main/java/org/apache/camel/k/jvm/URIResolver.java
+++ b/runtime/jvm/src/main/java/org/apache/camel/k/jvm/URIResolver.java
@@ -46,7 +46,7 @@ public class URIResolver {
 
     public static Reader resolveEnv(String uri) {
         if (!uri.startsWith(Constants.SCHEME_ENV)) {
-            throw new IllegalArgumentException("The provided content is not inline: " + uri);
+            throw new IllegalArgumentException("The provided content is not env: " + uri);
         }
 
         final String envvar = StringHelper.after(uri, ":");