You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by as...@apache.org on 2018/09/28 09:14:22 UTC
[incubator-servicecomb-service-center] branch master updated:
SCB-941 Support multiple datacenter deployment (#451)
This is an automated email from the ASF dual-hosted git repository.
asifdxtreme pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-service-center.git
The following commit(s) were added to refs/heads/master by this push:
new 14b3acb SCB-941 Support multiple datacenter deployment (#451)
14b3acb is described below
commit 14b3acb261ca29a093ee12572f1c85a2d6be96e5
Author: little-cui <su...@qq.com>
AuthorDate: Fri Sep 28 17:14:02 2018 +0800
SCB-941 Support multiple datacenter deployment (#451)
* Support discovery microservice by ServiceCenter cluster outside
* Aggregate service center client impl
* Support query schema content
* Restructure code
* Update Examples
* Support bootstrap with aggregate discovery
* Update README and travis config
---
.travis.yml | 18 +-
README.md | 1 +
docs/README.md | 4 +-
.../infrastructures}/docker/README.md | 0
.../infrastructures}/docker/docker-compose.yml | 0
.../infrastructures}/docker/prometheus.yml | 0
.../infrastructures}/k8s/README.md | 10 +-
.../infrastructures}/k8s/etcd/Chart.yaml | 0
.../k8s/etcd/charts/etcd-operator}/.helmignore | 0
.../k8s/etcd/charts/etcd-operator/Chart.yaml | 0
.../k8s/etcd/charts/etcd-operator/OWNERS | 0
.../k8s/etcd/charts/etcd-operator/README.md | 0
.../etcd/charts/etcd-operator/templates/NOTES.txt | 0
.../charts/etcd-operator/templates/_helpers.tpl | 0
.../etcd-operator/templates/backup-etcd-crd.yaml | 0
.../backup-operator-clusterrole-binding.yaml | 0
.../templates/backup-operator-deployment.yaml | 0
.../templates/backup-operator-service-account.yaml | 0
.../etcd-operator/templates/etcd-cluster-crd.yaml | 0
.../templates/operator-cluster-role.yaml | 0
.../templates/operator-clusterrole-binding.yaml | 0
.../templates/operator-deployment.yaml | 0
.../templates/operator-service-account.yaml | 0
.../etcd-operator/templates/restore-etcd-crd.yaml | 0
.../restore-operator-clusterrole-binding.yaml | 0
.../templates/restore-operator-deployment.yaml | 0
.../restore-operator-service-account.yaml | 0
.../templates/restore-operator-service.yaml | 0
.../k8s/etcd/charts/etcd-operator/values.yaml | 0
.../k8s/etcd/templates/_helpers.tpl | 0
.../k8s/etcd/templates/deployment.yaml | 0
.../infrastructures}/k8s/etcd/values.yaml | 0
.../k8s/service-center}/.helmignore | 0
.../infrastructures}/k8s/service-center/Chart.yaml | 0
.../k8s/service-center/templates/NOTES.txt | 0
.../k8s/service-center/templates/_helpers.tpl | 0
.../k8s/service-center/templates/configmap.yaml | 10 +
.../k8s/service-center/templates/deployment.yaml | 0
.../k8s/service-center/templates/ingress.yaml | 0
.../k8s/service-center/templates/rbac.yaml | 0
.../k8s/service-center/templates/service.yaml | 0
.../k8s/service-center/values.yaml | 22 +-
pkg/client/etcd/client.go | 27 +--
.../types_test.go => pkg/client/etcd/config.go | 28 +--
pkg/client/sc/apis.go | 98 +++++---
pkg/client/sc/client.go | 38 ++--
.../types_test.go => pkg/client/sc/config.go | 26 +--
pkg/etcdsync/etcdsync_suite_test.go | 4 +-
pkg/etcdsync/mutex.go | 2 +-
pkg/rest/client.go | 8 +-
scctl/pkg/cmd/cmd.go | 17 +-
scctl/pkg/plugin/diagnose/cmd.go | 14 +-
scctl/pkg/plugin/diagnose/compare_holder.go | 9 +-
scctl/pkg/plugin/diagnose/diagnose.go | 10 +-
scctl/pkg/plugin/get/instance/instance_cmd.go | 8 +-
scctl/pkg/plugin/get/schema/schema_cmd.go | 11 +-
scctl/pkg/plugin/get/service/service_cmd.go | 8 +-
scctl/pkg/plugin/version/cmd.go | 2 +-
scripts/build/local.sh | 2 +
scripts/ut_test_in_docker.sh | 16 +-
server/admin/model/dump.go | 80 +++++--
server/admin/service.go | 3 +-
server/bootstrap/bootstrap.go | 26 ++-
server/broker/service.go | 2 +-
server/broker/store.go | 2 +-
server/broker/util.go | 2 +-
server/core/backend/common.go | 6 +-
server/core/backend/defer_instance.go | 2 +-
server/core/backend/defer_test.go | 2 +-
server/core/backend/discovery.go | 11 +-
server/core/backend/discovery_test.go | 4 +-
server/core/backend/lease.go | 2 +-
server/core/backend/lease_test.go | 2 +-
server/core/backend/registry.go | 2 +-
server/core/key_convertor.go | 16 +-
server/core/key_convertor_test.go | 16 +-
server/core/swagger/v4.yaml | 4 +
server/govern/service.go | 2 +-
.../{infra/discovery/k8s/repo.go => common.go} | 36 ++-
server/plugin/export.go | 69 ++++++
server/plugin/infra/discovery/k8s/cacher.go | 93 --------
server/{infra => plugin/pkg}/auditlog/auditlog.go | 0
server/{infra => plugin/pkg}/auth/auth.go | 0
.../plugin/{infra => pkg}/auth/buildin/buildin.go | 0
server/plugin/pkg/discovery/aggregate/adaptor.go | 70 ++++++
.../pkg/discovery/aggregate/common.go} | 25 +--
.../k8s => pkg/discovery/aggregate}/repo.go | 22 +-
server/{infra => plugin/pkg}/discovery/cache.go | 0
server/{infra => plugin/pkg}/discovery/cache_kv.go | 0
.../{infra => plugin/pkg}/discovery/cache_null.go | 0
.../{infra => plugin/pkg}/discovery/cache_test.go | 0
.../k8s/repo.go => pkg/discovery/cacher.go} | 60 +++--
server/{infra => plugin/pkg}/discovery/common.go | 0
server/{infra => plugin/pkg}/discovery/config.go | 0
.../{infra => plugin/pkg}/discovery/config_test.go | 0
server/{infra => plugin/pkg}/discovery/defer.go | 0
.../{infra => plugin/pkg}/discovery/discovery.go | 3 +
.../{infra => pkg}/discovery/etcd/adaptor.go | 19 +-
.../{infra => pkg}/discovery/etcd/adaptor_test.go | 6 +-
.../{infra => pkg}/discovery/etcd/cacher_kv.go | 4 +-
.../discovery/etcd/cacher_kv_test.go | 4 +-
.../plugin/{infra => pkg}/discovery/etcd/common.go | 2 +-
.../{infra => pkg}/discovery/etcd/indexer_cache.go | 4 +-
.../{infra => pkg}/discovery/etcd/indexer_etcd.go | 4 +-
.../{infra => pkg}/discovery/etcd/indexer_test.go | 4 +-
.../{infra => pkg}/discovery/etcd/listwatch.go | 2 +-
.../discovery/etcd/listwatch_inner.go | 2 +-
.../discovery/etcd/listwatch_test.go | 4 +-
.../{infra => pkg}/discovery/etcd/metrics.go | 0
.../{infra => pkg}/discovery/etcd/metrics_test.go | 0
.../plugin/{infra => pkg}/discovery/etcd/repo.go | 12 +-
.../{infra => pkg}/discovery/etcd/watcher.go | 2 +-
.../{infra => pkg}/discovery/etcd/watcher_inner.go | 2 +-
.../{infra => pkg}/discovery/etcd/watcher_test.go | 2 +-
.../{infra => plugin/pkg}/discovery/event_proxy.go | 0
.../pkg}/discovery/event_proxy_test.go | 0
server/{infra => plugin/pkg}/discovery/extend.go | 0
.../{infra => plugin/pkg}/discovery/extend_test.go | 0
server/{infra => plugin/pkg}/discovery/indexer.go | 2 +-
.../pkg}/discovery/indexer_cache.go | 2 +-
.../pkg}/discovery/indexer_test.go | 2 +-
.../plugin/{infra => pkg}/discovery/k8s/adaptor.go | 4 +-
.../k8s/repo.go => pkg/discovery/k8s/cacher.go} | 35 ++-
.../{infra => pkg}/discovery/k8s/cacher_index.go | 7 +-
.../discovery/k8s/cacher_instance.go | 8 +-
.../{infra => pkg}/discovery/k8s/cacher_service.go | 7 +-
.../plugin/{infra => pkg}/discovery/k8s/common.go | 0
.../{infra => pkg}/discovery/k8s/convertor.go | 2 +-
.../{infra => pkg}/discovery/k8s/kube_client.go | 0
.../{infra => pkg}/discovery/k8s/listwatcher.go | 0
server/plugin/{infra => pkg}/discovery/k8s/repo.go | 12 +-
.../discovery/k8s => pkg/discovery/sc}/adaptor.go | 27 ++-
server/plugin/pkg/discovery/sc/aggregate.go | 96 ++++++++
.../k8s/repo.go => pkg/discovery/sc/cacher.go} | 30 ++-
server/plugin/pkg/discovery/sc/cluster.go | 212 ++++++++++++++++++
.../pkg/discovery/sc/common.go} | 31 +--
.../discovery/k8s => pkg/discovery/sc}/repo.go | 22 +-
server/{infra => plugin/pkg}/discovery/service.go | 0
server/{infra => plugin/pkg}/discovery/types.go | 0
.../{infra => plugin/pkg}/discovery/types_test.go | 0
.../plugin/{infra => pkg}/quota/buildin/buildin.go | 2 +-
.../plugin/{infra => pkg}/quota/buildin/common.go | 6 +-
.../{infra => pkg}/quota/buildin/common_test.go | 2 +-
server/{infra => plugin/pkg}/quota/quota.go | 0
.../plugin/{infra => pkg}/quota/unlimit/unlimit.go | 2 +-
.../{infra => pkg}/registry/buildin/buildin.go | 2 +-
.../k8s/repo.go => pkg/registry/common.go} | 63 ++++--
server/plugin/pkg/registry/config.go | 89 ++++++++
.../registry/embededetcd/embededetcd.go | 21 +-
server/plugin/{infra => pkg}/registry/etcd/etcd.go | 12 +-
.../{infra => pkg}/registry/etcd/etcd_test.go | 26 +--
.../plugin/{infra => pkg}/registry/etcd/logger.go | 0
.../{infra => pkg}/registry/etcd/logger_test.go | 0
.../plugin/{infra => pkg}/registry/etcd/metrics.go | 0
.../plugin/{infra => pkg}/registry/etcd/tracing.go | 4 +-
.../registry.go => plugin/pkg/registry/option.go} | 246 ++-------------------
server/plugin/pkg/registry/registry.go | 41 ++++
server/plugin/pkg/registry/types.go | 123 +++++++++++
.../{infra => pkg}/security/buildin/buildin.go | 0
server/{infra => plugin/pkg}/security/cipher.go | 0
.../plugin/{infra => pkg}/tls/buildin/buildin.go | 0
server/plugin/{infra => pkg}/tls/buildin/tls.go | 0
.../plugin/{infra => pkg}/tls/buildin/tls_test.go | 4 +-
server/{infra => plugin/pkg}/tls/tls.go | 0
.../{infra => pkg}/tracing/buildin/README.md | 0
.../{infra => pkg}/tracing/buildin/buildin.go | 2 +-
.../{infra => pkg}/tracing/buildin/buildin_test.go | 4 +-
.../{infra => pkg}/tracing/buildin/common.go | 0
.../{infra => pkg}/tracing/buildin/common_test.go | 0
.../tracing/buildin/file_collector.go | 0
.../tracing/buildin/file_collector_test.go | 0
.../plugin/{infra => pkg}/tracing/buildin/span.go | 0
.../{infra => pkg}/tracing/buildin/span_test.go | 0
server/{infra => plugin/pkg}/tracing/tracing.go | 2 +-
.../plugin/{infra => pkg}/uuid/buildin/buildin.go | 0
server/{infra => plugin/pkg}/uuid/uuid.go | 0
server/plugin/plugin.go | 100 ---------
.../{infra/discovery/k8s/repo.go => types.go} | 41 ++--
server/service/cache/filter_instances.go | 2 +-
server/service/dependency.go | 2 +-
server/service/event/dependency_event_handler.go | 4 +-
server/service/event/domain_event_handler.go | 2 +-
server/service/event/event.go | 2 +-
server/service/event/instance_event_handler.go | 2 +-
server/service/event/rule_event_handler.go | 2 +-
server/service/event/service_event_handler.go | 2 +-
server/service/event/tag_event_handler.go | 2 +-
server/service/instance.go | 4 +-
server/service/microservice.go | 4 +-
server/service/microservice_test.go | 2 +-
server/service/microservice_validator.go | 2 +-
server/service/notification/websocket_test.go | 4 +-
server/service/rule.go | 4 +-
server/service/rule_test.go | 2 +-
server/service/rule_validator.go | 2 +-
server/service/schema.go | 10 +-
server/service/schema_test.go | 2 +-
server/service/schema_validator.go | 2 +-
server/service/tag.go | 4 +-
server/service/tag_test.go | 2 +-
server/service/tag_validator.go | 2 +-
server/service/util/dependency.go | 2 +-
server/service/util/dependency_query.go | 2 +-
server/service/util/dependency_util.go | 2 +-
server/service/util/domain_util.go | 4 +-
server/service/util/heartbeat_util.go | 2 +-
server/service/util/instance_util.go | 4 +-
server/service/util/microservice_util.go | 6 +-
server/service/util/rule_util.go | 2 +-
server/service/util/schema_util.go | 2 +-
server/service/util/tag_util.go | 2 +-
server/service/util/util.go | 2 +-
server/service/util/util_suite_test.go | 8 +-
server/service/util/versionrule.go | 2 +-
server/service/util/versionrule_test.go | 2 +-
server/version.go | 2 +-
216 files changed, 1390 insertions(+), 1039 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index 008ae3f..0a77d4a 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -10,17 +10,11 @@ go:
before_install:
- go get github.com/mattn/goveralls
- - go get golang.org/x/tools/cmd/cover
- - go get github.com/tedsuo/rata
- - go get github.com/onsi/ginkgo
- - go get github.com/onsi/ginkgo/config
- - go get github.com/onsi/ginkgo/types
- - go get github.com/onsi/ginkgo/ginkgo
- - go get github.com/astaxie/beego
- - go get github.com/onsi/gomega
- - go get github.com/onsi/gomega/gbytes
- curl https://glide.sh/get | sh
-
+ - curl -sL https://deb.nodesource.com/setup_8.x | sudo bash -
+ - sudo apt-get install -y nodejs
+ - npm install -g bower
+
before_script:
- mkdir -p $HOME/gopath/src/github.com/apache/incubator-servicecomb-service-center
- rsync -az ${TRAVIS_BUILD_DIR}/ $HOME/gopath/src/github.com/apache/incubator-servicecomb-service-center/
@@ -33,11 +27,11 @@ install: true
jobs:
include:
- stage: Building Service Center
- script: go build -o servicecenter
+ script: bash -x scripts/build/local.sh
- stage: Unit Testing
script: bash -x scripts/ut_test_in_docker.sh && $HOME/gopath/bin/goveralls -coverprofile=coverage.txt -service=travis-ci
- stage: Integration Testing
- script: bash -x scripts/integration_test.sh
+ script: bash -x scripts/integration_test.sh
after_success:
- bash <(curl -s https://codecov.io/bash)
diff --git a/README.md b/README.md
index c930804..2e1e700 100644
--- a/README.md
+++ b/README.md
@@ -17,6 +17,7 @@ Apache ServiceComb (incubating) Service-Center is a Restful based service-regist
- **Performance**: Performance/Caching design
- **Metrics**: Able to expose Prometheus metric API automatically
- **Tracing**: Able to report tracing data to Zipkin server
+ - **Multi Datacenter**: Additional layer of abstraction to clusters deployed in multiple datacenters
## Documentation
diff --git a/docs/README.md b/docs/README.md
index 69a1ea6..51a5ce2 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -16,11 +16,11 @@ Swagger [`v4`](/server/core/swagger/v4.yaml)|[`v3`](/server/core/swagger/v3.yaml
#### Deploy Service-Center Locally
-- [In Docker](/integration/docker)
+- [In Docker](/examples/infrastructures/docker)
#### Deploy Service-Center Cluster
-- [In Kubernetes Cluster](/integration/k8s)
+- [In Kubernetes Cluster](/examples/infrastructures/k8s)
- [In VMs](/docs/sc-cluster.md)
- [Deploy with TLS](/docs/security-tls.md)
diff --git a/integration/docker/README.md b/examples/infrastructures/docker/README.md
similarity index 100%
rename from integration/docker/README.md
rename to examples/infrastructures/docker/README.md
diff --git a/integration/docker/docker-compose.yml b/examples/infrastructures/docker/docker-compose.yml
similarity index 100%
rename from integration/docker/docker-compose.yml
rename to examples/infrastructures/docker/docker-compose.yml
diff --git a/integration/docker/prometheus.yml b/examples/infrastructures/docker/prometheus.yml
similarity index 100%
rename from integration/docker/prometheus.yml
rename to examples/infrastructures/docker/prometheus.yml
diff --git a/integration/k8s/README.md b/examples/infrastructures/k8s/README.md
similarity index 93%
rename from integration/k8s/README.md
rename to examples/infrastructures/k8s/README.md
index 3186030..a929598 100644
--- a/integration/k8s/README.md
+++ b/examples/infrastructures/k8s/README.md
@@ -23,7 +23,7 @@ Notes: After deployment, it only create ServiceCenter cluster in the `default` n
You can use the command `kubectl apply` to deploy ServiceCenter cluster.
```bash
-cd ${PROJECT_ROOT}/integration/k8s
+cd ${PROJECT_ROOT}/examples/infrastructures/k8s
kubectl apply -f <(helm template --name servicecomb --namespace default service-center/)
```
@@ -33,7 +33,7 @@ You can also use the helm commands to deploy ServiceCenter cluster if
you already deploy helm tiller.
```bash
-cd ${PROJECT_ROOT}/integration/k8s
+cd ${PROJECT_ROOT}/examples/infrastructures/k8s
helm install --name servicecomb --namespace default service-center/
```
@@ -50,7 +50,7 @@ Notes: After deployment, it create ServiceCenter cluster and etcd cluster in the
You can use the command `kubectl apply` to deploy ServiceCenter cluster.
```bash
-cd ${PROJECT_ROOT}/integration/k8s
+cd ${PROJECT_ROOT}/examples/infrastructures/k8s
# install etcd cluster
kubectl apply -f <(helm template --name coreos --namespace default etcd/)
# install sc cluster
@@ -66,7 +66,7 @@ You can also use the helm commands to deploy ServiceCenter cluster if
you already deploy helm tiller.
```bash
-cd ${PROJECT_ROOT}/integration/k8s
+cd ${PROJECT_ROOT}/examples/infrastructures/k8s
# install etcd cluster
helm install --name coreos --namespace default etcd/
# install sc cluster
@@ -97,7 +97,7 @@ By default, the ServiceCenter frontend use `NodePort` service type to deploy in
If you use the kubectl to deploy, take deploy mode `platform registration` as example.
```bash
-cd ${PROJECT_ROOT}/integration/k8s
+cd ${PROJECT_ROOT}/examples/infrastructures/k8s
kubectl delete -f <(helm template --name servicecomb --namespace default service-center/)
```
diff --git a/integration/k8s/etcd/Chart.yaml b/examples/infrastructures/k8s/etcd/Chart.yaml
similarity index 100%
rename from integration/k8s/etcd/Chart.yaml
rename to examples/infrastructures/k8s/etcd/Chart.yaml
diff --git a/integration/k8s/service-center/.helmignore b/examples/infrastructures/k8s/etcd/charts/etcd-operator/.helmignore
similarity index 100%
rename from integration/k8s/service-center/.helmignore
rename to examples/infrastructures/k8s/etcd/charts/etcd-operator/.helmignore
diff --git a/integration/k8s/etcd/charts/etcd-operator/Chart.yaml b/examples/infrastructures/k8s/etcd/charts/etcd-operator/Chart.yaml
similarity index 100%
rename from integration/k8s/etcd/charts/etcd-operator/Chart.yaml
rename to examples/infrastructures/k8s/etcd/charts/etcd-operator/Chart.yaml
diff --git a/integration/k8s/etcd/charts/etcd-operator/OWNERS b/examples/infrastructures/k8s/etcd/charts/etcd-operator/OWNERS
similarity index 100%
rename from integration/k8s/etcd/charts/etcd-operator/OWNERS
rename to examples/infrastructures/k8s/etcd/charts/etcd-operator/OWNERS
diff --git a/integration/k8s/etcd/charts/etcd-operator/README.md b/examples/infrastructures/k8s/etcd/charts/etcd-operator/README.md
similarity index 100%
rename from integration/k8s/etcd/charts/etcd-operator/README.md
rename to examples/infrastructures/k8s/etcd/charts/etcd-operator/README.md
diff --git a/integration/k8s/etcd/charts/etcd-operator/templates/NOTES.txt b/examples/infrastructures/k8s/etcd/charts/etcd-operator/templates/NOTES.txt
similarity index 100%
rename from integration/k8s/etcd/charts/etcd-operator/templates/NOTES.txt
rename to examples/infrastructures/k8s/etcd/charts/etcd-operator/templates/NOTES.txt
diff --git a/integration/k8s/etcd/charts/etcd-operator/templates/_helpers.tpl b/examples/infrastructures/k8s/etcd/charts/etcd-operator/templates/_helpers.tpl
similarity index 100%
rename from integration/k8s/etcd/charts/etcd-operator/templates/_helpers.tpl
rename to examples/infrastructures/k8s/etcd/charts/etcd-operator/templates/_helpers.tpl
diff --git a/integration/k8s/etcd/charts/etcd-operator/templates/backup-etcd-crd.yaml b/examples/infrastructures/k8s/etcd/charts/etcd-operator/templates/backup-etcd-crd.yaml
similarity index 100%
rename from integration/k8s/etcd/charts/etcd-operator/templates/backup-etcd-crd.yaml
rename to examples/infrastructures/k8s/etcd/charts/etcd-operator/templates/backup-etcd-crd.yaml
diff --git a/integration/k8s/etcd/charts/etcd-operator/templates/backup-operator-clusterrole-binding.yaml b/examples/infrastructures/k8s/etcd/charts/etcd-operator/templates/backup-operator-clusterrole-binding.yaml
similarity index 100%
rename from integration/k8s/etcd/charts/etcd-operator/templates/backup-operator-clusterrole-binding.yaml
rename to examples/infrastructures/k8s/etcd/charts/etcd-operator/templates/backup-operator-clusterrole-binding.yaml
diff --git a/integration/k8s/etcd/charts/etcd-operator/templates/backup-operator-deployment.yaml b/examples/infrastructures/k8s/etcd/charts/etcd-operator/templates/backup-operator-deployment.yaml
similarity index 100%
rename from integration/k8s/etcd/charts/etcd-operator/templates/backup-operator-deployment.yaml
rename to examples/infrastructures/k8s/etcd/charts/etcd-operator/templates/backup-operator-deployment.yaml
diff --git a/integration/k8s/etcd/charts/etcd-operator/templates/backup-operator-service-account.yaml b/examples/infrastructures/k8s/etcd/charts/etcd-operator/templates/backup-operator-service-account.yaml
similarity index 100%
rename from integration/k8s/etcd/charts/etcd-operator/templates/backup-operator-service-account.yaml
rename to examples/infrastructures/k8s/etcd/charts/etcd-operator/templates/backup-operator-service-account.yaml
diff --git a/integration/k8s/etcd/charts/etcd-operator/templates/etcd-cluster-crd.yaml b/examples/infrastructures/k8s/etcd/charts/etcd-operator/templates/etcd-cluster-crd.yaml
similarity index 100%
rename from integration/k8s/etcd/charts/etcd-operator/templates/etcd-cluster-crd.yaml
rename to examples/infrastructures/k8s/etcd/charts/etcd-operator/templates/etcd-cluster-crd.yaml
diff --git a/integration/k8s/etcd/charts/etcd-operator/templates/operator-cluster-role.yaml b/examples/infrastructures/k8s/etcd/charts/etcd-operator/templates/operator-cluster-role.yaml
similarity index 100%
rename from integration/k8s/etcd/charts/etcd-operator/templates/operator-cluster-role.yaml
rename to examples/infrastructures/k8s/etcd/charts/etcd-operator/templates/operator-cluster-role.yaml
diff --git a/integration/k8s/etcd/charts/etcd-operator/templates/operator-clusterrole-binding.yaml b/examples/infrastructures/k8s/etcd/charts/etcd-operator/templates/operator-clusterrole-binding.yaml
similarity index 100%
rename from integration/k8s/etcd/charts/etcd-operator/templates/operator-clusterrole-binding.yaml
rename to examples/infrastructures/k8s/etcd/charts/etcd-operator/templates/operator-clusterrole-binding.yaml
diff --git a/integration/k8s/etcd/charts/etcd-operator/templates/operator-deployment.yaml b/examples/infrastructures/k8s/etcd/charts/etcd-operator/templates/operator-deployment.yaml
similarity index 100%
rename from integration/k8s/etcd/charts/etcd-operator/templates/operator-deployment.yaml
rename to examples/infrastructures/k8s/etcd/charts/etcd-operator/templates/operator-deployment.yaml
diff --git a/integration/k8s/etcd/charts/etcd-operator/templates/operator-service-account.yaml b/examples/infrastructures/k8s/etcd/charts/etcd-operator/templates/operator-service-account.yaml
similarity index 100%
rename from integration/k8s/etcd/charts/etcd-operator/templates/operator-service-account.yaml
rename to examples/infrastructures/k8s/etcd/charts/etcd-operator/templates/operator-service-account.yaml
diff --git a/integration/k8s/etcd/charts/etcd-operator/templates/restore-etcd-crd.yaml b/examples/infrastructures/k8s/etcd/charts/etcd-operator/templates/restore-etcd-crd.yaml
similarity index 100%
rename from integration/k8s/etcd/charts/etcd-operator/templates/restore-etcd-crd.yaml
rename to examples/infrastructures/k8s/etcd/charts/etcd-operator/templates/restore-etcd-crd.yaml
diff --git a/integration/k8s/etcd/charts/etcd-operator/templates/restore-operator-clusterrole-binding.yaml b/examples/infrastructures/k8s/etcd/charts/etcd-operator/templates/restore-operator-clusterrole-binding.yaml
similarity index 100%
rename from integration/k8s/etcd/charts/etcd-operator/templates/restore-operator-clusterrole-binding.yaml
rename to examples/infrastructures/k8s/etcd/charts/etcd-operator/templates/restore-operator-clusterrole-binding.yaml
diff --git a/integration/k8s/etcd/charts/etcd-operator/templates/restore-operator-deployment.yaml b/examples/infrastructures/k8s/etcd/charts/etcd-operator/templates/restore-operator-deployment.yaml
similarity index 100%
rename from integration/k8s/etcd/charts/etcd-operator/templates/restore-operator-deployment.yaml
rename to examples/infrastructures/k8s/etcd/charts/etcd-operator/templates/restore-operator-deployment.yaml
diff --git a/integration/k8s/etcd/charts/etcd-operator/templates/restore-operator-service-account.yaml b/examples/infrastructures/k8s/etcd/charts/etcd-operator/templates/restore-operator-service-account.yaml
similarity index 100%
rename from integration/k8s/etcd/charts/etcd-operator/templates/restore-operator-service-account.yaml
rename to examples/infrastructures/k8s/etcd/charts/etcd-operator/templates/restore-operator-service-account.yaml
diff --git a/integration/k8s/etcd/charts/etcd-operator/templates/restore-operator-service.yaml b/examples/infrastructures/k8s/etcd/charts/etcd-operator/templates/restore-operator-service.yaml
similarity index 100%
rename from integration/k8s/etcd/charts/etcd-operator/templates/restore-operator-service.yaml
rename to examples/infrastructures/k8s/etcd/charts/etcd-operator/templates/restore-operator-service.yaml
diff --git a/integration/k8s/etcd/charts/etcd-operator/values.yaml b/examples/infrastructures/k8s/etcd/charts/etcd-operator/values.yaml
similarity index 100%
rename from integration/k8s/etcd/charts/etcd-operator/values.yaml
rename to examples/infrastructures/k8s/etcd/charts/etcd-operator/values.yaml
diff --git a/integration/k8s/etcd/templates/_helpers.tpl b/examples/infrastructures/k8s/etcd/templates/_helpers.tpl
similarity index 100%
rename from integration/k8s/etcd/templates/_helpers.tpl
rename to examples/infrastructures/k8s/etcd/templates/_helpers.tpl
diff --git a/integration/k8s/etcd/templates/deployment.yaml b/examples/infrastructures/k8s/etcd/templates/deployment.yaml
similarity index 100%
rename from integration/k8s/etcd/templates/deployment.yaml
rename to examples/infrastructures/k8s/etcd/templates/deployment.yaml
diff --git a/integration/k8s/etcd/values.yaml b/examples/infrastructures/k8s/etcd/values.yaml
similarity index 100%
rename from integration/k8s/etcd/values.yaml
rename to examples/infrastructures/k8s/etcd/values.yaml
diff --git a/integration/k8s/etcd/charts/etcd-operator/.helmignore b/examples/infrastructures/k8s/service-center/.helmignore
similarity index 100%
rename from integration/k8s/etcd/charts/etcd-operator/.helmignore
rename to examples/infrastructures/k8s/service-center/.helmignore
diff --git a/integration/k8s/service-center/Chart.yaml b/examples/infrastructures/k8s/service-center/Chart.yaml
similarity index 100%
rename from integration/k8s/service-center/Chart.yaml
rename to examples/infrastructures/k8s/service-center/Chart.yaml
diff --git a/integration/k8s/service-center/templates/NOTES.txt b/examples/infrastructures/k8s/service-center/templates/NOTES.txt
similarity index 100%
rename from integration/k8s/service-center/templates/NOTES.txt
rename to examples/infrastructures/k8s/service-center/templates/NOTES.txt
diff --git a/integration/k8s/service-center/templates/_helpers.tpl b/examples/infrastructures/k8s/service-center/templates/_helpers.tpl
similarity index 100%
rename from integration/k8s/service-center/templates/_helpers.tpl
rename to examples/infrastructures/k8s/service-center/templates/_helpers.tpl
diff --git a/integration/k8s/service-center/templates/configmap.yaml b/examples/infrastructures/k8s/service-center/templates/configmap.yaml
similarity index 79%
rename from integration/k8s/service-center/templates/configmap.yaml
rename to examples/infrastructures/k8s/service-center/templates/configmap.yaml
index 94949be..e9c8dcd 100644
--- a/integration/k8s/service-center/templates/configmap.yaml
+++ b/examples/infrastructures/k8s/service-center/templates/configmap.yaml
@@ -22,6 +22,16 @@ data:
registry_plugin = etcd
self_register = 1
manager_cluster = {{ .Values.sc.discovery.uris }}
+ {{- else if eq .Values.sc.discovery.type "servicecenter" }}
+ discovery_plugin = servicecenter
+ registry_plugin = buildin
+ self_register = 0
+ manager_cluster = "{{ .Values.sc.discovery.clusters }}"
+ {{- else if eq .Values.sc.discovery.type "aggregate" }}
+ discovery_plugin = aggregate
+ registry_plugin = buildin
+ self_register = 0
+ manager_cluster = "{{ .Values.sc.discovery.clusters }}"
{{- else }}
discovery_plugin = etcd
registry_plugin = embeded_etcd
diff --git a/integration/k8s/service-center/templates/deployment.yaml b/examples/infrastructures/k8s/service-center/templates/deployment.yaml
similarity index 100%
rename from integration/k8s/service-center/templates/deployment.yaml
rename to examples/infrastructures/k8s/service-center/templates/deployment.yaml
diff --git a/integration/k8s/service-center/templates/ingress.yaml b/examples/infrastructures/k8s/service-center/templates/ingress.yaml
similarity index 100%
rename from integration/k8s/service-center/templates/ingress.yaml
rename to examples/infrastructures/k8s/service-center/templates/ingress.yaml
diff --git a/integration/k8s/service-center/templates/rbac.yaml b/examples/infrastructures/k8s/service-center/templates/rbac.yaml
similarity index 100%
rename from integration/k8s/service-center/templates/rbac.yaml
rename to examples/infrastructures/k8s/service-center/templates/rbac.yaml
diff --git a/integration/k8s/service-center/templates/service.yaml b/examples/infrastructures/k8s/service-center/templates/service.yaml
similarity index 100%
rename from integration/k8s/service-center/templates/service.yaml
rename to examples/infrastructures/k8s/service-center/templates/service.yaml
diff --git a/integration/k8s/service-center/values.yaml b/examples/infrastructures/k8s/service-center/values.yaml
similarity index 56%
rename from integration/k8s/service-center/values.yaml
rename to examples/infrastructures/k8s/service-center/values.yaml
index 1abad5a..05bbf6d 100644
--- a/integration/k8s/service-center/values.yaml
+++ b/examples/infrastructures/k8s/service-center/values.yaml
@@ -17,8 +17,26 @@ frontend:
sc:
replicaCount: 2
discovery:
- type: k8s # support local, etcd and k8s discovery mode
- uris: ""
+ # support local, servicecenter, etcd, k8s and aggregate discovery mode
+ # type: local
+ # bootstrap a lightweight service center, can only support replicaCount is one
+ # type: servicecenter
+ # The precondition is that one or more service center clusters have been deployed,
+ # this deployment will bootstrap a service center aggregation service which
+ # provides micro-services and instances information aggregation queries
+ # type: etcd
+ # bootstrap a standard service center cluster which micro-services and instances
+ # information stored in etcd
+ # type: k8s
+ # bootstrap a standard service center cluster which micro-services and instances
+ # information discovered from kubernetes services
+ # type: aggregate
+ # this type not only support aggregate service center cluster but also aggregate
+ # the kubernetes services
+ type: k8s
+ # the cluster urls list, can only support discovery type is "servicecenter" or "aggregate"
+ # e.g. clusters: "sc-0=http://service-center-1:30100,sc-1=http://service-center-2:30100"
+ clusters: ""
image:
repository: servicecomb/service-center
tag: latest
diff --git a/pkg/client/etcd/client.go b/pkg/client/etcd/client.go
index d7a5f0b..11cdd0f 100644
--- a/pkg/client/etcd/client.go
+++ b/pkg/client/etcd/client.go
@@ -24,31 +24,22 @@ import (
"time"
)
-var (
- Addrs string
- CertPath string
- KeyPath string
- KeyPassPath string
- KeyPass string
- CAPath string
-)
-
-func NewEtcdClient() (*clientv3.Client, error) {
+func NewEtcdClient(cfg Config) (*clientv3.Client, error) {
var (
- endpoints = strings.Split(Addrs, ",")
+ endpoints = strings.Split(cfg.Addrs, ",")
cliTls *tls.Config
)
for _, ip := range endpoints {
if strings.Index(ip, "https://") >= 0 {
- if len(KeyPass) == 0 && len(KeyPassPath) > 0 {
- content, _ := ioutil.ReadFile(KeyPassPath)
- KeyPass = string(content)
+ if len(cfg.CertKeyPWD) == 0 && len(cfg.CertKeyPWDPath) > 0 {
+ content, _ := ioutil.ReadFile(cfg.CertKeyPWDPath)
+ cfg.CertKeyPWD = string(content)
}
opts := append(tlsutil.DefaultClientTLSOptions(),
- tlsutil.WithCA(CAPath),
- tlsutil.WithCert(CertPath),
- tlsutil.WithKey(KeyPath),
- tlsutil.WithKeyPass(KeyPass))
+ tlsutil.WithCA(cfg.CAFile),
+ tlsutil.WithCert(cfg.CertFile),
+ tlsutil.WithKey(cfg.CertKeyFile),
+ tlsutil.WithKeyPass(cfg.CertKeyPWD))
cliTls, _ = tlsutil.GetClientTLSConfig(opts...)
break
}
diff --git a/server/infra/discovery/types_test.go b/pkg/client/etcd/config.go
similarity index 67%
copy from server/infra/discovery/types_test.go
copy to pkg/client/etcd/config.go
index 5d54c5b..d1406f1 100644
--- a/server/infra/discovery/types_test.go
+++ b/pkg/client/etcd/config.go
@@ -13,25 +13,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package discovery
+package etcd
-import "testing"
-
-func TestTypes(t *testing.T) {
- id, _ := Install(NewAddOn("TestTypes", Configure()))
- found := false
- for _, t := range Types() {
- if t == id {
- found = true
- }
- }
- if !found {
- t.Fatalf("TestTypes failed")
- }
- if id.String() != "TestTypes" {
- t.Fatalf("TestTypes failed")
- }
- if TypeError.String() != "TypeError" {
- t.Fatalf("TestTypes failed")
- }
+type Config struct {
+ Addrs string
+ CertFile string
+ CertKeyFile string
+ CertKeyPWDPath string
+ CertKeyPWD string
+ CAFile string
}
diff --git a/pkg/client/sc/apis.go b/pkg/client/sc/apis.go
index 7e0e6ab..99e0c81 100644
--- a/pkg/client/sc/apis.go
+++ b/pkg/client/sc/apis.go
@@ -18,109 +18,157 @@ package sc
import (
"encoding/json"
"fmt"
+ "github.com/apache/incubator-servicecomb-service-center/pkg/util"
"github.com/apache/incubator-servicecomb-service-center/server/admin/model"
"github.com/apache/incubator-servicecomb-service-center/server/core"
pb "github.com/apache/incubator-servicecomb-service-center/server/core/proto"
+ scerr "github.com/apache/incubator-servicecomb-service-center/server/error"
"github.com/apache/incubator-servicecomb-service-center/version"
"io/ioutil"
"net/http"
)
const (
- apiVersionURL = "/version"
- apiDumpURL = "/v4/default/admin/dump"
- apiGetSchemasURL = "/v4/%s/registry/microservices/%s/schemas"
+ apiVersionURL = "/version"
+ apiDumpURL = "/v4/default/admin/dump"
+ apiSchemasURL = "/v4/%s/registry/microservices/%s/schemas"
+ apiSchemaURL = "/v4/%s/registry/microservices/%s/schemas/%s"
)
+func (c *SCClient) toError(body []byte) *scerr.Error {
+ message := new(scerr.Error)
+ err := json.Unmarshal(body, message)
+ if err != nil {
+ return scerr.NewError(scerr.ErrInternal, util.BytesToStringWithNoCopy(body))
+ }
+ return message
+}
+
func (c *SCClient) commonHeaders() http.Header {
var headers = make(http.Header)
- if len(Token) > 0 {
- headers.Set("X-Auth-Token", Token)
+ if len(c.Config.Token) > 0 {
+ headers.Set("X-Auth-Token", c.Config.Token)
}
return headers
}
-func (c *SCClient) GetScVersion() (*version.VersionSet, error) {
- resp, err := c.client.HttpDo(http.MethodGet, Addr+apiVersionURL, c.commonHeaders(), nil)
+func (c *SCClient) GetScVersion() (*version.VersionSet, *scerr.Error) {
+ resp, err := c.URLClient.HttpDo(http.MethodGet, c.Config.Addr+apiVersionURL, c.commonHeaders(), nil)
if err != nil {
- return nil, err
+ return nil, scerr.NewError(scerr.ErrInternal, err.Error())
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
- return nil, err
+ return nil, scerr.NewError(scerr.ErrInternal, err.Error())
}
if resp.StatusCode != http.StatusOK {
- return nil, fmt.Errorf("%d %s", resp.StatusCode, string(body))
+ return nil, c.toError(body)
}
v := &version.VersionSet{}
err = json.Unmarshal(body, v)
if err != nil {
fmt.Println(string(body))
- return nil, err
+ return nil, scerr.NewError(scerr.ErrInternal, err.Error())
}
return v, nil
}
-func (c *SCClient) GetScCache() (*model.Cache, error) {
+func (c *SCClient) GetScCache() (*model.Cache, *scerr.Error) {
headers := c.commonHeaders()
+ // only default domain has admin permission
headers.Set("X-Domain-Name", "default")
- resp, err := c.client.HttpDo(http.MethodGet, Addr+apiDumpURL, headers, nil)
+ resp, err := c.URLClient.HttpDo(http.MethodGet, c.Config.Addr+apiDumpURL, headers, nil)
if err != nil {
- return nil, err
+ return nil, scerr.NewError(scerr.ErrInternal, err.Error())
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
- return nil, err
+ return nil, scerr.NewError(scerr.ErrInternal, err.Error())
}
if resp.StatusCode != http.StatusOK {
- return nil, fmt.Errorf("%d %s", resp.StatusCode, string(body))
+ return nil, c.toError(body)
}
dump := &model.DumpResponse{}
err = json.Unmarshal(body, dump)
if err != nil {
fmt.Println(string(body))
- return nil, err
+ return nil, scerr.NewError(scerr.ErrInternal, err.Error())
}
return dump.Cache, nil
}
-func (c *SCClient) GetSchemasByServiceId(domainProject, serviceId string) ([]*pb.Schema, error) {
+func (c *SCClient) GetSchemasByServiceId(domainProject, serviceId string) ([]*pb.Schema, *scerr.Error) {
domain, project := core.FromDomainProject(domainProject)
headers := c.commonHeaders()
headers.Set("X-Domain-Name", domain)
- resp, err := c.client.HttpDo(http.MethodGet,
- Addr+fmt.Sprintf(apiGetSchemasURL, project, serviceId)+"?withSchema=1",
+ resp, err := c.URLClient.HttpDo(http.MethodGet,
+ c.Config.Addr+fmt.Sprintf(apiSchemasURL, project, serviceId)+"?withSchema=1",
headers, nil)
if err != nil {
- return nil, err
+ return nil, scerr.NewError(scerr.ErrInternal, err.Error())
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
- return nil, err
+ return nil, scerr.NewError(scerr.ErrInternal, err.Error())
}
if resp.StatusCode != http.StatusOK {
- return nil, fmt.Errorf("%d %s", resp.StatusCode, string(body))
+ return nil, c.toError(body)
}
schemas := &pb.GetAllSchemaResponse{}
err = json.Unmarshal(body, schemas)
if err != nil {
- fmt.Println(string(body))
- return nil, err
+ fmt.Println(util.BytesToStringWithNoCopy(body))
+ return nil, scerr.NewError(scerr.ErrInternal, err.Error())
}
return schemas.Schemas, nil
}
+
+func (c *SCClient) GetSchemaBySchemaId(domainProject, serviceId, schemaId string) (*pb.Schema, *scerr.Error) {
+ domain, project := core.FromDomainProject(domainProject)
+ headers := c.commonHeaders()
+ headers.Set("X-Domain-Name", domain)
+ resp, err := c.URLClient.HttpDo(http.MethodGet,
+ c.Config.Addr+fmt.Sprintf(apiSchemaURL, project, serviceId, schemaId),
+ headers, nil)
+ if err != nil {
+ return nil, scerr.NewError(scerr.ErrInternal, err.Error())
+ }
+ defer resp.Body.Close()
+
+ body, err := ioutil.ReadAll(resp.Body)
+ if err != nil {
+ return nil, scerr.NewError(scerr.ErrInternal, err.Error())
+ }
+
+ if resp.StatusCode != http.StatusOK {
+ return nil, c.toError(body)
+ }
+
+ schema := &pb.GetSchemaResponse{}
+ err = json.Unmarshal(body, schema)
+ if err != nil {
+ fmt.Println(util.BytesToStringWithNoCopy(body))
+ return nil, scerr.NewError(scerr.ErrInternal, err.Error())
+ }
+
+ return &pb.Schema{
+ SchemaId: schemaId,
+ Schema: schema.Schema,
+ Summary: schema.SchemaSummary,
+ }, nil
+}
diff --git a/pkg/client/sc/client.go b/pkg/client/sc/client.go
index 1067fd3..62b9c1e 100644
--- a/pkg/client/sc/client.go
+++ b/pkg/client/sc/client.go
@@ -22,38 +22,28 @@ import (
"time"
)
-var (
- Addr string
- Token string
- VerifyPeer bool
- CertPath string
- KeyPath string
- KeyPassPath string
- KeyPass string
- CAPath string
-)
-
-func NewSCClient() (*SCClient, error) {
- ssl := strings.Index(Addr, "https://") >= 0
- if ssl && len(KeyPass) == 0 && len(KeyPassPath) > 0 {
- content, _ := ioutil.ReadFile(KeyPassPath)
- KeyPass = string(content)
+func NewSCClient(cfg Config) (*SCClient, error) {
+ ssl := strings.Index(cfg.Addr, "https://") >= 0
+ if ssl && len(cfg.CertKeyPWD) == 0 && len(cfg.CertKeyPWDPath) > 0 {
+ content, _ := ioutil.ReadFile(cfg.CertKeyPWDPath)
+ cfg.CertKeyPWD = string(content)
}
- client, err := rest.GetURLClient(&rest.URLClientOption{
+ client, err := rest.GetURLClient(rest.URLClientOption{
SSLEnabled: ssl,
- VerifyPeer: VerifyPeer,
- CAFile: CAPath,
- CertFile: CertPath,
- CertKeyFile: KeyPath,
- CertKeyPWD: KeyPass,
+ VerifyPeer: cfg.VerifyPeer,
+ CAFile: cfg.CAFile,
+ CertFile: cfg.CertFile,
+ CertKeyFile: cfg.CertKeyFile,
+ CertKeyPWD: cfg.CertKeyPWD,
RequestTimeout: 10 * time.Second,
})
if err != nil {
return nil, err
}
- return &SCClient{client: client}, nil
+ return &SCClient{Config: cfg, URLClient: client}, nil
}
type SCClient struct {
- client *rest.URLClient
+ *rest.URLClient
+ Config Config
}
diff --git a/server/infra/discovery/types_test.go b/pkg/client/sc/config.go
similarity index 67%
copy from server/infra/discovery/types_test.go
copy to pkg/client/sc/config.go
index 5d54c5b..2a707a7 100644
--- a/server/infra/discovery/types_test.go
+++ b/pkg/client/sc/config.go
@@ -13,25 +13,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package discovery
+package sc
-import "testing"
+import "github.com/apache/incubator-servicecomb-service-center/pkg/rest"
-func TestTypes(t *testing.T) {
- id, _ := Install(NewAddOn("TestTypes", Configure()))
- found := false
- for _, t := range Types() {
- if t == id {
- found = true
- }
- }
- if !found {
- t.Fatalf("TestTypes failed")
- }
- if id.String() != "TestTypes" {
- t.Fatalf("TestTypes failed")
- }
- if TypeError.String() != "TypeError" {
- t.Fatalf("TestTypes failed")
- }
+type Config struct {
+ rest.URLClientOption
+ Addr string
+ Token string
+ CertKeyPWDPath string
}
diff --git a/pkg/etcdsync/etcdsync_suite_test.go b/pkg/etcdsync/etcdsync_suite_test.go
index 9688bed..e8ada7e 100644
--- a/pkg/etcdsync/etcdsync_suite_test.go
+++ b/pkg/etcdsync/etcdsync_suite_test.go
@@ -18,8 +18,8 @@ package etcdsync
import (
"fmt"
- _ "github.com/apache/incubator-servicecomb-service-center/server/plugin/infra/registry/etcd"
- _ "github.com/apache/incubator-servicecomb-service-center/server/plugin/infra/tracing/buildin"
+ _ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/registry/etcd"
+ _ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/tracing/buildin"
"github.com/astaxie/beego"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
diff --git a/pkg/etcdsync/mutex.go b/pkg/etcdsync/mutex.go
index 7c4bd5b..8731db1 100644
--- a/pkg/etcdsync/mutex.go
+++ b/pkg/etcdsync/mutex.go
@@ -22,7 +22,7 @@ import (
"github.com/apache/incubator-servicecomb-service-center/pkg/log"
"github.com/apache/incubator-servicecomb-service-center/pkg/util"
"github.com/apache/incubator-servicecomb-service-center/server/core/backend"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/registry"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/registry"
"github.com/coreos/etcd/client"
"golang.org/x/net/context"
"os"
diff --git a/pkg/rest/client.go b/pkg/rest/client.go
index 987e3c0..0518b6e 100644
--- a/pkg/rest/client.go
+++ b/pkg/rest/client.go
@@ -29,7 +29,7 @@ import (
"time"
)
-var defaultURLClientOption = &URLClientOption{
+var defaultURLClientOption = URLClientOption{
Compressed: true,
VerifyPeer: true,
SSLVersion: tls.VersionTLS12,
@@ -128,7 +128,7 @@ func (client *URLClient) HttpDo(method string, rawURL string, headers http.Heade
func setOptionDefaultValue(o *URLClientOption) URLClientOption {
if o == nil {
- return *defaultURLClientOption
+ return defaultURLClientOption
}
option := *o
@@ -147,8 +147,8 @@ func setOptionDefaultValue(o *URLClientOption) URLClientOption {
return option
}
-func GetURLClient(o *URLClientOption) (client *URLClient, err error) {
- option := setOptionDefaultValue(o)
+func GetURLClient(o URLClientOption) (client *URLClient, err error) {
+ option := setOptionDefaultValue(&o)
client = &URLClient{
Client: &http.Client{
Transport: &http.Transport{
diff --git a/scctl/pkg/cmd/cmd.go b/scctl/pkg/cmd/cmd.go
index 55e6dfc..567cf53 100644
--- a/scctl/pkg/cmd/cmd.go
+++ b/scctl/pkg/cmd/cmd.go
@@ -33,6 +33,7 @@ var rootCmd = &cobra.Command{
Use: version.TOOL_NAME + " <command>",
Short: "The admin control command of service center",
}
+var ScClientConfig sc.Config
func init() {
rootCmd.PersistentFlags().BoolP("verbose", "v", false, "make the operation more talkative")
@@ -42,24 +43,24 @@ func init() {
}
}
- rootCmd.PersistentFlags().StringVar(&sc.Addr, "addr",
+ rootCmd.PersistentFlags().StringVar(&ScClientConfig.Addr, "addr",
"http://"+util.GetEnvString("HOSTING_SERVER_IP", "127.0.0.1")+":30100",
"the http host and port of service center, can be overrode by env HOSTING_SERVER_IP.")
- rootCmd.PersistentFlags().StringVarP(&sc.Token, "token", "t", "",
+ rootCmd.PersistentFlags().StringVarP(&ScClientConfig.Token, "token", "t", "",
"the auth token string to access service center.")
- rootCmd.PersistentFlags().BoolVarP(&sc.VerifyPeer, "peer", "p", false,
+ rootCmd.PersistentFlags().BoolVarP(&ScClientConfig.VerifyPeer, "peer", "p", false,
"verify service center certificates.")
- rootCmd.PersistentFlags().StringVar(&sc.CertPath, "cert", "",
+ rootCmd.PersistentFlags().StringVar(&ScClientConfig.CertFile, "cert", "",
"the certificate file path to access service center.")
- rootCmd.PersistentFlags().StringVar(&sc.KeyPath, "key", "",
+ rootCmd.PersistentFlags().StringVar(&ScClientConfig.CertKeyFile, "key", "",
"the key file path to access service center.")
- rootCmd.PersistentFlags().StringVar(&sc.CAPath, "ca", "",
+ rootCmd.PersistentFlags().StringVar(&ScClientConfig.CAFile, "ca", "",
"the CA file path to access service center.")
- rootCmd.PersistentFlags().StringVar(&sc.KeyPassPath, "pass-file", "",
+ rootCmd.PersistentFlags().StringVar(&ScClientConfig.CertKeyPWDPath, "pass-file", "",
"the passphase file path to decrypt key file.")
- rootCmd.PersistentFlags().StringVar(&sc.KeyPass, "pass", "",
+ rootCmd.PersistentFlags().StringVar(&ScClientConfig.CertKeyPWD, "pass", "",
"the passphase string to decrypt key file.")
}
diff --git a/scctl/pkg/plugin/diagnose/cmd.go b/scctl/pkg/plugin/diagnose/cmd.go
index 81ae1d4..8844b04 100644
--- a/scctl/pkg/plugin/diagnose/cmd.go
+++ b/scctl/pkg/plugin/diagnose/cmd.go
@@ -23,6 +23,8 @@ import (
"path/filepath"
)
+var EtcdClientConfig etcd.Config
+
func init() {
root.RootCmd().AddCommand(NewDiagnoseCommand(root.RootCmd()))
}
@@ -35,22 +37,22 @@ func NewDiagnoseCommand(parent *cobra.Command) *cobra.Command {
Example: parent.CommandPath() + ` diagnose --addr "http://127.0.0.1:30100" --etcd-addr "http://127.0.0.1:2379";`,
}
- cmd.Flags().StringVar(&etcd.Addrs, "etcd-addr",
+ cmd.Flags().StringVar(&EtcdClientConfig.Addrs, "etcd-addr",
util.GetEnvString("CSE_REGISTRY_ADDRESS", "http://127.0.0.1:2379"),
"the http addr and port of etcd endpoints")
- cmd.Flags().StringVar(&etcd.CertPath, "etcd-cert",
+ cmd.Flags().StringVar(&EtcdClientConfig.CertFile, "etcd-cert",
filepath.Join(util.GetEnvString("SSL_ROOT", "."), "server.cer"),
"the certificate file path to access etcd, can be overrode by env $SSL_ROOT/server.cer.")
- cmd.Flags().StringVar(&etcd.KeyPath, "etcd-key",
+ cmd.Flags().StringVar(&EtcdClientConfig.CertKeyFile, "etcd-key",
filepath.Join(util.GetEnvString("SSL_ROOT", "."), "server_key.pem"),
"the key file path to access etcd, can be overrode by env $SSL_ROOT/server_key.pem.")
- cmd.Flags().StringVar(&etcd.CAPath, "etcd-ca",
+ cmd.Flags().StringVar(&EtcdClientConfig.CAFile, "etcd-ca",
filepath.Join(util.GetEnvString("SSL_ROOT", "."), "trust.cer"),
"the CA file path to access etcd, can be overrode by env $SSL_ROOT/trust.cer.")
- cmd.Flags().StringVar(&etcd.KeyPassPath, "etcd-pass-file",
+ cmd.Flags().StringVar(&EtcdClientConfig.CertKeyPWDPath, "etcd-pass-file",
filepath.Join(util.GetEnvString("SSL_ROOT", "."), "cert_pwd"),
"the passphase file path to decrypt key file, can be overrode by env $SSL_ROOT/cert_pwd.")
- cmd.Flags().StringVar(&etcd.KeyPass, "etcd-pass", "",
+ cmd.Flags().StringVar(&EtcdClientConfig.CertKeyPWD, "etcd-pass", "",
"the passphase string to decrypt key file.")
return cmd
diff --git a/scctl/pkg/plugin/diagnose/compare_holder.go b/scctl/pkg/plugin/diagnose/compare_holder.go
index 304de86..bc8295d 100644
--- a/scctl/pkg/plugin/diagnose/compare_holder.go
+++ b/scctl/pkg/plugin/diagnose/compare_holder.go
@@ -33,10 +33,12 @@ type DataStore struct {
DataParser pb.Parser
}
-func (d *DataStore) ForEach(f func(i int, v *model.KV)) {
+func (d *DataStore) ForEach(f func(i int, v *model.KV) bool) {
for i, kv := range d.Data {
obj, _ := d.DataParser.Unmarshal(kv.Value)
- f(i, &model.KV{Key: string(kv.Key), Rev: kv.ModRevision, Value: obj})
+ if !f(i, &model.KV{Key: string(kv.Key), Rev: kv.ModRevision, Value: obj}) {
+ return
+ }
}
}
@@ -53,8 +55,9 @@ type abstractCompareHolder struct {
func (h *abstractCompareHolder) toMap(getter model.Getter) map[string]*model.KV {
m := make(map[string]*model.KV)
- getter.ForEach(func(i int, v *model.KV) {
+ getter.ForEach(func(i int, v *model.KV) bool {
m[v.Key] = v
+ return true
})
return m
}
diff --git a/scctl/pkg/plugin/diagnose/diagnose.go b/scctl/pkg/plugin/diagnose/diagnose.go
index 6892955..bb77da5 100644
--- a/scctl/pkg/plugin/diagnose/diagnose.go
+++ b/scctl/pkg/plugin/diagnose/diagnose.go
@@ -48,11 +48,11 @@ type etcdResponse map[string][]*mvccpb.KeyValue
func DiagnoseCommandFunc(_ *cobra.Command, args []string) {
// initialize sc/etcd clients
- scClient, err := sc.NewSCClient()
+ scClient, err := sc.NewSCClient(cmd.ScClientConfig)
if err != nil {
cmd.StopAndExit(cmd.ExitError, err)
}
- etcdClient, err := etcd.NewEtcdClient()
+ etcdClient, err := etcd.NewEtcdClient(EtcdClientConfig)
if err != nil {
cmd.StopAndExit(cmd.ExitError, err)
}
@@ -65,9 +65,9 @@ func DiagnoseCommandFunc(_ *cobra.Command, args []string) {
}
// query sc
- cache, err := scClient.GetScCache()
- if err != nil {
- cmd.StopAndExit(cmd.ExitError, err)
+ cache, scErr := scClient.GetScCache()
+ if scErr != nil {
+ cmd.StopAndExit(cmd.ExitError, scErr)
}
// diagnose go...
diff --git a/scctl/pkg/plugin/get/instance/instance_cmd.go b/scctl/pkg/plugin/get/instance/instance_cmd.go
index 43cf960..2a38bd1 100644
--- a/scctl/pkg/plugin/get/instance/instance_cmd.go
+++ b/scctl/pkg/plugin/get/instance/instance_cmd.go
@@ -43,13 +43,13 @@ func NewInstanceCommand(parent *cobra.Command) *cobra.Command {
}
func InstanceCommandFunc(_ *cobra.Command, args []string) {
- scClient, err := sc.NewSCClient()
+ scClient, err := sc.NewSCClient(cmd.ScClientConfig)
if err != nil {
cmd.StopAndExit(cmd.ExitError, err)
}
- cache, err := scClient.GetScCache()
- if err != nil {
- cmd.StopAndExit(cmd.ExitError, err)
+ cache, scErr := scClient.GetScCache()
+ if scErr != nil {
+ cmd.StopAndExit(cmd.ExitError, scErr)
}
svcMap := make(map[string]*admin.Microservice)
diff --git a/scctl/pkg/plugin/get/schema/schema_cmd.go b/scctl/pkg/plugin/get/schema/schema_cmd.go
index caa2cfe..31e58cf 100644
--- a/scctl/pkg/plugin/get/schema/schema_cmd.go
+++ b/scctl/pkg/plugin/get/schema/schema_cmd.go
@@ -80,13 +80,13 @@ func saveDirectory(root string, ms *adminModel.Microservice) string {
}
func SchemaCommandFunc(_ *cobra.Command, args []string) {
- scClient, err := sc.NewSCClient()
+ scClient, err := sc.NewSCClient(cmd.ScClientConfig)
if err != nil {
cmd.StopAndExit(cmd.ExitError, err)
}
- cache, err := scClient.GetScCache()
- if err != nil {
- cmd.StopAndExit(cmd.ExitError, err)
+ cache, scErr := scClient.GetScCache()
+ if scErr != nil {
+ cmd.StopAndExit(cmd.ExitError, scErr)
}
var progressBarWriter io.Writer = os.Stdout
@@ -122,8 +122,7 @@ func SchemaCommandFunc(_ *cobra.Command, args []string) {
}
writer := NewSchemaWriter(Config{SaveDir: saveDirectory(SaveDir, ms)})
- err = writer.Write(schemas)
- if err != nil {
+ if err := writer.Write(schemas); err != nil {
fmt.Fprintln(os.Stderr, "output schema data failed", err.Error())
}
}
diff --git a/scctl/pkg/plugin/get/service/service_cmd.go b/scctl/pkg/plugin/get/service/service_cmd.go
index b69bd15..7c4ae03 100644
--- a/scctl/pkg/plugin/get/service/service_cmd.go
+++ b/scctl/pkg/plugin/get/service/service_cmd.go
@@ -44,13 +44,13 @@ func NewServiceCommand(parent *cobra.Command) *cobra.Command {
}
func ServiceCommandFunc(_ *cobra.Command, args []string) {
- scClient, err := sc.NewSCClient()
+ scClient, err := sc.NewSCClient(cmd.ScClientConfig)
if err != nil {
cmd.StopAndExit(cmd.ExitError, err)
}
- cache, err := scClient.GetScCache()
- if err != nil {
- cmd.StopAndExit(cmd.ExitError, err)
+ cache, scErr := scClient.GetScCache()
+ if scErr != nil {
+ cmd.StopAndExit(cmd.ExitError, scErr)
}
endpointMap := make(map[string][]string)
diff --git a/scctl/pkg/plugin/version/cmd.go b/scctl/pkg/plugin/version/cmd.go
index ddbec2f..6cd11dc 100644
--- a/scctl/pkg/plugin/version/cmd.go
+++ b/scctl/pkg/plugin/version/cmd.go
@@ -47,7 +47,7 @@ func VersionCommandFunc(_ *cobra.Command, _ []string) {
fmt.Print(version.TOOL_NAME, " ")
version.Ver().Print()
- scClient, err := sc.NewSCClient()
+ scClient, err := sc.NewSCClient(cmd.ScClientConfig)
if err != nil {
return
}
diff --git a/scripts/build/local.sh b/scripts/build/local.sh
index 3e38b81..a229fc3 100644
--- a/scripts/build/local.sh
+++ b/scripts/build/local.sh
@@ -40,6 +40,8 @@ personal_build() {
build_frontend
+ build_scctl
+
package
}
diff --git a/scripts/ut_test_in_docker.sh b/scripts/ut_test_in_docker.sh
index 944e163..14640af 100755
--- a/scripts/ut_test_in_docker.sh
+++ b/scripts/ut_test_in_docker.sh
@@ -23,6 +23,13 @@ set -e
red=`tput setaf 1`
green=`tput setaf 2`
reset=`tput sgr0`
+
+ut_for_dir() {
+ local name=$1
+ echo "${green}Running UT for Service-Center $name${reset}"
+ bash -x ./scripts/ut.sh $name
+}
+
echo "${green}Starting Unit Testing for Service Center${reset}"
echo "${green}Starting etcd in docker${reset}"
@@ -36,13 +43,10 @@ echo "${green}Etcd is running......${reset}"
echo "${green}Preparing the env for UT....${reset}"
./scripts/prepare_env_ut.sh
-echo "${green}Running UT for Service-Center server"
-bash -x ./scripts/ut.sh pkg
+[ $? == 0 ] && ut_for_dir pkg
+[ $? == 0 ] && ut_for_dir server
+[ $? == 0 ] && ut_for_dir scctl
ret=$?
-if [ ${ret} == 0 ]; then
- bash -x ./scripts/ut.sh server
- ret=$?
-fi
if [ ${ret} == 0 ]; then
echo "${green}All the unit test passed..${reset}"
diff --git a/server/admin/model/dump.go b/server/admin/model/dump.go
index 60ac6ce..461be7e 100644
--- a/server/admin/model/dump.go
+++ b/server/admin/model/dump.go
@@ -22,7 +22,7 @@ import (
)
type Getter interface {
- ForEach(i func(i int, v *KV))
+ ForEach(i func(i int, v *KV) bool)
}
type Setter interface {
@@ -34,64 +34,90 @@ type MicroserviceIndexSlice []*MicroserviceIndex
type MicroserviceAliasSlice []*MicroserviceAlias
type TagSlice []*Tag
type MicroServiceRuleSlice []*MicroServiceRule
+type MicroServiceRuleIndexSlice []*MicroServiceRuleIndex
type MicroServiceDependencyRuleSlice []*MicroServiceDependencyRule
type SummarySlice []*Summary
type InstanceSlice []*Instance
-func (s *MicroserviceSlice) ForEach(f func(i int, v *KV)) {
+func (s *MicroserviceSlice) ForEach(f func(i int, v *KV) bool) {
for i, v := range *s {
v.KV.Value = v.Value
- f(i, v.KV)
+ if !f(i, v.KV) {
+ break
+ }
}
}
-func (s *MicroserviceIndexSlice) ForEach(f func(i int, v *KV)) {
+func (s *MicroserviceIndexSlice) ForEach(f func(i int, v *KV) bool) {
for i, v := range *s {
v.KV.Value = v.Value
- f(i, v.KV)
+ if !f(i, v.KV) {
+ break
+ }
}
}
-func (s *MicroserviceAliasSlice) ForEach(f func(i int, v *KV)) {
+func (s *MicroserviceAliasSlice) ForEach(f func(i int, v *KV) bool) {
for i, v := range *s {
v.KV.Value = v.Value
- f(i, v.KV)
+ if !f(i, v.KV) {
+ break
+ }
}
}
-func (s *TagSlice) ForEach(f func(i int, v *KV)) {
+func (s *TagSlice) ForEach(f func(i int, v *KV) bool) {
for i, v := range *s {
v.KV.Value = v.Value
- f(i, v.KV)
+ if !f(i, v.KV) {
+ break
+ }
}
}
-func (s *MicroServiceRuleSlice) ForEach(f func(i int, v *KV)) {
+func (s *MicroServiceRuleIndexSlice) ForEach(f func(i int, v *KV) bool) {
for i, v := range *s {
v.KV.Value = v.Value
- f(i, v.KV)
+ if !f(i, v.KV) {
+ break
+ }
}
}
-func (s *MicroServiceDependencyRuleSlice) ForEach(f func(i int, v *KV)) {
+func (s *MicroServiceRuleSlice) ForEach(f func(i int, v *KV) bool) {
for i, v := range *s {
v.KV.Value = v.Value
- f(i, v.KV)
+ if !f(i, v.KV) {
+ break
+ }
}
}
-func (s *SummarySlice) ForEach(f func(i int, v *KV)) {
+func (s *MicroServiceDependencyRuleSlice) ForEach(f func(i int, v *KV) bool) {
for i, v := range *s {
v.KV.Value = v.Value
- f(i, v.KV)
+ if !f(i, v.KV) {
+ break
+ }
}
}
-func (s *InstanceSlice) ForEach(f func(i int, v *KV)) {
+func (s *SummarySlice) ForEach(f func(i int, v *KV) bool) {
for i, v := range *s {
v.KV.Value = v.Value
- f(i, v.KV)
+ if !f(i, v.KV) {
+ break
+ }
+ }
+}
+func (s *InstanceSlice) ForEach(f func(i int, v *KV) bool) {
+ for i, v := range *s {
+ v.KV.Value = v.Value
+ if !f(i, v.KV) {
+ break
+ }
}
}
-func (s *MicroserviceSlice) SetValue(v *KV) { *s = append(*s, NewMicroservice(v)) }
-func (s *MicroserviceIndexSlice) SetValue(v *KV) { *s = append(*s, NewMicroserviceIndex(v)) }
-func (s *MicroserviceAliasSlice) SetValue(v *KV) { *s = append(*s, NewMicroserviceAlias(v)) }
-func (s *TagSlice) SetValue(v *KV) { *s = append(*s, NewTag(v)) }
-func (s *MicroServiceRuleSlice) SetValue(v *KV) { *s = append(*s, NewMicroServiceRule(v)) }
+func (s *MicroserviceSlice) SetValue(v *KV) { *s = append(*s, NewMicroservice(v)) }
+func (s *MicroserviceIndexSlice) SetValue(v *KV) { *s = append(*s, NewMicroserviceIndex(v)) }
+func (s *MicroserviceAliasSlice) SetValue(v *KV) { *s = append(*s, NewMicroserviceAlias(v)) }
+func (s *TagSlice) SetValue(v *KV) { *s = append(*s, NewTag(v)) }
+func (s *MicroServiceRuleIndexSlice) SetValue(v *KV) { *s = append(*s, NewMicroServiceRuleIndex(v)) }
+func (s *MicroServiceRuleSlice) SetValue(v *KV) { *s = append(*s, NewMicroServiceRule(v)) }
func (s *MicroServiceDependencyRuleSlice) SetValue(v *KV) {
*s = append(*s, NewMicroServiceDependencyRule(v))
}
@@ -108,6 +134,9 @@ func NewMicroserviceAlias(kv *KV) *MicroserviceAlias {
return &MicroserviceAlias{kv, kv.Value.(string)}
}
func NewTag(kv *KV) *Tag { return &Tag{kv, kv.Value.(map[string]string)} }
+func NewMicroServiceRuleIndex(kv *KV) *MicroServiceRuleIndex {
+ return &MicroServiceRuleIndex{kv, kv.Value.(string)}
+}
func NewMicroServiceRule(kv *KV) *MicroServiceRule {
return &MicroServiceRule{kv, kv.Value.(*pb.ServiceRule)}
}
@@ -125,6 +154,7 @@ type Cache struct {
Aliases MicroserviceAliasSlice `json:"serviceAliases,omitempty"`
Tags TagSlice `json:"serviceTags,omitempty"`
Rules MicroServiceRuleSlice `json:"serviceRules,omitempty"`
+ RuleIndexes MicroServiceRuleIndexSlice `json:"serviceRuleIndexes,omitempty"`
DependencyRules MicroServiceDependencyRuleSlice `json:"dependencyRules,omitempty"`
Summaries SummarySlice `json:"summaries,omitempty"`
Instances InstanceSlice `json:"instances,omitempty"`
@@ -156,11 +186,15 @@ type MicroServiceDependencyRule struct {
Value *pb.MicroServiceDependency `json:"value,omitempty"`
}
+type MicroServiceRuleIndex struct {
+ *KV
+ Value string `json:"value,omitempty"`
+}
+
type MicroServiceRule struct {
*KV
Value *pb.ServiceRule `json:"value,omitempty"`
}
-
type Summary struct {
*KV
Value string `json:"value,omitempty"`
diff --git a/server/admin/service.go b/server/admin/service.go
index 297ebbb..d178a65 100644
--- a/server/admin/service.go
+++ b/server/admin/service.go
@@ -24,7 +24,7 @@ import (
"github.com/apache/incubator-servicecomb-service-center/server/core/backend"
pb "github.com/apache/incubator-servicecomb-service-center/server/core/proto"
scerr "github.com/apache/incubator-servicecomb-service-center/server/error"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/discovery"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/discovery"
"github.com/apache/incubator-servicecomb-service-center/version"
"github.com/astaxie/beego"
"golang.org/x/net/context"
@@ -82,6 +82,7 @@ func (service *AdminService) dumpAll(ctx context.Context, cache *model.Cache) {
Do(func(_ context.Context) { setValue(backend.Store().ServiceIndex(), &cache.Indexes) }).
Do(func(_ context.Context) { setValue(backend.Store().ServiceAlias(), &cache.Aliases) }).
Do(func(_ context.Context) { setValue(backend.Store().ServiceTag(), &cache.Tags) }).
+ Do(func(_ context.Context) { setValue(backend.Store().RuleIndex(), &cache.RuleIndexes) }).
Do(func(_ context.Context) { setValue(backend.Store().Rule(), &cache.Rules) }).
Do(func(_ context.Context) { setValue(backend.Store().DependencyRule(), &cache.DependencyRules) }).
Do(func(_ context.Context) { setValue(backend.Store().SchemaSummary(), &cache.Summaries) }).
diff --git a/server/bootstrap/bootstrap.go b/server/bootstrap/bootstrap.go
index d5defb5..c0ebc88 100644
--- a/server/bootstrap/bootstrap.go
+++ b/server/bootstrap/bootstrap.go
@@ -21,32 +21,34 @@ import _ "github.com/apache/incubator-servicecomb-service-center/server/rest/con
import _ "github.com/apache/incubator-servicecomb-service-center/server/rest/controller/v4"
// registry
-import _ "github.com/apache/incubator-servicecomb-service-center/server/plugin/infra/registry/buildin"
-import _ "github.com/apache/incubator-servicecomb-service-center/server/plugin/infra/registry/etcd"
-import _ "github.com/apache/incubator-servicecomb-service-center/server/plugin/infra/registry/embededetcd"
+import _ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/registry/buildin"
+import _ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/registry/etcd"
+import _ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/registry/embededetcd"
// discovery
-import _ "github.com/apache/incubator-servicecomb-service-center/server/plugin/infra/discovery/etcd"
-import _ "github.com/apache/incubator-servicecomb-service-center/server/plugin/infra/discovery/k8s"
+import _ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/discovery/aggregate"
+import _ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/discovery/sc"
+import _ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/discovery/etcd"
+import _ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/discovery/k8s"
// cipher
-import _ "github.com/apache/incubator-servicecomb-service-center/server/plugin/infra/security/buildin"
+import _ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/security/buildin"
// quota
-import _ "github.com/apache/incubator-servicecomb-service-center/server/plugin/infra/quota/buildin"
-import _ "github.com/apache/incubator-servicecomb-service-center/server/plugin/infra/quota/unlimit"
+import _ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/quota/buildin"
+import _ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/quota/unlimit"
// auth
-import _ "github.com/apache/incubator-servicecomb-service-center/server/plugin/infra/auth/buildin"
+import _ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/auth/buildin"
// uuid
-import _ "github.com/apache/incubator-servicecomb-service-center/server/plugin/infra/uuid/buildin"
+import _ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/uuid/buildin"
// tracing
-import _ "github.com/apache/incubator-servicecomb-service-center/server/plugin/infra/tracing/buildin"
+import _ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/tracing/buildin"
// tls
-import _ "github.com/apache/incubator-servicecomb-service-center/server/plugin/infra/tls/buildin"
+import _ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/tls/buildin"
// module 'govern'
import _ "github.com/apache/incubator-servicecomb-service-center/server/govern"
diff --git a/server/broker/service.go b/server/broker/service.go
index dac2b2a..942787a 100644
--- a/server/broker/service.go
+++ b/server/broker/service.go
@@ -30,7 +30,7 @@ import (
apt "github.com/apache/incubator-servicecomb-service-center/server/core"
pb "github.com/apache/incubator-servicecomb-service-center/server/core/proto"
scerr "github.com/apache/incubator-servicecomb-service-center/server/error"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/registry"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/registry"
serviceUtil "github.com/apache/incubator-servicecomb-service-center/server/service/util"
"golang.org/x/net/context"
)
diff --git a/server/broker/store.go b/server/broker/store.go
index 6cad3db..68c16bc 100644
--- a/server/broker/store.go
+++ b/server/broker/store.go
@@ -18,7 +18,7 @@ package broker
import (
"github.com/apache/incubator-servicecomb-service-center/server/core/backend"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/discovery"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/discovery"
)
var (
diff --git a/server/broker/util.go b/server/broker/util.go
index f09c4aa..598eff6 100644
--- a/server/broker/util.go
+++ b/server/broker/util.go
@@ -31,7 +31,7 @@ import (
"github.com/apache/incubator-servicecomb-service-center/server/core/backend"
pb "github.com/apache/incubator-servicecomb-service-center/server/core/proto"
scerr "github.com/apache/incubator-servicecomb-service-center/server/error"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/registry"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/registry"
serviceUtil "github.com/apache/incubator-servicecomb-service-center/server/service/util"
"path/filepath"
)
diff --git a/server/core/backend/common.go b/server/core/backend/common.go
index 12127ef..df6b676 100644
--- a/server/core/backend/common.go
+++ b/server/core/backend/common.go
@@ -18,7 +18,7 @@ package backend
import (
"github.com/apache/incubator-servicecomb-service-center/server/core"
pb "github.com/apache/incubator-servicecomb-service-center/server/core/proto"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/discovery"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/discovery"
"time"
)
@@ -40,7 +40,6 @@ var (
SERVICE_TAG discovery.Type
RULE discovery.Type
RULE_INDEX discovery.Type
- DEPENDENCY discovery.Type
DEPENDENCY_RULE discovery.Type
DEPENDENCY_QUEUE discovery.Type
SCHEMA discovery.Type
@@ -84,9 +83,6 @@ func registerInnerTypes() {
RULE_INDEX = Store().MustInstall(discovery.NewAddOn("RULE_INDEX",
discovery.Configure().WithPrefix(core.GetServiceRuleIndexRootKey("")).
WithInitSize(100).WithParser(pb.StringParser)))
- DEPENDENCY = Store().MustInstall(discovery.NewAddOn("DEPENDENCY",
- discovery.Configure().WithPrefix(core.GetServiceDependencyRootKey("")).
- WithInitSize(100)))
DEPENDENCY_RULE = Store().MustInstall(discovery.NewAddOn("DEPENDENCY_RULE",
discovery.Configure().WithPrefix(core.GetServiceDependencyRuleRootKey("")).
WithInitSize(100).WithParser(pb.DependencyRuleParser)))
diff --git a/server/core/backend/defer_instance.go b/server/core/backend/defer_instance.go
index 5ddc121..82e81b0 100644
--- a/server/core/backend/defer_instance.go
+++ b/server/core/backend/defer_instance.go
@@ -21,7 +21,7 @@ import (
"github.com/apache/incubator-servicecomb-service-center/pkg/log"
"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/server/infra/discovery"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/discovery"
"golang.org/x/net/context"
"sync"
"time"
diff --git a/server/core/backend/defer_test.go b/server/core/backend/defer_test.go
index 9fa5bc8..bb246fc 100644
--- a/server/core/backend/defer_test.go
+++ b/server/core/backend/defer_test.go
@@ -20,7 +20,7 @@ import (
"fmt"
"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/server/infra/discovery"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/discovery"
"testing"
"time"
)
diff --git a/server/core/backend/discovery.go b/server/core/backend/discovery.go
index bdbf9db..1e6435b 100644
--- a/server/core/backend/discovery.go
+++ b/server/core/backend/discovery.go
@@ -21,9 +21,9 @@ import (
"github.com/apache/incubator-servicecomb-service-center/pkg/log"
"github.com/apache/incubator-servicecomb-service-center/pkg/task"
"github.com/apache/incubator-servicecomb-service-center/pkg/util"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/discovery"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/registry"
"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/registry"
"golang.org/x/net/context"
"sync"
)
@@ -72,10 +72,12 @@ func (s *KvStore) getOrCreateAdaptor(t discovery.Type) discovery.Adaptor {
v, _ := s.adaptors.Fetch(t, func() (interface{}, error) {
addOn, ok := s.addOns.Get(t)
if ok {
- return s.repo().New(t, addOn.(discovery.AddOn).Config()), nil
+ adaptor := s.repo().New(t, addOn.(discovery.AddOn).Config())
+ adaptor.Run()
+ return adaptor, nil
}
log.Warnf("type '%s' not found", t)
- return s.repo().New(t, nil), nil
+ return nil, nil
})
return v.(discovery.Adaptor)
}
@@ -160,7 +162,6 @@ func (s *KvStore) ServiceTag() discovery.Adaptor { return s.Adapt
func (s *KvStore) Rule() discovery.Adaptor { return s.Adaptors(RULE) }
func (s *KvStore) RuleIndex() discovery.Adaptor { return s.Adaptors(RULE_INDEX) }
func (s *KvStore) Schema() discovery.Adaptor { return s.Adaptors(SCHEMA) }
-func (s *KvStore) Dependency() discovery.Adaptor { return s.Adaptors(DEPENDENCY) }
func (s *KvStore) DependencyRule() discovery.Adaptor { return s.Adaptors(DEPENDENCY_RULE) }
func (s *KvStore) DependencyQueue() discovery.Adaptor { return s.Adaptors(DEPENDENCY_QUEUE) }
func (s *KvStore) Domain() discovery.Adaptor { return s.Adaptors(DOMAIN) }
diff --git a/server/core/backend/discovery_test.go b/server/core/backend/discovery_test.go
index 520c7e6..1c5102e 100644
--- a/server/core/backend/discovery_test.go
+++ b/server/core/backend/discovery_test.go
@@ -19,8 +19,8 @@ package backend
import (
"errors"
"github.com/apache/incubator-servicecomb-service-center/pkg/task"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/discovery"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/registry"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/discovery"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/registry"
"golang.org/x/net/context"
"testing"
)
diff --git a/server/core/backend/lease.go b/server/core/backend/lease.go
index 6e56ace..dac84c9 100644
--- a/server/core/backend/lease.go
+++ b/server/core/backend/lease.go
@@ -20,7 +20,7 @@ import (
errorsEx "github.com/apache/incubator-servicecomb-service-center/pkg/errors"
"github.com/apache/incubator-servicecomb-service-center/pkg/log"
"github.com/apache/incubator-servicecomb-service-center/pkg/util"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/registry"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/registry"
"golang.org/x/net/context"
"time"
)
diff --git a/server/core/backend/lease_test.go b/server/core/backend/lease_test.go
index f06dbd2..bc51897 100644
--- a/server/core/backend/lease_test.go
+++ b/server/core/backend/lease_test.go
@@ -19,7 +19,7 @@ package backend
import (
"fmt"
errorsEx "github.com/apache/incubator-servicecomb-service-center/pkg/errors"
- "github.com/apache/incubator-servicecomb-service-center/server/plugin/infra/registry/buildin"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/registry/buildin"
"golang.org/x/net/context"
"testing"
"time"
diff --git a/server/core/backend/registry.go b/server/core/backend/registry.go
index b6b4133..6e1d3b0 100644
--- a/server/core/backend/registry.go
+++ b/server/core/backend/registry.go
@@ -24,8 +24,8 @@ import (
"github.com/apache/incubator-servicecomb-service-center/pkg/util"
"github.com/apache/incubator-servicecomb-service-center/server/core"
pb "github.com/apache/incubator-servicecomb-service-center/server/core/proto"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/registry"
"github.com/apache/incubator-servicecomb-service-center/server/plugin"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/registry"
"golang.org/x/net/context"
"sync"
"time"
diff --git a/server/core/key_convertor.go b/server/core/key_convertor.go
index 0e860f1..fbb59fb 100644
--- a/server/core/key_convertor.go
+++ b/server/core/key_convertor.go
@@ -108,24 +108,24 @@ func GetInfoFromSvcIndexKV(key []byte) *pb.MicroServiceKey {
}
}
-func GetInfoFromSchemaSummaryKV(key []byte) (schemaId string) {
+func GetInfoFromSchemaSummaryKV(key []byte) (domainProject, serviceId, schemaId string) {
keys := KvToResponse(key)
l := len(keys)
- if l < 2 {
+ if l < 4 {
return
}
-
- return keys[l-1]
+ domainProject = fmt.Sprintf("%s/%s", keys[l-4], keys[l-3])
+ return domainProject, keys[l-2], keys[l-1]
}
-func GetInfoFromSchemaKV(key []byte) (schemaId string) {
+func GetInfoFromSchemaKV(key []byte) (domainProject, serviceId, schemaId string) {
keys := KvToResponse(key)
l := len(keys)
- if l < 2 {
+ if l < 4 {
return
}
-
- return keys[l-1]
+ domainProject = fmt.Sprintf("%s/%s", keys[l-4], keys[l-3])
+ return domainProject, keys[l-2], keys[l-1]
}
func GetInfoFromDependencyQueueKV(key []byte) (consumerId, domainProject, uuid string) {
diff --git a/server/core/key_convertor_test.go b/server/core/key_convertor_test.go
index 298f4d4..21dd2bf 100644
--- a/server/core/key_convertor_test.go
+++ b/server/core/key_convertor_test.go
@@ -101,21 +101,21 @@ func TestGetInfoFromKV(t *testing.T) {
t.Fatalf("TestGetInfoFromKV failed")
}
- m := GetInfoFromSchemaSummaryKV([]byte(GenerateServiceSchemaSummaryKey("a/b", "c", "d")))
- if m != "d" {
+ d, s, m := GetInfoFromSchemaSummaryKV([]byte(GenerateServiceSchemaSummaryKey("a/b", "c", "d")))
+ if m != "d" || s != "c" || d != "a/b" {
t.Fatalf("TestGetInfoFromKV failed")
}
- m = GetInfoFromSchemaSummaryKV([]byte("sdf"))
- if m != "" {
+ d, s, m = GetInfoFromSchemaSummaryKV([]byte("sdf"))
+ if m != "" || s != "" || d != "" {
t.Fatalf("TestGetInfoFromKV failed")
}
- m = GetInfoFromSchemaKV([]byte(GenerateServiceSchemaKey("a/b", "c", "d")))
- if m != "d" {
+ d, s, m = GetInfoFromSchemaKV([]byte(GenerateServiceSchemaKey("a/b", "c", "d")))
+ if m != "d" || s != "c" || d != "a/b" {
t.Fatalf("TestGetInfoFromKV failed")
}
- m = GetInfoFromSchemaKV([]byte("sdf"))
- if m != "" {
+ d, s, m = GetInfoFromSchemaKV([]byte("sdf"))
+ if m != "" || s != "" || d != "" {
t.Fatalf("TestGetInfoFromKV failed")
}
diff --git a/server/core/swagger/v4.yaml b/server/core/swagger/v4.yaml
index c7ea633..07fe446 100644
--- a/server/core/swagger/v4.yaml
+++ b/server/core/swagger/v4.yaml
@@ -2338,6 +2338,10 @@ definitions:
type: array
items:
$ref: "#/definitions/MicroserviceTagKV"
+ serviceRuleIndexes:
+ type: array
+ items:
+ $ref: "#/definitions/StringKV"
serviceRules:
type: array
items:
diff --git a/server/govern/service.go b/server/govern/service.go
index 955d01f..494288b 100644
--- a/server/govern/service.go
+++ b/server/govern/service.go
@@ -24,7 +24,7 @@ import (
"github.com/apache/incubator-servicecomb-service-center/server/core/backend"
pb "github.com/apache/incubator-servicecomb-service-center/server/core/proto"
scerr "github.com/apache/incubator-servicecomb-service-center/server/error"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/registry"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/registry"
"github.com/apache/incubator-servicecomb-service-center/server/service"
serviceUtil "github.com/apache/incubator-servicecomb-service-center/server/service/util"
"golang.org/x/net/context"
diff --git a/server/plugin/infra/discovery/k8s/repo.go b/server/plugin/common.go
similarity index 60%
copy from server/plugin/infra/discovery/k8s/repo.go
copy to server/plugin/common.go
index 7a93961..eedd028 100644
--- a/server/plugin/infra/discovery/k8s/repo.go
+++ b/server/plugin/common.go
@@ -13,32 +13,30 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package k8s
+package plugin
import (
"github.com/apache/incubator-servicecomb-service-center/pkg/log"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/discovery"
- mgr "github.com/apache/incubator-servicecomb-service-center/server/plugin"
+ "github.com/apache/incubator-servicecomb-service-center/pkg/plugin"
+ pg "plugin"
)
-func init() {
- mgr.RegisterPlugin(mgr.Plugin{mgr.DISCOVERY, "k8s", NewRepository})
-}
-
-type K8sRepository struct {
-}
+const (
+ BUILDIN = "buildin"
+ STATIC = "static"
+ DYNAMIC = "dynamic"
+ keyPluginName = "name"
+)
-func (r *K8sRepository) New(t discovery.Type, cfg *discovery.Config) discovery.Adaptor {
- if cfg == nil {
- // do not new instance
- log.Warnf("type '%s' config is nil", t)
+// DynamicPluginFunc should be called in buildin implement
+func DynamicPluginFunc(pn PluginName, funcName string) pg.Symbol {
+ if wi, ok := Plugins().instances[pn]; ok && !wi.dynamic {
return nil
}
- e := NewK8sAdaptor(t, cfg)
- e.Run()
- return e
-}
-func NewRepository() mgr.PluginInstance {
- return &K8sRepository{}
+ f, err := plugin.FindFunc(pn.String(), funcName)
+ if err != nil {
+ log.Errorf(err, "plugin '%s': not implemented function '%s'.", pn, funcName)
+ }
+ return f
}
diff --git a/server/plugin/export.go b/server/plugin/export.go
new file mode 100644
index 0000000..02c1596
--- /dev/null
+++ b/server/plugin/export.go
@@ -0,0 +1,69 @@
+// 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 plugin
+
+import (
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/auditlog"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/auth"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/discovery"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/quota"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/registry"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/security"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/tls"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/tracing"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/uuid"
+)
+
+const (
+ UUID PluginName = iota
+ AUDIT_LOG
+ AUTH
+ CIPHER
+ QUOTA
+ REGISTRY
+ TRACING
+ TLS
+ DISCOVERY
+ typeEnd
+)
+
+var pluginNames = map[PluginName]string{
+ UUID: "uuid",
+ AUDIT_LOG: "auditlog",
+ AUTH: "auth",
+ CIPHER: "cipher",
+ QUOTA: "quota",
+ REGISTRY: "registry",
+ TRACING: "trace",
+ DISCOVERY: "discovery",
+ TLS: "ssl",
+}
+
+func (pm *PluginManager) Discovery() discovery.AdaptorRepository {
+ return pm.Instance(DISCOVERY).(discovery.AdaptorRepository)
+}
+func (pm *PluginManager) Registry() registry.Registry {
+ return pm.Instance(REGISTRY).(registry.Registry)
+}
+func (pm *PluginManager) UUID() uuid.UUID { return pm.Instance(UUID).(uuid.UUID) }
+func (pm *PluginManager) AuditLog() auditlog.AuditLogger {
+ return pm.Instance(AUDIT_LOG).(auditlog.AuditLogger)
+}
+func (pm *PluginManager) Auth() auth.Auth { return pm.Instance(AUTH).(auth.Auth) }
+func (pm *PluginManager) Cipher() security.Cipher { return pm.Instance(CIPHER).(security.Cipher) }
+func (pm *PluginManager) Quota() quota.QuotaManager { return pm.Instance(QUOTA).(quota.QuotaManager) }
+func (pm *PluginManager) Tracing() (v tracing.Tracing) { return pm.Instance(TRACING).(tracing.Tracing) }
+func (pm *PluginManager) TLS() tls.TLS { return pm.Instance(TLS).(tls.TLS) }
diff --git a/server/plugin/infra/discovery/k8s/cacher.go b/server/plugin/infra/discovery/k8s/cacher.go
deleted file mode 100644
index d2ee128..0000000
--- a/server/plugin/infra/discovery/k8s/cacher.go
+++ /dev/null
@@ -1,93 +0,0 @@
-// 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 k8s
-
-import (
- "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/util"
- "github.com/apache/incubator-servicecomb-service-center/server/core/backend"
- "github.com/apache/incubator-servicecomb-service-center/server/core/proto"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/discovery"
- "golang.org/x/net/context"
-)
-
-type K8sCacher struct {
- Cfg *discovery.Config
- // cache for indexer
- cache discovery.Cache
-
- ready chan struct{}
- goroutine *gopool.Pool
-}
-
-func (c *K8sCacher) Cache() discovery.Cache {
- return c.cache
-}
-
-func (c *K8sCacher) Notify(action proto.EventType, key string, kv *discovery.KeyValue) {
- switch action {
- case proto.EVT_DELETE:
- c.cache.Remove(key)
- default:
- c.cache.Put(key, kv)
- }
- c.OnEvents(discovery.KvEvent{Type: action, KV: kv})
-}
-
-func (c *K8sCacher) OnEvents(evt discovery.KvEvent) {
- if c.Cfg.OnEvent == nil {
- return
- }
-
- defer log.Recover()
- c.Cfg.OnEvent(evt)
-}
-
-func (c *K8sCacher) Run() {
- util.SafeCloseChan(c.ready)
-}
-
-func (c *K8sCacher) Stop() {
- c.goroutine.Close(true)
-}
-
-func (c *K8sCacher) Ready() <-chan struct{} {
- return c.ready
-}
-
-func NewK8sCacher(cfg *discovery.Config, cache discovery.Cache) *K8sCacher {
- return &K8sCacher{
- Cfg: cfg,
- cache: cache,
- ready: make(chan struct{}),
- goroutine: gopool.New(context.Background()),
- }
-}
-
-func BuildCacher(t discovery.Type, cfg *discovery.Config, cache discovery.Cache) discovery.Cacher {
- kc := NewK8sCacher(cfg, cache)
- switch t {
- case backend.SERVICE:
- return NewServiceCacher(kc)
- case backend.SERVICE_INDEX:
- return NewServiceIndexCacher(kc)
- case backend.INSTANCE:
- return NewInstanceCacher(kc)
- default:
- return kc
- }
-}
diff --git a/server/infra/auditlog/auditlog.go b/server/plugin/pkg/auditlog/auditlog.go
similarity index 100%
rename from server/infra/auditlog/auditlog.go
rename to server/plugin/pkg/auditlog/auditlog.go
diff --git a/server/infra/auth/auth.go b/server/plugin/pkg/auth/auth.go
similarity index 100%
rename from server/infra/auth/auth.go
rename to server/plugin/pkg/auth/auth.go
diff --git a/server/plugin/infra/auth/buildin/buildin.go b/server/plugin/pkg/auth/buildin/buildin.go
similarity index 100%
rename from server/plugin/infra/auth/buildin/buildin.go
rename to server/plugin/pkg/auth/buildin/buildin.go
diff --git a/server/plugin/pkg/discovery/aggregate/adaptor.go b/server/plugin/pkg/discovery/aggregate/adaptor.go
new file mode 100644
index 0000000..3965eca
--- /dev/null
+++ b/server/plugin/pkg/discovery/aggregate/adaptor.go
@@ -0,0 +1,70 @@
+// 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 sc
+
+import (
+ "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"
+)
+
+// Aggregator is a discovery service adaptor implement of one kubernetes cluster
+type Aggregator []discovery.Adaptor
+
+func (as *Aggregator) Search(ctx context.Context, opts ...registry.PluginOpOption) (*discovery.Response, error) {
+ var response discovery.Response
+ for _, a := range *as {
+ resp, err := a.Search(ctx, opts...)
+ if err != nil {
+ continue
+ }
+ response.Kvs = append(response.Kvs, resp.Kvs...)
+ response.Count += resp.Count
+ }
+ return &response, nil
+}
+
+func (as *Aggregator) Cache() discovery.Cache {
+ return discovery.NullCache
+}
+
+func (as *Aggregator) Run() {
+ for _, a := range *as {
+ a.Run()
+ }
+}
+
+func (as *Aggregator) Stop() {
+ for _, a := range *as {
+ a.Stop()
+ }
+}
+
+func (as *Aggregator) Ready() <-chan struct{} {
+ for _, a := range *as {
+ <-a.Ready()
+ }
+ return closedCh
+}
+
+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))
+ return as
+}
diff --git a/server/infra/discovery/types_test.go b/server/plugin/pkg/discovery/aggregate/common.go
similarity index 67%
copy from server/infra/discovery/types_test.go
copy to server/plugin/pkg/discovery/aggregate/common.go
index 5d54c5b..d8448ae 100644
--- a/server/infra/discovery/types_test.go
+++ b/server/plugin/pkg/discovery/aggregate/common.go
@@ -13,25 +13,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package discovery
+package sc
-import "testing"
+var (
+ closedCh = make(chan struct{})
+)
-func TestTypes(t *testing.T) {
- id, _ := Install(NewAddOn("TestTypes", Configure()))
- found := false
- for _, t := range Types() {
- if t == id {
- found = true
- }
- }
- if !found {
- t.Fatalf("TestTypes failed")
- }
- if id.String() != "TestTypes" {
- t.Fatalf("TestTypes failed")
- }
- if TypeError.String() != "TypeError" {
- t.Fatalf("TestTypes failed")
- }
+func init() {
+ close(closedCh)
}
diff --git a/server/plugin/infra/discovery/k8s/repo.go b/server/plugin/pkg/discovery/aggregate/repo.go
similarity index 69%
copy from server/plugin/infra/discovery/k8s/repo.go
copy to server/plugin/pkg/discovery/aggregate/repo.go
index 7a93961..4fd9f02 100644
--- a/server/plugin/infra/discovery/k8s/repo.go
+++ b/server/plugin/pkg/discovery/aggregate/repo.go
@@ -13,32 +13,24 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package k8s
+package sc
import (
- "github.com/apache/incubator-servicecomb-service-center/pkg/log"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/discovery"
mgr "github.com/apache/incubator-servicecomb-service-center/server/plugin"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/discovery"
)
func init() {
- mgr.RegisterPlugin(mgr.Plugin{mgr.DISCOVERY, "k8s", NewRepository})
+ mgr.RegisterPlugin(mgr.Plugin{mgr.DISCOVERY, "aggregate", NewRepository})
}
-type K8sRepository struct {
+type AggregateRepository struct {
}
-func (r *K8sRepository) New(t discovery.Type, cfg *discovery.Config) discovery.Adaptor {
- if cfg == nil {
- // do not new instance
- log.Warnf("type '%s' config is nil", t)
- return nil
- }
- e := NewK8sAdaptor(t, cfg)
- e.Run()
- return e
+func (r *AggregateRepository) New(t discovery.Type, cfg *discovery.Config) discovery.Adaptor {
+ return NewAggregator(t, cfg)
}
func NewRepository() mgr.PluginInstance {
- return &K8sRepository{}
+ return &AggregateRepository{}
}
diff --git a/server/infra/discovery/cache.go b/server/plugin/pkg/discovery/cache.go
similarity index 100%
rename from server/infra/discovery/cache.go
rename to server/plugin/pkg/discovery/cache.go
diff --git a/server/infra/discovery/cache_kv.go b/server/plugin/pkg/discovery/cache_kv.go
similarity index 100%
rename from server/infra/discovery/cache_kv.go
rename to server/plugin/pkg/discovery/cache_kv.go
diff --git a/server/infra/discovery/cache_null.go b/server/plugin/pkg/discovery/cache_null.go
similarity index 100%
rename from server/infra/discovery/cache_null.go
rename to server/plugin/pkg/discovery/cache_null.go
diff --git a/server/infra/discovery/cache_test.go b/server/plugin/pkg/discovery/cache_test.go
similarity index 100%
rename from server/infra/discovery/cache_test.go
rename to server/plugin/pkg/discovery/cache_test.go
diff --git a/server/plugin/infra/discovery/k8s/repo.go b/server/plugin/pkg/discovery/cacher.go
similarity index 51%
copy from server/plugin/infra/discovery/k8s/repo.go
copy to server/plugin/pkg/discovery/cacher.go
index 7a93961..a09332a 100644
--- a/server/plugin/infra/discovery/k8s/repo.go
+++ b/server/plugin/pkg/discovery/cacher.go
@@ -13,32 +13,60 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package k8s
+package discovery
import (
"github.com/apache/incubator-servicecomb-service-center/pkg/log"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/discovery"
- mgr "github.com/apache/incubator-servicecomb-service-center/server/plugin"
+ "github.com/apache/incubator-servicecomb-service-center/pkg/util"
+ "github.com/apache/incubator-servicecomb-service-center/server/core/proto"
)
-func init() {
- mgr.RegisterPlugin(mgr.Plugin{mgr.DISCOVERY, "k8s", NewRepository})
+type CommonCacher struct {
+ Cfg *Config
+ // cache for indexer
+ cache Cache
+
+ ready chan struct{}
+}
+
+func (c *CommonCacher) Cache() Cache {
+ return c.cache
}
-type K8sRepository struct {
+func (c *CommonCacher) Notify(action proto.EventType, key string, kv *KeyValue) {
+ switch action {
+ case proto.EVT_DELETE:
+ c.cache.Remove(key)
+ default:
+ c.cache.Put(key, kv)
+ }
+ c.OnEvent(KvEvent{Type: action, KV: kv})
}
-func (r *K8sRepository) New(t discovery.Type, cfg *discovery.Config) discovery.Adaptor {
- if cfg == nil {
- // do not new instance
- log.Warnf("type '%s' config is nil", t)
- return nil
+func (c *CommonCacher) OnEvent(evt KvEvent) {
+ if c.Cfg.OnEvent == nil {
+ return
}
- e := NewK8sAdaptor(t, cfg)
- e.Run()
- return e
+
+ defer log.Recover()
+ c.Cfg.OnEvent(evt)
+}
+
+func (c *CommonCacher) Run() {
+ util.SafeCloseChan(c.ready)
+}
+
+func (c *CommonCacher) Stop() {
}
-func NewRepository() mgr.PluginInstance {
- return &K8sRepository{}
+func (c *CommonCacher) Ready() <-chan struct{} {
+ return c.ready
+}
+
+func NewCommonCacher(cfg *Config, cache Cache) *CommonCacher {
+ return &CommonCacher{
+ Cfg: cfg,
+ cache: cache,
+ ready: make(chan struct{}),
+ }
}
diff --git a/server/infra/discovery/common.go b/server/plugin/pkg/discovery/common.go
similarity index 100%
rename from server/infra/discovery/common.go
rename to server/plugin/pkg/discovery/common.go
diff --git a/server/infra/discovery/config.go b/server/plugin/pkg/discovery/config.go
similarity index 100%
rename from server/infra/discovery/config.go
rename to server/plugin/pkg/discovery/config.go
diff --git a/server/infra/discovery/config_test.go b/server/plugin/pkg/discovery/config_test.go
similarity index 100%
rename from server/infra/discovery/config_test.go
rename to server/plugin/pkg/discovery/config_test.go
diff --git a/server/infra/discovery/defer.go b/server/plugin/pkg/discovery/defer.go
similarity index 100%
rename from server/infra/discovery/defer.go
rename to server/plugin/pkg/discovery/defer.go
diff --git a/server/infra/discovery/discovery.go b/server/plugin/pkg/discovery/discovery.go
similarity index 86%
rename from server/infra/discovery/discovery.go
rename to server/plugin/pkg/discovery/discovery.go
index 98f35a6..d0c0d94 100644
--- a/server/infra/discovery/discovery.go
+++ b/server/plugin/pkg/discovery/discovery.go
@@ -18,7 +18,10 @@ package discovery
type Adaptor interface {
Runnable
+ // Indexer is the key indexer of cache
Indexer
+ // Cacher is the cache manager to sync data from registry server
+ // and publish the cache event if cache changed
Cacher
}
diff --git a/server/plugin/infra/discovery/etcd/adaptor.go b/server/plugin/pkg/discovery/etcd/adaptor.go
similarity index 82%
rename from server/plugin/infra/discovery/etcd/adaptor.go
rename to server/plugin/pkg/discovery/etcd/adaptor.go
index 35e5b0e..09cd7e8 100644
--- a/server/plugin/infra/discovery/etcd/adaptor.go
+++ b/server/plugin/pkg/discovery/etcd/adaptor.go
@@ -19,14 +19,7 @@ package etcd
import (
"github.com/apache/incubator-servicecomb-service-center/pkg/log"
"github.com/apache/incubator-servicecomb-service-center/server/core"
- pb "github.com/apache/incubator-servicecomb-service-center/server/core/proto"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/discovery"
- "sync"
-)
-
-var (
- defaultEtcdAdaptor *EtcdAdaptor
- newEtcdAdaptorOnce sync.Once
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/discovery"
)
type EtcdAdaptor struct {
@@ -69,13 +62,3 @@ func NewEtcdAdaptor(name string, cfg *discovery.Config) *EtcdAdaptor {
}
return &adaptor
}
-
-func DefaultKvEntity() *EtcdAdaptor {
- newEtcdAdaptorOnce.Do(func() {
- defaultEtcdAdaptor = &EtcdAdaptor{
- Cacher: discovery.NullCacher,
- Indexer: NewEtcdIndexer(discovery.Configure().Key, pb.BytesParser),
- }
- })
- return defaultEtcdAdaptor
-}
diff --git a/server/plugin/infra/discovery/etcd/adaptor_test.go b/server/plugin/pkg/discovery/etcd/adaptor_test.go
similarity index 93%
rename from server/plugin/infra/discovery/etcd/adaptor_test.go
rename to server/plugin/pkg/discovery/etcd/adaptor_test.go
index 54a3130..d84c8f8 100644
--- a/server/plugin/infra/discovery/etcd/adaptor_test.go
+++ b/server/plugin/pkg/discovery/etcd/adaptor_test.go
@@ -18,7 +18,7 @@ package etcd
import (
"github.com/apache/incubator-servicecomb-service-center/server/core"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/discovery"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/discovery"
"testing"
)
@@ -50,10 +50,6 @@ func TestNewKvEntity(t *testing.T) {
func TestNewRepository(t *testing.T) {
repo := NewRepository()
- if repo.(*EtcdRepository).New(0, nil) != DefaultKvEntity() {
- t.Fatalf("TestNewIndexer failed")
- }
-
i := repo.(*EtcdRepository).New(0, discovery.Configure())
if _, ok := i.(*EtcdAdaptor); !ok {
t.Fatalf("TestNewIndexer failed")
diff --git a/server/plugin/infra/discovery/etcd/cacher_kv.go b/server/plugin/pkg/discovery/etcd/cacher_kv.go
similarity index 99%
rename from server/plugin/infra/discovery/etcd/cacher_kv.go
rename to server/plugin/pkg/discovery/etcd/cacher_kv.go
index 0cade62..8136244 100644
--- a/server/plugin/infra/discovery/etcd/cacher_kv.go
+++ b/server/plugin/pkg/discovery/etcd/cacher_kv.go
@@ -25,8 +25,8 @@ 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/core/proto"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/discovery"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/registry"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/discovery"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/registry"
"github.com/coreos/etcd/mvcc/mvccpb"
"golang.org/x/net/context"
"sync"
diff --git a/server/plugin/infra/discovery/etcd/cacher_kv_test.go b/server/plugin/pkg/discovery/etcd/cacher_kv_test.go
similarity index 99%
rename from server/plugin/infra/discovery/etcd/cacher_kv_test.go
rename to server/plugin/pkg/discovery/etcd/cacher_kv_test.go
index 5ac42f8..6b9e9b1 100644
--- a/server/plugin/infra/discovery/etcd/cacher_kv_test.go
+++ b/server/plugin/pkg/discovery/etcd/cacher_kv_test.go
@@ -22,8 +22,8 @@ import (
"github.com/apache/incubator-servicecomb-service-center/pkg/gopool"
"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/server/infra/discovery"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/registry"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/discovery"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/registry"
"github.com/coreos/etcd/mvcc/mvccpb"
"golang.org/x/net/context"
"math/rand"
diff --git a/server/plugin/infra/discovery/etcd/common.go b/server/plugin/pkg/discovery/etcd/common.go
similarity index 98%
rename from server/plugin/infra/discovery/etcd/common.go
rename to server/plugin/pkg/discovery/etcd/common.go
index d789167..59bef09 100644
--- a/server/plugin/infra/discovery/etcd/common.go
+++ b/server/plugin/pkg/discovery/etcd/common.go
@@ -17,7 +17,7 @@ package etcd
import (
pb "github.com/apache/incubator-servicecomb-service-center/server/core/proto"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/discovery"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/discovery"
"github.com/coreos/etcd/mvcc/mvccpb"
"time"
)
diff --git a/server/plugin/infra/discovery/etcd/indexer_cache.go b/server/plugin/pkg/discovery/etcd/indexer_cache.go
similarity index 97%
rename from server/plugin/infra/discovery/etcd/indexer_cache.go
rename to server/plugin/pkg/discovery/etcd/indexer_cache.go
index 6e8fb7f..bf0bef7 100644
--- a/server/plugin/infra/discovery/etcd/indexer_cache.go
+++ b/server/plugin/pkg/discovery/etcd/indexer_cache.go
@@ -19,8 +19,8 @@ package etcd
import (
"fmt"
"github.com/apache/incubator-servicecomb-service-center/pkg/util"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/discovery"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/registry"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/discovery"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/registry"
"golang.org/x/net/context"
)
diff --git a/server/plugin/infra/discovery/etcd/indexer_etcd.go b/server/plugin/pkg/discovery/etcd/indexer_etcd.go
similarity index 98%
rename from server/plugin/infra/discovery/etcd/indexer_etcd.go
rename to server/plugin/pkg/discovery/etcd/indexer_etcd.go
index f69a51c..3a4d4be 100644
--- a/server/plugin/infra/discovery/etcd/indexer_etcd.go
+++ b/server/plugin/pkg/discovery/etcd/indexer_etcd.go
@@ -22,8 +22,8 @@ import (
"github.com/apache/incubator-servicecomb-service-center/pkg/util"
"github.com/apache/incubator-servicecomb-service-center/server/core/backend"
pb "github.com/apache/incubator-servicecomb-service-center/server/core/proto"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/discovery"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/registry"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/discovery"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/registry"
"golang.org/x/net/context"
"strings"
)
diff --git a/server/plugin/infra/discovery/etcd/indexer_test.go b/server/plugin/pkg/discovery/etcd/indexer_test.go
similarity index 99%
rename from server/plugin/infra/discovery/etcd/indexer_test.go
rename to server/plugin/pkg/discovery/etcd/indexer_test.go
index 1284678..84b2479 100644
--- a/server/plugin/infra/discovery/etcd/indexer_test.go
+++ b/server/plugin/pkg/discovery/etcd/indexer_test.go
@@ -19,8 +19,8 @@ package etcd
import (
"context"
pb "github.com/apache/incubator-servicecomb-service-center/server/core/proto"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/discovery"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/registry"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/discovery"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/registry"
"github.com/coreos/etcd/mvcc/mvccpb"
"testing"
)
diff --git a/server/plugin/infra/discovery/etcd/listwatch.go b/server/plugin/pkg/discovery/etcd/listwatch.go
similarity index 98%
rename from server/plugin/infra/discovery/etcd/listwatch.go
rename to server/plugin/pkg/discovery/etcd/listwatch.go
index 71c70ab..fe5cacc 100644
--- a/server/plugin/infra/discovery/etcd/listwatch.go
+++ b/server/plugin/pkg/discovery/etcd/listwatch.go
@@ -18,7 +18,7 @@ package etcd
import (
"fmt"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/registry"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/registry"
"golang.org/x/net/context"
"time"
)
diff --git a/server/plugin/infra/discovery/etcd/listwatch_inner.go b/server/plugin/pkg/discovery/etcd/listwatch_inner.go
similarity index 99%
rename from server/plugin/infra/discovery/etcd/listwatch_inner.go
rename to server/plugin/pkg/discovery/etcd/listwatch_inner.go
index 3817185..265cf91 100644
--- a/server/plugin/infra/discovery/etcd/listwatch_inner.go
+++ b/server/plugin/pkg/discovery/etcd/listwatch_inner.go
@@ -19,7 +19,7 @@ package etcd
import (
"fmt"
"github.com/apache/incubator-servicecomb-service-center/pkg/log"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/registry"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/registry"
"golang.org/x/net/context"
)
diff --git a/server/plugin/infra/discovery/etcd/listwatch_test.go b/server/plugin/pkg/discovery/etcd/listwatch_test.go
similarity index 98%
rename from server/plugin/infra/discovery/etcd/listwatch_test.go
rename to server/plugin/pkg/discovery/etcd/listwatch_test.go
index cf2717a..3e0d896 100644
--- a/server/plugin/infra/discovery/etcd/listwatch_test.go
+++ b/server/plugin/pkg/discovery/etcd/listwatch_test.go
@@ -18,8 +18,8 @@ package etcd
import (
"fmt"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/registry"
- "github.com/apache/incubator-servicecomb-service-center/server/plugin/infra/registry/buildin"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/registry"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/registry/buildin"
"github.com/coreos/etcd/mvcc/mvccpb"
"golang.org/x/net/context"
"testing"
diff --git a/server/plugin/infra/discovery/etcd/metrics.go b/server/plugin/pkg/discovery/etcd/metrics.go
similarity index 100%
rename from server/plugin/infra/discovery/etcd/metrics.go
rename to server/plugin/pkg/discovery/etcd/metrics.go
diff --git a/server/plugin/infra/discovery/etcd/metrics_test.go b/server/plugin/pkg/discovery/etcd/metrics_test.go
similarity index 100%
rename from server/plugin/infra/discovery/etcd/metrics_test.go
rename to server/plugin/pkg/discovery/etcd/metrics_test.go
diff --git a/server/plugin/infra/discovery/etcd/repo.go b/server/plugin/pkg/discovery/etcd/repo.go
similarity index 83%
rename from server/plugin/infra/discovery/etcd/repo.go
rename to server/plugin/pkg/discovery/etcd/repo.go
index 6b48651..564aeca 100644
--- a/server/plugin/infra/discovery/etcd/repo.go
+++ b/server/plugin/pkg/discovery/etcd/repo.go
@@ -16,9 +16,8 @@
package etcd
import (
- "github.com/apache/incubator-servicecomb-service-center/pkg/log"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/discovery"
mgr "github.com/apache/incubator-servicecomb-service-center/server/plugin"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/discovery"
)
func init() {
@@ -30,14 +29,7 @@ type EtcdRepository struct {
}
func (r *EtcdRepository) New(t discovery.Type, cfg *discovery.Config) discovery.Adaptor {
- if cfg == nil {
- // do not new instance
- log.Warnf("'%s' config is nil, new default entity", t)
- return DefaultKvEntity()
- }
- e := NewEtcdAdaptor(t.String(), cfg)
- e.Run()
- return e
+ return NewEtcdAdaptor(t.String(), cfg)
}
func NewRepository() mgr.PluginInstance {
diff --git a/server/plugin/infra/discovery/etcd/watcher.go b/server/plugin/pkg/discovery/etcd/watcher.go
similarity index 97%
rename from server/plugin/infra/discovery/etcd/watcher.go
rename to server/plugin/pkg/discovery/etcd/watcher.go
index 4c0a612..62be2e8 100644
--- a/server/plugin/infra/discovery/etcd/watcher.go
+++ b/server/plugin/pkg/discovery/etcd/watcher.go
@@ -17,7 +17,7 @@
package etcd
import (
- "github.com/apache/incubator-servicecomb-service-center/server/infra/registry"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/registry"
)
type Watcher interface {
diff --git a/server/plugin/infra/discovery/etcd/watcher_inner.go b/server/plugin/pkg/discovery/etcd/watcher_inner.go
similarity index 99%
rename from server/plugin/infra/discovery/etcd/watcher_inner.go
rename to server/plugin/pkg/discovery/etcd/watcher_inner.go
index 3fd598b..cb8dfbb 100644
--- a/server/plugin/infra/discovery/etcd/watcher_inner.go
+++ b/server/plugin/pkg/discovery/etcd/watcher_inner.go
@@ -19,7 +19,7 @@ package etcd
import (
"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/server/infra/registry"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/registry"
"golang.org/x/net/context"
"sync"
)
diff --git a/server/plugin/infra/discovery/etcd/watcher_test.go b/server/plugin/pkg/discovery/etcd/watcher_test.go
similarity index 99%
rename from server/plugin/infra/discovery/etcd/watcher_test.go
rename to server/plugin/pkg/discovery/etcd/watcher_test.go
index 6f91e7c..d0d71b7 100644
--- a/server/plugin/infra/discovery/etcd/watcher_test.go
+++ b/server/plugin/pkg/discovery/etcd/watcher_test.go
@@ -18,7 +18,7 @@ package etcd
import (
"fmt"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/registry"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/registry"
"golang.org/x/net/context"
"testing"
"time"
diff --git a/server/infra/discovery/event_proxy.go b/server/plugin/pkg/discovery/event_proxy.go
similarity index 100%
rename from server/infra/discovery/event_proxy.go
rename to server/plugin/pkg/discovery/event_proxy.go
diff --git a/server/infra/discovery/event_proxy_test.go b/server/plugin/pkg/discovery/event_proxy_test.go
similarity index 100%
rename from server/infra/discovery/event_proxy_test.go
rename to server/plugin/pkg/discovery/event_proxy_test.go
diff --git a/server/infra/discovery/extend.go b/server/plugin/pkg/discovery/extend.go
similarity index 100%
rename from server/infra/discovery/extend.go
rename to server/plugin/pkg/discovery/extend.go
diff --git a/server/infra/discovery/extend_test.go b/server/plugin/pkg/discovery/extend_test.go
similarity index 100%
rename from server/infra/discovery/extend_test.go
rename to server/plugin/pkg/discovery/extend_test.go
diff --git a/server/infra/discovery/indexer.go b/server/plugin/pkg/discovery/indexer.go
similarity index 98%
rename from server/infra/discovery/indexer.go
rename to server/plugin/pkg/discovery/indexer.go
index 394231c..e9854dc 100644
--- a/server/infra/discovery/indexer.go
+++ b/server/plugin/pkg/discovery/indexer.go
@@ -17,7 +17,7 @@
package discovery
import (
- "github.com/apache/incubator-servicecomb-service-center/server/infra/registry"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/registry"
"golang.org/x/net/context"
)
diff --git a/server/infra/discovery/indexer_cache.go b/server/plugin/pkg/discovery/indexer_cache.go
similarity index 99%
rename from server/infra/discovery/indexer_cache.go
rename to server/plugin/pkg/discovery/indexer_cache.go
index c3fe80b..f10b755 100644
--- a/server/infra/discovery/indexer_cache.go
+++ b/server/plugin/pkg/discovery/indexer_cache.go
@@ -19,7 +19,7 @@ package discovery
import (
"github.com/apache/incubator-servicecomb-service-center/pkg/log"
"github.com/apache/incubator-servicecomb-service-center/pkg/util"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/registry"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/registry"
"golang.org/x/net/context"
"sync"
"time"
diff --git a/server/infra/discovery/indexer_test.go b/server/plugin/pkg/discovery/indexer_test.go
similarity index 99%
rename from server/infra/discovery/indexer_test.go
rename to server/plugin/pkg/discovery/indexer_test.go
index 0ce69c3..746071b 100644
--- a/server/infra/discovery/indexer_test.go
+++ b/server/plugin/pkg/discovery/indexer_test.go
@@ -16,7 +16,7 @@
package discovery
import (
- "github.com/apache/incubator-servicecomb-service-center/server/infra/registry"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/registry"
"golang.org/x/net/context"
"testing"
)
diff --git a/server/plugin/infra/discovery/k8s/adaptor.go b/server/plugin/pkg/discovery/k8s/adaptor.go
similarity index 97%
copy from server/plugin/infra/discovery/k8s/adaptor.go
copy to server/plugin/pkg/discovery/k8s/adaptor.go
index 60b1598..4ea90f2 100644
--- a/server/plugin/infra/discovery/k8s/adaptor.go
+++ b/server/plugin/pkg/discovery/k8s/adaptor.go
@@ -16,7 +16,7 @@
package k8s
import (
- "github.com/apache/incubator-servicecomb-service-center/server/infra/discovery"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/discovery"
)
// K8sAdaptor is a discovery service adaptor implement of one kubernetes cluster
@@ -41,7 +41,7 @@ func (se *K8sAdaptor) Ready() <-chan struct{} {
if r, ok := se.Cacher.(discovery.Runnable); ok {
return r.Ready()
}
- return nil //closedCh
+ return closedCh
}
func NewK8sAdaptor(t discovery.Type, cfg *discovery.Config) *K8sAdaptor {
diff --git a/server/plugin/infra/discovery/k8s/repo.go b/server/plugin/pkg/discovery/k8s/cacher.go
similarity index 60%
copy from server/plugin/infra/discovery/k8s/repo.go
copy to server/plugin/pkg/discovery/k8s/cacher.go
index 7a93961..e92f5d6 100644
--- a/server/plugin/infra/discovery/k8s/repo.go
+++ b/server/plugin/pkg/discovery/k8s/cacher.go
@@ -16,29 +16,20 @@
package k8s
import (
- "github.com/apache/incubator-servicecomb-service-center/pkg/log"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/discovery"
- mgr "github.com/apache/incubator-servicecomb-service-center/server/plugin"
+ "github.com/apache/incubator-servicecomb-service-center/server/core/backend"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/discovery"
)
-func init() {
- mgr.RegisterPlugin(mgr.Plugin{mgr.DISCOVERY, "k8s", NewRepository})
-}
-
-type K8sRepository struct {
-}
-
-func (r *K8sRepository) New(t discovery.Type, cfg *discovery.Config) discovery.Adaptor {
- if cfg == nil {
- // do not new instance
- log.Warnf("type '%s' config is nil", t)
- return nil
+func BuildCacher(t discovery.Type, cfg *discovery.Config, cache discovery.Cache) discovery.Cacher {
+ kc := discovery.NewCommonCacher(cfg, cache)
+ switch t {
+ case backend.SERVICE:
+ return NewServiceCacher(kc)
+ case backend.SERVICE_INDEX:
+ return NewServiceIndexCacher(kc)
+ case backend.INSTANCE:
+ return NewInstanceCacher(kc)
+ default:
+ return kc
}
- e := NewK8sAdaptor(t, cfg)
- e.Run()
- return e
-}
-
-func NewRepository() mgr.PluginInstance {
- return &K8sRepository{}
}
diff --git a/server/plugin/infra/discovery/k8s/cacher_index.go b/server/plugin/pkg/discovery/k8s/cacher_index.go
similarity index 88%
rename from server/plugin/infra/discovery/k8s/cacher_index.go
rename to server/plugin/pkg/discovery/k8s/cacher_index.go
index 834d379..ac31669 100644
--- a/server/plugin/infra/discovery/k8s/cacher_index.go
+++ b/server/plugin/pkg/discovery/k8s/cacher_index.go
@@ -18,12 +18,13 @@ package k8s
import (
"github.com/apache/incubator-servicecomb-service-center/server/core"
pb "github.com/apache/incubator-servicecomb-service-center/server/core/proto"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/discovery"
"k8s.io/api/core/v1"
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
)
type ServiceIndexCacher struct {
- *K8sCacher
+ *discovery.CommonCacher
}
// onServiceEvent is the method to refresh service cache
@@ -50,8 +51,8 @@ func (c *ServiceIndexCacher) onServiceEvent(evt K8sEvent) {
}
}
-func NewServiceIndexCacher(c *K8sCacher) (si *ServiceIndexCacher) {
- si = &ServiceIndexCacher{K8sCacher: c}
+func NewServiceIndexCacher(c *discovery.CommonCacher) (si *ServiceIndexCacher) {
+ si = &ServiceIndexCacher{CommonCacher: c}
Kubernetes().AppendEventFunc(TypeService, si.onServiceEvent)
return
}
diff --git a/server/plugin/infra/discovery/k8s/cacher_instance.go b/server/plugin/pkg/discovery/k8s/cacher_instance.go
similarity index 96%
rename from server/plugin/infra/discovery/k8s/cacher_instance.go
rename to server/plugin/pkg/discovery/k8s/cacher_instance.go
index b9025f6..0179058 100644
--- a/server/plugin/infra/discovery/k8s/cacher_instance.go
+++ b/server/plugin/pkg/discovery/k8s/cacher_instance.go
@@ -19,7 +19,7 @@ import (
"github.com/apache/incubator-servicecomb-service-center/pkg/util"
"github.com/apache/incubator-servicecomb-service-center/server/core"
pb "github.com/apache/incubator-servicecomb-service-center/server/core/proto"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/discovery"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/discovery"
"k8s.io/api/core/v1"
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
"reflect"
@@ -27,7 +27,7 @@ import (
)
type InstanceCacher struct {
- *K8sCacher
+ *discovery.CommonCacher
}
// onServiceEvent is the method to refresh service cache
@@ -135,8 +135,8 @@ func (c *InstanceCacher) onEndpointsEvent(evt K8sEvent) {
}
}
-func NewInstanceCacher(c *K8sCacher) (i *InstanceCacher) {
- i = &InstanceCacher{K8sCacher: c}
+func NewInstanceCacher(c *discovery.CommonCacher) (i *InstanceCacher) {
+ i = &InstanceCacher{CommonCacher: c}
Kubernetes().AppendEventFunc(TypeService, i.onServiceEvent)
Kubernetes().AppendEventFunc(TypeEndpoint, i.onEndpointsEvent)
return
diff --git a/server/plugin/infra/discovery/k8s/cacher_service.go b/server/plugin/pkg/discovery/k8s/cacher_service.go
similarity index 89%
rename from server/plugin/infra/discovery/k8s/cacher_service.go
rename to server/plugin/pkg/discovery/k8s/cacher_service.go
index 113b3d1..3ec5bb5 100644
--- a/server/plugin/infra/discovery/k8s/cacher_service.go
+++ b/server/plugin/pkg/discovery/k8s/cacher_service.go
@@ -18,12 +18,13 @@ package k8s
import (
"github.com/apache/incubator-servicecomb-service-center/server/core"
pb "github.com/apache/incubator-servicecomb-service-center/server/core/proto"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/discovery"
"k8s.io/api/core/v1"
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
)
type ServiceCacher struct {
- *K8sCacher
+ *discovery.CommonCacher
}
// onServiceEvent is the method to refresh service cache
@@ -51,8 +52,8 @@ func (c *ServiceCacher) onServiceEvent(evt K8sEvent) {
}
}
-func NewServiceCacher(c *K8sCacher) (s *ServiceCacher) {
- s = &ServiceCacher{K8sCacher: c}
+func NewServiceCacher(c *discovery.CommonCacher) (s *ServiceCacher) {
+ s = &ServiceCacher{CommonCacher: c}
Kubernetes().AppendEventFunc(TypeService, s.onServiceEvent)
return
}
diff --git a/server/plugin/infra/discovery/k8s/common.go b/server/plugin/pkg/discovery/k8s/common.go
similarity index 100%
rename from server/plugin/infra/discovery/k8s/common.go
rename to server/plugin/pkg/discovery/k8s/common.go
diff --git a/server/plugin/infra/discovery/k8s/convertor.go b/server/plugin/pkg/discovery/k8s/convertor.go
similarity index 99%
rename from server/plugin/infra/discovery/k8s/convertor.go
rename to server/plugin/pkg/discovery/k8s/convertor.go
index e0b8629..bdff021 100644
--- a/server/plugin/infra/discovery/k8s/convertor.go
+++ b/server/plugin/pkg/discovery/k8s/convertor.go
@@ -18,7 +18,7 @@ package k8s
import (
"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/server/infra/discovery"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/discovery"
"k8s.io/api/core/v1"
"net/url"
"strconv"
diff --git a/server/plugin/infra/discovery/k8s/kube_client.go b/server/plugin/pkg/discovery/k8s/kube_client.go
similarity index 100%
rename from server/plugin/infra/discovery/k8s/kube_client.go
rename to server/plugin/pkg/discovery/k8s/kube_client.go
diff --git a/server/plugin/infra/discovery/k8s/listwatcher.go b/server/plugin/pkg/discovery/k8s/listwatcher.go
similarity index 100%
rename from server/plugin/infra/discovery/k8s/listwatcher.go
rename to server/plugin/pkg/discovery/k8s/listwatcher.go
diff --git a/server/plugin/infra/discovery/k8s/repo.go b/server/plugin/pkg/discovery/k8s/repo.go
similarity index 84%
copy from server/plugin/infra/discovery/k8s/repo.go
copy to server/plugin/pkg/discovery/k8s/repo.go
index 7a93961..ccdb240 100644
--- a/server/plugin/infra/discovery/k8s/repo.go
+++ b/server/plugin/pkg/discovery/k8s/repo.go
@@ -16,9 +16,8 @@
package k8s
import (
- "github.com/apache/incubator-servicecomb-service-center/pkg/log"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/discovery"
mgr "github.com/apache/incubator-servicecomb-service-center/server/plugin"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/discovery"
)
func init() {
@@ -29,14 +28,7 @@ type K8sRepository struct {
}
func (r *K8sRepository) New(t discovery.Type, cfg *discovery.Config) discovery.Adaptor {
- if cfg == nil {
- // do not new instance
- log.Warnf("type '%s' config is nil", t)
- return nil
- }
- e := NewK8sAdaptor(t, cfg)
- e.Run()
- return e
+ return NewK8sAdaptor(t, cfg)
}
func NewRepository() mgr.PluginInstance {
diff --git a/server/plugin/infra/discovery/k8s/adaptor.go b/server/plugin/pkg/discovery/sc/adaptor.go
similarity index 66%
rename from server/plugin/infra/discovery/k8s/adaptor.go
rename to server/plugin/pkg/discovery/sc/adaptor.go
index 60b1598..0b12378 100644
--- a/server/plugin/infra/discovery/k8s/adaptor.go
+++ b/server/plugin/pkg/discovery/sc/adaptor.go
@@ -13,40 +13,47 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package k8s
+package sc
import (
- "github.com/apache/incubator-servicecomb-service-center/server/infra/discovery"
+ "github.com/apache/incubator-servicecomb-service-center/server/core/backend"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/discovery"
)
-// K8sAdaptor is a discovery service adaptor implement of one kubernetes cluster
-type K8sAdaptor struct {
+// ServiceCenterAdaptor is a discovery service adaptor implement of one kubernetes cluster
+type ServiceCenterAdaptor struct {
discovery.Cacher
discovery.Indexer
}
-func (se *K8sAdaptor) Run() {
+func (se *ServiceCenterAdaptor) Run() {
if r, ok := se.Cacher.(discovery.Runnable); ok {
r.Run()
}
}
-func (se *K8sAdaptor) Stop() {
+func (se *ServiceCenterAdaptor) Stop() {
if r, ok := se.Cacher.(discovery.Runnable); ok {
r.Stop()
}
}
-func (se *K8sAdaptor) Ready() <-chan struct{} {
+func (se *ServiceCenterAdaptor) Ready() <-chan struct{} {
if r, ok := se.Cacher.(discovery.Runnable); ok {
return r.Ready()
}
- return nil //closedCh
+ return closedCh
}
-func NewK8sAdaptor(t discovery.Type, cfg *discovery.Config) *K8sAdaptor {
+func NewServiceCenterAdaptor(t discovery.Type, cfg *discovery.Config) *ServiceCenterAdaptor {
+ if t == backend.SCHEMA {
+ return &ServiceCenterAdaptor{
+ Indexer: ServiceCenter(),
+ Cacher: discovery.NullCacher,
+ }
+ }
cache := discovery.NewKvCache(t.String(), cfg)
- return &K8sAdaptor{
+ return &ServiceCenterAdaptor{
Indexer: discovery.NewCacheIndexer(cache),
Cacher: BuildCacher(t, cfg, cache),
}
diff --git a/server/plugin/pkg/discovery/sc/aggregate.go b/server/plugin/pkg/discovery/sc/aggregate.go
new file mode 100644
index 0000000..77dce38
--- /dev/null
+++ b/server/plugin/pkg/discovery/sc/aggregate.go
@@ -0,0 +1,96 @@
+// 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 sc
+
+import (
+ "github.com/apache/incubator-servicecomb-service-center/pkg/client/sc"
+ "github.com/apache/incubator-servicecomb-service-center/pkg/log"
+ "github.com/apache/incubator-servicecomb-service-center/server/admin/model"
+ pb "github.com/apache/incubator-servicecomb-service-center/server/core/proto"
+ scerr "github.com/apache/incubator-servicecomb-service-center/server/error"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/registry"
+)
+
+type SCClientAggregate []*sc.SCClient
+
+func (c *SCClientAggregate) GetScCache() (*model.Cache, error) {
+ var caches model.Cache
+ for _, client := range *c {
+ cache, err := client.GetScCache()
+ if err != nil {
+ log.Errorf(err, "get service center[%s] cache failed", client.Config.Addr)
+ continue
+ }
+ caches.Microservices = append(caches.Microservices, cache.Microservices...)
+ caches.Indexes = append(caches.Indexes, cache.Indexes...)
+ caches.Aliases = append(caches.Aliases, cache.Aliases...)
+ caches.Tags = append(caches.Tags, cache.Tags...)
+ caches.Rules = append(caches.Rules, cache.Rules...)
+ caches.RuleIndexes = append(caches.RuleIndexes, cache.RuleIndexes...)
+ caches.DependencyRules = append(caches.DependencyRules, cache.DependencyRules...)
+ caches.Summaries = append(caches.Summaries, cache.Summaries...)
+ caches.Instances = append(caches.Instances, cache.Instances...)
+ }
+ return &caches, nil
+}
+
+func (c *SCClientAggregate) GetSchemasByServiceId(domainProject, serviceId string) ([]*pb.Schema, *scerr.Error) {
+ var schemas []*pb.Schema
+ for _, client := range *c {
+ ss, err := client.GetSchemasByServiceId(domainProject, serviceId)
+ if err != nil {
+ log.Errorf(err, "get schema by serviceId[%s/%s] failed", domainProject, serviceId)
+ continue
+ }
+ schemas = append(schemas, ss...)
+ }
+
+ return schemas, nil
+}
+
+func (c *SCClientAggregate) GetSchemaBySchemaId(domainProject, serviceId, schemaId string) (schema *pb.Schema, err *scerr.Error) {
+ for _, client := range *c {
+ schema, err = client.GetSchemaBySchemaId(domainProject, serviceId, schemaId)
+ if err != nil {
+ log.Errorf(err, "get schema by serviceId[%s/%s] failed", domainProject, serviceId)
+ continue
+ }
+ if schema != nil {
+ return
+ }
+ }
+
+ return
+}
+
+func NewSCClientAggregate() *SCClientAggregate {
+ c := &SCClientAggregate{}
+ clusters := registry.Configuration().Clusters()
+ for name, addr := range clusters {
+ if len(name) == 0 || name == registry.Configuration().ClusterName {
+ continue
+ }
+ client, err := sc.NewSCClient(sc.Config{Addr: addr})
+ if err != nil {
+ log.Errorf(err, "new service center[%s][%s] client failed", name, addr)
+ continue
+ }
+ client.Timeout = registry.Configuration().RequestTimeOut
+ *c = append(*c, client)
+ log.Infof("new service center[%s][%s] client", name, addr)
+ }
+ return c
+}
diff --git a/server/plugin/infra/discovery/k8s/repo.go b/server/plugin/pkg/discovery/sc/cacher.go
similarity index 60%
copy from server/plugin/infra/discovery/k8s/repo.go
copy to server/plugin/pkg/discovery/sc/cacher.go
index 7a93961..01f0861 100644
--- a/server/plugin/infra/discovery/k8s/repo.go
+++ b/server/plugin/pkg/discovery/sc/cacher.go
@@ -13,32 +13,28 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package k8s
+package sc
import (
- "github.com/apache/incubator-servicecomb-service-center/pkg/log"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/discovery"
- mgr "github.com/apache/incubator-servicecomb-service-center/server/plugin"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/discovery"
)
-func init() {
- mgr.RegisterPlugin(mgr.Plugin{mgr.DISCOVERY, "k8s", NewRepository})
+type ServiceCenterCacher struct {
+ *discovery.CommonCacher
}
-type K8sRepository struct {
+func (c *ServiceCenterCacher) Ready() <-chan struct{} {
+ return ServiceCenter().Ready()
}
-func (r *K8sRepository) New(t discovery.Type, cfg *discovery.Config) discovery.Adaptor {
- if cfg == nil {
- // do not new instance
- log.Warnf("type '%s' config is nil", t)
- return nil
+func NewServiceCenterCacher(cfg *discovery.Config, cache discovery.Cache) *ServiceCenterCacher {
+ return &ServiceCenterCacher{
+ CommonCacher: discovery.NewCommonCacher(cfg, cache),
}
- e := NewK8sAdaptor(t, cfg)
- e.Run()
- return e
}
-func NewRepository() mgr.PluginInstance {
- return &K8sRepository{}
+func BuildCacher(t discovery.Type, cfg *discovery.Config, cache discovery.Cache) discovery.Cacher {
+ cr := NewServiceCenterCacher(cfg, cache)
+ ServiceCenter().AddCacher(t, cr)
+ return cr
}
diff --git a/server/plugin/pkg/discovery/sc/cluster.go b/server/plugin/pkg/discovery/sc/cluster.go
new file mode 100644
index 0000000..a07a241
--- /dev/null
+++ b/server/plugin/pkg/discovery/sc/cluster.go
@@ -0,0 +1,212 @@
+// 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 sc
+
+import (
+ "fmt"
+ "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/util"
+ "github.com/apache/incubator-servicecomb-service-center/server/admin/model"
+ "github.com/apache/incubator-servicecomb-service-center/server/core"
+ "github.com/apache/incubator-servicecomb-service-center/server/core/backend"
+ pb "github.com/apache/incubator-servicecomb-service-center/server/core/proto"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/discovery"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/registry"
+ "golang.org/x/net/context"
+ "strings"
+ "sync"
+ "time"
+)
+
+var (
+ cluster *ServiceCenterCluster
+ clusterOnce sync.Once
+)
+
+type ServiceCenterCluster struct {
+ Client *SCClientAggregate
+
+ cachers map[discovery.Type]*ServiceCenterCacher
+}
+
+func (c *ServiceCenterCluster) Initialize() {
+ c.cachers = make(map[discovery.Type]*ServiceCenterCacher)
+ c.Client = NewSCClientAggregate()
+}
+
+func (c *ServiceCenterCluster) Search(ctx context.Context, opts ...registry.PluginOpOption) (r *discovery.Response, err error) {
+ op := registry.OpGet(opts...)
+ key := util.BytesToStringWithNoCopy(op.Key)
+ switch {
+ case strings.Index(key, core.GetServiceSchemaRootKey("")) == 0:
+ domainProject, serviceId, schemaId := core.GetInfoFromSchemaKV(op.Key)
+ var schemas []*pb.Schema
+ if op.Prefix && len(schemaId) == 0 {
+ schemas, err = c.Client.GetSchemasByServiceId(domainProject, serviceId)
+ if err != nil {
+ return nil, err
+ }
+ } else {
+ schema, err := c.Client.GetSchemaBySchemaId(domainProject, serviceId, schemaId)
+ if err != nil {
+ return nil, err
+ }
+ schemas = append(schemas, schema)
+ }
+ var response discovery.Response
+ response.Count = int64(len(schemas))
+ if op.CountOnly {
+ return &response, nil
+ }
+ for _, schema := range schemas {
+ response.Kvs = append(response.Kvs, &discovery.KeyValue{
+ Key: util.StringToBytesWithNoCopy(
+ core.GenerateServiceSchemaKey(domainProject, serviceId, schema.SchemaId)),
+ Value: util.StringToBytesWithNoCopy(schema.Schema),
+ })
+ }
+ return &response, nil
+ default:
+ return nil, fmt.Errorf("no implement")
+ }
+}
+
+func (c *ServiceCenterCluster) Sync(ctx context.Context) error {
+ cache, err := c.Client.GetScCache()
+ if err != nil {
+ log.Errorf(err, "sync failed")
+ return err
+ }
+
+ // microservice
+ // TODO remove duplicate SERVICECENTER
+ serviceCacher, ok := c.cachers[backend.SERVICE]
+ if ok {
+ c.check(serviceCacher, &cache.Microservices)
+ }
+ aliasCacher, ok := c.cachers[backend.SERVICE_ALIAS]
+ if ok {
+ c.check(aliasCacher, &cache.Aliases)
+ }
+ indexCacher, ok := c.cachers[backend.SERVICE_INDEX]
+ if ok {
+ c.check(indexCacher, &cache.Indexes)
+ }
+ // instance
+ instCacher, ok := c.cachers[backend.INSTANCE]
+ if ok {
+ c.check(instCacher, &cache.Instances)
+ }
+ // microservice meta
+ tagCacher, ok := c.cachers[backend.SERVICE_TAG]
+ if ok {
+ c.check(tagCacher, &cache.Tags)
+ }
+ ruleCacher, ok := c.cachers[backend.RULE]
+ if ok {
+ c.check(ruleCacher, &cache.Rules)
+ }
+ ruleIndexCacher, ok := c.cachers[backend.RULE_INDEX]
+ if ok {
+ c.check(ruleIndexCacher, &cache.RuleIndexes)
+ }
+ depRuleCacher, ok := c.cachers[backend.DEPENDENCY_RULE]
+ if ok {
+ c.check(depRuleCacher, &cache.DependencyRules)
+ }
+ return nil
+}
+
+func (c *ServiceCenterCluster) check(local *ServiceCenterCacher, remote model.Getter) {
+ remote.ForEach(func(_ int, v *model.KV) bool {
+ kv := local.Cache().Get(v.Key)
+ newKv := &discovery.KeyValue{
+ Key: util.StringToBytesWithNoCopy(v.Key),
+ Value: v.Value,
+ Version: v.Rev,
+ CreateRevision: v.Rev,
+ ModRevision: v.Rev,
+ }
+ switch {
+ case kv == nil:
+ local.Notify(pb.EVT_CREATE, v.Key, newKv)
+ case kv.ModRevision != v.Rev:
+ local.Notify(pb.EVT_UPDATE, v.Key, newKv)
+ }
+ return true
+ })
+
+ var deletes []*discovery.KeyValue
+ local.Cache().ForEach(func(key string, v *discovery.KeyValue) (next bool) {
+ var exist bool
+ remote.ForEach(func(_ int, v *model.KV) bool {
+ exist = v.Key == key
+ return !exist
+ })
+ if !exist {
+ deletes = append(deletes, v)
+ }
+ return true
+ })
+ for _, v := range deletes {
+ local.Notify(pb.EVT_DELETE, util.BytesToStringWithNoCopy(v.Key), v)
+ }
+}
+
+func (c *ServiceCenterCluster) loop(ctx context.Context) {
+ select {
+ case <-ctx.Done():
+ case <-time.After(minWaitInterval):
+ c.Sync(ctx)
+ loop:
+ for {
+ select {
+ case <-ctx.Done():
+ break loop
+ case <-time.After(registry.Configuration().AutoSyncInterval):
+ // TODO support watching sc
+ c.Sync(ctx)
+ }
+ }
+ }
+
+ log.Debug("service center client is stopped")
+}
+
+// unsafe
+func (c *ServiceCenterCluster) AddCacher(t discovery.Type, cacher *ServiceCenterCacher) {
+ c.cachers[t] = cacher
+}
+
+func (c *ServiceCenterCluster) Run() {
+ c.Initialize()
+ gopool.Go(c.loop)
+}
+
+func (c *ServiceCenterCluster) Stop() {}
+
+func (c *ServiceCenterCluster) Ready() <-chan struct{} {
+ return closedCh
+}
+
+func ServiceCenter() *ServiceCenterCluster {
+ clusterOnce.Do(func() {
+ cluster = &ServiceCenterCluster{}
+ cluster.Run()
+ })
+ return cluster
+}
diff --git a/server/infra/discovery/types_test.go b/server/plugin/pkg/discovery/sc/common.go
similarity index 67%
copy from server/infra/discovery/types_test.go
copy to server/plugin/pkg/discovery/sc/common.go
index 5d54c5b..d6227fd 100644
--- a/server/infra/discovery/types_test.go
+++ b/server/plugin/pkg/discovery/sc/common.go
@@ -13,25 +13,18 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package discovery
+package sc
-import "testing"
+import "time"
-func TestTypes(t *testing.T) {
- id, _ := Install(NewAddOn("TestTypes", Configure()))
- found := false
- for _, t := range Types() {
- if t == id {
- found = true
- }
- }
- if !found {
- t.Fatalf("TestTypes failed")
- }
- if id.String() != "TestTypes" {
- t.Fatalf("TestTypes failed")
- }
- if TypeError.String() != "TypeError" {
- t.Fatalf("TestTypes failed")
- }
+const (
+ minWaitInterval = 5 * time.Second
+)
+
+var (
+ closedCh = make(chan struct{})
+)
+
+func init() {
+ close(closedCh)
}
diff --git a/server/plugin/infra/discovery/k8s/repo.go b/server/plugin/pkg/discovery/sc/repo.go
similarity index 69%
copy from server/plugin/infra/discovery/k8s/repo.go
copy to server/plugin/pkg/discovery/sc/repo.go
index 7a93961..cedc6f6 100644
--- a/server/plugin/infra/discovery/k8s/repo.go
+++ b/server/plugin/pkg/discovery/sc/repo.go
@@ -13,32 +13,24 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package k8s
+package sc
import (
- "github.com/apache/incubator-servicecomb-service-center/pkg/log"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/discovery"
mgr "github.com/apache/incubator-servicecomb-service-center/server/plugin"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/discovery"
)
func init() {
- mgr.RegisterPlugin(mgr.Plugin{mgr.DISCOVERY, "k8s", NewRepository})
+ mgr.RegisterPlugin(mgr.Plugin{mgr.DISCOVERY, "servicecenter", NewRepository})
}
-type K8sRepository struct {
+type ServiceCenterRepository struct {
}
-func (r *K8sRepository) New(t discovery.Type, cfg *discovery.Config) discovery.Adaptor {
- if cfg == nil {
- // do not new instance
- log.Warnf("type '%s' config is nil", t)
- return nil
- }
- e := NewK8sAdaptor(t, cfg)
- e.Run()
- return e
+func (r *ServiceCenterRepository) New(t discovery.Type, cfg *discovery.Config) discovery.Adaptor {
+ return NewServiceCenterAdaptor(t, cfg)
}
func NewRepository() mgr.PluginInstance {
- return &K8sRepository{}
+ return &ServiceCenterRepository{}
}
diff --git a/server/infra/discovery/service.go b/server/plugin/pkg/discovery/service.go
similarity index 100%
rename from server/infra/discovery/service.go
rename to server/plugin/pkg/discovery/service.go
diff --git a/server/infra/discovery/types.go b/server/plugin/pkg/discovery/types.go
similarity index 100%
rename from server/infra/discovery/types.go
rename to server/plugin/pkg/discovery/types.go
diff --git a/server/infra/discovery/types_test.go b/server/plugin/pkg/discovery/types_test.go
similarity index 100%
rename from server/infra/discovery/types_test.go
rename to server/plugin/pkg/discovery/types_test.go
diff --git a/server/plugin/infra/quota/buildin/buildin.go b/server/plugin/pkg/quota/buildin/buildin.go
similarity index 99%
rename from server/plugin/infra/quota/buildin/buildin.go
rename to server/plugin/pkg/quota/buildin/buildin.go
index cac1e9f..329a8bc 100644
--- a/server/plugin/infra/quota/buildin/buildin.go
+++ b/server/plugin/pkg/quota/buildin/buildin.go
@@ -18,8 +18,8 @@ package buildin
import (
"github.com/apache/incubator-servicecomb-service-center/pkg/log"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/quota"
mgr "github.com/apache/incubator-servicecomb-service-center/server/plugin"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/quota"
"golang.org/x/net/context"
)
diff --git a/server/plugin/infra/quota/buildin/common.go b/server/plugin/pkg/quota/buildin/common.go
similarity index 98%
rename from server/plugin/infra/quota/buildin/common.go
rename to server/plugin/pkg/quota/buildin/common.go
index 263d482..eaa6add 100644
--- a/server/plugin/infra/quota/buildin/common.go
+++ b/server/plugin/pkg/quota/buildin/common.go
@@ -23,10 +23,10 @@ import (
"github.com/apache/incubator-servicecomb-service-center/server/core"
"github.com/apache/incubator-servicecomb-service-center/server/core/backend"
scerr "github.com/apache/incubator-servicecomb-service-center/server/error"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/discovery"
- "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"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/discovery"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/quota"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/registry"
serviceUtil "github.com/apache/incubator-servicecomb-service-center/server/service/util"
"golang.org/x/net/context"
)
diff --git a/server/plugin/infra/quota/buildin/common_test.go b/server/plugin/pkg/quota/buildin/common_test.go
similarity index 99%
rename from server/plugin/infra/quota/buildin/common_test.go
rename to server/plugin/pkg/quota/buildin/common_test.go
index a3c13a7..8fbcc2f 100644
--- a/server/plugin/infra/quota/buildin/common_test.go
+++ b/server/plugin/pkg/quota/buildin/common_test.go
@@ -17,7 +17,7 @@ package buildin
import (
"errors"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/quota"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/quota"
"golang.org/x/net/context"
"testing"
)
diff --git a/server/infra/quota/quota.go b/server/plugin/pkg/quota/quota.go
similarity index 100%
rename from server/infra/quota/quota.go
rename to server/plugin/pkg/quota/quota.go
diff --git a/server/plugin/infra/quota/unlimit/unlimit.go b/server/plugin/pkg/quota/unlimit/unlimit.go
similarity index 99%
rename from server/plugin/infra/quota/unlimit/unlimit.go
rename to server/plugin/pkg/quota/unlimit/unlimit.go
index 7658284..e4e87eb 100644
--- a/server/plugin/infra/quota/unlimit/unlimit.go
+++ b/server/plugin/pkg/quota/unlimit/unlimit.go
@@ -18,8 +18,8 @@ package unlimit
import (
"github.com/apache/incubator-servicecomb-service-center/pkg/log"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/quota"
mgr "github.com/apache/incubator-servicecomb-service-center/server/plugin"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/quota"
"github.com/astaxie/beego"
"golang.org/x/net/context"
)
diff --git a/server/plugin/infra/registry/buildin/buildin.go b/server/plugin/pkg/registry/buildin/buildin.go
similarity index 99%
rename from server/plugin/infra/registry/buildin/buildin.go
rename to server/plugin/pkg/registry/buildin/buildin.go
index c233b0b..b6ee6b6 100644
--- a/server/plugin/infra/registry/buildin/buildin.go
+++ b/server/plugin/pkg/registry/buildin/buildin.go
@@ -17,8 +17,8 @@
package buildin
import (
- "github.com/apache/incubator-servicecomb-service-center/server/infra/registry"
mgr "github.com/apache/incubator-servicecomb-service-center/server/plugin"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/registry"
"golang.org/x/net/context"
)
diff --git a/server/plugin/infra/discovery/k8s/repo.go b/server/plugin/pkg/registry/common.go
similarity index 51%
copy from server/plugin/infra/discovery/k8s/repo.go
copy to server/plugin/pkg/registry/common.go
index 7a93961..fd7efb9 100644
--- a/server/plugin/infra/discovery/k8s/repo.go
+++ b/server/plugin/pkg/registry/common.go
@@ -13,32 +13,53 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package k8s
+package registry
import (
- "github.com/apache/incubator-servicecomb-service-center/pkg/log"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/discovery"
- mgr "github.com/apache/incubator-servicecomb-service-center/server/plugin"
+ "golang.org/x/net/context"
+ "time"
)
-func init() {
- mgr.RegisterPlugin(mgr.Plugin{mgr.DISCOVERY, "k8s", NewRepository})
-}
+const (
+ Get ActionType = iota
+ Put
+ Delete
+)
-type K8sRepository struct {
-}
+const (
+ SORT_NONE SortOrder = iota
+ SORT_ASCEND
+ SORT_DESCEND
+)
-func (r *K8sRepository) New(t discovery.Type, cfg *discovery.Config) discovery.Adaptor {
- if cfg == nil {
- // do not new instance
- log.Warnf("type '%s' config is nil", t)
- return nil
- }
- e := NewK8sAdaptor(t, cfg)
- e.Run()
- return e
-}
+const (
+ CMP_VERSION CompareType = iota
+ CMP_CREATE
+ CMP_MOD
+ CMP_VALUE
+)
+
+const (
+ CMP_EQUAL CompareResult = iota
+ CMP_GREATER
+ CMP_LESS
+ CMP_NOT_EQUAL
+)
+
+const (
+ MODE_BOTH CacheMode = iota
+ MODE_CACHE
+ MODE_NO_CACHE
+)
+
+const (
+ // grpc does not allow to transport a large body more then 4MB in a request
+ DEFAULT_PAGE_COUNT = 4096
+ // the timeout dial to etcd
+ defaultDialTimeout = 10 * time.Second
+ defaultRequestTimeout = 30 * time.Second
+)
-func NewRepository() mgr.PluginInstance {
- return &K8sRepository{}
+func WithTimeout(ctx context.Context) (context.Context, context.CancelFunc) {
+ return context.WithTimeout(ctx, defaultRegistryConfig.RequestTimeOut)
}
diff --git a/server/plugin/pkg/registry/config.go b/server/plugin/pkg/registry/config.go
new file mode 100644
index 0000000..5f404cf
--- /dev/null
+++ b/server/plugin/pkg/registry/config.go
@@ -0,0 +1,89 @@
+// 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 registry
+
+import (
+ "github.com/apache/incubator-servicecomb-service-center/pkg/log"
+ "github.com/apache/incubator-servicecomb-service-center/server/core"
+ "github.com/astaxie/beego"
+ "strings"
+ "sync"
+ "time"
+)
+
+var (
+ defaultRegistryConfig Config
+ configOnce sync.Once
+)
+
+type Config struct {
+ SslEnabled bool
+ EmbedMode string
+ ManagerAddress string
+ ClusterName string
+ ClusterAddresses string
+ DialTimeout time.Duration
+ RequestTimeOut time.Duration
+ AutoSyncInterval time.Duration
+}
+
+func (c *Config) Clusters() map[string]string {
+ clusters := make(map[string]string)
+ kvs := strings.Split(c.ClusterAddresses, ",")
+ for _, cluster := range kvs {
+ // sc-0=http(s)://host:port
+ names := strings.Split(cluster, "=")
+ if len(names) != 2 {
+ continue
+ }
+ clusters[names[0]] = names[1]
+ }
+ if len(clusters) == 0 {
+ clusters[c.ClusterName] = c.ClusterAddresses
+ }
+ return clusters
+}
+
+func (c *Config) ClusterAddress() string {
+ return c.Clusters()[c.ClusterName]
+}
+
+func Configuration() *Config {
+ configOnce.Do(func() {
+ var err error
+
+ defaultRegistryConfig.ClusterName = beego.AppConfig.String("manager_name")
+ 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"))
+ if err != nil {
+ log.Errorf(err, "connect_timeout is invalid, use default time %s", defaultDialTimeout)
+ defaultRegistryConfig.DialTimeout = defaultDialTimeout
+ }
+ defaultRegistryConfig.RequestTimeOut, err = time.ParseDuration(beego.AppConfig.DefaultString("registry_timeout", "30s"))
+ if err != nil {
+ log.Errorf(err, "registry_timeout is invalid, use default time %s", defaultRequestTimeout)
+ defaultRegistryConfig.RequestTimeOut = defaultRequestTimeout
+ }
+ defaultRegistryConfig.SslEnabled = core.ServerInfo.Config.SslEnabled &&
+ strings.Index(strings.ToLower(defaultRegistryConfig.ClusterAddresses), "https://") >= 0
+ defaultRegistryConfig.AutoSyncInterval, err = time.ParseDuration(core.ServerInfo.Config.AutoSyncInterval)
+ if err != nil {
+ log.Errorf(err, "auto_sync_interval is invalid")
+ }
+ })
+ return &defaultRegistryConfig
+}
diff --git a/server/plugin/infra/registry/embededetcd/embededetcd.go b/server/plugin/pkg/registry/embededetcd/embededetcd.go
similarity index 96%
rename from server/plugin/infra/registry/embededetcd/embededetcd.go
rename to server/plugin/pkg/registry/embededetcd/embededetcd.go
index c0f1949..b31689f 100644
--- a/server/plugin/infra/registry/embededetcd/embededetcd.go
+++ b/server/plugin/pkg/registry/embededetcd/embededetcd.go
@@ -24,9 +24,8 @@ import (
"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/util"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/registry"
mgr "github.com/apache/incubator-servicecomb-service-center/server/plugin"
- "github.com/astaxie/beego"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/registry"
"github.com/coreos/etcd/embed"
"github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes"
"github.com/coreos/etcd/etcdserver/etcdserverpb"
@@ -442,7 +441,7 @@ func (s *EtcdEmbed) Watch(ctx context.Context, opts ...registry.PluginOpOption)
}
func (s *EtcdEmbed) readyNotify() {
- timeout := registry.RegistryConfig().DialTimeout
+ timeout := registry.Configuration().DialTimeout
select {
case <-s.Embed.Server.ReadyNotify():
close(s.ready)
@@ -522,10 +521,16 @@ func callback(action registry.ActionType, rev int64, kvs []*mvccpb.KeyValue, cb
}
func getEmbedInstance() mgr.PluginInstance {
- log.Warnf("starting service center in embed mode")
+ log.Warnf("enable embedded registry mode")
- hostName := beego.AppConfig.DefaultString("manager_name", "sc-0")
- mgrAddrs := beego.AppConfig.DefaultString("manager_addr", "http://127.0.0.1:2380")
+ hostName := "sc-0"
+ if len(registry.Configuration().ClusterName) > 0 {
+ hostName = registry.Configuration().ClusterName
+ }
+ mgrAddrs := "http://127.0.0.1:2380"
+ if len(registry.Configuration().ManagerAddress) > 0 {
+ mgrAddrs = registry.Configuration().ManagerAddress
+ }
inst := &EtcdEmbed{
err: make(chan error, 1),
@@ -533,7 +538,7 @@ func getEmbedInstance() mgr.PluginInstance {
goroutine: gopool.New(context.Background()),
}
- if registry.RegistryConfig().SslEnabled {
+ if registry.Configuration().SslEnabled {
var err error
embedTLSConfig, err = mgr.Plugins().TLS().ServerConfig()
if err != nil {
@@ -550,7 +555,7 @@ func getEmbedInstance() mgr.PluginInstance {
// 集群支持
serverCfg.Name = hostName
- serverCfg.InitialCluster = registry.RegistryConfig().ClusterAddresses
+ serverCfg.InitialCluster = registry.Configuration().ClusterAddresses
// 1. 管理端口
urls, err := parseURL(mgrAddrs)
diff --git a/server/plugin/infra/registry/etcd/etcd.go b/server/plugin/pkg/registry/etcd/etcd.go
similarity index 98%
rename from server/plugin/infra/registry/etcd/etcd.go
rename to server/plugin/pkg/registry/etcd/etcd.go
index dbbfa12..b94fa00 100644
--- a/server/plugin/infra/registry/etcd/etcd.go
+++ b/server/plugin/pkg/registry/etcd/etcd.go
@@ -24,8 +24,8 @@ import (
"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/util"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/registry"
mgr "github.com/apache/incubator-servicecomb-service-center/server/plugin"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/registry"
"github.com/coreos/etcd/clientv3"
"github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes"
"github.com/coreos/etcd/etcdserver/etcdserverpb"
@@ -74,7 +74,7 @@ func (c *EtcdClient) Initialize() (err error) {
// parse the endpoints from config
c.parseEndpoints()
}
- if c.TLSConfig == nil && registry.RegistryConfig().SslEnabled {
+ if c.TLSConfig == nil && registry.Configuration().SslEnabled {
var err error
// go client tls限制,提供身份证书、不认证服务端、不校验CN
c.TLSConfig, err = mgr.Plugins().TLS().ClientConfig()
@@ -84,10 +84,10 @@ func (c *EtcdClient) Initialize() (err error) {
}
}
if c.DialTimeout == 0 {
- c.DialTimeout = registry.RegistryConfig().DialTimeout
+ c.DialTimeout = registry.Configuration().DialTimeout
}
if c.AutoSyncInterval == 0 {
- c.AutoSyncInterval = registry.RegistryConfig().AutoSyncInterval
+ c.AutoSyncInterval = registry.Configuration().AutoSyncInterval
}
c.Client, err = c.newClient()
@@ -747,7 +747,7 @@ func (c *EtcdClient) ReOpen() error {
func (c *EtcdClient) parseEndpoints() {
// use the default cluster endpoints
- addrs := strings.Split(registry.RegistryConfig().ClusterAddresses, ",")
+ addrs := strings.Split(registry.Configuration().ClusterAddress(), ",")
endpoints := make([]string, 0, len(addrs))
for _, addr := range addrs {
@@ -827,7 +827,7 @@ func callback(action registry.ActionType, rev int64, kvs []*mvccpb.KeyValue, cb
}
func NewRegistry() mgr.PluginInstance {
- log.Warnf("starting service center in proxy mode")
+ log.Warnf("enable etcd registry mode")
inst := &EtcdClient{}
if err := inst.Initialize(); err != nil {
diff --git a/server/plugin/infra/registry/etcd/etcd_test.go b/server/plugin/pkg/registry/etcd/etcd_test.go
similarity index 97%
rename from server/plugin/infra/registry/etcd/etcd_test.go
rename to server/plugin/pkg/registry/etcd/etcd_test.go
index 40a8e0d..7f1a50b 100644
--- a/server/plugin/infra/registry/etcd/etcd_test.go
+++ b/server/plugin/pkg/registry/etcd/etcd_test.go
@@ -16,13 +16,13 @@
*/
package etcd
-import _ "github.com/apache/incubator-servicecomb-service-center/server/plugin/infra/tracing/buildin"
-import _ "github.com/apache/incubator-servicecomb-service-center/server/plugin/infra/security/buildin"
-import _ "github.com/apache/incubator-servicecomb-service-center/server/plugin/infra/tls/buildin"
+import _ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/tracing/buildin"
+import _ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/security/buildin"
+import _ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/tls/buildin"
import (
"fmt"
"github.com/apache/incubator-servicecomb-service-center/server/core"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/registry"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/registry"
"github.com/apache/incubator-servicecomb-service-center/server/rpc"
"golang.org/x/net/context"
"google.golang.org/grpc/status"
@@ -39,7 +39,7 @@ const (
)
var (
- endpoint = registry.RegistryConfig().ClusterAddresses
+ endpoint = registry.Configuration().ClusterAddresses
)
func TestEtcdClient(t *testing.T) {
@@ -64,10 +64,10 @@ func TestEtcdClient(t *testing.T) {
if inst == nil || firstEndpoint != endpoint {
t.Fatalf("TestEtcdClient failed, %s != %s", firstEndpoint, endpoint)
}
- old1 := registry.RegistryConfig().ClusterAddresses
- old2 := registry.RegistryConfig().DialTimeout
- registry.RegistryConfig().ClusterAddresses = "x"
- registry.RegistryConfig().DialTimeout = dialTimeout
+ old1 := registry.Configuration().ClusterAddresses
+ old2 := registry.Configuration().DialTimeout
+ registry.Configuration().ClusterAddresses = "x"
+ registry.Configuration().DialTimeout = dialTimeout
inst = NewRegistry()
if inst == nil {
t.Fatalf("TestEtcdClient failed, %#v", err)
@@ -77,8 +77,8 @@ func TestEtcdClient(t *testing.T) {
default:
t.Fatalf("TestEtcdClient failed, %#v", err)
}
- registry.RegistryConfig().ClusterAddresses = old1
- registry.RegistryConfig().DialTimeout = old2
+ registry.Configuration().ClusterAddresses = old1
+ registry.Configuration().DialTimeout = old2
// case: etcd do
// put
@@ -709,10 +709,10 @@ func TestWithTLS(t *testing.T) {
os.Setenv("SSL_ROOT", sslRoot)
core.ServerInfo.Config.SslEnabled = true
- registry.RegistryConfig().SslEnabled = true
+ registry.Configuration().SslEnabled = true
defer func() {
core.ServerInfo.Config.SslEnabled = false
- registry.RegistryConfig().SslEnabled = false
+ registry.Configuration().SslEnabled = false
os.Setenv("SSL_ROOT", "")
}()
diff --git a/server/plugin/infra/registry/etcd/logger.go b/server/plugin/pkg/registry/etcd/logger.go
similarity index 100%
rename from server/plugin/infra/registry/etcd/logger.go
rename to server/plugin/pkg/registry/etcd/logger.go
diff --git a/server/plugin/infra/registry/etcd/logger_test.go b/server/plugin/pkg/registry/etcd/logger_test.go
similarity index 100%
rename from server/plugin/infra/registry/etcd/logger_test.go
rename to server/plugin/pkg/registry/etcd/logger_test.go
diff --git a/server/plugin/infra/registry/etcd/metrics.go b/server/plugin/pkg/registry/etcd/metrics.go
similarity index 100%
rename from server/plugin/infra/registry/etcd/metrics.go
rename to server/plugin/pkg/registry/etcd/metrics.go
diff --git a/server/plugin/infra/registry/etcd/tracing.go b/server/plugin/pkg/registry/etcd/tracing.go
similarity index 97%
rename from server/plugin/infra/registry/etcd/tracing.go
rename to server/plugin/pkg/registry/etcd/tracing.go
index db7695e..018a9bc 100644
--- a/server/plugin/infra/registry/etcd/tracing.go
+++ b/server/plugin/pkg/registry/etcd/tracing.go
@@ -17,9 +17,9 @@
package etcd
import (
- "github.com/apache/incubator-servicecomb-service-center/server/infra/registry"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/tracing"
"github.com/apache/incubator-servicecomb-service-center/server/plugin"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/registry"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/tracing"
"golang.org/x/net/context"
"net/http"
)
diff --git a/server/infra/registry/registry.go b/server/plugin/pkg/registry/option.go
similarity index 50%
rename from server/infra/registry/registry.go
rename to server/plugin/pkg/registry/option.go
index 74fec6c..2f33987 100644
--- a/server/infra/registry/registry.go
+++ b/server/plugin/pkg/registry/option.go
@@ -1,215 +1,25 @@
-/*
- * 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.
- */
+// 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 registry
import (
"bytes"
"fmt"
- "github.com/apache/incubator-servicecomb-service-center/pkg/log"
- "github.com/apache/incubator-servicecomb-service-center/server/core"
- "github.com/astaxie/beego"
- "github.com/coreos/etcd/mvcc/mvccpb"
- "golang.org/x/net/context"
- "strconv"
- "strings"
- "sync"
- "time"
-)
-
-const (
- // the timeout dial to etcd
- defaultDialTimeout = 10 * time.Second
- defaultRequestTimeout = 30 * time.Second
-)
-
-var (
- defaultRegistryConfig Config
- once sync.Once
-)
-
-func RegistryConfig() *Config {
- once.Do(func() {
- var err error
-
- defaultRegistryConfig.ClusterAddresses = beego.AppConfig.DefaultString("manager_cluster", "http://127.0.0.1:2379")
- defaultRegistryConfig.DialTimeout, err = time.ParseDuration(beego.AppConfig.DefaultString("registry_timeout", "30s"))
- if err != nil {
- log.Errorf(err, "connect_timeout is invalid, use default time %s", defaultDialTimeout)
- defaultRegistryConfig.DialTimeout = defaultDialTimeout
- }
- defaultRegistryConfig.RequestTimeOut, err = time.ParseDuration(beego.AppConfig.DefaultString("registry_timeout", "30s"))
- if err != nil {
- log.Errorf(err, "registry_timeout is invalid, use default time %s", defaultRequestTimeout)
- defaultRegistryConfig.RequestTimeOut = defaultRequestTimeout
- }
- defaultRegistryConfig.SslEnabled = core.ServerInfo.Config.SslEnabled &&
- strings.Index(strings.ToLower(defaultRegistryConfig.ClusterAddresses), "https://") >= 0
- defaultRegistryConfig.AutoSyncInterval, err = time.ParseDuration(core.ServerInfo.Config.AutoSyncInterval)
- if err != nil {
- log.Errorf(err, "auto_sync_interval is invalid")
- }
- })
- return &defaultRegistryConfig
-}
-
-type ActionType int
-
-func (at ActionType) String() string {
- switch at {
- case Get:
- return "GET"
- case Put:
- return "PUT"
- case Delete:
- return "DELETE"
- default:
- return "ACTION" + strconv.Itoa(int(at))
- }
-}
-
-type CacheMode int
-
-func (cm CacheMode) String() string {
- switch cm {
- case MODE_BOTH:
- return "MODE_BOTH"
- case MODE_CACHE:
- return "MODE_CACHE"
- case MODE_NO_CACHE:
- return "MODE_NO_CACHE"
- default:
- return "MODE" + strconv.Itoa(int(cm))
- }
-}
-
-type SortOrder int
-
-func (so SortOrder) String() string {
- switch so {
- case SORT_NONE:
- return "SORT_NONE"
- case SORT_ASCEND:
- return "SORT_ASCEND"
- case SORT_DESCEND:
- return "SORT_DESCEND"
- default:
- return "SORT" + strconv.Itoa(int(so))
- }
-}
-
-type CompareType int
-
-func (ct CompareType) String() string {
- switch ct {
- case CMP_VERSION:
- return "CMP_VERSION"
- case CMP_CREATE:
- return "CMP_CREATE"
- case CMP_MOD:
- return "CMP_MOD"
- case CMP_VALUE:
- return "CMP_VALUE"
- default:
- return "CMP_TYPE" + strconv.Itoa(int(ct))
- }
-}
-
-type CompareResult int
-
-func (cr CompareResult) String() string {
- switch cr {
- case CMP_EQUAL:
- return "CMP_EQUAL"
- case CMP_GREATER:
- return "CMP_GREATER"
- case CMP_LESS:
- return "CMP_LESS"
- case CMP_NOT_EQUAL:
- return "CMP_NOT_EQUAL"
- default:
- return "CMP_RESULT" + strconv.Itoa(int(cr))
- }
-}
-
-const (
- Get ActionType = iota
- Put
- Delete
-)
-
-const (
- SORT_NONE SortOrder = iota
- SORT_ASCEND
- SORT_DESCEND
-)
-
-const (
- CMP_VERSION CompareType = iota
- CMP_CREATE
- CMP_MOD
- CMP_VALUE
)
-const (
- CMP_EQUAL CompareResult = iota
- CMP_GREATER
- CMP_LESS
- CMP_NOT_EQUAL
-)
-
-const (
- MODE_BOTH CacheMode = iota
- MODE_CACHE
- MODE_NO_CACHE
-)
-
-const (
- DEFAULT_PAGE_COUNT = 4096 // grpc does not allow to transport a large body more then 4MB in a request.
-)
-
-type Registry interface {
- Err() <-chan error
- Ready() <-chan struct{}
- PutNoOverride(ctx context.Context, opts ...PluginOpOption) (bool, error)
- Do(ctx context.Context, opts ...PluginOpOption) (*PluginResponse, error)
- Txn(ctx context.Context, ops []PluginOp) (*PluginResponse, error)
- TxnWithCmp(ctx context.Context, success []PluginOp, cmp []CompareOp, fail []PluginOp) (*PluginResponse, error)
- LeaseGrant(ctx context.Context, TTL int64) (leaseID int64, err error)
- LeaseRenew(ctx context.Context, leaseID int64) (TTL int64, err error)
- LeaseRevoke(ctx context.Context, leaseID int64) error
- // this function block util:
- // 1. connection error
- // 2. call send function failed
- // 3. response.Err()
- // 4. time out to watch, but return nil
- Watch(ctx context.Context, opts ...PluginOpOption) error
- Compact(ctx context.Context, reserve int64) error
- Close()
-}
-
-type Config struct {
- SslEnabled bool
- EmbedMode string
- ClusterAddresses string
- DialTimeout time.Duration
- RequestTimeOut time.Duration
- AutoSyncInterval time.Duration
-}
-
type PluginOp struct {
Action ActionType
Key []byte
@@ -342,28 +152,6 @@ func OptionsToOp(opts ...PluginOpOption) (op PluginOp) {
return
}
-type PluginResponse struct {
- Action ActionType
- Kvs []*mvccpb.KeyValue
- Count int64
- Revision int64
- Succeeded bool
-}
-
-func (pr *PluginResponse) MaxModRevision() (max int64) {
- for _, kv := range pr.Kvs {
- if max < kv.ModRevision {
- max = kv.ModRevision
- }
- }
- return
-}
-
-func (pr *PluginResponse) String() string {
- return fmt.Sprintf("{action: %s, count: %d/%d, rev: %d, succeed: %v}",
- pr.Action, len(pr.Kvs), pr.Count, pr.Revision, pr.Succeeded)
-}
-
type CompareOp struct {
Key []byte
Type CompareType
@@ -402,7 +190,3 @@ func OpCmp(opt CompareOperation, result CompareResult, v interface{}) (cmp Compa
cmp.Value = v
return cmp
}
-
-func WithTimeout(ctx context.Context) (context.Context, context.CancelFunc) {
- return context.WithTimeout(ctx, defaultRegistryConfig.RequestTimeOut)
-}
diff --git a/server/plugin/pkg/registry/registry.go b/server/plugin/pkg/registry/registry.go
new file mode 100644
index 0000000..f2333b4
--- /dev/null
+++ b/server/plugin/pkg/registry/registry.go
@@ -0,0 +1,41 @@
+/*
+ * 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 registry
+
+import (
+ "golang.org/x/net/context"
+)
+
+type Registry interface {
+ Err() <-chan error
+ Ready() <-chan struct{}
+ PutNoOverride(ctx context.Context, opts ...PluginOpOption) (bool, error)
+ Do(ctx context.Context, opts ...PluginOpOption) (*PluginResponse, error)
+ Txn(ctx context.Context, ops []PluginOp) (*PluginResponse, error)
+ TxnWithCmp(ctx context.Context, success []PluginOp, cmp []CompareOp, fail []PluginOp) (*PluginResponse, error)
+ LeaseGrant(ctx context.Context, TTL int64) (leaseID int64, err error)
+ LeaseRenew(ctx context.Context, leaseID int64) (TTL int64, err error)
+ LeaseRevoke(ctx context.Context, leaseID int64) error
+ // this function block util:
+ // 1. connection error
+ // 2. call send function failed
+ // 3. response.Err()
+ // 4. time out to watch, but return nil
+ Watch(ctx context.Context, opts ...PluginOpOption) error
+ Compact(ctx context.Context, reserve int64) error
+ Close()
+}
diff --git a/server/plugin/pkg/registry/types.go b/server/plugin/pkg/registry/types.go
new file mode 100644
index 0000000..986e95d
--- /dev/null
+++ b/server/plugin/pkg/registry/types.go
@@ -0,0 +1,123 @@
+// 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 registry
+
+import (
+ "fmt"
+ "github.com/coreos/etcd/mvcc/mvccpb"
+ "strconv"
+)
+
+type ActionType int
+
+func (at ActionType) String() string {
+ switch at {
+ case Get:
+ return "GET"
+ case Put:
+ return "PUT"
+ case Delete:
+ return "DELETE"
+ default:
+ return "ACTION" + strconv.Itoa(int(at))
+ }
+}
+
+type CacheMode int
+
+func (cm CacheMode) String() string {
+ switch cm {
+ case MODE_BOTH:
+ return "MODE_BOTH"
+ case MODE_CACHE:
+ return "MODE_CACHE"
+ case MODE_NO_CACHE:
+ return "MODE_NO_CACHE"
+ default:
+ return "MODE" + strconv.Itoa(int(cm))
+ }
+}
+
+type SortOrder int
+
+func (so SortOrder) String() string {
+ switch so {
+ case SORT_NONE:
+ return "SORT_NONE"
+ case SORT_ASCEND:
+ return "SORT_ASCEND"
+ case SORT_DESCEND:
+ return "SORT_DESCEND"
+ default:
+ return "SORT" + strconv.Itoa(int(so))
+ }
+}
+
+type CompareType int
+
+func (ct CompareType) String() string {
+ switch ct {
+ case CMP_VERSION:
+ return "CMP_VERSION"
+ case CMP_CREATE:
+ return "CMP_CREATE"
+ case CMP_MOD:
+ return "CMP_MOD"
+ case CMP_VALUE:
+ return "CMP_VALUE"
+ default:
+ return "CMP_TYPE" + strconv.Itoa(int(ct))
+ }
+}
+
+type CompareResult int
+
+func (cr CompareResult) String() string {
+ switch cr {
+ case CMP_EQUAL:
+ return "CMP_EQUAL"
+ case CMP_GREATER:
+ return "CMP_GREATER"
+ case CMP_LESS:
+ return "CMP_LESS"
+ case CMP_NOT_EQUAL:
+ return "CMP_NOT_EQUAL"
+ default:
+ return "CMP_RESULT" + strconv.Itoa(int(cr))
+ }
+}
+
+type PluginResponse struct {
+ Action ActionType
+ Kvs []*mvccpb.KeyValue
+ Count int64
+ Revision int64
+ Succeeded bool
+}
+
+func (pr *PluginResponse) MaxModRevision() (max int64) {
+ for _, kv := range pr.Kvs {
+ if max < kv.ModRevision {
+ max = kv.ModRevision
+ }
+ }
+ return
+}
+
+func (pr *PluginResponse) String() string {
+ return fmt.Sprintf("{action: %s, count: %d/%d, rev: %d, succeed: %v}",
+ pr.Action, len(pr.Kvs), pr.Count, pr.Revision, pr.Succeeded)
+}
diff --git a/server/plugin/infra/security/buildin/buildin.go b/server/plugin/pkg/security/buildin/buildin.go
similarity index 100%
rename from server/plugin/infra/security/buildin/buildin.go
rename to server/plugin/pkg/security/buildin/buildin.go
diff --git a/server/infra/security/cipher.go b/server/plugin/pkg/security/cipher.go
similarity index 100%
rename from server/infra/security/cipher.go
rename to server/plugin/pkg/security/cipher.go
diff --git a/server/plugin/infra/tls/buildin/buildin.go b/server/plugin/pkg/tls/buildin/buildin.go
similarity index 100%
rename from server/plugin/infra/tls/buildin/buildin.go
rename to server/plugin/pkg/tls/buildin/buildin.go
diff --git a/server/plugin/infra/tls/buildin/tls.go b/server/plugin/pkg/tls/buildin/tls.go
similarity index 100%
rename from server/plugin/infra/tls/buildin/tls.go
rename to server/plugin/pkg/tls/buildin/tls.go
diff --git a/server/plugin/infra/tls/buildin/tls_test.go b/server/plugin/pkg/tls/buildin/tls_test.go
similarity index 96%
rename from server/plugin/infra/tls/buildin/tls_test.go
rename to server/plugin/pkg/tls/buildin/tls_test.go
index 71e5e25..41b0d1a 100644
--- a/server/plugin/infra/tls/buildin/tls_test.go
+++ b/server/plugin/pkg/tls/buildin/tls_test.go
@@ -19,7 +19,7 @@ package buildin
import (
"crypto/tls"
"github.com/apache/incubator-servicecomb-service-center/server/core"
- _ "github.com/apache/incubator-servicecomb-service-center/server/plugin/infra/security/buildin"
+ _ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/security/buildin"
"os"
"testing"
)
@@ -42,7 +42,7 @@ func TestGetServerTLSConfig(t *testing.T) {
if serverTLSConfig.ClientCAs == nil {
t.Fatalf("GetServerTLSConfig failed")
}
- if len(serverTLSConfig.CipherSuites) != 4 {
+ if len(serverTLSConfig.CipherSuites) != 0 {
t.Fatalf("GetServerTLSConfig failed")
}
if serverTLSConfig.MinVersion != tls.VersionTLS12 {
diff --git a/server/infra/tls/tls.go b/server/plugin/pkg/tls/tls.go
similarity index 100%
rename from server/infra/tls/tls.go
rename to server/plugin/pkg/tls/tls.go
diff --git a/server/plugin/infra/tracing/buildin/README.md b/server/plugin/pkg/tracing/buildin/README.md
similarity index 100%
rename from server/plugin/infra/tracing/buildin/README.md
rename to server/plugin/pkg/tracing/buildin/README.md
diff --git a/server/plugin/infra/tracing/buildin/buildin.go b/server/plugin/pkg/tracing/buildin/buildin.go
similarity index 99%
rename from server/plugin/infra/tracing/buildin/buildin.go
rename to server/plugin/pkg/tracing/buildin/buildin.go
index 6ffc09d..3aa4c90 100644
--- a/server/plugin/infra/tracing/buildin/buildin.go
+++ b/server/plugin/pkg/tracing/buildin/buildin.go
@@ -20,8 +20,8 @@ import (
"context"
"github.com/apache/incubator-servicecomb-service-center/pkg/log"
"github.com/apache/incubator-servicecomb-service-center/pkg/util"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/tracing"
mgr "github.com/apache/incubator-servicecomb-service-center/server/plugin"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/tracing"
"github.com/opentracing/opentracing-go"
"github.com/opentracing/opentracing-go/ext"
"github.com/openzipkin/zipkin-go-opentracing/thrift/gen-go/zipkincore"
diff --git a/server/plugin/infra/tracing/buildin/buildin_test.go b/server/plugin/pkg/tracing/buildin/buildin_test.go
similarity index 98%
rename from server/plugin/infra/tracing/buildin/buildin_test.go
rename to server/plugin/pkg/tracing/buildin/buildin_test.go
index f8262a1..16e90e5 100644
--- a/server/plugin/infra/tracing/buildin/buildin_test.go
+++ b/server/plugin/pkg/tracing/buildin/buildin_test.go
@@ -19,8 +19,8 @@ package buildin
import (
"context"
"github.com/apache/incubator-servicecomb-service-center/server/core"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/registry"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/tracing"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/registry"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/tracing"
"net/http"
"os"
"testing"
diff --git a/server/plugin/infra/tracing/buildin/common.go b/server/plugin/pkg/tracing/buildin/common.go
similarity index 100%
rename from server/plugin/infra/tracing/buildin/common.go
rename to server/plugin/pkg/tracing/buildin/common.go
diff --git a/server/plugin/infra/tracing/buildin/common_test.go b/server/plugin/pkg/tracing/buildin/common_test.go
similarity index 100%
rename from server/plugin/infra/tracing/buildin/common_test.go
rename to server/plugin/pkg/tracing/buildin/common_test.go
diff --git a/server/plugin/infra/tracing/buildin/file_collector.go b/server/plugin/pkg/tracing/buildin/file_collector.go
similarity index 100%
rename from server/plugin/infra/tracing/buildin/file_collector.go
rename to server/plugin/pkg/tracing/buildin/file_collector.go
diff --git a/server/plugin/infra/tracing/buildin/file_collector_test.go b/server/plugin/pkg/tracing/buildin/file_collector_test.go
similarity index 100%
rename from server/plugin/infra/tracing/buildin/file_collector_test.go
rename to server/plugin/pkg/tracing/buildin/file_collector_test.go
diff --git a/server/plugin/infra/tracing/buildin/span.go b/server/plugin/pkg/tracing/buildin/span.go
similarity index 100%
rename from server/plugin/infra/tracing/buildin/span.go
rename to server/plugin/pkg/tracing/buildin/span.go
diff --git a/server/plugin/infra/tracing/buildin/span_test.go b/server/plugin/pkg/tracing/buildin/span_test.go
similarity index 100%
rename from server/plugin/infra/tracing/buildin/span_test.go
rename to server/plugin/pkg/tracing/buildin/span_test.go
diff --git a/server/infra/tracing/tracing.go b/server/plugin/pkg/tracing/tracing.go
similarity index 98%
rename from server/infra/tracing/tracing.go
rename to server/plugin/pkg/tracing/tracing.go
index a7d855e..6b1c394 100644
--- a/server/infra/tracing/tracing.go
+++ b/server/plugin/pkg/tracing/tracing.go
@@ -17,7 +17,7 @@
package tracing
import (
- "github.com/apache/incubator-servicecomb-service-center/server/infra/registry"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/registry"
"golang.org/x/net/context"
)
diff --git a/server/plugin/infra/uuid/buildin/buildin.go b/server/plugin/pkg/uuid/buildin/buildin.go
similarity index 100%
rename from server/plugin/infra/uuid/buildin/buildin.go
rename to server/plugin/pkg/uuid/buildin/buildin.go
diff --git a/server/infra/uuid/uuid.go b/server/plugin/pkg/uuid/uuid.go
similarity index 100%
rename from server/infra/uuid/uuid.go
rename to server/plugin/pkg/uuid/uuid.go
diff --git a/server/plugin/plugin.go b/server/plugin/plugin.go
index ba3f54d..58b5332 100644
--- a/server/plugin/plugin.go
+++ b/server/plugin/plugin.go
@@ -20,87 +20,16 @@ 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/discovery"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/quota"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/registry"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/security"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/tls"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/tracing"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/uuid"
"github.com/astaxie/beego"
- pg "plugin"
- "strconv"
"sync"
)
-const (
- BUILDIN = "buildin"
- STATIC = "static"
- DYNAMIC = "dynamic"
- keyPluginName = "name"
-)
-
-const (
- UUID PluginName = iota
- AUDIT_LOG
- AUTH
- CIPHER
- QUOTA
- REGISTRY
- TRACING
- TLS
- DISCOVERY
- typeEnd
-)
-
-var pluginNames = map[PluginName]string{
- UUID: "uuid",
- AUDIT_LOG: "auditlog",
- AUTH: "auth",
- CIPHER: "cipher",
- QUOTA: "quota",
- REGISTRY: "registry",
- TRACING: "trace",
- DISCOVERY: "discovery",
- TLS: "ssl",
-}
-
var pluginMgr = &PluginManager{}
func init() {
pluginMgr.Initialize()
}
-type PluginName int
-
-func (pn PluginName) String() string {
- if name, ok := pluginNames[pn]; ok {
- return name
- }
- 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
- // plugin name
- Name string
- New func() PluginInstance
-}
-
-type PluginInstance interface{}
-
type wrapInstance struct {
dynamic bool
instance PluginInstance
@@ -220,22 +149,6 @@ func (pm *PluginManager) existDynamicPlugin(pn PluginName) *Plugin {
return nil
}
-func (pm *PluginManager) Discovery() discovery.AdaptorRepository {
- return pm.Instance(DISCOVERY).(discovery.AdaptorRepository)
-}
-func (pm *PluginManager) Registry() registry.Registry {
- return pm.Instance(REGISTRY).(registry.Registry)
-}
-func (pm *PluginManager) UUID() uuid.UUID { return pm.Instance(UUID).(uuid.UUID) }
-func (pm *PluginManager) AuditLog() auditlog.AuditLogger {
- return pm.Instance(AUDIT_LOG).(auditlog.AuditLogger)
-}
-func (pm *PluginManager) Auth() auth.Auth { return pm.Instance(AUTH).(auth.Auth) }
-func (pm *PluginManager) Cipher() security.Cipher { return pm.Instance(CIPHER).(security.Cipher) }
-func (pm *PluginManager) Quota() quota.QuotaManager { return pm.Instance(QUOTA).(quota.QuotaManager) }
-func (pm *PluginManager) Tracing() (v tracing.Tracing) { return pm.Instance(TRACING).(tracing.Tracing) }
-func (pm *PluginManager) TLS() tls.TLS { return pm.Instance(TLS).(tls.TLS) }
-
func Plugins() *PluginManager {
return pluginMgr
}
@@ -244,19 +157,6 @@ func RegisterPlugin(p Plugin) {
Plugins().Register(p)
}
-// DynamicPluginFunc should be called in buildin implement
-func DynamicPluginFunc(pn PluginName, funcName string) pg.Symbol {
- if wi, ok := Plugins().instances[pn]; ok && !wi.dynamic {
- return nil
- }
-
- f, err := plugin.FindFunc(pn.String(), funcName)
- if err != nil {
- log.Errorf(err, "plugin '%s': not implemented function '%s'.", pn, funcName)
- }
- return f
-}
-
func LoadPlugins() {
for t := PluginName(0); t != typeEnd; t++ {
Plugins().Instance(t)
diff --git a/server/plugin/infra/discovery/k8s/repo.go b/server/plugin/types.go
similarity index 59%
rename from server/plugin/infra/discovery/k8s/repo.go
rename to server/plugin/types.go
index 7a93961..0591dd7 100644
--- a/server/plugin/infra/discovery/k8s/repo.go
+++ b/server/plugin/types.go
@@ -13,32 +13,37 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package k8s
+package plugin
import (
- "github.com/apache/incubator-servicecomb-service-center/pkg/log"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/discovery"
- mgr "github.com/apache/incubator-servicecomb-service-center/server/plugin"
+ "github.com/apache/incubator-servicecomb-service-center/pkg/util"
+ "github.com/apache/incubator-servicecomb-service-center/server/core"
+ "strconv"
)
-func init() {
- mgr.RegisterPlugin(mgr.Plugin{mgr.DISCOVERY, "k8s", NewRepository})
+type PluginInstance interface{}
+
+type PluginName int
+
+func (pn PluginName) String() string {
+ if name, ok := pluginNames[pn]; ok {
+ return name
+ }
+ return "PLUGIN" + strconv.Itoa(int(pn))
}
-type K8sRepository struct {
+func (pn PluginName) ActiveConfigs() util.JSONObject {
+ return core.ServerInfo.Config.Plugins.Object(pn.String())
}
-func (r *K8sRepository) New(t discovery.Type, cfg *discovery.Config) discovery.Adaptor {
- if cfg == nil {
- // do not new instance
- log.Warnf("type '%s' config is nil", t)
- return nil
- }
- e := NewK8sAdaptor(t, cfg)
- e.Run()
- return e
+func (pn PluginName) ClearConfigs() {
+ core.ServerInfo.Config.Plugins.Set(pn.String(), nil)
}
-func NewRepository() mgr.PluginInstance {
- return &K8sRepository{}
+type Plugin struct {
+ // plugin class name
+ PName PluginName
+ // plugin name
+ Name string
+ New func() PluginInstance
}
diff --git a/server/service/cache/filter_instances.go b/server/service/cache/filter_instances.go
index 94f77df..e30b703 100644
--- a/server/service/cache/filter_instances.go
+++ b/server/service/cache/filter_instances.go
@@ -23,7 +23,7 @@ import (
apt "github.com/apache/incubator-servicecomb-service-center/server/core"
"github.com/apache/incubator-servicecomb-service-center/server/core/backend"
pb "github.com/apache/incubator-servicecomb-service-center/server/core/proto"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/registry"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/registry"
serviceUtil "github.com/apache/incubator-servicecomb-service-center/server/service/util"
"golang.org/x/net/context"
)
diff --git a/server/service/dependency.go b/server/service/dependency.go
index 71a8cbd..8ba1bb5 100644
--- a/server/service/dependency.go
+++ b/server/service/dependency.go
@@ -25,7 +25,7 @@ import (
"github.com/apache/incubator-servicecomb-service-center/server/core/backend"
pb "github.com/apache/incubator-servicecomb-service-center/server/core/proto"
scerr "github.com/apache/incubator-servicecomb-service-center/server/error"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/registry"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/registry"
serviceUtil "github.com/apache/incubator-servicecomb-service-center/server/service/util"
"golang.org/x/net/context"
)
diff --git a/server/service/event/dependency_event_handler.go b/server/service/event/dependency_event_handler.go
index 87f8bea..b2b2104 100644
--- a/server/service/event/dependency_event_handler.go
+++ b/server/service/event/dependency_event_handler.go
@@ -25,9 +25,9 @@ import (
"github.com/apache/incubator-servicecomb-service-center/server/core"
"github.com/apache/incubator-servicecomb-service-center/server/core/backend"
pb "github.com/apache/incubator-servicecomb-service-center/server/core/proto"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/discovery"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/registry"
"github.com/apache/incubator-servicecomb-service-center/server/mux"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/discovery"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/registry"
serviceUtil "github.com/apache/incubator-servicecomb-service-center/server/service/util"
"golang.org/x/net/context"
"time"
diff --git a/server/service/event/domain_event_handler.go b/server/service/event/domain_event_handler.go
index 75626ed..2222898 100644
--- a/server/service/event/domain_event_handler.go
+++ b/server/service/event/domain_event_handler.go
@@ -19,7 +19,7 @@ package event
import (
"github.com/apache/incubator-servicecomb-service-center/server/core/backend"
pb "github.com/apache/incubator-servicecomb-service-center/server/core/proto"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/discovery"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/discovery"
"github.com/apache/incubator-servicecomb-service-center/server/service/metrics"
)
diff --git a/server/service/event/event.go b/server/service/event/event.go
index c933997..3b5d2a8 100644
--- a/server/service/event/event.go
+++ b/server/service/event/event.go
@@ -17,7 +17,7 @@
package event
import (
- "github.com/apache/incubator-servicecomb-service-center/server/infra/discovery"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/discovery"
)
func init() {
diff --git a/server/service/event/instance_event_handler.go b/server/service/event/instance_event_handler.go
index 1f183ad..e781f70 100644
--- a/server/service/event/instance_event_handler.go
+++ b/server/service/event/instance_event_handler.go
@@ -22,7 +22,7 @@ import (
apt "github.com/apache/incubator-servicecomb-service-center/server/core"
"github.com/apache/incubator-servicecomb-service-center/server/core/backend"
pb "github.com/apache/incubator-servicecomb-service-center/server/core/proto"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/discovery"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/discovery"
"github.com/apache/incubator-servicecomb-service-center/server/service/cache"
"github.com/apache/incubator-servicecomb-service-center/server/service/metrics"
nf "github.com/apache/incubator-servicecomb-service-center/server/service/notification"
diff --git a/server/service/event/rule_event_handler.go b/server/service/event/rule_event_handler.go
index f9ce5d2..f609473 100644
--- a/server/service/event/rule_event_handler.go
+++ b/server/service/event/rule_event_handler.go
@@ -24,7 +24,7 @@ import (
"github.com/apache/incubator-servicecomb-service-center/server/core"
"github.com/apache/incubator-servicecomb-service-center/server/core/backend"
pb "github.com/apache/incubator-servicecomb-service-center/server/core/proto"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/discovery"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/discovery"
nf "github.com/apache/incubator-servicecomb-service-center/server/service/notification"
serviceUtil "github.com/apache/incubator-servicecomb-service-center/server/service/util"
"golang.org/x/net/context"
diff --git a/server/service/event/service_event_handler.go b/server/service/event/service_event_handler.go
index 4bf3506..5b3ada8 100644
--- a/server/service/event/service_event_handler.go
+++ b/server/service/event/service_event_handler.go
@@ -21,7 +21,7 @@ import (
"github.com/apache/incubator-servicecomb-service-center/server/core"
"github.com/apache/incubator-servicecomb-service-center/server/core/backend"
pb "github.com/apache/incubator-servicecomb-service-center/server/core/proto"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/discovery"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/discovery"
"github.com/apache/incubator-servicecomb-service-center/server/service/cache"
"github.com/apache/incubator-servicecomb-service-center/server/service/metrics"
serviceUtil "github.com/apache/incubator-servicecomb-service-center/server/service/util"
diff --git a/server/service/event/tag_event_handler.go b/server/service/event/tag_event_handler.go
index 8388803..0c83661 100644
--- a/server/service/event/tag_event_handler.go
+++ b/server/service/event/tag_event_handler.go
@@ -24,7 +24,7 @@ import (
"github.com/apache/incubator-servicecomb-service-center/server/core"
"github.com/apache/incubator-servicecomb-service-center/server/core/backend"
pb "github.com/apache/incubator-servicecomb-service-center/server/core/proto"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/discovery"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/discovery"
"github.com/apache/incubator-servicecomb-service-center/server/service/cache"
nf "github.com/apache/incubator-servicecomb-service-center/server/service/notification"
serviceUtil "github.com/apache/incubator-servicecomb-service-center/server/service/util"
diff --git a/server/service/instance.go b/server/service/instance.go
index d147cf5..9ee509d 100644
--- a/server/service/instance.go
+++ b/server/service/instance.go
@@ -27,9 +27,9 @@ import (
"github.com/apache/incubator-servicecomb-service-center/server/core/backend"
pb "github.com/apache/incubator-servicecomb-service-center/server/core/proto"
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"
"github.com/apache/incubator-servicecomb-service-center/server/plugin"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/quota"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/registry"
"github.com/apache/incubator-servicecomb-service-center/server/service/cache"
serviceUtil "github.com/apache/incubator-servicecomb-service-center/server/service/util"
"golang.org/x/net/context"
diff --git a/server/service/microservice.go b/server/service/microservice.go
index cbde70f..60c40f1 100644
--- a/server/service/microservice.go
+++ b/server/service/microservice.go
@@ -28,9 +28,9 @@ import (
"github.com/apache/incubator-servicecomb-service-center/server/core/backend"
pb "github.com/apache/incubator-servicecomb-service-center/server/core/proto"
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"
"github.com/apache/incubator-servicecomb-service-center/server/plugin"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/quota"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/registry"
serviceUtil "github.com/apache/incubator-servicecomb-service-center/server/service/util"
"golang.org/x/net/context"
"strconv"
diff --git a/server/service/microservice_test.go b/server/service/microservice_test.go
index e9de325..f27c897 100644
--- a/server/service/microservice_test.go
+++ b/server/service/microservice_test.go
@@ -20,7 +20,7 @@ import (
"github.com/apache/incubator-servicecomb-service-center/server/core"
pb "github.com/apache/incubator-servicecomb-service-center/server/core/proto"
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/plugin/pkg/quota"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"strconv"
diff --git a/server/service/microservice_validator.go b/server/service/microservice_validator.go
index 70a3072..d010ec5 100644
--- a/server/service/microservice_validator.go
+++ b/server/service/microservice_validator.go
@@ -20,7 +20,7 @@ import (
"github.com/apache/incubator-servicecomb-service-center/pkg/util"
"github.com/apache/incubator-servicecomb-service-center/pkg/validate"
pb "github.com/apache/incubator-servicecomb-service-center/server/core/proto"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/quota"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/quota"
serviceUtil "github.com/apache/incubator-servicecomb-service-center/server/service/util"
"regexp"
)
diff --git a/server/service/notification/websocket_test.go b/server/service/notification/websocket_test.go
index 03b228d..d2b1e4d 100644
--- a/server/service/notification/websocket_test.go
+++ b/server/service/notification/websocket_test.go
@@ -21,8 +21,8 @@ import (
"context"
"errors"
"github.com/apache/incubator-servicecomb-service-center/server/core/proto"
- _ "github.com/apache/incubator-servicecomb-service-center/server/plugin/infra/discovery/etcd"
- _ "github.com/apache/incubator-servicecomb-service-center/server/plugin/infra/registry/buildin"
+ _ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/discovery/etcd"
+ _ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/registry/buildin"
"github.com/gorilla/websocket"
"net/http"
"net/http/httptest"
diff --git a/server/service/rule.go b/server/service/rule.go
index ad3efc7..bde2a54 100644
--- a/server/service/rule.go
+++ b/server/service/rule.go
@@ -24,9 +24,9 @@ import (
"github.com/apache/incubator-servicecomb-service-center/server/core/backend"
pb "github.com/apache/incubator-servicecomb-service-center/server/core/proto"
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"
"github.com/apache/incubator-servicecomb-service-center/server/plugin"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/quota"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/registry"
serviceUtil "github.com/apache/incubator-servicecomb-service-center/server/service/util"
"golang.org/x/net/context"
"strconv"
diff --git a/server/service/rule_test.go b/server/service/rule_test.go
index 051b1f4..0221889 100644
--- a/server/service/rule_test.go
+++ b/server/service/rule_test.go
@@ -19,7 +19,7 @@ package service_test
import (
pb "github.com/apache/incubator-servicecomb-service-center/server/core/proto"
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/plugin/pkg/quota"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"strconv"
diff --git a/server/service/rule_validator.go b/server/service/rule_validator.go
index 71a7cc6..2929727 100644
--- a/server/service/rule_validator.go
+++ b/server/service/rule_validator.go
@@ -18,7 +18,7 @@ package service
import (
"github.com/apache/incubator-servicecomb-service-center/pkg/validate"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/quota"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/quota"
"regexp"
)
diff --git a/server/service/schema.go b/server/service/schema.go
index 4b26450..02592b3 100644
--- a/server/service/schema.go
+++ b/server/service/schema.go
@@ -24,10 +24,10 @@ import (
"github.com/apache/incubator-servicecomb-service-center/server/core/backend"
pb "github.com/apache/incubator-servicecomb-service-center/server/core/proto"
scerr "github.com/apache/incubator-servicecomb-service-center/server/error"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/discovery"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/quota"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/registry"
"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/quota"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/registry"
serviceUtil "github.com/apache/incubator-servicecomb-service-center/server/service/util"
"golang.org/x/net/context"
"strings"
@@ -143,14 +143,14 @@ func (s *MicroServiceService) GetAllSchemaInfo(ctx context.Context, in *pb.GetAl
tempSchema := &pb.Schema{}
tempSchema.SchemaId = schemaId
for _, summarySchema := range resp.Kvs {
- schemaIdOfSummary := apt.GetInfoFromSchemaSummaryKV(summarySchema.Key)
+ _, _, schemaIdOfSummary := apt.GetInfoFromSchemaSummaryKV(summarySchema.Key)
if schemaId == schemaIdOfSummary {
tempSchema.Summary = summarySchema.Value.(string)
}
}
for _, contentSchema := range respWithSchema.Kvs {
- schemaIdOfSchema := apt.GetInfoFromSchemaKV(contentSchema.Key)
+ _, _, schemaIdOfSchema := apt.GetInfoFromSchemaKV(contentSchema.Key)
if schemaId == schemaIdOfSchema {
tempSchema.Schema = util.BytesToStringWithNoCopy(contentSchema.Value.([]byte))
}
diff --git a/server/service/schema_test.go b/server/service/schema_test.go
index b79ef06..421f4da 100644
--- a/server/service/schema_test.go
+++ b/server/service/schema_test.go
@@ -19,7 +19,7 @@ package service_test
import (
pb "github.com/apache/incubator-servicecomb-service-center/server/core/proto"
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/plugin/pkg/quota"
"github.com/apache/incubator-servicecomb-service-center/server/service"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
diff --git a/server/service/schema_validator.go b/server/service/schema_validator.go
index 0b55ace..811eb69 100644
--- a/server/service/schema_validator.go
+++ b/server/service/schema_validator.go
@@ -18,7 +18,7 @@ package service
import (
"github.com/apache/incubator-servicecomb-service-center/pkg/validate"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/quota"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/quota"
"regexp"
)
diff --git a/server/service/tag.go b/server/service/tag.go
index d07a1db..6b90f63 100644
--- a/server/service/tag.go
+++ b/server/service/tag.go
@@ -24,9 +24,9 @@ import (
"github.com/apache/incubator-servicecomb-service-center/server/core/backend"
pb "github.com/apache/incubator-servicecomb-service-center/server/core/proto"
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"
"github.com/apache/incubator-servicecomb-service-center/server/plugin"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/quota"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/registry"
serviceUtil "github.com/apache/incubator-servicecomb-service-center/server/service/util"
"golang.org/x/net/context"
)
diff --git a/server/service/tag_test.go b/server/service/tag_test.go
index 8396eac..40e767b 100644
--- a/server/service/tag_test.go
+++ b/server/service/tag_test.go
@@ -19,7 +19,7 @@ package service_test
import (
pb "github.com/apache/incubator-servicecomb-service-center/server/core/proto"
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/plugin/pkg/quota"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"strconv"
diff --git a/server/service/tag_validator.go b/server/service/tag_validator.go
index 31a37cd..ee681ad 100644
--- a/server/service/tag_validator.go
+++ b/server/service/tag_validator.go
@@ -18,7 +18,7 @@ package service
import (
"github.com/apache/incubator-servicecomb-service-center/pkg/validate"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/quota"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/quota"
"regexp"
)
diff --git a/server/service/util/dependency.go b/server/service/util/dependency.go
index b8776b0..752bb54 100644
--- a/server/service/util/dependency.go
+++ b/server/service/util/dependency.go
@@ -24,7 +24,7 @@ import (
apt "github.com/apache/incubator-servicecomb-service-center/server/core"
"github.com/apache/incubator-servicecomb-service-center/server/core/backend"
pb "github.com/apache/incubator-servicecomb-service-center/server/core/proto"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/registry"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/registry"
"golang.org/x/net/context"
)
diff --git a/server/service/util/dependency_query.go b/server/service/util/dependency_query.go
index b873b72..db03659 100644
--- a/server/service/util/dependency_query.go
+++ b/server/service/util/dependency_query.go
@@ -23,7 +23,7 @@ import (
apt "github.com/apache/incubator-servicecomb-service-center/server/core"
"github.com/apache/incubator-servicecomb-service-center/server/core/backend"
pb "github.com/apache/incubator-servicecomb-service-center/server/core/proto"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/registry"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/registry"
"golang.org/x/net/context"
"strings"
)
diff --git a/server/service/util/dependency_util.go b/server/service/util/dependency_util.go
index 348e000..90979d4 100644
--- a/server/service/util/dependency_util.go
+++ b/server/service/util/dependency_util.go
@@ -26,7 +26,7 @@ import (
"github.com/apache/incubator-servicecomb-service-center/server/core/backend"
pb "github.com/apache/incubator-servicecomb-service-center/server/core/proto"
scerr "github.com/apache/incubator-servicecomb-service-center/server/error"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/registry"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/registry"
"golang.org/x/net/context"
"strings"
)
diff --git a/server/service/util/domain_util.go b/server/service/util/domain_util.go
index 7dd9bd3..8ccd552 100644
--- a/server/service/util/domain_util.go
+++ b/server/service/util/domain_util.go
@@ -21,8 +21,8 @@ import (
"github.com/apache/incubator-servicecomb-service-center/pkg/util"
apt "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/infra/discovery"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/registry"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/discovery"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/registry"
"golang.org/x/net/context"
"strings"
)
diff --git a/server/service/util/heartbeat_util.go b/server/service/util/heartbeat_util.go
index 7f8a675..e070518 100644
--- a/server/service/util/heartbeat_util.go
+++ b/server/service/util/heartbeat_util.go
@@ -20,7 +20,7 @@ import (
"errors"
apt "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/infra/registry"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/registry"
"golang.org/x/net/context"
)
diff --git a/server/service/util/instance_util.go b/server/service/util/instance_util.go
index d2b02ce..eebd647 100644
--- a/server/service/util/instance_util.go
+++ b/server/service/util/instance_util.go
@@ -25,8 +25,8 @@ import (
"github.com/apache/incubator-servicecomb-service-center/server/core/backend"
pb "github.com/apache/incubator-servicecomb-service-center/server/core/proto"
scerr "github.com/apache/incubator-servicecomb-service-center/server/error"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/discovery"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/registry"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/discovery"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/registry"
"golang.org/x/net/context"
"strconv"
"strings"
diff --git a/server/service/util/microservice_util.go b/server/service/util/microservice_util.go
index 39a625e..c54a0e1 100644
--- a/server/service/util/microservice_util.go
+++ b/server/service/util/microservice_util.go
@@ -23,10 +23,10 @@ import (
apt "github.com/apache/incubator-servicecomb-service-center/server/core"
"github.com/apache/incubator-servicecomb-service-center/server/core/backend"
pb "github.com/apache/incubator-servicecomb-service-center/server/core/proto"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/discovery"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/quota"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/registry"
"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/quota"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/registry"
"golang.org/x/net/context"
)
diff --git a/server/service/util/rule_util.go b/server/service/util/rule_util.go
index aa671a0..50ecd21 100644
--- a/server/service/util/rule_util.go
+++ b/server/service/util/rule_util.go
@@ -24,7 +24,7 @@ import (
"github.com/apache/incubator-servicecomb-service-center/server/core/backend"
pb "github.com/apache/incubator-servicecomb-service-center/server/core/proto"
scerr "github.com/apache/incubator-servicecomb-service-center/server/error"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/registry"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/registry"
"golang.org/x/net/context"
"reflect"
"regexp"
diff --git a/server/service/util/schema_util.go b/server/service/util/schema_util.go
index 5a0bd0f..c84912c 100644
--- a/server/service/util/schema_util.go
+++ b/server/service/util/schema_util.go
@@ -18,7 +18,7 @@ package util
import (
"github.com/apache/incubator-servicecomb-service-center/server/core/backend"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/registry"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/registry"
"golang.org/x/net/context"
)
diff --git a/server/service/util/tag_util.go b/server/service/util/tag_util.go
index 859c019..7e60d6a 100644
--- a/server/service/util/tag_util.go
+++ b/server/service/util/tag_util.go
@@ -23,7 +23,7 @@ import (
apt "github.com/apache/incubator-servicecomb-service-center/server/core"
"github.com/apache/incubator-servicecomb-service-center/server/core/backend"
scerr "github.com/apache/incubator-servicecomb-service-center/server/error"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/registry"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/registry"
"golang.org/x/net/context"
)
diff --git a/server/service/util/util.go b/server/service/util/util.go
index 6d0653c..76e398e 100644
--- a/server/service/util/util.go
+++ b/server/service/util/util.go
@@ -17,7 +17,7 @@
package util
import (
- "github.com/apache/incubator-servicecomb-service-center/server/infra/registry"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/registry"
"golang.org/x/net/context"
)
diff --git a/server/service/util/util_suite_test.go b/server/service/util/util_suite_test.go
index cdccb5d..9fdc324 100644
--- a/server/service/util/util_suite_test.go
+++ b/server/service/util/util_suite_test.go
@@ -17,15 +17,15 @@
package util_test
import (
- _ "github.com/apache/incubator-servicecomb-service-center/server/plugin/infra/discovery/etcd"
- _ "github.com/apache/incubator-servicecomb-service-center/server/plugin/infra/quota/buildin"
- _ "github.com/apache/incubator-servicecomb-service-center/server/plugin/infra/registry/buildin"
+ _ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/discovery/etcd"
+ _ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/quota/buildin"
+ _ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/registry/buildin"
)
import (
"github.com/apache/incubator-servicecomb-service-center/pkg/util"
"github.com/apache/incubator-servicecomb-service-center/server/core/proto"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/registry"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/registry"
serviceUtil "github.com/apache/incubator-servicecomb-service-center/server/service/util"
. "github.com/onsi/ginkgo"
"github.com/onsi/ginkgo/reporters"
diff --git a/server/service/util/versionrule.go b/server/service/util/versionrule.go
index 376ca64..2a0d207 100644
--- a/server/service/util/versionrule.go
+++ b/server/service/util/versionrule.go
@@ -18,7 +18,7 @@ package util
import (
"github.com/apache/incubator-servicecomb-service-center/pkg/util"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/discovery"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/discovery"
"regexp"
"sort"
"strconv"
diff --git a/server/service/util/versionrule_test.go b/server/service/util/versionrule_test.go
index 128e2f0..6e6b947 100644
--- a/server/service/util/versionrule_test.go
+++ b/server/service/util/versionrule_test.go
@@ -18,7 +18,7 @@ package util
import (
"fmt"
- "github.com/apache/incubator-servicecomb-service-center/server/infra/discovery"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/discovery"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"sort"
diff --git a/server/version.go b/server/version.go
index 090d090..89c2658 100644
--- a/server/version.go
+++ b/server/version.go
@@ -21,7 +21,7 @@ import (
"github.com/apache/incubator-servicecomb-service-center/pkg/log"
"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/infra/registry"
+ "github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/registry"
"golang.org/x/net/context"
)