use of com.alibaba.nacos.naming.core.ServiceOperator in project nacos by alibaba.
the class UpgradeOpsController method searchService.
/**
* Search service names.
*
* @param namespaceId namespace
* @param expr search pattern
* @param responsibleOnly whether only search responsible service
* @return search result
*/
@RequestMapping("/service/names")
@Secured(action = ActionTypes.READ)
public ObjectNode searchService(@RequestParam(defaultValue = "v2", required = false) String ver, @RequestParam(defaultValue = StringUtils.EMPTY) String namespaceId, @RequestParam(defaultValue = StringUtils.EMPTY) String expr, @RequestParam(required = false) boolean responsibleOnly) throws NacosException {
Map<String, Collection<String>> serviceNameMap = new HashMap<>(16);
int totalCount = 0;
ServiceOperator serviceOperator = getServiceOperator(ver);
if (StringUtils.isNotBlank(namespaceId)) {
Collection<String> names = serviceOperator.searchServiceName(namespaceId, expr, responsibleOnly);
serviceNameMap.put(namespaceId, names);
totalCount = names.size();
} else {
for (String each : serviceOperator.listAllNamespace()) {
Collection<String> names = serviceOperator.searchServiceName(each, expr, responsibleOnly);
serviceNameMap.put(each, names);
totalCount += names.size();
}
}
ObjectNode result = JacksonUtils.createEmptyJsonNode();
result.replace("services", JacksonUtils.transferToJsonNode(serviceNameMap));
result.put("count", totalCount);
return result;
}
Aggregations