diff options
Diffstat (limited to 'web-app/server.go')
-rw-r--r-- | web-app/server.go | 62 |
1 files changed, 59 insertions, 3 deletions
diff --git a/web-app/server.go b/web-app/server.go index efbff70..62e1842 100644 --- a/web-app/server.go +++ b/web-app/server.go @@ -260,7 +260,63 @@ func Results_Tempest_AllJobIds(w http.ResponseWriter, r *http.Request) { func Results_Tempest_OS(w http.ResponseWriter, r *http.Request) { - fmt.Fprintf(w, "URL: %s", r.URL.Path) + w.Header().Set("Content-Type", "application/json") + + count_param := mux.Vars(r)["count"] + count, err := strconv.Atoi(count_param) + if err != nil { + log.Println("error converting parameter from string to int: ", err) + } + + if count < 1 { + count = 1 + } + + if count > 60 { + count = 60 + } + + db, err := neoism.Connect(*neo4j_server) + if err != nil { + log.Println("error connecting to database: ", err) + } + + res := [] struct { + LAVA_Job int32 `json:"t.lava_job"` + Date string `json:"t.date"` + SHA1 string `json:"t.sha1"` + All_tests int32 `json:"t.all_tests"` + Passing_tests int32 `json:"t.passing_tests"` + Failing_tests int32 `json:"t.failing_tests"` + Tests_run int32 `json:"t.tests_run"` + Skipped_tests int32 `json:"t.skipped_tests"` + OS_Distro string `json:"o.distro"` + OS_Version string `json:"o.version"` + Devstack_Branch string `json:"d.name"` + Epoch_time int64 `json:"t.epoch_time"` + }{} + + cq := neoism.CypherQuery{ + Statement: `MATCH (d:Devstack)<-[:USING]-(t:TempestRun)-[:ON]->(o:OS) + WHERE o.distro = {osdistro} AND o.version = {osversion} + RETURN t.lava_job, t.date, t.sha1, t.all_tests, + t.passing_tests, t.failing_tests, t.tests_run, t.skipped_tests, + t.epoch_time, o.distro, o.version, d.name + ORDER BY t.epoch_time DESC + LIMIT {count}`, + Parameters: neoism.Props{"count": count, "osdistro": mux.Vars(r)["osdistro"], "osversion": mux.Vars(r)["osversion"]}, + Result: &res, + } + + err = db.Cypher(&cq) + if err != nil { + log.Println("query error: ", err) + } + + log.Printf("%#v", res) + + enc := json.NewEncoder(w) + enc.Encode(res) } @@ -379,8 +435,8 @@ func main() { s.HandleFunc("/tempest", Results_Tempest_LastN).Queries("count", "{count:[0-9]+}") // DONE s.HandleFunc("/tempest", Results_Tempest_Summary) // DONE s.HandleFunc("/tempest/jobs", Results_Tempest_AllJobIds) // DONE - s.HandleFunc("/tempest/operating-system/{os-distro}/{os-version}", Results_Tempest_OS).Queries("count", "{count:[0-9]+}") - s.HandleFunc("/tempest/operating-system/{os-distro}/{os-version}", Results_Tempest_OS_Summary) + s.HandleFunc("/tempest/operating-system/{osdistro}/{osversion}", Results_Tempest_OS).Queries("count", "{count:[0-9]+}") + s.HandleFunc("/tempest/operating-system/{osdistro}/{osversion}", Results_Tempest_OS_Summary) s.HandleFunc("/tempest/devstack-branch/{branch}", Results_Tempest_Branch).Queries("count", "{count:[0-9]+}") s.HandleFunc("/tempest/devstack-branch/{branch}", Results_Tempest_Branch_Summary) s.HandleFunc("/tempest/job/{job:[0-9]+}", Results_Tempest_Job_Summary) // DONE |