You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by mi...@apache.org on 2023/02/21 07:33:52 UTC
[shardingsphere-on-cloud] branch main updated: feat(pitr): agent server api input parameter (#217)
This is an automated email from the ASF dual-hosted git repository.
miaoliyao pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/shardingsphere-on-cloud.git
The following commit(s) were added to refs/heads/main by this push:
new 4b0b135 feat(pitr): agent server api input parameter (#217)
4b0b135 is described below
commit 4b0b13593df07fb0a6c183eadd384fd4c02271ac
Author: lltgo <ll...@outlook.com>
AuthorDate: Tue Feb 21 15:33:47 2023 +0800
feat(pitr): agent server api input parameter (#217)
---
pitr/agent/internal/cons/error.go | 10 ++++
pitr/agent/internal/cons/http_header.go | 2 +-
pitr/agent/internal/handler/backup.go | 22 ++++++-
.../internal/handler/{resotre.go => restore.go} | 21 ++++++-
pitr/agent/internal/handler/show.go | 22 ++++++-
pitr/agent/internal/handler/view/backup.go | 69 ++++++++++++++++++++++
.../internal/handler/{show.go => view/restore.go} | 42 ++++++++++++-
pitr/agent/internal/handler/{ => view}/show.go | 42 ++++++++++++-
pitr/agent/internal/pkg/opengauss_test.go | 2 +-
9 files changed, 218 insertions(+), 14 deletions(-)
diff --git a/pitr/agent/internal/cons/error.go b/pitr/agent/internal/cons/error.go
index a617dde..d3969c6 100644
--- a/pitr/agent/internal/cons/error.go
+++ b/pitr/agent/internal/cons/error.go
@@ -33,4 +33,14 @@ var (
StartOpenGaussFailed = xerror.New(10008, "Failed to start opengauss.")
StopOpenGaussFailed = xerror.New(10009, "Failed to stop opengauss.")
RestoreFailed = xerror.New(10010, "Failed to restore opengauss.")
+ InvalidDbPort = xerror.New(10011, "Invalid dn port.")
+ MissingUsername = xerror.New(10012, "Missing username")
+ MissingPassword = xerror.New(10013, "Missing password.")
+ MissingDnBackupPath = xerror.New(10014, "Missing dn backup path.")
+ InvalidDnThreadsNum = xerror.New(10015, "Invalid dn threads num.")
+ MissingDnBackupMode = xerror.New(10016, "Missing dn backup mode.")
+ InvalidDnBackupMode = xerror.New(10017, "Invalid dn backup mode.")
+ MissingInstance = xerror.New(10018, "Missing instance.")
+ MissingDnBackupId = xerror.New(10019, "Missing dn backup id.")
+ BodyParseFailed = xerror.New(10020, "Invalid http request body.")
)
diff --git a/pitr/agent/internal/cons/http_header.go b/pitr/agent/internal/cons/http_header.go
index 17d3fa4..ef461b6 100644
--- a/pitr/agent/internal/cons/http_header.go
+++ b/pitr/agent/internal/cons/http_header.go
@@ -18,5 +18,5 @@
package cons
const (
- RequestID string = "request-id"
+ RequestID string = "x-request-id"
)
diff --git a/pitr/agent/internal/handler/backup.go b/pitr/agent/internal/handler/backup.go
index a736b6d..10d3006 100644
--- a/pitr/agent/internal/handler/backup.go
+++ b/pitr/agent/internal/handler/backup.go
@@ -17,8 +17,26 @@
package handler
-import "github.com/gofiber/fiber/v2"
+import (
+ "fmt"
+
+ "github.com/apache/shardingsphere-on-cloud/pitr/agent/internal/handler/view"
+
+ "github.com/gofiber/fiber/v2"
+
+ "github.com/apache/shardingsphere-on-cloud/pitr/agent/internal/cons"
+)
func Backup(ctx *fiber.Ctx) error {
- return nil
+ in := &view.BackupIn{}
+
+ if err := ctx.BodyParser(in); err != nil {
+ return fmt.Errorf("body parse err=%s,wrap=%w", err, cons.BodyParseFailed)
+ }
+
+ if err := in.Validate(); err != nil {
+ return err
+ }
+
+ return ctx.JSON(in)
}
diff --git a/pitr/agent/internal/handler/resotre.go b/pitr/agent/internal/handler/restore.go
similarity index 66%
rename from pitr/agent/internal/handler/resotre.go
rename to pitr/agent/internal/handler/restore.go
index bdf7a51..66f0043 100644
--- a/pitr/agent/internal/handler/resotre.go
+++ b/pitr/agent/internal/handler/restore.go
@@ -17,8 +17,25 @@
package handler
-import "github.com/gofiber/fiber/v2"
+import (
+ "fmt"
+
+ "github.com/gofiber/fiber/v2"
+
+ "github.com/apache/shardingsphere-on-cloud/pitr/agent/internal/cons"
+ "github.com/apache/shardingsphere-on-cloud/pitr/agent/internal/handler/view"
+)
func Restore(ctx *fiber.Ctx) error {
- return nil
+ in := &view.RestoreIn{}
+
+ if err := ctx.BodyParser(in); err != nil {
+ return fmt.Errorf("body parse err=%s,wrap=%w", err, cons.BodyParseFailed)
+ }
+
+ if err := in.Validate(); err != nil {
+ return err
+ }
+
+ return ctx.JSON(in)
}
diff --git a/pitr/agent/internal/handler/show.go b/pitr/agent/internal/handler/show.go
index e92efd7..da7bc17 100644
--- a/pitr/agent/internal/handler/show.go
+++ b/pitr/agent/internal/handler/show.go
@@ -17,8 +17,26 @@
package handler
-import "github.com/gofiber/fiber/v2"
+import (
+ "fmt"
+
+ "github.com/apache/shardingsphere-on-cloud/pitr/agent/internal/handler/view"
+
+ "github.com/gofiber/fiber/v2"
+
+ "github.com/apache/shardingsphere-on-cloud/pitr/agent/internal/cons"
+)
func Show(ctx *fiber.Ctx) error {
- return nil
+ in := &view.ShowIn{}
+
+ if err := ctx.BodyParser(in); err != nil {
+ return fmt.Errorf("body parse err=%s,wrap=%w", err, cons.BodyParseFailed)
+ }
+
+ if err := in.Validate(); err != nil {
+ return err
+ }
+
+ return ctx.JSON(in)
}
diff --git a/pitr/agent/internal/handler/view/backup.go b/pitr/agent/internal/handler/view/backup.go
new file mode 100644
index 0000000..d379e79
--- /dev/null
+++ b/pitr/agent/internal/handler/view/backup.go
@@ -0,0 +1,69 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+ */
+
+package view
+
+import "github.com/apache/shardingsphere-on-cloud/pitr/agent/internal/cons"
+
+type BackupIn struct {
+ DbPort uint16 `json:"db_port"`
+ Username string `json:"username"`
+ Password string `json:"password"`
+ DnBackupPath string `json:"dn_backup_path"`
+ DnThreadsNum uint8 `json:"dn_threads_num"`
+ DnBackupMode string `json:"dn_backup_mode"`
+ Instance string `json:"instance"`
+}
+
+func (in *BackupIn) Validate() error {
+ if in == nil {
+ return cons.Internal
+ }
+
+ if in.DbPort == 0 {
+ return cons.InvalidDbPort
+ }
+
+ if in.Username == "" {
+ return cons.MissingUsername
+ }
+
+ if in.Password == "" {
+ return cons.MissingPassword
+ }
+
+ if in.DnBackupPath == "" {
+ return cons.MissingDnBackupPath
+ }
+
+ if in.DnThreadsNum == 0 {
+ return cons.InvalidDnThreadsNum
+ }
+
+ if in.DnBackupMode == "" {
+ return cons.MissingDnBackupMode
+ }
+
+ if in.DnBackupMode != "FULL" && in.DnBackupMode != "PTRACK" {
+ return cons.InvalidDnBackupMode
+ }
+
+ if in.Instance == "" {
+ return cons.MissingInstance
+ }
+ return nil
+}
diff --git a/pitr/agent/internal/handler/show.go b/pitr/agent/internal/handler/view/restore.go
similarity index 50%
copy from pitr/agent/internal/handler/show.go
copy to pitr/agent/internal/handler/view/restore.go
index e92efd7..75d3ba5 100644
--- a/pitr/agent/internal/handler/show.go
+++ b/pitr/agent/internal/handler/view/restore.go
@@ -15,10 +15,46 @@
* limitations under the License.
*/
-package handler
+package view
-import "github.com/gofiber/fiber/v2"
+import "github.com/apache/shardingsphere-on-cloud/pitr/agent/internal/cons"
-func Show(ctx *fiber.Ctx) error {
+type RestoreIn struct {
+ DbPort uint16 `json:"db_port"`
+ Username string `json:"username"`
+ Password string `json:"password"`
+ Instance string `json:"instance"`
+ DnBackupPath string `json:"dn_backup_path"`
+ DnBackupId string `json:"dn_backup_id"`
+}
+
+func (in *RestoreIn) Validate() error {
+ if in == nil {
+ return cons.Internal
+ }
+
+ if in.DbPort == 0 {
+ return cons.InvalidDbPort
+ }
+
+ if in.Username == "" {
+ return cons.MissingUsername
+ }
+
+ if in.Password == "" {
+ return cons.MissingPassword
+ }
+
+ if in.DnBackupPath == "" {
+ return cons.MissingDnBackupPath
+ }
+
+ if in.DnBackupId == "" {
+ return cons.MissingDnBackupId
+ }
+
+ if in.Instance == "" {
+ return cons.MissingInstance
+ }
return nil
}
diff --git a/pitr/agent/internal/handler/show.go b/pitr/agent/internal/handler/view/show.go
similarity index 50%
copy from pitr/agent/internal/handler/show.go
copy to pitr/agent/internal/handler/view/show.go
index e92efd7..5551187 100644
--- a/pitr/agent/internal/handler/show.go
+++ b/pitr/agent/internal/handler/view/show.go
@@ -15,10 +15,46 @@
* limitations under the License.
*/
-package handler
+package view
-import "github.com/gofiber/fiber/v2"
+import "github.com/apache/shardingsphere-on-cloud/pitr/agent/internal/cons"
-func Show(ctx *fiber.Ctx) error {
+type ShowIn struct {
+ DbPort uint16 `json:"db_port"`
+ Username string `json:"username"`
+ Password string `json:"password"`
+ DnBackupId string `json:"dn_backup_id"`
+ DnBackupPath string `json:"dn_backup_path"`
+ Instance string `json:"instance"`
+}
+
+func (in *ShowIn) Validate() error {
+ if in == nil {
+ return cons.Internal
+ }
+
+ if in.DbPort == 0 {
+ return cons.InvalidDbPort
+ }
+
+ if in.Username == "" {
+ return cons.MissingUsername
+ }
+
+ if in.Password == "" {
+ return cons.MissingPassword
+ }
+
+ if in.DnBackupPath == "" {
+ return cons.MissingDnBackupPath
+ }
+
+ if in.DnBackupId == "" {
+ return cons.MissingDnBackupId
+ }
+
+ if in.Instance == "" {
+ return cons.MissingInstance
+ }
return nil
}
diff --git a/pitr/agent/internal/pkg/opengauss_test.go b/pitr/agent/internal/pkg/opengauss_test.go
index fef26e8..ee451b7 100644
--- a/pitr/agent/internal/pkg/opengauss_test.go
+++ b/pitr/agent/internal/pkg/opengauss_test.go
@@ -153,7 +153,7 @@ var _ = Describe("OpenGauss,requires opengauss environment", func() {
Expect(err).To(BeNil())
err = og.Stop(pgData)
- Expect(errors.Is(err, cons.StopOpenGaussFailed)).To(BeTrue())
+ Expect(errors.Is(err, cons.StopOpenGaussFailed)).To(BeTrue())
err = og.Start(pgData)
Expect(err).To(BeNil())