Beispiel #1
0
// Dcoker模块
func StartControllerrModule(joinAddress, serviceAddress, clusterAddress string) {
	// 设置日志格式
	log.SetFlags(log.Ldate | log.Lmicroseconds | log.Lshortfile)
	// 参数检查
	if serviceAddress == "" {
		log.Fatal("Service address is required")
	}
	if clusterAddress == "" {
		log.Fatal("Cluster address is required")
	}
	// 保存配置
	config.JoinAddress = joinAddress
	config.ServiceAddress = serviceAddress
	config.ClusterAddress = clusterAddress
	config.Role = config.ControllerRoleName
	config.Controllers[clusterAddress] = time.Now().Unix()

	// 集群内部通信服务器
	go cluster.NewClusterServer()
	// 注册内部通信命令处理函数
	cluster.ClusterHandlers()
	// 与docker连接断开后处理
	cluster.ClusterSwitcher.Register("disconnect", DockerDisconnection)

	if config.JoinAddress != "" {
		config.Controllers[joinAddress] = time.Now().Unix()
		// 从接入点获取集群的结构
		go cluster.ControllerJoinCluster()
	}

	// 启动代理服务器
	proxy.NewProxyServer()
}
Beispiel #2
0
// Dcoker插件
func StartDockerModule(protoAddrs []string, joinAddress string, eng *engine.Engine) {
	var (
		clusterAddress string
	)
	for _, protoAddr := range protoAddrs {
		protoAddrParts := strings.SplitN(protoAddr, "://", 2)
		if len(protoAddrParts) == 2 && protoAddrParts[0] == "tcp" {
			clusterAddress = protoAddrParts[1]
		}
	}

	if joinAddress == "" {
		log.Fatal("Join address is required")
	}
	if clusterAddress == "" {
		log.Fatal("Cluster address is required")
	}

	// 设置日志格式
	log.SetFlags(log.Ldate | log.Lmicroseconds | log.Lshortfile)

	// 保存配置
	config.JoinAddress = joinAddress
	config.Role = config.DockerRoleName
	config.ClusterAddress = clusterAddress
	config.Dockers[clusterAddress] = time.Now().Unix()
	config.Controllers[joinAddress] = time.Now().Unix()

	// 注册内部通信命令处理函数
	cluster.ClusterHandlers()
	// 与controller连接断开后,将向连接的所有controller广播
	cluster.ClusterSwitcher.Register("disconnect", ControllerDisconnection)

	// docker加入集群
	cluster.DockerJoinCluster(eng)
}