asifdxtreme closed pull request #436: SCB-892 Output plugins configs in version 
api
URL: https://github.com/apache/incubator-servicecomb-service-center/pull/436
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/pkg/util/map.go b/pkg/util/map.go
new file mode 100644
index 00000000..f5d85972
--- /dev/null
+++ b/pkg/util/map.go
@@ -0,0 +1,76 @@
+// 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 util
+
+import (
+       "fmt"
+       "reflect"
+       "strconv"
+)
+
+type JSONObject map[string]interface{}
+
+func (c JSONObject) Set(k interface{}, v interface{}) JSONObject {
+       c[toString(k)] = v
+       return c
+}
+
+func (c JSONObject) Bool(k interface{}, def bool) bool {
+       if v, ok := c[toString(k)].(bool); ok {
+               return v
+       }
+       return def
+}
+
+func (c JSONObject) Int(k interface{}, def int) int {
+       if v, ok := c[toString(k)].(int); ok {
+               return v
+       }
+       return def
+}
+
+func (c JSONObject) String(k interface{}, def string) string {
+       if v, ok := c[toString(k)].(string); ok {
+               return v
+       }
+       return def
+}
+
+func (c JSONObject) Object(k interface{}) JSONObject {
+       key := toString(k)
+       if v, ok := c[key].(JSONObject); ok {
+               return v
+       }
+       v := make(JSONObject)
+       c[key] = v
+       return v
+}
+
+func toString(v interface{}) string {
+       r := reflect.ValueOf(v)
+       switch r.Kind() {
+       case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, 
reflect.Int64:
+               return strconv.FormatInt(r.Int(), 10)
+       case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, 
reflect.Uint64:
+               return strconv.FormatUint(r.Uint(), 10)
+       case reflect.Float32, reflect.Float64:
+               return strconv.FormatFloat(r.Float(), 'f', -1, 64)
+       case reflect.String:
+               return r.String()
+       default:
+               return fmt.Sprintf("%#v", v)
+       }
+}
diff --git a/pkg/util/map_test.go b/pkg/util/map_test.go
new file mode 100644
index 00000000..2e4affe2
--- /dev/null
+++ b/pkg/util/map_test.go
@@ -0,0 +1,86 @@
+// 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 util
+
+import (
+       "encoding/json"
+       "fmt"
+       "testing"
+)
+
+func TestNewServerInformation(t *testing.T) {
+       var c JSONObject
+       c = make(JSONObject)
+       if !c.Bool("a", true) {
+               t.Fatalf("TestNewServerInformation failed")
+       }
+       if 1 != c.Int("a", 1) {
+               t.Fatalf("TestNewServerInformation failed")
+       }
+       if "a" != c.String("a", "a") {
+               t.Fatalf("TestNewServerInformation failed")
+       }
+       if nil == c.Object("a") {
+               t.Fatalf("TestNewServerInformation failed")
+       }
+
+       c.Set("a", true)
+       c.Set("b", 1)
+       c.Set("c", "a")
+       c.Object("d").Set("a", false)
+       if !c.Bool("a", true) {
+               t.Fatalf("TestNewServerInformation failed")
+       }
+       if 1 != c.Int("b", 1) {
+               t.Fatalf("TestNewServerInformation failed")
+       }
+       if "a" != c.String("c", "a") {
+               t.Fatalf("TestNewServerInformation failed")
+       }
+       if c.Object("d").Bool("a", true) {
+               t.Fatalf("TestNewServerInformation failed")
+       }
+
+       if "a" != c.String("a", "a") {
+               t.Fatalf("TestNewServerInformation failed")
+       }
+       if !c.Bool("b", true) {
+               t.Fatalf("TestNewServerInformation failed")
+       }
+       if 1 != c.Int("c", 1) {
+               t.Fatalf("TestNewServerInformation failed")
+       }
+       if "a" != c.String("d", "a") {
+               t.Fatalf("TestNewServerInformation failed")
+       }
+       if nil == c.Object("a") {
+               t.Fatalf("TestNewServerInformation failed")
+       }
+
+       c.Set(1, 1)
+       c.Set(uint(2), 2)
+       c.Set(1.2, 1.2)
+       c.Set(1+1i, 0)
+       c.Set(nil, nil)
+       c.Set(make(map[string]string), "")
+       c.Set(make([]string, 1), "")
+       type a struct{}
+       c.Set(a{}, "")
+       c.Set(&a{}, "")
+
+       b, _ := json.Marshal(c)
+       fmt.Println(string(b))
+}
diff --git a/server/admin/model/dump.go b/server/admin/model/dump.go
index 3354d7c6..60ac6ce1 100644
--- a/server/admin/model/dump.go
+++ b/server/admin/model/dump.go
@@ -183,7 +183,7 @@ type DumpRequest struct {
 type DumpResponse struct {
        Response     *pb.Response        `json:"response,omitempty"`
        Info         *version.VersionSet `json:"info,omitempty"`
-       Config       map[string]string   `json:"config,omitempty"`
+       AppConfig    map[string]string   `json:"appConf,omitempty"`
        Environments map[string]string   `json:"environments,omitempty"`
        Cache        *Cache              `json:"cache,omitempty"`
 }
diff --git a/server/admin/service.go b/server/admin/service.go
index 91689b21..b22e05b5 100644
--- a/server/admin/service.go
+++ b/server/admin/service.go
@@ -69,7 +69,7 @@ func (service *AdminService) Dump(ctx context.Context, in 
*model.DumpRequest) (*
        return &model.DumpResponse{
                Response:     pb.CreateResponse(pb.Response_SUCCESS, "Admin 
dump successfully"),
                Info:         version.Ver(),
-               Config:       configs,
+               AppConfig:    configs,
                Environments: environments,
                Cache:        &cache,
        }, nil
diff --git a/server/core/config.go b/server/core/config.go
index 33876e7e..587396b2 100644
--- a/server/core/config.go
+++ b/server/core/config.go
@@ -19,6 +19,7 @@ package core
 import (
        "github.com/apache/incubator-servicecomb-service-center/pkg/log"
        "github.com/apache/incubator-servicecomb-service-center/pkg/plugin"
+       "github.com/apache/incubator-servicecomb-service-center/pkg/util"
        pb 
"github.com/apache/incubator-servicecomb-service-center/server/core/proto"
        "github.com/apache/incubator-servicecomb-service-center/version"
        "github.com/astaxie/beego"
@@ -30,7 +31,7 @@ const (
        INIT_VERSION = "0"
 )
 
-var ServerInfo = new(pb.ServerInformation)
+var ServerInfo = pb.NewServerInformation()
 
 func Configure() {
        setCPUs()
@@ -87,6 +88,7 @@ func newInfo() pb.ServerInformation {
                        LogSys:         beego.AppConfig.DefaultBool("log_sys", 
false),
 
                        PluginsDir: 
beego.AppConfig.DefaultString("plugins_dir", "./plugins"),
+                       Plugins:    make(util.JSONObject),
 
                        EnablePProf: beego.AppConfig.DefaultInt("enable_pprof", 
0) != 0,
                        EnableCache: beego.AppConfig.DefaultInt("enable_cache", 
1) != 0,
diff --git a/server/core/microservice.go b/server/core/microservice.go
index 47adf688..807fdf9c 100644
--- a/server/core/microservice.go
+++ b/server/core/microservice.go
@@ -28,7 +28,7 @@ import (
 
 var (
        ServiceAPI         pb.ServiceCtrlServer
-       InstanceAPI        pb.SerivceInstanceCtrlServerEx
+       InstanceAPI        pb.ServiceInstanceCtrlServerEx
        Service            *pb.MicroService
        Instance           *pb.MicroServiceInstance
        sharedServiceNames map[string]struct{}
diff --git a/server/core/proto/common.go b/server/core/proto/common.go
new file mode 100644
index 00000000..1595eebc
--- /dev/null
+++ b/server/core/proto/common.go
@@ -0,0 +1,93 @@
+// 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 proto
+
+import (
+       scerr 
"github.com/apache/incubator-servicecomb-service-center/server/error"
+)
+
+const (
+       EVT_INIT   EventType = "INIT"
+       EVT_CREATE EventType = "CREATE"
+       EVT_UPDATE EventType = "UPDATE"
+       EVT_DELETE EventType = "DELETE"
+       EVT_EXPIRE EventType = "EXPIRE"
+       EVT_ERROR  EventType = "ERROR"
+       MS_UP      string    = "UP"
+       MS_DOWN    string    = "DOWN"
+
+       MSI_UP           string = "UP"
+       MSI_DOWN         string = "DOWN"
+       MSI_STARTING     string = "STARTING"
+       MSI_OUTOFSERVICE string = "OUTOFSERVICE"
+
+       CHECK_BY_HEARTBEAT string = "push"
+       CHECK_BY_PLATFORM  string = "pull"
+
+       EXISTENCE_MS     string = "microservice"
+       EXISTENCE_SCHEMA string = "schema"
+
+       PROP_ALLOW_CROSS_APP = "allowCrossApp"
+
+       Response_SUCCESS int32 = 0
+
+       ENV_DEV    string = "development"
+       ENV_TEST   string = "testing"
+       ENV_ACCEPT string = "acceptance"
+       ENV_PROD   string = "production"
+
+       REGISTERBY_SDK      string = "SDK"
+       REGISTERBY_SIDECAR  string = "SIDECAR"
+       REGISTERBY_PLATFORM string = "PLATFORM"
+
+       APP_ID  = "default"
+       VERSION = "0.0.1"
+)
+
+func CreateResponse(code int32, message string) *Response {
+       resp := &Response{
+               Code:    code,
+               Message: message,
+       }
+       return resp
+}
+
+func CreateResponseWithSCErr(err *scerr.Error) *Response {
+       return &Response{
+               Code:    err.Code,
+               Message: err.Detail,
+       }
+}
+
+func DependenciesToKeys(in []*MicroServiceKey, domainProject string) 
[]*MicroServiceKey {
+       for _, value := range in {
+               if len(value.Tenant) == 0 {
+                       value.Tenant = domainProject
+               }
+       }
+       return in
+}
+
+func MicroServiceToKey(domainProject string, in *MicroService) 
*MicroServiceKey {
+       return &MicroServiceKey{
+               Tenant:      domainProject,
+               Environment: in.Environment,
+               AppId:       in.AppId,
+               ServiceName: in.ServiceName,
+               Alias:       in.Alias,
+               Version:     in.Version,
+       }
+}
diff --git a/server/core/proto/services.go b/server/core/proto/services.go
index 7fd0d38b..80b158af 100644
--- a/server/core/proto/services.go
+++ b/server/core/proto/services.go
@@ -17,139 +17,14 @@
 package proto
 
 import (
-       scerr 
"github.com/apache/incubator-servicecomb-service-center/server/error"
        "github.com/gorilla/websocket"
        "golang.org/x/net/context"
 )
 
-type EventType string
-
-const (
-       EVT_INIT   EventType = "INIT"
-       EVT_CREATE EventType = "CREATE"
-       EVT_UPDATE EventType = "UPDATE"
-       EVT_DELETE EventType = "DELETE"
-       EVT_EXPIRE EventType = "EXPIRE"
-       EVT_ERROR  EventType = "ERROR"
-       MS_UP      string    = "UP"
-       MS_DOWN    string    = "DOWN"
-
-       MSI_UP           string = "UP"
-       MSI_DOWN         string = "DOWN"
-       MSI_STARTING     string = "STARTING"
-       MSI_OUTOFSERVICE string = "OUTOFSERVICE"
-
-       CHECK_BY_HEARTBEAT string = "push"
-       CHECK_BY_PLATFORM  string = "pull"
-
-       EXISTENCE_MS     string = "microservice"
-       EXISTENCE_SCHEMA string = "schema"
-
-       PROP_ALLOW_CROSS_APP = "allowCrossApp"
-
-       Response_SUCCESS int32 = 0
-
-       ENV_DEV    string = "development"
-       ENV_TEST   string = "testing"
-       ENV_ACCEPT string = "acceptance"
-       ENV_PROD   string = "production"
-
-       REGISTERBY_SDK      string = "SDK"
-       REGISTERBY_SIDECAR  string = "SIDECAR"
-       REGISTERBY_PLATFORM string = "PLATFORM"
-
-       APP_ID  = "default"
-       VERSION = "0.0.1"
-)
-
-type SerivceInstanceCtrlServerEx interface {
+type ServiceInstanceCtrlServerEx interface {
        ServiceInstanceCtrlServer
 
        WebSocketWatch(ctx context.Context, in *WatchInstanceRequest, conn 
*websocket.Conn)
        WebSocketListAndWatch(ctx context.Context, in *WatchInstanceRequest, 
conn *websocket.Conn)
        ClusterHealth(ctx context.Context) (*GetInstancesResponse, error)
 }
-
-type GovernServiceCtrlServerEx interface {
-       GovernServiceCtrlServer
-}
-
-type MicroServiceDependency struct {
-       Dependency []*MicroServiceKey `json:"Dependency,omitempty"`
-}
-
-type ServerConfig struct {
-       MaxHeaderBytes int64 `json:"maxHeaderBytes"`
-       MaxBodyBytes   int64 `json:"maxBodyBytes"`
-
-       ReadHeaderTimeout string `json:"readHeaderTimeout"`
-       ReadTimeout       string `json:"readTimeout"`
-       IdleTimeout       string `json:"idleTimeout"`
-       WriteTimeout      string `json:"writeTimeout"`
-
-       LimitTTLUnit     string `json:"limitTTLUnit"`
-       LimitConnections int64  `json:"limitConnections"`
-       LimitIPLookup    string `json:"limitIPLookup"`
-
-       SslEnabled    bool   `json:"sslEnabled,string"`
-       SslMinVersion string `json:"sslMinVersion"`
-       SslVerifyPeer bool   `json:"sslVerifyPeer,string"`
-       SslCiphers    string `json:"sslCiphers"`
-
-       AutoSyncInterval  string `json:"-"`
-       CompactIndexDelta int64  `json:"-"`
-       CompactInterval   string `json:"-"`
-
-       EnablePProf bool `json:"-"`
-       EnableCache bool `json:"-"`
-
-       LoggerName     string `json:"-"`
-       LogRotateSize  int64  `json:"-"`
-       LogBackupCount int64  `json:"-"`
-       LogFilePath    string `json:"-"`
-       LogLevel       string `json:"-"`
-       LogFormat      string `json:"-"`
-       LogSys         bool   `json:"-"`
-
-       PluginsDir string `json:"-"`
-}
-
-type ServerInformation struct {
-       Version string       `json:"version"`
-       Config  ServerConfig `json:"-"`
-}
-
-func CreateResponse(code int32, message string) *Response {
-       resp := &Response{
-               Code:    code,
-               Message: message,
-       }
-       return resp
-}
-
-func CreateResponseWithSCErr(err *scerr.Error) *Response {
-       return &Response{
-               Code:    err.Code,
-               Message: err.Detail,
-       }
-}
-
-func DependenciesToKeys(in []*MicroServiceKey, domainProject string) 
[]*MicroServiceKey {
-       for _, value := range in {
-               if len(value.Tenant) == 0 {
-                       value.Tenant = domainProject
-               }
-       }
-       return in
-}
-
-func MicroServiceToKey(domainProject string, in *MicroService) 
*MicroServiceKey {
-       return &MicroServiceKey{
-               Tenant:      domainProject,
-               Environment: in.Environment,
-               AppId:       in.AppId,
-               ServiceName: in.ServiceName,
-               Alias:       in.Alias,
-               Version:     in.Version,
-       }
-}
diff --git a/server/core/proto/types.go b/server/core/proto/types.go
new file mode 100644
index 00000000..fce62955
--- /dev/null
+++ b/server/core/proto/types.go
@@ -0,0 +1,72 @@
+// 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 proto
+
+import (
+       "github.com/apache/incubator-servicecomb-service-center/pkg/util"
+)
+
+type EventType string
+
+type MicroServiceDependency struct {
+       Dependency []*MicroServiceKey `json:"Dependency,omitempty"`
+}
+
+type ServerConfig struct {
+       MaxHeaderBytes int64 `json:"maxHeaderBytes"`
+       MaxBodyBytes   int64 `json:"maxBodyBytes"`
+
+       ReadHeaderTimeout string `json:"readHeaderTimeout"`
+       ReadTimeout       string `json:"readTimeout"`
+       IdleTimeout       string `json:"idleTimeout"`
+       WriteTimeout      string `json:"writeTimeout"`
+
+       LimitTTLUnit     string `json:"limitTTLUnit"`
+       LimitConnections int64  `json:"limitConnections"`
+       LimitIPLookup    string `json:"limitIPLookup"`
+
+       SslEnabled    bool   `json:"sslEnabled,string"`
+       SslMinVersion string `json:"sslMinVersion"`
+       SslVerifyPeer bool   `json:"sslVerifyPeer,string"`
+       SslCiphers    string `json:"sslCiphers"`
+
+       AutoSyncInterval  string `json:"-"`
+       CompactIndexDelta int64  `json:"-"`
+       CompactInterval   string `json:"-"`
+
+       EnablePProf bool `json:"-"`
+       EnableCache bool `json:"-"`
+
+       LoggerName     string `json:"-"`
+       LogRotateSize  int64  `json:"-"`
+       LogBackupCount int64  `json:"-"`
+       LogFilePath    string `json:"-"`
+       LogLevel       string `json:"-"`
+       LogFormat      string `json:"-"`
+       LogSys         bool   `json:"-"`
+
+       PluginsDir string          `json:"-"`
+       Plugins    util.JSONObject `json:"plugins"`
+}
+
+type ServerInformation struct {
+       Version string       `json:"version"`
+       Config  ServerConfig `json:"-"`
+}
+
+func NewServerInformation() *ServerInformation {
+       return &ServerInformation{Config: ServerConfig{Plugins: 
make(util.JSONObject)}}
+}
diff --git a/server/govern/govern_suite_test.go 
b/server/govern/govern_suite_test.go
index a5c38b50..3c333c53 100644
--- a/server/govern/govern_suite_test.go
+++ b/server/govern/govern_suite_test.go
@@ -38,7 +38,7 @@ func TestGovern(t *testing.T) {
        RunSpecsWithDefaultAndCustomReporters(t, "model Suite", 
[]Reporter{junitReporter})
 }
 
-var governService pb.GovernServiceCtrlServerEx
+var governService pb.GovernServiceCtrlServer
 
 var _ = BeforeSuite(func() {
        //init plugin
diff --git a/server/govern/service.go b/server/govern/service.go
index 7384a650..fe26eece 100644
--- a/server/govern/service.go
+++ b/server/govern/service.go
@@ -30,7 +30,7 @@ import (
        "golang.org/x/net/context"
 )
 
-var GovernServiceAPI pb.GovernServiceCtrlServerEx = &GovernService{}
+var GovernServiceAPI pb.GovernServiceCtrlServer = &GovernService{}
 
 type GovernService struct {
 }
diff --git a/server/plugin/infra/quota/buildin/buildin.go 
b/server/plugin/infra/quota/buildin/buildin.go
index a4eb7b0c..cac1e9f1 100644
--- a/server/plugin/infra/quota/buildin/buildin.go
+++ b/server/plugin/infra/quota/buildin/buildin.go
@@ -28,6 +28,7 @@ func init() {
 }
 
 func New() mgr.PluginInstance {
+       InitConfigs()
        log.Infof("quota init, service: %d, instance: %d, schema: %d/service, 
tag: %d/service, rule: %d/service",
                quota.DefaultServiceQuota, quota.DefaultInstanceQuota,
                quota.DefaultSchemaQuota, quota.DefaultTagQuota, 
quota.DefaultRuleQuota)
diff --git a/server/plugin/infra/quota/buildin/common.go 
b/server/plugin/infra/quota/buildin/common.go
index d31ef8c5..e47a131b 100644
--- a/server/plugin/infra/quota/buildin/common.go
+++ b/server/plugin/infra/quota/buildin/common.go
@@ -25,6 +25,7 @@ import (
        scerr 
"github.com/apache/incubator-servicecomb-service-center/server/error"
        
"github.com/apache/incubator-servicecomb-service-center/server/infra/quota"
        
"github.com/apache/incubator-servicecomb-service-center/server/infra/registry"
+       mgr 
"github.com/apache/incubator-servicecomb-service-center/server/plugin"
        serviceUtil 
"github.com/apache/incubator-servicecomb-service-center/server/service/util"
        "golang.org/x/net/context"
 )
@@ -113,3 +114,12 @@ func resourceLimitHandler(ctx context.Context, res 
*quota.ApplyQuotaResource) (i
        }
        return resp.Count, nil
 }
+
+func InitConfigs() {
+       mgr.QUOTA.ActiveConfigs().
+               Set("service", quota.DefaultServiceQuota).
+               Set("instance", quota.DefaultInstanceQuota).
+               Set("schema", quota.DefaultSchemaQuota).
+               Set("tag", quota.DefaultTagQuota).
+               Set("rule", quota.DefaultRuleQuota)
+}
diff --git a/server/plugin/plugin.go b/server/plugin/plugin.go
index 9627f794..7511cd07 100644
--- a/server/plugin/plugin.go
+++ b/server/plugin/plugin.go
@@ -20,6 +20,7 @@ import (
        "github.com/apache/incubator-servicecomb-service-center/pkg/log"
        "github.com/apache/incubator-servicecomb-service-center/pkg/plugin"
        "github.com/apache/incubator-servicecomb-service-center/pkg/util"
+       "github.com/apache/incubator-servicecomb-service-center/server/core"
        
"github.com/apache/incubator-servicecomb-service-center/server/infra/auditlog"
        
"github.com/apache/incubator-servicecomb-service-center/server/infra/auth"
        
"github.com/apache/incubator-servicecomb-service-center/server/infra/quota"
@@ -34,7 +35,12 @@ import (
        "sync"
 )
 
-const BUILDIN = "buildin"
+const (
+       BUILDIN       = "buildin"
+       STATIC        = "static"
+       DYNAMIC       = "dynamic"
+       keyPluginName = "name"
+)
 
 const (
        UUID PluginName = iota
@@ -74,6 +80,14 @@ func (pn PluginName) String() string {
        return "PLUGIN" + strconv.Itoa(int(pn))
 }
 
+func (pn PluginName) ActiveConfigs() util.JSONObject {
+       return core.ServerInfo.Config.Plugins.Object(pn.String())
+}
+
+func (pn PluginName) ClearConfigs() {
+       core.ServerInfo.Config.Plugins.Set(pn.String(), nil)
+}
+
 type Plugin struct {
        // plugin class name
        PName PluginName
@@ -151,7 +165,7 @@ func (pm *PluginManager) Instance(pn PluginName) 
PluginInstance {
 
 func (pm *PluginManager) New(pn PluginName) {
        var (
-               title = "static"
+               title = STATIC
                f     func() PluginInstance
        )
 
@@ -159,7 +173,7 @@ func (pm *PluginManager) New(pn PluginName) {
        p := pm.existDynamicPlugin(pn)
        if p != nil {
                wi.dynamic = true
-               title = "dynamic"
+               title = DYNAMIC
                f = p.New
        } else {
                wi.dynamic = false
@@ -175,6 +189,7 @@ func (pm *PluginManager) New(pn PluginName) {
                }
 
                f = p.New
+               pn.ActiveConfigs().Set(keyPluginName, name)
        }
        log.Infof("call %s '%s' plugin %s(), new a '%s' instance",
                title, p.PName, util.FuncName(f), p.Name)
@@ -186,6 +201,7 @@ func (pm *PluginManager) Reload(pn PluginName) {
        wi := pm.instances[pn]
        wi.lock.Lock()
        wi.instance = nil
+       pn.ClearConfigs()
        wi.lock.Unlock()
 }
 
@@ -234,3 +250,9 @@ func DynamicPluginFunc(pn PluginName, funcName string) 
pg.Symbol {
        }
        return f
 }
+
+func LoadPlugins() {
+       for t := PluginName(0); t != typeEnd; t++ {
+               Plugins().Instance(t)
+       }
+}
diff --git a/server/plugin/plugin_test.go b/server/plugin/plugin_test.go
index 7df1e843..2cbf810e 100644
--- a/server/plugin/plugin_test.go
+++ b/server/plugin/plugin_test.go
@@ -41,16 +41,21 @@ func TestPluginManager_New(t *testing.T) {
        times := 0
        fn := func() PluginInstance {
                times++
+               AUTH.ActiveConfigs().Set("a", "a")
                return &mockAuthPlugin{times}
        }
        pm.Register(Plugin{AUTH, "buildin", fn})
 
        i := pm.Instance(AUTH)
-       if i != pm.Instance(AUTH) {
+       if i != pm.Instance(AUTH) || AUTH.ActiveConfigs().String("a", "") != 
"a" {
                t.Fatalf("TestPluginManager_New failed")
        }
 
        pm.ReloadAll()
+       if AUTH.ActiveConfigs().String("a", "") != "" {
+               t.Fatalf("TestPluginManager_New failed")
+       }
+
        n := pm.Instance(AUTH)
        if i == n {
                t.Fatalf("TestPluginManager_New failed")
@@ -63,4 +68,6 @@ func TestPluginManager_New(t *testing.T) {
        }()
        RegisterPlugin(Plugin{PluginName(999), "999", nil})
        DynamicPluginFunc(PluginName(999), "999")
+
+       LoadPlugins()
 }
diff --git a/server/server.go b/server/server.go
index f8048d02..e111874f 100644
--- a/server/server.go
+++ b/server/server.go
@@ -24,6 +24,7 @@ import (
        "github.com/apache/incubator-servicecomb-service-center/server/core"
        
"github.com/apache/incubator-servicecomb-service-center/server/core/backend"
        "github.com/apache/incubator-servicecomb-service-center/server/mux"
+       "github.com/apache/incubator-servicecomb-service-center/server/plugin"
        nf 
"github.com/apache/incubator-servicecomb-service-center/server/service/notification"
        serviceUtil 
"github.com/apache/incubator-servicecomb-service-center/server/service/util"
        "github.com/apache/incubator-servicecomb-service-center/version"
@@ -101,6 +102,9 @@ func (s *ServiceCenterServer) initialize() {
        s.apiServer = GetAPIServer()
        s.goroutine = gopool.New(context.Background())
 
+       // load server plugins
+       plugin.LoadPlugins()
+
        // check version
        s.loadOrUpgradeServerVersion()
 
diff --git a/server/service/microservice.go b/server/service/microservice.go
index ab9b0b71..389b5b9e 100644
--- a/server/service/microservice.go
+++ b/server/service/microservice.go
@@ -38,7 +38,7 @@ import (
 )
 
 type MicroServiceService struct {
-       instanceService pb.SerivceInstanceCtrlServerEx
+       instanceService pb.ServiceInstanceCtrlServerEx
 }
 
 const (
diff --git a/server/service/service.go b/server/service/service.go
index 494db55b..24a5f65b 100644
--- a/server/service/service.go
+++ b/server/service/service.go
@@ -24,7 +24,7 @@ import (
 
 var (
        serviceService  pb.ServiceCtrlServer
-       instanceService pb.SerivceInstanceCtrlServerEx
+       instanceService pb.ServiceInstanceCtrlServerEx
 )
 
 func init() {
@@ -40,6 +40,6 @@ func RegisterGrpcServices(s *grpc.Server) {
        pb.RegisterServiceInstanceCtrlServer(s, instanceService)
 }
 
-func AssembleResources() (pb.ServiceCtrlServer, 
pb.SerivceInstanceCtrlServerEx) {
+func AssembleResources() (pb.ServiceCtrlServer, 
pb.ServiceInstanceCtrlServerEx) {
        return serviceService, instanceService
 }
diff --git a/server/service/service_suite_test.go 
b/server/service/service_suite_test.go
index 09c0a202..7b590989 100644
--- a/server/service/service_suite_test.go
+++ b/server/service/service_suite_test.go
@@ -33,7 +33,7 @@ import (
 )
 
 var serviceResource pb.ServiceCtrlServer
-var instanceResource pb.SerivceInstanceCtrlServerEx
+var instanceResource pb.ServiceInstanceCtrlServerEx
 
 var _ = BeforeSuite(func() {
        //init plugin


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to