Skip to content

Commit

Permalink
decouple go chassis (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
tianxiaoliang authored Jan 25, 2019
1 parent d7dcc6b commit ee4ab30
Show file tree
Hide file tree
Showing 5 changed files with 163 additions and 217 deletions.
89 changes: 84 additions & 5 deletions core/config-manager/configurationmanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import (
"github.com/go-chassis/go-archaius/sources/file-source"
"github.com/go-chassis/go-archaius/sources/memory-source"
"github.com/go-chassis/go-archaius/sources/test-source"
"github.com/go-chassis/go-chassis/core/config/model"
"github.com/go-chassis/go-chassis/pkg/util/fileutil"
"github.com/stretchr/testify/assert"
"io"
"os"
Expand All @@ -19,6 +17,79 @@ import (
"time"
)

//GlobalCfg chassis.yaml 配置项
type GlobalCfg struct {
AppID string `yaml:"APPLICATION_ID"` //Deprecated
Panel ControlPanel `yaml:"control"`
Ssl map[string]string `yaml:"ssl"`
Tracing TracingStruct `yaml:"tracing"`
DataCenter *DataCenterInfo `yaml:"region"`
}

// DataCenterInfo gives data center information
type DataCenterInfo struct {
Name string `yaml:"name"`
Region string `yaml:"region"`
AvailableZone string `yaml:"availableZone"`
}

// TracingStruct tracing structure
type TracingStruct struct {
Tracer string `yaml:"tracer"`
Settings map[string]string `yaml:"settings"`
}

//ControlPanel define control panel config
type ControlPanel struct {
Infra string `yaml:"infra"`
Settings map[string]string `yaml:"settings"`
}

// LBWrapper loadbalancing structure
type LBWrapper struct {
Prefix *LoadBalancingConfig `yaml:"cse"`
}

// LoadBalancingConfig loadbalancing structure
type LoadBalancingConfig struct {
LBConfig *LoadBalancing `yaml:"loadbalance"`
}

// LoadBalancing loadbalancing structure
type LoadBalancing struct {
Strategy map[string]string `yaml:"strategy"`
RetryEnabled bool `yaml:"retryEnabled"`
RetryOnNext int `yaml:"retryOnNext"`
RetryOnSame int `yaml:"retryOnSame"`
Filters string `yaml:"serverListFilters"`
Backoff BackoffStrategy `yaml:"backoff"`
SessionStickinessRule SessionStickinessRule `yaml:"SessionStickinessRule"`
AnyService map[string]LoadBalancingSpec `yaml:",inline"`
}

// LoadBalancingSpec loadbalancing structure
type LoadBalancingSpec struct {
Strategy map[string]string `yaml:"strategy"`
SessionStickinessRule SessionStickinessRule `yaml:"SessionStickinessRule"`
RetryEnabled bool `yaml:"retryEnabled"`
RetryOnNext int `yaml:"retryOnNext"`
RetryOnSame int `yaml:"retryOnSame"`
Backoff BackoffStrategy `yaml:"backoff"`
}

// SessionStickinessRule loadbalancing structure
type SessionStickinessRule struct {
SessionTimeoutInSeconds int `yaml:"sessionTimeoutInSeconds"`
SuccessiveFailedTimes int `yaml:"successiveFailedTimes"`
}

// BackoffStrategy back off strategy
type BackoffStrategy struct {
Kind string `yaml:"kind"`
MinMs int `yaml:"minMs"`
MaxMs int `yaml:"maxMs"`
}

func check(e error) {
if e != nil {
panic(e)
Expand Down Expand Up @@ -195,6 +266,14 @@ func TestConfigurationManager(t *testing.T) {

}

//GetWorkDir is a function used to get the working directory
func GetWorkDir() (string, error) {
wd, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil {
return "", err
}
return wd, nil
}
func TestConfigurationManager_AddSource(t *testing.T) {

file := []byte(`
Expand Down Expand Up @@ -278,7 +357,7 @@ cse:
`)

root, _ := fileutil.GetWorkDir()
root, _ := GetWorkDir()
os.Setenv("CHASSIS_HOME", root)
t.Log(os.Getenv("CHASSIS_HOME"))

Expand Down Expand Up @@ -314,7 +393,7 @@ cse:
time.Sleep(2 * time.Second)

t.Log("verifying Unmarshalling")
globalDef := model.GlobalCfg{}
globalDef := GlobalCfg{}
err = confmanager.Unmarshal(&globalDef)
if err != nil {
t.Error(err)
Expand All @@ -331,7 +410,7 @@ cse:
confmanager.AddSource(fsource, fsource.GetPriority())
time.Sleep(2 * time.Second)

lbConfig := model.LBWrapper{}
lbConfig := LBWrapper{}
err = confmanager.Unmarshal(&lbConfig)
if err != nil {
t.Error(err)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/go-chassis/go-archaius
require (
github.com/fsnotify/fsnotify v1.4.7
github.com/go-chassis/go-cc-client v0.0.0-20181109091810-e4f730e7ed13
github.com/go-chassis/go-chassis v1.2.2
github.com/go-chassis/go-chassis v1.2.2 // indirect
github.com/go-mesh/openlogging v0.0.0-20181122085847-3daf3ad8ed35
github.com/gorilla/websocket v1.4.0
github.com/spf13/cast v1.2.0
Expand Down
Loading

0 comments on commit ee4ab30

Please sign in to comment.