Skip to content

Commit 2a54db6

Browse files
committed
chore(bfl): remove some unused API handlers
1 parent 4ed649b commit 2a54db6

File tree

8 files changed

+2
-358
lines changed

8 files changed

+2
-358
lines changed

framework/bfl/pkg/apis/backend/v1/handler.go

Lines changed: 0 additions & 163 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,19 @@ package v1
22

33
import (
44
"fmt"
5-
"math"
6-
"net/http"
75
"strconv"
86
"time"
97

108
"bytetrade.io/web3os/bfl/internal/log"
119
"bytetrade.io/web3os/bfl/pkg/api"
1210
"bytetrade.io/web3os/bfl/pkg/api/response"
1311
"bytetrade.io/web3os/bfl/pkg/apis"
14-
"bytetrade.io/web3os/bfl/pkg/apis/backend/v1/metrics"
15-
iamV1alpha1 "bytetrade.io/web3os/bfl/pkg/apis/iam/v1alpha1"
1612
"bytetrade.io/web3os/bfl/pkg/apis/iam/v1alpha1/operator"
17-
monitov1alpha1 "bytetrade.io/web3os/bfl/pkg/apis/monitor/v1alpha1"
1813
"bytetrade.io/web3os/bfl/pkg/apiserver/runtime"
1914
"bytetrade.io/web3os/bfl/pkg/app_service/v1"
2015
"bytetrade.io/web3os/bfl/pkg/client/clientset/v1alpha1"
2116
"bytetrade.io/web3os/bfl/pkg/constants"
22-
"bytetrade.io/web3os/bfl/pkg/utils"
2317
"bytetrade.io/web3os/bfl/pkg/utils/certmanager"
24-
"bytetrade.io/web3os/bfl/pkg/utils/k8sutil"
2518

2619
iamV1alpha2 "github.com/beclab/api/iam/v1alpha2"
2720
"github.com/emicklei/go-restful/v3"
@@ -42,53 +35,6 @@ func New() *Handler {
4235
}
4336
}
4437

