fix export data, set no limit; expand timeout

This commit is contained in:
wanyaoqi
2019-07-02 17:50:08 +08:00
parent a0c3f87b09
commit 17c886084a
4 changed files with 25 additions and 1 deletions
+1 -1
View File
@@ -245,7 +245,7 @@ func (app *Application) defaultHandle(w http.ResponseWriter, r *http.Request, ri
if ok {
fw := newResponseWriterChannel(w)
worker := make(chan *SWorker)
to := hand.processTimeout
to := hand.FetchProcessTimeout(r)
if to == 0 {
to = app.processTimeout
}
+8
View File
@@ -41,6 +41,14 @@ type SHandlerInfo struct {
skipLog bool
}
func (this *SHandlerInfo) FetchProcessTimeout(r *http.Request) time.Duration {
if r.Method == http.MethodGet && r.Header.Get("X-Export-Keys") == "true" {
return time.Hour * 2
} else {
return this.processTimeout
}
}
func (this *SHandlerInfo) GetName(params map[string]string) string {
if len(this.name) > 0 {
return this.name
+6
View File
@@ -476,6 +476,12 @@ func ListItems(manager IModelManager, ctx context.Context, userCred mcclient.Tok
limit = maxLimit
}
// export data only
exportLimit, err := query.Int("export_limit")
if query.Contains("export_keys") && err == nil {
limit = exportLimit
}
var primaryCol sqlchemy.IColumnSpec
primaryCols := manager.TableSpec().PrimaryColumns()
if len(primaryCols) == 1 {
+10
View File
@@ -1550,6 +1550,13 @@ func (manager *SGuestManager) ListItemExportKeys(ctx context.Context, q *sqlchem
q.AppendField(eipsSubQuery.Field("ip_addr", "eip"))
}
if utils.IsInStringArray("host", keys) {
hostQuery := HostManager.Query("id", "name").GroupBy("id")
hostSubQuery := hostQuery.SubQuery()
q.LeftJoin(hostSubQuery, sqlchemy.Equals(q.Field("host_id"), hostSubQuery.Field("id")))
q.AppendField(hostSubQuery.Field("name", "host"))
}
// host_id as filter key
if utils.IsInStringArray("region", keys) {
zoneQuery := ZoneManager.Query("id", "cloudregion_id").SubQuery()
@@ -1589,6 +1596,9 @@ func (manager *SGuestManager) GetExportExtraKeys(ctx context.Context, query json
if disk, ok := rowMap["disk_size"]; ok {
res.Set("disk", jsonutils.NewString(disk))
}
if host, ok := rowMap["host"]; ok && len(host) > 0 {
res.Set("host", jsonutils.NewString(host))
}
if region, ok := rowMap["region"]; ok && len(region) > 0 {
res.Set("region", jsonutils.NewString(region))
}