From 7a8da568f99a929bd26edf2a3a739a7f63f8a216 Mon Sep 17 00:00:00 2001 From: nthota Date: Mon, 27 Apr 2020 18:07:04 +0530 Subject: [PATCH 1/2] add descriptor json to rule action --- examples/flogo/creditcard/flogo.json | 3 +-- examples/flogo/simple-kafka/flogo.json | 4 ++++ examples/flogo/simple/flogo.json | 4 ++++ examples/flogo/trackntrace/flogo.json | 4 ++++ go.mod | 24 +++++++++++++++------ ruleaction/{action.json => descriptor.json} | 2 -- 6 files changed, 31 insertions(+), 10 deletions(-) rename ruleaction/{action.json => descriptor.json} (91%) diff --git a/examples/flogo/creditcard/flogo.json b/examples/flogo/creditcard/flogo.json index 48126cb..30f4b90 100644 --- a/examples/flogo/creditcard/flogo.json +++ b/examples/flogo/creditcard/flogo.json @@ -6,8 +6,7 @@ "appModel": "1.0.0", "imports": [ "github.com/project-flogo/contrib/trigger/rest", - "github.com/project-flogo/rules/ruleaction", - "github.com/project-flogo/legacybridge" + "github.com/project-flogo/rules/ruleaction" ], "triggers": [ { diff --git a/examples/flogo/simple-kafka/flogo.json b/examples/flogo/simple-kafka/flogo.json index 806a19a..5786d21 100644 --- a/examples/flogo/simple-kafka/flogo.json +++ b/examples/flogo/simple-kafka/flogo.json @@ -4,6 +4,10 @@ "version": "0.0.1", "description": "Sample Flogo App", "appModel": "1.0.0", + "imports": [ + "github.com/project-flogo/contrib/trigger/kafka", + "github.com/project-flogo/rules/ruleaction" + ], "triggers": [ { "id": "receive_kafka_message", diff --git a/examples/flogo/simple/flogo.json b/examples/flogo/simple/flogo.json index 41e8ca1..ce6004a 100644 --- a/examples/flogo/simple/flogo.json +++ b/examples/flogo/simple/flogo.json @@ -4,6 +4,10 @@ "version": "0.0.1", "description": "Sample Flogo App", "appModel": "1.0.0", + "imports": [ + "github.com/project-flogo/contrib/trigger/rest", + "github.com/project-flogo/rules/ruleaction" + ], "triggers": [ { "id": "receive_http_message", diff --git a/examples/flogo/trackntrace/flogo.json b/examples/flogo/trackntrace/flogo.json index dbaad3c..b41e0a1 100644 --- a/examples/flogo/trackntrace/flogo.json +++ b/examples/flogo/trackntrace/flogo.json @@ -3,6 +3,10 @@ "type": "flogo:app", "version": "0.0.1", "appModel": "1.0.0", + "imports": [ + "github.com/project-flogo/contrib/trigger/rest", + "github.com/project-flogo/rules/ruleaction" + ], "triggers": [ { "id": "receive_http_message", diff --git a/go.mod b/go.mod index f36faf1..26f7c40 100644 --- a/go.mod +++ b/go.mod @@ -1,13 +1,25 @@ module github.com/project-flogo/rules require ( - github.com/aws/aws-sdk-go v1.18.3 - github.com/gorilla/websocket v1.4.0 + github.com/DataDog/zstd v1.4.5 // indirect + github.com/Shopify/sarama v1.26.1 // indirect + github.com/aws/aws-sdk-go v1.30.14 + github.com/gorilla/websocket v1.4.2 + github.com/klauspost/compress v1.10.5 // indirect github.com/oklog/ulid v1.3.1 - github.com/project-flogo/contrib/trigger/kafka v0.9.0 - github.com/project-flogo/contrib/trigger/rest v0.9.0 - github.com/project-flogo/core v0.9.3 - github.com/stretchr/testify v1.3.0 + github.com/pierrec/lz4 v2.5.2+incompatible // indirect + github.com/project-flogo/contrib/trigger/kafka v0.10.0 + github.com/project-flogo/contrib/trigger/rest v0.10.0 + github.com/project-flogo/core v0.10.2 + github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0 // indirect + github.com/stretchr/objx v0.2.0 // indirect + github.com/stretchr/testify v1.5.1 + go.uber.org/zap v1.15.0 // indirect + golang.org/x/crypto v0.0.0-20200423211502-4bdfaf469ed5 // indirect + golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect + golang.org/x/net v0.0.0-20200425230154-ff2c4b7c35a0 // indirect + golang.org/x/tools v0.0.0-20200426102838-f3a5411a4c3b // indirect + honnef.co/go/tools v0.0.1-2020.1.3 // indirect ) go 1.13 diff --git a/ruleaction/action.json b/ruleaction/descriptor.json similarity index 91% rename from ruleaction/action.json rename to ruleaction/descriptor.json index 90bd52e..82b398e 100644 --- a/ruleaction/action.json +++ b/ruleaction/descriptor.json @@ -1,13 +1,11 @@ { "name": "rulesaction", "type": "flogo:action", - "ref": "github.com/project-flogo/rules/ruleaction", "version": "0.0.1", "title": "Rules Action", "description": "Simple Rules Action", "homepage": "https://github.com/project-flogo/rules/ruleaction", "async": false, - "settings": [ { "name": "ruleSessionURI", From 50eb9ba106c684693f64e90e46847d8ecd135c30 Mon Sep 17 00:00:00 2001 From: nthota Date: Mon, 27 Apr 2020 18:29:56 +0530 Subject: [PATCH 2/2] examples updated --- examples/flogo/creditcard/imports.go | 6 ++++ examples/flogo/creditcard/main.go | 34 ++++++++++++--------- examples/flogo/simple-kafka/imports.go | 6 ++++ examples/flogo/simple-kafka/main.go | 38 ++++++++++++++---------- examples/flogo/simple/imports.go | 6 ++++ examples/flogo/simple/main.go | 41 +++++++++++++++----------- examples/flogo/trackntrace/imports.go | 6 ++++ examples/flogo/trackntrace/main.go | 41 +++++++++++++++----------- 8 files changed, 112 insertions(+), 66 deletions(-) create mode 100644 examples/flogo/creditcard/imports.go create mode 100644 examples/flogo/simple-kafka/imports.go create mode 100644 examples/flogo/simple/imports.go create mode 100644 examples/flogo/trackntrace/imports.go diff --git a/examples/flogo/creditcard/imports.go b/examples/flogo/creditcard/imports.go new file mode 100644 index 0000000..89913aa --- /dev/null +++ b/examples/flogo/creditcard/imports.go @@ -0,0 +1,6 @@ +package main + +import ( + _ "github.com/project-flogo/rules/ruleaction" + _ "github.com/project-flogo/contrib/trigger/rest" +) diff --git a/examples/flogo/creditcard/main.go b/examples/flogo/creditcard/main.go index 132d1a2..68b9b88 100644 --- a/examples/flogo/creditcard/main.go +++ b/examples/flogo/creditcard/main.go @@ -9,41 +9,43 @@ import ( _ "github.com/project-flogo/core/data/expression/script" "github.com/project-flogo/core/engine" - "github.com/project-flogo/core/support/log" - - _ "github.com/project-flogo/contrib/trigger/rest" - _ "github.com/project-flogo/rules/ruleaction" ) var ( cpuProfile = flag.String("cpuprofile", "", "Writes CPU profile to the specified file") memProfile = flag.String("memprofile", "", "Writes memory profile to the specified file") cfgJson string + cfgEngine string cfgCompressed bool ) func main() { + cpuProfiling := false + flag.Parse() if *cpuProfile != "" { f, err := os.Create(*cpuProfile) if err != nil { - fmt.Println(fmt.Sprintf("Failed to create CPU profiling file due to error - %s", err.Error())) + fmt.Fprintf(os.Stderr, "Failed to create CPU profiling file: %v\n", err) + os.Exit(1) + } + if err = pprof.StartCPUProfile(f); err != nil { + fmt.Fprintf(os.Stderr, "Failed to start CPU profiling: %v\n", err) os.Exit(1) } - pprof.StartCPUProfile(f) - defer pprof.StopCPUProfile() + cpuProfiling = true } cfg, err := engine.LoadAppConfig(cfgJson, cfgCompressed) if err != nil { - log.RootLogger().Errorf("Failed to create engine: %s", err.Error()) + fmt.Fprintf(os.Stderr, "Failed to create engine: %v\n", err) os.Exit(1) } - e, err := engine.New(cfg) + e, err := engine.New(cfg, engine.ConfigOption(cfgEngine, cfgCompressed)) if err != nil { - log.RootLogger().Errorf("Failed to create engine: %s", err.Error()) + fmt.Fprintf(os.Stderr, "Failed to create engine: %v\n", err) os.Exit(1) } @@ -52,17 +54,21 @@ func main() { if *memProfile != "" { f, err := os.Create(*memProfile) if err != nil { - fmt.Println(fmt.Sprintf("Failed to create memory profiling file due to error - %s", err.Error())) + fmt.Fprintf(os.Stderr, "Failed to create memory profiling file: %v\n", err) os.Exit(1) } runtime.GC() // get up-to-date statistics if err := pprof.WriteHeapProfile(f); err != nil { - fmt.Println(fmt.Sprintf("Failed to write memory profiling data to file due to error - %s", err.Error())) + fmt.Fprintf(os.Stderr, "Failed to write memory profiling data: %v", err) os.Exit(1) } - f.Close() + _ = f.Close() + } + + if cpuProfiling { + pprof.StopCPUProfile() } os.Exit(code) -} +} \ No newline at end of file diff --git a/examples/flogo/simple-kafka/imports.go b/examples/flogo/simple-kafka/imports.go new file mode 100644 index 0000000..701b350 --- /dev/null +++ b/examples/flogo/simple-kafka/imports.go @@ -0,0 +1,6 @@ +package main + +import ( + _ "github.com/project-flogo/contrib/trigger/kafka" + _ "github.com/project-flogo/rules/ruleaction" +) diff --git a/examples/flogo/simple-kafka/main.go b/examples/flogo/simple-kafka/main.go index b4de78f..68b9b88 100644 --- a/examples/flogo/simple-kafka/main.go +++ b/examples/flogo/simple-kafka/main.go @@ -9,41 +9,43 @@ import ( _ "github.com/project-flogo/core/data/expression/script" "github.com/project-flogo/core/engine" - "github.com/project-flogo/core/support/log" - - _ "github.com/project-flogo/contrib/trigger/kafka" - _ "github.com/project-flogo/rules/ruleaction" ) var ( cpuProfile = flag.String("cpuprofile", "", "Writes CPU profile to the specified file") memProfile = flag.String("memprofile", "", "Writes memory profile to the specified file") - cfgJSON string + cfgJson string + cfgEngine string cfgCompressed bool ) func main() { + cpuProfiling := false + flag.Parse() if *cpuProfile != "" { f, err := os.Create(*cpuProfile) if err != nil { - fmt.Println(fmt.Sprintf("Failed to create CPU profiling file due to error - %s", err.Error())) + fmt.Fprintf(os.Stderr, "Failed to create CPU profiling file: %v\n", err) + os.Exit(1) + } + if err = pprof.StartCPUProfile(f); err != nil { + fmt.Fprintf(os.Stderr, "Failed to start CPU profiling: %v\n", err) os.Exit(1) } - pprof.StartCPUProfile(f) - defer pprof.StopCPUProfile() + cpuProfiling = true } - cfg, err := engine.LoadAppConfig(cfgJSON, cfgCompressed) + cfg, err := engine.LoadAppConfig(cfgJson, cfgCompressed) if err != nil { - log.RootLogger().Errorf("Failed to create engine: %s", err.Error()) + fmt.Fprintf(os.Stderr, "Failed to create engine: %v\n", err) os.Exit(1) } - e, err := engine.New(cfg) + e, err := engine.New(cfg, engine.ConfigOption(cfgEngine, cfgCompressed)) if err != nil { - log.RootLogger().Errorf("Failed to create engine: %s", err.Error()) + fmt.Fprintf(os.Stderr, "Failed to create engine: %v\n", err) os.Exit(1) } @@ -52,17 +54,21 @@ func main() { if *memProfile != "" { f, err := os.Create(*memProfile) if err != nil { - fmt.Println(fmt.Sprintf("Failed to create memory profiling file due to error - %s", err.Error())) + fmt.Fprintf(os.Stderr, "Failed to create memory profiling file: %v\n", err) os.Exit(1) } runtime.GC() // get up-to-date statistics if err := pprof.WriteHeapProfile(f); err != nil { - fmt.Println(fmt.Sprintf("Failed to write memory profiling data to file due to error - %s", err.Error())) + fmt.Fprintf(os.Stderr, "Failed to write memory profiling data: %v", err) os.Exit(1) } - f.Close() + _ = f.Close() + } + + if cpuProfiling { + pprof.StopCPUProfile() } os.Exit(code) -} +} \ No newline at end of file diff --git a/examples/flogo/simple/imports.go b/examples/flogo/simple/imports.go new file mode 100644 index 0000000..de2804e --- /dev/null +++ b/examples/flogo/simple/imports.go @@ -0,0 +1,6 @@ +package main + +import ( + _ "github.com/project-flogo/contrib/trigger/rest" + _ "github.com/project-flogo/rules/ruleaction" +) diff --git a/examples/flogo/simple/main.go b/examples/flogo/simple/main.go index b1f6c5b..68b9b88 100644 --- a/examples/flogo/simple/main.go +++ b/examples/flogo/simple/main.go @@ -9,42 +9,43 @@ import ( _ "github.com/project-flogo/core/data/expression/script" "github.com/project-flogo/core/engine" - "github.com/project-flogo/core/support/log" - - _ "github.com/project-flogo/contrib/trigger/rest" - _ "github.com/project-flogo/rules/ruleaction" - ) var ( - cpuProfile = flag.String("cpuprofile", "", "Writes CPU profile to the specified file") - memProfile = flag.String("memprofile", "", "Writes memory profile to the specified file") - cfgJson string + cpuProfile = flag.String("cpuprofile", "", "Writes CPU profile to the specified file") + memProfile = flag.String("memprofile", "", "Writes memory profile to the specified file") + cfgJson string + cfgEngine string cfgCompressed bool ) func main() { + cpuProfiling := false + flag.Parse() if *cpuProfile != "" { f, err := os.Create(*cpuProfile) if err != nil { - fmt.Println(fmt.Sprintf("Failed to create CPU profiling file due to error - %s", err.Error())) + fmt.Fprintf(os.Stderr, "Failed to create CPU profiling file: %v\n", err) os.Exit(1) } - pprof.StartCPUProfile(f) - defer pprof.StopCPUProfile() + if err = pprof.StartCPUProfile(f); err != nil { + fmt.Fprintf(os.Stderr, "Failed to start CPU profiling: %v\n", err) + os.Exit(1) + } + cpuProfiling = true } cfg, err := engine.LoadAppConfig(cfgJson, cfgCompressed) if err != nil { - log.RootLogger().Errorf("Failed to create engine: %s", err.Error()) + fmt.Fprintf(os.Stderr, "Failed to create engine: %v\n", err) os.Exit(1) } - e, err := engine.New(cfg) + e, err := engine.New(cfg, engine.ConfigOption(cfgEngine, cfgCompressed)) if err != nil { - log.RootLogger().Errorf("Failed to create engine: %s", err.Error()) + fmt.Fprintf(os.Stderr, "Failed to create engine: %v\n", err) os.Exit(1) } @@ -53,17 +54,21 @@ func main() { if *memProfile != "" { f, err := os.Create(*memProfile) if err != nil { - fmt.Println(fmt.Sprintf("Failed to create memory profiling file due to error - %s", err.Error())) + fmt.Fprintf(os.Stderr, "Failed to create memory profiling file: %v\n", err) os.Exit(1) } runtime.GC() // get up-to-date statistics if err := pprof.WriteHeapProfile(f); err != nil { - fmt.Println(fmt.Sprintf("Failed to write memory profiling data to file due to error - %s", err.Error())) + fmt.Fprintf(os.Stderr, "Failed to write memory profiling data: %v", err) os.Exit(1) } - f.Close() + _ = f.Close() + } + + if cpuProfiling { + pprof.StopCPUProfile() } os.Exit(code) -} +} \ No newline at end of file diff --git a/examples/flogo/trackntrace/imports.go b/examples/flogo/trackntrace/imports.go new file mode 100644 index 0000000..de2804e --- /dev/null +++ b/examples/flogo/trackntrace/imports.go @@ -0,0 +1,6 @@ +package main + +import ( + _ "github.com/project-flogo/contrib/trigger/rest" + _ "github.com/project-flogo/rules/ruleaction" +) diff --git a/examples/flogo/trackntrace/main.go b/examples/flogo/trackntrace/main.go index b1f6c5b..68b9b88 100644 --- a/examples/flogo/trackntrace/main.go +++ b/examples/flogo/trackntrace/main.go @@ -9,42 +9,43 @@ import ( _ "github.com/project-flogo/core/data/expression/script" "github.com/project-flogo/core/engine" - "github.com/project-flogo/core/support/log" - - _ "github.com/project-flogo/contrib/trigger/rest" - _ "github.com/project-flogo/rules/ruleaction" - ) var ( - cpuProfile = flag.String("cpuprofile", "", "Writes CPU profile to the specified file") - memProfile = flag.String("memprofile", "", "Writes memory profile to the specified file") - cfgJson string + cpuProfile = flag.String("cpuprofile", "", "Writes CPU profile to the specified file") + memProfile = flag.String("memprofile", "", "Writes memory profile to the specified file") + cfgJson string + cfgEngine string cfgCompressed bool ) func main() { + cpuProfiling := false + flag.Parse() if *cpuProfile != "" { f, err := os.Create(*cpuProfile) if err != nil { - fmt.Println(fmt.Sprintf("Failed to create CPU profiling file due to error - %s", err.Error())) + fmt.Fprintf(os.Stderr, "Failed to create CPU profiling file: %v\n", err) os.Exit(1) } - pprof.StartCPUProfile(f) - defer pprof.StopCPUProfile() + if err = pprof.StartCPUProfile(f); err != nil { + fmt.Fprintf(os.Stderr, "Failed to start CPU profiling: %v\n", err) + os.Exit(1) + } + cpuProfiling = true } cfg, err := engine.LoadAppConfig(cfgJson, cfgCompressed) if err != nil { - log.RootLogger().Errorf("Failed to create engine: %s", err.Error()) + fmt.Fprintf(os.Stderr, "Failed to create engine: %v\n", err) os.Exit(1) } - e, err := engine.New(cfg) + e, err := engine.New(cfg, engine.ConfigOption(cfgEngine, cfgCompressed)) if err != nil { - log.RootLogger().Errorf("Failed to create engine: %s", err.Error()) + fmt.Fprintf(os.Stderr, "Failed to create engine: %v\n", err) os.Exit(1) } @@ -53,17 +54,21 @@ func main() { if *memProfile != "" { f, err := os.Create(*memProfile) if err != nil { - fmt.Println(fmt.Sprintf("Failed to create memory profiling file due to error - %s", err.Error())) + fmt.Fprintf(os.Stderr, "Failed to create memory profiling file: %v\n", err) os.Exit(1) } runtime.GC() // get up-to-date statistics if err := pprof.WriteHeapProfile(f); err != nil { - fmt.Println(fmt.Sprintf("Failed to write memory profiling data to file due to error - %s", err.Error())) + fmt.Fprintf(os.Stderr, "Failed to write memory profiling data: %v", err) os.Exit(1) } - f.Close() + _ = f.Close() + } + + if cpuProfiling { + pprof.StopCPUProfile() } os.Exit(code) -} +} \ No newline at end of file