Move Function and HTTPTrigger types to top level 'fission' package
This commit is contained in:
@@ -22,12 +22,14 @@ import (
|
||||
"net/http"
|
||||
"net/http/httputil"
|
||||
"net/url"
|
||||
|
||||
"github.com/platform9/fission"
|
||||
)
|
||||
|
||||
type functionHandler struct {
|
||||
fmap *functionServiceMap
|
||||
poolManagerUrl string
|
||||
Function
|
||||
fission.Function
|
||||
}
|
||||
|
||||
func (*functionHandler) getServiceForFunction() (*url.URL, error) {
|
||||
|
||||
@@ -19,10 +19,11 @@ package router
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
"testing"
|
||||
// "net/http/httputil"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"testing"
|
||||
|
||||
"github.com/platform9/fission"
|
||||
)
|
||||
|
||||
func createBackendService(testResponseString string) *url.URL {
|
||||
@@ -48,7 +49,7 @@ func TestFunctionProxying(t *testing.T) {
|
||||
backendURL := createBackendService(testResponseString)
|
||||
log.Printf("Created backend svc at %v", backendURL)
|
||||
|
||||
fn := &Function{Name: "foo", Uid: "xxx"}
|
||||
fn := &fission.Function{Name: "foo", Uid: "xxx"}
|
||||
fmap := makeFunctionServiceMap()
|
||||
fmap.assign(fn, backendURL)
|
||||
|
||||
|
||||
@@ -20,6 +20,8 @@ import (
|
||||
"errors"
|
||||
"log"
|
||||
"net/url"
|
||||
|
||||
"github.com/platform9/fission"
|
||||
)
|
||||
|
||||
type requestType int
|
||||
@@ -36,7 +38,7 @@ type functionServiceMapResponse struct {
|
||||
error
|
||||
}
|
||||
type functionServiceMapRequest struct {
|
||||
Function
|
||||
fission.Function
|
||||
serviceUrl url.URL
|
||||
requestType
|
||||
responseChannel chan<- functionServiceMapResponse
|
||||
@@ -48,7 +50,7 @@ type functionServiceMapEntry struct {
|
||||
|
||||
type functionServiceMap struct {
|
||||
// map (funcname, uid) -> url
|
||||
svc map[Function]functionServiceMapEntry
|
||||
svc map[fission.Function]functionServiceMapEntry
|
||||
currentGeneration uint64
|
||||
requestChannel chan *functionServiceMapRequest
|
||||
}
|
||||
@@ -56,7 +58,7 @@ type functionServiceMap struct {
|
||||
func makeFunctionServiceMap() *functionServiceMap {
|
||||
fmap := &functionServiceMap{}
|
||||
fmap.requestChannel = make(chan *functionServiceMapRequest)
|
||||
fmap.svc = make(map[Function]functionServiceMapEntry)
|
||||
fmap.svc = make(map[fission.Function]functionServiceMapEntry)
|
||||
go fmap.functionServiceMapWork()
|
||||
return fmap
|
||||
}
|
||||
@@ -87,7 +89,7 @@ func (fmap *functionServiceMap) functionServiceMapWork() {
|
||||
}
|
||||
}
|
||||
|
||||
func (fmap *functionServiceMap) lookup(f *Function) (*url.URL, error) {
|
||||
func (fmap *functionServiceMap) lookup(f *fission.Function) (*url.URL, error) {
|
||||
respChannel := make(chan functionServiceMapResponse)
|
||||
fmap.requestChannel <- &functionServiceMapRequest{Function: *f, requestType: LOOKUP, responseChannel: respChannel}
|
||||
resp := <-respChannel
|
||||
@@ -98,7 +100,7 @@ func (fmap *functionServiceMap) lookup(f *Function) (*url.URL, error) {
|
||||
}
|
||||
}
|
||||
|
||||
func (fmap *functionServiceMap) assign(f *Function, serviceUrl *url.URL) {
|
||||
func (fmap *functionServiceMap) assign(f *fission.Function, serviceUrl *url.URL) {
|
||||
fmap.requestChannel <- &functionServiceMapRequest{Function: *f, serviceUrl: *serviceUrl, requestType: ASSIGN}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,11 +19,13 @@ package router
|
||||
import (
|
||||
"net/url"
|
||||
"testing"
|
||||
|
||||
"github.com/platform9/fission"
|
||||
)
|
||||
|
||||
func TestFunctionServiceMap(t *testing.T) {
|
||||
m := makeFunctionServiceMap()
|
||||
fn := &Function{Name: "foo", Uid: "012"}
|
||||
fn := &fission.Function{Name: "foo", Uid: "012"}
|
||||
u, err := url.Parse("/foo012")
|
||||
if err != nil {
|
||||
t.Errorf("can't parse url")
|
||||
|
||||
@@ -18,6 +18,7 @@ package router
|
||||
|
||||
import (
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/platform9/fission"
|
||||
)
|
||||
|
||||
type HTTPTriggerSet struct {
|
||||
@@ -25,11 +26,11 @@ type HTTPTriggerSet struct {
|
||||
*mutableRouter
|
||||
controllerUrl string
|
||||
poolManagerUrl string
|
||||
triggers []HTTPTrigger
|
||||
triggers []fission.HTTPTrigger
|
||||
}
|
||||
|
||||
func makeHTTPTriggerSet(fmap *functionServiceMap, controllerUrl string, poolManagerUrl string) *HTTPTriggerSet {
|
||||
triggers := make([]HTTPTrigger, 1)
|
||||
triggers := make([]fission.HTTPTrigger, 1)
|
||||
return &HTTPTriggerSet{
|
||||
functionServiceMap: fmap,
|
||||
triggers: triggers,
|
||||
|
||||
@@ -47,16 +47,6 @@ import (
|
||||
)
|
||||
|
||||
type (
|
||||
Function struct {
|
||||
Name string
|
||||
Uid string
|
||||
}
|
||||
|
||||
HTTPTrigger struct {
|
||||
UrlPattern string
|
||||
Function
|
||||
}
|
||||
|
||||
options struct {
|
||||
port int
|
||||
poolManagerUrl string
|
||||
|
||||
@@ -20,11 +20,13 @@ import (
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/platform9/fission"
|
||||
)
|
||||
|
||||
func TestRouter(t *testing.T) {
|
||||
fmap := makeFunctionServiceMap()
|
||||
fn := &Function{Name: "foo", Uid: "xxx"}
|
||||
fn := &fission.Function{Name: "foo", Uid: "xxx"}
|
||||
|
||||
testResponseString := "hi"
|
||||
testServiceUrl := createBackendService(testResponseString)
|
||||
@@ -33,7 +35,7 @@ func TestRouter(t *testing.T) {
|
||||
|
||||
triggers := makeHTTPTriggerSet(fmap, "", "")
|
||||
triggerUrl := "/foo"
|
||||
triggers.triggers = append(triggers.triggers, HTTPTrigger{triggerUrl, *fn})
|
||||
triggers.triggers = append(triggers.triggers, fission.HTTPTrigger{triggerUrl, *fn})
|
||||
|
||||
port := 4242
|
||||
go server(port, triggers)
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
Copyright 2016 The Fission Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package fission
|
||||
|
||||
type (
|
||||
Function struct {
|
||||
Name string
|
||||
Uid string
|
||||
}
|
||||
|
||||
HTTPTrigger struct {
|
||||
UrlPattern string
|
||||
Function
|
||||
}
|
||||
)
|
||||
Reference in New Issue
Block a user