예제 #1
0
파일: main.go 프로젝트: dawanda/mmsd
func (mmsd *mmsdService) getMarathonApp(appID string) (*marathon.App, error) {
	m, err := marathon.NewService(mmsd.MarathonIP, mmsd.MarathonPort)
	if err != nil {
		return nil, err
	}

	app, err := m.GetApp(appID)
	if err != nil {
		return nil, err
	}

	return app, nil
}
예제 #2
0
파일: main.go 프로젝트: dawanda/mmsd
func (mmsd *mmsdService) MaybeResetFromTasks(force bool) error {
	m, err := marathon.NewService(mmsd.MarathonIP, mmsd.MarathonPort)
	if err != nil {
		return fmt.Errorf("Could not create new marathon service. %v", err)
	}

	apps, err := m.GetApps()
	if err != nil {
		return fmt.Errorf("Could not get apps. %v", err)
	}

	for _, handler := range mmsd.Handlers {
		err = handler.Apply(apps, force)
		if err != nil {
			log.Printf("Failed to apply changes to handler. %v\n", err)
		}
	}

	return nil
}
예제 #3
0
파일: main.go 프로젝트: dawanda/mmsd
// enable/disable given app:task
func (mmsd *mmsdService) Update(appID string, taskID string, alive bool) {
	m, err := marathon.NewService(mmsd.MarathonIP, mmsd.MarathonPort)
	if err != nil {
		log.Printf("Update: NewService(%q, %v) failed. %v\n", mmsd.MarathonIP, mmsd.MarathonPort, err)
		return
	}

	app, err := m.GetApp(appID)
	if err != nil {
		log.Printf("Update: GetApp(%q) failed. %v\n", appID, err)
		return
	}

	for _, handler := range mmsd.Handlers {
		err = handler.Update(app, taskID)
		if err != nil {
			log.Printf("Update failed. %v\n", err)
		}
	}
}
예제 #4
0
파일: main.go 프로젝트: dawanda/mmsd
func (mmsd *mmsdService) v1Apps(w http.ResponseWriter, r *http.Request) {
	m, err := marathon.NewService(mmsd.MarathonIP, mmsd.MarathonPort)

	if err != nil {
		w.WriteHeader(http.StatusInternalServerError)
		log.Printf("NewService error. %v\n", err)
		return
	}

	apps, err := m.GetApps()
	if err != nil {
		w.WriteHeader(http.StatusInternalServerError)
		log.Printf("GetApps error. %v\n", err)
		return
	}

	var appList []string
	for _, app := range apps {
		appList = append(appList, app.Id)
	}
	sort.Strings(appList)

	fmt.Fprintf(w, "%s\n", strings.Join(appList, "\n"))
}
예제 #5
0
파일: main.go 프로젝트: dawanda/mmsd
func (mmsd *mmsdService) v1Instances(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	appID := vars["app_id"]
	noResolve := r.URL.Query().Get("noresolve") == "1"
	withServerID := r.URL.Query().Get("withid") == "1"

	portBegin, portEnd, err := parseRange(r.URL.Query().Get("portIndex"))
	if err != nil {
		w.WriteHeader(http.StatusBadRequest)
		log.Printf("error parsing range. %v\n", err)
		return
	}

	m, err := marathon.NewService(mmsd.MarathonIP, mmsd.MarathonPort)
	if err != nil {
		w.WriteHeader(http.StatusInternalServerError)
		log.Printf("NewService error. %v\n", err)
		return
	}

	app, err := m.GetApp(appID)
	if err != nil {
		w.WriteHeader(http.StatusInternalServerError)
		log.Printf("GetApp error. %v\n", err)
		return
	}

	if app == nil {
		w.WriteHeader(http.StatusNotFound)
		return
	}

	log.Printf("parseRange: %v .. %v (%v)\n", portBegin, portEnd, len(app.Ports))

	if portEnd >= len(app.Ports) {
		w.WriteHeader(http.StatusBadRequest)
		return
	}
	if portEnd < 0 {
		portEnd = len(app.Ports) - 1
	}

	if len(app.Tasks) == 0 {
		w.WriteHeader(http.StatusNoContent)
		return
	}

	// appJson, err := json.MarshalIndent(app, "", " ")
	// w.Write(appJson)
	// fmt.Fprintf(w, "\n")
	// return

	var list []string
	for _, task := range app.Tasks {
		item := ""
		if withServerID {
			item += fmt.Sprintf("%v:", Hash(task.SlaveId))
		}

		item += resolveIPAddr(task.Host, noResolve)

		for portIndex := portBegin; portIndex <= portEnd; portIndex++ {
			item += fmt.Sprintf(":%d", task.Ports[portIndex])
		}

		list = append(list, item)
	}

	sort.Strings(list)

	for _, entry := range list {
		fmt.Fprintln(w, entry)
	}
}