diff --git a/router/functionHandler.go b/router/functionHandler.go index af9f25bd..37f2cb6c 100644 --- a/router/functionHandler.go +++ b/router/functionHandler.go @@ -42,10 +42,11 @@ func (fh *functionHandler) handler(responseWriter http.ResponseWriter, request * // Cache miss: request the Pool Manager to make a new service. serviceUrl, poolErr := fh.getServiceForFunction() if poolErr != nil { - // now we're really screwed log.Printf("Failed to get service for function (%v,%v): %v", fh.Function.Name, fh.Function.Uid, poolErr) - responseWriter.WriteHeader(500) // TODO: make this smarter based on the actual error + // We might want a specific error code or header for fission + // failures as opposed to user function bugs. + http.Error(responseWriter, poolErr.Error(), 500) return } diff --git a/router/router.go b/router/router.go index 7ea066ab..41037ef0 100644 --- a/router/router.go +++ b/router/router.go @@ -42,19 +42,9 @@ package router import ( "fmt" "github.com/gorilla/mux" - flag "github.com/ogier/pflag" "net/http" ) -type ( - options struct { - port int - poolManagerUrl string - controllerUrl string - //... - } -) - // request url ---[mux]---> Function(name,uid) ----[fmap]----> k8s service url // request url ---[trigger]---> Function(name, deployment) ----[deployment]----> Function(name, uid) ----[pool mgr]---> k8s service url @@ -66,27 +56,14 @@ func router(httpTriggerSet *HTTPTriggerSet) *mutableRouter { return mr } -func server(port int, httpTriggerSet *HTTPTriggerSet) { +func serve(port int, httpTriggerSet *HTTPTriggerSet) { mr := router(httpTriggerSet) url := fmt.Sprintf(":%v", port) http.ListenAndServe(url, mr) } -func getOptions() *options { - options := &options{} - - flag.IntVar(&options.port, "port", 80, "Port to listen on") - - // default to using dns service discovery - flag.StringVar(&options.poolManagerUrl, "poolmanager_url", "http://poolmanager/", "URL for the PoolManager service") - flag.StringVar(&options.controllerUrl, "controller_url", "http://controller/", "URL for the controller service") - - return options -} - -func main() { - options := getOptions() +func Start(port int, controllerUrl string, poolmgrUrl string) { fmap := makeFunctionServiceMap() - triggers := makeHTTPTriggerSet(fmap, options.controllerUrl, options.poolManagerUrl) - server(options.port, triggers) + triggers := makeHTTPTriggerSet(fmap, controllerUrl, poolmgrUrl) + serve(port, triggers) } diff --git a/router/router_test.go b/router/router_test.go index 119d035a..db6c8c59 100644 --- a/router/router_test.go +++ b/router/router_test.go @@ -38,7 +38,7 @@ func TestRouter(t *testing.T) { triggers.triggers = append(triggers.triggers, fission.HTTPTrigger{UrlPattern: triggerUrl, Function: *fn}) port := 4242 - go server(port, triggers) + go serve(port, triggers) time.Sleep(100 * time.Millisecond) testUrl := fmt.Sprintf("http://localhost:%v%v", port, triggerUrl)