use of org.apache.dubbo.metadata.definition.model.FullServiceDefinition 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.definition.model.FullServiceDefinition in project dubbo by alibaba.
the class ProtobufTypeBuilderTest method testProtobufBuilder.
@Test
public void testProtobufBuilder() {
// TEST Pb Service metaData builder
FullServiceDefinition serviceDefinition = ServiceDefinitionBuilder.buildFullDefinition(ServiceInterface.class);
MethodDefinition methodDefinition = serviceDefinition.getMethods().get(0);
String parameterName = methodDefinition.getParameterTypes()[0];
TypeDefinition typeDefinition = null;
for (TypeDefinition type : serviceDefinition.getTypes()) {
if (parameterName.equals(type.getType())) {
typeDefinition = type;
break;
}
}
Map<String, TypeDefinition> propertiesMap = typeDefinition.getProperties();
assertThat(propertiesMap.size(), is(11));
assertThat(propertiesMap.containsKey("money"), is(true));
assertThat(propertiesMap.get("money").getType(), equalTo("double"));
assertThat(propertiesMap.containsKey("cash"), is(true));
assertThat(propertiesMap.get("cash").getType(), equalTo("float"));
assertThat(propertiesMap.containsKey("age"), is(true));
assertThat(propertiesMap.get("age").getType(), equalTo("int"));
assertThat(propertiesMap.containsKey("num"), is(true));
assertThat(propertiesMap.get("num").getType(), equalTo("long"));
assertThat(propertiesMap.containsKey("sex"), is(true));
assertThat(propertiesMap.get("sex").getType(), equalTo("boolean"));
assertThat(propertiesMap.containsKey("name"), is(true));
assertThat(propertiesMap.get("name").getType(), equalTo("java.lang.String"));
assertThat(propertiesMap.containsKey("msg"), is(true));
assertThat(propertiesMap.get("msg").getType(), equalTo("com.google.protobuf.ByteString"));
assertThat(propertiesMap.containsKey("phone"), is(true));
assertThat(propertiesMap.get("phone").getType(), equalTo("java.util.List<org.apache.dubbo.metadata.definition.protobuf.model.GooglePB$PhoneNumber>"));
assertThat(propertiesMap.containsKey("doubleMap"), is(true));
assertThat(propertiesMap.get("doubleMap").getType(), equalTo("java.util.Map<java.lang.String,org.apache.dubbo.metadata.definition.protobuf.model.GooglePB$PhoneNumber>"));
assertThat(propertiesMap.get("bytesList").getType(), equalTo("java.util.List<com.google.protobuf.ByteString>"));
assertThat(propertiesMap.get("bytesMap").getType(), equalTo("java.util.Map<java.lang.String,com.google.protobuf.ByteString>"));
}
use of org.apache.dubbo.metadata.definition.model.FullServiceDefinition 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.definition.model.FullServiceDefinition 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.definition.model.FullServiceDefinition 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;
}
Aggregations