Esempio n. 1
0
func ApplicationStart(cocs backend.Cocaine, w http.ResponseWriter, r *http.Request) {
	name := r.FormValue("name")
	profile := r.FormValue("profile")

	if len(name) == 0 || len(profile) == 0 {
		http.Error(w, "name or profile wasn't specified", http.StatusInternalServerError)
		return
	}

	stream, err := cocs.ApplicationStart(name, profile)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	if f, ok := w.(http.Flusher); !ok {
		for {
			var p []byte
			_, err := stream.Read(p)
			fmt.Println(p, err)
			if err != nil {
				break
			}
			w.Write(p)
			f.Flush()
		}
	} else {
		body, _ := ioutil.ReadAll(stream)
		fmt.Fprintf(w, "%s", body)
	}
}
Esempio n. 2
0
func ApplicationUpload(cocs backend.Cocaine, w http.ResponseWriter, r *http.Request) {
	name := mux.Vars(r)["name"]
	version := mux.Vars(r)["version"]

	defer r.Body.Close()
	path, err := archive.Unpack(r.Body)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	defer os.RemoveAll(path)

	info := backend.AppUplodaInfo{
		Path:    path,
		App:     name,
		Version: version,
	}

	ch, _, err := cocs.ApplicationUpload(info)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	for lg := range ch {
		w.Write([]byte(lg))
		w.(http.Flusher).Flush()
	}
}
Esempio n. 3
0
func HostList(cocs backend.Cocaine, w http.ResponseWriter, r *http.Request) {
	hosts, err := cocs.HostList()
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	SendJson(w, hosts)
}
Esempio n. 4
0
func ApplicationList(cocs backend.Cocaine, w http.ResponseWriter, r *http.Request) {
	apps, err := cocs.ApplicationList()
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	SendJson(w, apps)
}
Esempio n. 5
0
func BuildLogList(cocs backend.Cocaine, w http.ResponseWriter, r *http.Request) {
	buildlogs, err := cocs.BuildLogList()
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	SendJson(w, buildlogs)
}
Esempio n. 6
0
func GroupRemove(cocs backend.Cocaine, w http.ResponseWriter, r *http.Request) {
	name := mux.Vars(r)["name"]
	err := cocs.GroupRemove(name)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	fmt.Fprint(w, "OK")
}
Esempio n. 7
0
func GroupRead(cocs backend.Cocaine, w http.ResponseWriter, r *http.Request) {
	name := mux.Vars(r)["name"]
	group, err := cocs.GroupRead(name)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	SendJson(w, group)
}
Esempio n. 8
0
func HostAdd(cocs backend.Cocaine, w http.ResponseWriter, r *http.Request) {
	host := mux.Vars(r)["host"]
	err := cocs.HostAdd(host)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	fmt.Fprint(w, "OK")
}
Esempio n. 9
0
func CrashlogList(cocs backend.Cocaine, w http.ResponseWriter, r *http.Request) {
	name := mux.Vars(r)["name"]

	crashlogs, err := cocs.CrashlogList(name)
	if err != nil {
		http.Error(w, err.Error(), http.StatusBadRequest)
		return
	}
	SendJson(w, crashlogs)
}
Esempio n. 10
0
func ProfileList(cocs backend.Cocaine, w http.ResponseWriter, r *http.Request) {
	profiles, err := cocs.ProfileList()

	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	SendJson(w, profiles)
}
Esempio n. 11
0
func BuildLogRead(cocs backend.Cocaine, w http.ResponseWriter, r *http.Request) {
	id := mux.Vars(r)["id"]

	buildlog, err := cocs.BuildLogRead(id)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	fmt.Fprintf(w, buildlog)
}
Esempio n. 12
0
func GroupPopApp(cocs backend.Cocaine, w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	name := vars["name"]
	app := vars["app"]

	err := cocs.GroupPopApp(name, app)
	if err != nil {
		http.Error(w, err.Error(), http.StatusBadRequest)
		return
	}
	fmt.Fprint(w, "OK")
}
Esempio n. 13
0
func ProfileUpload(cocs backend.Cocaine, w http.ResponseWriter, r *http.Request) {
	name := mux.Vars(r)["name"]
	defer r.Body.Close()
	body, _ := ioutil.ReadAll(r.Body)
	if len(body) == 0 {
		http.Error(w, "Empty profile", http.StatusInternalServerError)
		return
	}

	err := cocs.ProfileUpload(name, body)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	fmt.Fprintln(w, "OK")
}
Esempio n. 14
0
func CrashlogView(cocs backend.Cocaine, w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	name := vars["name"]
	timestamp, err := strconv.Atoi(vars["timestamp"])
	if err != nil {
		http.Error(w, "timestamp must be a number", http.StatusBadRequest)
		return
	}

	crashlog, err := cocs.CrashlogView(name, timestamp)
	if err != nil {
		http.Error(w, err.Error(), http.StatusBadRequest)
		return
	}
	fmt.Fprintf(w, crashlog)
}
Esempio n. 15
0
func GroupPushApp(cocs backend.Cocaine, w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)

	name := vars["name"]
	app := vars["app"]
	weights, ok := r.URL.Query()["weight"]
	if !ok || len(weights) == 0 {
		http.Error(w, "weight argument is absent", http.StatusBadRequest)
		return
	}

	weight, err := strconv.Atoi(weights[0])
	if err != nil {
		http.Error(w, "weight must be an integer value", http.StatusBadRequest)
		return
	}

	err = cocs.GroupPushApp(name, app, weight)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	fmt.Fprint(w, "OK")
}