| | |
| | | } |
| | | |
| | | // Create create serf agent with config |
| | | func Create(conf *Config) (*Agent, error) { |
| | | func Create(conf *Config, snapshotPath string) (*Agent, error) { |
| | | // config cover to serf config |
| | | serfConf, err := conf.convertToSerf() |
| | | serfConf, err := conf.convertToSerf(snapshotPath) |
| | | if err != nil { |
| | | return nil, err |
| | | } |
| | |
| | | } |
| | | |
| | | //Init serf Init |
| | | func Init(clusterID string, password string, nodeID string, addrs []string) (*Agent, error) { |
| | | agent, err := InitNode(clusterID, password, nodeID) |
| | | func Init(clusterID string, password string, nodeID string, addrs []string, snapshotPath string) (*Agent, error) { |
| | | agent, err := InitNode(clusterID, password, nodeID, snapshotPath) |
| | | if err != nil { |
| | | logger.Error("InitNode failed, error: %s", err) |
| | | return agent, err |
| | |
| | | } |
| | | |
| | | //InitNode web后台收到创建集群的请求, |
| | | func InitNode(clusterID string, password string, nodeID string) (*Agent, error) { |
| | | func InitNode(clusterID string, password string, nodeID string, snapshotPath string) (*Agent, error) { |
| | | conf := DefaultConfig() |
| | | logger.Info("clusterID:", clusterID, "password:", password, "nodeID:", nodeID) |
| | | conf.ClusterID = clusterID |
| | |
| | | } |
| | | conf.EncryptKey = password |
| | | } |
| | | agent, err := Create(conf) |
| | | agent, err := Create(conf, snapshotPath) |
| | | if err != nil { |
| | | logger.Error("create agent failed, error: %s", err) |
| | | return agent, err |
| | |
| | | conf := DefaultConfig() |
| | | conf.ClusterID = "testCluster" |
| | | conf.NodeName = "testnode" |
| | | agent, err := Create(conf) |
| | | agent, err := Create(conf, "./snapshotfile") |
| | | if err != nil { |
| | | t.Errorf("create agent failed, error: %s", err) |
| | | } |
| | |
| | | "fmt" |
| | | "net" |
| | | "strconv" |
| | | |
| | | //"github.com/apache/servicecomb-service-center/syncer/pkg/utils" |
| | | "github.com/hashicorp/memberlist" |
| | | "github.com/hashicorp/serf/cmd/serf/command/agent" |
| | |
| | | MaxQuerySize = 50 * 1024 * 1024 |
| | | MaxUserEventSize = 9 * 1024 |
| | | ReplayOnJoinDefault = false |
| | | SnapshotPathDefault = "/opt/vasystem/serfSnapShot" |
| | | SnapshotPathDefault = "./serfSnapShot" |
| | | MaxEventBufferCount = 2048 |
| | | |
| | | TcpTransportPort = 30194 //tcp传输大数据量接口 |
| | |
| | | } |
| | | |
| | | // convertToSerf convert Config to serf.Config |
| | | func (c *Config) convertToSerf() (*serf.Config, error) { |
| | | func (c *Config) convertToSerf(snapshotPath string) (*serf.Config, error) { |
| | | serfConf := serf.DefaultConfig() |
| | | |
| | | bindIP, bindPort, err := SplitHostPort(c.BindAddr, DefaultBindPort) |
| | |
| | | if c.Mode == ModeCluster && c.RetryMaxAttempts <= 0 { |
| | | c.RetryMaxAttempts = retryMaxAttempts |
| | | } |
| | | |
| | | c.SnapshotPath = SnapshotPathDefault |
| | | if snapshotPath != "" { |
| | | c.SnapshotPath = snapshotPath |
| | | } |
| | | |
| | | c.ReplayOnJoin = ReplayOnJoinDefault |
| | | |
| | | serfConf.QueryResponseSizeLimit = c.QueryResponseSizeLimit |