use of org.apache.dubbo.admin.model.domain.Provider in project incubator-dubbo-ops by apache.
the class SyncUtils method url2Provider.
public static Provider url2Provider(Pair<String, URL> pair) {
if (pair == null) {
return null;
}
String id = pair.getKey();
URL url = pair.getValue();
if (url == null)
return null;
Provider p = new Provider();
p.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);
p.setService(service);
p.setAddress(url.getAddress());
p.setApplication(url.getParameter(Constants.APPLICATION_KEY));
p.setUrl(url.toIdentityString());
p.setParameters(url.toParameterString());
p.setDynamic(url.getParameter("dynamic", true));
p.setEnabled(url.getParameter(Constants.ENABLED_KEY, true));
p.setWeight(url.getParameter(Constants.WEIGHT_KEY, Constants.DEFAULT_WEIGHT));
p.setUsername(url.getParameter("owner"));
p.setRegistrySource(RegistrySource.INTERFACE);
return p;
}
use of org.apache.dubbo.admin.model.domain.Provider 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.Provider in project incubator-dubbo-ops by apache.
the class InstanceRegistryQueryHelper method urlsToProviderList.
private List<Provider> urlsToProviderList(List<InstanceAddressURL> urls) {
List<Provider> providers = Lists.newArrayList();
urls.stream().distinct().forEach(url -> {
ServiceInstance instance = url.getInstance();
MetadataInfo metadataInfo = url.getMetadataInfo();
metadataInfo.getServices().forEach((serviceKey, serviceInfo) -> {
Provider p = new Provider();
String service = serviceInfo.getServiceKey();
p.setService(service);
p.setAddress(url.getAddress());
p.setApplication(instance.getServiceName());
p.setUrl(url.toParameterString());
p.setDynamic(url.getParameter("dynamic", true));
p.setEnabled(url.getParameter(Constants.ENABLED_KEY, true));
p.setWeight(url.getParameter(Constants.WEIGHT_KEY, Constants.DEFAULT_WEIGHT));
p.setUsername(url.getParameter("owner"));
p.setRegistrySource(RegistrySource.INSTANCE);
providers.add(p);
});
});
return providers;
}
use of org.apache.dubbo.admin.model.domain.Provider in project incubator-dubbo-ops by apache.
the class ProviderServiceImpl method getServiceDTOS.
@Override
public Set<ServiceDTO> getServiceDTOS(String pattern, String filter, String env) {
List<Provider> providers = new ArrayList<>();
if (!filter.contains(Constants.ANY_VALUE) && !filter.contains(Constants.INTERROGATION_POINT)) {
// filter with specific string
if (Constants.IP.equals(pattern)) {
providers = findByAddress(filter);
} else if (Constants.SERVICE.equals(pattern)) {
providers = findByService(filter);
} else if (Constants.APPLICATION.equals(pattern)) {
providers = findByApplication(filter);
}
} else {
// filter with fuzzy search
Set<String> candidates = Collections.emptySet();
if (Constants.SERVICE.equals(pattern)) {
candidates = findServices();
} else if (Constants.APPLICATION.equals(pattern)) {
candidates = findApplications();
} else if (Constants.IP.equals(pattern)) {
candidates = findAddresses().stream().collect(Collectors.toSet());
}
// replace dot symbol and asterisk symbol to java-based regex pattern
filter = filter.toLowerCase().replace(Constants.PUNCTUATION_POINT, Constants.PUNCTUATION_SEPARATOR_POINT);
// filter start with [* 、? 、+] will triggering PatternSyntaxException
if (filter.startsWith(Constants.ANY_VALUE) || filter.startsWith(Constants.INTERROGATION_POINT) || filter.startsWith(Constants.PLUS_SIGNS)) {
filter = Constants.PUNCTUATION_POINT + filter;
}
// search with no case insensitive
Pattern regex = Pattern.compile(filter, Pattern.CASE_INSENSITIVE);
for (String candidate : candidates) {
Matcher matcher = regex.matcher(candidate);
if (matcher.matches() || matcher.lookingAt()) {
if (Constants.SERVICE.equals(pattern)) {
providers.addAll(findByService(candidate));
} else if (Constants.IP.equals(pattern)) {
providers.addAll(findByAddress(candidate));
} else {
providers.addAll(findByApplication(candidate));
}
}
}
}
return convertProviders2DTO(providers);
}
use of org.apache.dubbo.admin.model.domain.Provider 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