From d8d330d3d56663e9ea7825f85d7a00511988679b Mon Sep 17 00:00:00 2001 From: rainzm Date: Tue, 7 Sep 2021 10:33:32 +0800 Subject: [PATCH] fix(devtool): create serviceurl --- pkg/devtool/models/service_url.go | 8 ++++---- pkg/devtool/utils/service_url.go | 24 +++++++++++++++------- pkg/mcclient/options/devtool/serviceurl.go | 3 ++- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/pkg/devtool/models/service_url.go b/pkg/devtool/models/service_url.go index 97815175d3..699013fa97 100644 --- a/pkg/devtool/models/service_url.go +++ b/pkg/devtool/models/service_url.go @@ -30,10 +30,10 @@ import ( type SServiceUrl struct { db.SStatusStandaloneResourceBase - Service string `width:"32" charset:"ascii" list:"user" create:"required"` - ServerId string `width:"128" charset:"ascii" list:"user" create:"required"` - Url string `wdith:"32" charset:"ascii" list:"user"` - ServerAnsibleInfo *SServerAnisbleInfo + Service string `width:"32" charset:"ascii" list:"user" create:"required"` + ServerId string `width:"128" charset:"ascii" list:"user" create:"required"` + Url string `wdith:"32" charset:"ascii" list:"user"` + ServerAnsibleInfo *SServerAnisbleInfo `width:"128" list:"user" create:"required"` FailedReason string } diff --git a/pkg/devtool/utils/service_url.go b/pkg/devtool/utils/service_url.go index c983c43abb..5ccbb270df 100644 --- a/pkg/devtool/utils/service_url.go +++ b/pkg/devtool/utils/service_url.go @@ -42,7 +42,18 @@ type Service struct { Url string } -func serviceComplete(service Service) (completeUrl string, expectedCode int) { +func serviceComplete(serviceName, address string, port int) (url, checkUrl string, expectedCode int) { + switch serviceName { + case "influxdb": + return fmt.Sprintf("https://%s:%d", address, port), fmt.Sprintf("https://%s:%d/ping", address, port), 204 + case "repo": + return fmt.Sprintf("http://%s:%d", address, port), fmt.Sprintf("http://%s:%d", address, port), 200 + default: + return fmt.Sprintf("http://%s:%d", address, port), fmt.Sprintf("http://%s:%d", address, port), 200 + } +} + +func serviceComplete2(service Service) (completeUrl string, expectedCode int) { switch service.Name { case "influxdb": return fmt.Sprintf("%s/ping", service.Url), 204 @@ -104,7 +115,7 @@ func proxyEndpoints(ctx context.Context, proxyEndpointId string, info sServerInf } func serviceUrlDirect(ctx context.Context, service Service, proxyEndpointId string, info sServerInfo, host *ansible_api.AnsibleHost) (string, error) { - url, code := serviceComplete(service) + url, code := serviceComplete2(service) ok, err := checkUrl(ctx, url, code, host) if err != nil { return "", err @@ -200,11 +211,10 @@ func checkProxyEndpoint(ctx context.Context, service Service, proxyEndpointId, a if err != nil { return "", err } - url, code := serviceComplete(service) - nUrl := fmt.Sprintf("https://%s:%d", address, port) - ok, err := checkUrl(ctx, url, code, host) + url, cUrl, code := serviceComplete(service.Name, address, int(port)) + ok, err := checkUrl(ctx, cUrl, code, host) if err != nil { - return "", errors.Wrapf(err, "check url %q", nUrl) + return "", errors.Wrapf(err, "check url %q", cUrl) } if !ok { if recycle != nil { @@ -215,7 +225,7 @@ func checkProxyEndpoint(ctx context.Context, service Service, proxyEndpointId, a } return "", nil } - return nUrl, nil + return url, nil } type sServerInfo struct { diff --git a/pkg/mcclient/options/devtool/serviceurl.go b/pkg/mcclient/options/devtool/serviceurl.go index b15a6fd6f2..e419b2ff38 100644 --- a/pkg/mcclient/options/devtool/serviceurl.go +++ b/pkg/mcclient/options/devtool/serviceurl.go @@ -21,6 +21,7 @@ import ( ) type ServiceUrlCreateOptions struct { + NAME string `help:"Name"` Service string `help:"service name"` ServerId string `help:"server id"` ServerAnsibleInfo SServerAnisbleInfo @@ -28,7 +29,7 @@ type ServiceUrlCreateOptions struct { type SServerAnisbleInfo struct { User string `json:"user"` - IP string `json:"ip"` + Ip string `json:"ip"` Port int `json:"port"` Name string `json:"name"` }