forked from druid-io/druid-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzookeeper_dep_mgmt.go
34 lines (29 loc) · 973 Bytes
/
zookeeper_dep_mgmt.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
package druid
import (
"encoding/json"
"fmt"
"github.com/druid-io/druid-operator/apis/druid/v1alpha1"
"github.com/druid-io/druid-operator/controllers/druid/ext"
"reflect"
)
var zkExtTypes = map[string]reflect.Type{}
func init() {
zkExtTypes["default"] = reflect.TypeOf(ext.DefaultZkManager{})
}
// We might have to add more methods to this interface to enable extensions that completely manage
// deploy, upgrade and termination of zk cluster.
type zookeeperManager interface {
Configuration() string
}
func createZookeeperManager(spec *v1alpha1.ZookeeperSpec) (zookeeperManager, error) {
if t, ok := zkExtTypes[spec.Type]; ok {
v := reflect.New(t).Interface()
if err := json.Unmarshal(spec.Spec, v); err != nil {
return nil, fmt.Errorf("Couldn't unmarshall zk type[%s]. Error[%s].", spec.Type, err.Error())
} else {
return v.(zookeeperManager), nil
}
} else {
return nil, fmt.Errorf("Can't find type[%s] for Zookeeper Mgmt.", spec.Type)
}
}