-
Notifications
You must be signed in to change notification settings - Fork 929
/
service_proxy.go
190 lines (163 loc) · 6.13 KB
/
service_proxy.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/*
* 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 local
import (
"context"
"reflect"
)
import (
"github.com/dubbogo/gost/log/logger"
)
import (
"dubbo.apache.org/dubbo-go/v3/common"
"dubbo.apache.org/dubbo-go/v3/common/constant"
"dubbo.apache.org/dubbo-go/v3/protocol"
"dubbo.apache.org/dubbo-go/v3/protocol/invocation"
)
// MetadataServiceProxy actually is a RPC stub which will only be used by client-side.
// If the metadata service is "local" metadata service in server side, which means that
// metadata service is RPC service too. So in client-side, if we want to get the metadata
// information, we must call metadata service .This is the stub, or proxy for now, only
// GetMetadataInfo need to be implemented.
// TODO use ProxyFactory to create proxy
type MetadataServiceProxy struct {
Invoker protocol.Invoker
}
// nolint
func (m *MetadataServiceProxy) GetExportedURLs(serviceInterface string, group string, version string, protocol string) ([]*common.URL, error) {
siV := reflect.ValueOf(serviceInterface)
gV := reflect.ValueOf(group)
vV := reflect.ValueOf(version)
pV := reflect.ValueOf(protocol)
const methodName = "getExportedURLs"
inv := invocation.NewRPCInvocationWithOptions(invocation.WithMethodName(methodName),
invocation.WithArguments([]interface{}{siV.Interface(), gV.Interface(), vV.Interface(), pV.Interface()}),
invocation.WithReply(reflect.ValueOf(&[]interface{}{}).Interface()),
invocation.WithAttachments(map[string]interface{}{constant.AsyncKey: "false"}),
invocation.WithParameterValues([]reflect.Value{siV, gV, vV, pV}))
res := m.Invoker.Invoke(context.Background(), inv)
if res.Error() != nil {
logger.Errorf("could not get the metadata service from remote provider: %v", res.Error())
return []*common.URL{}, nil
}
urlStrs := res.Result().([]string)
ret := make([]*common.URL, 0, len(urlStrs))
for _, v := range urlStrs {
tempURL, err := common.NewURL(v)
if err != nil {
return []*common.URL{}, err
}
ret = append(ret, tempURL)
}
return ret, nil
}
// nolint
func (m *MetadataServiceProxy) GetExportedServiceURLs() ([]*common.URL, error) {
logger.Error("you should never invoke this implementation")
return nil, nil
}
// nolint
func (m *MetadataServiceProxy) GetMetadataServiceURL() (*common.URL, error) {
logger.Error("you should never invoke this implementation")
return nil, nil
}
// nolint
func (m *MetadataServiceProxy) SetMetadataServiceURL(*common.URL) error {
logger.Error("you should never invoke this implementation")
return nil
}
// nolint
func (m *MetadataServiceProxy) MethodMapper() map[string]string {
return map[string]string{}
}
// nolint
func (m *MetadataServiceProxy) Reference() string {
logger.Error("you should never invoke this implementation")
return constant.MetadataServiceName
}
// nolint
func (m *MetadataServiceProxy) ServiceName() (string, error) {
logger.Error("you should never invoke this implementation")
return "", nil
}
// nolint
func (m *MetadataServiceProxy) ExportURL(url *common.URL) (bool, error) {
logger.Error("you should never invoke this implementation")
return false, nil
}
// nolint
func (m *MetadataServiceProxy) UnexportURL(url *common.URL) error {
logger.Error("you should never invoke this implementation")
return nil
}
// nolint
func (m *MetadataServiceProxy) SubscribeURL(url *common.URL) (bool, error) {
logger.Error("you should never invoke this implementation")
return false, nil
}
// nolint
func (m *MetadataServiceProxy) UnsubscribeURL(url *common.URL) error {
logger.Error("you should never invoke this implementation")
return nil
}
// nolint
func (m *MetadataServiceProxy) PublishServiceDefinition(url *common.URL) error {
logger.Error("you should never invoke this implementation")
return nil
}
// nolint
func (m *MetadataServiceProxy) GetSubscribedURLs() ([]*common.URL, error) {
logger.Error("you should never invoke this implementation")
return nil, nil
}
// nolint
func (m *MetadataServiceProxy) GetServiceDefinition(interfaceName string, group string, version string) (string, error) {
logger.Error("you should never invoke this implementation")
return "", nil
}
// nolint
func (m *MetadataServiceProxy) GetServiceDefinitionByServiceKey(serviceKey string) (string, error) {
logger.Error("you should never invoke this implementation")
return "", nil
}
// nolint
func (m *MetadataServiceProxy) RefreshMetadata(exportedRevision string, subscribedRevision string) (bool, error) {
logger.Error("you should never invoke this implementation")
return false, nil
}
// nolint
func (m *MetadataServiceProxy) Version() (string, error) {
logger.Error("you should never invoke this implementation")
return "", nil
}
// nolint
func (m *MetadataServiceProxy) GetMetadataInfo(revision string) (*common.MetadataInfo, error) {
rV := reflect.ValueOf(revision)
const methodName = "getMetadataInfo"
inv := invocation.NewRPCInvocationWithOptions(invocation.WithMethodName(methodName),
invocation.WithArguments([]interface{}{rV.Interface()}),
invocation.WithReply(reflect.ValueOf(&common.MetadataInfo{}).Interface()),
invocation.WithAttachments(map[string]interface{}{constant.AsyncKey: "false"}),
invocation.WithParameterValues([]reflect.Value{rV}))
res := m.Invoker.Invoke(context.Background(), inv)
if res.Error() != nil {
logger.Errorf("could not get the metadata info from remote provider: %v", res.Error())
return nil, res.Error()
}
metaDataInfo := res.Result().(*common.MetadataInfo)
return metaDataInfo, nil
}