Merge remote-tracking branch 'upstream/master'

This commit is contained in:
hongming
2018-06-01 23:57:42 +08:00
12 changed files with 689 additions and 257 deletions

View File

@@ -0,0 +1,47 @@
/*
Copyright 2018 The KubeSphere Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package components
import (
"github.com/emicklei/go-restful"
"kubesphere.io/kubesphere/pkg/filter/route"
"kubesphere.io/kubesphere/pkg/models"
"net/http"
"kubesphere.io/kubesphere/pkg/constants"
)
func Register(ws *restful.WebService, subPath string) {
ws.Route(ws.GET(subPath).To(handleGetComponents).Filter(route.RouteLogging)).
Consumes(restful.MIME_JSON, restful.MIME_XML).
Produces(restful.MIME_JSON)
}
//get all components
func handleGetComponents(request *restful.Request, response *restful.Response) {
result, err := models.GetComponents()
if err != nil {
response.WriteHeaderAndEntity(http.StatusInternalServerError, constants.MessageResponse{Message: err.Error()})
}
response.WriteAsJson(result)
}

View File

@@ -25,6 +25,9 @@ import (
)
func Register(ws *restful.WebService) {
ws.Route(ws.GET("/namespaces/{namespace}/pods/{podname}/containers/{containername}").To(handleContainerUnderNameSpaceAndPod).Filter(route.RouteLogging)).
Consumes(restful.MIME_JSON, restful.MIME_XML).
Produces(restful.MIME_JSON)
ws.Route(ws.GET("/namespaces/{namespace}/pods/{podname}/containers").To(handleContainersUnderNameSpaceAndPod).Filter(route.RouteLogging)).
Consumes(restful.MIME_JSON, restful.MIME_XML).
Produces(restful.MIME_JSON)
@@ -33,28 +36,23 @@ func Register(ws *restful.WebService) {
Produces(restful.MIME_JSON)
}
func handleContainerUnderNameSpaceAndPod(request *restful.Request, response *restful.Response) {
var resultContainer models.ResultContainer
resultContainer = models.FormatContainerMetrics(request.PathParameter("namespace"), request.PathParameter("podname"), request.PathParameter("containername"))
resultContainer.NodeName = models.GetNodeNameForPod(request.PathParameter("podname"), request.PathParameter("namespace"))
response.WriteAsJson(resultContainer)
}
func handleContainersUnderNameSpaceAndPod(request *restful.Request, response *restful.Response) {
var result constants.ResultMessage
var resultNameSpaces []models.ResultNameSpaceForContainer
var resultNameSpace models.ResultNameSpaceForContainer
var resultNameSpace constants.PageableResponse
resultNameSpace = models.FormatContainersMetrics("", request.PathParameter("namespace"), request.PathParameter("podname"))
resultNameSpaces = append(resultNameSpaces, resultNameSpace)
result.Data = resultNameSpaces
response.WriteAsJson(result)
response.WriteAsJson(resultNameSpace)
}
func handleContainersUnderNodeAndNameSpaceAndPod(request *restful.Request, response *restful.Response) {
var result constants.ResultMessage
var resultNameSpaces []models.ResultNameSpaceForContainer
var resultNameSpace models.ResultNameSpaceForContainer
var resultNameSpace constants.PageableResponse
resultNameSpace = models.FormatContainersMetrics(request.PathParameter("nodename"), request.PathParameter("namespace"), request.PathParameter("podname"))
resultNameSpaces = append(resultNameSpaces, resultNameSpace)
result.Data = resultNameSpaces
response.WriteAsJson(result)
response.WriteAsJson(resultNameSpace)
}

View File

@@ -27,6 +27,7 @@ import (
"kubesphere.io/kubesphere/pkg/apis/v1alpha/storage"
"kubesphere.io/kubesphere/pkg/apis/v1alpha/volumes"
"kubesphere.io/kubesphere/pkg/apis/v1alpha/iam"
"kubesphere.io/kubesphere/pkg/apis/v1alpha/components"
)
func init() {
@@ -43,6 +44,7 @@ func init() {
pods.Register(ws)
containers.Register(ws)
iam.Register(ws)
components.Register(ws,"/components")
// add webservice to default container
restful.Add(ws)

View File

@@ -35,32 +35,28 @@ func Register(ws *restful.WebService, subPath string) {
}
func handleNodes(request *restful.Request, response *restful.Response) {
var result constants.ResultMessage
var resultNodes []models.ResultNode
var result constants.PageableResponse
var resultNode models.ResultNode
nodes := models.GetNodes()
for _, node := range nodes {
var total_count int
for i, node := range nodes {
resultNode = models.FormatNodeMetrics(node)
resultNodes = append(resultNodes, resultNode)
result.Items = append(result.Items, resultNode)
total_count = i
}
total_count = total_count + 1
result.Data = resultNodes
result.TotalCount = total_count
response.WriteAsJson(result)
}
func handleSingleNode(request *restful.Request, response *restful.Response) {
nodeName := request.PathParameter("nodename")
var result constants.ResultMessage
var resultNodes []models.ResultNode
var resultNode models.ResultNode
resultNode = models.FormatNodeMetrics(nodeName)
resultNodes = append(resultNodes, resultNode)
result.Data = resultNodes
response.WriteAsJson(result)
response.WriteAsJson(resultNode)
}

View File

@@ -30,55 +30,75 @@ func Register(ws *restful.WebService) {
ws.Route(ws.GET("/pods").To(handleAllPods).Filter(route.RouteLogging)).
Consumes(restful.MIME_JSON, restful.MIME_XML).
Produces(restful.MIME_JSON)
ws.Route(ws.GET("/namespaces/{namespace}/pods/{podname}").To(handlePodUnderNameSpace).Filter(route.RouteLogging)).
Consumes(restful.MIME_JSON, restful.MIME_XML).
Produces(restful.MIME_JSON)
ws.Route(ws.GET("/namespaces/{namespace}/pods").To(handlePodsUnderNameSpace).Filter(route.RouteLogging)).
Consumes(restful.MIME_JSON, restful.MIME_XML).
Produces(restful.MIME_JSON)
ws.Route(ws.GET("/nodes/{nodename}/pods").To(handlePodsUnderNode).Filter(route.RouteLogging)).
Consumes(restful.MIME_JSON, restful.MIME_XML).
Produces(restful.MIME_JSON)
ws.Route(ws.GET("/nodes/{nodename}/namespaces/{namespace}/pods").To(handlePodsUnderNodeAndNameSpace).Filter(route.RouteLogging)).
Consumes(restful.MIME_JSON, restful.MIME_XML).
Produces(restful.MIME_JSON)
}
func handleAllPods(request *restful.Request, response *restful.Response) {
var result constants.ResultMessage
var resultNameSpaces []models.ResultNameSpace
var resultNameSpace models.ResultNameSpace
var result constants.PageableResponse
namespaces := models.GetNameSpaces()
for _, namespace := range namespaces {
resultNameSpace = models.FormatPodsMetrics("", namespace)
resultNameSpaces = append(resultNameSpaces, resultNameSpace)
var total_count int
for i, namespace := range namespaces {
result = models.FormatPodsMetrics("", namespace)
result.Items = append(result.Items, result)
total_count = i
}
result.Data = resultNameSpaces
result.TotalCount = total_count
response.WriteAsJson(result)
}
func handlePodsUnderNameSpace(request *restful.Request, response *restful.Response) {
var result constants.ResultMessage
var resultNameSpaces []models.ResultNameSpace
var resultNameSpace models.ResultNameSpace
var result constants.PageableResponse
resultNameSpace = models.FormatPodsMetrics("", request.PathParameter("namespace"))
result = models.FormatPodsMetrics("", request.PathParameter("namespace"))
resultNameSpaces = append(resultNameSpaces, resultNameSpace)
result.Data = resultNameSpaces
response.WriteAsJson(result)
}
func handlePodsUnderNode(request *restful.Request, response *restful.Response) {
var result constants.PageableResponse
var resultNameSpace constants.PageableResponse
namespaces := models.GetNameSpaces()
var total_count int
for _, namespace := range namespaces {
resultNameSpace = models.FormatPodsMetrics(request.PathParameter("nodename"), namespace)
var sub_total_count int
for j, pod := range resultNameSpace.Items {
result.Items = append(result.Items, pod)
sub_total_count = j
}
total_count += sub_total_count
}
result.TotalCount = total_count
response.WriteAsJson(result)
}
func handlePodUnderNameSpace(request *restful.Request, response *restful.Response) {
var resultPod models.ResultPod
resultPod = models.FormatPodMetrics(request.PathParameter("namespace"), request.PathParameter("podname"))
response.WriteAsJson(resultPod)
}
func handlePodsUnderNodeAndNameSpace(request *restful.Request, response *restful.Response) {
var result constants.ResultMessage
var resultNameSpaces []models.ResultNameSpace
var resultNameSpace models.ResultNameSpace
var result constants.PageableResponse
resultNameSpace = models.FormatPodsMetrics(request.PathParameter("nodename"), request.PathParameter("namespace"))
result = models.FormatPodsMetrics(request.PathParameter("nodename"), request.PathParameter("namespace"))
resultNameSpaces = append(resultNameSpaces, resultNameSpace)
result.Data = resultNameSpaces
response.WriteAsJson(result)
}

View File

@@ -21,6 +21,7 @@ import (
"kubesphere.io/kubesphere/pkg/models"
"kubesphere.io/kubesphere/pkg/filter/route"
"net/http"
"kubesphere.io/kubesphere/pkg/constants"
)
func Register(ws *restful.WebService, subPath string) {
@@ -39,7 +40,7 @@ func handlerRegistryValidation(request *restful.Request, response *restful.Respo
if err != nil {
response.WriteError(http.StatusInternalServerError, err)
response.WriteHeaderAndEntity(http.StatusInternalServerError, constants.MessageResponse{Message: err.Error()})
}