use of org.apache.dubbo.metadata.report.identifier.MetadataIdentifier in project incubator-dubbo-ops by apache.
the class ConsulMetaDataCollectorTest method testGetConsumerMetaData.
@Test
public void testGetConsumerMetaData() {
MetadataIdentifier identifier = buildIdentifier(false);
Map<String, String> consumerParams = new HashMap<>();
consumerParams.put("k1", "v1");
consumerParams.put("k2", "1");
consumerParams.put("k3", "true");
String metadata = gson.toJson(consumerParams);
consulMetaDataCollector.getClient().setKVValue(identifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY), metadata);
String consumerMetaData = consulMetaDataCollector.getConsumerMetaData(identifier);
Map<String, String> retParams = gson.fromJson(consumerMetaData, new TypeToken<Map<String, String>>() {
}.getType());
Assert.assertEquals(consumerParams, retParams);
}
use of org.apache.dubbo.metadata.report.identifier.MetadataIdentifier in project incubator-dubbo-ops by apache.
the class ServiceController method serviceDetail.
@RequestMapping(value = "/service/{service}", method = RequestMethod.GET)
public ServiceDetailDTO serviceDetail(@PathVariable String service, @PathVariable String env) {
service = service.replace(Constants.ANY_VALUE, Constants.PATH_SEPARATOR);
String group = Tool.getGroup(service);
String version = Tool.getVersion(service);
String interfaze = Tool.getInterface(service);
List<Provider> providers = providerService.findByService(service);
List<Consumer> consumers = consumerService.findByService(service);
String application = null;
if (providers != null && providers.size() > 0) {
application = providers.get(0).getApplication();
}
MetadataIdentifier identifier = new MetadataIdentifier(interfaze, version, group, Constants.PROVIDER_SIDE, application);
String metadata = providerService.getProviderMetaData(identifier);
ServiceDetailDTO serviceDetailDTO = new ServiceDetailDTO();
serviceDetailDTO.setConsumers(consumers);
serviceDetailDTO.setProviders(providers);
if (metadata != null) {
try {
// for dubbo version under 2.7, this metadata will represent as IP address, like 10.0.0.1.
// So the json conversion will fail.
String release = providerService.findVersionInApplication(application);
// serialization compatible 2.x version
if (release.startsWith("2")) {
org.apache.dubbo.admin.model.domain.FullServiceDefinition serviceDefinition = gson.fromJson(metadata, org.apache.dubbo.admin.model.domain.FullServiceDefinition.class);
serviceDetailDTO.setMetadata(serviceDefinition);
} else {
FullServiceDefinition serviceDefinition = gson.fromJson(metadata, FullServiceDefinition.class);
serviceDetailDTO.setMetadata(serviceDefinition);
}
} catch (JsonParseException e) {
throw new VersionValidationException("dubbo 2.6 does not support metadata");
}
}
serviceDetailDTO.setConsumers(consumers);
serviceDetailDTO.setProviders(providers);
serviceDetailDTO.setService(service);
serviceDetailDTO.setApplication(application);
return serviceDetailDTO;
}
use of org.apache.dubbo.metadata.report.identifier.MetadataIdentifier in project dubbo by alibaba.
the class RedisMetadataReportTest method testStoreConsumer.
private void testStoreConsumer(RedisMetadataReport redisMetadataReport, String version, long moreTime) throws ClassNotFoundException {
String interfaceName = "org.apache.dubbo.metadata.store.redis.RedisMetadata4TstService";
String group = null;
String application = "vic.redis.md";
MetadataIdentifier consumerMetadataIdentifier = storeConsumer(redisMetadataReport, interfaceName, version, group, application);
Jedis jedis = null;
try {
jedis = redisMetadataReport.pool.getResource();
String keyTmp = consumerMetadataIdentifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY);
String value = jedis.get(keyTmp);
if (value == null) {
Thread.sleep(moreTime);
value = jedis.get(keyTmp);
}
Assertions.assertEquals(value, "{\"paramConsumerTest\":\"redisCm\"}");
} catch (Throwable e) {
throw new RpcException("Failed to put to redis . cause: " + e.getMessage(), e);
} finally {
if (jedis != null) {
jedis.del(consumerMetadataIdentifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY));
}
redisMetadataReport.pool.close();
}
}
use of org.apache.dubbo.metadata.report.identifier.MetadataIdentifier in project dubbo by alibaba.
the class RedisMetadataReportTest method testStoreProvider.
private void testStoreProvider(RedisMetadataReport redisMetadataReport, String version, long moreTime) throws ClassNotFoundException {
String interfaceName = "org.apache.dubbo.metadata.store.redis.RedisMetadata4TstService";
String group = null;
String application = "vic.redis.md";
MetadataIdentifier providerMetadataIdentifier = storePrivider(redisMetadataReport, interfaceName, version, group, application);
Jedis jedis = null;
try {
jedis = redisMetadataReport.pool.getResource();
String keyTmp = providerMetadataIdentifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY);
String value = jedis.get(keyTmp);
if (value == null) {
Thread.sleep(moreTime);
value = jedis.get(keyTmp);
}
Assertions.assertNotNull(value);
Gson gson = new Gson();
FullServiceDefinition fullServiceDefinition = gson.fromJson(value, FullServiceDefinition.class);
Assertions.assertEquals(fullServiceDefinition.getParameters().get("paramTest"), "redisTest");
} catch (Throwable e) {
throw new RpcException("Failed to put to redis . cause: " + e.getMessage(), e);
} finally {
if (jedis != null) {
jedis.del(providerMetadataIdentifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY));
}
redisMetadataReport.pool.close();
}
}
use of org.apache.dubbo.metadata.report.identifier.MetadataIdentifier in project dubbo by alibaba.
the class ZookeeperMetadataReportTest method storeConsumer.
private MetadataIdentifier storeConsumer(MetadataReport zookeeperMetadataReport, String interfaceName, String version, String group, String application) throws ClassNotFoundException, InterruptedException {
URL url = URL.valueOf("xxx://" + NetUtils.getLocalAddress().getHostName() + ":4444/" + interfaceName + "?version=" + version + "&application=" + application + (group == null ? "" : "&group=" + group));
MetadataIdentifier consumerMetadataIdentifier = new MetadataIdentifier(interfaceName, version, group, CONSUMER_SIDE, application);
Class interfaceClass = Class.forName(interfaceName);
Map<String, String> tmp = new HashMap<>();
tmp.put("paramConsumerTest", "zkCm");
zookeeperMetadataReport.storeConsumerMetadata(consumerMetadataIdentifier, tmp);
Thread.sleep(2000);
return consumerMetadataIdentifier;
}
Aggregations