app_info.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. package modelse
  2. import "time"
  3. const (
  4. APP_NAME = "app_name"
  5. APP_ID = "app_id"
  6. AGENT_ID = "agent_id"
  7. INSTANCE_ID = "instance_id"
  8. )
  9. type APP_TYPE int
  10. const (
  11. APP_WAIT APP_TYPE = iota
  12. APP_SUCCESS
  13. APP_UPROBE_ERROR
  14. APP_STACK_ERROR
  15. APP_UNINSTALL
  16. APP_UNINSTALL_ERROR
  17. APP_FUSE
  18. APP_FUSE_ERROR
  19. )
  20. func (s APP_TYPE) Error() APP_TYPE {
  21. switch s {
  22. case APP_UNINSTALL:
  23. return APP_UNINSTALL_ERROR
  24. case APP_FUSE:
  25. return APP_FUSE_ERROR
  26. default:
  27. return APP_UPROBE_ERROR
  28. }
  29. }
  30. func (s APP_TYPE) IsSuccess() bool {
  31. if s == APP_SUCCESS {
  32. return true
  33. }
  34. return false
  35. }
  36. func (s APP_TYPE) IsError() bool {
  37. switch s {
  38. case APP_UNINSTALL_ERROR:
  39. case APP_FUSE_ERROR:
  40. case APP_UPROBE_ERROR:
  41. return true
  42. default:
  43. return false
  44. }
  45. return false
  46. }
  47. func (s APP_TYPE) String() string {
  48. switch s {
  49. case APP_SUCCESS:
  50. return "SUCCESS"
  51. case APP_UPROBE_ERROR:
  52. return "UPROBE ERROR"
  53. case APP_UNINSTALL:
  54. return "UNINSTALL"
  55. case APP_FUSE:
  56. return "FUSE"
  57. default:
  58. return "-"
  59. }
  60. }
  61. type AppInfo struct {
  62. AppName string `json:"app_name"`
  63. AppIdHash INT_HASH_ID `json:"app_id_hash"`
  64. InstanceIdHash INT_HASH_ID `json:"instance_id_hash"`
  65. AgentId int64 `json:"agent_id"`
  66. Sn string `json:"sn"`
  67. Sport int `json:"sport"`
  68. ServiceType string `json:"service_name"`
  69. CodeType CodeType `json:"code_type"`
  70. EBPFProcInfo *EbpfProcInfo `json:"ebpf_proc_info"`
  71. RegisterAt int64 `json:"register_at"`
  72. UpdateAt int64 `json:"update_at"`
  73. PreStatus APP_TYPE `json:"pre_status"`
  74. Status APP_TYPE `json:"status"`
  75. Version string `json:"version"`
  76. }
  77. func (a *AppInfo) UpdateAtTime() {
  78. a.UpdateAt = time.Now().Unix()
  79. }
  80. func (a *AppInfo) SetAppStatus(status APP_TYPE) {
  81. a.PreStatus = a.Status
  82. a.Status = status
  83. a.UpdateAtTime()
  84. }
  85. func (a *AppInfo) SetAppSuccess() {
  86. if !a.Status.IsSuccess() {
  87. a.SetAppStatus(APP_SUCCESS)
  88. }
  89. }
  90. func (a *AppInfo) SetAppStackError() {
  91. a.SetAppStatus(APP_STACK_ERROR)
  92. }
  93. func (a *AppInfo) AppUninstall() {
  94. a.SetAppStatus(APP_UNINSTALL)
  95. }