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