@Test public void testServiceDetail() throws Exception { Service service = new Service(TEST_SERVICE_NAME); service.setNamespaceId(Constants.DEFAULT_NAMESPACE_ID); service.setProtectThreshold(12.34f); service.setGroupName(TEST_GROUP_NAME); Cluster cluster = new Cluster(TEST_CLUSTER_NAME, service); cluster.setDefaultPort(1); service.addCluster(cluster); when(serviceManager.getService(anyString(), anyString())).thenReturn(service); String result1 = mockmvc.perform(get(UtilsAndCommons.NACOS_NAMING_CONTEXT + "/catalog/service") .param(CommonParams.NAMESPACE_ID, Constants.DEFAULT_NAMESPACE_ID) .param(CommonParams.SERVICE_NAME, TEST_SERVICE_NAME) .param(CommonParams.GROUP_NAME, TEST_GROUP_NAME)) .andReturn().getResponse().getContentAsString(); JSONObject result = JSONObject.parseObject(result1); JSONObject serviceResult = (JSONObject) result.get("service"); Assert.assertEquals(TEST_SERVICE_NAME, serviceResult.get("name")); Assert.assertEquals(12.34, Float.parseFloat(serviceResult.get("protectThreshold").toString()), 0.01); Assert.assertEquals(TEST_GROUP_NAME, serviceResult.get("groupName")); JSONArray clusterResults = (JSONArray) result.get("clusters"); Assert.assertEquals(1, clusterResults.size()); JSONObject clusterResult = (JSONObject) clusterResults.get(0); Assert.assertEquals(TEST_CLUSTER_NAME, clusterResult.get("name")); Assert.assertEquals(1, Integer.parseInt(clusterResult.get("defaultPort").toString())); Assert.assertTrue(Boolean.parseBoolean(clusterResult.get("useIPPort4Check").toString())); Assert.assertEquals(TEST_SERVICE_NAME, clusterResult.get("serviceName")); Assert.assertEquals(80, Integer.parseInt(clusterResult.get("defaultCheckPort").toString())); }
@Secured(parser = NamingResourceParser.class, action = ActionTypes.READ) @GetMapping("/service") public JSONObject serviceDetail(@RequestParam(defaultValue = Constants.DEFAULT_NAMESPACE_ID) String namespaceId, String serviceName) throws NacosException { Service detailedService = serviceManager.getService(namespaceId, serviceName); if (detailedService == null) { throw new NacosException(NacosException.NOT_FOUND, "service " + serviceName + " is not found!"); } JSONObject detailView = new JSONObject(); JSONObject serviceObject = new JSONObject(); serviceObject.put("name", NamingUtils.getServiceName(serviceName)); serviceObject.put("protectThreshold", detailedService.getProtectThreshold()); serviceObject.put("groupName", NamingUtils.getGroupName(serviceName)); serviceObject.put("selector", detailedService.getSelector()); serviceObject.put("metadata", detailedService.getMetadata()); detailView.put("service", serviceObject); List<Cluster> clusters = new ArrayList<>(); for (com.alibaba.nacos.naming.core.Cluster cluster : detailedService.getClusterMap().values()) { Cluster clusterView = new Cluster(); clusterView.setName(cluster.getName()); clusterView.setHealthChecker(cluster.getHealthChecker()); clusterView.setMetadata(cluster.getMetadata()); clusterView.setUseIPPort4Check(cluster.isUseIPPort4Check()); clusterView.setDefaultPort(cluster.getDefaultPort()); clusterView.setDefaultCheckPort(cluster.getDefaultCheckPort()); clusterView.setServiceName(cluster.getService().getName()); clusters.add(clusterView); } detailView.put("clusters", clusters); return detailView; }
CatalogController { @Secured(parser = NamingResourceParser.class, action = ActionTypes.READ) @GetMapping("/service") public JSONObject serviceDetail(@RequestParam(defaultValue = Constants.DEFAULT_NAMESPACE_ID) String namespaceId, String serviceName) throws NacosException { Service detailedService = serviceManager.getService(namespaceId, serviceName); if (detailedService == null) { throw new NacosException(NacosException.NOT_FOUND, "service " + serviceName + " is not found!"); } JSONObject detailView = new JSONObject(); JSONObject serviceObject = new JSONObject(); serviceObject.put("name", NamingUtils.getServiceName(serviceName)); serviceObject.put("protectThreshold", detailedService.getProtectThreshold()); serviceObject.put("groupName", NamingUtils.getGroupName(serviceName)); serviceObject.put("selector", detailedService.getSelector()); serviceObject.put("metadata", detailedService.getMetadata()); detailView.put("service", serviceObject); List<Cluster> clusters = new ArrayList<>(); for (com.alibaba.nacos.naming.core.Cluster cluster : detailedService.getClusterMap().values()) { Cluster clusterView = new Cluster(); clusterView.setName(cluster.getName()); clusterView.setHealthChecker(cluster.getHealthChecker()); clusterView.setMetadata(cluster.getMetadata()); clusterView.setUseIPPort4Check(cluster.isUseIPPort4Check()); clusterView.setDefaultPort(cluster.getDefaultPort()); clusterView.setDefaultCheckPort(cluster.getDefaultCheckPort()); clusterView.setServiceName(cluster.getService().getName()); clusters.add(clusterView); } detailView.put("clusters", clusters); return detailView; } }
CatalogController { @Secured(parser = NamingResourceParser.class, action = ActionTypes.READ) @GetMapping("/service") public JSONObject serviceDetail(@RequestParam(defaultValue = Constants.DEFAULT_NAMESPACE_ID) String namespaceId, String serviceName) throws NacosException { Service detailedService = serviceManager.getService(namespaceId, serviceName); if (detailedService == null) { throw new NacosException(NacosException.NOT_FOUND, "service " + serviceName + " is not found!"); } JSONObject detailView = new JSONObject(); JSONObject serviceObject = new JSONObject(); serviceObject.put("name", NamingUtils.getServiceName(serviceName)); serviceObject.put("protectThreshold", detailedService.getProtectThreshold()); serviceObject.put("groupName", NamingUtils.getGroupName(serviceName)); serviceObject.put("selector", detailedService.getSelector()); serviceObject.put("metadata", detailedService.getMetadata()); detailView.put("service", serviceObject); List<Cluster> clusters = new ArrayList<>(); for (com.alibaba.nacos.naming.core.Cluster cluster : detailedService.getClusterMap().values()) { Cluster clusterView = new Cluster(); clusterView.setName(cluster.getName()); clusterView.setHealthChecker(cluster.getHealthChecker()); clusterView.setMetadata(cluster.getMetadata()); clusterView.setUseIPPort4Check(cluster.isUseIPPort4Check()); clusterView.setDefaultPort(cluster.getDefaultPort()); clusterView.setDefaultCheckPort(cluster.getDefaultCheckPort()); clusterView.setServiceName(cluster.getService().getName()); clusters.add(clusterView); } detailView.put("clusters", clusters); return detailView; }  }
CatalogController { @Secured(parser = NamingResourceParser.class, action = ActionTypes.READ) @GetMapping("/service") public JSONObject serviceDetail(@RequestParam(defaultValue = Constants.DEFAULT_NAMESPACE_ID) String namespaceId, String serviceName) throws NacosException { Service detailedService = serviceManager.getService(namespaceId, serviceName); if (detailedService == null) { throw new NacosException(NacosException.NOT_FOUND, "service " + serviceName + " is not found!"); } JSONObject detailView = new JSONObject(); JSONObject serviceObject = new JSONObject(); serviceObject.put("name", NamingUtils.getServiceName(serviceName)); serviceObject.put("protectThreshold", detailedService.getProtectThreshold()); serviceObject.put("groupName", NamingUtils.getGroupName(serviceName)); serviceObject.put("selector", detailedService.getSelector()); serviceObject.put("metadata", detailedService.getMetadata()); detailView.put("service", serviceObject); List<Cluster> clusters = new ArrayList<>(); for (com.alibaba.nacos.naming.core.Cluster cluster : detailedService.getClusterMap().values()) { Cluster clusterView = new Cluster(); clusterView.setName(cluster.getName()); clusterView.setHealthChecker(cluster.getHealthChecker()); clusterView.setMetadata(cluster.getMetadata()); clusterView.setUseIPPort4Check(cluster.isUseIPPort4Check()); clusterView.setDefaultPort(cluster.getDefaultPort()); clusterView.setDefaultCheckPort(cluster.getDefaultCheckPort()); clusterView.setServiceName(cluster.getService().getName()); clusters.add(clusterView); } detailView.put("clusters", clusters); return detailView; }  @Secured(parser = NamingResourceParser.class, action = ActionTypes.READ) @GetMapping("/service") JSONObject serviceDetail(@RequestParam(defaultValue = Constants.DEFAULT_NAMESPACE_ID) String namespaceId,
                                    String serviceName); @Secured(parser = NamingResourceParser.class, action = ActionTypes.READ) @RequestMapping(value = "/instances") JSONObject 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") JSONObject rt4Service(HttpServletRequest request); }
CatalogController { @Secured(parser = NamingResourceParser.class, action = ActionTypes.READ) @GetMapping("/service") public JSONObject serviceDetail(@RequestParam(defaultValue = Constants.DEFAULT_NAMESPACE_ID) String namespaceId, String serviceName) throws NacosException { Service detailedService = serviceManager.getService(namespaceId, serviceName); if (detailedService == null) { throw new NacosException(NacosException.NOT_FOUND, "service " + serviceName + " is not found!"); } JSONObject detailView = new JSONObject(); JSONObject serviceObject = new JSONObject(); serviceObject.put("name", NamingUtils.getServiceName(serviceName)); serviceObject.put("protectThreshold", detailedService.getProtectThreshold()); serviceObject.put("groupName", NamingUtils.getGroupName(serviceName)); serviceObject.put("selector", detailedService.getSelector()); serviceObject.put("metadata", detailedService.getMetadata()); detailView.put("service", serviceObject); List<Cluster> clusters = new ArrayList<>(); for (com.alibaba.nacos.naming.core.Cluster cluster : detailedService.getClusterMap().values()) { Cluster clusterView = new Cluster(); clusterView.setName(cluster.getName()); clusterView.setHealthChecker(cluster.getHealthChecker()); clusterView.setMetadata(cluster.getMetadata()); clusterView.setUseIPPort4Check(cluster.isUseIPPort4Check()); clusterView.setDefaultPort(cluster.getDefaultPort()); clusterView.setDefaultCheckPort(cluster.getDefaultCheckPort()); clusterView.setServiceName(cluster.getService().getName()); clusters.add(clusterView); } detailView.put("clusters", clusters); return detailView; }  @Secured(parser = NamingResourceParser.class, action = ActionTypes.READ) @GetMapping("/service") JSONObject serviceDetail(@RequestParam(defaultValue = Constants.DEFAULT_NAMESPACE_ID) String namespaceId,
                                    String serviceName); @Secured(parser = NamingResourceParser.class, action = ActionTypes.READ) @RequestMapping(value = "/instances") JSONObject 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") JSONObject rt4Service(HttpServletRequest request);  }