use of com.alibaba.nacos.naming.core.Service in project nacos by alibaba.
the class ServiceUtilTest method testPageServiceName.
@Test
public void testPageServiceName() {
Map<String, Service> input = new HashMap<>();
input.put("Group@@Service", new Service());
input.put("Service", new Service());
List<String> actual = ServiceUtil.pageServiceName(1, 20, input);
assertEquals(2, actual.size());
assertEquals("Service", actual.get(0));
assertEquals("Service", actual.get(1));
}
use of com.alibaba.nacos.naming.core.Service in project nacos by alibaba.
the class ServiceUtilTest method testSelectServiceWithGroupName.
@Test
public void testSelectServiceWithGroupName() {
Service service1 = new Service();
service1.setEnabled(true);
service1.setName("serviceName");
service1.setGroupName("groupName");
service1.setAppName("appName");
service1.setNamespaceId("namespaceId");
service1.setResetWeight(true);
Map<String, Service> services = new HashMap<>();
services.put("service1", service1);
Map<String, Service> resultMap = ServiceUtil.selectServiceWithGroupName(services, "groupName");
assertNotNull(resultMap);
}
use of com.alibaba.nacos.naming.core.Service in project nacos by alibaba.
the class CatalogController method rt4Service.
/**
* Get response time of service.
*
* @param request http request
* @return response time information
*/
@RequestMapping("/rt/service")
public ObjectNode rt4Service(HttpServletRequest request) throws NacosException {
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID, Constants.DEFAULT_NAMESPACE_ID);
String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME);
Service service = serviceManager.getService(namespaceId, serviceName);
serviceManager.checkServiceIsNull(service, namespaceId, serviceName);
ObjectNode result = JacksonUtils.createEmptyJsonNode();
ArrayNode clusters = JacksonUtils.createEmptyArrayNode();
for (Map.Entry<String, com.alibaba.nacos.naming.core.Cluster> entry : service.getClusterMap().entrySet()) {
ObjectNode packet = JacksonUtils.createEmptyJsonNode();
HealthCheckTask task = entry.getValue().getHealthCheckTask();
packet.put("name", entry.getKey());
packet.put("checkRTBest", task.getCheckRtBest());
packet.put("checkRTWorst", task.getCheckRtWorst());
packet.put("checkRTNormalized", task.getCheckRtNormalized());
clusters.add(packet);
}
result.replace("clusters", clusters);
return result;
}
use of com.alibaba.nacos.naming.core.Service in project nacos by alibaba.
the class OperatorController method getResponsibleServer4Service.
@GetMapping("/distro/server")
public ObjectNode getResponsibleServer4Service(@RequestParam(defaultValue = Constants.DEFAULT_NAMESPACE_ID) String namespaceId, @RequestParam String serviceName) throws NacosException {
Service service = serviceManager.getService(namespaceId, serviceName);
serviceManager.checkServiceIsNull(service, namespaceId, serviceName);
ObjectNode result = JacksonUtils.createEmptyJsonNode();
result.put("responsibleServer", distroMapper.mapSrv(serviceName));
return result;
}
use of com.alibaba.nacos.naming.core.Service in project nacos by alibaba.
the class RaftController method onPublish.
/**
* Commit publish datum.
*
* @param request http request
* @param response http response
* @return 'ok' if success
* @throws Exception exception
*/
@PostMapping("/datum/commit")
public String onPublish(HttpServletRequest request, HttpServletResponse response) throws Exception {
if (versionJudgement.allMemberIsNewVersion()) {
throw new IllegalStateException("old raft protocol already stop");
}
response.setHeader("Content-Type", "application/json; charset=" + getAcceptEncoding(request));
response.setHeader("Cache-Control", "no-cache");
response.setHeader("Content-Encode", "gzip");
String entity = IoUtils.toString(request.getInputStream(), "UTF-8");
String value = URLDecoder.decode(entity, "UTF-8");
JsonNode jsonObject = JacksonUtils.toObj(value);
String key = "key";
RaftPeer source = JacksonUtils.toObj(jsonObject.get("source").toString(), RaftPeer.class);
JsonNode datumJson = jsonObject.get("datum");
Datum datum = null;
if (KeyBuilder.matchInstanceListKey(datumJson.get(key).asText())) {
datum = JacksonUtils.toObj(jsonObject.get("datum").toString(), new TypeReference<Datum<Instances>>() {
});
} else if (KeyBuilder.matchSwitchKey(datumJson.get(key).asText())) {
datum = JacksonUtils.toObj(jsonObject.get("datum").toString(), new TypeReference<Datum<SwitchDomain>>() {
});
} else if (KeyBuilder.matchServiceMetaKey(datumJson.get(key).asText())) {
datum = JacksonUtils.toObj(jsonObject.get("datum").toString(), new TypeReference<Datum<Service>>() {
});
}
raftConsistencyService.onPut(datum, source);
return "ok";
}
Aggregations