Skip to content

Commit

Permalink
test: test
Browse files Browse the repository at this point in the history
Signed-off-by: 张启航 <[email protected]>
  • Loading branch information
ZhangSetSail committed Sep 29, 2024
1 parent e43020c commit 40eadd9
Show file tree
Hide file tree
Showing 116 changed files with 2,072 additions and 2,058 deletions.
4 changes: 1 addition & 3 deletions api/api_routers/version2/v2Routers.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,17 @@ import (
"github.com/go-chi/chi"
"github.com/goodrain/rainbond/api/controller"
"github.com/goodrain/rainbond/api/middleware"
"github.com/goodrain/rainbond/cmd/api/option"
dbmodel "github.com/goodrain/rainbond/db/model"
)

// V2 v2
type V2 struct {
Cfg *option.Config
}

// Routes routes
func (v2 *V2) Routes() chi.Router {
r := chi.NewRouter()
license := middleware.NewLicense(v2.Cfg)
license := middleware.NewLicense()
r.Use(license.Verify)
r.Get("/show", controller.GetManager().Show)

Expand Down
20 changes: 10 additions & 10 deletions api/controller/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package controller
import (
"bytes"
"fmt"
"github.com/goodrain/rainbond/pkg/component/storage"
"io"
"io/ioutil"
"net/http"
Expand All @@ -21,10 +22,10 @@ import (
"github.com/sirupsen/logrus"
)

//AppStruct -
// AppStruct -
type AppStruct struct{}

//ExportApp -
// ExportApp -
func (a *AppStruct) ExportApp(w http.ResponseWriter, r *http.Request) {

switch r.Method {
Expand Down Expand Up @@ -72,7 +73,7 @@ func (a *AppStruct) ExportApp(w http.ResponseWriter, r *http.Request) {

}

//Download -
// Download -
func (a *AppStruct) Download(w http.ResponseWriter, r *http.Request) {
format := strings.TrimSpace(chi.URLParam(r, "format"))
fileName := strings.TrimSpace(chi.URLParam(r, "fileName"))
Expand All @@ -83,11 +84,10 @@ func (a *AppStruct) Download(w http.ResponseWriter, r *http.Request) {
httputil.ReturnError(r, w, 404, fmt.Sprintf("Not found export app tar file: %s", tarFile))
return
}

http.ServeFile(w, r, tarFile)
storage.Default().StorageCli.ServeFile(w, r, tarFile)
}

//ImportID -
// ImportID -
func (a *AppStruct) ImportID(w http.ResponseWriter, r *http.Request) {
eventID := strings.TrimSpace(chi.URLParam(r, "eventID"))
if eventID == "" {
Expand Down Expand Up @@ -156,7 +156,7 @@ func (a *AppStruct) ImportID(w http.ResponseWriter, r *http.Request) {
}
}

//UploadID -
// UploadID -
func (a *AppStruct) UploadID(w http.ResponseWriter, r *http.Request) {
eventID := strings.TrimSpace(chi.URLParam(r, "eventID"))
if eventID == "" {
Expand Down Expand Up @@ -220,7 +220,7 @@ func (a *AppStruct) UploadID(w http.ResponseWriter, r *http.Request) {
}
}

//NewUpload -
// NewUpload -
func (a *AppStruct) NewUpload(w http.ResponseWriter, r *http.Request) {
eventID := strings.TrimSpace(chi.URLParam(r, "eventID"))
switch r.Method {
Expand All @@ -245,7 +245,7 @@ func (a *AppStruct) NewUpload(w http.ResponseWriter, r *http.Request) {

}

//Upload -
// Upload -
func (a *AppStruct) Upload(w http.ResponseWriter, r *http.Request) {
eventID := strings.TrimSpace(chi.URLParam(r, "eventID"))
switch r.Method {
Expand Down Expand Up @@ -300,7 +300,7 @@ func (a *AppStruct) Upload(w http.ResponseWriter, r *http.Request) {

}

//ImportApp -
// ImportApp -
func (a *AppStruct) ImportApp(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case "POST":
Expand Down
25 changes: 13 additions & 12 deletions api/controller/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package controller

import (
"fmt"
"github.com/goodrain/rainbond/config/configs"
"net/http"
"net/url"
"strconv"
Expand All @@ -28,7 +29,6 @@ import (
"github.com/goodrain/rainbond/api/handler"
api_model "github.com/goodrain/rainbond/api/model"
ctxutil "github.com/goodrain/rainbond/api/util/ctx"
"github.com/goodrain/rainbond/cmd/api/option"
"github.com/goodrain/rainbond/mq/client"
httputil "github.com/goodrain/rainbond/util/http"
"github.com/jinzhu/gorm"
Expand All @@ -39,7 +39,6 @@ import (
// GatewayStruct -
type GatewayStruct struct {
MQClient client.MQClient
cfg *option.Config
}

// HTTPRule is used to add, update or delete http rule which enables
Expand All @@ -55,7 +54,7 @@ func (g *GatewayStruct) HTTPRule(w http.ResponseWriter, r *http.Request) {
}
}

//GatewayCertificate k8s gateway certificate related operations
// GatewayCertificate k8s gateway certificate related operations
func (g *GatewayStruct) GatewayCertificate(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case "PUT":
Expand All @@ -67,15 +66,15 @@ func (g *GatewayStruct) GatewayCertificate(w http.ResponseWriter, r *http.Reques
}
}

//BatchGatewayHTTPRoute k8s gateway http route batch operation
// BatchGatewayHTTPRoute k8s gateway http route batch operation
func (g *GatewayStruct) BatchGatewayHTTPRoute(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case "GET":
g.batchGetGatewayHTTPRoute(w, r)
}
}

//GatewayHTTPRoute k8s gateway http route related operations
// GatewayHTTPRoute k8s gateway http route related operations
func (g *GatewayStruct) GatewayHTTPRoute(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case "GET":
Expand Down Expand Up @@ -337,13 +336,14 @@ func (g *GatewayStruct) AddTCPRule(w http.ResponseWriter, r *http.Request) {
h := handler.GetGatewayHandler()
// verify request
values := url.Values{}
apiConfig := configs.Default().APIConfig
if req.ContainerPort == 0 {
values["container_port"] = []string{"The container_port field is required"}
}
if req.Port == 0 {
values["port"] = []string{"The port field is required"}
} else if req.Port <= g.cfg.MinExtPort {
values["port"] = []string{fmt.Sprintf("The port field should be greater than %d", g.cfg.MinExtPort)}
} else if req.Port <= apiConfig.MinExtPort {
values["port"] = []string{fmt.Sprintf("The port field should be greater than %d", apiConfig.MinExtPort)}
} else {
// check if the port exists
if h.TCPIPPortExists(req.IP, req.Port) {
Expand Down Expand Up @@ -385,8 +385,9 @@ func (g *GatewayStruct) updateTCPRule(w http.ResponseWriter, r *http.Request) {
h := handler.GetGatewayHandler()
// verify reqeust
values := url.Values{}
if req.Port != 0 && req.Port <= g.cfg.MinExtPort {
values["port"] = []string{fmt.Sprintf("The port field should be greater than %d", g.cfg.MinExtPort)}
apiConfig := configs.Default().APIConfig
if req.Port != 0 && req.Port <= apiConfig.MinExtPort {
values["port"] = []string{fmt.Sprintf("The port field should be greater than %d", apiConfig.MinExtPort)}
}
if len(req.RuleExtensions) > 0 {
for _, re := range req.RuleExtensions {
Expand All @@ -405,7 +406,7 @@ func (g *GatewayStruct) updateTCPRule(w http.ResponseWriter, r *http.Request) {
return
}

err := h.UpdateTCPRule(&req, g.cfg.MinExtPort)
err := h.UpdateTCPRule(&req, apiConfig.MinExtPort)
if err != nil {
httputil.ReturnError(r, w, 500, fmt.Sprintf("Unexpected error occorred while "+
"updating tcp rule: %v", err))
Expand Down Expand Up @@ -472,7 +473,7 @@ func (g *GatewayStruct) Certificate(w http.ResponseWriter, r *http.Request) {
}
}

//updCertificate updates certificate and refresh http rules based on certificate id
// updCertificate updates certificate and refresh http rules based on certificate id
func (g *GatewayStruct) updCertificate(w http.ResponseWriter, r *http.Request) {
var req api_model.UpdCertificateReq
ok := httputil.ValidatorRequestStructAndErrorResponse(r, w, &req, nil)
Expand All @@ -493,7 +494,7 @@ func (g *GatewayStruct) updCertificate(w http.ResponseWriter, r *http.Request) {
httputil.ReturnSuccess(r, w, nil)
}

//GetGatewayIPs get gateway ips
// GetGatewayIPs get gateway ips
func GetGatewayIPs(w http.ResponseWriter, r *http.Request) {
ips := handler.GetGatewayHandler().GetGatewayIPs()
httputil.ReturnSuccess(r, w, ips)
Expand Down
6 changes: 3 additions & 3 deletions api/controller/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@
package controller

import (
"github.com/goodrain/rainbond/cmd/api/option"
"github.com/goodrain/rainbond/config/configs"
httputil "github.com/goodrain/rainbond/util/http"
"net/http"
)

// LabelController implements Labeler.
type LabelController struct {
optconfig *option.Config
}

// Labels - get -> list labels
Expand All @@ -38,5 +37,6 @@ func (l *LabelController) Labels(w http.ResponseWriter, r *http.Request) {
}

func (l *LabelController) listLabels(w http.ResponseWriter, r *http.Request) {
httputil.ReturnSuccess(r, w, l.optconfig.EnableFeature)
config := configs.Default()
httputil.ReturnSuccess(r, w, config.APIConfig.EnableFeature)
}
21 changes: 7 additions & 14 deletions api/controller/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@
package controller

import (
"github.com/goodrain/rainbond/pkg/component/mq"
"net/http"

"github.com/goodrain/rainbond/api/api"
"github.com/goodrain/rainbond/api/proxy"
"github.com/goodrain/rainbond/cmd/api/option"
mqclient "github.com/goodrain/rainbond/mq/client"
"github.com/goodrain/rainbond/worker/client"
)

Expand Down Expand Up @@ -57,8 +56,8 @@ type V2Manager interface {
var defaultV2Manager V2Manager

// CreateV2RouterManager 创建manager
func CreateV2RouterManager(conf option.Config, statusCli *client.AppRuntimeSyncClient) (err error) {
defaultV2Manager, err = NewManager(conf, statusCli)
func CreateV2RouterManager(statusCli *client.AppRuntimeSyncClient) (err error) {
defaultV2Manager, err = NewAPIManager(statusCli)
return err
}

Expand All @@ -67,18 +66,12 @@ func GetManager() V2Manager {
return defaultV2Manager
}

// NewManager new manager
func NewManager(conf option.Config, statusCli *client.AppRuntimeSyncClient) (*V2Routes, error) {
mqClient, err := mqclient.NewMqClient(conf.MQAPI)
if err != nil {
return nil, err
}
// NewAPIManager new manager
func NewAPIManager(statusCli *client.AppRuntimeSyncClient) (*V2Routes, error) {
var v2r V2Routes
v2r.TenantStruct.StatusCli = statusCli
v2r.TenantStruct.MQClient = mqClient
v2r.GatewayStruct.MQClient = mqClient
v2r.GatewayStruct.cfg = &conf
v2r.LabelController.optconfig = &conf
v2r.TenantStruct.MQClient = mq.Default().MqClient
v2r.GatewayStruct.MQClient = mq.Default().MqClient
eventServerProxy := proxy.CreateProxy("eventlog", "http", []string{"local=>rbd-eventlog:6363"})
v2r.EventLogStruct.EventlogServerProxy = eventServerProxy
return &v2r, nil
Expand Down
2 changes: 0 additions & 2 deletions api/controller/registry_auth_secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,13 @@ import (

"github.com/goodrain/rainbond/api/handler"
api_model "github.com/goodrain/rainbond/api/model"
"github.com/goodrain/rainbond/cmd/api/option"
"github.com/goodrain/rainbond/mq/client"
httputil "github.com/goodrain/rainbond/util/http"
)

// RegistryAuthSecretStruct -
type RegistryAuthSecretStruct struct {
MQClient client.MQClient
cfg *option.Config
}

// RegistryAuthSecret http handler for registry auth secret
Expand Down
19 changes: 5 additions & 14 deletions api/controller/service_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/goodrain/rainbond/api/util"
dbmodel "github.com/goodrain/rainbond/db/model"
"github.com/goodrain/rainbond/pkg/component/k8s"
"github.com/goodrain/rainbond/pkg/component/storage"
"github.com/sirupsen/logrus"
"io"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -97,22 +98,12 @@ func (t *TenantStruct) UploadPackage(w http.ResponseWriter, r *http.Request) {
defer reader.Close()

dirName := fmt.Sprintf("/grdata/package_build/temp/events/%s", eventID)
os.MkdirAll(dirName, 0755)

storage.Default().StorageCli.MkdirAll(dirName, 0755)
fileName := fmt.Sprintf("%s/%s", dirName, header.Filename)
file, err := os.OpenFile(fileName, os.O_WRONLY|os.O_CREATE, 0644)
err = storage.Default().StorageCli.SaveFile(fileName, reader)
if err != nil {
logrus.Errorf("Failed to open file: %s", err.Error())
httputil.ReturnError(r, w, 502, "Failed to open file: "+err.Error())
}
defer file.Close()

logrus.Debug("Start write file to: ", fileName)
if _, err := io.Copy(file, reader); err != nil {
logrus.Errorf("Failed to write file:%s", err.Error())
httputil.ReturnError(r, w, 503, "Failed to write file: "+err.Error())
httputil.ReturnError(r, w, 503, "Failed to save file: "+err.Error())
}

logrus.Debug("successful write file to: ", fileName)
origin := r.Header.Get("Origin")
w.Header().Add("Access-Control-Allow-Origin", origin)
Expand Down Expand Up @@ -267,7 +258,7 @@ func (f FileManage) DownloadFile(w http.ResponseWriter, r *http.Request) {
}
defer os.Remove(path.Join("./", fileName))
w.Header().Set("Content-Disposition", "attachment;filename="+fileName)
http.ServeFile(w, r, path.Join("./", fileName))
storage.Default().StorageCli.ServeFile(w, r, path.Join("./", fileName))
}

func (f FileManage) AppFileUpload(containerName, podName, srcPath, destPath, namespace string) error {
Expand Down
5 changes: 3 additions & 2 deletions api/controller/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"context"
webcli "github.com/goodrain/rainbond/api/webcli/app"
"github.com/goodrain/rainbond/config/configs"
"github.com/goodrain/rainbond/pkg/component/storage"
"github.com/gorilla/websocket"
"net/http"
"os"
Expand Down Expand Up @@ -160,7 +161,7 @@ func (d LogFile) Get(w http.ResponseWriter, r *http.Request) {
filename := chi.URLParam(r, "filename")
filePath := path.Join(d.Root, gid, filename)
if isExist(filePath) {
http.ServeFile(w, r, filePath)
storage.Default().StorageCli.ServeFile(w, r, filePath)
} else {
w.WriteHeader(404)
}
Expand All @@ -175,7 +176,7 @@ func (d LogFile) GetInstallLog(w http.ResponseWriter, r *http.Request) {
filename := chi.URLParam(r, "filename")
filePath := d.Root + filename
if isExist(filePath) {
http.ServeFile(w, r, filePath)
storage.Default().StorageCli.ServeFile(w, r, filePath)
} else {
w.WriteHeader(404)
}
Expand Down
11 changes: 6 additions & 5 deletions api/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ import (
"context"
"encoding/json"
"github.com/goodrain/rainbond/config/configs"
"github.com/goodrain/rainbond/db/config"
"github.com/goodrain/rainbond/mq/api/grpc/pb"
"github.com/goodrain/rainbond/pkg/gogo"
"time"

tsdbClient "github.com/bluebreezecf/opentsdb-goclient/client"
tsdbConfig "github.com/bluebreezecf/opentsdb-goclient/config"
"github.com/goodrain/rainbond/db"
"github.com/goodrain/rainbond/db/config"
dbModel "github.com/goodrain/rainbond/db/model"
"github.com/goodrain/rainbond/worker/discover/model"
"github.com/jinzhu/gorm"
Expand All @@ -48,12 +48,13 @@ func New() *ConDB {
}

// Start -
func (d *ConDB) Start(ctx context.Context, cfg *configs.Config) error {
func (d *ConDB) Start(ctx context.Context) error {
dbConfig := configs.Default().DBConfig
logrus.Info("start db client...")
dbCfg := config.Config{
MysqlConnectionInfo: cfg.APIConfig.DBConnectionInfo,
DBType: cfg.APIConfig.DBType,
ShowSQL: cfg.APIConfig.ShowSQL,
MysqlConnectionInfo: dbConfig.DBConnectionInfo,
DBType: dbConfig.DBType,
ShowSQL: dbConfig.ShowSQL,
}
if err := db.CreateManager(dbCfg); err != nil {
logrus.Errorf("get db manager failed,%s", err.Error())
Expand Down
Loading

0 comments on commit 40eadd9

Please sign in to comment.