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 f7509f1  feat(pitr): agent helath check support schema
     new 327b71e  Merge pull request #334 from Xu-Wentao/pitr
f7509f1 is described below

commit f7509f16401591ac28e62ac87f410e1895d94381
Author: xuwentao <[email protected]>
AuthorDate: Thu May 4 15:09:50 2023 +0800

    feat(pitr): agent helath check support schema
---
 pitr/agent/internal/handler/healthcheck.go      |  7 +++++++
 pitr/agent/internal/handler/view/healthcheck.go |  1 +
 pitr/agent/internal/pkg/mocks/opengauss.go      | 14 ++++++++++++++
 pitr/agent/internal/pkg/opengauss.go            | 14 ++++++++++++++
 pitr/agent/pkg/gsutil/conn.go                   |  8 ++++++++
 5 files changed, 44 insertions(+)

diff --git a/pitr/agent/internal/handler/healthcheck.go 
b/pitr/agent/internal/handler/healthcheck.go
index 877adc0..b2b2973 100644
--- a/pitr/agent/internal/handler/healthcheck.go
+++ b/pitr/agent/internal/handler/healthcheck.go
@@ -38,5 +38,12 @@ func HealthCheck(ctx *fiber.Ctx) error {
                return fmt.Errorf(efmt, in.Username, len(in.Password), 
in.DBName, err)
        }
 
+       // check schema if needed
+       if in.Schema != "" {
+               if err := pkg.OG.CheckSchema(in.Username, in.Password, 
in.DBName, in.DBPort, in.Schema); err != nil {
+                       return fmt.Errorf("pkg.OG.CheckSchema return 
err=%s,wrap=%w", err, err)
+               }
+       }
+
        return responder.Success(ctx, "")
 }
diff --git a/pitr/agent/internal/handler/view/healthcheck.go 
b/pitr/agent/internal/handler/view/healthcheck.go
index f214fa0..d2e9211 100644
--- a/pitr/agent/internal/handler/view/healthcheck.go
+++ b/pitr/agent/internal/handler/view/healthcheck.go
@@ -22,4 +22,5 @@ type HealthCheckIn struct {
        DBName   string `json:"db_name"`
        Username string `json:"username"`
        Password string `json:"password"`
+       Schema   string `json:"schema"`
 }
diff --git a/pitr/agent/internal/pkg/mocks/opengauss.go 
b/pitr/agent/internal/pkg/mocks/opengauss.go
index 9b8f95f..256ad75 100644
--- a/pitr/agent/internal/pkg/mocks/opengauss.go
+++ b/pitr/agent/internal/pkg/mocks/opengauss.go
@@ -77,6 +77,20 @@ func (mr *MockIOpenGaussMockRecorder) Auth(user, password, 
dbName, dbPort interf
        return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Auth", 
reflect.TypeOf((*MockIOpenGauss)(nil).Auth), user, password, dbName, dbPort)
 }
 
+// CheckSchema mocks base method.
+func (m *MockIOpenGauss) CheckSchema(user, password, dbName string, dbPort 
uint16, schema string) error {
+       m.ctrl.T.Helper()
+       ret := m.ctrl.Call(m, "CheckSchema", user, password, dbName, dbPort, 
schema)
+       ret0, _ := ret[0].(error)
+       return ret0
+}
+
+// CheckSchema indicates an expected call of CheckSchema.
+func (mr *MockIOpenGaussMockRecorder) CheckSchema(user, password, dbName, 
dbPort, schema interface{}) *gomock.Call {
+       mr.mock.ctrl.T.Helper()
+       return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CheckSchema", 
reflect.TypeOf((*MockIOpenGauss)(nil).CheckSchema), user, password, dbName, 
dbPort, schema)
+}
+
 // CleanPgDataTemp mocks base method.
 func (m *MockIOpenGauss) CleanPgDataTemp() error {
        m.ctrl.T.Helper()
diff --git a/pitr/agent/internal/pkg/opengauss.go 
b/pitr/agent/internal/pkg/opengauss.go
index 9d463e2..7bf84bd 100644
--- a/pitr/agent/internal/pkg/opengauss.go
+++ b/pitr/agent/internal/pkg/opengauss.go
@@ -52,6 +52,7 @@ type (
                Restore(backupPath, instance, backupID string) error
                ShowBackupList(backupPath, instanceName string) 
([]*model.Backup, error)
                Auth(user, password, dbName string, dbPort uint16) error
+               CheckSchema(user, password, dbName string, dbPort uint16, 
schema string) error
                MvTempToPgData() error
                MvPgDataToTemp() error
                CleanPgDataTemp() error
@@ -362,6 +363,7 @@ func (og *openGauss) Auth(user, password, dbName string, 
dbPort uint16) error {
        if err := _og.Ping(); err != nil {
                return fmt.Errorf("ping openGauss fail[user=%s,pw 
length=%d,dbName=%s],err=%w", user, len(password), dbName, err)
        }
+
        return nil
 }
 
@@ -401,3 +403,15 @@ func (og *openGauss) CleanPgDataTemp() error {
        }
        return nil
 }
+
+func (og *openGauss) CheckSchema(user, password, dbName string, dbPort uint16, 
schema string) error {
+       _og, err := gsutil.Open(user, password, dbName, dbPort)
+       if err != nil {
+               return fmt.Errorf("gsutil.Open failure,err=%w", err)
+       }
+
+       if err := _og.CheckSchema(schema); err != nil {
+               return fmt.Errorf("check openGauss schema 
fail[user=%s,dbName=%s, schema=%s],err=%w", user, dbName, schema, err)
+       }
+       return nil
+}
diff --git a/pitr/agent/pkg/gsutil/conn.go b/pitr/agent/pkg/gsutil/conn.go
index a5bca1d..70308df 100644
--- a/pitr/agent/pkg/gsutil/conn.go
+++ b/pitr/agent/pkg/gsutil/conn.go
@@ -68,3 +68,11 @@ func (og *OpenGauss) Ping() error {
        }
        return og.db.Close()
 }
+
+func (og *OpenGauss) CheckSchema(s string) error {
+       _, err := og.db.Exec(s)
+       if err != nil {
+               return err
+       }
+       return og.db.Close()
+}

Reply via email to