Exemplo n.º 1
0
func start() {
	client := consulClient()

	marathonUrl := viper.GetString("marathon")
	if marathonUrl == "" {
		marathonUrl = NewDiscovery(client, "marathon", "", "http", marathonUrl).discoveredUrl
	}
	marathonClient, err := marathon.NewMarathon(
		marathonUrl,
		viper.GetString("marathon-user"),
		viper.GetString("marathon-password"),
		viper.GetBool("marathon-no-verify-ssl"),
	)
	if err != nil {
		log.Fatalf("Could not create marathon client: %v", err)
	}

	mesosUrl := viper.GetString("mesos")
	if mesosUrl == "" {
		mesosUrl = NewDiscovery(client, "mesos", "leader", "http", "http://localhost:5050").discoveredUrl
	}
	mesosClient, err := mesos.NewMesos(
		mesosUrl,
		viper.GetString("mesos-principal"),
		viper.GetString("mesos-secret"),
		viper.GetBool("mesos-no-verify-ssl"),
	)
	if err != nil {
		log.Fatalf("Could not create mesos client: %v", err)
	}

	zkUrls := viper.GetString("zookeeper")
	if zkUrls == "" {
		zkUrls = NewDiscovery(client, "zookeeper", "", "", "localhost:2181").discoveredUrl
	}
	zkServers := strings.Split(zkUrls, ",")
	zk := zookeeper.NewZookeeper(zkServers)

	inst, err := install.NewInstall(client, marathonClient, mesosClient, zk)
	if err != nil {
		log.Fatalf("Could not create install client: %v", err)
	}

	// sync sources to consul
	sync(inst, viper.GetBool("force-sync"))

	// start listener
	api.NewApi(viper.GetString("listen"), inst).Start()
}
Exemplo n.º 2
0
func start() {
	log.Infof("Starting %s v%s", Name, Version)
	client := consulClient()

	initVault()

	marathonUrl := viper.GetString("marathon")
	if marathonUrl == "" {
		marathonHosts := NewDiscovery(client, "marathon", "").discoveredHosts
		if len(marathonHosts) > 0 {
			marathonUrl = fmt.Sprintf("http://%s", marathonHosts[0])
		} else {
			marathonUrl = "http://localhost:8080"
		}
	}
	marathonClient, err := marathon.NewMarathon(
		marathonUrl,
		viper.GetString("marathon-user"),
		viper.GetString("marathon-password"),
		viper.GetBool("marathon-no-verify-ssl"),
	)
	if err != nil {
		log.Fatalf("Could not create marathon client: %v", err)
	}

	mesosUrl := viper.GetString("mesos")
	if mesosUrl == "" {
		mesosHosts := NewDiscovery(client, "mesos", "leader").discoveredHosts
		if len(mesosHosts) > 0 {
			mesosUrl = fmt.Sprintf("http://%s", mesosHosts[0])
		} else {
			mesosUrl = "http://locahost:5050"
		}
	}
	mesosClient, err := mesos.NewMesos(
		mesosUrl,
		viper.GetString("mesos-principal"),
		viper.GetString("mesos-secret-path"),
		viper.GetBool("mesos-no-verify-ssl"),
	)
	if err != nil {
		log.Fatalf("Could not create mesos client: %v", err)
	}

	var zkHosts []string
	zkUrls := viper.GetString("zookeeper")
	if zkUrls == "" {
		zkHosts = NewDiscovery(client, "zookeeper", "").discoveredHosts
		if len(zkHosts) == 0 {
			zkHosts = []string{"locahost:2181"}
		}
	} else {
		zkHosts = strings.Split(zkUrls, ",")
	}

	inst, err := install.NewInstall(client, marathonClient, mesosClient, zkHosts)
	if err != nil {
		log.Fatalf("Could not create install client: %v", err)
	}

	// sync sources to consul
	syncRepo(inst, viper.GetBool("force-sync"))

	wg.Add(1)
	go inst.Watch(time.Duration(viper.GetInt("consul-refresh-interval")))
	go api.NewApi(Name, viper.GetString("listen"), inst, mesosClient, wg).Start()
	wg.Wait()
}