Merge pull request #1103 from weaveworks/994-pipes-check-endpoint

Add pipe/{pipeID}/check endpoint
This commit is contained in:
Alfonso Acosta
2016-03-03 13:10:22 +00:00
2 changed files with 24 additions and 8 deletions

View File

@@ -12,6 +12,10 @@ import (
// RegisterPipeRoutes registers the pipe routes
func RegisterPipeRoutes(router *mux.Router, pr PipeRouter) {
router.Methods("GET").
Path("/api/pipe/{pipeID}/check").
HandlerFunc(requestContextDecorator(checkPipe(pr, UIEnd)))
router.Methods("GET").
Path("/api/pipe/{pipeID}").
HandlerFunc(requestContextDecorator(handlePipeWs(pr, UIEnd)))
@@ -25,6 +29,18 @@ func RegisterPipeRoutes(router *mux.Router, pr PipeRouter) {
HandlerFunc(requestContextDecorator(deletePipe(pr)))
}
func checkPipe(pr PipeRouter, end End) CtxHandlerFunc {
return func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
id := mux.Vars(r)["pipeID"]
_, _, ok := pr.Get(ctx, id, end)
if !ok {
w.WriteHeader(http.StatusNoContent)
return
}
pr.Release(ctx, id, end)
}
}
func handlePipeWs(pr PipeRouter, end End) CtxHandlerFunc {
return func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
id := mux.Vars(r)["pipeID"]

View File

@@ -214,21 +214,21 @@ export function deletePipe(pipeId) {
}
export function getPipeStatus(pipeId) {
const url = `/api/pipe/${encodeURIComponent(pipeId)}`;
const url = `/api/pipe/${encodeURIComponent(pipeId)}/check`;
reqwest({
method: 'GET',
url: url,
success: function(res) {
log('ERROR: expected responses: [400, 404]. Got:', res);
},
error: function(err) {
log('ERROR: unexpected response:', err);
},
success: function(res) {
const status = {
400: 'PIPE_ALIVE',
404: 'PIPE_DELETED'
}[err.status];
200: 'PIPE_ALIVE',
204: 'PIPE_DELETED'
}[res.status];
if (!status) {
log('Unexpected pipe status:', err.status);
log('Unexpected pipe status:', res.status);
return;
}