API endpoint for continuous queries should return simplified results.

pull/269/head
Todd Persen 2014-02-19 14:35:53 -05:00
parent ca1d9bf160
commit 5d68db9f7f
2 changed files with 29 additions and 31 deletions

View File

@ -699,6 +699,11 @@ type UserDetail struct {
IsAdmin bool `json:"isAdmin"`
}
type ContinuousQuery struct {
Id int64 `json:"id"`
Query string `json:"query"`
}
type NewContinuousQuery struct {
Query string `json:"query"`
}
@ -1010,11 +1015,17 @@ func (self *HttpServer) listDbContinuousQueries(w libhttp.ResponseWriter, r *lib
db := r.URL.Query().Get(":db")
self.tryAsDbUserAndClusterAdmin(w, r, func(u common.User) (int, interface{}) {
queries, err := self.coordinator.ListContinuousQueries(u, db)
series, err := self.coordinator.ListContinuousQueries(u, db)
if err != nil {
return errorToStatusCode(err), err.Error()
}
queries := make([]ContinuousQuery, 0, len(series[0].Points))
for _, point := range series[0].Points {
queries = append(queries, ContinuousQuery{Id: *point.Values[0].Int64Value, Query: *point.Values[1].StringValue})
}
return libhttp.StatusOK, queries
})
}
@ -1030,7 +1041,6 @@ func (self *HttpServer) createDbContinuousQueries(w libhttp.ResponseWriter, r *l
}
json.Unmarshal(body, &values)
query := values.(map[string]interface{})["query"].(string)
fmt.Println(query)
if err := self.coordinator.CreateContinuousQuery(u, db, query); err != nil {
return errorToStatusCode(err), err.Error()

View File

@ -801,16 +801,13 @@ func (self *ApiSuite) TestContinuousQueryOperations(c *C) {
c.Assert(resp.Header.Get("content-type"), Equals, "application/json")
body, err := ioutil.ReadAll(resp.Body)
c.Assert(err, IsNil)
series := []*protocol.Series{}
err = json.Unmarshal(body, &series)
queries := []ContinuousQuery{}
err = json.Unmarshal(body, &queries)
c.Assert(err, IsNil)
c.Assert(series, HasLen, 1)
c.Assert(series[0].Points, HasLen, 1)
c.Assert(series[0].Points[0].Values, HasLen, 2)
c.Assert(queries, HasLen, 1)
c.Assert(*series[0].Name, Equals, "continuous queries")
c.Assert(*series[0].Points[0].Values[0].Int64Value, Equals, int64(1))
c.Assert(*series[0].Points[0].Values[1].StringValue, Equals, "select * from foo into bar;")
c.Assert(queries[0].Id, Equals, int64(1))
c.Assert(queries[0].Query, Equals, "select * from foo into bar;")
resp.Body.Close()
@ -829,20 +826,15 @@ func (self *ApiSuite) TestContinuousQueryOperations(c *C) {
c.Assert(resp.Header.Get("content-type"), Equals, "application/json")
body, err = ioutil.ReadAll(resp.Body)
c.Assert(err, IsNil)
series = []*protocol.Series{}
err = json.Unmarshal(body, &series)
queries = []ContinuousQuery{}
err = json.Unmarshal(body, &queries)
c.Assert(err, IsNil)
c.Assert(series, HasLen, 1)
c.Assert(series[0].Points, HasLen, 2)
c.Assert(series[0].Points[0].Values, HasLen, 2)
c.Assert(series[0].Points[1].Values, HasLen, 2)
c.Assert(*series[0].Name, Equals, "continuous queries")
c.Assert(*series[0].Points[0].Values[0].Int64Value, Equals, int64(1))
c.Assert(*series[0].Points[0].Values[1].StringValue, Equals, "select * from foo into bar;")
c.Assert(*series[0].Points[1].Values[0].Int64Value, Equals, int64(2))
c.Assert(*series[0].Points[1].Values[1].StringValue, Equals, "select * from quu into qux;")
c.Assert(queries, HasLen, 2)
c.Assert(queries[0].Id, Equals, int64(1))
c.Assert(queries[0].Query, Equals, "select * from foo into bar;")
c.Assert(queries[1].Id, Equals, int64(2))
c.Assert(queries[1].Query, Equals, "select * from quu into qux;")
resp.Body.Close()
@ -864,15 +856,11 @@ func (self *ApiSuite) TestContinuousQueryOperations(c *C) {
c.Assert(resp.Header.Get("content-type"), Equals, "application/json")
body, err = ioutil.ReadAll(resp.Body)
c.Assert(err, IsNil)
series = []*protocol.Series{}
err = json.Unmarshal(body, &series)
queries = []ContinuousQuery{}
err = json.Unmarshal(body, &queries)
c.Assert(err, IsNil)
c.Assert(series, HasLen, 1)
c.Assert(series[0].Points, HasLen, 1)
c.Assert(series[0].Points[0].Values, HasLen, 2)
c.Assert(*series[0].Name, Equals, "continuous queries")
c.Assert(*series[0].Points[0].Values[0].Int64Value, Equals, int64(1))
c.Assert(*series[0].Points[0].Values[1].StringValue, Equals, "select * from foo into bar;")
c.Assert(queries, HasLen, 1)
c.Assert(queries[0].Id, Equals, int64(1))
c.Assert(queries[0].Query, Equals, "select * from foo into bar;")
resp.Body.Close()
}