@Test public void testInstanceList() throws NacosException { Instance instance = new Instance("1.1.1.1", 1234, TEST_CLUSTER_NAME); cluster.updateIps(Collections.singletonList(instance), false); ObjectNode result = catalogController.instanceList(Constants.DEFAULT_NAMESPACE_ID, TEST_GROUP_NAME + Constants.SERVICE_INFO_SPLITER + TEST_SERVICE_NAME, TEST_CLUSTER_NAME, 1, 10); String actual = result.toString(); assertTrue(actual.contains("\"count\":1")); assertTrue(actual.contains("\"list\":[")); assertTrue(actual.contains("\"clusterName\":\"test-cluster\"")); assertTrue(actual.contains("\"ip\":\"1.1.1.1\"")); assertTrue(actual.contains("\"port\":1234")); }
@Secured(parser = NamingResourceParser.class, action = ActionTypes.READ) @RequestMapping(value = "/instances") public ObjectNode instanceList(@RequestParam(defaultValue = Constants.DEFAULT_NAMESPACE_ID) String namespaceId, @RequestParam String serviceName, @RequestParam String clusterName, @RequestParam(name = "pageNo") int page, @RequestParam int pageSize) throws NacosException { Service service = serviceManager.getService(namespaceId, serviceName); if (service == null) { throw new NacosException(NacosException.NOT_FOUND, "serivce " + serviceName + " is not found!"); } if (!service.getClusterMap().containsKey(clusterName)) { throw new NacosException(NacosException.NOT_FOUND, "cluster " + clusterName + " is not found!"); } List<Instance> instances = service.getClusterMap().get(clusterName).allIPs(); int start = (page - 1) * pageSize; int end = page * pageSize; if (start < 0) { start = 0; } if (start > instances.size()) { start = instances.size(); } if (end > instances.size()) { end = instances.size(); } ObjectNode result = JacksonUtils.createEmptyJsonNode(); result.replace("list", JacksonUtils.transferToJsonNode(instances.subList(start, end))); result.put("count", instances.size()); return result; }
CatalogController { @Secured(parser = NamingResourceParser.class, action = ActionTypes.READ) @RequestMapping(value = "/instances") public ObjectNode instanceList(@RequestParam(defaultValue = Constants.DEFAULT_NAMESPACE_ID) String namespaceId, @RequestParam String serviceName, @RequestParam String clusterName, @RequestParam(name = "pageNo") int page, @RequestParam int pageSize) throws NacosException { Service service = serviceManager.getService(namespaceId, serviceName); if (service == null) { throw new NacosException(NacosException.NOT_FOUND, "serivce " + serviceName + " is not found!"); } if (!service.getClusterMap().containsKey(clusterName)) { throw new NacosException(NacosException.NOT_FOUND, "cluster " + clusterName + " is not found!"); } List<Instance> instances = service.getClusterMap().get(clusterName).allIPs(); int start = (page - 1) * pageSize; int end = page * pageSize; if (start < 0) { start = 0; } if (start > instances.size()) { start = instances.size(); } if (end > instances.size()) { end = instances.size(); } ObjectNode result = JacksonUtils.createEmptyJsonNode(); result.replace("list", JacksonUtils.transferToJsonNode(instances.subList(start, end))); result.put("count", instances.size()); return result; } }
CatalogController { @Secured(parser = NamingResourceParser.class, action = ActionTypes.READ) @RequestMapping(value = "/instances") public ObjectNode instanceList(@RequestParam(defaultValue = Constants.DEFAULT_NAMESPACE_ID) String namespaceId, @RequestParam String serviceName, @RequestParam String clusterName, @RequestParam(name = "pageNo") int page, @RequestParam int pageSize) throws NacosException { Service service = serviceManager.getService(namespaceId, serviceName); if (service == null) { throw new NacosException(NacosException.NOT_FOUND, "serivce " + serviceName + " is not found!"); } if (!service.getClusterMap().containsKey(clusterName)) { throw new NacosException(NacosException.NOT_FOUND, "cluster " + clusterName + " is not found!"); } List<Instance> instances = service.getClusterMap().get(clusterName).allIPs(); int start = (page - 1) * pageSize; int end = page * pageSize; if (start < 0) { start = 0; } if (start > instances.size()) { start = instances.size(); } if (end > instances.size()) { end = instances.size(); } ObjectNode result = JacksonUtils.createEmptyJsonNode(); result.replace("list", JacksonUtils.transferToJsonNode(instances.subList(start, end))); result.put("count", instances.size()); return result; }  }
CatalogController { @Secured(parser = NamingResourceParser.class, action = ActionTypes.READ) @RequestMapping(value = "/instances") public ObjectNode instanceList(@RequestParam(defaultValue = Constants.DEFAULT_NAMESPACE_ID) String namespaceId, @RequestParam String serviceName, @RequestParam String clusterName, @RequestParam(name = "pageNo") int page, @RequestParam int pageSize) throws NacosException { Service service = serviceManager.getService(namespaceId, serviceName); if (service == null) { throw new NacosException(NacosException.NOT_FOUND, "serivce " + serviceName + " is not found!"); } if (!service.getClusterMap().containsKey(clusterName)) { throw new NacosException(NacosException.NOT_FOUND, "cluster " + clusterName + " is not found!"); } List<Instance> instances = service.getClusterMap().get(clusterName).allIPs(); int start = (page - 1) * pageSize; int end = page * pageSize; if (start < 0) { start = 0; } if (start > instances.size()) { start = instances.size(); } if (end > instances.size()) { end = instances.size(); } ObjectNode result = JacksonUtils.createEmptyJsonNode(); result.replace("list", JacksonUtils.transferToJsonNode(instances.subList(start, end))); result.put("count", instances.size()); return result; }  @Secured(parser = NamingResourceParser.class, action = ActionTypes.READ) @GetMapping("/service") ObjectNode serviceDetail(@RequestParam(defaultValue = Constants.DEFAULT_NAMESPACE_ID) String namespaceId,
            String serviceName); @Secured(parser = NamingResourceParser.class, action = ActionTypes.READ) @RequestMapping(value = "/instances") ObjectNode instanceList(@RequestParam(defaultValue = Constants.DEFAULT_NAMESPACE_ID) String namespaceId,
            @RequestParam String serviceName, @RequestParam String clusterName, @RequestParam(name = "pageNo") int page,
            @RequestParam int pageSize); @Secured(parser = NamingResourceParser.class, action = ActionTypes.READ) @GetMapping("/services") Object listDetail(@RequestParam(required = false) boolean withInstances,
            @RequestParam(defaultValue = Constants.DEFAULT_NAMESPACE_ID) String namespaceId,
            @RequestParam(required = false) int pageNo, @RequestParam(required = false) int pageSize,
            @RequestParam(name = "serviceNameParam", defaultValue = StringUtils.EMPTY) String serviceName,
            @RequestParam(name = "groupNameParam", defaultValue = StringUtils.EMPTY) String groupName,
            @RequestParam(name = "instance", defaultValue = StringUtils.EMPTY) String containedInstance,
            @RequestParam(required = false) boolean hasIpCount); @RequestMapping("/rt/service") ObjectNode rt4Service(HttpServletRequest request); }
