[FIX] fix the bug that configs value type is []interface{}

This commit is contained in:
goodrain 2017-12-22 16:45:21 +08:00
parent 934ef6be08
commit 7ccc4ca9f4
3 changed files with 33 additions and 8 deletions

View File

@ -145,13 +145,27 @@ func (d *DataCenterConfig) PutConfig(c *model.ConfigUnit) error {
if c.Name == "" {
return fmt.Errorf("config name can not be empty")
}
//将值类型由[]interface{} 转 []string
if c.ValueType == "array" {
switch c.Value.(type) {
case []interface{}:
var data []string
for _, v := range c.Value.([]interface{}) {
data = append(data, v.(string))
}
c.Value = data
}
}
if c.ValueType == "array" {
oldC := d.config.Get(c.Name)
if oldC != nil {
oldV, ok := oldC.Value.([]string)
newV, newOK := c.Value.([]string)
if ok && newOK {
c.Value = append(oldV, newV...)
switch oldC.Value.(type) {
case string:
c.Value = append(c.Value.([]string), oldC.Value.(string))
case []string:
c.Value = append(c.Value.([]string), oldC.Value.([]string)...)
default:
logrus.Info(4)
}
}
}

View File

@ -20,9 +20,11 @@ package config
import (
"os"
"strings"
"testing"
"github.com/goodrain/rainbond/cmd/node/option"
"github.com/goodrain/rainbond/pkg/node/api/model"
"github.com/goodrain/rainbond/pkg/node/core/store"
"github.com/Sirupsen/logrus"
@ -38,11 +40,21 @@ func init() {
logrus.Error(err.Error())
os.Exit(1)
}
option.Config = &option.Conf{
ConfigStoragePath: "/rainbond/configs",
}
}
func TestGetDataCenterConfig(t *testing.T) {
c := DataCenterConfig{options: &option.Conf{
ConfigStoragePath: "/rainbond/acp_configs",
}}
str := "asdadad|"
t.Log(strings.Index(str, "|"))
t.Log(strings.Index(str, ","))
c := GetDataCenterConfig()
c.PutConfig(&model.ConfigUnit{
Name: strings.ToUpper("ARRAY"),
Value: []string{"121211212"},
ValueType: "array",
IsConfigurable: false,
})
gc, err := c.GetDataCenterConfig()
t.Log(gc.String())
t.Fatal(err)

View File

@ -85,7 +85,6 @@ func (t *TaskEngine) startScheduler() {
next, err := t.scheduler.Next()
if err != nil {
if err.Error() == "time out" {
logrus.Warningf("get next scheduler job timeout")
continue
}
if err.Error() == "ctx context cancel" {