Dev focused conversations, questions and discussions around PRs, etc should happen here.
mellistibco on readme-updates
mellistibco on master
Readme updates (#570) * Update… (compare)
mellistibco on readme-updates
Update README.md (compare)
mellistibco on readme-updates
Update README.md (compare)
package main
import (
"context"
"fmt"
logg "github.com/project-flogo/contrib/activity/log"
"github.com/project-flogo/core/activity"
"github.com/project-flogo/core/api"
"github.com/project-flogo/core/engine"
"github.com/project-flogo/core/support/log"
"github.com/project-flogo/core/trigger"
"errors"
"github.com/edgexfoundry/app-functions-sdk-go/appcontext"
"github.com/edgexfoundry/app-functions-sdk-go/appsdk"
"github.com/edgexfoundry/app-functions-sdk-go/pkg/transforms"
"os"
)
// trigger starts here
type HandlerSettings struct{}
var triggerMd = trigger.NewMetadata(&HandlerSettings{})
func init() {
_ = trigger.Register(&Trigger{}, &Factory{})
}
type Factory struct{}
// Metadata implements trigger.Factory.Metadata
func (*Factory) Metadata() *trigger.Metadata {
return triggerMd
}
// New implements trigger.Factory.New
func (*Factory) New(config *trigger.Config) (trigger.Trigger, error) {
return &Trigger{}, nil
}
type Trigger struct {
logger log.Logger
handlers []trigger.Handler
}
// Init implements trigger.Init
func (t *Trigger) Initialize(ctx trigger.InitContext) error {
t.logger = ctx.Logger()
t.handlers = ctx.GetHandlers()
return nil
}
// Start implements ext.Trigger.Start
func (t *Trigger) Start() error {
fmt.Println("flogo trigger just started")
//Assume you just have one handler.
go edgexEventCatcher(t.handlers[0])
return nil
}
// Stop implements ext.Trigger.Stop
func (t *Trigger) Stop() error {
fmt.Println("flogo trigger stopped")
return nil
}
type callHandler struct {
handler trigger.Handler
}
// edgex
func edgexEventCatcher(handler trigger.Handler) {
// turn off secure mode for examples. Not recommended for production
os.Setenv("EDGEX_SECURITY_SECRET_STORE", "false")
// 1) First thing to do is to create an instance of the EdgeX SDK, giving it a service key
edgexSdk := &appsdk.AppFunctionsSDK{ServiceKey: "sampleFilterJSON"}
// 2) Next, we need to initialize the SDK
if err := edgexSdk.Initialize(); err != nil {
edgexSdk.LoggingClient.Error(fmt.Sprintf("SDK initialization failed: %v\n", err))
os.Exit(-1)
}
// 3) Shows how to access the application's specific configuration settings.
deviceNames, err := edgexSdk.GetAppSettingStrings("DeviceNames")
if err != nil {
edgexSdk.LoggingClient.Error(err.Error())
os.Exit(-1)
}
edgexSdk.LoggingClient.Info(fmt.Sprintf("Filtering for devices &v", deviceNames))
// 4) This is our pipeline configuration, the collection of functions to
// execute every time an event is triggered.
callHandler := &callHandler{handler: handler}
if err = edgexSdk.SetFunctionsPipeline(
transforms.NewFilter(deviceNames).FilterByDeviceName,
transforms.NewConversion().TransformToJSON,
callHandler.printXMLToConsole,
); err != nil {
edgexSdk.LoggingClient.Error(fmt.Sprintf("SDK SetPipeline failed: %v\n", err))
os.Exit(-1)
}
// 5) Lastly, we'll go ahead and tell the SDK to "start" and begin listening for events to trigger the pipeline.
err = edgexSdk.MakeItRun()
if err != nil {
edgexSdk.LoggingClient.Error("MakeItRun returned error: ", err.Error())
os.Exit(-1)
}
os.Exit(0)
}
func (c *callHandler) printXMLToConsole(edgexcontext *appcontext.Context, params ...interface{}) (bool, interface{}) {
if len(params) < 1 {
// We didn't receive a result
return false, errors.New("No Data Received")
}
println(params[0].(string))
// Leverage the built in logging service in EdgeX
edgexcontext.LoggingClient.Debug("JSON printed to console")
//Here go and call flows, and data goes to flow
triggerData := map[string]interface{}{}
triggerData["jsonData"] = params
results, err := c.handler.Handle(context.Background(), triggerData)
//You can handle returned result and possible error.
println(err)
println(results)
return true, nil
}
hi @lixingwang,
i'm facing this error while piping the data to the handler,
Error invoking action : unsupported trigger data: &{{"apiVersion":"v2","id":"c4a72616-07e1-4300-a928-1bf764814c79","deviceName":"Random-Integer-Device","profileName":"Random-Integer-Device","sourceName":"Int16","origin":1627408154564184234,"readings":[{"id":"15f855a8-bd4b-4155-9e68-0e76a48deb6e","origin":1627408154564184234,"deviceName":"Random-Integer-Device","resourceName":"Int16","profileName":"Random-Integer-Device","valueType":"Int16","binaryValue":null,"mediaType":"","value":"23047"}]}}
I have tried to pass the data as a string then as a struct pointer but still facing the same error.
vagrant@vagrant:~/tryflogo/tryingCliInstallation$ flogo create newapp
Creating Flogo App: newapp
Installing: github.com/project-flogo/core@latest
Error creating project: open pkg/mod/github.com/project-flogo/core@v1.4.0/examples/engine/main.go: no such file or directory
vagrant@vagrant:~/tryflogo/tryingCliInstallation$
debug: [01:14:16.092] Installation of 'github.com/afarooq8/trigger' failed in 'undefined' step.
debug: [01:14:16.093] Starting engine recovery.
debug: [01:14:16.093] Resource cleaning: removing the backup folder.
info: [01:16:43.848] [log] Install : 'github.com/afarooqi8/trigger'
debug: [01:16:43.849] Backing up 'src' to 'backupsrc'.
debug: [01:16:43.854] Started installing 'github.com/afarooqi8/trigger' to the engine.
info: [01:16:43.855] Exec command: flogo install github.com/afarooqi8/trigger in /flogo-web/local/engines/flogo-web
info: [01:16:43.860] run command: flogo install github.com/afarooqi8/trigger
engine:install:contribution: 1279911.114ms
debug: [01:38:03.777] Building engine.
info: [01:38:03.782] [log] Build flogo: "flogo build " compileOpts:
info: [01:38:03.789] run command: flogo build
warn: [01:38:48.910] command exited with code 1: flogo build
error: [01:38:48.920] [error] Encountered error while installing the 'github.com/afarooqi8/trigger' to the engine:
error: [01:38:48.921] Error building project: # github.com/edgexfoundry/go-mod-core-contracts/v2/errors
/go/pkg/mod/github.com/edgexfoundry/go-mod-core-contracts/v2@v2.0.0/errors/types.go:79:6: undefined: errors.As
note: module requires Go 1.16
# github.com/pebbe/zmq4
/go/pkg/mod/github.com/pebbe/zmq4@v1.2.7/reactor.go:10:4: undefined: State
/go/pkg/mod/github.com/pebbe/zmq4@v1.2.7/reactor.go:11:9: undefined: State
note: module requires Go 1.16
# go.uber.org/multierr
/go/pkg/mod/go.uber.org/multierr@v1.7.0/error.go:249:6: undefined: errors.As
/go/pkg/mod/go.uber.org/multierr@v1.7.0/error.go:262:6: undefined: errors.Is
note: module requires Go 1.14
docker build -t flogo/flogo-web -f tools/docker/Dockerfile .
-> that's failing for me when I upgrade the golang version to 1.16 (in the Dockerfile), something in the out of the box activities/triggers seems to be incompatible. I'm seeing:
#13 2036.0 [release:build-engines ] [configure-engines] Error building project: /go/pkg/mod/github.com/project-flogo/contrib/activity/xml2json@v0.10.0/activity.go:7:2: missing go.sum entry for module providing package github.com/basgys/goxml2json (imported by github.com/project-flogo/contrib/activity/xml2json); to add:
#13 2036.0 [release:build-engines ] [configure-engines] go get github.com/project-flogo/contrib/activity/xml2json@v0.10.0
#13 2036.0 [release:build-engines ] [configure-engines] /go/pkg/mod/github.com/project-flogo/contrib/trigger/timer@v0.10.0/timer.go:8:2: missing go.sum entry for module providing package github.com/carlescere/scheduler (imported by github.com/project-flogo/contrib/trigger/timer); to add:
#13 2036.0 [release:build-engines ] [configure-engines] go get github.com/project-flogo/contrib/trigger/timer@v0.10.0
#13 2036.0 [release:build-engines ] [configure-engines] /go/pkg/mod/github.com/project-flogo/contrib/activity/jsexec@v0.10.0/activity.go:7:2: missing go.sum entry for module providing package github.com/dop251/goja (imported by github.com/project-flogo/contrib/activity/jsexec); to add:
#13 2036.0 [release:build-engines ] [configure-engines] go get github.com/project-flogo/contrib/activity/jsexec@v0.10.0
#13 2036.0 [release:build-engines ] [configure-engines] /go/pkg/mod/github.com/project-flogo/stream/service/telemetry@v0.0.0-20200124014152-d2d7c82a602d/service.go:11:2: missing go.sum entry for module providing package github.com/gorilla/websocket (imported by github.com/project-flogo/stream/service/telemetry); to add:
#13 2036.0 [release:build-engines ] [configure-engines] go get github.com/project-flogo/stream/service/telemetry@v0.0.0-20200124014152-d2d7c82a602d
#13 2036.0 [release:build-engines ] [configure-engines] /go/pkg/mod/github.com/project-flogo/contrib/function/json@v0.10.0/path.go:4:2: missing go.sum entry for module providing package github.com/oliveagle/jsonpath (imported by github.com/project-flogo/contrib/function/json); to add:
#13 2036.0 [release:build-engines ] [configure-engines] go get github.com/project-flogo/contrib/function/json@v0.10.0
#13 2036.0 [release:build-engines ] [configure-engines] /go/pkg/mod/github.com/project-flogo/contrib/function/datetime@v0.10.0/formatdate.go:9:2: missing go.sum entry for module providing package github.com/tkuchiki/parsetime (imported by github.com/project-flogo/contrib/function/datetime); to add:
#13 2036.0 [release:build-engines ] [configure-engines] go get github.com/project-flogo/contrib/function/datetime@v0.10.0
I am getting below error while trying to build aws lambda. Followed the steps from https://tibcosoftware.github.io/flogo/faas/how-to/
Tried few things. I am using same example given on https://tibcosoftware.github.io/flogo/faas/how-to/
D:\Flogo\app\myapp2>flogo build -e --shim aws_lambda_trigger --verbose
Embedding configuration in application...
Creating shim support files...
Preparing shim...
Using build.go to build shim......
Running build script for the Lambda trigger
Cleaning up previous executables
Building a new handler file
go: main: package github.com/aws/aws-lambda-go/lambda imported from implicitly required module; to add missing requirements, run:
go get github.com/aws/aws-lambda-go/lambda@v1.10.0
exit status 1Zipping the new handler file
Failed to compress file: open D:\Flogo\app\myapp2\src\handler: The system cannot find the file specified.Cleaning up shim support files...
sure I can approach it that way.
My main reason contributing to the repository is because same components are available by default on TIBCO Cloud Integration.
So as a user I wanted to contribute to a whole Marketplace available in TCI
Should I create PR on https://github.com/TIBCOSoftware/tci-awesome/blob/master/docs/data/items.toml ?
hi, I think I’ll go for now with option 2.
And introduce activity into my TCI org for now for the team to use.
For option 2 (OSS), I followed process from tci-awsome
and created issue: TIBCOSoftware/tci-awesome#14
If needed I can create PR with this addition?