mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #17525 from gouqi11/fixHcsoProviderDescriber
20230714 make mod
This commit is contained in:
@@ -83,14 +83,14 @@ require (
|
||||
k8s.io/client-go v0.19.3
|
||||
k8s.io/cluster-bootstrap v0.19.3
|
||||
moul.io/http2curl/v2 v2.3.0
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20230711074211-bf76b0fe29f4
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20230714020436-02f1bfcc8e8e
|
||||
yunion.io/x/executor v0.0.0-20230705125604-c5ac3141db32
|
||||
yunion.io/x/jsonutils v1.0.1-0.20230613121553-0f3b41e2ef19
|
||||
yunion.io/x/log v1.0.1-0.20230411060016-feb3f46ab361
|
||||
yunion.io/x/ovsdb v0.0.0-20230306173834-f164f413a900
|
||||
yunion.io/x/pkg v1.0.1-0.20230705150700-c631d3f97d59
|
||||
yunion.io/x/pkg v1.0.1-0.20230711090507-0aafe0f0c9db
|
||||
yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e
|
||||
yunion.io/x/sqlchemy v1.1.2-0.20230710004318-67f7407c437d
|
||||
yunion.io/x/sqlchemy v1.1.2-0.20230712025503-b1892bc5944c
|
||||
yunion.io/x/structarg v0.0.0-20220312084958-9c6c79c7d1c6
|
||||
)
|
||||
|
||||
|
||||
@@ -1174,8 +1174,8 @@ sigs.k8s.io/structured-merge-diff/v4 v4.0.1/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK
|
||||
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
|
||||
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
|
||||
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20230711074211-bf76b0fe29f4 h1:BAwf1F8DLnOexasolyHQMpNVRWdMM82ex97jfsyUJZ8=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20230711074211-bf76b0fe29f4/go.mod h1:crMeQeaNaZefTXfXbQkoj5SStggqkSNVABHtYBFjM3Y=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20230714020436-02f1bfcc8e8e h1:5X432B4i7RMiA76FAFwQueyIvyw3t0LgjyrS+a37wfA=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20230714020436-02f1bfcc8e8e/go.mod h1:2sgCN7nRPQL3woLfdgqLDd92vwAHqtlz3KKiHxC5BAw=
|
||||
yunion.io/x/executor v0.0.0-20230705125604-c5ac3141db32 h1:v7POYkQwo1XzOxBoIoRVr/k0V9Y5JyjpshlIFa9raug=
|
||||
yunion.io/x/executor v0.0.0-20230705125604-c5ac3141db32/go.mod h1:Uxuou9WQIeJXNpy7t2fPLL0BYLvLiMvGQwY7Qc6aSws=
|
||||
yunion.io/x/jsonutils v0.0.0-20190625054549-a964e1e8a051/go.mod h1:4N0/RVzsYL3kH3WE/H1BjUQdFiWu50JGCFQuuy+Z634=
|
||||
@@ -1189,11 +1189,11 @@ yunion.io/x/ovsdb v0.0.0-20230306173834-f164f413a900 h1:Hu/4ERvoWaN6aiFs4h4/yvVB
|
||||
yunion.io/x/ovsdb v0.0.0-20230306173834-f164f413a900/go.mod h1:0vLkNEhlmA64HViPBAnSTUMrx5QP1CLsxXmxDKQ80tc=
|
||||
yunion.io/x/pkg v0.0.0-20190620104149-945c25821dbf/go.mod h1:t6rEGG2sQ4J7DhFxSZVOTjNd0YO/KlfWQyK1W4tog+E=
|
||||
yunion.io/x/pkg v0.0.0-20190628082551-f4033ba2ea30/go.mod h1:t6rEGG2sQ4J7DhFxSZVOTjNd0YO/KlfWQyK1W4tog+E=
|
||||
yunion.io/x/pkg v1.0.1-0.20230705150700-c631d3f97d59 h1:en9Mh7bfR2R2EZgA+QJWstl2WzK+ICt2aNEJAw8KXA4=
|
||||
yunion.io/x/pkg v1.0.1-0.20230705150700-c631d3f97d59/go.mod h1:ksCJVQ+DwKrJ5QBEoU8pzrDFfDaZVAFH/iJ6yQCYxJk=
|
||||
yunion.io/x/pkg v1.0.1-0.20230711090507-0aafe0f0c9db h1:GyBvo/gYl2MY5Q0SZ6Nso8WJHPonmngOtcpVfyCE0yA=
|
||||
yunion.io/x/pkg v1.0.1-0.20230711090507-0aafe0f0c9db/go.mod h1:ksCJVQ+DwKrJ5QBEoU8pzrDFfDaZVAFH/iJ6yQCYxJk=
|
||||
yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e h1:v+EzIadodSwkdZ/7bremd7J8J50Cise/HCylsOJngmo=
|
||||
yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e/go.mod h1:0iFKpOs1y4lbCxeOmq3Xx/0AcQoewVPwj62eRluioEo=
|
||||
yunion.io/x/sqlchemy v1.1.2-0.20230710004318-67f7407c437d h1:1VTL8DO3t8xZDLD/gFRHwaLwXlE/nd/r6ES1NtTpo1A=
|
||||
yunion.io/x/sqlchemy v1.1.2-0.20230710004318-67f7407c437d/go.mod h1:uuPVZEyEq3sWd5vf9VjGSy6lZzof22X87OEHw9sddJQ=
|
||||
yunion.io/x/sqlchemy v1.1.2-0.20230712025503-b1892bc5944c h1:jlJkjiL1jv6mpdV3Z0RdeEWB5U3qEwUnSjioGZmki70=
|
||||
yunion.io/x/sqlchemy v1.1.2-0.20230712025503-b1892bc5944c/go.mod h1:uuPVZEyEq3sWd5vf9VjGSy6lZzof22X87OEHw9sddJQ=
|
||||
yunion.io/x/structarg v0.0.0-20220312084958-9c6c79c7d1c6 h1:WuWXhY3DvhdRTzWCJ/kwt3Ss6KIq7+KqJwb+esvNGwU=
|
||||
yunion.io/x/structarg v0.0.0-20220312084958-9c6c79c7d1c6/go.mod h1:EP6NSv2C0zzqBDTKumv8hPWLb3XvgMZDHQRfyuOrQng=
|
||||
|
||||
@@ -310,6 +310,8 @@ type SHCSOAccountCreateOptions struct {
|
||||
SCloudAccountCreateBaseOptions
|
||||
cloudprovider.SHCSOEndpoints
|
||||
SAccessKeyCredential
|
||||
|
||||
DefaultRegion string `json:"default_region"`
|
||||
}
|
||||
|
||||
func (opts *SHCSOAccountCreateOptions) Params() (jsonutils.JSONObject, error) {
|
||||
|
||||
Vendored
+3
-3
@@ -1440,7 +1440,7 @@ sigs.k8s.io/structured-merge-diff/v4/value
|
||||
# sigs.k8s.io/yaml v1.2.0
|
||||
## explicit; go 1.12
|
||||
sigs.k8s.io/yaml
|
||||
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20230711074211-bf76b0fe29f4
|
||||
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20230714020436-02f1bfcc8e8e
|
||||
## explicit; go 1.18
|
||||
yunion.io/x/cloudmux/pkg/apis
|
||||
yunion.io/x/cloudmux/pkg/apis/billing
|
||||
@@ -1531,7 +1531,7 @@ yunion.io/x/log/hooks
|
||||
yunion.io/x/ovsdb/cli_util
|
||||
yunion.io/x/ovsdb/schema/ovn_nb
|
||||
yunion.io/x/ovsdb/types
|
||||
# yunion.io/x/pkg v1.0.1-0.20230705150700-c631d3f97d59
|
||||
# yunion.io/x/pkg v1.0.1-0.20230711090507-0aafe0f0c9db
|
||||
## explicit; go 1.18
|
||||
yunion.io/x/pkg/appctx
|
||||
yunion.io/x/pkg/errors
|
||||
@@ -1586,7 +1586,7 @@ yunion.io/x/pkg/utils
|
||||
# yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e
|
||||
## explicit; go 1.12
|
||||
yunion.io/x/s3cli
|
||||
# yunion.io/x/sqlchemy v1.1.2-0.20230710004318-67f7407c437d
|
||||
# yunion.io/x/sqlchemy v1.1.2-0.20230712025503-b1892bc5944c
|
||||
## explicit; go 1.17
|
||||
yunion.io/x/sqlchemy
|
||||
yunion.io/x/sqlchemy/backends
|
||||
|
||||
+1
-1
@@ -759,7 +759,7 @@ func (ae AzureResponseError) Error() string {
|
||||
return jsonutils.Marshal(ae).String()
|
||||
}
|
||||
|
||||
func (ae *AzureResponseError) ParseErrorFromJsonResponse(statusCode int, body jsonutils.JSONObject) error {
|
||||
func (ae *AzureResponseError) ParseErrorFromJsonResponse(statusCode int, status string, body jsonutils.JSONObject) error {
|
||||
if body != nil {
|
||||
body.Unmarshal(ae)
|
||||
}
|
||||
|
||||
+1
-1
@@ -860,7 +860,7 @@ func (g *gError) Error() string {
|
||||
return jsonutils.Marshal(g).String()
|
||||
}
|
||||
|
||||
func (g *gError) ParseErrorFromJsonResponse(statusCode int, body jsonutils.JSONObject) error {
|
||||
func (g *gError) ParseErrorFromJsonResponse(statusCode int, status string, body jsonutils.JSONObject) error {
|
||||
if body != nil {
|
||||
body.Unmarshal(g)
|
||||
}
|
||||
|
||||
+1
-1
@@ -176,7 +176,7 @@ func (ce *HuaweiClientError) Error() string {
|
||||
return jsonutils.Marshal(ce).String()
|
||||
}
|
||||
|
||||
func (ce *HuaweiClientError) ParseErrorFromJsonResponse(statusCode int, body jsonutils.JSONObject) error {
|
||||
func (ce *HuaweiClientError) ParseErrorFromJsonResponse(statusCode int, status string, body jsonutils.JSONObject) error {
|
||||
if body != nil {
|
||||
body.Unmarshal(ce)
|
||||
}
|
||||
|
||||
+1
@@ -353,6 +353,7 @@ func (self *SHuaweiClient) GetSubAccounts() ([]cloudprovider.SSubAccount, error)
|
||||
Name: fmt.Sprintf("%s-%s", self.cpcfg.Name, project.Name),
|
||||
Account: fmt.Sprintf("%s/%s", self.accessKey, project.ID),
|
||||
HealthStatus: project.GetHealthStatus(),
|
||||
Desc: project.GetDescription(),
|
||||
}
|
||||
|
||||
subAccounts = append(subAccounts, s)
|
||||
|
||||
+4
@@ -346,6 +346,10 @@ func (self *SInstance) GetCreatedAt() time.Time {
|
||||
return self.Created
|
||||
}
|
||||
|
||||
func (self *SInstance) GetDescription() string {
|
||||
return self.Description
|
||||
}
|
||||
|
||||
// charging_mode “0”:按需计费 “1”:按包年包月计费
|
||||
func (self *SInstance) GetExpiredAt() time.Time {
|
||||
var expiredTime time.Time
|
||||
|
||||
+4
@@ -40,6 +40,10 @@ func (self *SProject) GetRegionID() string {
|
||||
return strings.Split(self.Name, "_")[0]
|
||||
}
|
||||
|
||||
func (self *SProject) GetDescription() string {
|
||||
return self.Description
|
||||
}
|
||||
|
||||
func (self *SProject) GetHealthStatus() string {
|
||||
if self.Enabled {
|
||||
return api.CLOUD_PROVIDER_HEALTH_NORMAL
|
||||
|
||||
+1
-1
@@ -178,7 +178,7 @@ func (ce *HuaweiClientError) Error() string {
|
||||
return jsonutils.Marshal(ce).String()
|
||||
}
|
||||
|
||||
func (ce *HuaweiClientError) ParseErrorFromJsonResponse(statusCode int, body jsonutils.JSONObject) error {
|
||||
func (ce *HuaweiClientError) ParseErrorFromJsonResponse(statusCode int, status string, body jsonutils.JSONObject) error {
|
||||
if body != nil {
|
||||
body.Unmarshal(ce)
|
||||
}
|
||||
|
||||
+1
@@ -595,6 +595,7 @@ func (self *SHuaweiClient) GetSubAccounts() ([]cloudprovider.SSubAccount, error)
|
||||
Account: fmt.Sprintf("%s/%s", self.accessKey, project.ID),
|
||||
HealthStatus: project.GetHealthStatus(),
|
||||
DefaultProjectId: "0",
|
||||
Desc: project.GetDescription(),
|
||||
}
|
||||
for j := range self.iregions {
|
||||
region := self.iregions[j].(*SRegion)
|
||||
|
||||
+4
@@ -346,6 +346,10 @@ func (self *SInstance) GetCreatedAt() time.Time {
|
||||
return self.Created
|
||||
}
|
||||
|
||||
func (self *SInstance) GetDescription() string {
|
||||
return self.Description
|
||||
}
|
||||
|
||||
// charging_mode “0”:按需计费 “1”:按包年包月计费
|
||||
func (self *SInstance) GetExpiredAt() time.Time {
|
||||
if len(self.Metadata.MeteringOrderId) > 0 {
|
||||
|
||||
+84
-1
@@ -15,10 +15,12 @@
|
||||
package huawei
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/util/osprofile"
|
||||
|
||||
api "yunion.io/x/cloudmux/pkg/apis/compute"
|
||||
"yunion.io/x/cloudmux/pkg/cloudprovider"
|
||||
@@ -57,6 +59,8 @@ func (self *SHuaweiClient) getServerMetrics(opts *cloudprovider.MetricListOption
|
||||
metrics := []interface{}{}
|
||||
namespace, dimesionName, metricNames := "SYS.ECS", "instance_id", []string{
|
||||
"cpu_util",
|
||||
"mem_util",
|
||||
"disk_util_inband",
|
||||
"network_incoming_bytes_aggregate_rate",
|
||||
"network_outgoing_bytes_aggregate_rate",
|
||||
"disk_read_bytes_rate",
|
||||
@@ -97,6 +101,10 @@ func (self *SHuaweiClient) getServerMetrics(opts *cloudprovider.MetricListOption
|
||||
switch metricData[i].MetricName {
|
||||
case "cpu_util":
|
||||
ret.MetricType = cloudprovider.VM_METRIC_TYPE_CPU_USAGE
|
||||
case "disk_util_inband":
|
||||
ret.MetricType = cloudprovider.VM_METRIC_TYPE_DISK_USAGE
|
||||
case "mem_util":
|
||||
ret.MetricType = cloudprovider.VM_METRIC_TYPE_MEM_USAGE
|
||||
case "network_incoming_bytes_aggregate_rate":
|
||||
ret.MetricType = cloudprovider.VM_METRIC_TYPE_NET_BPS_RX
|
||||
tags = map[string]string{"net_type": "internet"}
|
||||
@@ -128,6 +136,72 @@ func (self *SHuaweiClient) getServerMetrics(opts *cloudprovider.MetricListOption
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (self *SHuaweiClient) getServerAgentMetrics(opts *cloudprovider.MetricListOptions) ([]cloudprovider.MetricValues, error) {
|
||||
if strings.ToLower(opts.OsType) == strings.ToLower(osprofile.OS_TYPE_WINDOWS) {
|
||||
return []cloudprovider.MetricValues{}, nil
|
||||
}
|
||||
params := map[string]interface{}{
|
||||
"from": opts.StartTime.UnixMilli(),
|
||||
"to": opts.EndTime.UnixMilli(),
|
||||
"period": "1",
|
||||
"filter": "average",
|
||||
}
|
||||
metrics := []interface{}{}
|
||||
namespace, dimesionName, metricNames := "AGT.ECS", "instance_id", []string{
|
||||
"mem_usedPercent",
|
||||
}
|
||||
for _, metricName := range metricNames {
|
||||
metrics = append(metrics, map[string]interface{}{
|
||||
"namespace": namespace,
|
||||
"metric_name": metricName,
|
||||
"dimensions": []map[string]string{
|
||||
{
|
||||
"name": dimesionName,
|
||||
"value": opts.ResourceId,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
params["metrics"] = metrics
|
||||
resp, err := self.monitorPost("batch-query-metric-data", params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
metricData := []MetricData{}
|
||||
err = resp.Unmarshal(&metricData, "metrics")
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "resp.Unmarshal")
|
||||
}
|
||||
result := []cloudprovider.MetricValues{}
|
||||
for i := range metricData {
|
||||
ret := cloudprovider.MetricValues{
|
||||
Id: opts.ResourceId,
|
||||
Unit: metricData[i].Unit,
|
||||
Values: []cloudprovider.MetricValue{},
|
||||
}
|
||||
tags := map[string]string{}
|
||||
switch metricData[i].MetricName {
|
||||
case "mem_usedPercent":
|
||||
ret.MetricType = cloudprovider.VM_METRIC_TYPE_MEM_USAGE
|
||||
case "disk_usedPercent":
|
||||
ret.MetricType = cloudprovider.VM_METRIC_TYPE_DISK_USAGE
|
||||
default:
|
||||
log.Warningf("invalid metricName %s for %s %s", metricData[i].MetricName, opts.ResourceType, opts.ResourceId)
|
||||
continue
|
||||
}
|
||||
for _, value := range metricData[i].Datapoints {
|
||||
metricValue := cloudprovider.MetricValue{
|
||||
Value: value.Average,
|
||||
Timestamp: time.UnixMilli(value.Timestamp),
|
||||
Tags: tags,
|
||||
}
|
||||
ret.Values = append(ret.Values, metricValue)
|
||||
}
|
||||
result = append(result, ret)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (self *SHuaweiClient) getRedisMetrics(opts *cloudprovider.MetricListOptions) ([]cloudprovider.MetricValues, error) {
|
||||
params := map[string]interface{}{
|
||||
"from": opts.StartTime.UnixMilli(),
|
||||
@@ -545,7 +619,16 @@ func (self *SHuaweiClient) getModelartsPoolMetrics(opts *cloudprovider.MetricLis
|
||||
func (self *SHuaweiClient) GetMetrics(opts *cloudprovider.MetricListOptions) ([]cloudprovider.MetricValues, error) {
|
||||
switch opts.ResourceType {
|
||||
case cloudprovider.METRIC_RESOURCE_TYPE_SERVER:
|
||||
return self.getServerMetrics(opts)
|
||||
ret, err := self.getServerMetrics(opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
agent, err := self.getServerAgentMetrics(opts)
|
||||
if err != nil {
|
||||
return ret, nil
|
||||
}
|
||||
ret = append(ret, agent...)
|
||||
return ret, nil
|
||||
case cloudprovider.METRIC_RESOURCE_TYPE_REDIS:
|
||||
return self.getRedisMetrics(opts)
|
||||
case cloudprovider.METRIC_RESOURCE_TYPE_RDS:
|
||||
|
||||
+4
@@ -38,6 +38,10 @@ func (self *SProject) GetRegionID() string {
|
||||
return strings.Split(self.Name, "_")[0]
|
||||
}
|
||||
|
||||
func (self *SProject) GetDescription() string {
|
||||
return self.Description
|
||||
}
|
||||
|
||||
func (self *SProject) GetHealthStatus() string {
|
||||
if self.Enabled {
|
||||
return api.CLOUD_PROVIDER_HEALTH_NORMAL
|
||||
|
||||
+1
-1
@@ -355,7 +355,7 @@ func (self *sNutanixError) Error() string {
|
||||
return jsonutils.Marshal(self).String()
|
||||
}
|
||||
|
||||
func (self *sNutanixError) ParseErrorFromJsonResponse(statusCode int, body jsonutils.JSONObject) error {
|
||||
func (self *sNutanixError) ParseErrorFromJsonResponse(statusCode int, status string, body jsonutils.JSONObject) error {
|
||||
if body != nil {
|
||||
body.Unmarshal(self)
|
||||
}
|
||||
|
||||
+1
-1
@@ -169,7 +169,7 @@ type OpenstackError struct {
|
||||
httputils.JSONClientError
|
||||
}
|
||||
|
||||
func (ce *OpenstackError) ParseErrorFromJsonResponse(statusCode int, body jsonutils.JSONObject) error {
|
||||
func (ce *OpenstackError) ParseErrorFromJsonResponse(statusCode int, status string, body jsonutils.JSONObject) error {
|
||||
if body != nil {
|
||||
body.Unmarshal(ce)
|
||||
}
|
||||
|
||||
+5
-3
@@ -137,13 +137,15 @@ type ProxmoxError struct {
|
||||
Code int
|
||||
Params []string
|
||||
Errors string
|
||||
Status string
|
||||
}
|
||||
|
||||
func (self ProxmoxError) Error() string {
|
||||
return fmt.Sprintf("[%d] %s with params %s", self.Code, self.Message, self.Params)
|
||||
return jsonutils.Marshal(self).String()
|
||||
}
|
||||
|
||||
func (ce *ProxmoxError) ParseErrorFromJsonResponse(statusCode int, body jsonutils.JSONObject) error {
|
||||
func (ce *ProxmoxError) ParseErrorFromJsonResponse(statusCode int, status string, body jsonutils.JSONObject) error {
|
||||
ce.Status = status
|
||||
if body != nil {
|
||||
body.Unmarshal(ce)
|
||||
log.Errorf("error: %v", body.PrettyString())
|
||||
@@ -290,7 +292,7 @@ func (cli *SProxmoxClient) __jsonRequest(method httputils.THttpMethod, res strin
|
||||
oe := &ProxmoxError{}
|
||||
_, resp, err := client.Send(context.Background(), req, oe, cli.debug)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "with params: %v", params)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
|
||||
+3
-3
@@ -212,10 +212,10 @@ func NewJsonRequest(method THttpMethod, url string, params interface{}) *JsonBas
|
||||
}
|
||||
|
||||
type JsonResponse interface {
|
||||
ParseErrorFromJsonResponse(statusCode int, body jsonutils.JSONObject) error
|
||||
ParseErrorFromJsonResponse(statusCode int, status string, body jsonutils.JSONObject) error
|
||||
}
|
||||
|
||||
func (ce *JSONClientError) ParseErrorFromJsonResponse(statusCode int, body jsonutils.JSONObject) error {
|
||||
func (ce *JSONClientError) ParseErrorFromJsonResponse(statusCode int, status string, body jsonutils.JSONObject) error {
|
||||
body.Unmarshal(ce)
|
||||
if ce.Code == 0 {
|
||||
ce.Code = statusCode
|
||||
@@ -734,7 +734,7 @@ func (client *JsonClient) Send(ctx context.Context, req JsonRequest, response Js
|
||||
return resp.Header, jrbody, &ce
|
||||
}
|
||||
|
||||
return resp.Header, jrbody, response.ParseErrorFromJsonResponse(resp.StatusCode, jrbody)
|
||||
return resp.Header, jrbody, response.ParseErrorFromJsonResponse(resp.StatusCode, resp.Status, jrbody)
|
||||
}
|
||||
|
||||
func IsRedirectError(err error) bool {
|
||||
|
||||
+1
@@ -54,6 +54,7 @@ func parseIndexes(ts sqlchemy.ITableSpec, defStr string) []sqlchemy.STableIndex
|
||||
for i := range matches {
|
||||
tcs[i] = sqlchemy.NewTableIndex(
|
||||
ts,
|
||||
matches[i][2],
|
||||
fetchColumns(matches[i][3]),
|
||||
len(matches[i][1]) > 0,
|
||||
)
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ func (mysql *SMySQLBackend) CommitTableChangeSQL(ts sqlchemy.ITableSpec, changes
|
||||
ret := make([]string, 0)
|
||||
|
||||
for _, idx := range changes.RemoveIndexes {
|
||||
sql := fmt.Sprintf("DROP INDEX `%s` ON `%s`", idx.RawName(), ts.Name())
|
||||
sql := fmt.Sprintf("DROP INDEX `%s` ON `%s`", idx.Name(), ts.Name())
|
||||
ret = append(ret, sql)
|
||||
log.Infof("%s;", sql)
|
||||
}
|
||||
|
||||
+2
-2
@@ -23,7 +23,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
indexPattern = `\((?P<cols>` + "`" + `\w+` + "`" + `(,\s*` + "`" + `\w+` + "`" + `)*)\)`
|
||||
indexPattern = `CREATE\s+INDEX\s+` + "`" + `(?P<name>\w+)` + "`" + `\s+ON\s+` + "`" + `(?P<tblname>\w+)` + "`" + `\s*\((?P<cols>` + "`" + `\w+` + "`" + `(,\s*` + "`" + `\w+` + "`" + `)*)\)`
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -39,7 +39,7 @@ type sSqliteTableInfo struct {
|
||||
func (ti *sSqliteTableInfo) parseTableIndex(ts sqlchemy.ITableSpec) (sqlchemy.STableIndex, error) {
|
||||
matches := indexRegexp.FindAllStringSubmatch(ti.Sql, -1)
|
||||
if len(matches) > 0 {
|
||||
return sqlchemy.NewTableIndex(ts, sqlchemy.FetchColumns(matches[0][1]), false), nil
|
||||
return sqlchemy.NewTableIndex(ts, matches[0][1], sqlchemy.FetchColumns(matches[0][3]), false), nil
|
||||
}
|
||||
return sqlchemy.STableIndex{}, errors.ErrNotFound
|
||||
}
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ func (sqlite *SSqliteBackend) CommitTableChangeSQL(ts sqlchemy.ITableSpec, chang
|
||||
ret := make([]string, 0)
|
||||
|
||||
for _, idx := range changes.RemoveIndexes {
|
||||
sql := fmt.Sprintf("DROP INDEX IF EXISTS `%s`.`%s`", ts.Name(), idx.RawName())
|
||||
sql := fmt.Sprintf("DROP INDEX IF EXISTS `%s`.`%s`", ts.Name(), idx.Name())
|
||||
ret = append(ret, sql)
|
||||
log.Infof("%s;", sql)
|
||||
}
|
||||
|
||||
+20
-21
@@ -21,24 +21,22 @@ import (
|
||||
)
|
||||
|
||||
type STableIndex struct {
|
||||
// name string
|
||||
columns []string
|
||||
rawColumns []string
|
||||
isUnique bool
|
||||
name string
|
||||
columns []string
|
||||
|
||||
isUnique bool
|
||||
|
||||
ts ITableSpec
|
||||
}
|
||||
|
||||
func NewTableIndex(ts ITableSpec, cols []string, unique bool) STableIndex {
|
||||
rawCols := make([]string, len(cols))
|
||||
copy(rawCols, cols)
|
||||
func NewTableIndex(ts ITableSpec, name string, cols []string, unique bool) STableIndex {
|
||||
sort.Sort(TColumnNames(cols))
|
||||
return STableIndex{
|
||||
// name: name,
|
||||
columns: cols,
|
||||
rawColumns: rawCols,
|
||||
isUnique: unique,
|
||||
ts: ts,
|
||||
name: name,
|
||||
columns: cols,
|
||||
|
||||
isUnique: unique,
|
||||
ts: ts,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,17 +59,14 @@ func (cols TColumnNames) Less(i, j int) bool {
|
||||
}
|
||||
|
||||
func (index *STableIndex) Name() string {
|
||||
if len(index.name) > 0 {
|
||||
return index.name
|
||||
}
|
||||
return fmt.Sprintf("ix_%s_%s", index.ts.Name(), strings.Join(index.columns, "_"))
|
||||
}
|
||||
|
||||
func (index *STableIndex) RawName() string {
|
||||
return fmt.Sprintf("ix_%s_%s", index.ts.Name(), strings.Join(index.rawColumns, "_"))
|
||||
}
|
||||
|
||||
func (index STableIndex) clone(ts ITableSpec) STableIndex {
|
||||
cols := make([]string, len(index.rawColumns))
|
||||
copy(cols, index.rawColumns)
|
||||
return NewTableIndex(ts, cols, index.isUnique)
|
||||
return NewTableIndex(ts, "", index.columns, index.isUnique)
|
||||
}
|
||||
|
||||
func (index *STableIndex) IsIdentical(cols ...string) bool {
|
||||
@@ -97,13 +92,17 @@ func (index *STableIndex) QuotedColumns() []string {
|
||||
|
||||
// AddIndex adds a SQL index over multiple columns for a Table
|
||||
// param unique: indicates a unique index cols: name of columns
|
||||
func (ts *STableSpec) AddIndex(unique bool, cols ...string) bool {
|
||||
func (ts *STableSpec) addIndexWithName(name string, unique bool, cols ...string) bool {
|
||||
for i := 0; i < len(ts._indexes); i++ {
|
||||
if ts._indexes[i].IsIdentical(cols...) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
idx := NewTableIndex(ts, cols, unique)
|
||||
idx := NewTableIndex(ts, name, cols, unique)
|
||||
ts._indexes = append(ts._indexes, idx)
|
||||
return true
|
||||
}
|
||||
|
||||
func (ts *STableSpec) AddIndex(unique bool, cols ...string) bool {
|
||||
return ts.addIndexWithName("", unique, cols...)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user