Example #1
0
func initServer(conf *configuration.Configuration, conn *zk.Conn, eventBus *event_bus.EventBus) {
	stateAPI := api.StateAPI{Config: conf, Zookeeper: conn}
	serviceAPI := api.ServiceAPI{Config: conf, Zookeeper: conn}
	eventSubAPI := api.EventSubscriptionAPI{Conf: conf, EventBus: eventBus}

	conf.StatsD.Increment(1.0, "restart", 1)
	// Status live information
	router := martini.Classic()
	router.Get("/status", api.HandleStatus)

	// API
	router.Group("/api", func(api martini.Router) {
		// State API
		api.Get("/state", stateAPI.Get)
		// Service API
		api.Get("/services", serviceAPI.All)
		api.Post("/services", serviceAPI.Create)
		api.Put("/services/**", serviceAPI.Put)
		api.Delete("/services/**", serviceAPI.Delete)
		api.Post("/marathon/event_callback", eventSubAPI.Callback)
	})

	// Static pages
	router.Use(martini.Static(path.Join(executableFolder(), "webapp")))

	registerMarathonEvent(conf)
	router.RunOnAddr(serverBindPort)
}
Example #2
0
func initServer(conf *configuration.Configuration, storage service.Storage, appStorage application.Storage, eventBus *event_bus.EventBus) {
	stateAPI := api.StateAPI{Config: conf, Storage: storage, AppStorage: appStorage}
	serviceAPI := api.ServiceAPI{Config: conf, Storage: storage}
	eventSubAPI := api.EventSubscriptionAPI{Conf: conf, EventBus: eventBus}
	weightAPI := api.WeightAPI{Config: conf, Storage: appStorage}

	conf.StatsD.Increment(1.0, "restart", 1)
	// Status live information
	router := martini.Classic()
	router.Get("/status", api.HandleStatus)
	// HealthCheck API
	router.Get("/healthcheck", api.HealthCheck)

	// API
	router.Group("/api", func(api martini.Router) {
		// State API
		api.Get("/state", stateAPI.Get)
		// Service API
		api.Get("/services", serviceAPI.All)
		api.Post("/services", serviceAPI.Create)
		api.Put("/services/**", serviceAPI.Put)
		api.Delete("/services/**", serviceAPI.Delete)
		api.Post("/marathon/event_callback", eventSubAPI.Callback)
		// Weight API
		api.Get("/weight", weightAPI.All)
		api.Post("/weight", weightAPI.Put)
		api.Put("/weight", weightAPI.Put)
		api.Delete("/weight/:id", weightAPI.Delete)
	})

	// Static pages
	router.Use(martini.Static(path.Join(executableFolder(), "webapp")))

	if conf.Marathon.UseEventStream {
		// Listen events stream from Marathon
		listenToMarathonEventStream(conf, eventSubAPI)
	} else {
		registerMarathonEvent(conf)
	}
	router.RunOnAddr(serverBindPort)
}