history.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package api
  15. import (
  16. "strconv"
  17. simplejson "github.com/bitly/go-simplejson"
  18. )
  19. type HistoryArgs struct {
  20. Offset int64
  21. Limit int64
  22. All bool
  23. IsSuggestion bool
  24. }
  25. type HistoryItem struct {
  26. Time string `json:"time"`
  27. Consuming string `json:"consuming"`
  28. SessionID string `json:"session_id"`
  29. Count string `json:"count"`
  30. Tenants []string `json:"tenants"`
  31. Status string `json:"status"`
  32. Guests []string `json:"guests"`
  33. IsSuggestion bool `json:"is_suggestion"`
  34. }
  35. type HistoryResult struct {
  36. Items []*HistoryItem `json:"data"`
  37. Total int64 `json:"total"`
  38. Offset int64 `json:"offset"`
  39. Limit int64 `json:"limit"`
  40. }
  41. func toInt64(j *simplejson.Json) int64 {
  42. if s, err := j.String(); err == nil {
  43. if r, err0 := strconv.Atoi(s); err0 == nil {
  44. return int64(r)
  45. }
  46. }
  47. return j.MustInt64()
  48. }
  49. func NewHistoryArgs(sjson *simplejson.Json) (*HistoryArgs, error) {
  50. args := new(HistoryArgs)
  51. if offset, ok := sjson.CheckGet("offset"); ok {
  52. args.Offset = toInt64(offset)
  53. }
  54. if limit, ok := sjson.CheckGet("limit"); ok {
  55. args.Limit = toInt64(limit)
  56. }
  57. if all, ok := sjson.CheckGet("all"); ok {
  58. args.All = all.MustBool()
  59. }
  60. if isSuggestion, ok := sjson.CheckGet("is_suggestion"); ok {
  61. args.IsSuggestion = isSuggestion.MustBool()
  62. }
  63. return args, nil
  64. }
  65. type HistoryDetailArgs struct {
  66. ID string
  67. Raw bool
  68. Log bool
  69. }
  70. type HistoryTask struct {
  71. Type string `json:"type"`
  72. Status string `json:"status"`
  73. Data *SchedInfo `json:"data"`
  74. Time string `json:"time"`
  75. Consuming string `json:"consuming"`
  76. //Result []SchedResultItem `json:"result"`
  77. Result interface{} `json:"result"`
  78. Error string `json:"error"`
  79. Logs []string `json:"logs"`
  80. CapacityMap interface{} `json:"capacity_map"`
  81. }
  82. type HistoryDetail struct {
  83. Time string `json:"time"`
  84. Consuming string `json:"consuming"`
  85. SessionID string `json:"session_id"`
  86. Tasks []HistoryTask `json:"tasks"`
  87. Input string `json:"input"`
  88. Output string `json:"output"`
  89. Error string `json:"error"`
  90. }
  91. type HistoryDetailResult struct {
  92. Detail *HistoryDetail `json:"history"`
  93. }
  94. func NewHistoryDetailArgs(sjson *simplejson.Json, id string) (*HistoryDetailArgs, error) {
  95. args := new(HistoryDetailArgs)
  96. args.ID = id
  97. if raw, ok := sjson.CheckGet("raw"); ok {
  98. args.Raw = raw.MustBool()
  99. }
  100. if log, ok := sjson.CheckGet("log"); ok {
  101. args.Log = log.MustBool()
  102. }
  103. return args, nil
  104. }