functiongraph.go 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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 huawei
  15. import (
  16. "fmt"
  17. "net/url"
  18. "time"
  19. )
  20. type SFunction struct {
  21. FuncUrn string `json:"func_urn"`
  22. FuncName string `json:"func_name"`
  23. DomainId string `json:"domain_id"`
  24. Namespace string `json:"namespace"`
  25. ProjectName string `json:"project_name"`
  26. Package string `json:"package"`
  27. Runtime string `json:"runtime"`
  28. Timeout int `json:"timeout"`
  29. Handler string `json:"handler"`
  30. MemorySize int `json:"memory_size"`
  31. CPU int `json:"cpu"`
  32. CodeType string `json:"code_type"`
  33. CodeFilename string `json:"code_filename"`
  34. CodeSize int `json:"code_size"`
  35. DomainNames string `json:"domain_names"`
  36. UserData string `json:"user_data"`
  37. Digest string `json:"digest"`
  38. Version string `json:"version"`
  39. ImageName string `json:"image_name"`
  40. Xrole string `json:"xrole"`
  41. AppXrole string `json:"app_xrole"`
  42. LastModified time.Time `json:"last_modified"`
  43. FuncCode struct {
  44. } `json:"func_code"`
  45. FuncCode0 struct {
  46. } `json:"FuncCode"`
  47. Concurrency int `json:"concurrency"`
  48. ConcurrentNum int `json:"concurrent_num"`
  49. StrategyConfig struct {
  50. Concurrency int `json:"concurrency"`
  51. ConcurrentNum int `json:"concurrent_num"`
  52. } `json:"strategy_config"`
  53. InitializerHandler string `json:"initializer_handler"`
  54. InitializerTimeout int `json:"initializer_timeout"`
  55. EnterpriseProjectId string `json:"enterprise_project_id"`
  56. FuncVpcId string `json:"func_vpc_id"`
  57. LongTime bool `json:"long_time"`
  58. LogConfig struct {
  59. GroupName string `json:"group_name"`
  60. GroupId string `json:"group_id"`
  61. StreamName string `json:"stream_name"`
  62. StreamId string `json:"stream_id"`
  63. SwitchTime int `json:"switch_time"`
  64. } `json:"log_config"`
  65. Type string `json:"type"`
  66. EnableCloudDebug string `json:"enable_cloud_debug"`
  67. EnableDynamicMemory bool `json:"enable_dynamic_memory"`
  68. CustomImage struct {
  69. } `json:"custom_image"`
  70. IsStatefulFunction bool `json:"is_stateful_function"`
  71. IsBridgeFunction bool `json:"is_bridge_function"`
  72. IsReturnStream bool `json:"is_return_stream"`
  73. EnableAuthInHeader bool `json:"enable_auth_in_header"`
  74. ReservedInstanceIdleMode bool `json:"reserved_instance_idle_mode"`
  75. EnableSnapshot bool `json:"enable_snapshot"`
  76. EphemeralStorage int `json:"ephemeral_storage"`
  77. IsShared bool `json:"is_shared"`
  78. EnableClassIsolation bool `json:"enable_class_isolation"`
  79. ResourceId string `json:"resource_id"`
  80. }
  81. func (self *SRegion) ListFunctions() ([]SFunction, error) {
  82. query := url.Values{}
  83. ret := []SFunction{}
  84. for {
  85. resp, err := self.list(SERVICE_FUNCTIONGRAPH, "fgs/functions", query)
  86. if err != nil {
  87. return nil, err
  88. }
  89. part := struct {
  90. Functions []SFunction
  91. NextMarker string
  92. }{}
  93. err = resp.Unmarshal(&part)
  94. if err != nil {
  95. return nil, err
  96. }
  97. ret = append(ret, part.Functions...)
  98. if len(part.NextMarker) == 0 || len(part.Functions) == 0 {
  99. break
  100. }
  101. query.Set("marker", part.NextMarker)
  102. }
  103. return ret, nil
  104. }
  105. type SWorkerflow struct {
  106. Id string
  107. Name string
  108. }
  109. func (self *SRegion) ListWorkerflows() ([]SWorkerflow, error) {
  110. query := url.Values{}
  111. query.Set("limit", "200")
  112. ret := []SWorkerflow{}
  113. for {
  114. resp, err := self.list(SERVICE_FUNCTIONGRAPH, "fgs/workflows", query)
  115. if err != nil {
  116. return nil, err
  117. }
  118. part := struct {
  119. Workflows []SWorkerflow
  120. Total int
  121. }{}
  122. err = resp.Unmarshal(&part)
  123. if err != nil {
  124. return nil, err
  125. }
  126. ret = append(ret, part.Workflows...)
  127. if len(ret) >= part.Total || len(part.Workflows) == 0 {
  128. break
  129. }
  130. query.Set("offset", fmt.Sprintf("%d", len(ret)))
  131. }
  132. return ret, nil
  133. }