/
extension.go
98 lines (75 loc) · 2.14 KB
/
extension.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package tester
import (
"os"
"strings"
"github.com/TIBCOSoftware/flogo-contrib/action/flow/definition"
"github.com/TIBCOSoftware/flogo-contrib/action/flow/instance"
"github.com/TIBCOSoftware/flogo-contrib/action/flow/model"
"github.com/TIBCOSoftware/flogo-contrib/action/flow/support"
"github.com/TIBCOSoftware/flogo-contrib/model/simple"
"github.com/TIBCOSoftware/flogo-lib/util"
)
const (
ENV_ENABLED = "TESTER_ENABLED"
ENV_SETTING_PORT = "TESTER_PORT"
ENV_SETTING_SR_HOST = "TESTER_SR_SERVER"
)
//ExtensionProvider is the extension provider for the flow action
type TesterProvider struct {
flowProvider definition.Provider
flowModel *model.FlowModel
stateRecorder instance.StateRecorder
flowTester *RestEngineTester
}
func NewExtensionProvider() *TesterProvider {
return &TesterProvider{}
}
func (fp *TesterProvider) GetFlowProvider() definition.Provider {
if fp.flowProvider == nil {
fp.flowProvider = &support.BasicRemoteFlowProvider{}
}
return fp.flowProvider
}
func (fp *TesterProvider) GetDefaultFlowModel() *model.FlowModel {
if fp.flowModel == nil {
fp.flowModel = simple.New()
}
return fp.flowModel
}
func (fp *TesterProvider) GetStateRecorder() instance.StateRecorder {
if fp.stateRecorder == nil {
config := &util.ServiceConfig{Enabled: true}
server := os.Getenv(ENV_SETTING_SR_HOST)
if server != "" {
parts := strings.Split(server, ":")
host := parts[0]
port := "9090"
if len(parts) > 1 {
port = parts[1]
}
settings := map[string]string{
"host": host,
"port": port,
}
config.Settings = settings
} else {
config.Enabled = false
}
fp.stateRecorder = instance.NewRemoteStateRecorder(config)
}
return fp.stateRecorder
}
func (fp *TesterProvider) GetMapperFactory() definition.MapperFactory {
return nil
}
func (fp *TesterProvider) GetLinkExprManagerFactory() definition.LinkExprManagerFactory {
return nil
}
func (fp *TesterProvider) GetFlowTester() *RestEngineTester {
config := &util.ServiceConfig{Enabled: true}
settings := map[string]string{
"port": os.Getenv(ENV_SETTING_PORT),
}
config.Settings = settings
return NewRestEngineTester(config)
}