update.go 1.2 KB
Newer Older
E
eoLinker API Management 已提交
1 2 3 4 5 6 7 8 9 10 11 12
package balance

import (
	"encoding/json"
	"github.com/eolinker/goku/common/general"
	dao_balance_update "github.com/eolinker/goku/server/dao/console-mysql/dao-balance-update"
	entity "github.com/eolinker/goku/server/entity/balance-entity"
)

func init() {
	general.RegeditLater(Update)
}
Y
Your Name 已提交
13
func Update() error {
E
eoLinker API Management 已提交
14

Y
Your Name 已提交
15 16
	l, e := dao_balance_update.GetAllOldVerSion()
	if e != nil {
E
eoLinker API Management 已提交
17 18 19
		return e
	}

Y
Your Name 已提交
20 21 22
	defStaticServiceName := dao_balance_update.GetDefaultServiceStatic()
	for _, e := range l {
		update(e, defStaticServiceName)
E
eoLinker API Management 已提交
23 24 25 26 27 28
	}

	return nil

}

Y
Your Name 已提交
29
func update(e *entity.BalanceInfoEntity, serviceName string) {
E
eoLinker API Management 已提交
30

Y
Your Name 已提交
31
	if e == nil {
E
eoLinker API Management 已提交
32 33 34
		return
	}

Y
Your Name 已提交
35
	param := &Param{
E
eoLinker API Management 已提交
36 37 38 39 40 41 42 43
		Name:          e.Name,
		ServiceName:   serviceName,
		AppName:       "",
		Static:        "",
		StaticCluster: "",
		Desc:          e.Desc,
	}

Y
Your Name 已提交
44
	info, err := e.Decode()
E
eoLinker API Management 已提交
45

Y
Your Name 已提交
46
	if err != nil {
E
eoLinker API Management 已提交
47 48 49
		return
	}

Y
Your Name 已提交
50
	if info.Default != nil {
E
eoLinker API Management 已提交
51 52 53

		param.Static = info.Default.ServersConfigOrg
	}
Y
Your Name 已提交
54 55 56
	if info.Cluster != nil {
		cluster := make(map[string]string)
		for clusterName, server := range info.Cluster {
E
eoLinker API Management 已提交
57 58 59 60
			cluster[clusterName] = server.ServersConfigOrg

		}

Y
Your Name 已提交
61
		data, err := json.Marshal(cluster)
E
eoLinker API Management 已提交
62

Y
Your Name 已提交
63
		if err == nil {
E
eoLinker API Management 已提交
64 65 66 67 68 69 70

			param.StaticCluster = string(data)
		}
	}

	Save(param)

Y
Your Name 已提交
71
}