You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by pc...@apache.org on 2021/12/28 10:19:57 UTC

[camel-k] 01/02: chore(kamelet): remove bean and ref error handler types

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

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

commit 2c58b44a546bdefc6151f5368889eea39cf90666
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Mon Dec 27 10:39:10 2021 +0100

    chore(kamelet): remove bean and ref error handler types
---
 .../kamelets/kameletbindings-error-handler.adoc    | 51 +----------------
 pkg/apis/camel/v1/zz_generated.deepcopy.go         |  8 +++
 pkg/apis/camel/v1alpha1/error_handler_types.go     | 65 ----------------------
 pkg/apis/camel/v1alpha1/zz_generated.deepcopy.go   | 48 +---------------
 pkg/cmd/bind.go                                    |  8 +--
 pkg/cmd/bind_test.go                               |  6 +-
 pkg/controller/kameletbinding/error_handler.go     |  4 --
 .../kameletbinding/error_handler_test.go           | 31 -----------
 8 files changed, 14 insertions(+), 207 deletions(-)

diff --git a/docs/modules/ROOT/pages/kamelets/kameletbindings-error-handler.adoc b/docs/modules/ROOT/pages/kamelets/kameletbindings-error-handler.adoc
index 57a7d8e..648e05b 100644
--- a/docs/modules/ROOT/pages/kamelets/kameletbindings-error-handler.adoc
+++ b/docs/modules/ROOT/pages/kamelets/kameletbindings-error-handler.adoc
@@ -23,7 +23,7 @@ spec:
 [[kameletbindings-error-handler-types]]
 == Error Handler Types
 
-We have different types of error handler: `ǹone`, `log`, `dead-letter-channel`, `bean`, `ref`. The `errorHandler` parameter is optional.
+We have different types of error handler: `ǹone`, `log` and `dead-letter-channel`. The `errorHandler` parameter is optional.
 
 [[kameletbindings-error-handler-none]]
 === No error handler
@@ -104,52 +104,3 @@ spec:
 <2> Properties belonging to the endpoint (in this example, to the `Kamelet` named error handler)
 <3> Parameters belonging to the `dead-letter-channel` error handler type
 
-[[kameletbindings-error-handler-bean]]
-=== Bean error handler
-
-With the `Bean` error handler you can extend the functionality of the Error Handler by providing a custom bean to be used as Error Handler.
-
-[source,yaml]
-----
-apiVersion: camel.apache.org/v1alpha1
-kind: KameletBinding
-metadata:
-  name: my-kamelet-binding
-spec:
-  source:
-...
-  sink: 
-...
-  errorHandler: 
-    bean:
-      type: "org.apache.camel.builder.DeadLetterChannelBuilder" # <1>
-      properties: # <2>
-        deadLetterUri: log:error
-        ... 
-----
-<1> Fully qualified name of the ErrorHandlerBuilder
-<2> Properties expected by your type
-
-[[kameletbindings-error-handler-ref]]
-=== Ref error handler
-
-With the `Ref` error handler you can use any `Bean` that is expected to be found in the Camel registry at runtime.
-
-[source,yaml]
-----
-apiVersion: camel.apache.org/v1alpha1
-kind: KameletBinding
-metadata:
-  name: my-kamelet-binding
-spec:
-  source:
-...
-  sink: 
-...
-  errorHandler: 
-    ref: my-custom-builder # <1>
-... 
-----
-<1> The name of the bean to be looked up at runtime
-
-NOTE: make sure to have the `ref` correctly bind at runtime.
diff --git a/pkg/apis/camel/v1/zz_generated.deepcopy.go b/pkg/apis/camel/v1/zz_generated.deepcopy.go
index bc44413..f23a7da 100644
--- a/pkg/apis/camel/v1/zz_generated.deepcopy.go
+++ b/pkg/apis/camel/v1/zz_generated.deepcopy.go
@@ -1,3 +1,4 @@
+//go:build !ignore_autogenerated
 // +build !ignore_autogenerated
 
 // Code generated by controller-gen. DO NOT EDIT.
@@ -1023,6 +1024,13 @@ func (in *IntegrationPlatformStatus) DeepCopyInto(out *IntegrationPlatformStatus
 			(*in)[i].DeepCopyInto(&(*out)[i])
 		}
 	}
