Esempio n. 1
0
func (this *Engine) LoadConfigFile() *Engine {
	log.Info("Engine[%s] loading config file %s", BuildID, this.configFile)

	cf := new(engineConfig)
	var err error
	cf.Conf, err = conf.Load(this.configFile)
	if err != nil {
		panic(err)
	}

	this.conf = cf
	this.doLoadConfig()

	// RegisterHttpApi is ready
	this.setupHttpServ()

	// when config loaded, create the servants
	svr := servant.NewFunServant(config.Servants)
	this.rpcProcessor = rpc.NewFunServantProcessor(svr)
	svr.Start()

	this.peer = peer.NewPeer(this.conf.peerGroupAddr,
		this.conf.peerHeartbeatInterval, this.conf.peerDeadThreshold)

	return this
}
Esempio n. 2
0
func main() {
	var fn string
	flag.StringVar(&fn, "c", "", "config file path")
	flag.Parse()

	cf, err := conf.Load(fn)
	if err != nil {
		fmt.Printf("Invalid config file[%s]: %v\n", fn, err)
		os.Exit(1)
	}

	graph = make(map[string]*identEntry)
	identName = make(map[string]string)

	// only visualize the plugins section
	for i := 0; i < len(cf.List("plugins", nil)); i++ {
		section, err := cf.Section(fmt.Sprintf("plugins[%d]", i))
		if err != nil {
			panic(err)
		}

		handleSection(section)
	}

	showGraph()
}
Esempio n. 3
0
func setupServant() *FunServantImpl {
	server.SetupLogging(".canbedeleted.test.log", "info", "", "", "")

	cf, _ := conf.Load("../etc/faed.cf")
	config.LoadEngineConfig(cf)
	server.LaunchHttpServer(":9999", "")
	return NewFunServant(config.Engine.Servants)
}
Esempio n. 4
0
func LoadConfig(fn string) {
	cf, err := jsconf.Load(fn)
	if err != nil {
		panic(err)
	}

	conf = new(config)
	conf.hostname, _ = os.Hostname()
	conf.kafkaHome = cf.String("kafka_home", "")
	conf.logLevel = cf.String("loglevel", "info")
	conf.influxdbHost = cf.String("influxdb_host", "")
	conf.zones = make(map[string]string)
	conf.consulBootstrap = cf.String("consul_bootstrap", "")
	conf.zkDefaultZone = cf.String("zk_default_zone", "")
	conf.tunnels = make(map[string]string)
	conf.aliases = make(map[string]string)
	for i := 0; i < len(cf.List("aliases", nil)); i++ {
		section, err := cf.Section(fmt.Sprintf("aliases[%d]", i))
		if err != nil {
			panic(err)
		}

		conf.aliases[section.String("cmd", "")] = section.String("alias", "")
	}

	for i := 0; i < len(cf.List("zones", nil)); i++ {
		section, err := cf.Section(fmt.Sprintf("zones[%d]", i))
		if err != nil {
			panic(err)
		}

		z := new(zone)
		z.loadConfig(section)
		conf.zones[z.name] = z.zk
		conf.tunnels[z.name] = z.tunnel
	}

	conf.reverseDns = make(map[string][]string)
	for _, entry := range cf.StringList("reverse_dns", nil) {
		if entry != "" {
			// entry e,g. k11000b.sit.wdds.kfk.com:10.213.33.149
			parts := strings.SplitN(entry, ":", 2)
			if len(parts) != 2 {
				panic("invalid reverse_dns record")
			}

			ip, host := strings.TrimSpace(parts[1]), strings.TrimSpace(parts[0])
			if _, present := conf.reverseDns[ip]; !present {
				conf.reverseDns[ip] = make([]string, 0)
			}

			conf.reverseDns[ip] = append(conf.reverseDns[ip], host)
		}
	}

}
Esempio n. 5
0
func (this *EngineConfig) LoadConfigFile(fn string) *EngineConfig {
	cf, err := conf.Load(fn)
	if err != nil {
		panic(err)
	}

	this.Conf = cf

	var (
		totalCpus int
		maxProcs  int
		globals   = Globals()
	)
	totalCpus = runtime.NumCPU()
	cpuNumConfig := this.String("cpu_num", "auto")
	if cpuNumConfig == "auto" {
		maxProcs = totalCpus/2 + 1
	} else {
		maxProcs, err = strconv.Atoi(cpuNumConfig)
		if err != nil {
			panic(err)
		}
	}
	runtime.GOMAXPROCS(maxProcs)

	globals.Printf("Starting engine with %d/%d CPUs...", maxProcs, totalCpus)

	// 'projects' section
	for i := 0; i < len(this.List("projects", nil)); i++ {
		section, err := this.Section(fmt.Sprintf("projects[%d]", i))
		if err != nil {
			panic(err)
		}

		project := &ConfProject{}
		project.fromConfig(section)
		if _, present := this.projects[project.Name]; present {
			panic("dup project: " + project.Name)
		}
		this.projects[project.Name] = project
	}

	// 'plugins' section
	for i := 0; i < len(this.List("plugins", nil)); i++ {
		section, err := this.Section(fmt.Sprintf("plugins[%d]", i))
		if err != nil {
			panic(err)
		}

		this.loadPluginSection(section)
	}

	return this
}
Esempio n. 6
0
func (this *Server) LoadConfig(fn string) *Server {
	log.Info("Server[%s %s@%s] loading config file: %s", this.Name, BuildId, Version, fn)

	var err error
	this.Conf, err = conf.Load(fn)
	if err != nil {
		panic(err)
	}

	return this
}
Esempio n. 7
0
func (this *Engine) LoadConfigFile() *Engine {
	log.Debug("Loading config file %s", this.configFile)

	cf := new(engineConfig)
	var err error
	cf.Conf, err = conf.Load(this.configFile)
	if err != nil {
		panic(err)
	}

	this.conf = cf
	this.doLoadConfig()

	// RegisterHttpApi is ready
	this.setupHttpServ()

	// when config loaded, create the servants
	this.rpcProcessor = rpc.NewFunServantProcessor(servant.NewFunServant(config.Servants))

	return this
}
Esempio n. 8
0
func loadConfig(fn string) error {
	cf, err := conf.Load(fn)
	if err != nil {
		return err
	}

	for i := 0; i < len(cf.List("tables", nil)); i++ {
		section, err := cf.Section(fmt.Sprintf("tables[%d]", i))
		if err != nil {
			return err
		}

		t := table{}
		if err = t.init(section); err != nil {
			return err
		}
		allTables[t.name] = t
	}

	return nil
}
Esempio n. 9
0
func loadConfig(fn string) (apis []apiConfig) {
	cf, err := conf.Load(fn)
	if err != nil {
		panic(err)
	}

	for i := 0; i < len(cf.List("api", nil)); i++ {
		section, err := cf.Section(fmt.Sprintf("api[%d]", i))
		if err != nil {
			panic(err)
		}

		apiInfo := apiConfig{}
		apiInfo.loadConfig(section)
		apis = append(apis, apiInfo)

		log.Debug("api: %+v", apiInfo)
	}

	return
}
Esempio n. 10
0
func setupConfig() *config.ConfigMongodb {
	cf, _ := conf.Load("../../etc/faed.cf")
	section, _ := cf.Section("servants")
	config.LoadServants(section)
	return config.Servants.Mongodb
}
Esempio n. 11
0
func setupServant() *FunServantImpl {
	cf, _ := conf.Load("../etc/faed.cf")
	section, _ := cf.Section("servants")
	config.LoadServants(section)
	return NewFunServant(config.Servants)
}