CatalogController { @Secured(parser = NamingResourceParser.class, action = ActionTypes.READ) @RequestMapping(value = "/instances") public ObjectNode instanceList(@RequestParam(defaultValue = Constants.DEFAULT_NAMESPACE_ID) String namespaceId, @RequestParam String serviceName, @RequestParam String clusterName, @RequestParam(name = "pageNo") int page, @RequestParam int pageSize) throws NacosException { Service service = serviceManager.getService(namespaceId, serviceName); if (service == null) { throw new NacosException(NacosException.NOT_FOUND, "serivce " + serviceName + " is not found!"); } if (!service.getClusterMap().containsKey(clusterName)) { throw new NacosException(NacosException.NOT_FOUND, "cluster " + clusterName + " is not found!"); } List<Instance> instances = service.getClusterMap().get(clusterName).allIPs(); int start = (page - 1) * pageSize; int end = page * pageSize; if (start < 0) { start = 0; } if (start > instances.size()) { start = instances.size(); } if (end > instances.size()) { end = instances.size(); } ObjectNode result = JacksonUtils.createEmptyJsonNode(); result.replace("list", JacksonUtils.transferToJsonNode(instances.subList(start, end))); result.put("count", instances.size()); return result; }  @Secured(parser = NamingResourceParser.class, action = ActionTypes.READ) @GetMapping("/service") ObjectNode serviceDetail(@RequestParam(defaultValue = Constants.DEFAULT_NAMESPACE_ID) String namespaceId,
            String serviceName); @Secured(parser = NamingResourceParser.class, action = ActionTypes.READ) @RequestMapping(value = "/instances") ObjectNode instanceList(@RequestParam(defaultValue = Constants.DEFAULT_NAMESPACE_ID) String namespaceId,
            @RequestParam String serviceName, @RequestParam String clusterName, @RequestParam(name = "pageNo") int page,
            @RequestParam int pageSize); @Secured(parser = NamingResourceParser.class, action = ActionTypes.READ) @GetMapping("/services") Object listDetail(@RequestParam(required = false) boolean withInstances,
            @RequestParam(defaultValue = Constants.DEFAULT_NAMESPACE_ID) String namespaceId,
            @RequestParam(required = false) int pageNo, @RequestParam(required = false) int pageSize,
            @RequestParam(name = "serviceNameParam", defaultValue = StringUtils.EMPTY) String serviceName,
            @RequestParam(name = "groupNameParam", defaultValue = StringUtils.EMPTY) String groupName,
            @RequestParam(name = "instance", defaultValue = StringUtils.EMPTY) String containedInstance,
            @RequestParam(required = false) boolean hasIpCount); @RequestMapping("/rt/service") ObjectNode rt4Service(HttpServletRequest request);  }