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:
@@ -29,7 +29,7 @@ import (
|
|||||||
type functionHandler struct {
|
type functionHandler struct {
|
||||||
fmap *functionServiceMap
|
fmap *functionServiceMap
|
||||||
poolManagerUrl string
|
poolManagerUrl string
|
||||||
fission.Function
|
Function fission.Metadata
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*functionHandler) getServiceForFunction() (*url.URL, error) {
|
func (*functionHandler) getServiceForFunction() (*url.URL, error) {
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ func TestFunctionProxying(t *testing.T) {
|
|||||||
backendURL := createBackendService(testResponseString)
|
backendURL := createBackendService(testResponseString)
|
||||||
log.Printf("Created backend svc at %v", backendURL)
|
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 := makeFunctionServiceMap()
|
||||||
fmap.assign(fn, backendURL)
|
fmap.assign(fn, backendURL)
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ type functionServiceMapResponse struct {
|
|||||||
error
|
error
|
||||||
}
|
}
|
||||||
type functionServiceMapRequest struct {
|
type functionServiceMapRequest struct {
|
||||||
fission.Function
|
Function fission.Metadata
|
||||||
serviceUrl url.URL
|
serviceUrl url.URL
|
||||||
requestType
|
requestType
|
||||||
responseChannel chan<- functionServiceMapResponse
|
responseChannel chan<- functionServiceMapResponse
|
||||||
@@ -50,7 +50,7 @@ type functionServiceMapEntry struct {
|
|||||||
|
|
||||||
type functionServiceMap struct {
|
type functionServiceMap struct {
|
||||||
// map (funcname, uid) -> url
|
// map (funcname, uid) -> url
|
||||||
svc map[fission.Function]functionServiceMapEntry
|
svc map[fission.Metadata]functionServiceMapEntry
|
||||||
currentGeneration uint64
|
currentGeneration uint64
|
||||||
requestChannel chan *functionServiceMapRequest
|
requestChannel chan *functionServiceMapRequest
|
||||||
}
|
}
|
||||||
@@ -58,7 +58,7 @@ type functionServiceMap struct {
|
|||||||
func makeFunctionServiceMap() *functionServiceMap {
|
func makeFunctionServiceMap() *functionServiceMap {
|
||||||
fmap := &functionServiceMap{}
|
fmap := &functionServiceMap{}
|
||||||
fmap.requestChannel = make(chan *functionServiceMapRequest)
|
fmap.requestChannel = make(chan *functionServiceMapRequest)
|
||||||
fmap.svc = make(map[fission.Function]functionServiceMapEntry)
|
fmap.svc = make(map[fission.Metadata]functionServiceMapEntry)
|
||||||
go fmap.functionServiceMapWork()
|
go fmap.functionServiceMapWork()
|
||||||
return fmap
|
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)
|
respChannel := make(chan functionServiceMapResponse)
|
||||||
fmap.requestChannel <- &functionServiceMapRequest{Function: *f, requestType: LOOKUP, responseChannel: respChannel}
|
fmap.requestChannel <- &functionServiceMapRequest{Function: *f, requestType: LOOKUP, responseChannel: respChannel}
|
||||||
resp := <-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}
|
fmap.requestChannel <- &functionServiceMapRequest{Function: *f, serviceUrl: *serviceUrl, requestType: ASSIGN}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import (
|
|||||||
|
|
||||||
func TestFunctionServiceMap(t *testing.T) {
|
func TestFunctionServiceMap(t *testing.T) {
|
||||||
m := makeFunctionServiceMap()
|
m := makeFunctionServiceMap()
|
||||||
fn := &fission.Function{Name: "foo", Uid: "012"}
|
fn := &fission.Metadata{Name: "foo", Uid: "012"}
|
||||||
u, err := url.Parse("/foo012")
|
u, err := url.Parse("/foo012")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("can't parse url")
|
t.Errorf("can't parse url")
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import (
|
|||||||
|
|
||||||
func TestRouter(t *testing.T) {
|
func TestRouter(t *testing.T) {
|
||||||
fmap := makeFunctionServiceMap()
|
fmap := makeFunctionServiceMap()
|
||||||
fn := &fission.Function{Name: "foo", Uid: "xxx"}
|
fn := &fission.Metadata{Name: "foo", Uid: "xxx"}
|
||||||
|
|
||||||
testResponseString := "hi"
|
testResponseString := "hi"
|
||||||
testServiceUrl := createBackendService(testResponseString)
|
testServiceUrl := createBackendService(testResponseString)
|
||||||
@@ -35,7 +35,7 @@ func TestRouter(t *testing.T) {
|
|||||||
|
|
||||||
triggers := makeHTTPTriggerSet(fmap, "", "")
|
triggers := makeHTTPTriggerSet(fmap, "", "")
|
||||||
triggerUrl := "/foo"
|
triggerUrl := "/foo"
|
||||||
triggers.triggers = append(triggers.triggers, fission.HTTPTrigger{triggerUrl, *fn})
|
triggers.triggers = append(triggers.triggers, fission.HTTPTrigger{UrlPattern: triggerUrl, Function: *fn})
|
||||||
|
|
||||||
port := 4242
|
port := 4242
|
||||||
go server(port, triggers)
|
go server(port, triggers)
|
||||||
|
|||||||
@@ -17,13 +17,41 @@ limitations under the License.
|
|||||||
package fission
|
package fission
|
||||||
|
|
||||||
type (
|
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
|
Name string
|
||||||
Uid 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 {
|
HTTPTrigger struct {
|
||||||
|
Metadata
|
||||||
UrlPattern string
|
UrlPattern string
|
||||||
Function
|
Function Metadata
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user