cluster.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package dao
  2. import (
  3. "context"
  4. "net/http"
  5. "go-common/app/admin/ep/melloi/conf"
  6. "go-common/app/admin/ep/melloi/model"
  7. "go-common/library/ecode"
  8. "go-common/library/log"
  9. )
  10. const (
  11. _rmTokenURI = "/api/v1/auth"
  12. _clusterNodeURI = "/api/v1/clusters?env=uat"
  13. )
  14. //RmToken get PaaS token
  15. func (d *Dao) RmToken(c context.Context) (token string, err error) {
  16. var (
  17. req *http.Request
  18. tokenURL = d.c.ServiceCluster.TestHost + _rmTokenURI
  19. res = &model.ClusterRmTokenResponse{}
  20. rmTokenPost = &model.RmTokenPost{
  21. APIToken: conf.Conf.Paas.APIToken,
  22. PlatformID: conf.Conf.Paas.PlatformID,
  23. }
  24. )
  25. if req, err = d.newRequest(http.MethodPost, tokenURL, rmTokenPost); err != nil {
  26. log.Error("query paas machine url(%s) err(%v)", tokenURL, err)
  27. return
  28. }
  29. if err = d.httpClient.Do(c, req, &res); err != nil {
  30. log.Error("RmToken error :(%v)", err)
  31. err = ecode.MelloiPaasRequestErr
  32. return
  33. }
  34. if err = res.CheckStatus(); err != nil {
  35. return
  36. }
  37. token = res.Data.Token
  38. return
  39. }
  40. //NetInfo get melloi server use
  41. func (d *Dao) NetInfo(c context.Context, token string) (cluster []*model.ClusterResponseItemsSon, err error) {
  42. var (
  43. url = d.c.ServiceCluster.UatHost + _clusterNodeURI
  44. req *http.Request
  45. resCluster = &model.ClusterResponse{}
  46. )
  47. if req, err = d.newRequest(http.MethodGet, url, nil); err != nil {
  48. return
  49. }
  50. req.Header.Set("Content-Type", "application/json")
  51. req.Header.Set("X-Authorization-Token", token)
  52. if err = d.httpClient.Do(c, req, &resCluster); err != nil {
  53. log.Error("d.Token url(%s) res($s) err(%v)", url, err)
  54. err = ecode.MelloiPaasRequestErr
  55. return
  56. }
  57. if err = resCluster.CheckStatus(); err != nil {
  58. return
  59. }
  60. cluster = resCluster.Data.Items
  61. return
  62. }