support application sorting
Signed-off-by: hongming <talonwan@yunify.com>
This commit is contained in:
@@ -39,6 +39,8 @@ func ListApplications(req *restful.Request, resp *restful.Response) {
|
|||||||
limit, offset := params.ParsePaging(req.QueryParameter(params.PagingParam))
|
limit, offset := params.ParsePaging(req.QueryParameter(params.PagingParam))
|
||||||
namespaceName := req.PathParameter("namespace")
|
namespaceName := req.PathParameter("namespace")
|
||||||
conditions, err := params.ParseConditions(req.QueryParameter(params.ConditionsParam))
|
conditions, err := params.ParseConditions(req.QueryParameter(params.ConditionsParam))
|
||||||
|
orderBy := req.QueryParameter(params.OrderByParam)
|
||||||
|
reverse := params.ParseReverse(req)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
resp.WriteHeaderAndEntity(http.StatusBadRequest, errors.Wrap(err))
|
resp.WriteHeaderAndEntity(http.StatusBadRequest, errors.Wrap(err))
|
||||||
@@ -67,7 +69,7 @@ func ListApplications(req *restful.Request, resp *restful.Response) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err := openpitrix.ListApplications(conditions, limit, offset)
|
result, err := openpitrix.ListApplications(conditions, limit, offset, orderBy, reverse)
|
||||||
|
|
||||||
if _, notEnabled := err.(client.ClientSetNotEnabledError); notEnabled {
|
if _, notEnabled := err.(client.ClientSetNotEnabledError); notEnabled {
|
||||||
resp.WriteHeaderAndEntity(http.StatusNotImplemented, errors.Wrap(err))
|
resp.WriteHeaderAndEntity(http.StatusNotImplemented, errors.Wrap(err))
|
||||||
|
|||||||
@@ -241,7 +241,7 @@ func ListAppVersions(req *restful.Request, resp *restful.Response) {
|
|||||||
if statistics {
|
if statistics {
|
||||||
for _, item := range result.Items {
|
for _, item := range result.Items {
|
||||||
if version, ok := item.(*openpitrix.AppVersion); ok {
|
if version, ok := item.(*openpitrix.AppVersion); ok {
|
||||||
statisticsResult, err := openpitrix.ListApplications(¶ms.Conditions{Match: map[string]string{"app_id": version.AppId, "version_id": version.VersionId}}, 0, 0)
|
statisticsResult, err := openpitrix.ListApplications(¶ms.Conditions{Match: map[string]string{"app_id": version.AppId, "version_id": version.VersionId}}, 0, 0, "", false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Errorln(err)
|
klog.Errorln(err)
|
||||||
resp.WriteHeaderAndEntity(http.StatusInternalServerError, errors.Wrap(err))
|
resp.WriteHeaderAndEntity(http.StatusInternalServerError, errors.Wrap(err))
|
||||||
@@ -287,7 +287,7 @@ func ListApps(req *restful.Request, resp *restful.Response) {
|
|||||||
if statistics {
|
if statistics {
|
||||||
for _, item := range result.Items {
|
for _, item := range result.Items {
|
||||||
if app, ok := item.(*openpitrix.App); ok {
|
if app, ok := item.(*openpitrix.App); ok {
|
||||||
statisticsResult, err := openpitrix.ListApplications(¶ms.Conditions{Match: map[string]string{"app_id": app.AppId, "status": "active|used|enabled|stopped"}}, 0, 0)
|
statisticsResult, err := openpitrix.ListApplications(¶ms.Conditions{Match: map[string]string{"app_id": app.AppId, "status": "active|used|enabled|stopped"}}, 0, 0, "", false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Errorln(err)
|
klog.Errorln(err)
|
||||||
resp.WriteHeaderAndEntity(http.StatusInternalServerError, errors.Wrap(err))
|
resp.WriteHeaderAndEntity(http.StatusInternalServerError, errors.Wrap(err))
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ type workLoads struct {
|
|||||||
Daemonsets []appsv1.DaemonSet `json:"daemonsets,omitempty" description:"daemonset list"`
|
Daemonsets []appsv1.DaemonSet `json:"daemonsets,omitempty" description:"daemonset list"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func ListApplications(conditions *params.Conditions, limit, offset int) (*models.PageableResponse, error) {
|
func ListApplications(conditions *params.Conditions, limit, offset int, orderBy string, reverse bool) (*models.PageableResponse, error) {
|
||||||
client, err := cs.ClientSets().OpenPitrix()
|
client, err := cs.ClientSets().OpenPitrix()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Error(err)
|
klog.Error(err)
|
||||||
@@ -80,6 +80,10 @@ func ListApplications(conditions *params.Conditions, limit, offset int) (*models
|
|||||||
if status := conditions.Match["status"]; status != "" {
|
if status := conditions.Match["status"]; status != "" {
|
||||||
describeClustersRequest.Status = strings.Split(status, "|")
|
describeClustersRequest.Status = strings.Split(status, "|")
|
||||||
}
|
}
|
||||||
|
if orderBy != "" {
|
||||||
|
describeClustersRequest.SortKey = &wrappers.StringValue{Value: orderBy}
|
||||||
|
}
|
||||||
|
describeClustersRequest.Reverse = &wrappers.BoolValue{Value: reverse}
|
||||||
resp, err := client.Cluster().DescribeClusters(openpitrix.SystemContext(), describeClustersRequest)
|
resp, err := client.Cluster().DescribeClusters(openpitrix.SystemContext(), describeClustersRequest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Errorln(err)
|
klog.Errorln(err)
|
||||||
|
|||||||
Reference in New Issue
Block a user