+	if in.Info != nil {
+		in, out := &in.Info, &out.Info
+		*out = make(map[string]string, len(*in))
+		for key, val := range *in {
+			(*out)[key] = val
+		}
+	}
 }
 
 // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new IntegrationPlatformStatus.
diff --git a/pkg/apis/camel/v1alpha1/error_handler_types.go b/pkg/apis/camel/v1alpha1/error_handler_types.go
index d60074a..c7ebd8a 100644
--- a/pkg/apis/camel/v1alpha1/error_handler_types.go
+++ b/pkg/apis/camel/v1alpha1/error_handler_types.go
@@ -19,7 +19,6 @@ package v1alpha1
 
 import (
 	"encoding/json"
-	"fmt"
 
 	v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
 )
@@ -153,66 +152,6 @@ func (e ErrorHandlerDeadLetterChannel) Configuration() (map[string]interface{},
 	return properties, err
 }
 
-// ErrorHandlerRef represents a reference to an error handler builder available in the registry
-type ErrorHandlerRef struct {
-	baseErrorHandler
-	v1.RawMessage
-}
-
-// Type --
-func (e ErrorHandlerRef) Type() ErrorHandlerType {
-	return ErrorHandlerTypeRef
-}
-
-// Configuration --
-func (e ErrorHandlerRef) Configuration() (map[string]interface{}, error) {
-	var refName string
-	err := json.Unmarshal(e.RawMessage, &refName)
-	if err != nil {
-		return nil, err
-	}
-
-	properties := map[string]interface{}{
-		ErrorHandlerRefName: refName,
-	}
-
-	return properties, nil
-}
-
-// ErrorHandlerBean represents a bean error handler type
-type ErrorHandlerBean struct {
-	ErrorHandlerNone
-	BeanType       *string         `json:"type,omitempty"`
-	BeanProperties *BeanProperties `json:"properties,omitempty"`
-}
-
-// Type --
-func (e ErrorHandlerBean) Type() ErrorHandlerType {
-	return ErrorHandlerTypeBean
-}
-
-// Configuration --
-func (e ErrorHandlerBean) Configuration() (map[string]interface{}, error) {
-	properties, err := e.ErrorHandlerNone.Configuration()
-	if err != nil {
-		return nil, err
-	}
-	properties[ErrorHandlerAppPropertiesPrefix] = fmt.Sprintf("#class:%v", *e.BeanType)
-
-	if e.BeanProperties != nil {
-		var beanProperties map[string]interface{}
-		err := json.Unmarshal(e.BeanProperties.RawMessage, &beanProperties)
-		if err != nil {
-			return nil, err
-		}
-		for key, value := range beanProperties {
-			properties[ErrorHandlerAppPropertiesPrefix+"."+key] = value
-		}
-	}
-
-	return properties, err
-}
-
 // ErrorHandlerType --
 type ErrorHandlerType string
 
@@ -224,8 +163,4 @@ const (
 	ErrorHandlerTypeLog ErrorHandlerType = "log"
 	// ErrorHandlerTypeDeadLetterChannel --
 	ErrorHandlerTypeDeadLetterChannel ErrorHandlerType = "dead-letter-channel"
-	// ErrorHandlerTypeRef --
-	ErrorHandlerTypeRef ErrorHandlerType = "ref"
-	// ErrorHandlerTypeBean --
-	ErrorHandlerTypeBean ErrorHandlerType = "bean"
 )
diff --git a/pkg/apis/camel/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/camel/v1alpha1/zz_generated.deepcopy.go
index 4bbf8b6..c492985 100644
--- a/pkg/apis/camel/v1alpha1/zz_generated.deepcopy.go
+++ b/pkg/apis/camel/v1alpha1/zz_generated.deepcopy.go
@@ -1,3 +1,4 @@
+//go:build !ignore_autogenerated
 // +build !ignore_autogenerated
 
 // Code generated by controller-gen. DO NOT EDIT.
@@ -104,32 +105,6 @@ func (in *EndpointProperties) DeepCopy() *EndpointProperties {
 }
 
 // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
