http.go 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/app/admin/ep/melloi/conf"
  5. "go-common/app/admin/ep/melloi/service"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. "go-common/library/net/http/blademaster/middleware/permit"
  9. )
  10. var (
  11. srv *service.Service
  12. // AuthSrv Auth Service
  13. AuthSrv *permit.Permit
  14. )
  15. // Init init
  16. func Init(c *conf.Config, s *service.Service) {
  17. srv = s
  18. AuthSrv = permit.New2(c.PermitGRPC)
  19. engine := bm.NewServer(c.BM)
  20. engine.Ping(ping)
  21. router(engine)
  22. if err := engine.Start(); err != nil {
  23. log.Error("xhttp.Serve2 error(%v)", err)
  24. panic(err)
  25. }
  26. }
  27. // router init outer router api path
  28. func router(e *bm.Engine) {
  29. e.Register(register)
  30. version := e.Group("/ep/admin/melloi/v1", AuthSrv.Permit2(""))
  31. {
  32. home := version.Group("/rank")
  33. {
  34. home.GET("/trees/query", treesQuery)
  35. home.GET("/top/http/query", topHttpQuery)
  36. home.GET("/top/dept/query", topDeptQuery)
  37. home.GET("/treenum/query", treeNumQuery)
  38. home.GET("/buildline/query", buildLineQuery)
  39. home.GET("/stateline/query", stateLineQuery)
  40. home.GET("/top/grpc/query", topGrpcQuery)
  41. home.GET("/top/scene/query", topSceneQuery)
  42. }
  43. user := version.Group("/user")
  44. {
  45. user.GET("/query", queryUser)
  46. user.POST("/update", updateUser)
  47. }
  48. //手工压测
  49. order := version.Group("/order")
  50. {
  51. order.GET("/query", queryOrder)
  52. order.POST("/add", addOrder)
  53. order.POST("/update", updateOrder)
  54. order.GET("/del", delOrder)
  55. order.POST("/report/add", addOrderReport)
  56. order.GET("/report/query", queryOrderReport)
  57. }
  58. //非压测时间段压测申请
  59. apply := version.Group("/apply")
  60. {
  61. apply.GET("/query", queryApply)
  62. apply.POST("/add", addApply)
  63. apply.POST("/update", updateApply)
  64. apply.GET("/del", delApply)
  65. }
  66. orderAdmin := version.Group("/admin")
  67. {
  68. orderAdmin.GET("/query", queryOrderAdmin)
  69. orderAdmin.GET("/add", addOrderAdmin)
  70. }
  71. script := version.Group("/script")
  72. {
  73. script.POST("/gettgroup", getThreadGroup)
  74. script.POST("/add", addAndExecuteScript)
  75. script.POST("/grpc/add", grpcAddScript)
  76. script.POST("/update", updateScript)
  77. script.POST("/updateall", updateScriptAll)
  78. script.GET("/delete", delScript)
  79. script.GET("/query", queryScripts)
  80. script.GET("/query/free", queryScripysFree)
  81. script.GET("/querysnap", queryScriptSnap)
  82. script.POST("/url/check", urlCheck)
  83. script.POST("/addtimer", addTimer)
  84. }
  85. scene := version.Group("/scene")
  86. {
  87. scene.POST("/addscene/auto", AddAndExecuScene)
  88. scene.GET("/draft/query", queryDraft)
  89. scene.POST("/update", updateScene)
  90. scene.POST("/add", addScene)
  91. scene.POST("/save", saveScene)
  92. scene.POST("/saveorder", saveOrder)
  93. scene.GET("/relation/query", queryRelation)
  94. scene.GET("/api/query", queryAPI)
  95. scene.POST("/api/delete", deleteAPI)
  96. scene.POST("/group/config/add", addConfig)
  97. scene.GET("/tree/query", queryTree)
  98. scene.GET("/query", queryScenes)
  99. scene.POST("/doptest", doScenePtest)
  100. scene.POST("/doptest/batch", doScenePtestBatch)
  101. scene.GET("/existapi/query", queryExistAPI)
  102. scene.GET("/preview/query", queryPreview)
  103. scene.GET("/params/query", queryParams)
  104. scene.POST("/bindScene/update", updateBindScene)
  105. scene.GET("/drawrelation/query", queryDrawRelation)
  106. scene.POST("/script/add", addSceneScript)
  107. scene.POST("/draft/delete", deleteDraft)
  108. scene.GET("/group/config/query", queryConfig)
  109. scene.GET("/delete", deleteScene)
  110. scene.POST("/copy", copyScene)
  111. scene.GET("/fusing/query", queryFusing)
  112. }
  113. run := version.Group("/run")
  114. {
  115. run.GET("/time/check", runTimeCheck)
  116. run.POST("/grpc/run", runGrpc)
  117. run.GET("/grpc/query", queryGrpc)
  118. run.POST("/grpc/update", updateGrpc)
  119. run.GET("/grpc/delete", deleteGrpc)
  120. run.GET("/grpc/snap/query", queryGrpcSnap)
  121. run.GET("/proto/query", getProto)
  122. }
  123. file := version.Group("/file")
  124. {
  125. file.POST("/upload", upload)
  126. file.POST("/proto/refer/upload", uploadDependProto)
  127. file.GET("/read", readFile)
  128. file.GET("/download", downloadFile)
  129. file.GET("/exists", isFileExists)
  130. file.POST("/img", uploadImg)
  131. file.POST("/proto/compile", compileProtoFile)
  132. }
  133. tree := version.Group("/tree")
  134. {
  135. tree.GET("/query", queryUserTree)
  136. tree.GET("/admin", queryTreeAdmin)
  137. }
  138. report := version.Group("report")
  139. {
  140. report.POST("/update/summary", updateReportSummary)
  141. report.GET("/query", queryReportSummarys)
  142. report.POST("/query/regraph", queryReGraph)
  143. report.POST("/query/regraphavg", queryReGraphAvg)
  144. report.GET("/update/status", updateReportStatus)
  145. report.GET("/del", delReport)
  146. report.GET("/query/id", queryReportByID)
  147. }
  148. moni := version.Group("moni")
  149. {
  150. moni.GET("/client", queryClientMoni)
  151. }
  152. ptest := version.Group("ptest")
  153. {
  154. ptest.GET("/add", addPtest)
  155. ptest.GET("/reduce", reducePtest)
  156. ptest.GET("/queryalljob", queryAllJob)
  157. ptest.GET("/queryalljob/free", queryAllJobFree)
  158. ptest.GET("/stop", stopPtest)
  159. ptest.GET("/stopall", stopAllPtest)
  160. ptest.GET("/doptest", doPtest)
  161. ptest.GET("/doptest/scriptid", doPtestByScriptId)
  162. ptest.POST("/grpc/quickstart", grpcQuickStart)
  163. ptest.POST("/grpc/qksave", saveGrpc)
  164. ptest.POST("/grpc/run", runGrpcByScriptId)
  165. ptest.POST("/grpc/createpath", createDependencyPath)
  166. ptest.POST("/doptestfile", doPtestByFile)
  167. ptest.POST("/dobatchptest", doPtestBatch)
  168. ptest.POST("/dodebug", doDebug)
  169. }
  170. cluster := version.Group("/cluster")
  171. {
  172. cluster.GET("/info", ClusterInfo)
  173. job := version.Group("/job")
  174. {
  175. job.POST("/add", addJob)
  176. job.POST("/delete/batch", deleteJobBatch)
  177. job.DELETE("/delete", deleteJob)
  178. job.GET("/get", Job)
  179. job.GET("/clean/query", queryClearnableDocker)
  180. job.GET("/clean", cleanNotRunningJob)
  181. }
  182. }
  183. comment := version.Group("/comment")
  184. {
  185. comment.GET("/query", queryComment)
  186. comment.POST("/add", addComment)
  187. comment.POST("/update", updateComment)
  188. comment.GET("/delete", deleteComment)
  189. }
  190. label := version.Group("/label")
  191. {
  192. label.GET("/query", queryLabels)
  193. label.POST("/add", addLabel)
  194. label.GET("/del", delLabel)
  195. label.POST("/relation/add", addLabelRelation)
  196. label.GET("/relation/del", delLabelRelation)
  197. }
  198. }
  199. versiond := e.Group("/ep/admin/melloi/v2")
  200. {
  201. script := versiond.Group("script")
  202. {
  203. script.POST("/addsample", addJmeterSample)
  204. script.POST("/addtgroup", addThreadGroup)
  205. }
  206. file := versiond.Group("/file")
  207. {
  208. file.GET("/download", downloadFile)
  209. }
  210. job := versiond.Group("/job")
  211. {
  212. job.GET("/force/delete", forceDelete)
  213. }
  214. }
  215. }
  216. func register(c *bm.Context) {
  217. c.JSON(map[string]interface{}{}, nil)
  218. }
  219. func ping(c *bm.Context) {
  220. if err := srv.Ping(c); err != nil {
  221. log.Error("ping error(%v)", err)
  222. c.AbortWithStatus(http.StatusServiceUnavailable)
  223. }
  224. }