Exemple #1
0
func newServer(args []string) (*http.Server, error) {

	c, err := NewCollector(args[0])
	if err != nil {
		fmt.Errorf("Error creating test collector: %s\n", err)
		return nil, err
	}
	log.Printf("Watching reports dir [%s]\n", c.ReportsDir)

	routes := rata.Routes{
		{Name: "get_index", Method: "GET", Path: "/"},
		{Name: "get_tests", Method: "GET", Path: "/tests"},
	}

	handlers := map[string]http.Handler{
		"get_index": http.FileServer(http.Dir(viewsDir)),
		"get_tests": newTestsHandler(c),
	}

	router, err := rata.NewRouter(routes, handlers)
	if err != nil {
		return nil, err
	}

	server := &http.Server{
		Addr:           ":8080",
		Handler:        router,
		ReadTimeout:    10 * time.Second,
		WriteTimeout:   10 * time.Second,
		MaxHeaderBytes: 1 << 20,
	}
	return server, nil
}
Exemple #2
0
func New(logger logger.Logger, store store.Store, clock clock.Clock) (http.Handler, error) {
	handlers := map[string]http.Handler{
		"bulk_app_state": NewBulkAppStateHandler(logger, store, clock),
	}

	return rata.NewRouter(apiserver.Routes, handlers)
}
Exemple #3
0
func constructApiServer(cfg config.Config, database db.DB, statsdClient statsd.Statter, stopChan chan struct{}, logger lager.Logger) ifrit.Runner {
	var token authentication.Token

	if *devMode {
		token = authentication.NullToken{}
	} else {
		token = authentication.NewAccessToken(cfg.UAAPublicKey)
		err := token.CheckPublicToken()
		if err != nil {
			logger.Error("failed to check public token", err)
			os.Exit(1)
		}
	}

	validator := handlers.NewValidator()
	routesHandler := handlers.NewRoutesHandler(token, *maxTTL, validator, database, logger)
	eventStreamHandler := handlers.NewEventStreamHandler(token, database, logger, statsdClient, stopChan)

	actions := rata.Handlers{
		"Upsert":      route(routesHandler.Upsert),
		"Delete":      route(routesHandler.Delete),
		"List":        route(routesHandler.List),
		"EventStream": route(eventStreamHandler.EventStream),
	}

	handler, err := rata.NewRouter(routing_api.Routes, actions)
	if err != nil {
		logger.Error("failed to create router", err)
		os.Exit(1)
	}

	handler = handlers.LogWrap(handler, logger)
	return http_server.New(":"+strconv.Itoa(*port), handler)
}
Exemple #4
0
func New(logger logger.Logger, store store.Store, timeProvider timeprovider.TimeProvider) (http.Handler, error) {
	handlers := map[string]http.Handler{
		"bulk_app_state": NewBulkAppStateHandler(logger, store, timeProvider),
	}

	return rata.NewRouter(apiserver.Routes, handlers)
}
Exemple #5
0
func initializeServer(
	bbsClient bbs.Client,
	executorClient executor.Client,
	evacuatable evacuation_context.Evacuatable,
	evacuationReporter evacuation_context.EvacuationReporter,
	logger lager.Logger,
	stackMap rep.StackPathMap,
	supportedProviders []string,
) (ifrit.Runner, string) {
	lrpStopper := initializeLRPStopper(*cellID, executorClient, logger)

	auctionCellRep := auction_cell_rep.New(*cellID, stackMap, supportedProviders, *zone, generateGuid, executorClient, evacuationReporter, logger)
	handlers := handlers.New(auctionCellRep, lrpStopper, executorClient, evacuatable, logger)

	router, err := rata.NewRouter(rep.Routes, handlers)
	if err != nil {
		logger.Fatal("failed-to-construct-router", err)
	}

	ip, err := localip.LocalIP()
	if err != nil {
		logger.Fatal("failed-to-fetch-ip", err)
	}

	port := strings.Split(*listenAddr, ":")[1]
	address := fmt.Sprintf("http://%s:%s", ip, port)

	return http_server.New(*listenAddr, router), address
}
func (f *FakeCell) SpinUp(serviceClient bbs.ServiceClient) {
	//make a test-friendly AuctionRepDelegate using the auction package's SimulationRepDelegate
	f.SimulationRep = simulationrep.New(f.stack, "Z0", rep.Resources{
		DiskMB:     100,
		MemoryMB:   100,
		Containers: 100,
	})

	//spin up an http auction server
	logger := lager.NewLogger(f.cellID)
	logger.RegisterSink(lager.NewWriterSink(GinkgoWriter, lager.INFO))

	fakeLRPStopper := new(fake_lrp_stopper.FakeLRPStopper)
	fakeExecutorClient := new(executorfakes.FakeClient)
	fakeEvacuatable := new(fake_evacuation_context.FakeEvacuatable)

	handlers := rephandlers.New(f.SimulationRep, fakeLRPStopper, fakeExecutorClient, fakeEvacuatable, logger)
	router, err := rata.NewRouter(rep.Routes, handlers)
	Expect(err).NotTo(HaveOccurred())
	f.server = httptest.NewServer(router)

	presence := models.NewCellPresence(
		f.cellID,
		f.server.URL,
		"az1",
		models.NewCellCapacity(512, 1024, 124),
		[]string{},
		[]string{})

	f.heartbeater = ifrit.Invoke(serviceClient.NewCellPresenceRunner(logger, &presence, time.Second))
}
func New(bbs bbs.Client, receptorBBS legacybbs.ReceptorBBS, logger lager.Logger, username, password string, corsEnabled bool) http.Handler {
	taskHandler := NewTaskHandler(bbs, logger)
	desiredLRPHandler := NewDesiredLRPHandler(bbs, receptorBBS, logger)
	actualLRPHandler := NewActualLRPHandler(bbs, receptorBBS, logger)
	cellHandler := NewCellHandler(receptorBBS, logger)
	domainHandler := NewDomainHandler(bbs, receptorBBS, logger)
	eventStreamHandler := NewEventStreamHandler(bbs, logger)
	authCookieHandler := NewAuthCookieHandler(logger)

	actions := rata.Handlers{
		// Tasks
		receptor.CreateTaskRoute: route(taskHandler.Create),
		receptor.TasksRoute:      route(taskHandler.GetAll),
		receptor.GetTaskRoute:    route(taskHandler.GetByGuid),
		receptor.DeleteTaskRoute: route(taskHandler.Delete),
		receptor.CancelTaskRoute: route(taskHandler.Cancel),

		// DesiredLRPs
		receptor.CreateDesiredLRPRoute: route(desiredLRPHandler.Create),
		receptor.GetDesiredLRPRoute:    route(desiredLRPHandler.Get),
		receptor.UpdateDesiredLRPRoute: route(desiredLRPHandler.Update),
		receptor.DeleteDesiredLRPRoute: route(desiredLRPHandler.Delete),
		receptor.DesiredLRPsRoute:      route(desiredLRPHandler.GetAll),

		// ActualLRPs
		receptor.ActualLRPsRoute:                         route(actualLRPHandler.GetAll),
		receptor.ActualLRPsByProcessGuidRoute:            route(actualLRPHandler.GetAllByProcessGuid),
		receptor.ActualLRPByProcessGuidAndIndexRoute:     route(actualLRPHandler.GetByProcessGuidAndIndex),
		receptor.KillActualLRPByProcessGuidAndIndexRoute: route(actualLRPHandler.KillByProcessGuidAndIndex),

		// Cells
		receptor.CellsRoute: route(cellHandler.GetAll),

		// Domains
		receptor.UpsertDomainRoute: route(domainHandler.Upsert),
		receptor.DomainsRoute:      route(domainHandler.GetAll),

		// Event Streaming
		receptor.EventStream: route(eventStreamHandler.EventStream),

		// Authentication Cookie
		receptor.GenerateCookie: route(authCookieHandler.GenerateCookie),
	}

	handler, err := rata.NewRouter(receptor.Routes, actions)
	if err != nil {
		panic("unable to create router: " + err.Error())
	}

	if username != "" {
		handler = CookieAuthWrap(BasicAuthWrap(handler, username, password), receptor.AuthorizationCookieName)
	}

	if corsEnabled {
		handler = CORSWrapper(handler)
	}

	return LogWrap(handler, logger)
}
func New(staticDirectory string, logger lager.Logger) (http.Handler, error) {
	staticRoute, err := fileserver.Routes.CreatePathForRoute(fileserver.StaticRoute, nil)
	if err != nil {
		return nil, err
	}

	return rata.NewRouter(fileserver.Routes, rata.Handlers{
		fileserver.StaticRoute: static.New(staticDirectory, staticRoute, logger),
	})
}
func NewHandler(logger lager.Logger, client volman.Manager) (http.Handler, error) {
	logger = logger.Session("server")
	logger.Info("start")
	defer logger.Info("end")

	var handlers = rata.Handlers{
		"drivers": newListDriversHandler(logger, client),
		"mount":   newMountHandler(logger, client),
		"unmount": newUnmountHandler(logger, client),
	}

	return rata.NewRouter(volman.Routes, handlers)
}
Exemple #10
0
func main() {
	flag.Parse()

	logger := lager.NewLogger("lattice-app")
	if quiet {
		logger.RegisterSink(lager.NewWriterSink(os.Stdout, lager.INFO))
	} else {
		logger.RegisterSink(lager.NewWriterSink(os.Stdout, lager.DEBUG))
	}

	ports := getServerPorts()

	logger.Info("lattice-app.starting", lager.Data{"ports": ports})
	handler, err := rata.NewRouter(routes.Routes, handlers.New(logger))
	if err != nil {
		logger.Fatal("router.creation.failed", err)
	}

	index, err := helpers.FetchIndex()
	appName := fetchAppName()
	go func() {
		t := time.NewTicker(time.Second)
		for {
			<-t.C
			if err != nil {
				fmt.Fprintf(os.Stderr, "Failed to fetch index: %s\n", err.Error())
			} else {
				fmt.Println(fmt.Sprintf("%s. Says %s. on index: %d", appName, message, index))
			}
		}
	}()

	wg := sync.WaitGroup{}
	for _, port := range ports {
		wg.Add(1)
		go func(wg *sync.WaitGroup, port string) {
			defer wg.Done()
			server := ifrit.Envoke(http_server.New(":"+port, handler))
			logger.Info("lattice-app.up", lager.Data{"port": port})
			err = <-server.Wait()
			if err != nil {
				logger.Error("shutting down server", err, lager.Data{"server port": port})
			}
			logger.Info("shutting down server", lager.Data{"server port": port})
		}(&wg, port)
	}
	wg.Wait()
	logger.Info("shutting latice app")
}
Exemple #11
0
func New(runner auctiontypes.AuctionRunner, logger lager.Logger) http.Handler {
	taskAuctionHandler := logWrap(route(NewTaskAuctionHandler(runner).Create), logger)
	lrpAuctionHandler := logWrap(route(NewLRPAuctionHandler(runner).Create), logger)

	actions := rata.Handlers{
		CreateTaskAuctionsRoute: taskAuctionHandler,
		CreateLRPAuctionsRoute:  lrpAuctionHandler,
	}

	handler, err := rata.NewRouter(Routes, actions)
	if err != nil {
		panic("unable to create router: " + err.Error())
	}

	return handler
}
Exemple #12
0
func constructApiServer(cfg config.Config, database db.DB, statsdClient statsd.Statter, stopChan chan struct{}, logger lager.Logger) ifrit.Runner {
	var tokenValidator authentication.TokenValidator

	if *devMode {
		tokenValidator = authentication.NullTokenValidator{}
	} else {
		uaaKeyFetcher := authentication.NewUaaKeyFetcher(logger, cfg.UAAEndpoint+"/token_key")
		uaaPublicKey, err := uaaKeyFetcher.FetchKey()
		if err != nil {
			logger.Error("Failed to get verification key from UAA", err)
			os.Exit(1)
		}
		tokenValidator = authentication.NewAccessTokenValidator(logger, uaaPublicKey, uaaKeyFetcher)
		err = tokenValidator.CheckPublicToken()
		if err != nil {
			logger.Error("Failed to check public token", err)
			os.Exit(1)
		}
	}

	validator := handlers.NewValidator()
	routesHandler := handlers.NewRoutesHandler(tokenValidator, *maxTTL, validator, database, logger)
	eventStreamHandler := handlers.NewEventStreamHandler(tokenValidator, database, logger, statsdClient, stopChan)
	routeGroupsHandler := handlers.NewRouteGroupsHandler(tokenValidator, logger)
	tcpMappingsHandler := handlers.NewTcpRouteMappingsHandler(tokenValidator, validator, database, logger)

	actions := rata.Handlers{
		routing_api.UpsertRoute:           route(routesHandler.Upsert),
		routing_api.DeleteRoute:           route(routesHandler.Delete),
		routing_api.ListRoute:             route(routesHandler.List),
		routing_api.EventStreamRoute:      route(eventStreamHandler.EventStream),
		routing_api.ListRouterGroups:      route(routeGroupsHandler.ListRouterGroups),
		routing_api.UpsertTcpRouteMapping: route(tcpMappingsHandler.Upsert),
		routing_api.DeleteTcpRouteMapping: route(tcpMappingsHandler.Delete),
		routing_api.ListTcpRouteMapping:   route(tcpMappingsHandler.List),
		routing_api.EventStreamTcpRoute:   route(eventStreamHandler.TcpEventStream),
	}

	handler, err := rata.NewRouter(routing_api.Routes, actions)
	if err != nil {
		logger.Error("failed to create router", err)
		os.Exit(1)
	}

	handler = handlers.LogWrap(handler, logger)
	return http_server.New(":"+strconv.Itoa(int(*port)), handler)
}
func rataWrap(handler http.Handler, method, path string, params rata.Params) (http.Handler, *http.Request) {
	testRoutes := rata.Routes{
		{Name: "wicked_smat", Method: method, Path: path},
	}
	requestGenerator := rata.NewRequestGenerator("", testRoutes)
	testHandlers := rata.Handlers{
		"wicked_smat": handler,
	}

	router, err := rata.NewRouter(testRoutes, testHandlers)
	Expect(err).NotTo(HaveOccurred())

	request, err := requestGenerator.CreateRequest("wicked_smat", params, nil)
	Expect(err).NotTo(HaveOccurred())

	return router, request
}
Exemple #14
0
func New(enqueue chan<- models.Task, logger lager.Logger) http.Handler {
	taskHandler := NewHandler(enqueue, logger)

	actions := rata.Handlers{
		// internal Tasks
		routes.CompleteTasks: taskHandler,
	}

	handler, err := rata.NewRouter(routes.CompleteTasksRoutes, actions)
	if err != nil {
		panic("unable to create router: " + err.Error())
	}

	handler = handlers.LogWrap(handler, logger)

	return handler
}
Exemple #15
0
func NewServer(secret string, enqueuer *build.Enqueuer) http.Handler {
	cbHandler := &callbackHandler{
		enqueuer: enqueuer,
	}

	handlers := map[string]http.Handler{
		Callback: GitHubHMAC(secret, http.HandlerFunc(cbHandler.callback)),
	}

	router, err := rata.NewRouter(Routes, handlers)
	if err != nil {
		panic(err)
	}

	return &server{
		rootHandler: router,
	}
}
Exemple #16
0
func New(logger lager.Logger, ccClient cc_client.CcClient, bbsClient bbs.Client, backends map[string]backend.Backend, clock clock.Clock) http.Handler {

	stagingHandler := NewStagingHandler(logger, backends, ccClient, bbsClient)
	stagingCompletedHandler := NewStagingCompletionHandler(logger, ccClient, backends, clock)

	actions := rata.Handlers{
		stager.StageRoute:            http.HandlerFunc(stagingHandler.Stage),
		stager.StopStagingRoute:      http.HandlerFunc(stagingHandler.StopStaging),
		stager.StagingCompletedRoute: http.HandlerFunc(stagingCompletedHandler.StagingComplete),
	}

	handler, err := rata.NewRouter(stager.Routes, actions)
	if err != nil {
		panic("unable to create router: " + err.Error())
	}

	return handler
}
Exemple #17
0
func NewOAuthHandler(
	logger lager.Logger,
	providers Providers,
	signingKey *rsa.PrivateKey,
) (http.Handler, error) {
	return rata.NewRouter(OAuthRoutes, map[string]http.Handler{
		OAuthBegin: NewOAuthBeginHandler(
			logger.Session("oauth-begin"),
			providers,
			signingKey,
		),

		OAuthCallback: NewOAuthCallbackHandler(
			logger.Session("oauth-callback"),
			providers,
			signingKey,
		),
	})
}
Exemple #18
0
func New(logger lager.Logger, bbsClient bbs.Client, recipebuilders map[string]recipebuilder.RecipeBuilder) http.Handler {

	desireAppHandler := NewDesireAppHandler(logger, bbsClient, recipebuilders)
	stopAppHandler := NewStopAppHandler(logger, bbsClient)
	killIndexHandler := NewKillIndexHandler(logger, bbsClient)

	actions := rata.Handlers{
		nsync.DesireAppRoute: http.HandlerFunc(desireAppHandler.DesireApp),
		nsync.StopAppRoute:   http.HandlerFunc(stopAppHandler.StopApp),
		nsync.KillIndexRoute: http.HandlerFunc(killIndexHandler.KillIndex),
	}

	handler, err := rata.NewRouter(nsync.Routes, actions)
	if err != nil {
		panic("unable to create router: " + err.Error())
	}

	return handler
}
Exemple #19
0
func New(logger lager.Logger, db db.DB, hub events.Hub) http.Handler {
	domainHandler := NewDomainHandler(logger, db)
	actualLRPHandler := NewActualLRPHandler(logger, db)
	actualLRPLifecycleHandler := NewActualLRPLifecycleHandler(logger, db)
	desiredLRPHandler := NewDesiredLRPHandler(logger, db)
	taskHandler := NewTaskHandler(logger, db)
	eventsHandler := NewEventHandler(logger, hub)

	actions := rata.Handlers{
		// Domains
		bbs.DomainsRoute:      route(domainHandler.GetAll),
		bbs.UpsertDomainRoute: route(domainHandler.Upsert),

		// Actual LRPs
		bbs.ActualLRPGroupsRoute:                     route(actualLRPHandler.ActualLRPGroups),
		bbs.ActualLRPGroupsByProcessGuidRoute:        route(actualLRPHandler.ActualLRPGroupsByProcessGuid),
		bbs.ActualLRPGroupByProcessGuidAndIndexRoute: route(actualLRPHandler.ActualLRPGroupByProcessGuidAndIndex),
		bbs.ClaimActualLRPRoute:                      route(actualLRPLifecycleHandler.ClaimActualLRP),
		bbs.StartActualLRPRoute:                      route(actualLRPLifecycleHandler.StartActualLRP),
		bbs.CrashActualLRPRoute:                      route(actualLRPLifecycleHandler.CrashActualLRP),
		bbs.RetireActualLRPRoute:                     route(actualLRPLifecycleHandler.RetireActualLRP),
		bbs.FailActualLRPRoute:                       route(actualLRPLifecycleHandler.FailActualLRP),
		bbs.RemoveActualLRPRoute:                     route(actualLRPLifecycleHandler.RemoveActualLRP),

		// Desired LRPs
		bbs.DesiredLRPsRoute:             route(desiredLRPHandler.DesiredLRPs),
		bbs.DesiredLRPByProcessGuidRoute: route(desiredLRPHandler.DesiredLRPByProcessGuid),

		// Tasks
		bbs.TasksRoute:      route(taskHandler.Tasks),
		bbs.TaskByGuidRoute: route(taskHandler.TaskByGuid),

		// Events
		bbs.EventStreamRoute: route(eventsHandler.Subscribe),
	}

	handler, err := rata.NewRouter(bbs.Routes, actions)
	if err != nil {
		panic("unable to create router: " + err.Error())
	}

	return LogWrap(logger, handler)
}
Exemple #20
0
func main() {
	logger := lager.NewLogger("lattice-app")
	if quiet {
		logger.RegisterSink(lager.NewWriterSink(os.Stdout, lager.INFO))
	} else {
		logger.RegisterSink(lager.NewWriterSink(os.Stdout, lager.DEBUG))
	}

	port := os.Getenv("PORT")
	if port == "" {
		port = "8080"
	}

	logger.Info("lattice-app.starting", lager.Data{"port": port})
	handler, err := rata.NewRouter(routes.Routes, handlers.New(logger))
	if err != nil {
		logger.Fatal("router.creation.failed", err)
	}

	index, err := helpers.FetchIndex()
	appName := helpers.FetchAppName()

	go func() {
		t := time.NewTicker(time.Second)
		for {
			<-t.C
			if err != nil {
				fmt.Fprintf(os.Stderr, "Failed to fetch index: %s\n", err.Error())
			} else {
				fmt.Println(fmt.Sprintf("%s. Says %s. on index: %d", appName, message, index))
			}
		}
	}()

	server := ifrit.Envoke(http_server.New(":"+port, handler))
	logger.Info("lattice-app.up", lager.Data{"port": port})
	err = <-server.Wait()
	if err != nil {
		logger.Error("farewell", err)
	}
	logger.Info("farewell")
}
Exemple #21
0
func constructApiServer(cfg config.Config, database db.DB, statsdClient statsd.Statter, logger lager.Logger) ifrit.Runner {

	uaaClient, err := newUaaClient(logger, cfg)
	if err != nil {
		logger.Error("Failed to create uaa client", err)
		os.Exit(1)
	}

	_, err = uaaClient.FetchKey()
	if err != nil {
		logger.Error("Failed to get verification key from UAA", err)
		os.Exit(1)
	}

	validator := handlers.NewValidator()
	routesHandler := handlers.NewRoutesHandler(uaaClient, int(maxTTL.Seconds()), validator, database, logger)
	eventStreamHandler := handlers.NewEventStreamHandler(uaaClient, database, logger, statsdClient)
	routeGroupsHandler := handlers.NewRouteGroupsHandler(uaaClient, logger, database)
	tcpMappingsHandler := handlers.NewTcpRouteMappingsHandler(uaaClient, validator, database, int(maxTTL.Seconds()), logger)

	actions := rata.Handlers{
		routing_api.UpsertRoute:           route(routesHandler.Upsert),
		routing_api.DeleteRoute:           route(routesHandler.Delete),
		routing_api.ListRoute:             route(routesHandler.List),
		routing_api.EventStreamRoute:      route(eventStreamHandler.EventStream),
		routing_api.ListRouterGroups:      route(routeGroupsHandler.ListRouterGroups),
		routing_api.UpsertTcpRouteMapping: route(tcpMappingsHandler.Upsert),
		routing_api.DeleteTcpRouteMapping: route(tcpMappingsHandler.Delete),
		routing_api.ListTcpRouteMapping:   route(tcpMappingsHandler.List),
		routing_api.EventStreamTcpRoute:   route(eventStreamHandler.TcpEventStream),
	}

	handler, err := rata.NewRouter(routing_api.Routes, actions)
	if err != nil {
		logger.Error("failed to create router", err)
		os.Exit(1)
	}

	handler = handlers.LogWrap(handler, logger)
	return http_server.New(":"+strconv.Itoa(int(*port)), handler)
}
Exemple #22
0
func New(apiClient bbs.Client, noaaClient lrpstats.NoaaClient, maxInFlight, bulkLRPStatusWorkers int, logger lager.Logger) (http.Handler, error) {
	semaphore := make(chan struct{}, maxInFlight)
	clock := clock.NewClock()

	handlers := map[string]http.Handler{
		tps.LRPStatus: tpsHandler{
			semaphore:       semaphore,
			delegateHandler: LogWrap(lrpstatus.NewHandler(apiClient, clock, logger), logger),
		},
		tps.LRPStats: tpsHandler{
			semaphore:       semaphore,
			delegateHandler: LogWrap(lrpstats.NewHandler(apiClient, noaaClient, clock, logger), logger),
		},
		tps.BulkLRPStatus: tpsHandler{
			semaphore:       semaphore,
			delegateHandler: LogWrap(bulklrpstatus.NewHandler(apiClient, clock, bulkLRPStatusWorkers, logger), logger),
		},
	}

	return rata.NewRouter(tps.Routes, handlers)
}
Exemple #23
0
func main() {
	logger := lager.NewLogger("cnsim-server")
	logger.RegisterSink(lager.NewWriterSink(os.Stdout, lager.DEBUG))

	port := getEnv(logger, "PORT", "9000")
	listenAddress := getEnv(logger, "LISTEN_ADDRESS", "127.0.0.1")

	address := fmt.Sprintf("%s:%s", listenAddress, port)
	logger.Info("listen", lager.Data{"address": address})

	routes := rata.Routes{
		{Name: "root", Method: "GET", Path: "/"},
		{Name: "steady_state", Method: "GET", Path: "/steady_state"},
	}

	rataHandlers := rata.Handlers{
		"root": &handlers.Root{
			Logger: logger,
		},
		"steady_state": gziphandler.GzipHandler(&handlers.SteadyState{
			Logger: logger,
			Simulator: &simulate.SteadyState{
				AppSizeDistribution: &distributions.GeometricWithPositiveSupport{},
			},
		}),
	}

	router, err := rata.NewRouter(routes, rataHandlers)
	if err != nil {
		log.Fatalf("unable to create rata Router: %s", err) // not tested
	}

	monitor := ifrit.Invoke(sigmon.New(grouper.NewOrdered(os.Interrupt, grouper.Members{
		{"http_server", http_server.New(address, router)},
	})))
	err = <-monitor.Wait()
	if err != nil {
		log.Fatalf("ifrit: %s", err)
	}
}
Exemple #24
0
func main() {
	cf_lager.AddFlags(flag.CommandLine)
	flag.Parse()

	if *repGuid == "" {
		panic("need rep-guid")
	}

	if *httpAddr == "" {
		panic("need http addr")
	}

	simulationRep := simulationrep.New(*stack, *zone, rep.Resources{
		MemoryMB:   int32(*memoryMB),
		DiskMB:     int32(*diskMB),
		Containers: *containers,
	})

	logger, _ := cf_lager.New("repnode-http")

	fakeLRPStopper := new(fake_lrp_stopper.FakeLRPStopper)
	fakeExecutorClient := new(executorfakes.FakeClient)
	fakeEvacuatable := new(fake_evacuation_context.FakeEvacuatable)

	handlers := rephandlers.New(simulationRep, fakeLRPStopper, fakeExecutorClient, fakeEvacuatable, logger.Session(*repGuid))
	router, err := rata.NewRouter(rep.Routes, handlers)
	if err != nil {
		log.Fatalln("failed to make router:", err)
	}
	httpServer := http_server.New(*httpAddr, router)

	monitor := ifrit.Invoke(sigmon.New(httpServer))
	fmt.Println("rep node listening")
	err = <-monitor.Wait()
	if err != nil {
		println("EXITED WITH ERROR: ", err.Error())
	}
}
Exemple #25
0
func New(logger lager.Logger, db db.DB, hub events.Hub, migrationsDone <-chan struct{}) http.Handler {
	pingHandler := NewPingHandler(logger)
	domainHandler := NewDomainHandler(logger, db)
	actualLRPHandler := NewActualLRPHandler(logger, db)
	actualLRPLifecycleHandler := NewActualLRPLifecycleHandler(logger, db)
	evacuationHandler := NewEvacuationHandler(logger, db)
	desiredLRPHandler := NewDesiredLRPHandler(logger, db)
	lrpConvergenceHandler := NewLRPConvergenceHandler(logger, db)
	taskHandler := NewTaskHandler(logger, db)
	eventsHandler := NewEventHandler(logger, hub)

	actions := rata.Handlers{
		// Ping
		bbs.PingRoute: route(EmitLatency(pingHandler.Ping)),

		// Domains
		bbs.DomainsRoute:      route(EmitLatency(domainHandler.Domains)),
		bbs.UpsertDomainRoute: route(EmitLatency(domainHandler.Upsert)),

		// Actual LRPs
		bbs.ActualLRPGroupsRoute:                     route(EmitLatency(actualLRPHandler.ActualLRPGroups)),
		bbs.ActualLRPGroupsByProcessGuidRoute:        route(EmitLatency(actualLRPHandler.ActualLRPGroupsByProcessGuid)),
		bbs.ActualLRPGroupByProcessGuidAndIndexRoute: route(EmitLatency(actualLRPHandler.ActualLRPGroupByProcessGuidAndIndex)),

		// Actual LRP Lifecycle
		bbs.ClaimActualLRPRoute:  route(EmitLatency(actualLRPLifecycleHandler.ClaimActualLRP)),
		bbs.StartActualLRPRoute:  route(EmitLatency(actualLRPLifecycleHandler.StartActualLRP)),
		bbs.CrashActualLRPRoute:  route(EmitLatency(actualLRPLifecycleHandler.CrashActualLRP)),
		bbs.RetireActualLRPRoute: route(EmitLatency(actualLRPLifecycleHandler.RetireActualLRP)),
		bbs.FailActualLRPRoute:   route(EmitLatency(actualLRPLifecycleHandler.FailActualLRP)),
		bbs.RemoveActualLRPRoute: route(EmitLatency(actualLRPLifecycleHandler.RemoveActualLRP)),

		// Evacuation
		bbs.RemoveEvacuatingActualLRPRoute: route(EmitLatency(evacuationHandler.RemoveEvacuatingActualLRP)),
		bbs.EvacuateClaimedActualLRPRoute:  route(EmitLatency(evacuationHandler.EvacuateClaimedActualLRP)),
		bbs.EvacuateCrashedActualLRPRoute:  route(EmitLatency(evacuationHandler.EvacuateCrashedActualLRP)),
		bbs.EvacuateStoppedActualLRPRoute:  route(EmitLatency(evacuationHandler.EvacuateStoppedActualLRP)),
		bbs.EvacuateRunningActualLRPRoute:  route(EmitLatency(evacuationHandler.EvacuateRunningActualLRP)),

		// LRP Convergence
		bbs.ConvergeLRPsRoute: route(EmitLatency(lrpConvergenceHandler.ConvergeLRPs)),

		// Desired LRPs
		bbs.DesiredLRPsRoute:               route(EmitLatency(desiredLRPHandler.DesiredLRPs)),
		bbs.DesiredLRPByProcessGuidRoute:   route(EmitLatency(desiredLRPHandler.DesiredLRPByProcessGuid)),
		bbs.DesiredLRPSchedulingInfosRoute: route(EmitLatency(desiredLRPHandler.DesiredLRPSchedulingInfos)),
		bbs.DesireDesiredLRPRoute:          route(EmitLatency(desiredLRPHandler.DesireDesiredLRP)),
		bbs.UpdateDesiredLRPRoute:          route(EmitLatency(desiredLRPHandler.UpdateDesiredLRP)),
		bbs.RemoveDesiredLRPRoute:          route(EmitLatency(desiredLRPHandler.RemoveDesiredLRP)),

		// Tasks
		bbs.TasksRoute:         route(EmitLatency(taskHandler.Tasks)),
		bbs.TaskByGuidRoute:    route(EmitLatency(taskHandler.TaskByGuid)),
		bbs.DesireTaskRoute:    route(EmitLatency(taskHandler.DesireTask)),
		bbs.StartTaskRoute:     route(EmitLatency(taskHandler.StartTask)),
		bbs.CancelTaskRoute:    route(EmitLatency(taskHandler.CancelTask)),
		bbs.FailTaskRoute:      route(EmitLatency(taskHandler.FailTask)),
		bbs.CompleteTaskRoute:  route(EmitLatency(taskHandler.CompleteTask)),
		bbs.ResolvingTaskRoute: route(EmitLatency(taskHandler.ResolvingTask)),
		bbs.DeleteTaskRoute:    route(EmitLatency(taskHandler.DeleteTask)),
		bbs.ConvergeTasksRoute: route(EmitLatency(taskHandler.ConvergeTasks)),

		// Events
		bbs.EventStreamRoute: route(eventsHandler.Subscribe),
	}

	handler, err := rata.NewRouter(bbs.Routes, actions)
	if err != nil {
		panic("unable to create router: " + err.Error())
	}

	return RequestCountWrap(LogWrap(logger, UnavailableWrap(handler, migrationsDone)))
}
Exemple #26
0
			{Path: "/something", Method: "POST", Name: "poster"},
			{Path: "/something", Method: "PuT", Name: "putter"},
			{Path: "/something", Method: "DELETE", Name: "deleter"},
		}

		Context("when all the handlers are present", func() {
			var resp *httptest.ResponseRecorder
			var handlers = rata.Handlers{
				"getter":  ghttp.RespondWith(http.StatusOK, "get response"),
				"poster":  ghttp.RespondWith(http.StatusOK, "post response"),
				"putter":  ghttp.RespondWith(http.StatusOK, "put response"),
				"deleter": ghttp.RespondWith(http.StatusOK, "delete response"),
			}
			BeforeEach(func() {
				resp = httptest.NewRecorder()
				r, err = rata.NewRouter(routes, handlers)
				Ω(err).ShouldNot(HaveOccurred())
			})

			It("makes GET handlers", func() {
				req, _ := http.NewRequest("GET", "/something", nil)

				r.ServeHTTP(resp, req)
				Ω(resp.Body.String()).Should(Equal("get response"))
			})

			It("makes POST handlers", func() {
				req, _ := http.NewRequest("POST", "/something", nil)

				r.ServeHTTP(resp, req)
				Ω(resp.Body.String()).Should(Equal("post response"))
Exemple #27
0
func New(
	listenNetwork, listenAddr string,
	containerGraceTime time.Duration,
	backend garden.Backend,
	logger lager.Logger,
) *GardenServer {
	s := &GardenServer{
		logger: logger.Session("garden-server"),

		listenNetwork: listenNetwork,
		listenAddr:    listenAddr,

		containerGraceTime: containerGraceTime,
		backend:            backend,

		stopping: make(chan bool),

		handling: new(sync.WaitGroup),
		conns:    make(map[net.Conn]net.Conn),

		streamer: streamer.New(time.Minute),

		destroys:  make(map[string]struct{}),
		destroysL: new(sync.Mutex),
	}

	handlers := map[string]http.Handler{
		routes.Ping:                   http.HandlerFunc(s.handlePing),
		routes.Capacity:               http.HandlerFunc(s.handleCapacity),
		routes.Create:                 http.HandlerFunc(s.handleCreate),
		routes.Destroy:                http.HandlerFunc(s.handleDestroy),
		routes.List:                   http.HandlerFunc(s.handleList),
		routes.Stop:                   http.HandlerFunc(s.handleStop),
		routes.StreamIn:               http.HandlerFunc(s.handleStreamIn),
		routes.StreamOut:              http.HandlerFunc(s.handleStreamOut),
		routes.LimitBandwidth:         http.HandlerFunc(s.handleLimitBandwidth),
		routes.CurrentBandwidthLimits: http.HandlerFunc(s.handleCurrentBandwidthLimits),
		routes.LimitCPU:               http.HandlerFunc(s.handleLimitCPU),
		routes.CurrentCPULimits:       http.HandlerFunc(s.handleCurrentCPULimits),
		routes.LimitDisk:              http.HandlerFunc(s.handleLimitDisk),
		routes.CurrentDiskLimits:      http.HandlerFunc(s.handleCurrentDiskLimits),
		routes.LimitMemory:            http.HandlerFunc(s.handleLimitMemory),
		routes.CurrentMemoryLimits:    http.HandlerFunc(s.handleCurrentMemoryLimits),
		routes.NetIn:                  http.HandlerFunc(s.handleNetIn),
		routes.NetOut:                 http.HandlerFunc(s.handleNetOut),
		routes.Info:                   http.HandlerFunc(s.handleInfo),
		routes.BulkInfo:               http.HandlerFunc(s.handleBulkInfo),
		routes.BulkMetrics:            http.HandlerFunc(s.handleBulkMetrics),
		routes.Run:                    http.HandlerFunc(s.handleRun),
		routes.Stdout:                 streamer.HandlerFunc(s.streamer.ServeStdout),
		routes.Stderr:                 streamer.HandlerFunc(s.streamer.ServeStderr),
		routes.Attach:                 http.HandlerFunc(s.handleAttach),
		routes.Metrics:                http.HandlerFunc(s.handleMetrics),
		routes.Properties:             http.HandlerFunc(s.handleProperties),
		routes.Property:               http.HandlerFunc(s.handleProperty),
		routes.SetProperty:            http.HandlerFunc(s.handleSetProperty),
		routes.RemoveProperty:         http.HandlerFunc(s.handleRemoveProperty),
		routes.SetGraceTime:           http.HandlerFunc(s.handleSetGraceTime),
	}

	mux, err := rata.NewRouter(routes.Routes, handlers)
	if err != nil {
		logger.Fatal("failed-to-initialize-rata", err)
	}

	conLogger := logger.Session("connection")

	s.server = http.Server{
		Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
			mux.ServeHTTP(w, r)
		}),

		ConnState: func(conn net.Conn, state http.ConnState) {
			switch state {
			case http.StateNew:
				conLogger.Debug("open", lager.Data{"local_addr": conn.LocalAddr(), "remote_addr": conn.RemoteAddr()})
				s.handling.Add(1)
			case http.StateActive:
				s.mu.Lock()
				delete(s.conns, conn)
				s.mu.Unlock()
			case http.StateIdle:
				select {
				case <-s.stopping:
					conn.Close()
				default:
					s.mu.Lock()
					s.conns[conn] = conn
					s.mu.Unlock()
				}
			case http.StateHijacked, http.StateClosed:
				s.mu.Lock()
				delete(s.conns, conn)
				s.mu.Unlock()
				conLogger.Debug("closed", lager.Data{"local_addr": conn.LocalAddr(), "remote_addr": conn.RemoteAddr()})
				s.handling.Done()
			}
		},
	}

	return s
}
Exemple #28
0
func New(
	logger, accessLogger lager.Logger,
	updateWorkers int,
	convergenceWorkersSize int,
	db db.DB,
	desiredHub, actualHub events.Hub,
	taskCompletionClient taskworkpool.TaskCompletionClient,
	serviceClient bbs.ServiceClient,
	auctioneerClient auctioneer.Client,
	repClientFactory rep.ClientFactory,
	migrationsDone <-chan struct{},
	exitChan chan struct{},
) http.Handler {
	retirer := controllers.NewActualLRPRetirer(db, actualHub, repClientFactory, serviceClient)
	pingHandler := NewPingHandler()
	domainHandler := NewDomainHandler(db, exitChan)
	actualLRPHandler := NewActualLRPHandler(db, exitChan)
	actualLRPLifecycleHandler := NewActualLRPLifecycleHandler(db, db, actualHub, auctioneerClient, retirer, exitChan)
	evacuationHandler := NewEvacuationHandler(db, db, db, actualHub, auctioneerClient, exitChan)
	desiredLRPHandler := NewDesiredLRPHandler(updateWorkers, db, db, desiredHub, actualHub, auctioneerClient, repClientFactory, serviceClient, exitChan)
	taskController := controllers.NewTaskController(db, taskCompletionClient, auctioneerClient, serviceClient, repClientFactory)
	taskHandler := NewTaskHandler(taskController, exitChan)
	eventsHandler := NewEventHandler(desiredHub, actualHub)
	cellsHandler := NewCellHandler(serviceClient, exitChan)

	emitter := middleware.NewLatencyEmitter(logger)

	actions := rata.Handlers{
		// Ping
		bbs.PingRoute: emitter.EmitLatency(middleware.LogWrap(logger, accessLogger, pingHandler.Ping)),

		// Domains
		bbs.DomainsRoute:      route(emitter.EmitLatency(middleware.LogWrap(logger, accessLogger, domainHandler.Domains))),
		bbs.UpsertDomainRoute: route(emitter.EmitLatency(middleware.LogWrap(logger, accessLogger, domainHandler.Upsert))),

		// Actual LRPs
		bbs.ActualLRPGroupsRoute:                     route(emitter.EmitLatency(middleware.LogWrap(logger, accessLogger, actualLRPHandler.ActualLRPGroups))),
		bbs.ActualLRPGroupsByProcessGuidRoute:        route(emitter.EmitLatency(middleware.LogWrap(logger, accessLogger, actualLRPHandler.ActualLRPGroupsByProcessGuid))),
		bbs.ActualLRPGroupByProcessGuidAndIndexRoute: route(emitter.EmitLatency(middleware.LogWrap(logger, accessLogger, actualLRPHandler.ActualLRPGroupByProcessGuidAndIndex))),

		// Actual LRP Lifecycle
		bbs.ClaimActualLRPRoute:  route(emitter.EmitLatency(middleware.LogWrap(logger, accessLogger, actualLRPLifecycleHandler.ClaimActualLRP))),
		bbs.StartActualLRPRoute:  route(emitter.EmitLatency(middleware.LogWrap(logger, accessLogger, actualLRPLifecycleHandler.StartActualLRP))),
		bbs.CrashActualLRPRoute:  route(emitter.EmitLatency(middleware.LogWrap(logger, accessLogger, actualLRPLifecycleHandler.CrashActualLRP))),
		bbs.RetireActualLRPRoute: route(emitter.EmitLatency(middleware.LogWrap(logger, accessLogger, actualLRPLifecycleHandler.RetireActualLRP))),
		bbs.FailActualLRPRoute:   route(emitter.EmitLatency(middleware.LogWrap(logger, accessLogger, actualLRPLifecycleHandler.FailActualLRP))),
		bbs.RemoveActualLRPRoute: route(emitter.EmitLatency(middleware.LogWrap(logger, accessLogger, actualLRPLifecycleHandler.RemoveActualLRP))),

		// Evacuation
		bbs.RemoveEvacuatingActualLRPRoute: route(emitter.EmitLatency(middleware.LogWrap(logger, accessLogger, evacuationHandler.RemoveEvacuatingActualLRP))),
		bbs.EvacuateClaimedActualLRPRoute:  route(emitter.EmitLatency(middleware.LogWrap(logger, accessLogger, evacuationHandler.EvacuateClaimedActualLRP))),
		bbs.EvacuateCrashedActualLRPRoute:  route(emitter.EmitLatency(middleware.LogWrap(logger, accessLogger, evacuationHandler.EvacuateCrashedActualLRP))),
		bbs.EvacuateStoppedActualLRPRoute:  route(emitter.EmitLatency(middleware.LogWrap(logger, accessLogger, evacuationHandler.EvacuateStoppedActualLRP))),
		bbs.EvacuateRunningActualLRPRoute:  route(emitter.EmitLatency(middleware.LogWrap(logger, accessLogger, evacuationHandler.EvacuateRunningActualLRP))),

		// Desired LRPs
		bbs.DesiredLRPsRoute:               route(emitter.EmitLatency(middleware.LogWrap(logger, accessLogger, desiredLRPHandler.DesiredLRPs))),
		bbs.DesiredLRPByProcessGuidRoute:   route(emitter.EmitLatency(middleware.LogWrap(logger, accessLogger, desiredLRPHandler.DesiredLRPByProcessGuid))),
		bbs.DesiredLRPSchedulingInfosRoute: route(emitter.EmitLatency(middleware.LogWrap(logger, accessLogger, desiredLRPHandler.DesiredLRPSchedulingInfos))),
		bbs.DesireDesiredLRPRoute:          route(emitter.EmitLatency(middleware.LogWrap(logger, accessLogger, desiredLRPHandler.DesireDesiredLRP))),
		bbs.UpdateDesiredLRPRoute:          route(emitter.EmitLatency(middleware.LogWrap(logger, accessLogger, desiredLRPHandler.UpdateDesiredLRP))),
		bbs.RemoveDesiredLRPRoute:          route(emitter.EmitLatency(middleware.LogWrap(logger, accessLogger, desiredLRPHandler.RemoveDesiredLRP))),

		bbs.DesiredLRPsRoute_r0:             route(emitter.EmitLatency(middleware.LogWrap(logger, accessLogger, desiredLRPHandler.DesiredLRPs_r0))),
		bbs.DesiredLRPsRoute_r1:             route(emitter.EmitLatency(middleware.LogWrap(logger, accessLogger, desiredLRPHandler.DesiredLRPs_r1))),
		bbs.DesiredLRPByProcessGuidRoute_r0: route(emitter.EmitLatency(middleware.LogWrap(logger, accessLogger, desiredLRPHandler.DesiredLRPByProcessGuid_r0))),
		bbs.DesiredLRPByProcessGuidRoute_r1: route(emitter.EmitLatency(middleware.LogWrap(logger, accessLogger, desiredLRPHandler.DesiredLRPByProcessGuid_r1))),
		bbs.DesireDesiredLRPRoute_r0:        route(emitter.EmitLatency(middleware.LogWrap(logger, accessLogger, desiredLRPHandler.DesireDesiredLRP_r0))),
		bbs.DesireDesiredLRPRoute_r1:        route(emitter.EmitLatency(middleware.LogWrap(logger, accessLogger, desiredLRPHandler.DesireDesiredLRP_r1))),

		// Tasks
		bbs.TasksRoute:         route(emitter.EmitLatency(middleware.LogWrap(logger, accessLogger, taskHandler.Tasks))),
		bbs.TaskByGuidRoute:    route(emitter.EmitLatency(middleware.LogWrap(logger, accessLogger, taskHandler.TaskByGuid))),
		bbs.DesireTaskRoute:    route(emitter.EmitLatency(middleware.LogWrap(logger, accessLogger, taskHandler.DesireTask))),
		bbs.StartTaskRoute:     route(emitter.EmitLatency(middleware.LogWrap(logger, accessLogger, taskHandler.StartTask))),
		bbs.CancelTaskRoute:    route(emitter.EmitLatency(middleware.LogWrap(logger, accessLogger, taskHandler.CancelTask))),
		bbs.FailTaskRoute:      route(emitter.EmitLatency(middleware.LogWrap(logger, accessLogger, taskHandler.FailTask))),
		bbs.CompleteTaskRoute:  route(emitter.EmitLatency(middleware.LogWrap(logger, accessLogger, taskHandler.CompleteTask))),
		bbs.ResolvingTaskRoute: route(emitter.EmitLatency(middleware.LogWrap(logger, accessLogger, taskHandler.ResolvingTask))),
		bbs.DeleteTaskRoute:    route(emitter.EmitLatency(middleware.LogWrap(logger, accessLogger, taskHandler.DeleteTask))),

		bbs.TasksRoute_r1:      route(emitter.EmitLatency(middleware.LogWrap(logger, accessLogger, taskHandler.Tasks_r1))),
		bbs.TasksRoute_r0:      route(emitter.EmitLatency(middleware.LogWrap(logger, accessLogger, taskHandler.Tasks_r0))),
		bbs.TaskByGuidRoute_r1: route(emitter.EmitLatency(middleware.LogWrap(logger, accessLogger, taskHandler.TaskByGuid_r1))),
		bbs.TaskByGuidRoute_r0: route(emitter.EmitLatency(middleware.LogWrap(logger, accessLogger, taskHandler.TaskByGuid_r0))),
		bbs.DesireTaskRoute_r1: route(emitter.EmitLatency(middleware.LogWrap(logger, accessLogger, taskHandler.DesireTask_r1))),
		bbs.DesireTaskRoute_r0: route(emitter.EmitLatency(middleware.LogWrap(logger, accessLogger, taskHandler.DesireTask_r0))),

		// Events
		bbs.EventStreamRoute_r0: route(middleware.LogWrap(logger, accessLogger, eventsHandler.Subscribe_r0)),

		// Cells
		bbs.CellsRoute:    route(emitter.EmitLatency(middleware.LogWrap(logger, accessLogger, cellsHandler.Cells))),
		bbs.CellsRoute_r1: route(emitter.EmitLatency(middleware.LogWrap(logger, accessLogger, cellsHandler.Cells))),
	}

	handler, err := rata.NewRouter(bbs.Routes, actions)
	if err != nil {
		panic("unable to create router: " + err.Error())
	}

	return middleware.RequestCountWrap(
		UnavailableWrap(handler,
			migrationsDone,
		),
	)
}
Exemple #29
0
}

var _ = BeforeSuite(func() {
	cfHttpTimeout = 1 * time.Second
	cf_http.Initialize(cfHttpTimeout)
})

var _ = BeforeEach(func() {
	logger := lagertest.NewTestLogger("test")

	auctionRep = &repfakes.FakeClient{}
	fakeLRPStopper = &fake_lrp_stopper.FakeLRPStopper{}
	fakeExecutorClient = &executorfakes.FakeClient{}
	fakeEvacuatable = &fake_evacuation_context.FakeEvacuatable{}

	handler, err := rata.NewRouter(rep.Routes, handlers.New(auctionRep, fakeLRPStopper, fakeExecutorClient, fakeEvacuatable, logger))
	Expect(err).NotTo(HaveOccurred())
	server = httptest.NewServer(handler)

	client = rep.NewClient(&http.Client{}, server.URL)

	serverThatErrors = ghttp.NewServer()
	erroringHandler := http.HandlerFunc(func(http.ResponseWriter, *http.Request) {
		serverThatErrors.CloseClientConnections()
	})
	//5 erroringHandlers should be more than enough: none of the individual tests should make more than 5 requests to this server
	serverThatErrors.AppendHandlers(erroringHandler, erroringHandler, erroringHandler, erroringHandler, erroringHandler)

	clientForServerThatErrors = rep.NewClient(&http.Client{}, serverThatErrors.URL())
})
Exemple #30
0
	RunSpecs(t, "AuctionHttpHandlers Suite")
}

var server *httptest.Server
var requestGenerator *rata.RequestGenerator
var client *http.Client
var fakeLocalRep *repfakes.FakeSimClient
var repGuid string

var _ = BeforeEach(func() {
	logger := lagertest.NewTestLogger("handlers")

	fakeLocalRep = new(repfakes.FakeSimClient)
	fakeExecutorClient := new(executorfakes.FakeClient)
	fakeEvacuatable := new(fake_evacuation_context.FakeEvacuatable)
	handler, err := rata.NewRouter(rep.Routes, handlers.New(fakeLocalRep, fakeExecutorClient, fakeEvacuatable, logger))
	Expect(err).NotTo(HaveOccurred())
	server = httptest.NewServer(handler)

	requestGenerator = rata.NewRequestGenerator(server.URL, rep.Routes)

	client = &http.Client{}
})

var _ = AfterEach(func() {
	server.Close()
})

func JSONFor(obj interface{}) string {
	marshalled, err := json.Marshal(obj)
	ExpectWithOffset(1, err).NotTo(HaveOccurred())