use of org.apache.dubbo.metadata.report.identifier.MetadataIdentifier in project dubbo by alibaba.
the class ZookeeperMetadataReportTest method testStoreProvider.
@Test
public void testStoreProvider() throws ClassNotFoundException, InterruptedException {
String interfaceName = "org.apache.dubbo.metadata.store.zookeeper.ZookeeperMetadataReport4TstService";
String version = "1.0.0.zk.md";
String group = null;
String application = "vic.zk.md";
MetadataIdentifier providerMetadataIdentifier = storePrivider(zookeeperMetadataReport, interfaceName, version, group, application);
String fileContent = zookeeperMetadataReport.zkClient.getContent(zookeeperMetadataReport.getNodePath(providerMetadataIdentifier));
fileContent = waitSeconds(fileContent, 3500, zookeeperMetadataReport.getNodePath(providerMetadataIdentifier));
Assertions.assertNotNull(fileContent);
deletePath(providerMetadataIdentifier, zookeeperMetadataReport);
fileContent = zookeeperMetadataReport.zkClient.getContent(zookeeperMetadataReport.getNodePath(providerMetadataIdentifier));
fileContent = waitSeconds(fileContent, 1000, zookeeperMetadataReport.getNodePath(providerMetadataIdentifier));
Assertions.assertNull(fileContent);
providerMetadataIdentifier = storePrivider(zookeeperMetadataReport, interfaceName, version, group, application);
fileContent = zookeeperMetadataReport.zkClient.getContent(zookeeperMetadataReport.getNodePath(providerMetadataIdentifier));
fileContent = waitSeconds(fileContent, 3500, zookeeperMetadataReport.getNodePath(providerMetadataIdentifier));
Assertions.assertNotNull(fileContent);
Gson gson = new Gson();
FullServiceDefinition fullServiceDefinition = gson.fromJson(fileContent, FullServiceDefinition.class);
Assertions.assertEquals(fullServiceDefinition.getParameters().get("paramTest"), "zkTest");
}
use of org.apache.dubbo.metadata.report.identifier.MetadataIdentifier in project dubbo by alibaba.
the class ZookeeperMetadataReportTest method storePrivider.
private MetadataIdentifier storePrivider(MetadataReport zookeeperMetadataReport, String interfaceName, String version, String group, String application) throws ClassNotFoundException, InterruptedException {
URL url = URL.valueOf("xxx://" + NetUtils.getLocalAddress().getHostName() + ":4444/" + interfaceName + "?paramTest=zkTest&version=" + version + "&application=" + application + (group == null ? "" : "&group=" + group));
MetadataIdentifier providerMetadataIdentifier = new MetadataIdentifier(interfaceName, version, group, PROVIDER_SIDE, application);
Class interfaceClass = Class.forName(interfaceName);
FullServiceDefinition fullServiceDefinition = ServiceDefinitionBuilder.buildFullDefinition(interfaceClass, url.getParameters());
zookeeperMetadataReport.storeProviderMetadata(providerMetadataIdentifier, fullServiceDefinition);
Thread.sleep(2000);
return providerMetadataIdentifier;
}
use of org.apache.dubbo.metadata.report.identifier.MetadataIdentifier in project dubbo by alibaba.
the class RemoteMetadataServiceImpl method publishProvider.
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);
try {
String interfaceName = providerUrl.getParameter(INTERFACE_KEY);
if (StringUtils.isNotEmpty(interfaceName)) {
Class interfaceClass = Class.forName(interfaceName);
FullServiceDefinition fullServiceDefinition = ServiceDefinitionBuilder.buildFullDefinition(interfaceClass, providerUrl.getParameters());
for (Map.Entry<String, MetadataReport> entry : getMetadataReports().entrySet()) {
MetadataReport metadataReport = entry.getValue();
metadataReport.storeProviderMetadata(new MetadataIdentifier(providerUrl.getServiceInterface(), providerUrl.getParameter(VERSION_KEY), providerUrl.getParameter(GROUP_KEY), PROVIDER_SIDE, providerUrl.getParameter(APPLICATION_KEY)), fullServiceDefinition);
}
return;
}
logger.error("publishProvider interfaceName is empty . providerUrl: " + providerUrl.toFullString());
} catch (ClassNotFoundException e) {
// ignore error
logger.error("publishProvider getServiceDescriptor error. providerUrl: " + providerUrl.toFullString(), e);
}
}
use of org.apache.dubbo.metadata.report.identifier.MetadataIdentifier in project dubbo by alibaba.
the class FailoverMetadataReportTest method testLocalDataCenterMetadataReport.
@Test
public void testLocalDataCenterMetadataReport() {
URL url = mockURL.addParameter("strategy", "local");
FailoverMetadataReport report = getFailoverReport(url);
Assertions.assertNotNull(report.getProxyReports(), "metadata reports should not be null.");
Assertions.assertEquals(2, report.getProxyReports().size(), "expect 2 metadata report, actual " + report.getProxyReports().size());
MetadataReport localReport = null, failoverReport = null;
for (FailoverMetadataReport.MetadataReportHolder holder : report.getProxyReports()) {
if (holder.url.getBackupAddress().contains(url.getAddress())) {
localReport = holder.report;
} else {
failoverReport = holder.report;
}
}
Assertions.assertNotNull(localReport);
Assertions.assertNotNull(failoverReport);
MetadataIdentifier identifier = new MetadataIdentifier("helloService", null, null, null, "test");
ServiceDefinition definition = new ServiceDefinition();
definition.setCanonicalName("helloService");
report.storeProviderMetadata(identifier, definition);
// assert local metadata report write already.
Assertions.assertNotNull(report.getServiceDefinition(identifier));
Assertions.assertNotNull(localReport.getServiceDefinition(identifier));
Assertions.assertNull(failoverReport.getServiceDefinition(identifier));
HashMap parameterMap = new HashMap();
report.storeConsumerMetadata(identifier, parameterMap);
// assert local metadata report write already.
Assertions.assertEquals(parameterMap, ((MockMetadataReport) localReport).consumerMetadata.get(identifier));
Assertions.assertNotEquals(parameterMap, ((MockMetadataReport) failoverReport).consumerMetadata.get(identifier));
SubscriberMetadataIdentifier subscribeIdentifier = new SubscriberMetadataIdentifier("test", "1.0");
MetadataInfo metadataInfo = new MetadataInfo(subscribeIdentifier.getApplication(), subscribeIdentifier.getRevision(), null);
report.publishAppMetadata(subscribeIdentifier, metadataInfo);
// assert all metadata report write already.
Assertions.assertEquals(metadataInfo, report.getAppMetadata(subscribeIdentifier, null));
Assertions.assertEquals(metadataInfo, localReport.getAppMetadata(subscribeIdentifier, null));
Assertions.assertNotEquals(metadataInfo, failoverReport.getAppMetadata(subscribeIdentifier, null));
report.registerServiceAppMapping("helloService", "test", null);
Set<String> appNames = report.getServiceAppMapping("helloService", null, null);
// assert local metadata report write already.
Assertions.assertEquals(appNames, report.getServiceAppMapping("helloService", null, null));
Assertions.assertEquals(appNames, localReport.getServiceAppMapping("helloService", null, null));
Assertions.assertNotEquals(appNames, failoverReport.getServiceAppMapping("helloService", null, null));
ServiceMetadataIdentifier serviceIdentifier = new ServiceMetadataIdentifier("helloService", null, null, null, "1.0", "dubbo");
report.saveServiceMetadata(serviceIdentifier, url);
// assert local metadata report write already.
Assertions.assertNotNull(report.getExportedURLs(serviceIdentifier));
Assertions.assertNotNull(localReport.getExportedURLs(serviceIdentifier));
Assertions.assertNull(failoverReport.getExportedURLs(serviceIdentifier));
Set<String> urls = new HashSet<>();
urls.add(url.toFullString());
report.saveSubscribedData(subscribeIdentifier, urls);
// assert local metadata report write already.
Assertions.assertEquals(new ArrayList<>(urls), report.getSubscribedURLs(subscribeIdentifier));
Assertions.assertEquals(new ArrayList<>(urls), localReport.getSubscribedURLs(subscribeIdentifier));
Assertions.assertNotEquals(new ArrayList<>(urls), failoverReport.getSubscribedURLs(subscribeIdentifier));
}
use of org.apache.dubbo.metadata.report.identifier.MetadataIdentifier in project dubbo by alibaba.
the class EtcdMetadataReportTest method storeProvider.
private MetadataIdentifier storeProvider(EtcdMetadataReport etcdMetadataReport, String interfaceName, String version, String group, String application) throws ClassNotFoundException, InterruptedException {
URL url = URL.valueOf("xxx://" + NetUtils.getLocalAddress().getHostName() + ":4444/" + interfaceName + "?paramTest=etcdTest&version=" + version + "&application=" + application + (group == null ? "" : "&group=" + group));
MetadataIdentifier providerMetadataIdentifier = new MetadataIdentifier(interfaceName, version, group, PROVIDER_SIDE, application);
Class interfaceClass = Class.forName(interfaceName);
FullServiceDefinition fullServiceDefinition = ServiceDefinitionBuilder.buildFullDefinition(interfaceClass, url.getParameters());
etcdMetadataReport.storeProviderMetadata(providerMetadataIdentifier, fullServiceDefinition);
Thread.sleep(1000);
return providerMetadataIdentifier;
}
Aggregations