Code clean at metadata service. (#8161)
* code clean at metadata service. * code clean. * code clean. * code clean. publish service definition is not provider side particular.
This commit is contained in:
parent
bb6d62b858
commit
23f19ce19c
|
|
@ -29,7 +29,7 @@ public class ConfigItem {
|
|||
/**
|
||||
* version information corresponding to the current configure item.
|
||||
*/
|
||||
private Object stat;
|
||||
private Object ticket;
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
|
|
@ -39,17 +39,17 @@ public class ConfigItem {
|
|||
this.content = content;
|
||||
}
|
||||
|
||||
public Object getStat() {
|
||||
return stat;
|
||||
public Object getTicket() {
|
||||
return ticket;
|
||||
}
|
||||
|
||||
public void setStat(Object stat) {
|
||||
this.stat = stat;
|
||||
public void setTicket(Object ticket) {
|
||||
this.ticket = ticket;
|
||||
}
|
||||
|
||||
public ConfigItem(String content, Object stat) {
|
||||
public ConfigItem(String content, Object ticket) {
|
||||
this.content = content;
|
||||
this.stat = stat;
|
||||
this.ticket = ticket;
|
||||
}
|
||||
|
||||
public ConfigItem() {
|
||||
|
|
|
|||
|
|
@ -149,11 +149,11 @@ public class ZookeeperDynamicConfigurationTest {
|
|||
String group = "org.apache.dubbo.service.UserService";
|
||||
String content = "test";
|
||||
ConfigItem configItem = configuration.getConfigItem(key, group);
|
||||
assertTrue(configuration.publishConfigCas(key, group, content, configItem.getStat()));
|
||||
assertTrue(configuration.publishConfigCas(key, group, content, configItem.getTicket()));
|
||||
configItem = configuration.getConfigItem(key, group);
|
||||
assertEquals("test", configItem.getContent());
|
||||
assertTrue(configuration.publishConfigCas(key, group, "newtest", configItem.getStat()));
|
||||
assertFalse(configuration.publishConfigCas(key, group, "newtest2", configItem.getStat()));
|
||||
assertTrue(configuration.publishConfigCas(key, group, "newtest", configItem.getTicket()));
|
||||
assertFalse(configuration.publishConfigCas(key, group, "newtest2", configItem.getTicket()));
|
||||
assertEquals("newtest", configuration.getConfigItem(key, group).getContent());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ public interface WritableMetadataService extends MetadataService {
|
|||
*/
|
||||
boolean unsubscribeURL(URL url);
|
||||
|
||||
void publishServiceDefinition(URL providerUrl);
|
||||
void publishServiceDefinition(URL url);
|
||||
|
||||
default void setMetadataServiceURL(URL url) {
|
||||
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ public class MetadataServiceNameMapping extends AbstractServiceNameMapping {
|
|||
}
|
||||
newConfigContent = oldConfigContent + COMMA_SEPARATOR + getName();
|
||||
}
|
||||
success = metadataReport.registerServiceAppMapping(serviceInterface, DEFAULT_MAPPING_GROUP, newConfigContent, configItem.getStat());
|
||||
success = metadataReport.registerServiceAppMapping(serviceInterface, DEFAULT_MAPPING_GROUP, newConfigContent, configItem.getTicket());
|
||||
} while (!success && currentRetryTimes++ <= CAS_RETRY_TIMES);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -201,25 +201,25 @@ public class InMemoryWritableMetadataService implements WritableMetadataService
|
|||
}
|
||||
|
||||
@Override
|
||||
public void publishServiceDefinition(URL providerUrl) {
|
||||
public void publishServiceDefinition(URL url) {
|
||||
try {
|
||||
String interfaceName = providerUrl.getServiceInterface();
|
||||
String interfaceName = url.getServiceInterface();
|
||||
if (StringUtils.isNotEmpty(interfaceName)
|
||||
&& !ProtocolUtils.isGeneric(providerUrl.getParameter(GENERIC_KEY))) {
|
||||
&& !ProtocolUtils.isGeneric(url.getParameter(GENERIC_KEY))) {
|
||||
Class interfaceClass = Class.forName(interfaceName);
|
||||
ServiceDefinition serviceDefinition = ServiceDefinitionBuilder.build(interfaceClass);
|
||||
Gson gson = new Gson();
|
||||
String data = gson.toJson(serviceDefinition);
|
||||
serviceDefinitions.put(providerUrl.getServiceKey(), data);
|
||||
serviceDefinitions.put(url.getServiceKey(), data);
|
||||
return;
|
||||
} else if (CONSUMER_SIDE.equalsIgnoreCase(providerUrl.getParameter(SIDE_KEY))) {
|
||||
} else if (CONSUMER_SIDE.equalsIgnoreCase(url.getParameter(SIDE_KEY))) {
|
||||
//to avoid consumer generic invoke style error
|
||||
return;
|
||||
}
|
||||
logger.error("publishProvider interfaceName is empty . providerUrl: " + providerUrl.toFullString());
|
||||
logger.error("publish service definition interfaceName is empty. url: " + url.toFullString());
|
||||
} catch (Throwable e) {
|
||||
//ignore error
|
||||
logger.error("publishProvider getServiceDescriptor error. providerUrl: " + providerUrl.toFullString(), e);
|
||||
logger.error("publish service definition getServiceDescriptor error. url: " + url.toFullString(), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -30,7 +30,6 @@ import org.apache.dubbo.metadata.report.identifier.MetadataIdentifier;
|
|||
import org.apache.dubbo.metadata.report.identifier.SubscriberMetadataIdentifier;
|
||||
import org.apache.dubbo.registry.client.ServiceInstance;
|
||||
import org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils;
|
||||
import org.apache.dubbo.remoting.Constants;
|
||||
import org.apache.dubbo.rpc.RpcException;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
|
@ -41,6 +40,9 @@ import static org.apache.dubbo.common.constants.CommonConstants.PID_KEY;
|
|||
import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER_SIDE;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.TIMESTAMP_KEY;
|
||||
import static org.apache.dubbo.common.constants.RegistryConstants.REGISTRY_CLUSTER_KEY;
|
||||
import static org.apache.dubbo.registry.Constants.REGISTER_IP_KEY;
|
||||
import static org.apache.dubbo.remoting.Constants.BIND_IP_KEY;
|
||||
import static org.apache.dubbo.remoting.Constants.BIND_PORT_KEY;
|
||||
|
||||
public class RemoteMetadataServiceImpl {
|
||||
protected final Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
|
@ -72,8 +74,7 @@ public class RemoteMetadataServiceImpl {
|
|||
metadataReport.publishAppMetadata(identifier, metadataInfo);
|
||||
} else {
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Remote Metadata Report Server not hasn't been configured. " +
|
||||
"Only publish Metadata to local.");
|
||||
logger.info("Remote Metadata Report Server not hasn't been configured. Only publish Metadata to local.");
|
||||
}
|
||||
}
|
||||
metadataInfo.markReported();
|
||||
|
|
@ -83,7 +84,7 @@ public class RemoteMetadataServiceImpl {
|
|||
|
||||
public MetadataInfo getMetadata(ServiceInstance instance) {
|
||||
SubscriberMetadataIdentifier identifier = new SubscriberMetadataIdentifier(instance.getServiceName(),
|
||||
ServiceInstanceMetadataUtils.getExportedServicesRevision(instance));
|
||||
ServiceInstanceMetadataUtils.getExportedServicesRevision(instance));
|
||||
|
||||
String registryCluster = instance.getRegistryCluster();
|
||||
|
||||
|
|
@ -102,18 +103,17 @@ public class RemoteMetadataServiceImpl {
|
|||
|
||||
private void checkRemoteConfigured() {
|
||||
if (getMetadataReports().size() == 0) {
|
||||
String msg = "Remote Metadata Report Server not hasn't been configured. " +
|
||||
"Unable to get Metadata from remote!";
|
||||
String msg = "Remote Metadata Report Server not hasn't been configured. Unable to get Metadata from remote!";
|
||||
logger.error(msg);
|
||||
throw new IllegalStateException(msg);
|
||||
}
|
||||
}
|
||||
|
||||
public void publishServiceDefinition(URL url) {
|
||||
String side = url.getSide();
|
||||
|
||||
checkRemoteConfigured();
|
||||
|
||||
String side = url.getSide();
|
||||
|
||||
if (PROVIDER_SIDE.equalsIgnoreCase(side)) {
|
||||
//TODO, the params part is duplicate with that stored by exportURL(url), can be further optimized in the future.
|
||||
publishProvider(url);
|
||||
|
|
@ -126,24 +126,23 @@ public class RemoteMetadataServiceImpl {
|
|||
private void publishProvider(URL providerUrl) throws RpcException {
|
||||
//first add into the list
|
||||
// remove the individual param
|
||||
providerUrl = providerUrl.removeParameters(PID_KEY, TIMESTAMP_KEY, Constants.BIND_IP_KEY,
|
||||
Constants.BIND_PORT_KEY, TIMESTAMP_KEY);
|
||||
providerUrl = providerUrl.removeParameters(PID_KEY, TIMESTAMP_KEY, BIND_IP_KEY, BIND_PORT_KEY);
|
||||
|
||||
try {
|
||||
String interfaceName = providerUrl.getServiceInterface();
|
||||
if (StringUtils.isNotEmpty(interfaceName)) {
|
||||
Class interfaceClass = Class.forName(interfaceName);
|
||||
FullServiceDefinition fullServiceDefinition = ServiceDefinitionBuilder.buildFullDefinition(interfaceClass,
|
||||
providerUrl.getParameters());
|
||||
providerUrl.getParameters());
|
||||
for (Map.Entry<String, MetadataReport> entry : getMetadataReports().entrySet()) {
|
||||
MetadataReport metadataReport = entry.getValue();
|
||||
metadataReport.storeProviderMetadata(new MetadataIdentifier(providerUrl.getServiceInterface(),
|
||||
providerUrl.getVersion(), providerUrl.getGroup(),
|
||||
PROVIDER_SIDE, providerUrl.getApplication()), fullServiceDefinition);
|
||||
providerUrl.getVersion(), providerUrl.getGroup(),
|
||||
PROVIDER_SIDE, providerUrl.getApplication()), fullServiceDefinition);
|
||||
}
|
||||
return;
|
||||
}
|
||||
logger.error("publishProvider interfaceName is empty . providerUrl: " + providerUrl.toFullString());
|
||||
logger.error("publishProvider interfaceName is empty. providerUrl: " + providerUrl.toFullString());
|
||||
} catch (ClassNotFoundException e) {
|
||||
//ignore error
|
||||
logger.error("publishProvider getServiceDescriptor error. providerUrl: " + providerUrl.toFullString(), e);
|
||||
|
|
@ -151,12 +150,11 @@ public class RemoteMetadataServiceImpl {
|
|||
}
|
||||
|
||||
private void publishConsumer(URL consumerURL) throws RpcException {
|
||||
final URL url = consumerURL.removeParameters(PID_KEY, TIMESTAMP_KEY, Constants.BIND_IP_KEY,
|
||||
Constants.BIND_PORT_KEY, TIMESTAMP_KEY);
|
||||
final URL url = consumerURL.removeParameters(PID_KEY, TIMESTAMP_KEY, BIND_IP_KEY, BIND_PORT_KEY, REGISTER_IP_KEY);
|
||||
getMetadataReports().forEach((registryKey, config) -> {
|
||||
config.storeConsumerMetadata(new MetadataIdentifier(url.getServiceInterface(),
|
||||
url.getVersion(), url.getGroup(), CONSUMER_SIDE,
|
||||
url.getApplication()), url.getParameters());
|
||||
url.getVersion(), url.getGroup(), CONSUMER_SIDE,
|
||||
url.getApplication()), url.getParameters());
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue