func setupRouteFetcher(c *config.Config, registry rregistry.RegistryInterface) { if c.RoutingApiEnabled() { tokenFetcher := token_fetcher.NewTokenFetcher(&c.OAuth) routingApiUri := fmt.Sprintf("%s:%d", c.RoutingApi.Uri, c.RoutingApi.Port) routingApiClient := routing_api.NewClient(routingApiUri) routeFetcher := route_fetcher.NewRouteFetcher(steno.NewLogger("router.route_fetcher"), tokenFetcher, registry, c, routingApiClient, 1) routeFetcher.StartFetchCycle() routeFetcher.StartEventCycle() } }
func NewEtcdEndpoint(c *config.Config) (*EtcdEndpoint, error) { cfg := etcd.Config{ Endpoints: c.EtcdServers(), Transport: etcd.DefaultTransport, HeaderTimeoutPerRequest: time.Second, } logger := steno.NewLogger("router.endpoint") logger.Infof("endpoint etcd config: %v", cfg) client, err := etcd.New(cfg) if err != nil { logger.Infof("create etcd client error: %s", err.Error()) return &EtcdEndpoint{}, err } keysAPI := etcd.NewKeysAPI(client) etcdEndpoint := &EtcdEndpoint{ KeysAPI: keysAPI, Path: fmt.Sprintf("%s/%s/%s", c.EtcdPrefix, c.Namespace, c.Service), Codec: latest.Codec, Namespace: c.Namespace, Service: c.Service, Logger: logger, } info, err := etcdEndpoint.getEtcdEndpoint() if err != nil { logger.Infof("get endpoint client error: %s", err.Error()) return etcdEndpoint, err } err = etcdEndpoint.updateEndpoint(info) if err != nil { logger.Infof("update endpoint client error: %s", err.Error()) return etcdEndpoint, err } go etcdEndpoint.watchEtcdEndPoint(info) return etcdEndpoint, nil }
"vulcan/router/registry" "vulcan/router/test_util" "testing" "time" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "vulcan/router/metrics/fakes" ) var ( r *registry.RouteRegistry p proxy.Proxy conf *config.Config proxyServer net.Listener accessLog access_log.AccessLogger accessLogFile *test_util.FakeFile crypto secure.Crypto cryptoPrev secure.Crypto ) func TestProxy(t *testing.T) { RegisterFailHandler(Fail) RunSpecs(t, "Proxy Suite") } var _ = BeforeEach(func() { var err error crypto, err = secure.NewAesGCM([]byte("ABCDEFGHIJKLMNOP")) Expect(err).NotTo(HaveOccurred())
"github.com/cloudfoundry/yagnats/fakeyagnats" "vulcan/router/config" "vulcan/router/metrics/fakes" "vulcan/router/route" "encoding/json" "time" ) var _ = Describe("RouteRegistry", func() { var r *RouteRegistry var messageBus *fakeyagnats.FakeNATSConn var reporter *fakes.FakeRouteReporter var fooEndpoint, barEndpoint, bar2Endpoint *route.Endpoint var configObj *config.Config BeforeEach(func() { configObj = config.DefaultConfig() configObj.PruneStaleDropletsInterval = 50 * time.Millisecond configObj.DropletStaleThreshold = 10 * time.Millisecond messageBus = fakeyagnats.Connect() reporter = new(fakes.FakeRouteReporter) r = NewRouteRegistry(configObj, messageBus, reporter) fooEndpoint = route.NewEndpoint("12345", "192.168.1.1", 1234, "id1", map[string]string{ "runtime": "ruby18", "framework": "sinatra", }, -1, "")
"vulcan/router/access_log" vcap "vulcan/router/common" cfg "vulcan/router/config" "vulcan/router/metrics/fakes" "vulcan/router/proxy" rregistry "vulcan/router/registry" "vulcan/router/route" . "vulcan/router/router" "vulcan/router/test" "vulcan/router/test_util" vvarz "vulcan/router/varz" ) var _ = Describe("Router", func() { var natsRunner *natsrunner.NATSRunner var config *cfg.Config var mbusClient yagnats.NATSConn var registry *rregistry.RouteRegistry var varz vvarz.Varz var router *Router var natsPort uint16 BeforeEach(func() { natsPort = test_util.NextAvailPort() natsRunner = natsrunner.NewNATSRunner(int(natsPort)) natsRunner.Start() proxyPort := test_util.NextAvailPort() statusPort := test_util.NextAvailPort()
"encoding/json" "fmt" "io/ioutil" "net" "net/http" "net/http/httputil" "strings" "time" "vulcan/router/metrics/fakes" ) var _ = Describe("Router", func() { var natsRunner *natsrunner.NATSRunner var natsPort uint16 var config *cfg.Config var mbusClient yagnats.NATSConn var registry *rregistry.RouteRegistry var varz vvarz.Varz var router *Router BeforeEach(func() { natsPort = test_util.NextAvailPort() natsRunner = natsrunner.NewNATSRunner(int(natsPort)) natsRunner.Start() fakeEmitter := fake.NewFakeEventEmitter("fake") dropsonde.InitializeWithEmitter(fakeEmitter) proxyPort := test_util.NextAvailPort()
"vulcan/router/route" . "vulcan/router/route_fetcher" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) var _ = Describe("RouteFetcher", func() { var ( cfg *config.Config tokenFetcher *testTokenFetcher.FakeTokenFetcher registry *testRegistry.FakeRegistryInterface fetcher *RouteFetcher logger *gosteno.Logger sink *gosteno.TestingSink client *fake_routing_api.FakeClient retryInterval int token *token_fetcher.Token response []db.Route ) BeforeEach(func() { cfg = config.DefaultConfig() retryInterval := 0 tokenFetcher = &testTokenFetcher.FakeTokenFetcher{} registry = &testRegistry.FakeRegistryInterface{} sink = gosteno.NewTestingSink()