diff options
author | Clark Laughlin <clark.laughlin@linaro.org> | 2015-05-15 16:17:00 -0400 |
---|---|---|
committer | Clark Laughlin <clark.laughlin@linaro.org> | 2015-05-15 16:17:00 -0400 |
commit | 59aca11e4e75dac1e0edfa95fbb1662146ec0e23 (patch) | |
tree | 39fd4f9e5b46335ce7015403caaa907b8c8a4d75 | |
parent | e9d8a76fa4b01d499e35fe4efafba49fd564ee2b (diff) |
implemented more queries
-rw-r--r-- | web-app/server.go | 132 |
1 files changed, 121 insertions, 11 deletions
diff --git a/web-app/server.go b/web-app/server.go index ad5bb8a..efbff70 100644 --- a/web-app/server.go +++ b/web-app/server.go @@ -197,17 +197,22 @@ func Results_Tempest_Job_Summary(w http.ResponseWriter, r *http.Request) { SHA1 string `json:"t.sha1"` All_tests int32 `json:"t.all_tests"` Passing_tests int32 `json:"t.passing_tests"` - Tests_run int32 `json:"t.tests_run"` + 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 (t:TempestRun) WHERE t.lava_job = {job} + Statement: `MATCH (d:Devstack)<-[:USING]-(t:TempestRun)-[:ON]->(o:OS) + WHERE t.lava_job = {job} 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`, + t.epoch_time, o.distro, o.version, d.name`, Parameters: neoism.Props{"job": job}, Result: &res, } @@ -224,6 +229,36 @@ func Results_Tempest_Job_Summary(w http.ResponseWriter, r *http.Request) { } +func Results_Tempest_AllJobIds(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + + db, err := neoism.Connect(*neo4j_server) + if err != nil { + log.Println("error connecting to database: ", err) + } + + res := [] struct{ + Job_Ids []int32 `json:"lava_job_ids"` + }{} + + cq := neoism.CypherQuery{ + Statement: `MATCH (n:TempestRun) WITH n.lava_job AS lava_job ORDER BY n.epoch_time DESC + RETURN COLLECT(lava_job) as lava_job_ids`, + Result: &res, + } + + err = db.Cypher(&cq) + if err != nil { + log.Println("query error: ", err) + } + + log.Printf("%#v", res[0].Job_Ids) + + enc := json.NewEncoder(w) + enc.Encode(res[0].Job_Ids) +} + + func Results_Tempest_OS(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "URL: %s", r.URL.Path) } @@ -245,12 +280,86 @@ func Results_Tempest_Branch_Summary(w http.ResponseWriter, r *http.Request) { func Results_Tempest_Job_Failures(w http.ResponseWriter, r *http.Request) { - fmt.Fprintf(w, "URL: %s", r.URL.Path) + w.Header().Set("Content-Type", "application/json") + + job_param := mux.Vars(r)["job"] + job, err := strconv.Atoi(job_param) + if err != nil { + log.Println("error converting parameter from string to int: ", err) + } + + db, err := neoism.Connect(*neo4j_server) + if err != nil { + log.Println("error connecting to database: ", err) + } + + res := [] struct{ + Test_Name string `json:"t.name"` + Test_Status string `json:"t.status"` + Test_Class string `json:"t.test_class"` + Start_Time string `json:"t.start_time"` + Stop_Time string `json:"t.stop_time"` + }{} + + cq := neoism.CypherQuery{ + Statement: `MATCH (n:TempestRun)-[:HAS_TEST {status:"failure"}]-(t:Test) + WHERE n.lava_job = {job} + RETURN t.name, t.status, t.start_time, t.stop_time, t.test_class`, + Parameters: neoism.Props{"job" : job}, + 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) } func Results_Tempest_Job_Skipped(w http.ResponseWriter, r *http.Request) { - fmt.Fprintf(w, "URL: %s", r.URL.Path) + w.Header().Set("Content-Type", "application/json") + + job_param := mux.Vars(r)["job"] + job, err := strconv.Atoi(job_param) + if err != nil { + log.Println("error converting parameter from string to int: ", err) + } + + db, err := neoism.Connect(*neo4j_server) + if err != nil { + log.Println("error connecting to database: ", err) + } + + res := [] struct{ + Test_Name string `json:"t.name"` + Test_Status string `json:"t.status"` + Test_Class string `json:"t.test_class"` + Start_Time string `json:"t.start_time"` + Stop_Time string `json:"t.stop_time"` + }{} + + cq := neoism.CypherQuery{ + Statement: `MATCH (n:TempestRun)-[:HAS_TEST {status:"skip"}]-(t:Test) + WHERE n.lava_job = {job} + RETURN t.name, t.status, t.start_time, t.stop_time, t.test_class`, + Parameters: neoism.Props{"job" : job}, + 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) } @@ -267,15 +376,16 @@ func main() { s.HandleFunc("/operating-systems", Results_AllOS) // tempest - s.HandleFunc("/tempest", Results_Tempest_LastN).Queries("count", "{count:[0-9]+}") - s.HandleFunc("/tempest", Results_Tempest_Summary) - s.HandleFunc("/tempest/operating-system/{os-distro}/{os-version}", Results_Tempest_OS).Queries("count", "{count:[0-9]+}") + 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/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) - s.HandleFunc("/tempest/job/{job:[0-9]+}/failures", Results_Tempest_Job_Failures) - s.HandleFunc("/tempest/job/{job:[0-9]+}/skipped", Results_Tempest_Job_Skipped) + s.HandleFunc("/tempest/job/{job:[0-9]+}", Results_Tempest_Job_Summary) // DONE + s.HandleFunc("/tempest/job/{job:[0-9]+}/failures", Results_Tempest_Job_Failures) // DONE + s.HandleFunc("/tempest/job/{job:[0-9]+}/skipped", Results_Tempest_Job_Skipped) // DONE //s.HandleFunc("/tempest/test/class/{class}", Results_Tempest_Class_LastN).Queries("count", "{count:[0-9]+}") //s.HandleFunc("/tempest/test/class/{class}", Results_Tempest_Class_Summary) //s.HandleFunc("/tempest/test/{test}", Results_Tempest_Test_LastN).Queries("count", "{count:[0-9]+}") |