-
Notifications
You must be signed in to change notification settings - Fork 10
/
invoke.go
74 lines (64 loc) · 2.27 KB
/
invoke.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
package main
import (
_ "github.com/go-sql-driver/mysql"
"github.com/qa-dev/jsonwire-grid/storage/mongo"
"github.com/qa-dev/jsonwire-grid/config"
"errors"
"github.com/qa-dev/jsonwire-grid/jsonwire"
"github.com/qa-dev/jsonwire-grid/pool"
"github.com/qa-dev/jsonwire-grid/pool/capabilities"
"github.com/qa-dev/jsonwire-grid/pool/strategy/kubernetes"
"github.com/qa-dev/jsonwire-grid/pool/strategy/persistent"
"github.com/qa-dev/jsonwire-grid/selenium"
"github.com/qa-dev/jsonwire-grid/storage/local"
"github.com/qa-dev/jsonwire-grid/storage/mysql"
"github.com/qa-dev/jsonwire-grid/wda"
)
type StorageFactoryInterface interface {
Create(config.Config) (pool.StorageInterface, error)
}
type StrategyFactoryInterface interface {
Create(pool.StorageInterface, capabilities.ComparatorInterface, jsonwire.ClientFactoryInterface) (pool.StrategyInterface, error)
}
func invokeStorageFactory(config config.Config) (factory StorageFactoryInterface, err error) {
switch config.DB.Implementation {
case "mysql":
factory = new(mysql.Factory)
case "local":
factory = new(local.Factory)
case "mongo":
for _, s := range config.Grid.StrategyList {
if s.Type != string(pool.NodeTypePersistent) {
err = errors.New("Invalid config: Mongo db supports only persistent node strategy ")
}
}
factory = new(mongo.Factory)
default:
err = errors.New("Invalid config, unknown param [db.implementation=" + config.DB.Implementation + "]")
}
return
}
func invokeStrategyFactoryList(config config.Config) (factoryList []StrategyFactoryInterface, err error) {
for _, strategyConfig := range config.Grid.StrategyList {
switch strategyConfig.Type {
case string(pool.NodeTypePersistent):
factoryList = append(factoryList, new(persistent.StrategyFactory))
case string(pool.NodeTypeKubernetes):
factoryList = append(factoryList, &kubernetes.StrategyFactory{Config: strategyConfig})
default:
err = errors.New("Undefined strategy type: " + strategyConfig.Type)
return
}
}
return
}
func createClient(config config.Config) (jsonwire.ClientFactoryInterface, error) {
switch config.Grid.ClientType {
case "wda":
return new(wda.ClientFactory), nil
case "selenium":
return new(selenium.ClientFactory), nil
default:
return nil, errors.New("undefined value config.Grid.ClientType")
}
}