diff --git a/pkg/apiserver/openpitrix/applications.go b/pkg/apiserver/openpitrix/applications.go index a12239f84ede4a1570c07d87cc7103a95dd8e6e3..8fafc9a17db53184fa7e0d40937f5528bccad31f 100644 --- a/pkg/apiserver/openpitrix/applications.go +++ b/pkg/apiserver/openpitrix/applications.go @@ -39,6 +39,8 @@ func ListApplications(req *restful.Request, resp *restful.Response) { limit, offset := params.ParsePaging(req.QueryParameter(params.PagingParam)) namespaceName := req.PathParameter("namespace") conditions, err := params.ParseConditions(req.QueryParameter(params.ConditionsParam)) + orderBy := req.QueryParameter(params.OrderByParam) + reverse := params.ParseReverse(req) if err != nil { 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 { resp.WriteHeaderAndEntity(http.StatusNotImplemented, errors.Wrap(err)) diff --git a/pkg/apiserver/openpitrix/apps.go b/pkg/apiserver/openpitrix/apps.go index 13457f3c00e6778ad8c79117fe60e331dbe85fb2..8a7fb3d3d6f0ecd50ecad37b5d644762c8e08103 100644 --- a/pkg/apiserver/openpitrix/apps.go +++ b/pkg/apiserver/openpitrix/apps.go @@ -241,7 +241,7 @@ func ListAppVersions(req *restful.Request, resp *restful.Response) { if statistics { for _, item := range result.Items { 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 { klog.Errorln(err) resp.WriteHeaderAndEntity(http.StatusInternalServerError, errors.Wrap(err)) @@ -287,7 +287,7 @@ func ListApps(req *restful.Request, resp *restful.Response) { if statistics { for _, item := range result.Items { 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 { klog.Errorln(err) resp.WriteHeaderAndEntity(http.StatusInternalServerError, errors.Wrap(err)) diff --git a/pkg/models/openpitrix/applications.go b/pkg/models/openpitrix/applications.go index ebcf713822e08220e9e191057aaad7ed98a1f9ae..f7a3751abdadcd701eb230c45927c070e5550570 100644 --- a/pkg/models/openpitrix/applications.go +++ b/pkg/models/openpitrix/applications.go @@ -56,7 +56,7 @@ type workLoads struct { 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() if err != nil { klog.Error(err) @@ -80,6 +80,10 @@ func ListApplications(conditions *params.Conditions, limit, offset int) (*models if status := conditions.Match["status"]; 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) if err != nil { klog.Errorln(err)