45-
func (h *Handler) handleGetIPAddress(req *restful.Request, resp *restful.Response) {
46-
ctx := req.Request.Context()
47-
master := req.QueryParameter("master")
48-
49-
var masterInternalIP string
50-
51-
if master == "true" {
52-
ip, err := k8sutil.GetL4ProxyNodeIP(ctx, 10*time.Second)
53-
if err != nil {
54-
log.Warnf("no master hostIP: %v", err)
55-
}
56-
57-
if ip != nil && *ip != "" {
58-
masterInternalIP = *ip
59-
}
60-
61-
resp.Write([]byte(masterInternalIP))
62-
return
63-
}
64-
65-
ipAddr := IPAddress{
66-
IsNatted: constants.IsNatted,
67-
Internal: utils.RemoteIp(req.Request),
68-
}
69-
70-
if masterInternalIP != "" {
71-
ipAddr.MasterInternalIP = masterInternalIP
72-
}
73-
74-
// master external ip
75-
masterExternalIP := k8sutil.GetMasterExternalIP(ctx)
76-
if masterExternalIP == nil {
77-
response.HandleError(resp, errors.New("no master external ip"))
78-
return
79-
}
80-
ipAddr.MasterExternalIP = *masterExternalIP
81-
82-
external := utils.GetMyExternalIPAddr()
83-
if external == "" {
84-
response.HandleInternalError(resp, errors.New("no external ip address"))
85-
return
86-
}
87-
ipAddr.External = external
88-
89-
response.Success(resp, ipAddr)
90-
}
91-
9238
func (h *Handler) handleUserInfo(req *restful.Request, resp *restful.Response) {
9339
var (
9440
isEphemeral bool
@@ -154,50 +100,6 @@ func (h *Handler) handleUserInfo(req *restful.Request, resp *restful.Response) {
154100
response.Success(resp, uInfo)
155101
}
156102

157-
func (h *Handler) handleVerifyUserPassword(req *restful.Request, resp *restful.Response) {
158-
var u iamV1alpha1.UserPassword
159-
err := req.ReadEntity(&u)
160-
if err != nil {
161-
response.HandleBadRequest(resp, errors.Errorf("verify password: %v", err))
162-
return
163-
}
164-
165-
log.Info("verify user password")
166-
167-
if u.UserName == "" {
168-
u.UserName = constants.Username
169-
}
170-
171-
// the user's password must be provided
172-
if u.Password == "" {
173-
response.HandleBadRequest(resp, errors.New("verify password: no password provided"))
174-
return
175-
}
176-
177-
data := map[string]string{
178-
"username": u.UserName,
179-
"password": u.Password,
180-
"client_id": constants.KubeSphereClientID,
181-
"client_secret": constants.KubeSphereClientSecret,
182-
"grant_type": "password",
183-
}
184-
185-
token, code, err := iamV1alpha1.RequestToken("", data)
186-
if err != nil {
187-
resp.WriteHeaderAndEntity(http.StatusOK, response.Header{
188-
Code: code,
189-
Message: err.Error(),
190-
})
191-
return
192-
}
193-
194-
if token.AccessToken != "" {
195-
response.SuccessNoData(resp)
196-
return
197-
}
198-
response.HandleUnauthorized(resp, errors.New(response.UnexpectedError))
199-
}
200-
201103
func (h *Handler) handleReDownloadCert(req *restful.Request, resp *restful.Response) {
202104
var (
203105
ctx = req.Request.Context()
@@ -469,68 +371,3 @@ func (h *Handler) myapps(req *restful.Request, resp *restful.Response) {
469371
response.Success(resp, api.NewListResult(list))
470372

471373
}
472-
473-
func (h *Handler) getClusterMetric(req *restful.Request, resp *restful.Response) {
474-
prome, err := metrics.NewPrometheus(metrics.PrometheusEndpoint)
475-
if err != nil {
476-
response.HandleError(resp, err)
477-
return
478-
}
479-
480-
opts := metrics.QueryOptions{
481-
Level: metrics.LevelCluster,
482-
}
483-
484-
metricsResult := prome.GetNamedMetrics(req.Request.Context(), []string{
485-
"cluster_cpu_usage",
486-
"cluster_cpu_total",
487-
"cluster_disk_size_usage",
488-
"cluster_disk_size_capacity",
489-
"cluster_memory_total",
490-
"cluster_memory_usage_wo_cache",
491-
"cluster_net_bytes_transmitted",
492-
"cluster_net_bytes_received",
493-
}, time.Now(), opts)
494-
495-
var clusterMetrics monitov1alpha1.ClusterMetrics
496-
for _, m := range metricsResult {
497-
switch m.MetricName {
498-
case "cluster_cpu_usage":
499-
clusterMetrics.CPU.Usage = metrics.GetValue(&m)
500-
case "cluster_cpu_total":
501-
clusterMetrics.CPU.Total = metrics.GetValue(&m)
502-
503-
case "cluster_disk_size_usage":
504-
clusterMetrics.Disk.Usage = metrics.GetValue(&m)
505-
case "cluster_disk_size_capacity":
506-
clusterMetrics.Disk.Total = metrics.GetValue(&m)
507-
508-
case "cluster_memory_total":
509-
clusterMetrics.Memory.Total = metrics.GetValue(&m)
510-
case "cluster_memory_usage_wo_cache":
511-
clusterMetrics.Memory.Usage = metrics.GetValue(&m)
512-
513-
case "cluster_net_bytes_transmitted":
514-
clusterMetrics.Net.Transmitted = metrics.GetValue(&m)
515-
516-
case "cluster_net_bytes_received":
517-
clusterMetrics.Net.Received = metrics.GetValue(&m)
518-
}
519-
}
520-
521-
roundToGB := func(v float64) float64 { return math.Round((v/1000000000.00)*100.00) / 100.00 }
522-
fmtMetricsValue(&clusterMetrics.CPU, "Cores", func(v float64) float64 { return v })
523-
fmtMetricsValue(&clusterMetrics.Memory, "GB", roundToGB)
524-
fmtMetricsValue(&clusterMetrics.Disk, "GB", roundToGB)
525-
526-
response.Success(resp, clusterMetrics)
527-
528-
}
529-
530-
func fmtMetricsValue(v *monitov1alpha1.MetricV, unit string, unitFunc func(float64) float64) {
531-
v.Unit = unit
532-
533-
v.Usage = unitFunc(v.Usage)
534-
v.Total = unitFunc(v.Total)
535-
v.Ratio = math.Round((v.Usage / v.Total) * 100)
536-
}

framework/bfl/pkg/apis/backend/v1/register.go

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"net/http"
55

66
"bytetrade.io/web3os/bfl/pkg/api/response"
7-
iamV1alpha1 "bytetrade.io/web3os/bfl/pkg/apis/iam/v1alpha1"
87
"bytetrade.io/web3os/bfl/pkg/apiserver/runtime"
98

109
restfulspec "github.com/emicklei/go-restful-openapi/v2"
@@ -23,13 +22,6 @@ func AddContainer(c *restful.Container) error {
2322

2423
handler := New()
2524

26-
ws.Route(ws.POST("/verify-password").
27-
To(handler.handleVerifyUserPassword).
28-
Doc("Verify user password.").
29-
Reads(iamV1alpha1.UserPassword{}).
30-
Metadata(restfulspec.KeyOpenAPITags, tags).
31-
Returns(http.StatusOK, "", response.Response{}))
32-
3325
ws.Route(ws.GET("/user-info").
3426
To(handler.handleUserInfo).
3527
Doc("User information.").
@@ -48,13 +40,6 @@ func AddContainer(c *restful.Container) error {
4840
Metadata(restfulspec.KeyOpenAPITags, tags).
4941
Returns(http.StatusOK, "", response.Response{}))
5042

51-
ws.Route(ws.GET("/ip").
52-
To(handler.handleGetIPAddress).
53-
Doc("IP Address.").
54-
Param(ws.QueryParameter("master", "get master nodeIP only").DataType("string").Required(false)).
55-
Metadata(restfulspec.KeyOpenAPITags, tags).
56-
Returns(http.StatusOK, "", response.Response{}))
57-
5843
ws.Route(ws.GET("/re-download-cert").
5944
To(handler.handleReDownloadCert).
6045
Doc("Re-download ssl certificate").
@@ -67,12 +52,6 @@ func AddContainer(c *restful.Container) error {
6752
Metadata(restfulspec.KeyOpenAPITags, tags).
6853
Returns(http.StatusOK, "", response.Response{}))
6954

70-
ws.Route(ws.GET("/cluster").
71-
To(handler.getClusterMetric).
72-
Doc("get the cluster current metrics ( cpu, memory, disk ).").
73-
Metadata(restfulspec.KeyOpenAPITags, tags).
74-
Returns(http.StatusOK, "", response.Response{}))
75-
7655
ws.Route(ws.GET("/config-system").
7756
To(handler.HandleGetSysConfig).
7857
Doc("get user locale.").
@@ -85,12 +64,6 @@ func AddContainer(c *restful.Container) error {
8564
wsWizard.Consumes(restful.MIME_JSON)
8665
wsWizard.Produces(restful.MIME_JSON)
8766

88-
wsWizard.Route(wsWizard.GET("/terminus-info").
89-
To(handler.handleTerminusInfo).
90-
Doc("terminus information.").
91-
Metadata(restfulspec.KeyOpenAPITags, tags).
92-
Returns(http.StatusOK, "", response.Response{}))
93-
9467
wsWizard.Route(wsWizard.GET("/olares-info").
9568
To(handler.handleOlaresInfo).
9669
Doc("olares information.").

framework/bfl/pkg/apis/callback/v1alpha1/backup.go

Lines changed: 0 additions & 43 deletions
This file was deleted.

framework/bfl/pkg/apis/callback/v1alpha1/register.go

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)