func sync(inst *install.Install, force bool) { if inst == nil { client := consulClient() inst = install.NewInstall(client, nil, nil, nil) } sources := []*install.Source{ &install.Source{ Name: "mantl", Path: "https://github.com/CiscoCloud/mantl-universe.git", SourceType: install.Git, Index: 1, }, &install.Source{ Name: "mesosphere", Path: "https://github.com/mesosphere/universe.git", SourceType: install.Git, Index: 0, }, &install.Source{ Name: "mesosphere-multiverse", Path: "https://github.com/mesosphere/multiverse.git", SourceType: install.Git, Index: 2, }, } inst.SyncSources(sources, force) }
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() }
func sync(inst *install.Install, force bool) { var err error if inst == nil { client := consulClient() inst, err = install.NewInstall(client, nil, nil, nil) if err != nil { log.Fatalf("Could not create install client: %v", err) } } defaultSources := []*install.Source{ &install.Source{ Name: "mantl", Path: "https://github.com/CiscoCloud/mantl-universe.git", SourceType: install.Git, Branch: "master", Index: 1, }, &install.Source{ Name: "mesosphere", Path: "https://github.com/mesosphere/universe.git", SourceType: install.Git, Index: 0, }, } sources := []*install.Source{} configuredSources := viper.GetStringMap("sources") if len(configuredSources) > 0 { for name, val := range configuredSources { source := &install.Source{Name: name, SourceType: install.FileSystem} sourceConfig := val.(map[string]interface{}) if path, ok := sourceConfig["path"].(string); ok { source.Path = path } if index, ok := sourceConfig["index"].(int64); ok { source.Index = int(index) } if sourceType, ok := sourceConfig["type"].(string); ok { if strings.EqualFold(sourceType, "git") { source.SourceType = install.Git } } if branch, ok := sourceConfig["branch"].(string); ok { source.Branch = branch } if source.IsValid() { sources = append(sources, source) } else { log.Warnf("Invalid source configuration for %s", name) } } } if len(sources) == 0 { sources = defaultSources } inst.SyncSources(sources, force) }
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() }