Define main resource types

Functions, HTTPTriggers, Metadata, Environment.  Update the router to
use fission.Metadata, not fission.Function, to identify functions.
This commit is contained in:
Soam Vasani
2016-09-10 00:59:39 -07:00
parent 405dd6fa0f
commit 732634b53c
6 changed files with 40 additions and 12 deletions
+1 -1
View File
@@ -29,7 +29,7 @@ import (
type functionHandler struct {
fmap *functionServiceMap
poolManagerUrl string
fission.Function
Function fission.Metadata
}
func (*functionHandler) getServiceForFunction() (*url.URL, error) {
+1 -1
View File
@@ -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)
+5 -5
View File
@@ -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}
}
+1 -1
View File
@@ -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")
+2 -2
View File
@@ -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)
+30 -2
View File
@@ -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
}
)