[ARVADOS] updated: 0e5dfbbcefcb462617ad89ef116a5b18f9e3ebc8
git at public.curoverse.com
git at public.curoverse.com
Sun Nov 16 16:01:51 EST 2014
Summary of changes:
sdk/go/keepclient/keepclient_test.go | 10 +++-
services/api/app/models/node.rb | 55 +++++++++++++++-------
services/api/config/application.default.yml | 17 ++++++-
services/api/config/unbound.template | 4 ++
services/api/script/restart-dns-server | 34 ++++++++++++++
services/api/script/restart-dnsmasq | 21 ---------
services/keepstore/handler_test.go | 71 +++++++++++------------------
services/keepstore/keepstore.go | 2 +-
services/keepstore/router_wrapper.go | 33 ++++++++------
9 files changed, 144 insertions(+), 103 deletions(-)
create mode 100644 services/api/config/unbound.template
create mode 100755 services/api/script/restart-dns-server
delete mode 100755 services/api/script/restart-dnsmasq
via 0e5dfbbcefcb462617ad89ef116a5b18f9e3ebc8 (commit)
via de35a630edcbe2ddcadf002ab3efe027d77fc046 (commit)
via 7395af3b19b8fc422fe2456c6bead1e7f4c60989 (commit)
via a75ef0985d2a385165168cbb488cf97382308549 (commit)
via d78db2b1b518abdac0893e65123504fb85319010 (commit)
from 11236731eda455b5df6448733e4c0090a5f727c4 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
commit 0e5dfbbcefcb462617ad89ef116a5b18f9e3ebc8
Merge: de35a63 7395af3
Author: radhika <radhika at curoverse.com>
Date: Sun Nov 16 15:57:22 2014 -0500
Merge branch 'master' into 4194-keep-logging
commit de35a630edcbe2ddcadf002ab3efe027d77fc046
Author: radhika <radhika at curoverse.com>
Date: Sun Nov 16 15:51:37 2014 -0500
4194: logging writer copies / appends passed in data into its own buffer.
diff --git a/services/keepstore/router_wrapper.go b/services/keepstore/router_wrapper.go
index 23e7eb2..b1ebd41 100644
--- a/services/keepstore/router_wrapper.go
+++ b/services/keepstore/router_wrapper.go
@@ -4,24 +4,25 @@ package main
// LoggingResponseWriter
import (
+ "bytes"
"github.com/gorilla/mux"
"log"
"net/http"
)
type LoggingResponseWriter struct {
- status int
- data []byte
+ Status int
+ Data *bytes.Buffer
http.ResponseWriter
}
func (loggingWriter *LoggingResponseWriter) WriteHeader(code int) {
- loggingWriter.status = code
+ loggingWriter.Status = code
loggingWriter.ResponseWriter.WriteHeader(code)
}
func (loggingWriter *LoggingResponseWriter) Write(data []byte) (int, error){
- loggingWriter.data = data
+ loggingWriter.Data.Write(data)
return loggingWriter.ResponseWriter.Write(data)
}
@@ -35,16 +36,17 @@ func MakeRESTRouterWrapper() (RESTRouterWrapper) {
}
func (wrapper RESTRouterWrapper) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
- loggingWriter := LoggingResponseWriter{200, nil, resp}
+ loggingWriter := LoggingResponseWriter{200, bytes.NewBuffer(make([]byte, 0, 0)), resp}
wrapper.router.ServeHTTP(&loggingWriter, req)
- if loggingWriter.data != nil && loggingWriter.status == 200 {
- data_len := len(loggingWriter.data)
- if data_len > 200 { // this could be a block, so just print the size
- log.Printf("[%s] %s %s %d %d", req.RemoteAddr, req.Method, req.URL.Path[1:], loggingWriter.status, data_len)
+ if loggingWriter.Status == 200 {
+ if loggingWriter.Data.Len() > 200 { // could be large block, so just print the size
+ log.Printf("[%s] %s %s %d %d", req.RemoteAddr, req.Method, req.URL.Path[1:],
+ loggingWriter.Status, loggingWriter.Data.Len())
} else { // this could be a hash or status or a small block etc
- log.Printf("[%s] %s %s %d %s", req.RemoteAddr, req.Method, req.URL.Path[1:], loggingWriter.status, loggingWriter.data)
+ log.Printf("[%s] %s %s %d %s", req.RemoteAddr, req.Method, req.URL.Path[1:],
+ loggingWriter.Status, loggingWriter.Data)
}
} else {
- log.Printf("[%s] %s %s %d", req.RemoteAddr, req.Method, req.URL.Path[1:], loggingWriter.status)
+ log.Printf("[%s] %s %s %d", req.RemoteAddr, req.Method, req.URL.Path[1:], loggingWriter.Status)
}
}
commit d78db2b1b518abdac0893e65123504fb85319010
Author: radhika <radhika at curoverse.com>
Date: Sat Nov 15 10:55:01 2014 -0500
4194: update keepstore and handler_test to make wrapper instance rather than the two step process of creating REST router and then the wrapper.
diff --git a/services/keepstore/handler_test.go b/services/keepstore/handler_test.go
index e50a9a3..fbf4ef3 100644
--- a/services/keepstore/handler_test.go
+++ b/services/keepstore/handler_test.go
@@ -13,7 +13,6 @@ import (
"bytes"
"encoding/json"
"fmt"
- "github.com/gorilla/mux"
"net/http"
"net/http/httptest"
"os"
@@ -51,9 +50,6 @@ func TestGetHandler(t *testing.T) {
t.Error(err)
}
- // Set up a REST router for testing the handlers.
- rest := MakeRESTRouter()
-
// Create locators for testing.
// Turn on permission settings so we can generate signed locators.
enforce_permissions = true
@@ -74,7 +70,7 @@ func TestGetHandler(t *testing.T) {
// Unauthenticated request, unsigned locator
// => OK
- response := IssueRequest(rest,
+ response := IssueRequest(
&RequestTester{
method: "GET",
uri: unsigned_locator,
@@ -97,7 +93,7 @@ func TestGetHandler(t *testing.T) {
// Authenticated request, signed locator
// => OK
- response = IssueRequest(rest, &RequestTester{
+ response = IssueRequest(&RequestTester{
method: "GET",
uri: signed_locator,
api_token: known_token,
@@ -114,7 +110,7 @@ func TestGetHandler(t *testing.T) {
// Authenticated request, unsigned locator
// => PermissionError
- response = IssueRequest(rest, &RequestTester{
+ response = IssueRequest(&RequestTester{
method: "GET",
uri: unsigned_locator,
api_token: known_token,
@@ -123,7 +119,7 @@ func TestGetHandler(t *testing.T) {
// Unauthenticated request, signed locator
// => PermissionError
- response = IssueRequest(rest, &RequestTester{
+ response = IssueRequest(&RequestTester{
method: "GET",
uri: signed_locator,
})
@@ -133,7 +129,7 @@ func TestGetHandler(t *testing.T) {
// Authenticated request, expired locator
// => ExpiredError
- response = IssueRequest(rest, &RequestTester{
+ response = IssueRequest(&RequestTester{
method: "GET",
uri: expired_locator,
api_token: known_token,
@@ -155,16 +151,13 @@ func TestPutHandler(t *testing.T) {
KeepVM = MakeTestVolumeManager(2)
defer KeepVM.Quit()
- // Set up a REST router for testing the handlers.
- rest := MakeRESTRouter()
-
// --------------
// No server key.
// Unauthenticated request, no server key
// => OK (unsigned response)
unsigned_locator := "/" + TEST_HASH
- response := IssueRequest(rest,
+ response := IssueRequest(
&RequestTester{
method: "PUT",
uri: unsigned_locator,
@@ -188,7 +181,7 @@ func TestPutHandler(t *testing.T) {
// Authenticated PUT, signed locator
// => OK (signed response)
- response = IssueRequest(rest,
+ response = IssueRequest(
&RequestTester{
method: "PUT",
uri: unsigned_locator,
@@ -208,7 +201,7 @@ func TestPutHandler(t *testing.T) {
// Unauthenticated PUT, unsigned locator
// => OK
- response = IssueRequest(rest,
+ response = IssueRequest(
&RequestTester{
method: "PUT",
uri: unsigned_locator,
@@ -249,9 +242,6 @@ func TestIndexHandler(t *testing.T) {
vols[0].Put(TEST_HASH+".meta", []byte("metadata"))
vols[1].Put(TEST_HASH_2+".meta", []byte("metadata"))
- // Set up a REST router for testing the handlers.
- rest := MakeRESTRouter()
-
data_manager_token = "DATA MANAGER TOKEN"
unauthenticated_req := &RequestTester{
@@ -293,7 +283,7 @@ func TestIndexHandler(t *testing.T) {
// unauthenticated /index request
// => UnauthorizedError
- response := IssueRequest(rest, unauthenticated_req)
+ response := IssueRequest(unauthenticated_req)
ExpectStatusCode(t,
"enforce_permissions on, unauthenticated request",
UnauthorizedError.HTTPCode,
@@ -301,7 +291,7 @@ func TestIndexHandler(t *testing.T) {
// unauthenticated /index/prefix request
// => UnauthorizedError
- response = IssueRequest(rest, unauth_prefix_req)
+ response = IssueRequest(unauth_prefix_req)
ExpectStatusCode(t,
"permissions on, unauthenticated /index/prefix request",
UnauthorizedError.HTTPCode,
@@ -309,7 +299,7 @@ func TestIndexHandler(t *testing.T) {
// authenticated /index request, non-superuser
// => UnauthorizedError
- response = IssueRequest(rest, authenticated_req)
+ response = IssueRequest(authenticated_req)
ExpectStatusCode(t,
"permissions on, authenticated request, non-superuser",
UnauthorizedError.HTTPCode,
@@ -317,7 +307,7 @@ func TestIndexHandler(t *testing.T) {
// authenticated /index/prefix request, non-superuser
// => UnauthorizedError
- response = IssueRequest(rest, auth_prefix_req)
+ response = IssueRequest(auth_prefix_req)
ExpectStatusCode(t,
"permissions on, authenticated /index/prefix request, non-superuser",
UnauthorizedError.HTTPCode,
@@ -325,7 +315,7 @@ func TestIndexHandler(t *testing.T) {
// superuser /index request
// => OK
- response = IssueRequest(rest, superuser_req)
+ response = IssueRequest(superuser_req)
ExpectStatusCode(t,
"permissions on, superuser request",
http.StatusOK,
@@ -338,7 +328,7 @@ func TestIndexHandler(t *testing.T) {
// superuser /index request
// => OK
- response = IssueRequest(rest, superuser_req)
+ response = IssueRequest(superuser_req)
ExpectStatusCode(t,
"permissions on, superuser request",
http.StatusOK,
@@ -357,7 +347,7 @@ func TestIndexHandler(t *testing.T) {
// superuser /index/prefix request
// => OK
- response = IssueRequest(rest, superuser_prefix_req)
+ response = IssueRequest(superuser_prefix_req)
ExpectStatusCode(t,
"permissions on, superuser request",
http.StatusOK,
@@ -415,9 +405,6 @@ func TestDeleteHandler(t *testing.T) {
// even though they have just been created.
permission_ttl = time.Duration(0)
- // Set up a REST router for testing the handlers.
- rest := MakeRESTRouter()
-
var user_token = "NOT DATA MANAGER TOKEN"
data_manager_token = "DATA MANAGER TOKEN"
@@ -446,14 +433,14 @@ func TestDeleteHandler(t *testing.T) {
// Unauthenticated request returns PermissionError.
var response *httptest.ResponseRecorder
- response = IssueRequest(rest, unauth_req)
+ response = IssueRequest(unauth_req)
ExpectStatusCode(t,
"unauthenticated request",
PermissionError.HTTPCode,
response)
// Authenticated non-admin request returns PermissionError.
- response = IssueRequest(rest, user_req)
+ response = IssueRequest(user_req)
ExpectStatusCode(t,
"authenticated non-admin request",
PermissionError.HTTPCode,
@@ -466,7 +453,7 @@ func TestDeleteHandler(t *testing.T) {
}
var response_dc, expected_dc deletecounter
- response = IssueRequest(rest, superuser_nonexistent_block_req)
+ response = IssueRequest(superuser_nonexistent_block_req)
ExpectStatusCode(t,
"data manager request, nonexistent block",
http.StatusNotFound,
@@ -474,7 +461,7 @@ func TestDeleteHandler(t *testing.T) {
// Authenticated admin request for existing block while never_delete is set.
never_delete = true
- response = IssueRequest(rest, superuser_existing_block_req)
+ response = IssueRequest(superuser_existing_block_req)
ExpectStatusCode(t,
"authenticated request, existing block, method disabled",
MethodDisabledError.HTTPCode,
@@ -482,7 +469,7 @@ func TestDeleteHandler(t *testing.T) {
never_delete = false
// Authenticated admin request for existing block.
- response = IssueRequest(rest, superuser_existing_block_req)
+ response = IssueRequest(superuser_existing_block_req)
ExpectStatusCode(t,
"data manager request, existing block",
http.StatusOK,
@@ -506,7 +493,7 @@ func TestDeleteHandler(t *testing.T) {
vols[0].Put(TEST_HASH, TEST_BLOCK)
permission_ttl = time.Duration(1) * time.Hour
- response = IssueRequest(rest, superuser_existing_block_req)
+ response = IssueRequest(superuser_existing_block_req)
ExpectStatusCode(t,
"data manager request, existing block",
http.StatusOK,
@@ -555,9 +542,6 @@ func TestDeleteHandler(t *testing.T) {
func TestPullHandler(t *testing.T) {
defer teardown()
- // Set up a REST router for testing the handlers.
- rest := MakeRESTRouter()
-
var user_token = "USER TOKEN"
data_manager_token = "DATA MANAGER TOKEN"
@@ -615,7 +599,7 @@ func TestPullHandler(t *testing.T) {
}
for _, tst := range testcases {
- response := IssueRequest(rest, &tst.req)
+ response := IssueRequest(&tst.req)
ExpectStatusCode(t, tst.name, tst.response_code, response)
ExpectBody(t, tst.name, tst.response_body, response)
}
@@ -662,9 +646,6 @@ func TestPullHandler(t *testing.T) {
func TestTrashHandler(t *testing.T) {
defer teardown()
- // Set up a REST router for testing the handlers.
- rest := MakeRESTRouter()
-
var user_token = "USER TOKEN"
data_manager_token = "DATA MANAGER TOKEN"
@@ -720,7 +701,7 @@ func TestTrashHandler(t *testing.T) {
}
for _, tst := range testcases {
- response := IssueRequest(rest, &tst.req)
+ response := IssueRequest(&tst.req)
ExpectStatusCode(t, tst.name, tst.response_code, response)
ExpectBody(t, tst.name, tst.response_body, response)
}
@@ -742,15 +723,15 @@ func TestTrashHandler(t *testing.T) {
// ====================
// IssueTestRequest executes an HTTP request described by rt, to a
-// specified REST router. It returns the HTTP response to the request.
-func IssueRequest(router *mux.Router, rt *RequestTester) *httptest.ResponseRecorder {
+// REST router. It returns the HTTP response to the request.
+func IssueRequest(rt *RequestTester) *httptest.ResponseRecorder {
response := httptest.NewRecorder()
body := bytes.NewReader(rt.request_body)
req, _ := http.NewRequest(rt.method, rt.uri, body)
if rt.api_token != "" {
req.Header.Set("Authorization", "OAuth2 "+rt.api_token)
}
- routerWrapper := MakeRESTRouterWrapper(router)
+ routerWrapper := MakeRESTRouterWrapper()
routerWrapper.ServeHTTP(response, req)
return response
}
diff --git a/services/keepstore/keepstore.go b/services/keepstore/keepstore.go
index 9c608d5..5ec1ad0 100644
--- a/services/keepstore/keepstore.go
+++ b/services/keepstore/keepstore.go
@@ -263,7 +263,7 @@ func main() {
KeepVM = MakeRRVolumeManager(goodvols)
// Tell the built-in HTTP server to direct all requests to the REST router.
- routerWrapper := MakeRESTRouterWrapper(MakeRESTRouter())
+ routerWrapper := MakeRESTRouterWrapper()
http.HandleFunc("/", func(resp http.ResponseWriter, req *http.Request) {
routerWrapper.ServeHTTP(resp, req)
})
diff --git a/services/keepstore/router_wrapper.go b/services/keepstore/router_wrapper.go
index 3e06f56..23e7eb2 100644
--- a/services/keepstore/router_wrapper.go
+++ b/services/keepstore/router_wrapper.go
@@ -29,13 +29,14 @@ type RESTRouterWrapper struct {
router *mux.Router
}
-func MakeRESTRouterWrapper(r *mux.Router) (RESTRouterWrapper) {
- return (RESTRouterWrapper{r})
+func MakeRESTRouterWrapper() (RESTRouterWrapper) {
+ router := MakeRESTRouter()
+ return (RESTRouterWrapper{router})
}
-func (this RESTRouterWrapper) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
+func (wrapper RESTRouterWrapper) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
loggingWriter := LoggingResponseWriter{200, nil, resp}
- this.router.ServeHTTP(&loggingWriter, req)
+ wrapper.router.ServeHTTP(&loggingWriter, req)
if loggingWriter.data != nil && loggingWriter.status == 200 {
data_len := len(loggingWriter.data)
if data_len > 200 { // this could be a block, so just print the size
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list