Exemplo n.º 1
0
func handleStatusUpdate(event *MarathonEvent) error {
	log.Infof("Received status update: %s", event.TaskStatus)

	for _, status := range addStatuses {
		if event.TaskStatus == status {
			server := getServer(event)

			if server != nil {
				return addVulcandServer(event.AppID, *server)
			}

			return nil
		}
	}

	for _, status := range removeStatuses {
		if event.TaskStatus == status {
			server := getServer(event)
			if server != nil {
				return removeVulcandServer(event.AppID, *server)
			}

			return nil
		}
	}

	log.Infof("No action for status: %s", event.TaskStatus)
	return nil
}
Exemplo n.º 2
0
func handleEvent(event *MarathonEvent) error {
	if event.EventType == StatusUpdateEvent {
		return handleStatusUpdate(event)
	}

	log.Infof("No action for event type: %s", event.EventType)
	return nil
}
Exemplo n.º 3
0
func getServer(event *MarathonEvent) *VulcandServer {
	if len(event.Ports) == 0 {
		log.Infof("No ports for app %s", event.AppID)
		return nil
	}

	port := event.Ports[0]
	url := fmt.Sprintf("http://%s:%d", event.Host, port)
	hostPort := fmt.Sprintf("%s:%d", event.Host, port)

	return &VulcandServer{
		ID:       event.TaskID,
		URL:      url,
		HostPort: hostPort,
	}
}
Exemplo n.º 4
0
func removeVulcandServer(appID string, server VulcandServer) error {
	backend, err := fetchBackend(appID)

	if err != nil {
		log.Errorf("Error fetching backend from etcd: %v", err)
		return err
	}

	path := serverPath(backend, server.ID)

	err = etcdDelete(path)

	if err != nil {
		log.Errorf("Error delete key from etcd: %v", err)
		return err
	}

	log.Infof("Removed server: %s from backend: %s, url: %s", server.ID, backend.BackendID, server.URL)
	return nil
}
Exemplo n.º 5
0
func addVulcandServer(appID string, server VulcandServer) error {
	backend, err := fetchBackend(appID)

	if err != nil {
		return err
	}

	path := serverPath(backend, server.ID)
	value := backend.Format(server)

	err = etcdSet(path, value)

	if err != nil {
		log.Errorf("Error setting key in etcd: %v", err)
		return err
	}

	log.Infof("Added server: %s to backend: %s, url: %s", server.ID, backend.BackendID, server.URL)
	return nil
}
Exemplo n.º 6
0
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())
	log.Init([]*log.LogConfig{&log.LogConfig{Name: "console"}})

	configtoml := flag.String("f", "kameni.toml", "Path to config. (default kameni.toml)")
	flag.Parse()

	if err := parseConfig(configtoml); err != nil {
		die(err)
	}

	setupEtcd()

	router := mux.NewRouter().StrictSlash(true)
	router.HandleFunc("/marathon_callback", marathonCallback)
	router.HandleFunc("/moxy_callback", marathonCallback)

	log.Infof("Running on: %s", config.ListenAddr())

	if err := http.ListenAndServe(config.ListenAddr(), router); err != nil {
		die(fmt.Errorf("Error starting server: %v", err))
	}
}