diff --git a/router/functionHandler.go b/router/functionHandler.go index 6464be63..af9f25bd 100644 --- a/router/functionHandler.go +++ b/router/functionHandler.go @@ -29,7 +29,7 @@ import ( type functionHandler struct { fmap *functionServiceMap poolManagerUrl string - fission.Function + Function fission.Metadata } func (*functionHandler) getServiceForFunction() (*url.URL, error) { diff --git a/router/functionHandler_test.go b/router/functionHandler_test.go index 274b199a..2d7537a8 100644 --- a/router/functionHandler_test.go +++ b/router/functionHandler_test.go @@ -49,7 +49,7 @@ func TestFunctionProxying(t *testing.T) { backendURL := createBackendService(testResponseString) log.Printf("Created backend svc at %v", backendURL) - fn := &fission.Function{Name: "foo", Uid: "xxx"} + fn := &fission.Metadata{Name: "foo", Uid: "xxx"} fmap := makeFunctionServiceMap() fmap.assign(fn, backendURL) diff --git a/router/functionServiceMap.go b/router/functionServiceMap.go index 23394315..671c19bc 100644 --- a/router/functionServiceMap.go +++ b/router/functionServiceMap.go @@ -38,7 +38,7 @@ type functionServiceMapResponse struct { error } type functionServiceMapRequest struct { - fission.Function + Function fission.Metadata serviceUrl url.URL requestType responseChannel chan<- functionServiceMapResponse @@ -50,7 +50,7 @@ type functionServiceMapEntry struct { type functionServiceMap struct { // map (funcname, uid) -> url - svc map[fission.Function]functionServiceMapEntry + svc map[fission.Metadata]functionServiceMapEntry currentGeneration uint64 requestChannel chan *functionServiceMapRequest } @@ -58,7 +58,7 @@ type functionServiceMap struct { func makeFunctionServiceMap() *functionServiceMap { fmap := &functionServiceMap{} fmap.requestChannel = make(chan *functionServiceMapRequest) - fmap.svc = make(map[fission.Function]functionServiceMapEntry) + fmap.svc = make(map[fission.Metadata]functionServiceMapEntry) go fmap.functionServiceMapWork() return fmap } @@ -89,7 +89,7 @@ func (fmap *functionServiceMap) functionServiceMapWork() { } } -func (fmap *functionServiceMap) lookup(f *fission.Function) (*url.URL, error) { +func (fmap *functionServiceMap) lookup(f *fission.Metadata) (*url.URL, error) { respChannel := make(chan functionServiceMapResponse) fmap.requestChannel <- &functionServiceMapRequest{Function: *f, requestType: LOOKUP, responseChannel: respChannel} resp := <-respChannel @@ -100,7 +100,7 @@ func (fmap *functionServiceMap) lookup(f *fission.Function) (*url.URL, error) { } } -func (fmap *functionServiceMap) assign(f *fission.Function, serviceUrl *url.URL) { +func (fmap *functionServiceMap) assign(f *fission.Metadata, serviceUrl *url.URL) { fmap.requestChannel <- &functionServiceMapRequest{Function: *f, serviceUrl: *serviceUrl, requestType: ASSIGN} } diff --git a/router/functionServiceMap_test.go b/router/functionServiceMap_test.go index 94c8f9df..9a57cc56 100644 --- a/router/functionServiceMap_test.go +++ b/router/functionServiceMap_test.go @@ -25,7 +25,7 @@ import ( func TestFunctionServiceMap(t *testing.T) { m := makeFunctionServiceMap() - fn := &fission.Function{Name: "foo", Uid: "012"} + fn := &fission.Metadata{Name: "foo", Uid: "012"} u, err := url.Parse("/foo012") if err != nil { t.Errorf("can't parse url") diff --git a/router/router_test.go b/router/router_test.go index 59aca9f0..119d035a 100644 --- a/router/router_test.go +++ b/router/router_test.go @@ -26,7 +26,7 @@ import ( func TestRouter(t *testing.T) { fmap := makeFunctionServiceMap() - fn := &fission.Function{Name: "foo", Uid: "xxx"} + fn := &fission.Metadata{Name: "foo", Uid: "xxx"} testResponseString := "hi" testServiceUrl := createBackendService(testResponseString) @@ -35,7 +35,7 @@ func TestRouter(t *testing.T) { triggers := makeHTTPTriggerSet(fmap, "", "") triggerUrl := "/foo" - triggers.triggers = append(triggers.triggers, fission.HTTPTrigger{triggerUrl, *fn}) + triggers.triggers = append(triggers.triggers, fission.HTTPTrigger{UrlPattern: triggerUrl, Function: *fn}) port := 4242 go server(port, triggers) diff --git a/types.go b/types.go index ad4e252e..01b08d2d 100644 --- a/types.go +++ b/types.go @@ -17,13 +17,41 @@ limitations under the License. package fission type ( - Function struct { + // Metadata is used as the general identifier for all kinds of + // resources managed by the controller. In general, when a + // resource is updated, the Name remains the same, but the UID + // changes. In other words, the UID identifies a particular + // value of a resource. + Metadata struct { Name string Uid string } + // Function is a unit of executable code. Though it's called + // a function, the code may have more than one function; it's + // usually some sort of module or package. + Function struct { + Metadata + Environment Metadata + Code string + } + + // Environment identifies the language and OS specific + // resources that a function depends on. For now this + // includes only the function run container image. Later, + // this will also include build containers, as well as support + // tools like debuggers, profilers, etc. + Environment struct { + Metadata + RunContainerImageUrl string + } + + // HTTPTrigger maps URL patterns to functions. Function.UID + // is optional; if absent, the latest version of the function + // will automatically be selected. HTTPTrigger struct { + Metadata UrlPattern string - Function + Function Metadata } )