Skip to content

Commit 4a5a8ed

Browse files
authored
Merge pull request #2930 from actiontech/2222
knowledge base support license
2 parents da7b2bc + b331d4f commit 4a5a8ed

File tree

5 files changed

+51
-15
lines changed

5 files changed

+51
-15
lines changed

sqle/config/config.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ type SqleOptions struct {
4141
Service SeviceOpts `yaml:"service"`
4242
OptimizationConfig OptimizationConfig `yaml:"optimization_config"`
4343
SQLRewritingConfig SQLRewritingConfig `yaml:"sql_rewriting_config"`
44-
KnowledgeBaseTempLicense string `yaml:"knowledge_base_temp_license"`
4544
}
4645

4746
type SeviceOpts struct {

sqle/dms/license.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package dms
2+
3+
import (
4+
"context"
5+
"fmt"
6+
pkgHttp "github.com/actiontech/dms/pkg/dms-common/pkg/http"
7+
)
8+
9+
type GetLicenseReply struct {
10+
Code int `json:"code"`
11+
Message string `json:"message"`
12+
Content string `json:"content"` // 只需要Content因此只解析Content
13+
}
14+
15+
// GET /v1/dms/configurations/license Configuration GetLicense
16+
func GetLicense(ctx context.Context, dmsAddr string) (*GetLicenseReply, error) {
17+
// Prepare the header with authorization token (assuming it's similar to the other request)
18+
header := map[string]string{
19+
"Authorization": pkgHttp.DefaultDMSToken, // Replace with your token if needed
20+
}
21+
22+
// Define the response structure to hold the data
23+
reply := &GetLicenseReply{}
24+
25+
// Construct the URL for the GET request
26+
url := fmt.Sprintf("%v/v1/dms/configurations/license", dmsAddr)
27+
28+
// Perform the GET request
29+
if err := pkgHttp.Get(ctx, url, header, nil, reply); err != nil {
30+
return nil, fmt.Errorf("failed to get license from %v: %v", url, err)
31+
}
32+
33+
// Handle the response code (if the reply structure contains such validation)
34+
if reply.Code != 0 { // Assuming a Code field in the reply, modify accordingly
35+
return nil, fmt.Errorf("http reply code(%v) error: %v", reply.Code, reply.Message)
36+
}
37+
38+
// Return the retrieved license data
39+
return reply, nil
40+
}

sqle/license/temp_knowledge_license_ce.go

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

sqle/server/knowledge_base/knowledge_base_ce.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,16 @@
33

44
package knowledge_base
55

6-
import "github.com/actiontech/sqle/sqle/model"
6+
import (
7+
"fmt"
8+
9+
"github.com/actiontech/sqle/sqle/model"
10+
)
711

812
func LoadKnowledge(rulesMap map[string][]*model.Rule) error {
913
return nil
1014
}
15+
16+
func CheckKnowledgeBaseLicense() error {
17+
return fmt.Errorf("license not support knowledge base")
18+
}

sqle/server/support_checker.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ package server
33
import (
44
"fmt"
55

6-
"github.com/actiontech/sqle/sqle/config"
76
"github.com/actiontech/sqle/sqle/driver"
87
driverV2 "github.com/actiontech/sqle/sqle/driver/v2"
9-
"github.com/actiontech/sqle/sqle/license"
8+
svcKnowledgeBase "github.com/actiontech/sqle/sqle/server/knowledge_base"
109
optimization "github.com/actiontech/sqle/sqle/server/optimization/rule"
1110
)
1211

@@ -65,7 +64,7 @@ type knowledgeBaseChecker struct {
6564
}
6665

6766
func (s knowledgeBaseChecker) CheckIsSupport() bool {
68-
if license.CheckKnowledgeBaseLicense(config.GetOptions().SqleOptions.KnowledgeBaseTempLicense) != nil {
67+
if svcKnowledgeBase.CheckKnowledgeBaseLicense() != nil {
6968
return false
7069
}
7170
return true

0 commit comments

Comments
 (0)