This is an automated email from the ASF dual-hosted git repository. nferraro pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit bb48d9ae9e482117d474027320dc1a222a0b1618 Author: Pasquale Congiusti <[email protected]> AuthorDate: Fri Apr 23 10:04:58 2021 +0200 feat(trait): error handler Ref --- pkg/apis/camel/v1alpha1/error_handler_types.go | 42 ++++++++++++++++++++++++++ pkg/controller/kameletbinding/error_handler.go | 6 ++++ pkg/trait/error_handler.go | 3 ++ 3 files changed, 51 insertions(+) diff --git a/pkg/apis/camel/v1alpha1/error_handler_types.go b/pkg/apis/camel/v1alpha1/error_handler_types.go index df46324..949fbd6 100644 --- a/pkg/apis/camel/v1alpha1/error_handler_types.go +++ b/pkg/apis/camel/v1alpha1/error_handler_types.go @@ -36,6 +36,7 @@ type AbstractErrorHandler interface { Type() ErrorHandlerType Params() *ErrorHandlerProperties Endpoint() *Endpoint + Ref() *string } // ErrorHandlerNone -- @@ -62,6 +63,11 @@ func (e ErrorHandlerNone) Endpoint() *Endpoint { return nil } +// Ref -- +func (e ErrorHandlerNone) Ref() *string { + return nil +} + // ErrorHandlerLog represent a default (log) error handler type type ErrorHandlerLog struct { Parameters *ErrorHandlerProperties `json:"parameters,omitempty"` @@ -82,6 +88,11 @@ func (e ErrorHandlerLog) Endpoint() *Endpoint { return nil } +// Ref -- +func (e ErrorHandlerLog) Ref() *string { + return nil +} + // ErrorHandlerDeadLetterChannel represents a dead letter channel error handler type type ErrorHandlerDeadLetterChannel struct { *ErrorHandlerLog @@ -103,6 +114,35 @@ func (e ErrorHandlerDeadLetterChannel) Endpoint() *Endpoint { return e.DLCEndpoint } +// Ref -- +func (e ErrorHandlerDeadLetterChannel) Ref() *string { + return nil +} + +// ErrorHandlerRef represents a reference to an error handler builder available in the registry +type ErrorHandlerRef string + +// Type -- +func (e ErrorHandlerRef) Type() ErrorHandlerType { + return ErrorHandlerTypeRef +} + +// Params -- +func (e ErrorHandlerRef) Params() *ErrorHandlerProperties { + return nil +} + +// Endpoint -- +func (e ErrorHandlerRef) Endpoint() *Endpoint { + return nil +} + +// Ref -- +func (e ErrorHandlerRef) Ref() *string { + s := string(e) + return &s +} + // ErrorHandlerType -- type ErrorHandlerType string @@ -113,4 +153,6 @@ const ( ErrorHandlerTypeLog ErrorHandlerType = "log" // ErrorHandlerTypeDeadLetterChannel -- ErrorHandlerTypeDeadLetterChannel ErrorHandlerType = "dead-letter-channel" + // ErrorHandlerTypeRef -- + ErrorHandlerTypeRef ErrorHandlerType = "ref" ) diff --git a/pkg/controller/kameletbinding/error_handler.go b/pkg/controller/kameletbinding/error_handler.go index 90ba3cc..c9858f9 100644 --- a/pkg/controller/kameletbinding/error_handler.go +++ b/pkg/controller/kameletbinding/error_handler.go @@ -43,6 +43,10 @@ func maybeErrorHandler(errHandlConf v1alpha1.ErrorHandler, bindingContext bindin errorHandlerURI = errorHandler.URI } + if errorHandlerSpec.Type() == v1alpha1.ErrorHandlerTypeRef { + errorHandlerURI = *errorHandlerSpec.Ref() + } + err = setIntegrationErrorHandler(itSpec, errorHandlerURI, errorHandlerSpec) if err != nil { return nil, errors.Wrap(err, "could not set integration error handler") @@ -72,6 +76,8 @@ func parseErrorHandler(rawMessage v1.RawMessage) (v1alpha1.AbstractErrorHandler, dst = new(v1alpha1.ErrorHandlerLog) case v1alpha1.ErrorHandlerTypeDeadLetterChannel: dst = new(v1alpha1.ErrorHandlerDeadLetterChannel) + case v1alpha1.ErrorHandlerTypeRef: + dst = new(v1alpha1.ErrorHandlerRef) default: return nil, errors.Errorf("Unknown error type %s, supported error types are: none, log, dead-letter-channel", errHandlType) } diff --git a/pkg/trait/error_handler.go b/pkg/trait/error_handler.go index e82dcf9..7945372 100644 --- a/pkg/trait/error_handler.go +++ b/pkg/trait/error_handler.go @@ -123,6 +123,9 @@ func parseErrorHandler(errorHandlerSpec v1.ErrorHandlerSpec) (string, error) { } return fmt.Sprintf(`errorHandler(deadLetterChannel("%v")%v);`, errorHandlerSpec.URI, errorHandlerConfiguration), nil + case "ref": + // TODO using URI temporarily, fix it properly + return fmt.Sprintf(`errorHandler("%v");`, errorHandlerSpec.URI), nil } return "", fmt.Errorf("Cannot recognize any error handler of type %s", errorHandlerSpec.Type)
