Skip to content
Snippets Groups Projects
Commit 690333bc authored by vito.he's avatar vito.he
Browse files

Mod:resolve conflict

parents 485cd5f7 2a60e2b0
No related branches found
No related tags found
No related merge requests found
Showing
with 336 additions and 161 deletions
......@@ -63,6 +63,7 @@ type ReferenceConfig struct {
Generic bool `yaml:"generic" json:"generic,omitempty" property:"generic"`
Sticky bool `yaml:"sticky" json:"sticky,omitempty" property:"sticky"`
RequestTimeout string `yaml:"timeout" json:"timeout,omitempty" property:"timeout"`
ForceTag bool `yaml:"force.tag" json:"force.tag,omitempty" property:"force.tag"`
}
// Prefix ...
......@@ -99,7 +100,9 @@ func (c *ReferenceConfig) Refer(_ interface{}) {
common.WithParams(c.getUrlMap()),
common.WithParamsValue(constant.BEAN_NAME_KEY, c.id),
)
if c.ForceTag {
cfgURL.AddParam(constant.ForceUseTag, "true")
}
if c.Url != "" {
// 1. user specified URL, could be peer-to-peer address, or register center's address.
urlStrings := gxstrings.RegSplit(c.Url, "\\s*[;]+\\s*")
......@@ -186,7 +189,7 @@ func (c *ReferenceConfig) getUrlMap() url.Values {
urlMap.Set(constant.GENERIC_KEY, strconv.FormatBool(c.Generic))
urlMap.Set(constant.ROLE_KEY, strconv.Itoa(common.CONSUMER))
urlMap.Set(constant.CATEGORY_KEY, (common.RoleType(common.CONSUMER)).String())
urlMap.Set(constant.DUBBO_KEY, "dubbo-consumer-golang-"+constant.Version)
urlMap.Set(constant.RELEASE_KEY, "dubbo-golang-"+constant.Version)
urlMap.Set(constant.SIDE_KEY, (common.RoleType(common.CONSUMER)).Role())
if len(c.RequestTimeout) != 0 {
......
......@@ -28,13 +28,14 @@ import (
"github.com/apache/dubbo-go/common/yaml"
)
//RouterInit Load config file to init router config
// RouterInit Load config file to init router config
func RouterInit(confRouterFile string) error {
fileRouterFactories := extension.GetFileRouterFactories()
bytes, err := yaml.LoadYMLConfig(confRouterFile)
if err != nil {
return perrors.Errorf("ioutil.ReadFile(file:%s) = error:%v", confRouterFile, perrors.WithStack(err))
}
logger.Warnf("get fileRouterFactories len{%+v})", len(fileRouterFactories))
for k, factory := range fileRouterFactories {
r, e := factory.NewFileRouter(bytes)
if e == nil {
......@@ -42,7 +43,7 @@ func RouterInit(confRouterFile string) error {
directory.AddRouterURLSet(&url)
return nil
}
logger.Warnf("router config type %s create fail \n", k)
logger.Warnf("router config type %s create fail {%v}\n", k, e)
}
return perrors.Errorf("no file router exists for parse %s , implement router.FIleRouterFactory please.", confRouterFile)
}
......@@ -69,6 +69,7 @@ type ServiceConfig struct {
ExecuteLimitRejectedHandler string `yaml:"execute.limit.rejected.handler" json:"execute.limit.rejected.handler,omitempty" property:"execute.limit.rejected.handler"`
Auth string `yaml:"auth" json:"auth,omitempty" property:"auth"`
ParamSign string `yaml:"param.sign" json:"param.sign,omitempty" property:"param.sign"`
Tag string `yaml:"tag" json:"tag,omitempty" property:"tag"`
unexported *atomic.Bool
exported *atomic.Bool
......@@ -144,7 +145,9 @@ func (c *ServiceConfig) Export() error {
common.WithMethods(strings.Split(methods, ",")),
common.WithToken(c.Token),
)
if len(c.Tag) > 0 {
ivkURL.AddParam(constant.Tagkey, c.Tag)
}
if len(regUrls) > 0 {
for _, regUrl := range regUrls {
regUrl.SubURL = ivkURL
......@@ -194,7 +197,7 @@ func (c *ServiceConfig) getUrlMap() url.Values {
urlMap.Set(constant.VERSION_KEY, c.Version)
urlMap.Set(constant.ROLE_KEY, strconv.Itoa(common.PROVIDER))
urlMap.Set(constant.CATEGORY_KEY, (common.RoleType(common.PROVIDER)).String())
urlMap.Set(constant.DUBBO_KEY, "dubbo-provider-golang-"+constant.Version)
urlMap.Set(constant.RELEASE_KEY, "dubbo-golang-"+constant.Version)
urlMap.Set(constant.SIDE_KEY, (common.RoleType(common.PROVIDER)).Role())
// application info
......
/*
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 apollo
......
/*
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 apollo
......
/*
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 apollo
......
/*
* 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 filter_impl
import (
......
/*
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 filter_impl
......
/*
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 filter_impl
......
// 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.
*/
// Code generated by MockGen. DO NOT EDIT.
// Source: tps_limit_strategy.go
......
// 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.
*/
// Code generated by MockGen. DO NOT EDIT.
// Source: tps_limiter.go
......
// 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.
*/
// Code generated by MockGen. DO NOT EDIT.
// Source: rejected_execution_handler.go
......
......@@ -5,6 +5,7 @@ require (
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5
github.com/aliyun/alibaba-cloud-sdk-go v0.0.0-20190802083043-4cd0c391755e // indirect
github.com/apache/dubbo-go-hessian2 v1.4.0
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869
github.com/buger/jsonparser v0.0.0-20181115193947-bf1c66bbce23 // indirect
github.com/coreos/bbolt v1.3.3 // indirect
github.com/coreos/etcd v3.3.13+incompatible
......@@ -14,7 +15,7 @@ require (
github.com/creasty/defaults v1.3.0
github.com/dubbogo/getty v1.3.3
github.com/dubbogo/go-zookeeper v1.0.0
github.com/dubbogo/gost v1.7.0
github.com/dubbogo/gost v1.8.0
github.com/emicklei/go-restful/v3 v3.0.0
github.com/emirpasic/gods v1.12.0
github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239 // indirect
......
......@@ -111,20 +111,19 @@ github.com/dubbogo/getty v1.3.3/go.mod h1:U92BDyJ6sW9Jpohr2Vlz8w2uUbIbNZ3d+6rJvF
github.com/dubbogo/go-zookeeper v1.0.0 h1:RsYdlGwhDW+iKXM3eIIcvt34P2swLdmQfuIJxsHlGoM=
github.com/dubbogo/go-zookeeper v1.0.0/go.mod h1:fn6n2CAEer3novYgk9ULLwAjuV8/g4DdC2ENwRb6E+c=
github.com/dubbogo/gost v1.5.1/go.mod h1:pPTjVyoJan3aPxBPNUX0ADkXjPibLo+/Ib0/fADXSG8=
github.com/dubbogo/gost v1.5.2 h1:ri/03971hdpnn3QeCU+4UZgnRNGDXLDGDucR/iozZm8=
github.com/dubbogo/gost v1.5.2/go.mod h1:pPTjVyoJan3aPxBPNUX0ADkXjPibLo+/Ib0/fADXSG8=
github.com/dubbogo/gost v1.7.0 h1:lWNBIE2hk1Aj2be2uXkyRTpZG0RQZj0/xbXnkIq6EHE=
github.com/dubbogo/gost v1.7.0/go.mod h1:pPTjVyoJan3aPxBPNUX0ADkXjPibLo+/Ib0/fADXSG8=
github.com/dubbogo/gost v1.8.0 h1:9ACbQe5OwMjqtinQcNJC5xp16kky27OsfSGw5L9A6vw=
github.com/dubbogo/gost v1.8.0/go.mod h1:pPTjVyoJan3aPxBPNUX0ADkXjPibLo+/Ib0/fADXSG8=
github.com/duosecurity/duo_api_golang v0.0.0-20190308151101-6c680f768e74 h1:2MIhn2R6oXQbgW5yHfS+d6YqyMfXiu2L55rFZC4UD/M=
github.com/duosecurity/duo_api_golang v0.0.0-20190308151101-6c680f768e74/go.mod h1:UqXY1lYT/ERa4OEAywUqdok1T4RCRdArkhic1Opuavo=
github.com/elazarl/go-bindata-assetfs v0.0.0-20160803192304-e1a2a7ec64b0 h1:ZoRgc53qJCfSLimXqJDrmBhnt5GChDsExMCK7t48o0Y=
github.com/elazarl/go-bindata-assetfs v0.0.0-20160803192304-e1a2a7ec64b0/go.mod h1:v+YaWX3bdea5J/mo8dSETolEo7R71Vk1u8bnjau5yw4=
github.com/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg=
github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o=
github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633 h1:H2pdYOb3KQ1/YsqVWoWNLQO+fusocsw354rqGTZtAgw=
github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs=
github.com/emicklei/go-restful/v3 v3.0.0 h1:Duxxa4x0WIHW3bYEDmoAPNjmy8Rbqn+utcF74dlF/G8=
github.com/emicklei/go-restful/v3 v3.0.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc=
github.com/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg=
github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o=
github.com/envoyproxy/go-control-plane v0.8.0 h1:uE6Fp4fOcAJdc1wTQXLJ+SYistkbG1dNoi6Zs1+Ybvk=
github.com/envoyproxy/go-control-plane v0.8.0/go.mod h1:GSSbY9P1neVhdY7G4wu+IK1rk/dqhiCC/4ExuWJZVuk=
github.com/envoyproxy/protoc-gen-validate v0.0.14 h1:YBW6/cKy9prEGRYLnaGa4IDhzxZhRCtKsax8srGKDnM=
......
......@@ -17,6 +17,10 @@
package definition
import (
"bytes"
)
type ServiceDefinition struct {
CanonicalName string
CodeSource string
......@@ -39,3 +43,25 @@ type TypeDefinition struct {
Properties map[string]TypeDefinition
TypeBuilderName string
}
// name...
func ServiceDefinitionBuild() *ServiceDefinition {
sd := &ServiceDefinition{}
return sd
}
// ServiceDescriperBuild: build the service key, format is `group/serviceName:version` which be same as URL's service key
func ServiceDescriperBuild(serviceName string, group string, version string) string {
buf := &bytes.Buffer{}
if group != "" {
buf.WriteString(group)
buf.WriteString("/")
}
buf.WriteString(serviceName)
if version != "" && version != "0.0.0" {
buf.WriteString(":")
buf.WriteString(version)
}
return buf.String()
}
......@@ -65,7 +65,7 @@ func (mdi *BaseServiceMetadataIdentifier) getFilePathKey(params ...string) strin
withPathSeparator(mdi.version) +
withPathSeparator(mdi.group) +
withPathSeparator(mdi.side) +
joinParams(constant.PATH_SEPARATOR, params)
joinParams("/", params)
}
......@@ -86,7 +86,7 @@ func serviceToPath(serviceInterface string) string {
//withPathSeparator...
func withPathSeparator(path string) string {
if len(path) != 0 {
path = constant.PATH_SEPARATOR + path
path = "/" + path
}
return path
}
......@@ -29,3 +29,6 @@ var (
type MetadataReportFactory interface {
CreateMetadataReport(*common.URL) report.MetadataReport
}
type BaseMetadataReportFactory struct {
}
......@@ -21,26 +21,40 @@ import (
)
import (
"github.com/apache/dubbo-go/common/logger"
"github.com/emirpasic/gods/sets"
"github.com/emirpasic/gods/sets/treeset"
"github.com/emirpasic/gods/utils"
)
import (
"github.com/apache/dubbo-go/common"
"github.com/apache/dubbo-go/common/constant"
"github.com/apache/dubbo-go/metadata/definition"
"github.com/apache/dubbo-go/metadata/service"
)
// InMemoryMetadataService is store and query the metadata info in memory when each service registry
type MetadataService struct {
service.BaseMetadataService
exportedServiceURLs sync.Map
subscribedServiceURLs sync.Map
exportedServiceURLs *sync.Map
subscribedServiceURLs *sync.Map
lock *sync.RWMutex
}
// NewMetadataService: initiate a metadata service
func NewMetadataService() *MetadataService {
return &MetadataService{
exportedServiceURLs: new(sync.Map),
subscribedServiceURLs: new(sync.Map),
lock: new(sync.RWMutex),
}
}
// urlComparator: defined as utils.Comparator for treeset to compare the URL
func urlComparator(a, b interface{}) int {
url1 := a.(common.URL)
url2 := b.(common.URL)
url1 := a.(*common.URL)
url2 := b.(*common.URL)
switch {
case url1.String() > url2.String():
return 1
......@@ -52,62 +66,130 @@ func urlComparator(a, b interface{}) int {
}
// addURL: add URL in memory
func addURL(targetMap sync.Map, url common.URL) bool {
func (mts *MetadataService) addURL(targetMap *sync.Map, url *common.URL) bool {
var (
urlSet interface{}
loaded bool
lock sync.RWMutex
)
logger.Debug(url.ServiceKey())
if urlSet, loaded = targetMap.LoadOrStore(url.ServiceKey(), treeset.NewWith(urlComparator)); loaded {
lock.RLock()
if urlSet.(treeset.Set).Contains(url) {
lock.RUnlock()
mts.lock.RLock()
if urlSet.(*treeset.Set).Contains(url) {
mts.lock.RUnlock()
return false
}
lock.RUnlock()
mts.lock.RUnlock()
}
lock.Lock()
urlSet.(treeset.Set).Add(url)
lock.Unlock()
mts.lock.Lock()
//double chk
if urlSet.(*treeset.Set).Contains(url) {
mts.lock.Unlock()
return false
}
urlSet.(*treeset.Set).Add(url)
mts.lock.Unlock()
return true
}
// name...
func removeURL(targetMap sync.Map, url common.URL) string {
// removeURL: used to remove specified url
func (mts *MetadataService) removeURL(targetMap *sync.Map, url *common.URL) {
if value, loaded := targetMap.Load(url.ServiceKey()); loaded {
value.(treeset.Set).Remove(url)
if value.(treeset.Set).Empty() {
mts.lock.Lock()
value.(*treeset.Set).Remove(url)
mts.lock.Unlock()
mts.lock.RLock()
defer mts.lock.RUnlock()
if value.(*treeset.Set).Empty() {
targetMap.Delete(url.ServiceKey())
}
}
}
// getAllService: return all the exportedUrlString except for metadataService
func (mts *MetadataService) getAllService(services *sync.Map) sets.Set {
sets := treeset.NewWith(utils.StringComparator)
services.Range(func(key, value interface{}) bool {
urls := value.(*treeset.Set)
urls.Each(func(index int, value interface{}) {
url := value.(*common.URL)
if url.GetParam(constant.INTERFACE_KEY, url.Path) != "MetadataService" {
sets.Add(url.String())
}
})
return true
})
return sets
}
// getSpecifiedService: return specified service url by serviceKey
func (mts *MetadataService) getSpecifiedService(services *sync.Map, serviceKey string, protocol string) sets.Set {
targetSets := treeset.NewWith(utils.StringComparator)
serviceSet, loaded := services.Load(serviceKey)
if loaded {
serviceSet.(*treeset.Set).Each(func(index int, value interface{}) {
url := value.(*common.URL)
if len(protocol) == 0 || url.Protocol == protocol || url.GetParam(constant.PROTOCOL_KEY, "") == protocol {
targetSets.Add(value.(*common.URL).String())
}
})
}
return targetSets
}
// ExportURL: store the in memory treeset
func (mts *MetadataService) ExportURL(url common.URL) bool {
return addURL(mts.exportedServiceURLs, url)
return mts.addURL(mts.exportedServiceURLs, &url)
}
func (MetadataService) UnexportURL(url common.URL) bool {
panic("implement me")
// UnexportURL: remove the url store in memory treeset
func (mts *MetadataService) UnexportURL(url common.URL) {
mts.removeURL(mts.exportedServiceURLs, &url)
}
// SubscribeURL...
func (mts *MetadataService) SubscribeURL(url common.URL) bool {
return addURL(mts.subscribedServiceURLs, url)
return mts.addURL(mts.subscribedServiceURLs, &url)
}
func (MetadataService) UnsubscribeURL(url common.URL) bool {
panic("implement me")
// UnsubscribeURL...
func (mts *MetadataService) UnsubscribeURL(url common.URL) {
mts.removeURL(mts.subscribedServiceURLs, &url)
}
// PublishServiceDefinition: publish url's service metadata info, and write into memory
func (MetadataService) PublishServiceDefinition(url common.URL) {
panic("implement me")
interfaceName := url.GetParam(constant.INTERFACE_KEY, "")
isGeneric := url.GetParamBool(constant.GENERIC_KEY, false)
if len(interfaceName) > 0 && !isGeneric {
//judge is consumer or provider
role := url.GetParam(constant.SIDE_KEY, "")
//var service common.RPCService
if role == common.RoleType(common.CONSUMER).Role() {
//TODO:BOSS FANG
} else if role == common.RoleType(common.PROVIDER).Role() {
//TODO:BOSS FANG
}
}
}
func (MetadataService) GetExportedURLs(serviceInterface string, group string, version string, protocol string) sets.Set {
panic("implement me")
// GetExportedURLs get all exported urls
func (mts *MetadataService) GetExportedURLs(serviceInterface string, group string, version string, protocol string) sets.Set {
if serviceInterface == constant.ANY_VALUE {
return mts.getAllService(mts.exportedServiceURLs)
} else {
serviceKey := definition.ServiceDescriperBuild(serviceInterface, group, version)
return mts.getSpecifiedService(mts.exportedServiceURLs, serviceKey, protocol)
}
}
// GetSubscribedURLs get all subscribedUrl
func (mts *MetadataService) GetSubscribedURLs() sets.Set {
return mts.getAllService(mts.subscribedServiceURLs)
}
func (MetadataService) GetServiceDefinition(interfaceName string, version string, group string) string {
func (MetadataService) GetServiceDefinition(interfaceName string, group string, version string) string {
panic("implement me")
}
......
package inmemory
import (
"fmt"
"github.com/apache/dubbo-go/common"
"github.com/bmizerany/assert"
"testing"
)
func TestMetadataService(t *testing.T) {
mts := NewMetadataService()
serviceName := "com.ikurento.user.UserProvider"
group := "group1"
version := "0.0.1"
protocol := "dubbo"
u, _ := common.NewURL(fmt.Sprintf("%v://127.0.0.1:20000/com.ikurento.user.UserProvider?anyhost=true&"+
"application=BDTService&category=providers&default.timeout=10000&dubbo=dubbo-provider-golang-1.0.0&"+
"environment=dev&interface=%v&ip=192.168.56.1&methods=GetUser&"+
"module=dubbogo+user-info+server&org=ikurento.com&owner=ZX&pid=1447&revision=0.0.1&"+
"side=provider&timeout=3000&timestamp=1556509797245&group=%v&version=%v", protocol, serviceName, group, version))
mts.ExportURL(u)
sets := mts.GetExportedURLs(serviceName, group, version, protocol)
assert.Equal(t, 1, sets.Size())
mts.SubscribeURL(u)
mts.SubscribeURL(u)
sets2 := mts.GetSubscribedURLs()
assert.Equal(t, 1, sets2.Size())
mts.UnexportURL(u)
sets11 := mts.GetExportedURLs(serviceName, group, version, protocol)
assert.Equal(t, 0, sets11.Size())
mts.UnsubscribeURL(u)
sets22 := mts.GetSubscribedURLs()
assert.Equal(t, 0, sets22.Size())
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment