// 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 }
// 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 }