// InstallDefaultHandlers registers the default set of supported HTTP request // patterns with the restful Container. func (s *Server) InstallDefaultHandlers() { healthz.InstallHandler(s.restfulCont, healthz.PingHealthz, healthz.NamedCheck("syncloop", s.syncLoopHealthCheck), healthz.NamedCheck("pleg", s.plegHealthCheck), ) var ws *restful.WebService ws = new(restful.WebService) ws. Path("/pods"). Produces(restful.MIME_JSON) ws.Route(ws.GET(""). To(s.getPods). Operation("getPods")) s.restfulCont.Add(ws) s.restfulCont.Add(stats.CreateHandlers(statsPath, s.host, s.resourceAnalyzer)) s.restfulCont.Handle(metricsPath, prometheus.Handler()) ws = new(restful.WebService) ws. Path(specPath). Produces(restful.MIME_JSON) ws.Route(ws.GET(""). To(s.getSpec). Operation("getSpec"). Writes(cadvisorapi.MachineInfo{})) s.restfulCont.Add(ws) }
// Creates a new HTTP handler that handles all requests to the API of the backend. func CreateApiHandler(client *client.Client) http.Handler { wsContainer := restful.NewContainer() // TODO(bryk): This is for tests only. Replace with real implementation once ready. ws := new(restful.WebService) ws.Path("/api/deploy"). Consumes(restful.MIME_JSON). Produces(restful.MIME_JSON) ws.Route(ws.POST("").To(func(request *restful.Request, response *restful.Response) { cfg := new(DeployAppConfig) if err := request.ReadEntity(cfg); err != nil { HandleInternalError(response, err) return } if err := DeployApp(cfg, client); err != nil { HandleInternalError(response, err) return } response.WriteHeaderAndEntity(http.StatusCreated, cfg) }).Reads(DeployAppConfig{}).Writes(DeployAppConfig{})) wsContainer.Add(ws) return wsContainer }
func (a *Api) Register(container *restful.Container) { ws := new(restful.WebService) ws.Path("/apis/metrics/v1alpha1"). Doc("Root endpoint of metrics API"). Produces(restful.MIME_JSON) ws.Route(ws.GET("/nodes/"). To(a.nodeMetricsList). Doc("Get a list of metrics for all available nodes."). Operation("nodeMetricsList")) ws.Route(ws.GET("/nodes/{node-name}/"). To(a.nodeMetrics). Doc("Get a list of all available metrics for the specified node."). Operation("nodeMetrics"). Param(ws.PathParameter("node-name", "The name of the node to lookup").DataType("string"))) ws.Route(ws.GET("/namespaces/{namespace-name}/pods/"). To(a.podMetricsList). Doc("Get a list of metrics for all available pods in the specified namespace."). Operation("podMetricsList"). Param(ws.PathParameter("namespace-name", "The name of the namespace to lookup").DataType("string"))). Param(ws.QueryParameter("labelSelector", "A selector to restrict the list of returned objects by their labels. Defaults to everything.").DataType("string")) ws.Route(ws.GET("/namespaces/{namespace-name}/pods/{pod-name}/"). To(a.podMetrics). Doc("Get metrics for the specified pod in the specified namespace."). Operation("podMetrics"). Param(ws.PathParameter("namespace-name", "The name of the namespace to lookup").DataType("string")). Param(ws.PathParameter("pod-name", "The name of the pod to lookup").DataType("string"))) container.Add(ws) }
// InstallDefaultHandlers registers the default set of supported HTTP request // patterns with the restful Container. func (s *Server) InstallDefaultHandlers() { healthz.InstallHandler(s.restfulCont, healthz.PingHealthz, healthz.NamedCheck("syncloop", s.syncLoopHealthCheck), ) var ws *restful.WebService ws = new(restful.WebService) ws. Path("/pods"). Produces(restful.MIME_JSON) ws.Route(ws.GET(""). To(s.getPods). Operation("getPods")) s.restfulCont.Add(ws) s.restfulCont.Handle("/stats/", &httpHandler{f: s.handleStats}) s.restfulCont.Handle("/metrics", prometheus.Handler()) ws = new(restful.WebService) ws. Path("/spec/"). Produces(restful.MIME_JSON) ws.Route(ws.GET(""). To(s.getSpec). Operation("getSpec"). Writes(cadvisorapi.MachineInfo{})) s.restfulCont.Add(ws) }
// Creates a new HTTP handler that handles all requests to the API of the backend. func CreateHttpApiHandler(client *client.Client) http.Handler { apiHandler := ApiHandler{client} wsContainer := restful.NewContainer() deployWs := new(restful.WebService) deployWs.Path("/api/deploy"). Consumes(restful.MIME_JSON). Produces(restful.MIME_JSON) deployWs.Route( deployWs.POST(""). To(apiHandler.handleDeploy). Reads(AppDeployment{}). Writes(AppDeployment{})) wsContainer.Add(deployWs) microserviceListWs := new(restful.WebService) microserviceListWs.Path("/api/microservice"). Produces(restful.MIME_JSON) microserviceListWs.Route( microserviceListWs.GET(""). To(apiHandler.handleGetMicroserviceList). Writes(MicroserviceList{})) wsContainer.Add(microserviceListWs) return wsContainer }
// Register the mainApi on the specified endpoint. func (a *Api) Register(container *restful.Container) { ws := new(restful.WebService) ws.Path("/api/v1/metric-export"). Doc("Exports the latest point for all Heapster metrics"). Produces(restful.MIME_JSON) ws.Route(ws.GET(""). To(a.exportMetrics). Doc("export the latest data point for all metrics"). Operation("exportMetrics"). Writes([]*types.Timeseries{})) container.Add(ws) ws = new(restful.WebService) ws.Path("/api/v1/metric-export-schema"). Doc("Schema for metrics exported by heapster"). Produces(restful.MIME_JSON) ws.Route(ws.GET(""). To(a.exportMetricsSchema). Doc("export the schema for all metrics"). Operation("exportmetricsSchema"). Writes(types.TimeseriesSchema{})) container.Add(ws) if a.metricSink != nil { a.RegisterModel(container) } if a.historicalSource != nil { a.RegisterHistorical(container) } }
// initOAuthAuthorizationServerMetadataRoute initializes an HTTP endpoint for OAuth 2.0 Authorization Server Metadata discovery // https://tools.ietf.org/id/draft-ietf-oauth-discovery-04.html#rfc.section.2 // masterPublicURL should be internally and externally routable to allow all users to discover this information func initOAuthAuthorizationServerMetadataRoute(apiContainer *genericmux.APIContainer, path, masterPublicURL string) { // Build OAuth metadata once metadata, err := json.MarshalIndent(discovery.Get(masterPublicURL, OpenShiftOAuthAuthorizeURL(masterPublicURL), OpenShiftOAuthTokenURL(masterPublicURL)), "", " ") if err != nil { glog.Errorf("Unable to initialize OAuth authorization server metadata route: %v", err) return } secretContainer := restful.Container{ ServeMux: apiContainer.SecretRoutes.(*http.ServeMux), // we know it's a *http.ServeMux. In kube 1.6, the type will actually be correct. } // Set up a service to return the OAuth metadata. ws := new(restful.WebService) ws.Path(path) ws.Doc("OAuth 2.0 Authorization Server Metadata") ws.Route( ws.GET("/").To(func(_ *restful.Request, resp *restful.Response) { writeJSON(resp, metadata) }). Doc("get the server's OAuth 2.0 Authorization Server Metadata"). Operation("getOAuthAuthorizationServerMetadata"). Produces(restful.MIME_JSON)) secretContainer.Add(ws) }
// RegisterHistorical registers the Historical API endpoints. It will register the same endpoints // as those in the model API, plus endpoints for aggregation retrieval, and endpoints to retrieve pod // metrics by using the pod id. func (normalApi *Api) RegisterHistorical(container *restful.Container) { ws := new(restful.WebService) ws.Path("/api/v1/historical"). Doc("Root endpoint of the historical access API"). Consumes("*/*"). Produces(restful.MIME_JSON) a := &HistoricalApi{normalApi} addClusterMetricsRoutes(a, ws) addAggregationRoutes(a, ws) // register the endpoint for fetching raw metrics based on pod id if a.isRunningInKubernetes() { // The /pod-id/{pod-id}/metrics-aggregated/{aggregations}/{metric-name} endpoint exposes // some aggregations for a Pod entity of the historical API. ws.Route(ws.GET("/pod-id/{pod-id}/metrics/{metric-name:*}"). To(metrics.InstrumentRouteFunc("podMetrics", a.podMetrics)). Doc("Export some pod-level metric aggregations"). Operation("podAggregations"). Param(ws.PathParameter("pod-id", "The UID of the pod to lookup").DataType("string")). Param(ws.PathParameter("metric-name", "The name of the requested metric").DataType("string")). Param(ws.QueryParameter("start", "Start time for requested metrics").DataType("string")). Param(ws.QueryParameter("end", "End time for requested metric").DataType("string")). Writes(types.MetricResult{})) // The /pod-id/{pod-id}/containers/{container-name}/metrics-aggregated/{aggregations}/{metric-name} endpoint exposes // some aggregations for a Container entity of the historical API. ws.Route(ws.GET("/pod-id/{pod-id}/containers/{container-name}/metrics/{metric-name:*}"). To(metrics.InstrumentRouteFunc("podContainerMetrics", a.podContainerMetrics)). Doc("Export some aggregations for a Pod Container"). Operation("podContainerAggregations"). Param(ws.PathParameter("pod-id", "The uid of the pod to use").DataType("string")). Param(ws.PathParameter("container-name", "The name of the namespace to use").DataType("string")). Param(ws.PathParameter("metric-name", "The name of the requested metric").DataType("string")). Param(ws.QueryParameter("start", "Start time for requested metrics").DataType("string")). Param(ws.QueryParameter("end", "End time for requested metric").DataType("string")). Writes(types.MetricResult{})) // The /pod-id-list/{pod-id-list}/metrics-aggregated/{aggregations}/{metric-name} endpoint exposes // metrics for a list of pod ids of the historical API. ws.Route(ws.GET("/pod-id-list/{pod-id-list}/metrics/{metric-name:*}"). To(metrics.InstrumentRouteFunc("podListAggregations", a.podListMetrics)). Doc("Export an aggregation for all pods from the given list"). Operation("podListAggregations"). Param(ws.PathParameter("pod-id-list", "Comma separated list of pod UIDs to lookup").DataType("string")). Param(ws.PathParameter("metric-name", "The name of the requested metric").DataType("string")). Param(ws.QueryParameter("start", "Start time for requested metrics").DataType("string")). Param(ws.QueryParameter("end", "End time for requested metric").DataType("string")). Writes(types.MetricResultList{})) } container.Add(ws) }
func NewWebService() *restful.WebService { ws := restful.WebService{} ws.Path("/api/v1"). Consumes(restful.MIME_JSON). Produces(restful.MIME_JSON, restful.MIME_XML) ws.Route(ws.POST("/artists").To(createArtist). Doc("Create a new Arist"). Reads(ArtistRequest{})) ws.Route(ws.POST("/artists/{artist-id}/patrons").To(patronize). Doc("Patronize an artist"). Param(ws.BodyParameter("artist-id", "artist identifier").DataType("int")). Reads(PatronageRequest{})) return &ws }
// initReadinessCheckRoute initializes an HTTP endpoint for readiness checking func initVersionRoute(container *restful.Container, path string) { // Set up a service to return the git code version. versionWS := new(restful.WebService) versionWS.Path(path) versionWS.Doc("git code version from which this is built") versionWS.Route( versionWS.GET("/").To(handleVersion). Doc("get the code version"). Operation("getCodeVersion"). Produces(restful.MIME_JSON). Consumes(restful.MIME_JSON)) container.Add(versionWS) }
func main() { port := env.StringDefault("PORT", "8080") baseUrl := ":" + port var ws restful.WebService ws.Path("/api"). Consumes(restful.MIME_JSON). Produces(restful.MIME_JSON) ws.Route(ws.GET("/bar").To(getBar). Writes(Bar{})) ws.Route(ws.GET("/foo").To(getFoo). Writes(Foo{})) restful.Add(&ws) log.Printf("Starting webserver on %v...", baseUrl) log.Fatal(http.ListenAndServe(baseUrl, nil)) }
// RegisterModel registers the Model API endpoints. // All endpoints that end with a {metric-name} also receive a start time query parameter. // The start and end times should be specified as a string, formatted according to RFC 3339. func (a *Api) RegisterModel(container *restful.Container) { ws := new(restful.WebService) ws.Path("/api/v1/model"). Doc("Root endpoint of the stats model"). Consumes("*/*"). Produces(restful.MIME_JSON) addClusterMetricsRoutes(a, ws) ws.Route(ws.GET("/debug/allkeys"). To(metrics.InstrumentRouteFunc("debugAllKeys", a.allKeys)). Doc("Get keys of all metric sets available"). Operation("debugAllKeys")) container.Add(ws) }
// RegisterMetrics registers the Metrics API endpoints. // All endpoints that end with a {metric-name} also receive a start time query parameter. // The start and end times should be specified as a string, formatted according to RFC 3339. // These apis are experimental, so they may change or disappear in the future. func (a *Api) RegisterMetrics(container *restful.Container) { ws := new(restful.WebService) ws. Path("/experimental/v2"). Doc("Root endpoint of the stats model"). Consumes("*/*"). Produces(restful.MIME_JSON) ws.Route(ws.GET("/nodeMetrics/derived/"). To(a.derivedNodeMetricsList). Filter(compressionFilter). Doc("Get a list of all available metrics for all nodes"). Writes([]types.DerivedNodeMetrics{}). Operation("derivedNodeMetricsList")) ws.Route(ws.GET("/nodeMetrics/derived/{node-name}"). To(a.derivedNodeMetrics). Filter(compressionFilter). Doc("Get a list of all raw metrics for a Node entity"). Writes(types.DerivedNodeMetrics{}). Operation("derivedNodeMetrics"). Param(ws.PathParameter("node-name", "The name of the node to look up").DataType("string"))) container.Add(ws) }
// Register the Api on the specified endpoint. func (a *Api) Register(container *restful.Container) { ws := new(restful.WebService) ws. Path("/api/v1/metric-export"). Doc("Exports the latest point for all Heapster metrics"). Produces(restful.MIME_JSON) ws.Route(ws.GET(""). Filter(compressionFilter). To(a.exportMetrics). Doc("export the latest data point for all metrics"). Operation("exportMetrics"). Writes([]*Timeseries{})) container.Add(ws) ws = new(restful.WebService) ws.Path("/api/v1/metric-export-schema"). Doc("Schema for metrics exported by heapster"). Produces(restful.MIME_JSON) ws.Route(ws.GET(""). To(a.exportMetricsSchema). Doc("export the schema for all metrics"). Operation("exportmetricsSchema"). Writes(TimeseriesSchema{})) container.Add(ws) ws = new(restful.WebService) ws.Path("/api/v1/sinks"). Doc("Configuration for Heapster sinks for exporting data"). Produces(restful.MIME_JSON) ws.Route(ws.POST(""). To(a.setSinks). Doc("set the current sinks"). Operation("setSinks"). Reads([]string{})) ws.Route(ws.GET(""). To(a.getSinks). Doc("get the current sinks"). Operation("getSinks"). Writes([]string{})) container.Add(ws) // Register the endpoints of the model a.RegisterModel(container) }
// initOAuthAuthorizationServerMetadataRoute initializes an HTTP endpoint for OAuth 2.0 Authorization Server Metadata discovery // https://tools.ietf.org/id/draft-ietf-oauth-discovery-04.html#rfc.section.2 // masterPublicURL should be internally and externally routable to allow all users to discover this information func initOAuthAuthorizationServerMetadataRoute(container *restful.Container, path, masterPublicURL string) { // Build OAuth metadata once metadata, err := json.MarshalIndent(discovery.Get(masterPublicURL, OpenShiftOAuthAuthorizeURL(masterPublicURL), OpenShiftOAuthTokenURL(masterPublicURL)), "", " ") if err != nil { glog.Errorf("Unable to initialize OAuth authorization server metadata route: %v", err) return } // Set up a service to return the OAuth metadata. oauthWS := new(restful.WebService) oauthWS.Path(path) oauthWS.Doc("OAuth 2.0 Authorization Server Metadata") oauthWS.Route( oauthWS.GET("/").To(func(_ *restful.Request, resp *restful.Response) { writeJSON(resp, metadata) }). Doc("get the server's OAuth 2.0 Authorization Server Metadata"). Operation("getOAuthAuthorizationServerMetadata"). Produces(restful.MIME_JSON)) container.Add(oauthWS) }
// initVersionRoute initializes an HTTP endpoint for the server's version information. func initVersionRoute(container *restful.Container, path string) { // Build version info once versionInfo, err := json.MarshalIndent(version.Get(), "", " ") if err != nil { glog.Errorf("Unable to initialize version route: %v", err) return } // Set up a service to return the git code version. versionWS := new(restful.WebService) versionWS.Path(path) versionWS.Doc("git code version from which this is built") versionWS.Route( versionWS.GET("/").To(func(_ *restful.Request, resp *restful.Response) { writeJSON(resp, versionInfo) }). Doc("get the code version"). Operation("getCodeVersion"). Produces(restful.MIME_JSON)) container.Add(versionWS) }
func register(container *restful.Container) { restful.RegisterEntityAccessor(MIME_MSGPACK, NewEntityAccessorMsgPack()) ws := new(restful.WebService) ws. Path("/test"). Consumes(restful.MIME_JSON, MIME_MSGPACK). Produces(restful.MIME_JSON, MIME_MSGPACK) // route user api ws.Route(ws.POST("/msgpack"). To(do). Reads(user{}). Writes(userResponse{})) container.Add(ws) }
func main() { ws := new(restful.WebService) ws.Path("/itrain").Consumes(restful.MIME_JSON).Produces(restful.MIME_JSON) ws.Route(ws.GET("/version"). To(report_version). Doc("get itrain version number"). Operation("version")) ws.Route(ws.GET("/report_inverter"). To(report_inverter). Doc("get inverter report data"). Operation("report_inverter"). Param(ws.QueryParameter("sd", "startdate"))) restful.Add(ws) config := swagger.Config{ WebServices: restful.DefaultContainer.RegisteredWebServices(), // you control what services are visible WebServicesUrl: "/", ApiPath: "/apidocs.json", // specifiy where the UI is located SwaggerPath: "/apidocs/", SwaggerFilePath: "./swaggerui"} swagger.RegisterSwaggerService(config, restful.DefaultContainer) var ( hostname string = "127.0.0.1" port int = 8080 ) // Listen on hostname:port fmt.Printf("Listening on %s:%d...\n", hostname, port) err := http.ListenAndServe(fmt.Sprintf("%s:%d", hostname, port), nil) if err != nil { log.Fatal("Error: ", err) } }
// Register the Api on the specified endpoint. func (a *Api) Register(container *restful.Container) { ws := new(restful.WebService) ws. Path("/api/v1/metric-export"). Doc("Exports the latest point for all Heapster metrics"). Produces(restful.MIME_JSON) ws.Route(ws.GET(""). Filter(compressionFilter). To(a.exportMetrics). Doc("export the latest data point for all metrics"). Operation("exportMetrics"). Writes([]*Timeseries{})) container.Add(ws) ws = new(restful.WebService) ws.Path("/api/v1/metric-export-schema"). Doc("Schema for metrics exported by heapster"). Produces(restful.MIME_JSON) ws.Route(ws.GET(""). To(a.exportMetricsSchema). Doc("export the schema for all metrics"). Operation("exportmetricsSchema"). Writes(TimeseriesSchema{})) container.Add(ws) }
// Creates a new HTTP handler that handles all requests to the API of the backend. func CreateHttpApiHandler(client *client.Client) http.Handler { apiHandler := ApiHandler{client} wsContainer := restful.NewContainer() deployWs := new(restful.WebService) deployWs.Path("/api/appdeployments"). Consumes(restful.MIME_JSON). Produces(restful.MIME_JSON) deployWs.Route( deployWs.POST(""). To(apiHandler.handleDeploy). Reads(AppDeployment{}). Writes(AppDeployment{})) wsContainer.Add(deployWs) replicaSetWs := new(restful.WebService) replicaSetWs.Path("/api/replicasets"). Produces(restful.MIME_JSON) replicaSetWs.Route( replicaSetWs.GET(""). To(apiHandler.handleGetReplicaSetList). Writes(ReplicaSetList{})) replicaSetWs.Route( replicaSetWs.GET("/{namespace}/{replicaSet}"). To(apiHandler.handleGetReplicaSetDetail). Writes(ReplicaSetDetail{})) wsContainer.Add(replicaSetWs) namespaceListWs := new(restful.WebService) namespaceListWs.Path("/api/namespaces"). Produces(restful.MIME_JSON) namespaceListWs.Route( namespaceListWs.GET(""). To(apiHandler.handleGetNamespaceList). Writes(NamespacesList{})) wsContainer.Add(namespaceListWs) return wsContainer }
// Creates a new HTTP handler that handles all requests to the API of the backend. func CreateHttpApiHandler(client *client.Client, heapsterClient HeapsterClient, clientConfig clientcmd.ClientConfig) http.Handler { apiHandler := ApiHandler{client, heapsterClient, clientConfig} wsContainer := restful.NewContainer() deployWs := new(restful.WebService) deployWs.Filter(wsLogger) deployWs.Path("/api/v1/appdeployments"). Consumes(restful.MIME_JSON). Produces(restful.MIME_JSON) deployWs.Route( deployWs.POST(""). To(apiHandler.handleDeploy). Reads(AppDeploymentSpec{}). Writes(AppDeploymentSpec{})) deployWs.Route( deployWs.POST("/validate/name"). To(apiHandler.handleNameValidity). Reads(AppNameValiditySpec{}). Writes(AppNameValidity{})) deployWs.Route( deployWs.POST("/validate/protocol"). To(apiHandler.handleProtocolValidity). Reads(ProtocolValiditySpec{}). Writes(ProtocolValidity{})) deployWs.Route( deployWs.GET("/protocols"). To(apiHandler.handleGetAvailableProcotols). Writes(Protocols{})) wsContainer.Add(deployWs) deployFromFileWs := new(restful.WebService) deployFromFileWs.Path("/api/v1/appdeploymentfromfile"). Consumes(restful.MIME_JSON). Produces(restful.MIME_JSON) deployFromFileWs.Route( deployFromFileWs.POST(""). To(apiHandler.handleDeployFromFile). Reads(AppDeploymentFromFileSpec{}). Writes(AppDeploymentFromFileResponse{})) wsContainer.Add(deployFromFileWs) replicationControllerWs := new(restful.WebService) replicationControllerWs.Filter(wsLogger) replicationControllerWs.Path("/api/v1/replicationcontrollers"). Consumes(restful.MIME_JSON). Produces(restful.MIME_JSON) replicationControllerWs.Route( replicationControllerWs.GET(""). To(apiHandler.handleGetReplicationControllerList). Writes(ReplicationControllerList{})) replicationControllerWs.Route( replicationControllerWs.GET("/{namespace}/{replicationController}"). To(apiHandler.handleGetReplicationControllerDetail). Writes(ReplicationControllerDetail{})) replicationControllerWs.Route( replicationControllerWs.POST("/{namespace}/{replicationController}/update/pods"). To(apiHandler.handleUpdateReplicasCount). Reads(ReplicationControllerSpec{})) replicationControllerWs.Route( replicationControllerWs.DELETE("/{namespace}/{replicationController}"). To(apiHandler.handleDeleteReplicationController)) replicationControllerWs.Route( replicationControllerWs.GET("/pods/{namespace}/{replicationController}"). To(apiHandler.handleGetReplicationControllerPods). Writes(ReplicationControllerPods{})) wsContainer.Add(replicationControllerWs) namespacesWs := new(restful.WebService) namespacesWs.Filter(wsLogger) namespacesWs.Path("/api/v1/namespaces"). Consumes(restful.MIME_JSON). Produces(restful.MIME_JSON) namespacesWs.Route( namespacesWs.POST(""). To(apiHandler.handleCreateNamespace). Reads(NamespaceSpec{}). Writes(NamespaceSpec{})) namespacesWs.Route( namespacesWs.GET(""). To(apiHandler.handleGetNamespaces). Writes(NamespaceList{})) wsContainer.Add(namespacesWs) logsWs := new(restful.WebService) logsWs.Filter(wsLogger) logsWs.Path("/api/v1/logs"). Produces(restful.MIME_JSON) logsWs.Route( logsWs.GET("/{namespace}/{podId}"). To(apiHandler.handleLogs). Writes(Logs{})) logsWs.Route( logsWs.GET("/{namespace}/{podId}/{container}"). To(apiHandler.handleLogs). Writes(Logs{})) wsContainer.Add(logsWs) eventsWs := new(restful.WebService) eventsWs.Filter(wsLogger) eventsWs.Path("/api/v1/events"). Produces(restful.MIME_JSON) eventsWs.Route( eventsWs.GET("/{namespace}/{replicationController}"). To(apiHandler.handleEvents). Writes(Events{})) wsContainer.Add(eventsWs) nodesWs := new(restful.WebService) nodesWs.Path("/api/nodes"). Produces(restful.MIME_JSON) nodesWs.Route( nodesWs.GET(""). To(apiHandler.handleGetNodes). Writes(NodeList{})) nodesWs.Route( nodesWs.GET("/{name}/stats"). To(apiHandler.handleGetNodeStats). Writes(NodeStats{})) wsContainer.Add(nodesWs) secretsWs := new(restful.WebService) secretsWs.Path("/api/v1/secrets").Produces(restful.MIME_JSON) secretsWs.Route( secretsWs.GET("/{namespace}"). To(apiHandler.handleGetSecrets). Writes(SecretsList{})) secretsWs.Route( secretsWs.POST(""). To(apiHandler.handleCreateImagePullSecret). Reads(ImagePullSecretSpec{}). Writes(Secret{})) wsContainer.Add(secretsWs) return wsContainer }
// Creates a new HTTP handler that handles all requests to the API of the backend. func CreateHttpApiHandler(client *client.Client) http.Handler { apiHandler := ApiHandler{client} wsContainer := restful.NewContainer() deployWs := new(restful.WebService) deployWs.Path("/api/appdeployments"). Consumes(restful.MIME_JSON). Produces(restful.MIME_JSON) deployWs.Route( deployWs.POST(""). To(apiHandler.handleDeploy). Reads(AppDeploymentSpec{}). Writes(AppDeploymentSpec{})) deployWs.Route( deployWs.POST("/validate/name"). To(apiHandler.handleNameValidity). Reads(AppNameValiditySpec{}). Writes(AppNameValidity{})) wsContainer.Add(deployWs) replicaSetWs := new(restful.WebService) replicaSetWs.Path("/api/replicasets"). Consumes(restful.MIME_JSON). Produces(restful.MIME_JSON) replicaSetWs.Route( replicaSetWs.GET(""). To(apiHandler.handleGetReplicaSetList). Writes(ReplicaSetList{})) replicaSetWs.Route( replicaSetWs.GET("/{namespace}/{replicaSet}"). To(apiHandler.handleGetReplicaSetDetail). Writes(ReplicaSetDetail{})) replicaSetWs.Route( replicaSetWs.POST("/{namespace}/{replicaSet}/update/pods"). To(apiHandler.handleUpdateReplicasCount). Reads(ReplicaSetSpec{})) replicaSetWs.Route( replicaSetWs.DELETE("/{namespace}/{replicaSet}"). To(apiHandler.handleDeleteReplicaSet)) replicaSetWs.Route( replicaSetWs.GET("/pods/{namespace}/{replicaSet}"). To(apiHandler.handleGetReplicaSetPods). Writes(ReplicaSetPods{})) wsContainer.Add(replicaSetWs) namespacesWs := new(restful.WebService) namespacesWs.Path("/api/namespaces"). Consumes(restful.MIME_JSON). Produces(restful.MIME_JSON) namespacesWs.Route( namespacesWs.POST(""). To(apiHandler.handleCreateNamespace). Reads(NamespaceSpec{}). Writes(NamespaceSpec{})) namespacesWs.Route( namespacesWs.GET(""). To(apiHandler.handleGetNamespaces). Writes(NamespaceList{})) wsContainer.Add(namespacesWs) logsWs := new(restful.WebService) logsWs.Path("/api/logs"). Produces(restful.MIME_JSON) logsWs.Route( logsWs.GET("/{namespace}/{podId}/{container}"). To(apiHandler.handleLogs). Writes(Logs{})) wsContainer.Add(logsWs) eventsWs := new(restful.WebService) eventsWs.Path("/api/events"). Produces(restful.MIME_JSON) eventsWs.Route( eventsWs.GET("/{namespace}/{replicaSet}"). To(apiHandler.handleEvents). Writes(Events{})) wsContainer.Add(eventsWs) return wsContainer }
// InstallDeguggingHandlers registers the HTTP request patterns that serve logs or run commands/containers func (s *Server) InstallDebuggingHandlers() { var ws *restful.WebService ws = new(restful.WebService) ws. Path("/run") ws.Route(ws.POST("/{podNamespace}/{podID}/{containerName}"). To(s.getRun). Operation("getRun")) ws.Route(ws.POST("/{podNamespace}/{podID}/{uid}/{containerName}"). To(s.getRun). Operation("getRun")) s.restfulCont.Add(ws) ws = new(restful.WebService) ws. Path("/exec") ws.Route(ws.GET("/{podNamespace}/{podID}/{containerName}"). To(s.getExec). Operation("getExec")) ws.Route(ws.POST("/{podNamespace}/{podID}/{containerName}"). To(s.getExec). Operation("getExec")) ws.Route(ws.GET("/{podNamespace}/{podID}/{uid}/{containerName}"). To(s.getExec). Operation("getExec")) ws.Route(ws.POST("/{podNamespace}/{podID}/{uid}/{containerName}"). To(s.getExec). Operation("getExec")) s.restfulCont.Add(ws) ws = new(restful.WebService) ws. Path("/attach") ws.Route(ws.GET("/{podNamespace}/{podID}/{containerName}"). To(s.getAttach). Operation("getAttach")) ws.Route(ws.POST("/{podNamespace}/{podID}/{containerName}"). To(s.getAttach). Operation("getAttach")) ws.Route(ws.GET("/{podNamespace}/{podID}/{uid}/{containerName}"). To(s.getAttach). Operation("getAttach")) ws.Route(ws.POST("/{podNamespace}/{podID}/{uid}/{containerName}"). To(s.getAttach). Operation("getAttach")) s.restfulCont.Add(ws) ws = new(restful.WebService) ws. Path("/portForward") ws.Route(ws.POST("/{podNamespace}/{podID}"). To(s.getPortForward). Operation("getPortForward")) ws.Route(ws.POST("/{podNamespace}/{podID}/{uid}"). To(s.getPortForward). Operation("getPortForward")) s.restfulCont.Add(ws) ws = new(restful.WebService) ws. Path("/logs/") ws.Route(ws.GET(""). To(s.getLogs). Operation("getLogs")) ws.Route(ws.GET("/{logpath:*}"). To(s.getLogs). Operation("getLogs")) s.restfulCont.Add(ws) ws = new(restful.WebService) ws. Path("/containerLogs") ws.Route(ws.GET("/{podNamespace}/{podID}/{containerName}"). To(s.getContainerLogs). Operation("getContainerLogs")) s.restfulCont.Add(ws) handlePprofEndpoint := func(req *restful.Request, resp *restful.Response) { name := strings.TrimPrefix(req.Request.URL.Path, pprofBasePath) switch name { case "profile": pprof.Profile(resp, req.Request) case "symbol": pprof.Symbol(resp, req.Request) case "cmdline": pprof.Cmdline(resp, req.Request) default: pprof.Index(resp, req.Request) } } // Setup pporf handlers. ws = new(restful.WebService).Path(pprofBasePath) ws.Route(ws.GET("/{subpath:*}").To(func(req *restful.Request, resp *restful.Response) { handlePprofEndpoint(req, resp) })).Doc("pprof endpoint") s.restfulCont.Add(ws) // The /runningpods endpoint is used for testing only. ws = new(restful.WebService) ws. Path("/runningpods/"). Produces(restful.MIME_JSON) ws.Route(ws.GET(""). To(s.getRunningPods). Operation("getRunningPods")) s.restfulCont.Add(ws) }
// RegisterModel registers the Model API endpoints. // All endpoints that end with a {metric-name} also receive a start time query parameter. // The start and end times should be specified as a string, formatted according to RFC 3339. func (a *Api) RegisterModel(container *restful.Container) { ws := new(restful.WebService) ws. Path("/api/v1/model"). Doc("Root endpoint of the stats model"). Consumes("*/*"). Produces(restful.MIME_JSON) // The / endpoint returns a list of all the entities that are available in the model ws.Route(ws.GET("/"). To(a.allEntities). Filter(compressionFilter). Doc("Get a list of all entities available in the model"). Operation("allEntities")) // The /metrics/ endpoint returns a list of all available metrics for the Cluster entity of the model. ws.Route(ws.GET("/metrics/"). To(a.availableMetrics). Filter(compressionFilter). Doc("Get a list of all available metrics for the Cluster entity"). Operation("availableMetrics")) // The /stats/ endpoint returns a list of all available stats for the Cluster entity of the model. ws.Route(ws.GET("/stats/"). To(a.clusterStats). Filter(compressionFilter). Doc("Get all available stats for the Cluster entity"). Operation("clusterStats")) // The /metrics/{metric-name} endpoint exposes an aggregated metric for the Cluster entity of the model. ws.Route(ws.GET("/metrics/{metric-name}"). To(a.clusterMetrics). Filter(compressionFilter). Doc("Export an aggregated cluster-level metric"). Operation("clusterMetrics"). Param(ws.PathParameter("metric-name", "The name of the requested metric").DataType("string")). Param(ws.QueryParameter("start", "Start time for requested metric").DataType("string")). Param(ws.QueryParameter("end", "End time for requested metric").DataType("string")). Writes(types.MetricResult{})) // The /nodes/ endpoint returns a list of all Node entities in the cluster. ws.Route(ws.GET("/nodes/"). To(a.allNodes). Filter(compressionFilter). Doc("Get a list of all Nodes in the model"). Operation("allNodes"). Writes(types.MetricResult{})) // The /nodes/{node-name} endpoint returns a list of all available API paths for a Node entity. ws.Route(ws.GET("/nodes/{node-name}"). To(a.nodePaths). Filter(compressionFilter). Doc("Get a list of all available API paths for a Node entity"). Operation("nodePaths"). Param(ws.PathParameter("node-name", "The name of the node to lookup").DataType("string"))) // The /nodes/{node-name}/stats endpoint returns all available derived stats for a Node entity. ws.Route(ws.GET("/nodes/{node-name}/stats/"). To(a.nodeStats). Filter(compressionFilter). Doc("Get all available stats for a Node entity."). Operation("nodeStats"). Param(ws.PathParameter("node-name", "The name of the node to lookup").DataType("string"))) // The /nodes/{node-name}/metrics endpoint returns a list of all available metrics for a Node entity. ws.Route(ws.GET("/nodes/{node-name}/metrics/"). To(a.availableMetrics). Filter(compressionFilter). Doc("Get a list of all available metrics for a Node entity"). Operation("availableMetrics"). Param(ws.PathParameter("node-name", "The name of the node to lookup").DataType("string"))) // The /nodes/{node-name}/metrics/{metric-name} endpoint exposes a metric for a Node entity of the model. // The {node-name} parameter is the hostname of a specific node. ws.Route(ws.GET("/nodes/{node-name}/metrics/{metric-name}"). To(a.nodeMetrics). Filter(compressionFilter). Doc("Export a node-level metric"). Operation("nodeMetrics"). Param(ws.PathParameter("node-name", "The name of the node to lookup").DataType("string")). Param(ws.PathParameter("metric-name", "The name of the requested metric").DataType("string")). Param(ws.QueryParameter("start", "Start time for requested metric").DataType("string")). Param(ws.QueryParameter("end", "End time for requested metric").DataType("string")). Writes(types.MetricResult{})) if a.runningInKubernetes { // The /namespaces/ endpoint returns a list of all Namespace entities in the model. ws.Route(ws.GET("/namespaces/"). To(a.allNamespaces). Filter(compressionFilter). Doc("Get a list of all Namespaces in the model"). Operation("allNamespaces")) // The /namespaces/{namespace-name} endpoint returns a list of all available API Paths for a Namespace entity. ws.Route(ws.GET("/namespaces/{namespace-name}"). To(a.namespacePaths). Filter(compressionFilter). Doc("Get a list of all available API paths for a namespace entity"). Operation("namespacePaths"). Param(ws.PathParameter("namespace-name", "The name of the namespace to lookup").DataType("string"))) // The /namespaces/{namespace-name}/stats endpoint returns all available derived stats for a Namespace entity. ws.Route(ws.GET("/namespaces/{namespace-name}/stats/"). To(a.namespaceStats). Filter(compressionFilter). Doc("Get all available stats for a Namespace entity."). Operation("namespaceStats"). Param(ws.PathParameter("namespace-name", "The name of the namespace to lookup").DataType("string"))) // The /namespaces/{namespace-name}/metrics endpoint returns a list of all available metrics for a Namespace entity. ws.Route(ws.GET("/namespaces/{namespace-name}/metrics"). To(a.availableMetrics). Filter(compressionFilter). Doc("Get a list of all available metrics for a Namespace entity"). Operation("availableMetrics"). Param(ws.PathParameter("namespace-name", "The name of the namespace to lookup").DataType("string"))) // The /namespaces/{namespace-name}/metrics/{metric-name} endpoint exposes an aggregated metrics // for a Namespace entity of the model. ws.Route(ws.GET("/namespaces/{namespace-name}/metrics/{metric-name}"). To(a.namespaceMetrics). Filter(compressionFilter). Doc("Export an aggregated namespace-level metric"). Operation("namespaceMetrics"). Param(ws.PathParameter("namespace-name", "The name of the namespace to lookup").DataType("string")). Param(ws.PathParameter("metric-name", "The name of the requested metric").DataType("string")). Param(ws.QueryParameter("start", "Start time for requested metrics").DataType("string")). Param(ws.QueryParameter("end", "End time for requested metric").DataType("string")). Writes(types.MetricResult{})) // The /namespaces/{namespace-name}/pods endpoint returns a list of all Pod entities in the model, // under a specified namespace. ws.Route(ws.GET("/namespaces/{namespace-name}/pods"). To(a.allPods). Filter(compressionFilter). Doc("Get a list of all Pods in the model, belonging to the specified Namespace"). Operation("allPods"). Param(ws.PathParameter("namespace-name", "The name of the namespace to lookup").DataType("string"))) // The /namespaces/{namespace-name}/pods/{pod-name} endpoint returns a list of all // API paths available for a pod ws.Route(ws.GET("/namespaces/{namespace-name}/pods/{pod-name}"). To(a.podPaths). Filter(compressionFilter). Doc("Get a list of all API paths available for a Pod entity"). Operation("podPaths"). Param(ws.PathParameter("namespace-name", "The name of the namespace to lookup").DataType("string")). Param(ws.PathParameter("pod-name", "The name of the pod to lookup").DataType("string"))) // The /namespaces/{namespace-name}/pods/{pod-name}/stats endpoint returns all available derived stats for a Pod entity. ws.Route(ws.GET("/namespaces/{namespace-name}/pods/{pod-name}/stats/"). To(a.podStats). Filter(compressionFilter). Doc("Get all available stats for a Pod entity."). Operation("podStats"). Param(ws.PathParameter("namespace-name", "The name of the namespace to lookup").DataType("string")). Param(ws.PathParameter("pod-name", "The name of the pod to lookup").DataType("string"))) // The /namespaces/{namespace-name}/pods/{pod-name}/metrics endpoint returns a list of all available metrics for a Pod entity. ws.Route(ws.GET("/namespaces/{namespace-name}/pods/{pod-name}/metrics"). To(a.availableMetrics). Filter(compressionFilter). Doc("Get a list of all available metrics for a Pod entity"). Operation("availableMetrics"). Param(ws.PathParameter("namespace-name", "The name of the namespace to lookup").DataType("string")). Param(ws.PathParameter("pod-name", "The name of the pod to lookup").DataType("string"))) // The /namespaces/{namespace-name}/pods/{pod-name}/metrics/{metric-name} endpoint exposes // an aggregated metric for a Pod entity of the model. ws.Route(ws.GET("/namespaces/{namespace-name}/pods/{pod-name}/metrics/{metric-name}"). To(a.podMetrics). Filter(compressionFilter). Doc("Export an aggregated pod-level metric"). Operation("podMetrics"). Param(ws.PathParameter("namespace-name", "The name of the namespace to lookup").DataType("string")). Param(ws.PathParameter("pod-name", "The name of the pod to lookup").DataType("string")). Param(ws.PathParameter("metric-name", "The name of the requested metric").DataType("string")). Param(ws.QueryParameter("start", "Start time for requested metrics").DataType("string")). Param(ws.QueryParameter("end", "End time for requested metric").DataType("string")). Writes(types.MetricResult{})) // The /namespaces/{namespace-name}/pods/{pod-name}/containers endpoint returns a list of all Container entities, // under a specified namespace and pod. ws.Route(ws.GET("/namespaces/{namespace-name}/pods/{pod-name}/containers"). To(a.allPodContainers). Filter(compressionFilter). Doc("Get a list of all Containers in the model, belonging to the specified Namespace and Pod"). Operation("allPodContainers"). Param(ws.PathParameter("namespace-name", "The name of the namespace to lookup").DataType("string")). Param(ws.PathParameter("pod-name", "The name of the pod to lookup").DataType("string"))) // The /namespaces/{namespace-name}/pods/{pod-name}/containers/{container-name} endpoint // returns a list of all API paths available for a Pod Container ws.Route(ws.GET("/namespaces/{namespace-name}/pods/{pod-name}/containers/{container-name}"). To(a.containerPaths). Filter(compressionFilter). Doc("Get a list of all API paths available for a Pod Container entity"). Operation("containerPaths"). Param(ws.PathParameter("namespace-name", "The name of the namespace to lookup").DataType("string")). Param(ws.PathParameter("pod-name", "The name of the pod to lookup").DataType("string")). Param(ws.PathParameter("container-name", "The name of the namespace to use").DataType("string"))) // The /namespaces/{namespace-name}/pods/{pod-name}/containers/{container-name}/stats endpoint returns derived stats for a Pod Container entity. ws.Route(ws.GET("/namespaces/{namespace-name}/pods/{pod-name}/containers/{container-name}/stats/"). To(a.podContainerStats). Filter(compressionFilter). Doc("Get all available stats for a Pod Container entity."). Operation("podContainerStats"). Param(ws.PathParameter("namespace-name", "The name of the namespace to lookup").DataType("string")). Param(ws.PathParameter("pod-name", "The name of the pod to lookup").DataType("string")). Param(ws.PathParameter("container-name", "The name of the namespace to use").DataType("string"))) // The /namespaces/{namespace-name}/pods/{pod-name}/containers/metrics/{container-name}/metrics endpoint // returns a list of all available metrics for a Pod Container entity. ws.Route(ws.GET("/namespaces/{namespace-name}/pods/{pod-name}/containers/{container-name}/metrics"). To(a.availableMetrics). Filter(compressionFilter). Doc("Get a list of all available metrics for a Pod entity"). Operation("availableMetrics"). Param(ws.PathParameter("namespace-name", "The name of the namespace to lookup").DataType("string")). Param(ws.PathParameter("pod-name", "The name of the pod to lookup").DataType("string")). Param(ws.PathParameter("container-name", "The name of the namespace to use").DataType("string"))) // The /namespaces/{namespace-name}/pods/{pod-name}/containers/{container-name}/metrics/{metric-name} endpoint exposes // a metric for a Container entity of the model. ws.Route(ws.GET("/namespaces/{namespace-name}/pods/{pod-name}/containers/{container-name}/metrics/{metric-name}"). To(a.podContainerMetrics). Filter(compressionFilter). Doc("Export an aggregated metric for a Pod Container"). Operation("podContainerMetrics"). Param(ws.PathParameter("namespace-name", "The name of the namespace to use").DataType("string")). Param(ws.PathParameter("pod-name", "The name of the pod to use").DataType("string")). Param(ws.PathParameter("container-name", "The name of the namespace to use").DataType("string")). Param(ws.PathParameter("metric-name", "The name of the requested metric").DataType("string")). Param(ws.QueryParameter("start", "Start time for requested metrics").DataType("string")). Param(ws.QueryParameter("end", "End time for requested metric").DataType("string")). Writes(types.MetricResult{})) // The /nodes/{node-name}/pods/ endpoint returns a list of all Pods entities under a specified node. ws.Route(ws.GET("/nodes/{node-name}/pods/"). To(a.nodePods). Filter(compressionFilter). Doc("Get a list of all Pods belonging to a specified Node in the model"). Operation("nodePods"). Param(ws.PathParameter("node-name", "The name of the namespace to lookup").DataType("string"))) } // The /nodes/{node-name}/freecontainers/ endpoint returns a list of all free Container entities, // under a specified node. ws.Route(ws.GET("/nodes/{node-name}/freecontainers/"). To(a.allFreeContainers). Filter(compressionFilter). Doc("Get a list of all free Containers in the model, belonging to the specified Node"). Operation("allFreeContainers"). Param(ws.PathParameter("node-name", "The name of the namespace to lookup").DataType("string"))) // The /nodes/{node-name}/freecontainers/{container-name}/ endpoint exposes // the available subpaths for a free container ws.Route(ws.GET("/nodes/{node-name}/freecontainers/{container-name}/"). To(a.containerPaths). Filter(compressionFilter). Doc("Get a list of API paths for a free Container entity"). Operation("freeContainerMetrics"). Param(ws.PathParameter("node-name", "The name of the node to use").DataType("string")). Param(ws.PathParameter("container-name", "The name of the container to use").DataType("string")). Writes(types.MetricResult{})) // The /nodes/{node-name}/freecontainers/{container-name}/stats endpoint returns derived stats for a Free Container entity. ws.Route(ws.GET("/nodes/{node-name}/freecontainers/{container-name}/stats"). To(a.freeContainerStats). Filter(compressionFilter). Doc("Get all available stats for a Free Container entity."). Operation("freeContainerStats"). Param(ws.PathParameter("node-name", "The name of the namespace to lookup").DataType("string")). Param(ws.PathParameter("container-name", "The name of the namespace to use").DataType("string"))) // The /nodes/{node-name}/freecontainers/{container-name}/metrics endpoint // returns a list of all available metrics for a Free Container entity. ws.Route(ws.GET("/nodes/{node-name}/freecontainers/{container-name}/metrics"). To(a.availableMetrics). Filter(compressionFilter). Doc("Get a list of all available metrics for a free Container entity"). Operation("availableMetrics"). Param(ws.PathParameter("node-name", "The name of the namespace to lookup").DataType("string")). Param(ws.PathParameter("container-name", "The name of the namespace to use").DataType("string"))) // The /nodes/{node-name}/freecontainers/{container-name}/metrics/{metric-name} endpoint exposes // a metric for a free Container entity of the model. ws.Route(ws.GET("/nodes/{node-name}/freecontainers/{container-name}/metrics/{metric-name}"). To(a.freeContainerMetrics). Filter(compressionFilter). Doc("Export a container-level metric for a free container"). Operation("freeContainerMetrics"). Param(ws.PathParameter("node-name", "The name of the node to use").DataType("string")). Param(ws.PathParameter("container-name", "The name of the container to use").DataType("string")). Param(ws.PathParameter("metric-name", "The name of the requested metric").DataType("string")). Param(ws.QueryParameter("start", "Start time for requested metrics").DataType("string")). Param(ws.QueryParameter("end", "End time for requested metric").DataType("string")). Writes(types.MetricResult{})) if a.runningInKubernetes { // The /namespaces/{namespace-name}/pod-list/{pod-list}/metrics/{metric-name} endpoint exposes // metrics for a list od pods of the model. ws.Route(ws.GET("/namespaces/{namespace-name}/pod-list/{pod-list}/metrics/{metric-name}"). To(a.podListMetrics). Filter(compressionFilter). Doc("Export a metric for all pods from the given list"). Operation("podListMetric"). Param(ws.PathParameter("namespace-name", "The name of the namespace to lookup").DataType("string")). Param(ws.PathParameter("pod-list", "Comma separated list of pod names to lookup").DataType("string")). Param(ws.PathParameter("metric-name", "The name of the requested metric").DataType("string")). Param(ws.QueryParameter("start", "Start time for requested metrics").DataType("string")). Param(ws.QueryParameter("end", "End time for requested metric").DataType("string")). Writes(types.MetricResult{})) } container.Add(ws) }
// CreateHttpApiHandler creates a new HTTP handler that handles all requests to the API of the backend. func CreateHttpApiHandler(client *client.Client, heapsterClient HeapsterClient, clientConfig clientcmd.ClientConfig) http.Handler { verber := common.NewResourceVerber(client.RESTClient, client.ExtensionsClient.RESTClient, client.AppsClient.RESTClient, client.BatchClient.RESTClient) apiHandler := ApiHandler{client, heapsterClient, clientConfig, verber} wsContainer := restful.NewContainer() apiV1Ws := new(restful.WebService) apiV1Ws.Filter(wsLogger) apiV1Ws.Path("/api/v1"). Consumes(restful.MIME_JSON). Produces(restful.MIME_JSON) wsContainer.Add(apiV1Ws) apiV1Ws.Route( apiV1Ws.POST("/appdeployment"). To(apiHandler.handleDeploy). Reads(AppDeploymentSpec{}). Writes(AppDeploymentSpec{})) apiV1Ws.Route( apiV1Ws.POST("/appdeployment/validate/name"). To(apiHandler.handleNameValidity). Reads(AppNameValiditySpec{}). Writes(AppNameValidity{})) apiV1Ws.Route( apiV1Ws.POST("/appdeployment/validate/imagereference"). To(apiHandler.handleImageReferenceValidity). Reads(ImageReferenceValiditySpec{}). Writes(ImageReferenceValidity{})) apiV1Ws.Route( apiV1Ws.POST("/appdeployment/validate/protocol"). To(apiHandler.handleProtocolValidity). Reads(ProtocolValiditySpec{}). Writes(ProtocolValidity{})) apiV1Ws.Route( apiV1Ws.GET("/appdeployment/protocols"). To(apiHandler.handleGetAvailableProcotols). Writes(Protocols{})) apiV1Ws.Route( apiV1Ws.POST("/appdeploymentfromfile"). To(apiHandler.handleDeployFromFile). Reads(AppDeploymentFromFileSpec{}). Writes(AppDeploymentFromFileResponse{})) apiV1Ws.Route( apiV1Ws.GET("/replicationcontroller"). To(apiHandler.handleGetReplicationControllerList). Writes(ReplicationControllerList{})) apiV1Ws.Route( apiV1Ws.GET("/replicationcontroller/{namespace}"). To(apiHandler.handleGetReplicationControllerList). Writes(ReplicationControllerList{})) apiV1Ws.Route( apiV1Ws.GET("/replicationcontroller/{namespace}/{replicationController}"). To(apiHandler.handleGetReplicationControllerDetail). Writes(ReplicationControllerDetail{})) apiV1Ws.Route( apiV1Ws.POST("/replicationcontroller/{namespace}/{replicationController}/update/pod"). To(apiHandler.handleUpdateReplicasCount). Reads(ReplicationControllerSpec{})) apiV1Ws.Route( apiV1Ws.DELETE("/replicationcontroller/{namespace}/{replicationController}"). To(apiHandler.handleDeleteReplicationController)) apiV1Ws.Route( apiV1Ws.GET("/replicationcontroller/pod/{namespace}/{replicationController}"). To(apiHandler.handleGetReplicationControllerPods). Writes(ReplicationControllerPods{})) apiV1Ws.Route( apiV1Ws.GET("/workload"). To(apiHandler.handleGetWorkloads). Writes(workload.Workloads{})) apiV1Ws.Route( apiV1Ws.GET("/workload/{namespace}"). To(apiHandler.handleGetWorkloads). Writes(workload.Workloads{})) apiV1Ws.Route( apiV1Ws.GET("/replicaset"). To(apiHandler.handleGetReplicaSets). Writes(replicaset.ReplicaSetList{})) apiV1Ws.Route( apiV1Ws.GET("/replicaset/{namespace}"). To(apiHandler.handleGetReplicaSets). Writes(replicaset.ReplicaSetList{})) apiV1Ws.Route( apiV1Ws.GET("/replicaset/{namespace}/{replicaSet}"). To(apiHandler.handleGetReplicaSetDetail). Writes(replicaset.ReplicaSetDetail{})) apiV1Ws.Route( apiV1Ws.GET("/pod"). To(apiHandler.handleGetPods). Writes(pod.PodList{})) apiV1Ws.Route( apiV1Ws.GET("/pod/{namespace}"). To(apiHandler.handleGetPods). Writes(pod.PodList{})) apiV1Ws.Route( apiV1Ws.GET("/pod/{namespace}/{pod}"). To(apiHandler.handleGetPodDetail). Writes(pod.PodDetail{})) apiV1Ws.Route( apiV1Ws.GET("/pod/{namespace}/{pod}/container"). To(apiHandler.handleGetPodContainers). Writes(pod.PodDetail{})) apiV1Ws.Route( apiV1Ws.GET("/pod/{namespace}/{pod}/log"). To(apiHandler.handleLogs). Writes(Logs{})) apiV1Ws.Route( apiV1Ws.GET("/pod/{namespace}/{pod}/log/{container}"). To(apiHandler.handleLogs). Writes(Logs{})) apiV1Ws.Route( apiV1Ws.GET("/deployment"). To(apiHandler.handleGetDeployments). Writes(deployment.DeploymentList{})) apiV1Ws.Route( apiV1Ws.GET("/deployment/{namespace}"). To(apiHandler.handleGetDeployments). Writes(deployment.DeploymentList{})) apiV1Ws.Route( apiV1Ws.GET("/deployment/{namespace}/{deployment}"). To(apiHandler.handleGetDeploymentDetail). Writes(deployment.DeploymentDetail{})) apiV1Ws.Route( apiV1Ws.GET("/daemonset"). To(apiHandler.handleGetDaemonSetList). Writes(daemonset.DaemonSetList{})) apiV1Ws.Route( apiV1Ws.GET("/daemonset/{namespace}"). To(apiHandler.handleGetDaemonSetList). Writes(daemonset.DaemonSetList{})) apiV1Ws.Route( apiV1Ws.GET("/daemonset/{namespace}/{daemonSet}"). To(apiHandler.handleGetDaemonSetDetail). Writes(daemonset.DaemonSetDetail{})) apiV1Ws.Route( apiV1Ws.DELETE("/daemonset/{namespace}/{daemonSet}"). To(apiHandler.handleDeleteDaemonSet)) apiV1Ws.Route( apiV1Ws.GET("/job"). To(apiHandler.handleGetJobs). Writes(job.JobList{})) apiV1Ws.Route( apiV1Ws.GET("/job/{namespace}"). To(apiHandler.handleGetJobs). Writes(job.JobList{})) apiV1Ws.Route( apiV1Ws.GET("/job/{namespace}/{job}"). To(apiHandler.handleGetJobDetail). Writes(job.JobDetail{})) apiV1Ws.Route( apiV1Ws.POST("/namespace"). To(apiHandler.handleCreateNamespace). Reads(NamespaceSpec{}). Writes(NamespaceSpec{})) apiV1Ws.Route( apiV1Ws.GET("/namespace"). To(apiHandler.handleGetNamespaces). Writes(NamespaceList{})) apiV1Ws.Route( apiV1Ws.GET("/event/{namespace}/{replicationController}"). To(apiHandler.handleEvents). Writes(common.EventList{})) apiV1Ws.Route( apiV1Ws.GET("/secret/{namespace}"). To(apiHandler.handleGetSecrets). Writes(SecretsList{})) apiV1Ws.Route( apiV1Ws.POST("/secret"). To(apiHandler.handleCreateImagePullSecret). Reads(ImagePullSecretSpec{}). Writes(Secret{})) apiV1Ws.Route( apiV1Ws.GET("/service"). To(apiHandler.handleGetServiceList). Writes(resourceService.ServiceList{})) apiV1Ws.Route( apiV1Ws.GET("/service/{namespace}"). To(apiHandler.handleGetServiceList). Writes(resourceService.ServiceList{})) apiV1Ws.Route( apiV1Ws.GET("/service/{namespace}/{service}"). To(apiHandler.handleGetServiceDetail). Writes(resourceService.ServiceDetail{})) apiV1Ws.Route( apiV1Ws.GET("/petset"). To(apiHandler.handleGetPetSetList). Writes(petset.PetSetList{})) apiV1Ws.Route( apiV1Ws.GET("/petset/{namespace}"). To(apiHandler.handleGetPetSetList). Writes(petset.PetSetList{})) apiV1Ws.Route( apiV1Ws.GET("/petset/{namespace}/{petset}"). To(apiHandler.handleGetPetSetDetail). Writes(petset.PetSetDetail{})) apiV1Ws.Route( apiV1Ws.GET("/node"). To(apiHandler.handleGetNodeList). Writes(node.NodeList{})) apiV1Ws.Route( apiV1Ws.GET("/node/{name}"). To(apiHandler.handleGetNodeDetail). Writes(node.NodeDetail{})) apiV1Ws.Route( apiV1Ws.DELETE("/{kind}/namespace/{namespace}/name/{name}"). To(apiHandler.handleDeleteResource)) apiV1Ws.Route( apiV1Ws.GET("/{kind}/namespace/{namespace}/name/{name}"). To(apiHandler.handleGetResource)) apiV1Ws.Route( apiV1Ws.PUT("/{kind}/namespace/{namespace}/name/{name}"). To(apiHandler.handlePutResource)) return wsContainer }
// RegisterModel registers the Model API endpoints. // All endpoints that end with a {metric-name} also receive a start time query parameter. // The start time should be specified as a string, formatted according to RFC 3339. func (a *Api) RegisterModel(container *restful.Container) { ws := new(restful.WebService) ws. Path("/api/v1/model"). Doc("Root endpoint of the stats model"). Consumes("*/*"). Produces(restful.MIME_JSON) // The / endpoint returns a list of all the metrics that are available in the model ws.Route(ws.GET("/"). To(a.availableMetrics). Filter(compressionFilter). Doc("Show which metrics are available"). Operation("clusterMetrics")) // The /cluster/{metric-name} endpoint exposes an aggregated metric for the Cluster entity of the model. ws.Route(ws.GET("/cluster/{metric-name}"). To(a.clusterMetrics). Filter(compressionFilter). Doc("Export an aggregated cluster-level metric"). Operation("clusterMetrics"). Param(ws.PathParameter("metric-name", "The name of the requested metric").DataType("string")). Param(ws.QueryParameter("start", "Start time for requested metric").DataType("string")). Writes(MetricResult{})) // The /nodes/{node-name}/{metric-name} endpoint exposes a metric for a Node entity of the model. // The {node-name} parameter is the hostname of a specific node. ws.Route(ws.GET("/nodes/{node-name}/{metric-name}"). To(a.nodeMetrics). Filter(compressionFilter). Doc("Export a node-level metric"). Operation("nodeMetrics"). Param(ws.PathParameter("node-name", "The name of the node to lookup").DataType("string")). Param(ws.PathParameter("metric-name", "The name of the requested metric").DataType("string")). Param(ws.QueryParameter("start", "Start time for requested metric").DataType("string")). Writes(MetricResult{})) // The /namespaces/{namespace-name}/{metric-name} endpoint exposes an aggregated metrics // for a Namespace entity of the model. ws.Route(ws.GET("/namespaces/{namespace-name}/{metric-name}"). To(a.namespaceMetrics). Filter(compressionFilter). Doc("Export an aggregated namespace-level metric"). Operation("namespaceMetrics"). Param(ws.PathParameter("metric-name", "The name of the requested metric").DataType("string")). Param(ws.QueryParameter("start", "Start time for requested metrics").DataType("string")). Writes(MetricResult{})) // The /namespaces/{namespace-name}/pods/{pod-name}/{metric-name} endpoint exposes // an aggregated metric for a Pod entity of the model. ws.Route(ws.GET("/namespaces/{namespace-name}/pods/{pod-name}/{metric-name}"). To(a.podMetrics). Filter(compressionFilter). Doc("Export an aggregated pod-level metric"). Operation("podMetrics"). Param(ws.PathParameter("namespace-name", "The name of the namespace to use").DataType("string")). Param(ws.PathParameter("pod-name", "The name of the pod to use").DataType("string")). Param(ws.PathParameter("metric-name", "The name of the requested metric").DataType("string")). Param(ws.QueryParameter("start", "Start time for requested metrics").DataType("string")). Writes(MetricResult{})) // The /namespaces/{namespace-name}/pods/{pod-name}/containers/{container-name}/{metric-name} endpoint exposes // a metric for a Container entity of the model. ws.Route(ws.GET("/namespaces/{namespace-name}/pods/{pod-name}/containers/{container-name}/{metric-name}"). To(a.podContainerMetrics). Filter(compressionFilter). Doc("Export an aggregated metric for a pod container"). Operation("podContainerMetrics"). Param(ws.PathParameter("namespace-name", "The name of the namespace to use").DataType("string")). Param(ws.PathParameter("pod-name", "The name of the pod to use").DataType("string")). Param(ws.PathParameter("metric-name", "The name of the requested metric").DataType("string")). Param(ws.QueryParameter("start", "Start time for requested metrics").DataType("string")). Writes(MetricResult{})) // The /nodes/{node-name}/freecontainers/{container-name}/{metric-name} endpoint exposes // a metric for a free Container entity of the model. ws.Route(ws.GET("/nodes/{node-name}/freecontainers/{container-name}/{metric-name}"). To(a.freeContainerMetrics). Filter(compressionFilter). Doc("Export a container-level metric for a free container"). Operation("freeContainerMetrics"). Param(ws.PathParameter("node-name", "The name of the node to use").DataType("string")). Param(ws.PathParameter("container-name", "The name of the container to use").DataType("string")). Param(ws.PathParameter("metric-name", "The name of the requested metric").DataType("string")). Param(ws.QueryParameter("start", "Start time for requested metrics").DataType("string")). Writes(MetricResult{})) container.Add(ws) }
// RegisterModel registers the Model API endpoints. // All endpoints that end with a {metric-name} also receive a start time query parameter. // The start and end times should be specified as a string, formatted according to RFC 3339. func (a *Api) RegisterModel(container *restful.Container) { ws := new(restful.WebService) ws.Path("/api/v1/model"). Doc("Root endpoint of the stats model"). Consumes("*/*"). Produces(restful.MIME_JSON) // The /metrics/ endpoint returns a list of all available metrics for the Cluster entity of the model. ws.Route(ws.GET("/metrics/"). To(metrics.InstrumentRouteFunc("availableClusterMetrics", a.availableClusterMetrics)). Doc("Get a list of all available metrics for the Cluster entity"). Operation("availableClusterMetrics")) // The /metrics/{metric-name} endpoint exposes an aggregated metric for the Cluster entity of the model. ws.Route(ws.GET("/metrics/{metric-name:*}"). To(metrics.InstrumentRouteFunc("clusterMetrics", a.clusterMetrics)). Doc("Export an aggregated cluster-level metric"). Operation("clusterMetrics"). Param(ws.PathParameter("metric-name", "The name of the requested metric").DataType("string")). Param(ws.QueryParameter("start", "Start time for requested metric").DataType("string")). Param(ws.QueryParameter("end", "End time for requested metric").DataType("string")). Writes(types.MetricResult{})) // The /nodes/{node-name}/metrics endpoint returns a list of all nodes with some metrics. ws.Route(ws.GET("/nodes/"). To(metrics.InstrumentRouteFunc("nodeList", a.nodeList)). Doc("Get a list of all nodes that have some current metrics"). Operation("nodeList")) // The /nodes/{node-name}/metrics endpoint returns a list of all available metrics for a Node entity. ws.Route(ws.GET("/nodes/{node-name}/metrics/"). To(metrics.InstrumentRouteFunc("availableNodeMetrics", a.availableNodeMetrics)). Doc("Get a list of all available metrics for a Node entity"). Operation("availableNodeMetrics"). Param(ws.PathParameter("node-name", "The name of the node to lookup").DataType("string"))) // The /nodes/{node-name}/metrics/{metric-name} endpoint exposes a metric for a Node entity of the model. // The {node-name} parameter is the hostname of a specific node. ws.Route(ws.GET("/nodes/{node-name}/metrics/{metric-name:*}"). To(metrics.InstrumentRouteFunc("nodeMetrics", a.nodeMetrics)). Doc("Export a node-level metric"). Operation("nodeMetrics"). Param(ws.PathParameter("node-name", "The name of the node to lookup").DataType("string")). Param(ws.PathParameter("metric-name", "The name of the requested metric").DataType("string")). Param(ws.QueryParameter("start", "Start time for requested metric").DataType("string")). Param(ws.QueryParameter("end", "End time for requested metric").DataType("string")). Writes(types.MetricResult{})) if a.runningInKubernetes { ws.Route(ws.GET("/namespaces/"). To(metrics.InstrumentRouteFunc("namespaceList", a.namespaceList)). Doc("Get a list of all namespaces that have some current metrics"). Operation("namespaceList")) // The /namespaces/{namespace-name}/metrics endpoint returns a list of all available metrics for a Namespace entity. ws.Route(ws.GET("/namespaces/{namespace-name}/metrics"). To(metrics.InstrumentRouteFunc("availableNamespaceMetrics", a.availableNamespaceMetrics)). Doc("Get a list of all available metrics for a Namespace entity"). Operation("availableNamespaceMetrics"). Param(ws.PathParameter("namespace-name", "The name of the namespace to lookup").DataType("string"))) // The /namespaces/{namespace-name}/metrics/{metric-name} endpoint exposes an aggregated metrics // for a Namespace entity of the model. ws.Route(ws.GET("/namespaces/{namespace-name}/metrics/{metric-name:*}"). To(metrics.InstrumentRouteFunc("namespaceMetrics", a.namespaceMetrics)). Doc("Export an aggregated namespace-level metric"). Operation("namespaceMetrics"). Param(ws.PathParameter("namespace-name", "The name of the namespace to lookup").DataType("string")). Param(ws.PathParameter("metric-name", "The name of the requested metric").DataType("string")). Param(ws.QueryParameter("start", "Start time for requested metrics").DataType("string")). Param(ws.QueryParameter("end", "End time for requested metric").DataType("string")). Writes(types.MetricResult{})) ws.Route(ws.GET("/namespaces/{namespace-name}/pods/"). To(metrics.InstrumentRouteFunc("namespacePodList", a.namespacePodList)). Doc("Get a list of pods from the given namespace that have some metrics"). Operation("namespacePodList"). Param(ws.PathParameter("namespace-name", "The name of the namespace to lookup").DataType("string"))) // The /namespaces/{namespace-name}/pods/{pod-name}/metrics endpoint returns a list of all available metrics for a Pod entity. ws.Route(ws.GET("/namespaces/{namespace-name}/pods/{pod-name}/metrics"). To(metrics.InstrumentRouteFunc("availablePodMetrics", a.availablePodMetrics)). Doc("Get a list of all available metrics for a Pod entity"). Operation("availablePodMetrics"). Param(ws.PathParameter("namespace-name", "The name of the namespace to lookup").DataType("string")). Param(ws.PathParameter("pod-name", "The name of the pod to lookup").DataType("string"))) // The /namespaces/{namespace-name}/pods/{pod-name}/metrics/{metric-name} endpoint exposes // an aggregated metric for a Pod entity of the model. ws.Route(ws.GET("/namespaces/{namespace-name}/pods/{pod-name}/metrics/{metric-name:*}"). To(metrics.InstrumentRouteFunc("podMetrics", a.podMetrics)). Doc("Export an aggregated pod-level metric"). Operation("podMetrics"). Param(ws.PathParameter("namespace-name", "The name of the namespace to lookup").DataType("string")). Param(ws.PathParameter("pod-name", "The name of the pod to lookup").DataType("string")). Param(ws.PathParameter("metric-name", "The name of the requested metric").DataType("string")). Param(ws.QueryParameter("start", "Start time for requested metrics").DataType("string")). Param(ws.QueryParameter("end", "End time for requested metric").DataType("string")). Writes(types.MetricResult{})) // The /namespaces/{namespace-name}/pods/{pod-name}/containers/metrics/{container-name}/metrics endpoint // returns a list of all available metrics for a Pod Container entity. ws.Route(ws.GET("/namespaces/{namespace-name}/pods/{pod-name}/containers/{container-name}/metrics"). To(metrics.InstrumentRouteFunc("availableContainerMetrics", a.availablePodContainerMetrics)). Doc("Get a list of all available metrics for a Pod entity"). Operation("availableContainerMetrics"). Param(ws.PathParameter("namespace-name", "The name of the namespace to lookup").DataType("string")). Param(ws.PathParameter("pod-name", "The name of the pod to lookup").DataType("string")). Param(ws.PathParameter("container-name", "The name of the namespace to use").DataType("string"))) // The /namespaces/{namespace-name}/pods/{pod-name}/containers/{container-name}/metrics/{metric-name} endpoint exposes // a metric for a Container entity of the model. ws.Route(ws.GET("/namespaces/{namespace-name}/pods/{pod-name}/containers/{container-name}/metrics/{metric-name:*}"). To(metrics.InstrumentRouteFunc("podContainerMetrics", a.podContainerMetrics)). Doc("Export an aggregated metric for a Pod Container"). Operation("podContainerMetrics"). Param(ws.PathParameter("namespace-name", "The name of the namespace to use").DataType("string")). Param(ws.PathParameter("pod-name", "The name of the pod to use").DataType("string")). Param(ws.PathParameter("container-name", "The name of the namespace to use").DataType("string")). Param(ws.PathParameter("metric-name", "The name of the requested metric").DataType("string")). Param(ws.QueryParameter("start", "Start time for requested metrics").DataType("string")). Param(ws.QueryParameter("end", "End time for requested metric").DataType("string")). Writes(types.MetricResult{})) } ws.Route(ws.GET("/nodes/{node-name}/freecontainers/"). To(metrics.InstrumentRouteFunc("systemContainerList", a.nodeSystemContainerList)). Doc("Get a list of all non-pod containers with some metrics"). Operation("systemContainerList"). Param(ws.PathParameter("node-name", "The name of the namespace to lookup").DataType("string"))) // The /nodes/{node-name}/freecontainers/{container-name}/metrics endpoint // returns a list of all available metrics for a Free Container entity. ws.Route(ws.GET("/nodes/{node-name}/freecontainers/{container-name}/metrics"). To(metrics.InstrumentRouteFunc("availableMetrics", a.availableFreeContainerMetrics)). Doc("Get a list of all available metrics for a free Container entity"). Operation("availableMetrics"). Param(ws.PathParameter("node-name", "The name of the namespace to lookup").DataType("string")). Param(ws.PathParameter("container-name", "The name of the namespace to use").DataType("string"))) // The /nodes/{node-name}/freecontainers/{container-name}/metrics/{metric-name} endpoint exposes // a metric for a free Container entity of the model. ws.Route(ws.GET("/nodes/{node-name}/freecontainers/{container-name}/metrics/{metric-name:*}"). To(metrics.InstrumentRouteFunc("freeContainerMetrics", a.freeContainerMetrics)). Doc("Export a container-level metric for a free container"). Operation("freeContainerMetrics"). Param(ws.PathParameter("node-name", "The name of the node to use").DataType("string")). Param(ws.PathParameter("container-name", "The name of the container to use").DataType("string")). Param(ws.PathParameter("metric-name", "The name of the requested metric").DataType("string")). Param(ws.QueryParameter("start", "Start time for requested metrics").DataType("string")). Param(ws.QueryParameter("end", "End time for requested metric").DataType("string")). Writes(types.MetricResult{})) if a.runningInKubernetes { // The /namespaces/{namespace-name}/pod-list/{pod-list}/metrics/{metric-name} endpoint exposes // metrics for a list od pods of the model. ws.Route(ws.GET("/namespaces/{namespace-name}/pod-list/{pod-list}/metrics/{metric-name:*}"). To(metrics.InstrumentRouteFunc("podListMetric", a.podListMetrics)). Doc("Export a metric for all pods from the given list"). Operation("podListMetric"). Param(ws.PathParameter("namespace-name", "The name of the namespace to lookup").DataType("string")). Param(ws.PathParameter("pod-list", "Comma separated list of pod names to lookup").DataType("string")). Param(ws.PathParameter("metric-name", "The name of the requested metric").DataType("string")). Param(ws.QueryParameter("start", "Start time for requested metrics").DataType("string")). Param(ws.QueryParameter("end", "End time for requested metric").DataType("string")). Writes(types.MetricResult{})) } ws.Route(ws.GET("/debug/allkeys"). To(metrics.InstrumentRouteFunc("debugAllKeys", a.allKeys)). Doc("Get keys of all metric sets available"). Operation("debugAllKeys")) container.Add(ws) }