[
https://issues.apache.org/jira/browse/SCB-949?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16644388#comment-16644388
]
ASF GitHub Bot commented on SCB-949:
------------------------------------
little-cui closed pull request #455: SCB-949 Support access distinct kubernetes
clusters
URL: https://github.com/apache/incubator-servicecomb-service-center/pull/455
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/etc/conf/app.conf b/etc/conf/app.conf
index 7e239977..4407f85e 100644
--- a/etc/conf/app.conf
+++ b/etc/conf/app.conf
@@ -73,7 +73,9 @@ manager_cluster = "127.0.0.1:2379"
# default 30s if value less then 0
auto_sync_interval = 30s
-# request registry time out
+# the timeout for failing to establish a connection
+connect_timeout = 10s
+# the timeout for failing to read response of registry
registry_timeout = 30s
# indicate how many revision you want to keep in etcd
diff --git a/pkg/etcdsync/mutex.go b/pkg/etcdsync/mutex.go
index 8731db17..88cffb4d 100644
--- a/pkg/etcdsync/mutex.go
+++ b/pkg/etcdsync/mutex.go
@@ -135,7 +135,7 @@ func (m *DLock) Lock(wait bool) (err error) {
return fmt.Errorf("Key %s is locked by id=%s", m.builder.key,
m.id)
}
- log.Errorf(err, "Key %s is locked, waiting for other node releases it,
id=%s, %s", m.builder.key, m.id)
+ log.Errorf(err, "Key %s is locked, waiting for other node releases it,
id=%s", m.builder.key, m.id)
ctx, cancel := context.WithTimeout(m.builder.ctx,
time.Duration(m.builder.ttl)*time.Second)
gopool.Go(func(context.Context) {
diff --git a/server/broker/store.go b/server/broker/store.go
index 68c16bca..4bffcb0c 100644
--- a/server/broker/store.go
+++ b/server/broker/store.go
@@ -34,13 +34,20 @@ var (
var brokerKvStore = &BKvStore{}
func init() {
- PARTICIPANT =
backend.Store().MustInstall(discovery.NewAddOn("PARTICIPANT",
discovery.Configure().WithPrefix(GetBrokerParticipantKey(""))))
- VERSION = backend.Store().MustInstall(discovery.NewAddOn("VERSION",
discovery.Configure().WithPrefix(GetBrokerVersionKey(""))))
- PACT = backend.Store().MustInstall(discovery.NewAddOn("PACT",
discovery.Configure().WithPrefix(GetBrokerPactKey(""))))
- PACT_VERSION =
backend.Store().MustInstall(discovery.NewAddOn("PACT_VERSION",
discovery.Configure().WithPrefix(GetBrokerPactVersionKey(""))))
- PACT_TAG = backend.Store().MustInstall(discovery.NewAddOn("PACT_TAG",
discovery.Configure().WithPrefix(GetBrokerTagKey(""))))
- VERIFICATION =
backend.Store().MustInstall(discovery.NewAddOn("VERIFICATION",
discovery.Configure().WithPrefix(GetBrokerVerificationKey(""))))
- PACT_LATEST =
backend.Store().MustInstall(discovery.NewAddOn("PACT_LATEST",
discovery.Configure().WithPrefix(GetBrokerLatestKey(""))))
+ PARTICIPANT =
backend.Store().MustInstall(backend.NewAddOn("PARTICIPANT",
+ discovery.Configure().WithPrefix(GetBrokerParticipantKey(""))))
+ VERSION = backend.Store().MustInstall(backend.NewAddOn("VERSION",
+ discovery.Configure().WithPrefix(GetBrokerVersionKey(""))))
+ PACT = backend.Store().MustInstall(backend.NewAddOn("PACT",
+ discovery.Configure().WithPrefix(GetBrokerPactKey(""))))
+ PACT_VERSION =
backend.Store().MustInstall(backend.NewAddOn("PACT_VERSION",
+ discovery.Configure().WithPrefix(GetBrokerPactVersionKey(""))))
+ PACT_TAG = backend.Store().MustInstall(backend.NewAddOn("PACT_TAG",
+ discovery.Configure().WithPrefix(GetBrokerTagKey(""))))
+ VERIFICATION =
backend.Store().MustInstall(backend.NewAddOn("VERIFICATION",
+ discovery.Configure().WithPrefix(GetBrokerVerificationKey(""))))
+ PACT_LATEST =
backend.Store().MustInstall(backend.NewAddOn("PACT_LATEST",
+ discovery.Configure().WithPrefix(GetBrokerLatestKey(""))))
}
type BKvStore struct {
diff --git a/server/plugin/pkg/discovery/extend.go
b/server/core/backend/addon.go
similarity index 66%
rename from server/plugin/pkg/discovery/extend.go
rename to server/core/backend/addon.go
index 572f1b9d..18c18136 100644
--- a/server/plugin/pkg/discovery/extend.go
+++ b/server/core/backend/addon.go
@@ -14,49 +14,33 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package discovery
+package backend
import (
- "errors"
- "fmt"
+
"github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/discovery"
)
type AddOn interface {
Name() string
- Config() *Config
+ Config() *discovery.Config
}
type addOn struct {
name string
- cfg *Config
+ cfg *discovery.Config
}
func (e *addOn) Name() string {
return e.name
}
-func (e *addOn) Config() *Config {
+func (e *addOn) Config() *discovery.Config {
return e.cfg
}
-func NewAddOn(name string, cfg *Config) AddOn {
+func NewAddOn(name string, cfg *discovery.Config) AddOn {
return &addOn{
name: name,
cfg: cfg,
}
}
-
-func Install(e AddOn) (id Type, err error) {
- if e == nil || len(e.Name()) == 0 || e.Config() == nil {
- return TypeError, errors.New("invalid parameter")
- }
- for _, n := range typeNames {
- if n == e.Name() {
- return TypeError, fmt.Errorf("redeclare store type
'%s'", n)
- }
- }
-
- id = RegisterType(e.Name())
- EventProxy(id).InjectConfig(e.Config())
- return
-}
diff --git a/server/core/backend/common.go b/server/core/backend/common.go
index df6b6769..8b4e5b94 100644
--- a/server/core/backend/common.go
+++ b/server/core/backend/common.go
@@ -49,47 +49,47 @@ var (
)
func registerInnerTypes() {
- SERVICE = Store().MustInstall(discovery.NewAddOn("SERVICE",
+ SERVICE = Store().MustInstall(NewAddOn("SERVICE",
discovery.Configure().WithPrefix(core.GetServiceRootKey("")).
WithInitSize(500).WithParser(pb.ServiceParser)))
- INSTANCE = Store().MustInstall(discovery.NewAddOn("INSTANCE",
+ INSTANCE = Store().MustInstall(NewAddOn("INSTANCE",
discovery.Configure().WithPrefix(core.GetInstanceRootKey("")).
WithInitSize(1000).WithParser(pb.InstanceParser).
WithDeferHandler(NewInstanceEventDeferHandler())))
- DOMAIN = Store().MustInstall(discovery.NewAddOn("DOMAIN",
+ DOMAIN = Store().MustInstall(NewAddOn("DOMAIN",
discovery.Configure().WithPrefix(core.GetDomainRootKey()+core.SPLIT).
WithInitSize(100).WithParser(pb.StringParser)))
- SCHEMA = Store().MustInstall(discovery.NewAddOn("SCHEMA",
+ SCHEMA = Store().MustInstall(NewAddOn("SCHEMA",
discovery.Configure().WithPrefix(core.GetServiceSchemaRootKey("")).
WithInitSize(0)))
- SCHEMA_SUMMARY =
Store().MustInstall(discovery.NewAddOn("SCHEMA_SUMMARY",
+ SCHEMA_SUMMARY = Store().MustInstall(NewAddOn("SCHEMA_SUMMARY",
discovery.Configure().WithPrefix(core.GetServiceSchemaSummaryRootKey("")).
WithInitSize(100).WithParser(pb.StringParser)))
- RULE = Store().MustInstall(discovery.NewAddOn("RULE",
+ RULE = Store().MustInstall(NewAddOn("RULE",
discovery.Configure().WithPrefix(core.GetServiceRuleRootKey("")).
WithInitSize(100).WithParser(pb.RuleParser)))
- LEASE = Store().MustInstall(discovery.NewAddOn("LEASE",
+ LEASE = Store().MustInstall(NewAddOn("LEASE",
discovery.Configure().WithPrefix(core.GetInstanceLeaseRootKey("")).
WithInitSize(1000).WithParser(pb.StringParser)))
- SERVICE_INDEX = Store().MustInstall(discovery.NewAddOn("SERVICE_INDEX",
+ SERVICE_INDEX = Store().MustInstall(NewAddOn("SERVICE_INDEX",
discovery.Configure().WithPrefix(core.GetServiceIndexRootKey("")).
WithInitSize(500).WithParser(pb.StringParser)))
- SERVICE_ALIAS = Store().MustInstall(discovery.NewAddOn("SERVICE_ALIAS",
+ SERVICE_ALIAS = Store().MustInstall(NewAddOn("SERVICE_ALIAS",
discovery.Configure().WithPrefix(core.GetServiceAliasRootKey("")).
WithInitSize(100).WithParser(pb.StringParser)))
- SERVICE_TAG = Store().MustInstall(discovery.NewAddOn("SERVICE_TAG",
+ SERVICE_TAG = Store().MustInstall(NewAddOn("SERVICE_TAG",
discovery.Configure().WithPrefix(core.GetServiceTagRootKey("")).
WithInitSize(100).WithParser(pb.MapParser)))
- RULE_INDEX = Store().MustInstall(discovery.NewAddOn("RULE_INDEX",
+ RULE_INDEX = Store().MustInstall(NewAddOn("RULE_INDEX",
discovery.Configure().WithPrefix(core.GetServiceRuleIndexRootKey("")).
WithInitSize(100).WithParser(pb.StringParser)))
- DEPENDENCY_RULE =
Store().MustInstall(discovery.NewAddOn("DEPENDENCY_RULE",
+ DEPENDENCY_RULE = Store().MustInstall(NewAddOn("DEPENDENCY_RULE",
discovery.Configure().WithPrefix(core.GetServiceDependencyRuleRootKey("")).
WithInitSize(100).WithParser(pb.DependencyRuleParser)))
- DEPENDENCY_QUEUE =
Store().MustInstall(discovery.NewAddOn("DEPENDENCY_QUEUE",
+ DEPENDENCY_QUEUE = Store().MustInstall(NewAddOn("DEPENDENCY_QUEUE",
discovery.Configure().WithPrefix(core.GetServiceDependencyQueueRootKey("")).
WithInitSize(100).WithParser(pb.DependencyQueueParser)))
- PROJECT = Store().MustInstall(discovery.NewAddOn("PROJECT",
+ PROJECT = Store().MustInstall(NewAddOn("PROJECT",
discovery.Configure().WithPrefix(core.GetProjectRootKey("")).
WithInitSize(100).WithParser(pb.StringParser)))
}
diff --git a/server/core/backend/discovery.go b/server/core/backend/discovery.go
index 1e6435b4..14f55a37 100644
--- a/server/core/backend/discovery.go
+++ b/server/core/backend/discovery.go
@@ -17,6 +17,7 @@
package backend
import (
+ "errors"
"github.com/apache/incubator-servicecomb-service-center/pkg/gopool"
"github.com/apache/incubator-servicecomb-service-center/pkg/log"
"github.com/apache/incubator-servicecomb-service-center/pkg/task"
@@ -36,8 +37,8 @@ func init() {
}
type KvStore struct {
- addOns *util.ConcurrentMap
- adaptors *util.ConcurrentMap
+ AddOns map[discovery.Type]AddOn
+ adaptors util.ConcurrentMap
taskService task.TaskService
lock sync.RWMutex
ready chan struct{}
@@ -47,8 +48,7 @@ type KvStore struct {
}
func (s *KvStore) Initialize() {
- s.addOns = util.NewConcurrentMap(0)
- s.adaptors = util.NewConcurrentMap(0)
+ s.AddOns = make(map[discovery.Type]AddOn, 0)
s.taskService = task.NewTaskService()
s.ready = make(chan struct{})
s.goroutine = gopool.New(context.Background())
@@ -70,9 +70,9 @@ func (s *KvStore) repo() discovery.AdaptorRepository {
func (s *KvStore) getOrCreateAdaptor(t discovery.Type) discovery.Adaptor {
v, _ := s.adaptors.Fetch(t, func() (interface{}, error) {
- addOn, ok := s.addOns.Get(t)
+ addOn, ok := s.AddOns[t]
if ok {
- adaptor := s.repo().New(t,
addOn.(discovery.AddOn).Config())
+ adaptor := s.repo().New(t, addOn.(AddOn).Config())
adaptor.Run()
return adaptor, nil
}
@@ -89,7 +89,7 @@ func (s *KvStore) Run() {
func (s *KvStore) store(ctx context.Context) {
// new all types
- for _, t := range discovery.Types() {
+ for _, t := range discovery.Types {
select {
case <-ctx.Done():
return
@@ -131,19 +131,27 @@ func (s *KvStore) Ready() <-chan struct{} {
return s.ready
}
-func (s *KvStore) Install(addOn discovery.AddOn) (id discovery.Type, err
error) {
- if id, err = discovery.Install(addOn); err != nil {
+func (s *KvStore) Install(addOn AddOn) (id discovery.Type, err error) {
+ if addOn == nil || len(addOn.Name()) == 0 || addOn.Config() == nil {
+ return discovery.TypeError, errors.New("invalid parameter")
+ }
+
+ id, err = discovery.RegisterType(addOn.Name())
+ if err != nil {
return
}
+
+ discovery.EventProxy(id).InjectConfig(addOn.Config())
+
s.InjectConfig(addOn.Config())
- s.addOns.Put(id, addOn)
+ s.AddOns[id] = addOn
log.Infof("install new type %d:%s->%s", id, addOn.Name(),
addOn.Config().Key)
return
}
-func (s *KvStore) MustInstall(addOn discovery.AddOn) discovery.Type {
+func (s *KvStore) MustInstall(addOn AddOn) discovery.Type {
id, err := s.Install(addOn)
if err != nil {
panic(err)
diff --git a/server/core/backend/discovery_test.go
b/server/core/backend/discovery_test.go
index 1c5102ef..86937ad3 100644
--- a/server/core/backend/discovery_test.go
+++ b/server/core/backend/discovery_test.go
@@ -118,8 +118,8 @@ func TestInstallType(t *testing.T) {
}
// case: inject config
- itf, _ := s.addOns.Get(id)
- cfg := itf.(discovery.AddOn).Config()
+ itf, _ := s.AddOns[id]
+ cfg := itf.(AddOn).Config()
if cfg == nil || cfg.OnEvent == nil {
t.Fatal("installType fail", err)
}
@@ -131,8 +131,34 @@ func TestInstallType(t *testing.T) {
// case: install again
cfg = discovery.Configure().WithPrefix("/test")
- id, err = s.Install(discovery.NewAddOn("test", cfg))
+ id, err = s.Install(NewAddOn("test", cfg))
if id != discovery.TypeError || err == nil {
t.Fatal("installType fail", err)
}
}
+
+func TestNewAddOn(t *testing.T) {
+ s := &KvStore{}
+ s.Initialize()
+
+ id, err := s.Install(NewAddOn("TestNewAddOn", nil))
+ if id != discovery.TypeError || err == nil {
+ t.Fatalf("TestNewAddOn failed")
+ }
+ id, err = s.Install(NewAddOn("", discovery.Configure()))
+ if id != discovery.TypeError || err == nil {
+ t.Fatalf("TestNewAddOn failed")
+ }
+ id, err = s.Install(nil)
+ if id != discovery.TypeError || err == nil {
+ t.Fatalf("TestNewAddOn failed")
+ }
+ id, err = s.Install(NewAddOn("TestNewAddOn", discovery.Configure()))
+ if id == discovery.TypeError || err != nil {
+ t.Fatalf("TestNewAddOn failed")
+ }
+ _, err = s.Install(NewAddOn("TestNewAddOn", discovery.Configure()))
+ if err == nil {
+ t.Fatalf("TestNewAddOn failed")
+ }
+}
diff --git a/server/plugin/pkg/discovery/aggregate/adaptor.go
b/server/plugin/pkg/discovery/aggregate/adaptor.go
index 3965eca6..ad1327e5 100644
--- a/server/plugin/pkg/discovery/aggregate/adaptor.go
+++ b/server/plugin/pkg/discovery/aggregate/adaptor.go
@@ -13,12 +13,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package sc
+package aggregate
import (
+ mgr
"github.com/apache/incubator-servicecomb-service-center/server/plugin"
"github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/discovery"
-
"github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/discovery/k8s"
-
"github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/discovery/sc"
"github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/registry"
"golang.org/x/net/context"
)
@@ -64,7 +63,9 @@ func (as *Aggregator) Ready() <-chan struct{} {
func NewAggregator(t discovery.Type, cfg *discovery.Config) (as *Aggregator) {
as = &Aggregator{}
- *as = append(*as, k8s.NewK8sAdaptor(t, cfg))
- *as = append(*as, sc.NewServiceCenterAdaptor(t, cfg))
+ for _, name := range repos {
+ repo := mgr.Plugins().Get(mgr.DISCOVERY,
name).New().(discovery.AdaptorRepository)
+ *as = append(*as, repo.New(t, cfg))
+ }
return as
}
diff --git a/server/plugin/pkg/discovery/aggregate/common.go
b/server/plugin/pkg/discovery/aggregate/common.go
index d8448ae2..48679e05 100644
--- a/server/plugin/pkg/discovery/aggregate/common.go
+++ b/server/plugin/pkg/discovery/aggregate/common.go
@@ -13,10 +13,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package sc
+package aggregate
var (
closedCh = make(chan struct{})
+ repos = []string{"k8s", "servicecenter"}
)
func init() {
diff --git a/server/plugin/pkg/discovery/aggregate/repo.go
b/server/plugin/pkg/discovery/aggregate/repo.go
index 4fd9f020..e7f34b3a 100644
--- a/server/plugin/pkg/discovery/aggregate/repo.go
+++ b/server/plugin/pkg/discovery/aggregate/repo.go
@@ -13,7 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package sc
+package aggregate
import (
mgr
"github.com/apache/incubator-servicecomb-service-center/server/plugin"
diff --git a/server/plugin/pkg/discovery/k8s/adaptor.go
b/server/plugin/pkg/discovery/k8s/adaptor/adaptor.go
similarity index 99%
rename from server/plugin/pkg/discovery/k8s/adaptor.go
rename to server/plugin/pkg/discovery/k8s/adaptor/adaptor.go
index 4ea90f23..b96c4df0 100644
--- a/server/plugin/pkg/discovery/k8s/adaptor.go
+++ b/server/plugin/pkg/discovery/k8s/adaptor/adaptor.go
@@ -13,7 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package k8s
+package adaptor
import (
"github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/discovery"
diff --git a/server/plugin/pkg/discovery/k8s/cacher.go
b/server/plugin/pkg/discovery/k8s/adaptor/cacher.go
similarity index 98%
rename from server/plugin/pkg/discovery/k8s/cacher.go
rename to server/plugin/pkg/discovery/k8s/adaptor/cacher.go
index e92f5d60..dcaade9b 100644
--- a/server/plugin/pkg/discovery/k8s/cacher.go
+++ b/server/plugin/pkg/discovery/k8s/adaptor/cacher.go
@@ -13,7 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package k8s
+package adaptor
import (
"github.com/apache/incubator-servicecomb-service-center/server/core/backend"
diff --git a/server/plugin/pkg/discovery/k8s/cacher_index.go
b/server/plugin/pkg/discovery/k8s/adaptor/cacher_index.go
similarity index 99%
rename from server/plugin/pkg/discovery/k8s/cacher_index.go
rename to server/plugin/pkg/discovery/k8s/adaptor/cacher_index.go
index ac31669e..2f0651c2 100644
--- a/server/plugin/pkg/discovery/k8s/cacher_index.go
+++ b/server/plugin/pkg/discovery/k8s/adaptor/cacher_index.go
@@ -13,7 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package k8s
+package adaptor
import (
"github.com/apache/incubator-servicecomb-service-center/server/core"
diff --git a/server/plugin/pkg/discovery/k8s/cacher_instance.go
b/server/plugin/pkg/discovery/k8s/adaptor/cacher_instance.go
similarity index 99%
rename from server/plugin/pkg/discovery/k8s/cacher_instance.go
rename to server/plugin/pkg/discovery/k8s/adaptor/cacher_instance.go
index 0179058a..852c69e7 100644
--- a/server/plugin/pkg/discovery/k8s/cacher_instance.go
+++ b/server/plugin/pkg/discovery/k8s/adaptor/cacher_instance.go
@@ -13,7 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package k8s
+package adaptor
import (
"github.com/apache/incubator-servicecomb-service-center/pkg/util"
diff --git a/server/plugin/pkg/discovery/k8s/cacher_service.go
b/server/plugin/pkg/discovery/k8s/adaptor/cacher_service.go
similarity index 99%
rename from server/plugin/pkg/discovery/k8s/cacher_service.go
rename to server/plugin/pkg/discovery/k8s/adaptor/cacher_service.go
index 3ec5bb52..c1455ba7 100644
--- a/server/plugin/pkg/discovery/k8s/cacher_service.go
+++ b/server/plugin/pkg/discovery/k8s/adaptor/cacher_service.go
@@ -13,7 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package k8s
+package adaptor
import (
"github.com/apache/incubator-servicecomb-service-center/server/core"
diff --git a/server/plugin/pkg/discovery/k8s/common.go
b/server/plugin/pkg/discovery/k8s/adaptor/common.go
similarity index 99%
rename from server/plugin/pkg/discovery/k8s/common.go
rename to server/plugin/pkg/discovery/k8s/adaptor/common.go
index 5c2353e2..ed9a88f6 100644
--- a/server/plugin/pkg/discovery/k8s/common.go
+++ b/server/plugin/pkg/discovery/k8s/adaptor/common.go
@@ -13,7 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package k8s
+package adaptor
import (
"github.com/apache/incubator-servicecomb-service-center/pkg/queue"
diff --git a/server/plugin/pkg/discovery/k8s/convertor.go
b/server/plugin/pkg/discovery/k8s/adaptor/convertor.go
similarity index 99%
rename from server/plugin/pkg/discovery/k8s/convertor.go
rename to server/plugin/pkg/discovery/k8s/adaptor/convertor.go
index bdff0216..a3239adb 100644
--- a/server/plugin/pkg/discovery/k8s/convertor.go
+++ b/server/plugin/pkg/discovery/k8s/adaptor/convertor.go
@@ -13,7 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package k8s
+package adaptor
import (
"github.com/apache/incubator-servicecomb-service-center/pkg/util"
diff --git a/server/plugin/pkg/discovery/k8s/kube_client.go
b/server/plugin/pkg/discovery/k8s/adaptor/kube_client.go
similarity index 99%
rename from server/plugin/pkg/discovery/k8s/kube_client.go
rename to server/plugin/pkg/discovery/k8s/adaptor/kube_client.go
index 03a5d05c..422d9a93 100644
--- a/server/plugin/pkg/discovery/k8s/kube_client.go
+++ b/server/plugin/pkg/discovery/k8s/adaptor/kube_client.go
@@ -13,7 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package k8s
+package adaptor
import (
"github.com/apache/incubator-servicecomb-service-center/pkg/gopool"
diff --git a/server/plugin/pkg/discovery/k8s/listwatcher.go
b/server/plugin/pkg/discovery/k8s/adaptor/listwatcher.go
similarity index 99%
rename from server/plugin/pkg/discovery/k8s/listwatcher.go
rename to server/plugin/pkg/discovery/k8s/adaptor/listwatcher.go
index 9a52be2a..035f072f 100644
--- a/server/plugin/pkg/discovery/k8s/listwatcher.go
+++ b/server/plugin/pkg/discovery/k8s/adaptor/listwatcher.go
@@ -13,7 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package k8s
+package adaptor
import (
"github.com/apache/incubator-servicecomb-service-center/pkg/queue"
diff --git a/server/plugin/pkg/discovery/extend_test.go
b/server/plugin/pkg/discovery/k8s/nok8s.go
similarity index 55%
rename from server/plugin/pkg/discovery/extend_test.go
rename to server/plugin/pkg/discovery/k8s/nok8s.go
index 55fc7a12..5e9d67b5 100644
--- a/server/plugin/pkg/discovery/extend_test.go
+++ b/server/plugin/pkg/discovery/k8s/nok8s.go
@@ -13,29 +13,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package discovery
+// +build nok8s
-import "testing"
+package k8s
-func TestNewAddOn(t *testing.T) {
- id, err := Install(NewAddOn("TestNewAddOn", nil))
- if id != TypeError || err == nil {
- t.Fatalf("TestNewAddOn failed")
- }
- id, err = Install(NewAddOn("", Configure()))
- if id != TypeError || err == nil {
- t.Fatalf("TestNewAddOn failed")
- }
- id, err = Install(nil)
- if id != TypeError || err == nil {
- t.Fatalf("TestNewAddOn failed")
- }
- id, err = Install(NewAddOn("TestNewAddOn", Configure()))
- if id == TypeError || err != nil {
- t.Fatalf("TestNewAddOn failed")
- }
- _, err = Install(NewAddOn("TestNewAddOn", Configure()))
- if err == nil {
- t.Fatalf("TestNewAddOn failed")
- }
+func init() {
}
diff --git a/server/plugin/pkg/discovery/k8s/repo.go
b/server/plugin/pkg/discovery/k8s/repo.go
index ccdb2409..aaf9b405 100644
--- a/server/plugin/pkg/discovery/k8s/repo.go
+++ b/server/plugin/pkg/discovery/k8s/repo.go
@@ -13,11 +13,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+// +build !nok8s
+
package k8s
import (
mgr
"github.com/apache/incubator-servicecomb-service-center/server/plugin"
"github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/discovery"
+
"github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/discovery/k8s/adaptor"
)
func init() {
@@ -28,7 +31,7 @@ type K8sRepository struct {
}
func (r *K8sRepository) New(t discovery.Type, cfg *discovery.Config)
discovery.Adaptor {
- return NewK8sAdaptor(t, cfg)
+ return adaptor.NewK8sAdaptor(t, cfg)
}
func NewRepository() mgr.PluginInstance {
diff --git a/server/plugin/pkg/discovery/types.go
b/server/plugin/pkg/discovery/types.go
index aeed4744..fd918af6 100644
--- a/server/plugin/pkg/discovery/types.go
+++ b/server/plugin/pkg/discovery/types.go
@@ -23,7 +23,10 @@ import (
"strconv"
)
-var typeNames []string
+var (
+ Types []Type
+ typeNames []string
+)
const (
TypeError = Type(-1)
@@ -41,15 +44,14 @@ func (st Type) String() string {
return "TYPE" + strconv.Itoa(int(st))
}
-func Types() (ids []Type) {
- for i := range typeNames {
- ids = append(ids, Type(i))
+func RegisterType(name string) (newId Type, err error) {
+ for _, n := range Types {
+ if n.String() == name {
+ return TypeError, fmt.Errorf("redeclare store type
'%s'", n)
+ }
}
- return
-}
-
-func RegisterType(name string) (newId Type) {
- newId = Type(len(typeNames))
+ newId = Type(len(Types))
+ Types = append(Types, newId)
typeNames = append(typeNames, name)
return
}
diff --git a/server/plugin/pkg/discovery/types_test.go
b/server/plugin/pkg/discovery/types_test.go
index 69dd8b88..e99f764f 100644
--- a/server/plugin/pkg/discovery/types_test.go
+++ b/server/plugin/pkg/discovery/types_test.go
@@ -18,9 +18,16 @@ package discovery
import "testing"
func TestTypes(t *testing.T) {
- id, _ := Install(NewAddOn("TestTypes", Configure()))
+ id, err := RegisterType("TestTypes")
+ if err != nil {
+ t.Fatalf("TestTypes failed")
+ }
+ _, err = RegisterType("TestTypes")
+ if err == nil {
+ t.Fatalf("TestTypes failed")
+ }
found := false
- for _, t := range Types() {
+ for _, t := range Types {
if t == id {
found = true
}
diff --git a/server/plugin/pkg/registry/buildin/buildin.go
b/server/plugin/pkg/registry/buildin/buildin.go
index b6ee6b63..fafb0f82 100644
--- a/server/plugin/pkg/registry/buildin/buildin.go
+++ b/server/plugin/pkg/registry/buildin/buildin.go
@@ -23,9 +23,8 @@ import (
)
var (
- closeCh = make(chan struct{})
- noPluginErr error = nil //fmt.Errorf("register center plugin does not
exist")
- noResponse = ®istry.PluginResponse{}
+ closeCh = make(chan struct{})
+ noResponse = ®istry.PluginResponse{}
)
func init() {
@@ -44,31 +43,31 @@ func (ec *BuildinRegistry) Ready() <-chan struct{} {
return closeCh
}
func (ec *BuildinRegistry) PutNoOverride(ctx context.Context, opts
...registry.PluginOpOption) (bool, error) {
- return false, noPluginErr
+ return false, nil
}
func (ec *BuildinRegistry) Do(ctx context.Context, opts
...registry.PluginOpOption) (*registry.PluginResponse, error) {
- return noResponse, noPluginErr
+ return noResponse, nil
}
func (ec *BuildinRegistry) Txn(ctx context.Context, ops []registry.PluginOp)
(*registry.PluginResponse, error) {
- return noResponse, noPluginErr
+ return noResponse, nil
}
func (ec *BuildinRegistry) TxnWithCmp(ctx context.Context, success
[]registry.PluginOp, cmp []registry.CompareOp, fail []registry.PluginOp)
(*registry.PluginResponse, error) {
- return noResponse, noPluginErr
+ return noResponse, nil
}
func (ec *BuildinRegistry) LeaseGrant(ctx context.Context, TTL int64) (leaseID
int64, err error) {
- return 0, noPluginErr
+ return 0, nil
}
func (ec *BuildinRegistry) LeaseRenew(ctx context.Context, leaseID int64) (TTL
int64, err error) {
- return 0, noPluginErr
+ return 0, nil
}
func (ec *BuildinRegistry) LeaseRevoke(ctx context.Context, leaseID int64)
error {
- return noPluginErr
+ return nil
}
func (ec *BuildinRegistry) Watch(ctx context.Context, opts
...registry.PluginOpOption) error {
- return noPluginErr
+ return nil
}
-func (c *BuildinRegistry) Compact(ctx context.Context, reserve int64) error {
- return noPluginErr
+func (ec *BuildinRegistry) Compact(ctx context.Context, reserve int64) error {
+ return nil
}
func (ec *BuildinRegistry) Close() {
}
diff --git a/server/plugin/pkg/registry/config.go
b/server/plugin/pkg/registry/config.go
index 0e7a61a4..fbfa9f3b 100644
--- a/server/plugin/pkg/registry/config.go
+++ b/server/plugin/pkg/registry/config.go
@@ -68,7 +68,7 @@ func Configuration() *Config {
defaultRegistryConfig.ClusterName =
beego.AppConfig.DefaultString("manager_name", "default")
defaultRegistryConfig.ManagerAddress =
beego.AppConfig.String("manager_addr")
defaultRegistryConfig.ClusterAddresses =
beego.AppConfig.DefaultString("manager_cluster", "http://127.0.0.1:2379")
- defaultRegistryConfig.DialTimeout, err =
time.ParseDuration(beego.AppConfig.DefaultString("registry_timeout", "30s"))
+ defaultRegistryConfig.DialTimeout, err =
time.ParseDuration(beego.AppConfig.DefaultString("connect_timeout", "10s"))
if err != nil {
log.Errorf(err, "connect_timeout is invalid, use
default time %s", defaultDialTimeout)
defaultRegistryConfig.DialTimeout = defaultDialTimeout
----------------------------------------------------------------
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]
> Support access distinct kubernetes clusters
> -------------------------------------------
>
> Key: SCB-949
> URL: https://issues.apache.org/jira/browse/SCB-949
> Project: Apache ServiceComb
> Issue Type: New Feature
> Components: Service-Center
> Reporter: little-cui
> Assignee: little-cui
> Priority: Major
> Fix For: service-center-1.1.0
>
>
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)