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) } }
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() } }
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) }
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) }
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) }
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") }
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) }
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") }
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) }
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) }
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) }
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") }
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") }
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) }
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") }