Skip to content

Commit 5c13e9e

Browse files
Frank Martinezmellistibco
Frank Martinez
authored andcommitted
update triggers to invoke latest RunAction command (#152)
* update triggers to invoke latest RunAction command * activity-return,reply,mapper: add support for running in tester service
1 parent 26723c0 commit 5c13e9e

File tree

11 files changed

+86
-23
lines changed

11 files changed

+86
-23
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ action_metadata.go
2828
activity_metadata.go
2929
trigger_metadata.go
3030

31+
action_metadata.go
32+
activity_metadata.go
33+
trigger_metadata.go
34+
3135
# Compiled Object files, Static and Dynamic libs (Shared Objects)
3236
*.o
3337
*.a

trigger/cli/trigger.go

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package cli
22

33
import (
4-
"context"
54
"encoding/json"
65
"flag"
76
"fmt"
@@ -143,14 +142,24 @@ func (t *CliTrigger) Invoke(actionId string, handlerCfg *trigger.HandlerConfig,
143142
startAttrs, _ := t.metadata.OutputsToAttrs(data, false)
144143

145144
act := action.Get(actionId)
146-
ctx := trigger.NewContextWithData(context.Background(), &trigger.ContextData{Attrs: startAttrs, HandlerCfg: handlerCfg})
147-
_, replyData, err := t.runner.Run(ctx, act, actionId, nil)
145+
146+
ctx := trigger.NewInitialContext(startAttrs, handlerCfg)
147+
results, err := t.runner.RunAction(ctx, act, nil)
148148

149149
if err != nil {
150150
log.Debugf("CLI Trigger Error: %s", err.Error())
151151
return "", err
152152
}
153153

154+
var replyData interface{}
155+
156+
if len(results) != 0 {
157+
dataAttr, ok := results["data"]
158+
if ok {
159+
replyData = dataAttr.Value
160+
}
161+
}
162+
154163
if replyData != nil {
155164
data, err := json.Marshal(replyData)
156165
if err != nil {

trigger/cli/trigger.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,18 @@
77
"title": "CLI Trigger",
88
"description": "Simple CLI Trigger",
99
"homepage": "https://github.com/TIBCOSoftware/flogo-contrib/tree/master/trigger/cli",
10-
"outputs": [
10+
"output": [
1111
{
1212
"name": "args",
1313
"type": "array"
1414
}
1515
],
16+
"reply": [
17+
{
18+
"name": "data",
19+
"type": "object"
20+
}
21+
],
1622
"handler": {
1723
"settings": [
1824
{

trigger/coap/trigger.go

+3-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package coap
22

33
import (
44
"bytes"
5-
"context"
65
"fmt"
76
"net"
87
"net/url"
@@ -228,10 +227,9 @@ func newActionHandler(rt *CoapTrigger, resource *CoapResource) coap.Handler {
228227
//rh.addr2 = addr
229228
//rh.conn = conn
230229

231-
action := action.Get(actionId)
232-
233-
context := trigger.NewContext(context.Background(), startAttrs)
234-
_, _, err := rt.runner.Run(context, action, actionId, nil)
230+
act := action.Get(actionId)
231+
ctx := trigger.NewInitialContext(startAttrs, nil)
232+
_, err := rt.runner.RunAction(ctx, act, nil)
235233

236234
if err != nil {
237235
//todo determining if 404 or 500

trigger/lambda/trigger.go

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package lambda
22

33
import (
4-
"context"
54
"encoding/json"
65
"flag"
76

@@ -99,8 +98,18 @@ func Invoke() (interface{}, error) {
9998
}
10099

101100
act := action.Get(actionId)
102-
ctx := trigger.NewContextWithData(context.Background(), &trigger.ContextData{Attrs: startAttrs, HandlerCfg: singleton.config.Handlers[0]})
103-
_, replyData, err := singleton.runner.Run(ctx, act, actionId, nil)
101+
102+
ctx := trigger.NewInitialContext(startAttrs, singleton.config.Handlers[0])
103+
results, err := singleton.runner.RunAction(ctx, act, nil)
104+
105+
var replyData interface{}
106+
107+
if len(results) != 0 {
108+
dataAttr, ok := results["data"]
109+
if ok {
110+
replyData = dataAttr.Value
111+
}
112+
}
104113

105114
if err != nil {
106115
log.Debugf("Lambda Trigger Error: %s", err.Error())

trigger/lambda/trigger.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"homepage": "https://github.com/TIBCOSoftware/flogo-contrib/tree/master/trigger/lambda",
1010
"settings": [
1111
],
12-
"outputs": [
12+
"output": [
1313
{
1414
"name": "logStreamName",
1515
"type": "string"
@@ -30,5 +30,11 @@
3030
"name": "evt",
3131
"type": "object"
3232
}
33+
],
34+
"reply": [
35+
{
36+
"name": "data",
37+
"type": "object"
38+
}
3339
]
3440
}

trigger/mqtt/trigger.go

+15-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package mqtt
22

33
import (
4-
"context"
54
"encoding/json"
65
"strconv"
76
"time"
@@ -141,14 +140,26 @@ func (t *MqttTrigger) RunAction(actionURI string, payload string) {
141140
//todo handle error
142141
startAttrs, _ := t.metadata.OutputsToAttrs(req.Data, false)
143142

144-
action := action.Get(actionURI)
145-
context := trigger.NewContext(context.Background(), startAttrs)
146-
_, replyData, err := t.runner.Run(context, action, actionURI, nil)
143+
act := action.Get(actionURI)
144+
145+
//add handlerCfg to handle return mappings
146+
ctx := trigger.NewInitialContext(startAttrs, nil)
147+
results, err := t.runner.RunAction(ctx, act, nil)
148+
147149
if err != nil {
148150
log.Error("Error starting action: ", err.Error())
149151
}
150152
log.Debugf("Ran action: [%s]", actionURI)
151153

154+
var replyData interface{}
155+
156+
if len(results) != 0 {
157+
dataAttr, ok := results["data"]
158+
if ok {
159+
replyData = dataAttr.Value
160+
}
161+
}
162+
152163
if replyData != nil {
153164
data, err := json.Marshal(replyData)
154165
if err != nil {

trigger/mqtt/trigger.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,18 @@
4141
"type": "boolean"
4242
}
4343
],
44-
"outputs": [
44+
"output": [
4545
{
4646
"name": "message",
4747
"type": "string"
4848
}
4949
],
50+
"reply": [
51+
{
52+
"name": "data",
53+
"type": "object"
54+
}
55+
],
5056
"handler": {
5157
"settings": [
5258
{

trigger/rest/trigger.go

+16-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package rest
22

33
import (
4-
"context"
54
"encoding/json"
65
"fmt"
76
"io"
@@ -156,8 +155,22 @@ func newActionHandler(rt *RestTrigger, actionId string, handlerCfg *trigger.Hand
156155
startAttrs, _ := rt.metadata.OutputsToAttrs(data, false)
157156

158157
act := action.Get(actionId)
159-
ctx := trigger.NewContextWithData(context.Background(), &trigger.ContextData{Attrs: startAttrs, HandlerCfg: handlerCfg})
160-
replyCode, replyData, err := rt.runner.Run(ctx, act, actionId, nil)
158+
ctx := trigger.NewInitialContext(startAttrs, handlerCfg)
159+
results, err := rt.runner.RunAction(ctx, act, nil)
160+
161+
var replyData interface{}
162+
var replyCode int
163+
164+
if len(results) != 0 {
165+
dataAttr, ok := results["data"]
166+
if ok {
167+
replyData = dataAttr.Value
168+
}
169+
codeAttr, ok := results["code"]
170+
if ok {
171+
replyCode = codeAttr.Value.(int)
172+
}
173+
}
161174

162175
if err != nil {
163176
log.Debugf("REST Trigger Error: %s", err.Error())

trigger/rest/trigger.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"required": true
1414
}
1515
],
16-
"outputs": [
16+
"output": [
1717
{
1818
"name": "params",
1919
"type": "params"

trigger/timer/timer.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ func (t *TimerTrigger) scheduleOnce(endpoint *trigger.HandlerConfig) {
111111

112112
if act != nil {
113113
log.Debugf("Running action: %s", endpoint.ActionId)
114-
_, _, err := t.runner.Run(context.Background(), act, endpoint.ActionId, nil)
114+
115+
_, err := t.runner.RunAction(context.Background(), act, nil )
115116

116117
if err != nil {
117118
log.Error("Error running action: ", err.Error())

0 commit comments

Comments
 (0)