use of org.apache.dubbo.metadata.definition.model.FullServiceDefinition in project dubbo by alibaba.
the class ServiceDefinitionBuilderTest method testBuilderComplextObject.
@Test
public void testBuilderComplextObject() {
FullServiceDefinition fullServiceDefinition = ServiceDefinitionBuilder.buildFullDefinition(DemoService.class);
checkComplextObjectAsParam(fullServiceDefinition);
}
use of org.apache.dubbo.metadata.definition.model.FullServiceDefinition in project dubbo by alibaba.
the class GenericServiceTest method testGenericComplexCompute4FullServiceMetadata.
@Test
public void testGenericComplexCompute4FullServiceMetadata() {
DemoService server = new DemoServiceImpl();
ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
URL url = URL.valueOf("dubbo://127.0.0.1:5342/" + DemoService.class.getName() + "?version=1.0.0&generic=true$timeout=3000");
Exporter<DemoService> exporter = protocol.export(proxyFactory.getInvoker(server, DemoService.class, url));
String var1 = "v1";
int var2 = 234;
long l = 555;
String[] var3 = { "var31", "var32" };
List<Integer> var4 = Arrays.asList(2, 4, 8);
ComplexObject.TestEnum testEnum = ComplexObject.TestEnum.VALUE2;
FullServiceDefinition fullServiceDefinition = ServiceDefinitionBuilder.buildFullDefinition(DemoService.class);
MethodDefinition methodDefinition = getMethod("complexCompute", fullServiceDefinition.getMethods());
Map mapObject = createComplexObject(fullServiceDefinition, var1, var2, l, var3, var4, testEnum);
ComplexObject complexObject = map2bean(mapObject);
Invoker<GenericService> invoker = protocol.refer(GenericService.class, url);
GenericService client = proxyFactory.getProxy(invoker, true);
Object result = client.$invoke(methodDefinition.getName(), methodDefinition.getParameterTypes(), new Object[] { "haha", mapObject });
Assertions.assertEquals("haha###" + complexObject.toString(), result);
Invoker<DemoService> invoker2 = protocol.refer(DemoService.class, url);
GenericService client2 = (GenericService) proxyFactory.getProxy(invoker2, true);
Object result2 = client2.$invoke("complexCompute", methodDefinition.getParameterTypes(), new Object[] { "haha2", mapObject });
Assertions.assertEquals("haha2###" + complexObject.toString(), result2);
invoker.destroy();
exporter.unexport();
}
use of org.apache.dubbo.metadata.definition.model.FullServiceDefinition in project dubbo by alibaba.
the class EtcdMetadataReportTest method testStoreProvider.
@Test
public void testStoreProvider() throws Exception {
String version = "1.0.0";
String group = null;
String application = "etcd-metdata-report-test";
String r = etcdMetadataReport.getServiceDefinition(new MetadataIdentifier(TEST_SERVICE, version, group, "provider", application));
Assertions.assertNull(r);
MetadataIdentifier providerIdentifier = storeProvider(etcdMetadataReport, TEST_SERVICE, version, group, application);
CompletableFuture<GetResponse> response = etcdClientForTest.getKVClient().get(ByteSequence.from(etcdMetadataReport.getNodeKey(providerIdentifier), StandardCharsets.UTF_8));
String fileContent = response.get().getKvs().get(0).getValue().toString(StandardCharsets.UTF_8);
Assertions.assertNotNull(fileContent);
Gson gson = new Gson();
FullServiceDefinition fullServiceDefinition = gson.fromJson(fileContent, FullServiceDefinition.class);
Assertions.assertEquals(fullServiceDefinition.getParameters().get("paramTest"), "etcdTest");
r = etcdMetadataReport.getServiceDefinition(new MetadataIdentifier(TEST_SERVICE, version, group, "provider", application));
Assertions.assertNotNull(r);
}
use of org.apache.dubbo.metadata.definition.model.FullServiceDefinition in project incubator-dubbo-ops by apache.
the class ServiceTestController method methodDetail.
@RequestMapping(value = "/method", method = RequestMethod.GET)
public MethodMetadata methodDetail(@PathVariable String env, @RequestParam String application, @RequestParam String service, @RequestParam String method) {
Map<String, String> info = ConvertUtil.serviceName2Map(service);
MetadataIdentifier identifier = new MetadataIdentifier(info.get(Constants.INTERFACE_KEY), info.get(Constants.VERSION_KEY), info.get(Constants.GROUP_KEY), Constants.PROVIDER_SIDE, application);
String metadata = providerService.getProviderMetaData(identifier);
MethodMetadata methodMetadata = null;
if (metadata != null) {
Gson gson = new Gson();
String release = providerService.findVersionInApplication(application);
if (release.startsWith("2.")) {
org.apache.dubbo.admin.model.domain.FullServiceDefinition serviceDefinition = gson.fromJson(metadata, org.apache.dubbo.admin.model.domain.FullServiceDefinition.class);
List<org.apache.dubbo.admin.model.domain.MethodDefinition> methods = serviceDefinition.getMethods();
if (methods != null) {
for (org.apache.dubbo.admin.model.domain.MethodDefinition m : methods) {
if (ServiceTestUtil.sameMethod(m, method)) {
methodMetadata = ServiceTestUtil.generateMethodMeta(serviceDefinition, m);
break;
}
}
}
} else {
FullServiceDefinition serviceDefinition = gson.fromJson(metadata, FullServiceDefinition.class);
List<MethodDefinition> methods = serviceDefinition.getMethods();
if (methods != null) {
for (MethodDefinition m : methods) {
if (ServiceTestV3Util.sameMethod(m, method)) {
methodMetadata = ServiceTestV3Util.generateMethodMeta(serviceDefinition, m);
break;
}
}
}
}
}
return methodMetadata;
}
use of org.apache.dubbo.metadata.definition.model.FullServiceDefinition in project incubator-dubbo-ops by apache.
the class MetricsCollectController method addMetricsConfigToMap.
protected void addMetricsConfigToMap(Map<String, String> configMap, String ip) {
List<Provider> providers = providerService.findByAddress(ip);
if (providers.size() > 0) {
Provider provider = providers.get(0);
String service = provider.getService();
MetadataIdentifier providerIdentifier = new MetadataIdentifier(Tool.getInterface(service), Tool.getVersion(service), Tool.getGroup(service), Constants.PROVIDER_SIDE, provider.getApplication());
String metaData = providerService.getProviderMetaData(providerIdentifier);
FullServiceDefinition providerServiceDefinition = new Gson().fromJson(metaData, FullServiceDefinition.class);
Map<String, String> parameters = providerServiceDefinition.getParameters();
configMap.put(parameters.get(Constants.METRICS_PORT), parameters.get(Constants.METRICS_PROTOCOL));
} else {
List<Consumer> consumers = consumerService.findByAddress(ip);
if (consumers.size() > 0) {
Consumer consumer = consumers.get(0);
String service = consumer.getService();
MetadataIdentifier consumerIdentifier = new MetadataIdentifier(Tool.getInterface(service), Tool.getVersion(service), Tool.getGroup(service), Constants.CONSUMER_SIDE, consumer.getApplication());
String metaData = consumerService.getConsumerMetadata(consumerIdentifier);
Map<String, String> consumerParameters = new Gson().fromJson(metaData, Map.class);
configMap.put(consumerParameters.get(Constants.METRICS_PORT), consumerParameters.get(Constants.METRICS_PROTOCOL));
}
}
}
Aggregations