-func (in *ErrorHandlerBean) DeepCopyInto(out *ErrorHandlerBean) {
-	*out = *in
-	out.ErrorHandlerNone = in.ErrorHandlerNone
-	if in.BeanType != nil {
-		in, out := &in.BeanType, &out.BeanType
-		*out = new(string)
-		**out = **in
-	}
-	if in.BeanProperties != nil {
-		in, out := &in.BeanProperties, &out.BeanProperties
-		*out = new(BeanProperties)
-		(*in).DeepCopyInto(*out)
-	}
-}
-
-// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ErrorHandlerBean.
-func (in *ErrorHandlerBean) DeepCopy() *ErrorHandlerBean {
-	if in == nil {
-		return nil
-	}
-	out := new(ErrorHandlerBean)
-	in.DeepCopyInto(out)
-	return out
-}
-
-// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
 func (in *ErrorHandlerDeadLetterChannel) DeepCopyInto(out *ErrorHandlerDeadLetterChannel) {
 	*out = *in
 	in.ErrorHandlerLog.DeepCopyInto(&out.ErrorHandlerLog)
@@ -208,27 +183,6 @@ func (in *ErrorHandlerParameters) DeepCopy() *ErrorHandlerParameters {
 }
 
 // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
-func (in *ErrorHandlerRef) DeepCopyInto(out *ErrorHandlerRef) {
-	*out = *in
-	out.baseErrorHandler = in.baseErrorHandler
-	if in.RawMessage != nil {
-		in, out := &in.RawMessage, &out.RawMessage
-		*out = make(v1.RawMessage, len(*in))
-		copy(*out, *in)
-	}
-}
-
-// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ErrorHandlerRef.
-func (in *ErrorHandlerRef) DeepCopy() *ErrorHandlerRef {
-	if in == nil {
-		return nil
-	}
-	out := new(ErrorHandlerRef)
-	in.DeepCopyInto(out)
-	return out
-}
-
-// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
 func (in *ErrorHandlerSpec) DeepCopyInto(out *ErrorHandlerSpec) {
 	*out = *in
 	if in.RawMessage != nil {
diff --git a/pkg/cmd/bind.go b/pkg/cmd/bind.go
index 019c1ff..396b3b2 100644
--- a/pkg/cmd/bind.go
+++ b/pkg/cmd/bind.go
@@ -58,7 +58,7 @@ func newCmdBind(rootCmdOptions *RootCmdOptions) (*cobra.Command, *bindCmdOptions
 	}
 
 	cmd.Flags().StringArrayP("connect", "c", nil, "A ServiceBinding or Provisioned Service that the integration should bind to, specified as [[apigroup/]version:]kind:[namespace/]name")
-	cmd.Flags().String("error-handler", "", `Add error handler (none|log|dlc:<endpoint>|bean:<type>|ref:<registry-ref>). DLC endpoints are expected in the format "[[apigroup/]version:]kind:[namespace/]name", plain Camel URIs or Kamelet name.`)
+	cmd.Flags().String("error-handler", "", `Add error handler (none|log|dlc:<endpoint>). DLC endpoints are expected in the format "[[apigroup/]version:]kind:[namespace/]name", plain Camel URIs or Kamelet name.`)
 	cmd.Flags().String("name", "", "Name for the binding")
 	cmd.Flags().StringP("output", "o", "", "Output format. One of: json|yaml")
 	cmd.Flags().StringArrayP("property", "p", nil, `Add a binding property in the form of "source.<key>=<value>", "sink.<key>=<value>", "error-handler.<key>=<value>" or "step-<n>.<key>=<value>"`)
@@ -247,12 +247,6 @@ func (o *bindCmdOptions) parseErrorHandler() (*v1alpha1.ErrorHandlerSpec, error)
 		errHandlMap["dead-letter-channel"] = map[string]interface{}{
 			"endpoint": dlcSpec,
 		}
-	case "bean":
-		errHandlMap["bean"] = map[string]interface{}{
-			"type": errHandlValue,
-		}
-	case "ref":
-		errHandlMap["ref"] = errHandlValue
 	default:
 		return nil, fmt.Errorf("invalid error handler type %s", o.ErrorHandler)
 	}
diff --git a/pkg/cmd/bind_test.go b/pkg/cmd/bind_test.go
index a23ee91..0065fb9 100644
--- a/pkg/cmd/bind_test.go
+++ b/pkg/cmd/bind_test.go
@@ -139,10 +139,10 @@ status: {}
 `, output)
 }
 
-func TestBindErrorHandlerRef(t *testing.T) {
+func TestBindErrorHandlerLog(t *testing.T) {
 	buildCmdOptions, bindCmd, _ := initializeBindCmdOptions(t)
 	output, err := test.ExecuteCommand(bindCmd, cmdBind, "my:src", "my:dst", "-o", "yaml",
-		"--error-handler", "ref:my-registry-reference")
+		"--error-handler", "log")
 	assert.Equal(t, "yaml", buildCmdOptions.OutputFormat)
 
 	assert.Nil(t, err)
@@ -153,7 +153,7 @@ metadata:
   name: my-to-my
 spec:
   errorHandler:
-    ref: my-registry-reference
+    log: null
   sink:
     uri: my:dst
   source:
diff --git a/pkg/controller/kameletbinding/error_handler.go b/pkg/controller/kameletbinding/error_handler.go
index df52dc2..e240e52 100644
--- a/pkg/controller/kameletbinding/error_handler.go
+++ b/pkg/controller/kameletbinding/error_handler.go
@@ -76,10 +76,6 @@ func parseErrorHandler(rawMessage v1.RawMessage) (v1alpha1.ErrorHandler, error)
 			dst = new(v1alpha1.ErrorHandlerLog)
 		case v1alpha1.ErrorHandlerTypeDeadLetterChannel:
 			dst = new(v1alpha1.ErrorHandlerDeadLetterChannel)
-		case v1alpha1.ErrorHandlerTypeRef:
-			dst = new(v1alpha1.ErrorHandlerRef)
-		case v1alpha1.ErrorHandlerTypeBean:
-			dst = new(v1alpha1.ErrorHandlerBean)
 		default:
 			return nil, errors.Errorf("Unknown error handler type %s", errHandlType)
 		}
diff --git a/pkg/controller/kameletbinding/error_handler_test.go b/pkg/controller/kameletbinding/error_handler_test.go
index 94e6643..c182ad1 100644
--- a/pkg/controller/kameletbinding/error_handler_test.go
+++ b/pkg/controller/kameletbinding/error_handler_test.go
@@ -101,34 +101,3 @@ func TestParseErrorHandlerDLCWithParametersDoesSucceed(t *testing.T) {
 	assert.Equal(t, "value1", parameters["camel.beans.defaultErrorHandler.param1"])
 	assert.Equal(t, "value2", parameters["camel.beans.defaultErrorHandler.param2"])
 }
-
-func TestParseErrorHandlerBeanWithParamsDoesSucceed(t *testing.T) {
-	beanErrorHandler, err := parseErrorHandler(
-		[]byte(`{
-			"bean": {
-				"type": "com.acme.MyType",
-				"properties": 
-					{"beanProp1": "value1", "beanProp2": "value2"}
-			}
-		}`),
-	)
-	assert.Nil(t, err)
-	assert.Equal(t, v1alpha1.ErrorHandlerTypeBean, beanErrorHandler.Type())
-	parameters, err := beanErrorHandler.Configuration()
-	assert.Nil(t, err)
-	assert.Equal(t, "#class:com.acme.MyType", parameters[v1alpha1.ErrorHandlerAppPropertiesPrefix])
-	assert.Equal(t, v1alpha1.ErrorHandlerRefDefaultName, parameters[v1alpha1.ErrorHandlerRefName])
-	assert.Equal(t, "value1", parameters["camel.beans.defaultErrorHandler.beanProp1"])
-	assert.Equal(t, "value2", parameters["camel.beans.defaultErrorHandler.beanProp2"])
-}
-
-func TestParseErrorHandlerRefDoesSucceed(t *testing.T) {
-	refErrorHandler, err := parseErrorHandler(
-		[]byte(`{"ref": "my-registry-ref"}`),
-	)
-	assert.Nil(t, err)
-	assert.Equal(t, v1alpha1.ErrorHandlerTypeRef, refErrorHandler.Type())
-	parameters, err := refErrorHandler.Configuration()
-	assert.Nil(t, err)
-	assert.Equal(t, "my-registry-ref", parameters[v1alpha1.ErrorHandlerRefName])
-}