rocketmq4.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package aliyun
  15. import (
  16. "fmt"
  17. "yunion.io/x/jsonutils"
  18. "yunion.io/x/pkg/errors"
  19. )
  20. const (
  21. ROCKYMQ4_API_VERSION = "2019-02-14"
  22. )
  23. type SRocketmq4Instance struct {
  24. InstanceId string
  25. InstanceName string
  26. }
  27. func (self *SRegion) onsRequest(apiName string, params map[string]string, body interface{}) (jsonutils.JSONObject, error) {
  28. client, err := self.getSdkClient()
  29. if err != nil {
  30. return nil, err
  31. }
  32. params = self.client.SetResourceGropuId(params)
  33. return doRequest(client, fmt.Sprintf("ons.%s.aliyuncs.com", self.RegionId), ROCKYMQ4_API_VERSION, apiName, params, body, self.client.debug)
  34. }
  35. func (region *SRegion) GetRocketmq4Instances() ([]SRocketmq4Instance, error) {
  36. params := map[string]string{}
  37. resp, err := region.onsRequest("OnsInstanceInServiceList", params, nil)
  38. if err != nil {
  39. return nil, errors.Wrapf(err, "OnsInstanceInServiceList")
  40. }
  41. ret := []SRocketmq4Instance{}
  42. return ret, resp.Unmarshal(&ret, "Data", "InstanceVO")
  43. }