Browse Source

remove from and to params from the data service (defaults to 24 hours), ensure data is only kept for 24 hours

Mark deVilliers 2 years ago
parent
commit
e052490ac2
5 changed files with 18 additions and 57 deletions
  1. 2 2
      client/storage/README.md
  2. 4 8
      client/storage/data_api.go
  3. 5 7
      client/storage/docs/DataApi.md
  4. 1 3
      node/api/data.go
  5. 6 37
      storage/api/data.go

+ 2 - 2
client/storage/README.md

@@ -6,7 +6,7 @@ This API client was generated by the [swagger-codegen](https://github.com/swagge
6 6
 
7 7
 - API version: 
8 8
 - Package version: 1.0.0
9
-- Build date: 2017-07-19T11:48:52.147+01:00
9
+- Build date: 2017-08-15T09:16:43.347+01:00
10 10
 - Build package: class io.swagger.codegen.languages.GoClientCodegen
11 11
 
12 12
 ## Installation
@@ -22,7 +22,7 @@ All URIs are relative to *https://localhost*
22 22
 Class | Method | HTTP request | Description
23 23
 ------------ | ------------- | ------------- | -------------
24 24
 *DataApi* | [**Append**](docs/DataApi.md#append) | **Put** /data/ | append data to a bucket, will create the bucket if it does not exist.
25
-*DataApi* | [**GetAll**](docs/DataApi.md#getall) | **Get** /data/ | returns all of the data stored in a logical 'bucket'.
25
+*DataApi* | [**GetAll**](docs/DataApi.md#getall) | **Get** /data/ | returns all of the data stored in a logical 'bucket' in the last 24 hours.
26 26
 
27 27
 
28 28
 ## Documentation For Models

+ 4 - 8
client/storage/data_api.go

@@ -100,15 +100,13 @@ func (a DataApi) Append(body ApiData) (*APIResponse, error) {
100 100
 }
101 101
 
102 102
 /**
103
- * returns all of the data stored in a logical 'bucket'.
104
- * returns all of the data stored in a logical 'bucket'.
103
+ * returns all of the data stored in a logical 'bucket' in the last 24 hours.
104
+ * returns all of the data stored in a logical 'bucket' in the last 24 hours.
105 105
  *
106
- * @param from return data from this ISO8601 timestamp. Defaults to 24 hours ago.
107
- * @param to finish at this ISO8601 timestamp 
108 106
  * @param bucketUid name of the 'bucket' of data
109 107
  * @return []ApiDataResponse
110 108
  */
111
-func (a DataApi) GetAll(from string, to string, bucketUid string) ([]ApiDataResponse, *APIResponse, error) {
109
+func (a DataApi) GetAll(bucketUid string) ([]ApiDataResponse, *APIResponse, error) {
112 110
 
113 111
 	var httpMethod = "Get"
114 112
 	// create path and map variables
@@ -125,9 +123,7 @@ func (a DataApi) GetAll(from string, to string, bucketUid string) ([]ApiDataResp
125 123
 	for key := range a.Configuration.DefaultHeader {
126 124
 		headerParams[key] = a.Configuration.DefaultHeader[key]
127 125
 	}
128
-		queryParams.Add("from", a.Configuration.APIClient.ParameterToString(from, ""))
129
-			queryParams.Add("to", a.Configuration.APIClient.ParameterToString(to, ""))
130
-			queryParams.Add("bucket-uid", a.Configuration.APIClient.ParameterToString(bucketUid, ""))
126
+		queryParams.Add("bucket-uid", a.Configuration.APIClient.ParameterToString(bucketUid, ""))
131 127
 	
132 128
 
133 129
 	// to determine the Content-Type header

+ 5 - 7
client/storage/docs/DataApi.md

@@ -5,7 +5,7 @@ All URIs are relative to *https://localhost*
5 5
 Method | HTTP request | Description
6 6
 ------------- | ------------- | -------------
7 7
 [**Append**](DataApi.md#Append) | **Put** /data/ | append data to a bucket, will create the bucket if it does not exist.
8
-[**GetAll**](DataApi.md#GetAll) | **Get** /data/ | returns all of the data stored in a logical 'bucket'.
8
+[**GetAll**](DataApi.md#GetAll) | **Get** /data/ | returns all of the data stored in a logical 'bucket' in the last 24 hours.
9 9
 
10 10
 
11 11
 # **Append**
@@ -38,20 +38,18 @@ No authorization required
38 38
 [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
39 39
 
40 40
 # **GetAll**
41
-> []ApiDataResponse GetAll($from, $to, $bucketUid)
41
+> []ApiDataResponse GetAll($bucketUid)
42 42
 
43
-returns all of the data stored in a logical 'bucket'.
43
+returns all of the data stored in a logical 'bucket' in the last 24 hours.
44 44
 
45
-returns all of the data stored in a logical 'bucket'.
45
+returns all of the data stored in a logical 'bucket' in the last 24 hours.
46 46
 
47 47
 
48 48
 ### Parameters
49 49
 
50 50
 Name | Type | Description  | Notes
51 51
 ------------- | ------------- | ------------- | -------------
52
- **from** | **string**| return data from this ISO8601 timestamp. Defaults to 24 hours ago. | [optional] [default to ]
53
- **to** | **string**| finish at this ISO8601 timestamp  | [optional] [default to ]
54
- **bucketUid** | **string**| name of the 'bucket' of data | [optional] [default to ]
52
+ **bucketUid** | **string**| name of the 'bucket' of data | [optional] 
55 53
 
56 54
 ### Return type
57 55
 

+ 1 - 3
node/api/data.go

@@ -107,9 +107,7 @@ func (e dataResource) getData(request *restful.Request, response *restful.Respon
107 107
 		return
108 108
 	}
109 109
 
110
-	// go and get the data
111
-	// TODO : specify beginning and end dates
112
-	data, _, err := e.sClient.GetAll("", "", req.Key)
110
+	data, _, err := e.sClient.GetAll(req.Key)
113 111
 
114 112
 	if err != nil {
115 113
 		response.WriteHeaderAndEntity(http.StatusInternalServerError, ErrorResponse{Error: err.Error()})

+ 6 - 37
storage/api/data.go

@@ -9,7 +9,6 @@ import (
9 9
 	restful "github.com/emicklei/go-restful"
10 10
 	restfulspec "github.com/emicklei/go-restful-openapi"
11 11
 	redis_client "github.com/garyburd/redigo/redis"
12
-	"gogs.dyne.org/DECODE/decode-prototype-da/utils"
13 12
 )
14 13
 
15 14
 // ErrorResponse signals error messages back to the client
@@ -51,9 +50,7 @@ func (e dataResource) WebService() *restful.WebService {
51 50
 	tags := []string{"data"}
52 51
 
53 52
 	ws.Route(ws.GET("/").To(e.getAll).
54
-		Doc("returns all of the data stored in a logical 'bucket'.").
55
-		Param(ws.QueryParameter("from", "return data from this ISO8601 timestamp. Defaults to 24 hours ago.").DataType("date").DataFormat(utils.ISO8601)).
56
-		Param(ws.QueryParameter("to", "finish at this ISO8601 timestamp ").DataType("date").DataFormat(utils.ISO8601)).
53
+		Doc("returns all of the data stored in a logical 'bucket' in the last 24 hours.").
57 54
 		Param(ws.QueryParameter("bucket-uid", "name of the 'bucket' of data").DataType("string")).
58 55
 		Metadata(restfulspec.KeyOpenAPITags, tags).
59 56
 		Writes([]DataResponse{}).
@@ -73,48 +70,20 @@ func (e dataResource) WebService() *restful.WebService {
73 70
 }
74 71
 func (e dataResource) getAll(request *restful.Request, response *restful.Response) {
75 72
 
76
-	fromStr := request.QueryParameter("from")
77
-	toStr := request.QueryParameter("to")
78 73
 	prefix := request.QueryParameter("bucket-uid")
79 74
 
80 75
 	timestep := time.Second
81
-	expiry := time.Duration(0)
76
+	expiry := time.Duration(time.Hour * 24)
82 77
 
83 78
 	ts := NewTimeSeries(prefix, timestep, expiry, e.pool)
84
-	var from, to time.Time
85
-	var err error
86 79
 
87 80
 	// TODO : review should this be UTC?
88
-	now := time.Now()
89
-
90
-	if fromStr == "" {
91
-		// default to 24 hours ago
92
-		from = now.Add(-(time.Hour * 24))
93
-	} else {
94
-
95
-		from, err = time.Parse(utils.ISO8601, fromStr)
96
-
97
-		if err != nil {
98
-			response.WriteHeaderAndEntity(http.StatusBadRequest, ErrorResponse{Error: err.Error()})
99
-			return
100
-		}
101
-
102
-	}
103
-	if toStr == "" {
104
-		//default to now
105
-		to = now
106
-	} else {
107
-		to, err = time.Parse(utils.ISO8601, toStr)
108
-
109
-		if err != nil {
110
-			response.WriteHeaderAndEntity(http.StatusBadRequest, ErrorResponse{Error: err.Error()})
111
-			return
112
-		}
113
-	}
81
+	to := time.Now()
82
+	from := to.Add(-(time.Hour * 24))
114 83
 
115 84
 	data := []*DataResponse{}
116 85
 
117
-	err = ts.FetchRange(from, to, &data)
86
+	err := ts.FetchRange(from, to, &data)
118 87
 
119 88
 	if err != nil {
120 89
 		response.WriteHeaderAndEntity(http.StatusInternalServerError, ErrorResponse{Error: err.Error()})
@@ -140,7 +109,7 @@ func (e dataResource) append(request *restful.Request, response *restful.Respons
140 109
 
141 110
 	prefix := data.Bucket
142 111
 	timestep := time.Second
143
-	expiry := time.Duration(0)
112
+	expiry := time.Duration(time.Hour * 24)
144 113
 
145 114
 	ts := NewTimeSeries(prefix, timestep, expiry, e.pool)
146 115