OSDN Git Service

move oss (#585)
authorOuter-God <39217235+Outer-God@users.noreply.github.com>
Thu, 1 Apr 2021 06:24:51 +0000 (14:24 +0800)
committerGitHub <noreply@github.com>
Thu, 1 Apr 2021 06:24:51 +0000 (14:24 +0800)
Co-authored-by: Welt <L5Accelerator@users.noreply.github.com>
cmd/vapord/commands/run_node.go
config/config.go
toolbar/osssync/download/download.go
toolbar/osssync/upload/config.go
toolbar/osssync/upload/oss.go
toolbar/osssync/upload/upload.go

index 19abf09..4dd642d 100644 (file)
@@ -58,7 +58,7 @@ func init() {
        runNodeCmd.Flags().Int("ws.max_num_concurrent_reqs", config.Websocket.MaxNumConcurrentReqs, "Max number of concurrent websocket requests that may be processed concurrently")
 
        // OSS
-       runNodeCmd.Flags().String("oss.endpoint", config.Oss.Endpoint, "Endpoint of OSS")
+       runNodeCmd.Flags().String("oss.url", config.Oss.Url, "URL of OSS")
 
        RootCmd.AddCommand(runNodeCmd)
 }
@@ -88,7 +88,7 @@ func runNode(cmd *cobra.Command, args []string) error {
        n := node.NewNode(config)
 
        // Get blocks from OSS
-       if err := download.Run(n, config.Oss.Endpoint); err != nil {
+       if err := download.Run(n, config.Oss.Url); err != nil {
                fmt.Println("Failed to get blocks from oss: ", err)
        }
 
index 0ef07e5..905f747 100644 (file)
@@ -223,7 +223,7 @@ type CrossChainConfig struct {
 }
 
 type OssConfig struct {
-       Endpoint string `mapstructure:"endpoint"`
+       Url string `mapstructure:"url"`
 }
 
 // Default configurable rpc's auth parameters.
index fb7f02a..5f82ef3 100644 (file)
@@ -38,12 +38,10 @@ type DownloadKeeper struct {
 
 // NewDownloadKeeper return one new instance of DownloadKeeper
 func NewDownloadKeeper(node *node.Node, ossEndpoint string) (*DownloadKeeper, error) {
-       fileUtil := util.NewFileUtil(LOCALDIR)
-
        return &DownloadKeeper{
                Node:        node,
                OssEndpoint: "http://" + ossEndpoint + "/",
-               FileUtil:    fileUtil,
+               FileUtil:    util.NewFileUtil(LOCALDIR),
        }, nil
 }
 
index d0f0dc6..f36bbea 100644 (file)
@@ -22,8 +22,9 @@ type Login struct {
 
 // Oss cfg
 type OssConfig struct {
-       Login  *Login `json:"login"`
-       Bucket string `json:"bucket"`
+       Login     *Login `json:"login"`
+       Bucket    string `json:"bucket"`
+       Directory string `json:"directory"`
 }
 
 // LoadConfig read path file to the config object for Upload from Vapor to OSS
index e833d99..512ad7b 100644 (file)
@@ -17,7 +17,7 @@ func (u *UploadKeeper) PutObjByteArr(objectName string, objectValue []byte) erro
 
 // GetInfoJson Download info.json
 func (u *UploadKeeper) GetInfoJson() (*util.Info, error) {
-       body, err := u.OssBucket.GetObject("info.json")
+       body, err := u.OssBucket.GetObject(u.OssDir + "info.json")
        if err != nil {
                return nil, err
        }
@@ -33,7 +33,7 @@ func (u *UploadKeeper) PutInfoJson(infoData *util.Info) error {
        }
 
        // Upload
-       return u.PutObjByteArr("info.json", jsonData)
+       return u.PutObjByteArr(u.OssDir+"info.json", jsonData)
 }
 
 // SetLatestBlockHeight set new latest blockHeight on OSS
@@ -49,7 +49,7 @@ func (u *UploadKeeper) SetLatestBlockHeight(newLatestBlockHeight uint64) error {
 
 // AddInterval if "info.json" exists on OSS, add Interval to the end; if not exist, create "info.json" with Interval
 func (u *UploadKeeper) AddInterval(end, gzSize uint64) error {
-       isJsonExist, err := u.OssBucket.IsObjectExist("info.json")
+       isJsonExist, err := u.OssBucket.IsObjectExist(u.OssDir + "info.json")
        if err != nil {
                return err
        }
index a0960ff..2d23834 100644 (file)
@@ -41,6 +41,7 @@ type UploadKeeper struct {
        Node      *apinode.Node
        OssClient *oss.Client
        OssBucket *oss.Bucket
+       OssDir    string
        FileUtil  *util.FileUtil
 }
 
@@ -51,8 +52,6 @@ func NewUploadKeeper() (*UploadKeeper, error) {
                return nil, err
        }
 
-       node := apinode.NewNode(cfg.VaporURL)
-
        ossClient, err := oss.New(cfg.OssConfig.Login.Endpoint, cfg.OssConfig.Login.AccessKeyID, cfg.OssConfig.Login.AccessKeySecret)
        if err != nil {
                return nil, err
@@ -63,13 +62,12 @@ func NewUploadKeeper() (*UploadKeeper, error) {
                return nil, err
        }
 
-       fileUtil := util.NewFileUtil(LOCALDIR)
-
        return &UploadKeeper{
-               Node:      node,
+               Node:      apinode.NewNode(cfg.VaporURL),
                OssClient: ossClient,
                OssBucket: ossBucket,
-               FileUtil:  fileUtil,
+               OssDir:    cfg.OssConfig.Directory,
+               FileUtil:  util.NewFileUtil(LOCALDIR),
        }, nil
 }
 
@@ -171,7 +169,7 @@ func (u *UploadKeeper) UploadFiles(start, end, size uint64) error {
                        return err
                }
 
-               if err = u.OssBucket.PutObjectFromFile(filenameGzip, u.FileUtil.LocalDir+filenameGzip); err != nil {
+               if err = u.OssBucket.PutObjectFromFile(u.OssDir+filenameGzip, u.FileUtil.LocalDir+filenameGzip); err != nil {
                        return err
                }