use of org.apache.dubbo.admin.model.domain.Consumer 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.admin.model.domain.Consumer in project incubator-dubbo-ops by apache.
the class MetricsServiceImpl method getApplicationRelation.
@Override
public RelationDTO getApplicationRelation() {
List<Consumer> consumerList = consumerService.findAll();
List<Provider> providerList = providerService.findAll();
int index = 0;
// collect all service
Set<String> serviceSet = new HashSet<>();
// collect consumer's nodes map <application, node>
Map<String, RelationDTO.Node> consumerNodeMap = new HashMap<>();
// collect consumer's service and applications map <service, set<application>>
Map<String, Set<String>> consumerServiceApplicationMap = new HashMap<>();
for (Consumer consumer : consumerList) {
String application = consumer.getApplication();
if (!consumerNodeMap.keySet().contains(application)) {
RelationDTO.Node node = new RelationDTO.Node(index, application, RelationDTO.CONSUMER_CATEGORIES.getIndex());
consumerNodeMap.put(application, node);
index++;
}
String service = consumer.getService();
serviceSet.add(service);
consumerServiceApplicationMap.computeIfAbsent(service, s -> new HashSet<>());
consumerServiceApplicationMap.get(service).add(application);
}
// collect provider's nodes
Map<String, RelationDTO.Node> providerNodeMap = new HashMap<>();
// collect provider's service and applications map <service, set<application>>
Map<String, Set<String>> providerServiceApplicationMap = new HashMap<>();
for (Provider provider : providerList) {
String application = provider.getApplication();
if (!providerNodeMap.keySet().contains(application)) {
RelationDTO.Node node = new RelationDTO.Node(index, application, RelationDTO.PROVIDER_CATEGORIES.getIndex());
providerNodeMap.put(application, node);
index++;
}
String service = provider.getService();
serviceSet.add(service);
providerServiceApplicationMap.computeIfAbsent(service, s -> new HashSet<>());
providerServiceApplicationMap.get(service).add(application);
}
// merge provider's nodes and consumer's nodes
Map<String, RelationDTO.Node> nodeMap = new HashMap<>(consumerNodeMap);
for (Map.Entry<String, RelationDTO.Node> entry : providerNodeMap.entrySet()) {
if (nodeMap.get(entry.getKey()) != null) {
nodeMap.get(entry.getKey()).setCategory(RelationDTO.CONSUMER_AND_PROVIDER_CATEGORIES.getIndex());
} else {
nodeMap.put(entry.getKey(), entry.getValue());
}
}
// build link by same service
Set<RelationDTO.Link> linkSet = new HashSet<>();
for (String service : serviceSet) {
Set<String> consumerApplicationSet = consumerServiceApplicationMap.get(service);
Set<String> providerApplicationSet = providerServiceApplicationMap.get(service);
if (CollectionUtils.isNotEmpty(consumerApplicationSet) && CollectionUtils.isNotEmpty(providerApplicationSet)) {
for (String providerApplication : providerApplicationSet) {
for (String consumerApplication : consumerApplicationSet) {
if (nodeMap.get(consumerApplication) != null && nodeMap.get(providerApplication) != null) {
Integer consumerIndex = nodeMap.get(consumerApplication).getIndex();
Integer providerIndex = nodeMap.get(providerApplication).getIndex();
linkSet.add(new RelationDTO.Link(consumerIndex, providerIndex));
}
}
}
}
}
// sort node by index
List<RelationDTO.Node> nodeList = nodeMap.values().stream().sorted(Comparator.comparingInt(RelationDTO.Node::getIndex)).collect(Collectors.toList());
return new RelationDTO(nodeList, new ArrayList<>(linkSet));
}
use of org.apache.dubbo.admin.model.domain.Consumer 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));
}
}
}
use of org.apache.dubbo.admin.model.domain.Consumer in project incubator-dubbo-ops by apache.
the class SyncUtils method url2Consumer.
public static Consumer url2Consumer(Pair<String, URL> pair) {
if (pair == null) {
return null;
}
String id = pair.getKey();
URL url = pair.getValue();
if (null == url)
return null;
Consumer c = new Consumer();
c.setHash(id);
String group = url.getUrlParam().getParameter(Constants.GROUP_KEY);
String version = url.getUrlParam().getParameter(Constants.VERSION_KEY);
String service = BaseServiceMetadata.buildServiceKey(getServiceInterface(url), group, version);
c.setService(service);
c.setAddress(url.getHost());
c.setApplication(url.getParameter(Constants.APPLICATION_KEY));
c.setParameters(url.toParameterString());
return c;
}
Aggregations