You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

task_impl.go 2.3 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package client
  2. import (
  3. "io/ioutil"
  4. "k8s.io/apimachinery/pkg/util/json"
  5. "log"
  6. "net/http"
  7. "strings"
  8. "sync"
  9. )
  10. type task struct {
  11. sync.RWMutex
  12. client *client
  13. options *TaskOptions
  14. log log.Logger
  15. }
  16. func newTask(client *client, options *TaskOptions) (*task, error) {
  17. task := &task{
  18. RWMutex: sync.RWMutex{},
  19. client: client,
  20. options: options,
  21. log: log.Logger{},
  22. }
  23. return task, nil
  24. }
  25. func (t *task) PullTaskInfo(pullTaskInfoReq PullTaskInfoReq) (*PullTaskInfoResp, error) {
  26. url := t.client.url + "/pcm/v1/core/pullTaskInfo"
  27. method := "GET"
  28. infoReq := PullTaskInfoReq{AdapterId: pullTaskInfoReq.AdapterId}
  29. jsonStr, _ := json.Marshal(infoReq)
  30. payload := strings.NewReader(string(jsonStr))
  31. client := &http.Client{}
  32. req, _ := http.NewRequest(method, url, payload)
  33. req.Header.Add("Content-Type", "application/json")
  34. res, _ := client.Do(req)
  35. defer res.Body.Close()
  36. body, _ := ioutil.ReadAll(res.Body)
  37. var resp PullTaskInfoResp
  38. json.Unmarshal(body, &resp)
  39. return &resp, nil
  40. }
  41. func (t *task) PushTaskInfo(pushTaskInfoReq PushTaskInfoReq) (*PushTaskInfoResp, error) {
  42. url := t.client.url + "/pcm/v1/core/pushTaskInfo"
  43. method := "POST"
  44. //infoReq := PullTaskInfoReq{AdapterId: pushTaskInfoReq.AdapterId}
  45. jsonStr, _ := json.Marshal(pushTaskInfoReq)
  46. payload := strings.NewReader(string(jsonStr))
  47. client := &http.Client{}
  48. req, _ := http.NewRequest(method, url, payload)
  49. req.Header.Add("Content-Type", "application/json")
  50. res, _ := client.Do(req)
  51. defer res.Body.Close()
  52. body, _ := ioutil.ReadAll(res.Body)
  53. var resp PushTaskInfoResp
  54. json.Unmarshal(body, &resp)
  55. return &resp, nil
  56. }
  57. func (t *task) PushResourceInfo(pushResourceInfoReq PushResourceInfoReq) (*PushResourceInfoResp, error) {
  58. url := t.client.url + "/pcm/v1/core/pushResourceInfo"
  59. method := "POST"
  60. //infoReq := PushResourceInfoReq{AdapterId: pushResourceInfoReq.AdapterId}
  61. jsonStr, _ := json.Marshal(pushResourceInfoReq)
  62. payload := strings.NewReader(string(jsonStr))
  63. client := &http.Client{}
  64. req, _ := http.NewRequest(method, url, payload)
  65. req.Header.Add("Content-Type", "application/json")
  66. res, _ := client.Do(req)
  67. defer res.Body.Close()
  68. body, _ := ioutil.ReadAll(res.Body)
  69. var resp PushResourceInfoResp
  70. json.Unmarshal(body, &resp)
  71. return &resp, nil
  72. }

PCM is positioned as Software stack over Cloud, aiming to build the standards and ecology of heterogeneous cloud collaboration for JCC in a non intrusive and autonomous peer-to-peer manner.