Skip to content

Commit

Permalink
Consolidate interactive request flagging to web router and allow inte…
Browse files Browse the repository at this point in the history
…ractive query string
  • Loading branch information
DocSavage committed Oct 8, 2014
1 parent 2e630a5 commit ef5af7d
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 44 deletions.
6 changes: 0 additions & 6 deletions datatype/keyvalue/keyvalue.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,12 +416,6 @@ func (d *Data) ServeHTTP(requestCtx context.Context, w http.ResponseWriter, r *h
}
storeCtx := datastore.NewVersionedContext(d, versionID)

// All HTTP requests are interactive so let server tally request.
// TODO: This command should be moved to web server handling when better
// framework for datatype-specific API is implemented, allowing type-specific
// logging of API calls, etc.
server.GotInteractiveRequest()

// Allow cross-origin resource sharing.
w.Header().Add("Access-Control-Allow-Origin", "*")

Expand Down
6 changes: 0 additions & 6 deletions datatype/labelgraph/labelgraph.go
Original file line number Diff line number Diff line change
Expand Up @@ -1319,12 +1319,6 @@ func (d *Data) ServeHTTP(requestCtx context.Context, w http.ResponseWriter, r *h
return
}

// All HTTP requests are interactive so let server tally request.
// TODO: This command should be moved to web server handling when better
// framework for datatype-specific API is implemented, allowing type-specific
// logging of API calls, etc.
server.GotInteractiveRequest()

// make sure transaction log is created
d.initializeLog()

Expand Down
6 changes: 0 additions & 6 deletions datatype/labelmap/labelmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,12 +494,6 @@ func (d *Data) ServeHTTP(requestCtx context.Context, w http.ResponseWriter, r *h
}
storeCtx := datastore.NewVersionedContext(d, versionID)

// All HTTP requests are interactive so let server tally request.
// TODO: This command should be moved to web server handling when better
// framework for datatype-specific API is implemented, allowing type-specific
// logging of API calls, etc.
server.GotInteractiveRequest()

// Allow cross-origin resource sharing.
w.Header().Add("Access-Control-Allow-Origin", "*")

Expand Down
6 changes: 0 additions & 6 deletions datatype/labels64/labels64.go
Original file line number Diff line number Diff line change
Expand Up @@ -752,12 +752,6 @@ func (d *Data) ServeHTTP(ctx context.Context, w http.ResponseWriter, r *http.Req
}
storeCtx := datastore.NewVersionedContext(d, versionID)

// All HTTP requests are interactive so let server tally request.
// TODO: This command should be moved to web server handling when better
// framework for datatype-specific API is implemented, allowing type-specific
// logging of API calls, etc.
server.GotInteractiveRequest()

// Allow cross-origin resource sharing.
w.Header().Add("Access-Control-Allow-Origin", "*")

Expand Down
6 changes: 0 additions & 6 deletions datatype/multichan16/multichan16.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,12 +321,6 @@ func (d *Data) ServeHTTP(requestCtx context.Context, w http.ResponseWriter, r *h
}
storeCtx := datastore.NewVersionedContext(d, versionID)

// All HTTP requests are interactive so let server tally request.
// TODO: This command should be moved to web server handling when better
// framework for datatype-specific API is implemented, allowing type-specific
// logging of API calls, etc.
server.GotInteractiveRequest()

// Allow cross-origin resource sharing.
w.Header().Add("Access-Control-Allow-Origin", "*")

Expand Down
16 changes: 8 additions & 8 deletions datatype/multiscale2d/multiscale2d.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ $ dvid -stdin node <UUID> <data name> generate <settings...> < config.json
the generated tiles are aligned in a grid having (0,0,0) as a top left corner of a tile, not
tiles that start from the corner of present data since the data can expand.
If not tile spec file is used, a default tile spec is generated that will cover the
extents of the source data.
Example:
$ dvid repo 3f8c mymultiscale2d generate /path/to/config.json
Expand Down Expand Up @@ -465,7 +468,7 @@ type Data struct {
Properties
}

// Returns the default tile spec for
// Returns the default tile spec that will fully cover the source extents.
func (d *Data) DefaultTileSpec() TileSpec {
return nil
}
Expand Down Expand Up @@ -549,9 +552,13 @@ func (d *Data) DoRPC(request datastore.Request, reply *datastore.Response) error
if err != nil {
return err
}
dvid.Infof("Using tile spec file: %s\n", filename)
} else {
dvid.Infof("Using default tile generation method since no tile spec file was given...\n")
tileSpec = d.DefaultTileSpec()
if tileSpec == nil {
return fmt.Errorf("No default tile spec is available")
}
}
}
return d.ConstructTiles(uuidStr, tileSpec, request)
Expand Down Expand Up @@ -579,13 +586,6 @@ func (d *Data) ServeHTTP(requestCtx context.Context, w http.ResponseWriter, r *h
// Allow cross-origin resource sharing.
w.Header().Add("Access-Control-Allow-Origin", "*")

// Get the action (GET, POST)
// All HTTP requests are interactive so let server tally request.
// TODO: This command should be moved to web server handling when better
// framework for datatype-specific API is implemented, allowing type-specific
// logging of API calls, etc.
server.GotInteractiveRequest()

action := strings.ToLower(r.Method)
switch action {
case "get", "post":
Expand Down
6 changes: 0 additions & 6 deletions datatype/roi/roi.go
Original file line number Diff line number Diff line change
Expand Up @@ -997,12 +997,6 @@ func (d *Data) ServeHTTP(requestCtx context.Context, w http.ResponseWriter, r *h
}
storeCtx := datastore.NewVersionedContext(d, versionID)

// All HTTP requests are interactive so let server tally request.
// TODO: This command should be moved to web server handling when better
// framework for datatype-specific API is implemented, allowing type-specific
// logging of API calls, etc.
server.GotInteractiveRequest()

// Allow cross-origin resource sharing.
w.Header().Add("Access-Control-Allow-Origin", "*")

Expand Down
16 changes: 16 additions & 0 deletions server/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ const WebHelp = `
%s
<p>Background batch processes like generation of tiles, sparse volumes, and various
indices, will be paused if a single server receives more than a few data type API
requests over a 5 minute moving window. You can mark your API request as
non-interactive (i.e., you don't mind if it's delayed) by appending a query string
<code>interactive=0</code>.
<h3>Licensing</h3>
<p><a href="https://github.com/janelia-flyem/dvid">DVID</a> is released under the
<a href="http://janelia-flyem.github.com/janelia_farm_license.html">Janelia Farm license</a>, a
Expand Down Expand Up @@ -338,6 +344,16 @@ func instanceSelector(c *web.C, h http.Handler) http.Handler {
BadRequest(w, r, err.Error())
return
}

// Handle DVID-wide query string commands like non-interactive call designations
queryValues := r.URL.Query()

// All HTTP requests are interactive so let server tally request.
interactive := queryValues.Get("interactive")
if interactive == "" || (interactive != "false" && interactive != "0") {
GotInteractiveRequest()
}

// Construct the Context
ctx := datastore.NewServerContext(context.Background(), repo, versionID)
dataservice.ServeHTTP(ctx, w, r)
Expand Down

0 comments on commit ef5af7d

Please sign in to comment.