Skip to content
This repository has been archived by the owner on Dec 11, 2023. It is now read-only.

Commit

Permalink
CE transformation improvements (#297)
Browse files Browse the repository at this point in the history
* Transformation event types automation. Core dependency update

* Docs update
  • Loading branch information
tzununbekov authored Apr 18, 2023
1 parent 335acc1 commit a555b66
Show file tree
Hide file tree
Showing 26 changed files with 88 additions and 36 deletions.
31 changes: 29 additions & 2 deletions cmd/create/transformation.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ func (o *CliOptions) transformation(name, target, file string, eventSourcesFilte
targetComponent = t
}

var expectedEventTypes []string
if consumer, ok := targetComponent.(triggermesh.Consumer); ok {
expectedEventTypes, _ = consumer.ConsumedEventTypes()
}

et, err := o.translateEventSource(eventSourcesFilter)
if err != nil {
return err
Expand Down Expand Up @@ -151,15 +156,37 @@ func (o *CliOptions) transformation(name, target, file string, eventSourcesFilte
t := transformation.New(name, "transformation", o.Config.Context, o.Config.Triggermesh.ComponentsVersion, crd, spec)

transformationEventType := fmt.Sprintf("%s.output", t.GetName())
if et, _ := t.(triggermesh.Producer).GetEventTypes(); len(et) == 0 {
if len(expectedEventTypes) > 0 {
transformationEventType = expectedEventTypes[0]
}

producedEventTypes, _ := t.(triggermesh.Producer).GetEventTypes()
if len(producedEventTypes) == 0 {
if err := t.(triggermesh.Producer).SetEventAttributes(map[string]string{
"type": transformationEventType,
}); err != nil {
return fmt.Errorf("setting event type: %w", err)
}
} else {
transformationEventType = et[0]
transformationEventType = producedEventTypes[0]
}

eventTypesMatch := false
if len(expectedEventTypes) == 0 {
eventTypesMatch = true
}
for _, eet := range expectedEventTypes {
if eet == transformationEventType {
eventTypesMatch = true
break
}
}

if targetComponent != nil && !eventTypesMatch {
log.Printf(`WARNING! The transformation produces events of %q type, while target %q expectes %s. The target adapter may not work in this configuration.`,
transformationEventType, targetComponent.GetName(), strings.Join(expectedEventTypes, ","))
}

log.Println("Updating manifest")
restart, err := o.Manifest.Add(t)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion docs/tmctl.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Find more information at: https://docs.triggermesh.io

```
-h, --help help for tmctl
--version string TriggerMesh components version. (default "v1.24.0")
--version string TriggerMesh components version. (default "v1.24.4")
```

### SEE ALSO
Expand Down
2 changes: 1 addition & 1 deletion docs/tmctl_brokers.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ tmctl brokers [--set <broker>] [flags]
### Options inherited from parent commands

```
--version string TriggerMesh components version. (default "v1.24.0")
--version string TriggerMesh components version. (default "v1.24.4")
```

### SEE ALSO
Expand Down
2 changes: 1 addition & 1 deletion docs/tmctl_config.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ tmctl config [set|get] [flags]
### Options inherited from parent commands

```
--version string TriggerMesh components version. (default "v1.24.0")
--version string TriggerMesh components version. (default "v1.24.4")
```

### SEE ALSO
Expand Down
2 changes: 1 addition & 1 deletion docs/tmctl_config_get.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ tmctl config get [key] [flags]
### Options inherited from parent commands

```
--version string TriggerMesh components version. (default "v1.24.0")
--version string TriggerMesh components version. (default "v1.24.4")
```

### SEE ALSO
Expand Down
2 changes: 1 addition & 1 deletion docs/tmctl_config_set.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ tmctl config set <key> <value> [flags]
### Options inherited from parent commands

```
--version string TriggerMesh components version. (default "v1.24.0")
--version string TriggerMesh components version. (default "v1.24.4")
```

### SEE ALSO
Expand Down
2 changes: 1 addition & 1 deletion docs/tmctl_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Create TriggerMesh component
### Options inherited from parent commands

```
--version string TriggerMesh components version. (default "v1.24.0")
--version string TriggerMesh components version. (default "v1.24.4")
```

### SEE ALSO
Expand Down
2 changes: 1 addition & 1 deletion docs/tmctl_create_broker.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ tmctl create broker foo

```
-h, --help help for broker
--version string TriggerMesh broker version. (default "v1.2.0")
--version string TriggerMesh broker version. (default "v1.2.1")
```

### SEE ALSO
Expand Down
2 changes: 1 addition & 1 deletion docs/tmctl_create_source.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ tmctl create source httppoller \
### Options inherited from parent commands

```
--version string TriggerMesh components version. (default "v1.24.0")
--version string TriggerMesh components version. (default "v1.24.4")
```

### SEE ALSO
Expand Down
2 changes: 1 addition & 1 deletion docs/tmctl_create_target.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ tmctl create target http \
### Options inherited from parent commands

```
--version string TriggerMesh components version. (default "v1.24.0")
--version string TriggerMesh components version. (default "v1.24.4")
```

### SEE ALSO
Expand Down
2 changes: 1 addition & 1 deletion docs/tmctl_create_transformation.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ EOF
### Options inherited from parent commands

```
--version string TriggerMesh components version. (default "v1.24.0")
--version string TriggerMesh components version. (default "v1.24.4")
```

### SEE ALSO
Expand Down
2 changes: 1 addition & 1 deletion docs/tmctl_create_trigger.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ tmctl create trigger --target sockeye --source foo-httppollersource
### Options inherited from parent commands

```
--version string TriggerMesh components version. (default "v1.24.0")
--version string TriggerMesh components version. (default "v1.24.4")
```

### SEE ALSO
Expand Down
2 changes: 1 addition & 1 deletion docs/tmctl_delete.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ tmctl delete --broker foo
### Options inherited from parent commands

```
--version string TriggerMesh components version. (default "v1.24.0")
--version string TriggerMesh components version. (default "v1.24.4")
```

### SEE ALSO
Expand Down
2 changes: 1 addition & 1 deletion docs/tmctl_describe.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ tmctl describe
### Options inherited from parent commands

```
--version string TriggerMesh components version. (default "v1.24.0")
--version string TriggerMesh components version. (default "v1.24.4")
```

### SEE ALSO
Expand Down
2 changes: 1 addition & 1 deletion docs/tmctl_dump.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ tmctl dump
### Options inherited from parent commands

```
--version string TriggerMesh components version. (default "v1.24.0")
--version string TriggerMesh components version. (default "v1.24.4")
```

### SEE ALSO
Expand Down
2 changes: 1 addition & 1 deletion docs/tmctl_import.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ tmctl import -f manifest.yaml
### Options inherited from parent commands

```
--version string TriggerMesh components version. (default "v1.24.0")
--version string TriggerMesh components version. (default "v1.24.4")
```

### SEE ALSO
Expand Down
2 changes: 1 addition & 1 deletion docs/tmctl_logs.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ tmctl logs
### Options inherited from parent commands

```
--version string TriggerMesh components version. (default "v1.24.0")
--version string TriggerMesh components version. (default "v1.24.4")
```

### SEE ALSO
Expand Down
2 changes: 1 addition & 1 deletion docs/tmctl_send-event.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ tmctl send-event '{"hello":"world"}'
### Options inherited from parent commands

```
--version string TriggerMesh components version. (default "v1.24.0")
--version string TriggerMesh components version. (default "v1.24.4")
```

### SEE ALSO
Expand Down
2 changes: 1 addition & 1 deletion docs/tmctl_start.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ tmctl start
### Options inherited from parent commands

```
--version string TriggerMesh components version. (default "v1.24.0")
--version string TriggerMesh components version. (default "v1.24.4")
```

### SEE ALSO
Expand Down
2 changes: 1 addition & 1 deletion docs/tmctl_stop.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ tmctl stop
### Options inherited from parent commands

```
--version string TriggerMesh components version. (default "v1.24.0")
--version string TriggerMesh components version. (default "v1.24.4")
```

### SEE ALSO
Expand Down
2 changes: 1 addition & 1 deletion docs/tmctl_version.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ tmctl version [flags]
### Options inherited from parent commands

```
--version string TriggerMesh components version. (default "v1.24.0")
--version string TriggerMesh components version. (default "v1.24.4")
```

### SEE ALSO
Expand Down
2 changes: 1 addition & 1 deletion docs/tmctl_watch.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ tmctl watch
### Options inherited from parent commands

```
--version string TriggerMesh components version. (default "v1.24.0")
--version string TriggerMesh components version. (default "v1.24.4")
```

### SEE ALSO
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require (
github.com/spf13/cobra v1.6.1
github.com/stretchr/testify v1.8.2
github.com/triggermesh/brokers v1.2.0
github.com/triggermesh/triggermesh v1.24.0
github.com/triggermesh/triggermesh v1.24.4
github.com/triggermesh/triggermesh-core v1.2.0
google.golang.org/api v0.108.0
gopkg.in/yaml.v3 v3.0.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1005,6 +1005,8 @@ github.com/triggermesh/brokers v1.2.0 h1:YzO+uiyw6e8tPO2Gt/sZxU2yO58EzExit/YT7eX
github.com/triggermesh/brokers v1.2.0/go.mod h1:aL+X0l1Tss73Dva9fZ/aXbS3yu/aCE6cZVY+vZZD9Bk=
github.com/triggermesh/triggermesh v1.24.0 h1:gSZt6SOF2d2FzuV8dMtqotKb7s3yBBN1Te2NPEBw9Pc=
github.com/triggermesh/triggermesh v1.24.0/go.mod h1:QsT5rGh8b4EzsFIhutiV0jCyVFSTIG1yyt3+IACOlho=
github.com/triggermesh/triggermesh v1.24.4 h1:4gwp6jg4lUZKyPS8XjYyBRdzvWKwFPfFefnyZtlrG94=
github.com/triggermesh/triggermesh v1.24.4/go.mod h1:QsT5rGh8b4EzsFIhutiV0jCyVFSTIG1yyt3+IACOlho=
github.com/triggermesh/triggermesh-core v1.2.0 h1:QdX8PaNs6Q0wwRutmNwfdx9JGyV7GX3GxaesOUCcefs=
github.com/triggermesh/triggermesh-core v1.2.0/go.mod h1:4weCl+2VFvo2qCID3umRDPVKCTQCKuL5G5+eC+MAGLc=
github.com/tsenart/go-tsz v0.0.0-20180814232043-cdeb9e1e981e/go.mod h1:SWZznP1z5Ki7hDT2ioqiFKEse8K9tU2OUvaRI0NeGQo=
Expand Down
10 changes: 9 additions & 1 deletion pkg/triggermesh/adapter/ce/targets.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,15 @@ func targets(object unstructured.Unstructured) (EventAttributes, error) {
AcceptedEventTypes: o.AcceptedEventTypes(),
}, nil
case "HTTPTarget":
return EventAttributes{}, nil
var o *targetsv1alpha1.HTTPTarget
if err := runtime.DefaultUnstructuredConverter.FromUnstructured(object.Object, &o); err != nil {
return EventAttributes{}, err
}
return EventAttributes{
ProducedEventTypes: o.GetEventTypes(),
ProducedEventSource: o.AsEventSource(),
AcceptedEventTypes: o.AcceptedEventTypes(),
}, nil
case "IBMMQTarget":
var o *targetsv1alpha1.IBMMQTarget
if err := runtime.DefaultUnstructuredConverter.FromUnstructured(object.Object, &o); err != nil {
Expand Down
37 changes: 26 additions & 11 deletions pkg/triggermesh/components/transformation/transformation.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,18 +320,33 @@ func (t *Transformation) getContextTransformationValue(key string) []string {
return []string{}
}
for _, op := range contextTransformation.([]interface{}) {
if opp, ok := op.(map[string]interface{}); ok {
if opp["operation"] == "add" {
if p, ok := opp["paths"].([]interface{}); ok {
for _, pp := range p {
if pm, ok := pp.(map[string]interface{}); ok {
if pm["key"] == key {
return []string{pm["value"].(string)}
}
}
}
}
spec, ok := op.(map[string]interface{})
if !ok {
continue
}
if spec["operation"] != "add" {
continue
}
paths, ok := spec["paths"].([]interface{})
if !ok {
continue
}
for _, path := range paths {
pm, ok := path.(map[string]interface{})
if !ok {
continue
}
if pm["key"] != key {
continue
}
val, ok := pm["value"]
if !ok {
continue
}
if val == nil {
continue
}
return []string{val.(string)}
}
}
return []string{}
Expand Down

0 comments on commit a555b66

Please sign in to comment.