Router uses poolmgr to specialize pods when necessary. Router uses controller to get the list of triggers to listen for. For now this integration is pretty crappy -- we just poll the controller every few seconds and cache the result. The right way would be to have some sort of watch API on the controller and use that. Or maybe share access to etcd directly.
55 lines
1.4 KiB
Go
55 lines
1.4 KiB
Go
/*
|
|
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 router
|
|
|
|
import (
|
|
"github.com/gorilla/mux"
|
|
"log"
|
|
"net/http"
|
|
"sync/atomic"
|
|
)
|
|
|
|
//
|
|
// mutableRouter wraps the mux router, and allows the router to be
|
|
// atomically changed.
|
|
//
|
|
|
|
type mutableRouter struct {
|
|
router atomic.Value // mux.Router
|
|
}
|
|
|
|
func NewMutableRouter(handler *mux.Router) *mutableRouter {
|
|
mr := mutableRouter{}
|
|
mr.router.Store(handler)
|
|
return &mr
|
|
}
|
|
|
|
func (mr *mutableRouter) ServeHTTP(responseWriter http.ResponseWriter, request *http.Request) {
|
|
// Atomically grab the underlying mux router and call it.
|
|
routerValue := mr.router.Load()
|
|
router, ok := routerValue.(*mux.Router)
|
|
if !ok {
|
|
log.Panic("Invalid router type")
|
|
}
|
|
router.ServeHTTP(responseWriter, request)
|
|
}
|
|
|
|
func (mr *mutableRouter) updateRouter(newHandler *mux.Router) {
|
|
log.Println("Updating router")
|
|
mr.router.Store(newHandler)
|
|
}
|