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.

ScheduleCloud.go 2.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package kq
  2. import (
  3. "bytes"
  4. "context"
  5. "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/pkg/scheduler"
  6. "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
  7. "gitlink.org.cn/jcce-pcm/pcm-coordinator/model"
  8. "io"
  9. "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
  10. "k8s.io/apimachinery/pkg/runtime"
  11. syaml "k8s.io/apimachinery/pkg/runtime/serializer/yaml"
  12. kyaml "k8s.io/apimachinery/pkg/util/yaml"
  13. )
  14. /*
  15. *
  16. Listening to the payment flow status change notification message queue
  17. */
  18. type ScheduleCloudMq struct {
  19. ctx context.Context
  20. svcCtx *svc.ServiceContext
  21. }
  22. func NewScheduleCloudMq(ctx context.Context, svcCtx *svc.ServiceContext) *ScheduleCloudMq {
  23. return &ScheduleCloudMq{
  24. ctx: ctx,
  25. svcCtx: svcCtx,
  26. }
  27. }
  28. func UnMarshalK8sStruct(yamlString string, taskId int64) model.Cloud {
  29. var cloud model.Cloud
  30. d := kyaml.NewYAMLOrJSONDecoder(bytes.NewBufferString(yamlString), 4096)
  31. var err error
  32. for {
  33. var rawObj runtime.RawExtension
  34. err = d.Decode(&rawObj)
  35. if err == io.EOF {
  36. break
  37. }
  38. if err != nil {
  39. }
  40. obj := &unstructured.Unstructured{}
  41. syaml.NewDecodingSerializer(unstructured.UnstructuredJSONScheme).Decode(rawObj.Raw, nil, obj)
  42. if err != nil {
  43. }
  44. unstructuredMap, err := runtime.DefaultUnstructuredConverter.ToUnstructured(obj)
  45. if err != nil {
  46. }
  47. unstructureObj := &unstructured.Unstructured{Object: unstructuredMap}
  48. cloud = model.Cloud{
  49. TaskId: taskId,
  50. ApiVersion: unstructureObj.GetAPIVersion(),
  51. Name: unstructureObj.GetName(),
  52. Kind: unstructureObj.GetKind(),
  53. Namespace: unstructureObj.GetNamespace(),
  54. Status: "Saved",
  55. }
  56. }
  57. return cloud
  58. }
  59. func (l *ScheduleCloudMq) Consume(_, val string) error {
  60. // 接受消息, 根据标签筛选过滤
  61. cloudScheduler := scheduler.NewCloudScheduler()
  62. scheduler, err := scheduler.NewScheduler(cloudScheduler, val)
  63. if err != nil {
  64. return err
  65. }
  66. scheduler.MatchLabels(l.svcCtx.DbEngin)
  67. // 存储数据
  68. err = scheduler.SaveToDb(l.svcCtx.DbEngin)
  69. if err != nil {
  70. return err
  71. }
  72. return nil
  73. }

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.