You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by GitBox <gi...@apache.org> on 2020/11/30 03:29:46 UTC
[GitHub] [servicecomb-service-center] tianxiaoliang commented on a change in pull request #766: [SCD-2133] governance northbound Interface / abstract access layer
tianxiaoliang commented on a change in pull request #766:
URL: https://github.com/apache/servicecomb-service-center/pull/766#discussion_r532327896
##########
File path: server/resource/v1/gov_resource.go
##########
@@ -50,26 +51,78 @@ func (t *Governance) Create(w http.ResponseWriter, req *http.Request) {
//Put gov config
func (t *Governance) Put(w http.ResponseWriter, req *http.Request) {
-
+ kind := req.URL.Query().Get(":kind")
+ id := req.URL.Query().Get(":id")
+ project := req.URL.Query().Get(":project")
+ body, err := ioutil.ReadAll(req.Body)
+ if err != nil {
+ log.Error("read body err", err)
+ controller.WriteError(w, discovery.ErrInternal, err.Error())
+ return
+ }
+ err = gov.Update(id, kind, project, body)
+ if err != nil {
+ log.Error("create gov err", err)
+ controller.WriteError(w, discovery.ErrInternal, err.Error())
+ return
+ }
+ w.WriteHeader(http.StatusOK)
}
//List return all gov config
func (t *Governance) List(w http.ResponseWriter, req *http.Request) {
+ kind := req.URL.Query().Get(":kind")
+ project := req.URL.Query().Get(":project")
+ app := req.URL.Query().Get("app")
+ environment := req.URL.Query().Get("environment")
+ body, err := gov.List(kind, project, app, environment)
+ if err != nil {
+ log.Error("create gov err", err)
+ controller.WriteError(w, discovery.ErrInternal, err.Error())
+ return
+ }
+ _, _ = w.Write(body)
+ w.WriteHeader(http.StatusOK)
+ w.Header().Set(rest.HeaderContentType, rest.ContentTypeJSON)
+}
+//Get gov config
+func (t *Governance) Get(w http.ResponseWriter, req *http.Request) {
+ id := req.URL.Query().Get(":id")
+ project := req.URL.Query().Get(":project")
+ body, err := gov.Get(id, project)
+ if err != nil {
+ log.Error("create gov err", err)
+ controller.WriteError(w, discovery.ErrInternal, err.Error())
+ return
+ }
+ _, _ = w.Write(body)
Review comment:
err不可忽略
##########
File path: server/service/gov/config_distributor.go
##########
@@ -72,13 +73,42 @@ func Init() error {
}
return nil
}
-func Create(kind string, spec []byte) error {
+
+func Create(kind, project string, spec []byte) error {
var err error
for _, cd := range distributors {
- err = cd.Create(kind, spec)
+ err = cd.Create(kind, project, spec)
if err != nil {
return err
Review comment:
用下errors.Wrap
##########
File path: server/service/gov/kie/kie_distributor.go
##########
@@ -0,0 +1,202 @@
+package kie
+
+import (
+ "context"
+ "encoding/json"
+ "fmt"
+ "github.com/apache/servicecomb-service-center/pkg/gov"
+ "github.com/apache/servicecomb-service-center/server/config"
+ svc "github.com/apache/servicecomb-service-center/server/service/gov"
+ "github.com/ghodss/yaml"
+ "github.com/go-chassis/kie-client"
+ "log"
+ "strings"
+)
+
+type Distributor struct {
+ lbPolicies map[string]*gov.LoadBalancer
+ name string
+ client *kie.Client
+}
+
+const PREFIX = "servicecomb."
+
+const EnableStatus = "enabled"
+
+const ValueType = "text"
+
+const AppKey = "app"
+
+const EnvironmentKey = "environment"
+
+var rule = Validator{}
+
+func (d *Distributor) Create(kind, project string, spec []byte) error {
+ p := &gov.LoadBalancer{}
Review comment:
应该通过kind加载不同的解析策略
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org