@Test public void testUpdate() throws Exception { Service service = new Service(TEST_SERVICE_NAME); service.setNamespaceId("test-namespace"); when(serviceManager.getService(Constants.DEFAULT_NAMESPACE_ID, TEST_SERVICE_NAME)).thenReturn(service); MockHttpServletRequestBuilder builder = MockMvcRequestBuilders .put(UtilsAndCommons.NACOS_NAMING_CONTEXT + "/cluster").param("clusterName", TEST_CLUSTER_NAME) .param("serviceName", TEST_SERVICE_NAME).param("healthChecker", "{\"type\":\"HTTP\"}") .param("checkPort", "1").param("useInstancePort4Check", "true"); Assert.assertEquals("ok", mockmvc.perform(builder).andReturn().getResponse().getContentAsString()); Cluster expectedCluster = new Cluster(TEST_CLUSTER_NAME, service); Cluster actualCluster = service.getClusterMap().get(TEST_CLUSTER_NAME); Assert.assertEquals(expectedCluster, actualCluster); Assert.assertEquals(1, actualCluster.getDefCkport()); Assert.assertTrue(actualCluster.isUseIPPort4Check()); }
@PutMapping @Secured(action = ActionTypes.WRITE) public String update(HttpServletRequest request) throws Exception { String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID, Constants.DEFAULT_NAMESPACE_ID); String clusterName = WebUtils.required(request, CommonParams.CLUSTER_NAME); String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME); String checkPort = WebUtils.required(request, "checkPort"); Service service = serviceManager.getService(namespaceId, serviceName); if (service == null) { throw new NacosException(NacosException.INVALID_PARAM, "service not found:" + serviceName); } Cluster cluster = service.getClusterMap().get(clusterName); if (cluster == null) { Loggers.SRV_LOG.warn("[UPDATE-CLUSTER] cluster not exist, will create it: {}, service: {}", clusterName, serviceName); cluster = new Cluster(clusterName, service); } cluster.setDefCkport(NumberUtils.toInt(checkPort)); cluster.setUseIPPort4Check(BooleanUtils.toBoolean(WebUtils.required(request, "useInstancePort4Check"))); AbstractHealthChecker abstractHealthChecker = HealthCheckerFactory .deserialize(WebUtils.required(request, "healthChecker")); cluster.setHealthChecker(abstractHealthChecker); cluster.setMetadata(UtilsAndCommons.parseMetadata(WebUtils.optional(request, "metadata", StringUtils.EMPTY))); cluster.init(); service.getClusterMap().put(clusterName, cluster); service.setLastModifiedMillis(System.currentTimeMillis()); service.recalculateChecksum(); service.validate(); serviceManager.addOrReplaceService(service); return "ok"; }
ClusterController { @PutMapping @Secured(action = ActionTypes.WRITE) public String update(HttpServletRequest request) throws Exception { String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID, Constants.DEFAULT_NAMESPACE_ID); String clusterName = WebUtils.required(request, CommonParams.CLUSTER_NAME); String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME); String checkPort = WebUtils.required(request, "checkPort"); Service service = serviceManager.getService(namespaceId, serviceName); if (service == null) { throw new NacosException(NacosException.INVALID_PARAM, "service not found:" + serviceName); } Cluster cluster = service.getClusterMap().get(clusterName); if (cluster == null) { Loggers.SRV_LOG.warn("[UPDATE-CLUSTER] cluster not exist, will create it: {}, service: {}", clusterName, serviceName); cluster = new Cluster(clusterName, service); } cluster.setDefCkport(NumberUtils.toInt(checkPort)); cluster.setUseIPPort4Check(BooleanUtils.toBoolean(WebUtils.required(request, "useInstancePort4Check"))); AbstractHealthChecker abstractHealthChecker = HealthCheckerFactory .deserialize(WebUtils.required(request, "healthChecker")); cluster.setHealthChecker(abstractHealthChecker); cluster.setMetadata(UtilsAndCommons.parseMetadata(WebUtils.optional(request, "metadata", StringUtils.EMPTY))); cluster.init(); service.getClusterMap().put(clusterName, cluster); service.setLastModifiedMillis(System.currentTimeMillis()); service.recalculateChecksum(); service.validate(); serviceManager.addOrReplaceService(service); return "ok"; } }
ClusterController { @PutMapping @Secured(action = ActionTypes.WRITE) public String update(HttpServletRequest request) throws Exception { String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID, Constants.DEFAULT_NAMESPACE_ID); String clusterName = WebUtils.required(request, CommonParams.CLUSTER_NAME); String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME); String checkPort = WebUtils.required(request, "checkPort"); Service service = serviceManager.getService(namespaceId, serviceName); if (service == null) { throw new NacosException(NacosException.INVALID_PARAM, "service not found:" + serviceName); } Cluster cluster = service.getClusterMap().get(clusterName); if (cluster == null) { Loggers.SRV_LOG.warn("[UPDATE-CLUSTER] cluster not exist, will create it: {}, service: {}", clusterName, serviceName); cluster = new Cluster(clusterName, service); } cluster.setDefCkport(NumberUtils.toInt(checkPort)); cluster.setUseIPPort4Check(BooleanUtils.toBoolean(WebUtils.required(request, "useInstancePort4Check"))); AbstractHealthChecker abstractHealthChecker = HealthCheckerFactory .deserialize(WebUtils.required(request, "healthChecker")); cluster.setHealthChecker(abstractHealthChecker); cluster.setMetadata(UtilsAndCommons.parseMetadata(WebUtils.optional(request, "metadata", StringUtils.EMPTY))); cluster.init(); service.getClusterMap().put(clusterName, cluster); service.setLastModifiedMillis(System.currentTimeMillis()); service.recalculateChecksum(); service.validate(); serviceManager.addOrReplaceService(service); return "ok"; }  }
ClusterController { @PutMapping @Secured(action = ActionTypes.WRITE) public String update(HttpServletRequest request) throws Exception { String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID, Constants.DEFAULT_NAMESPACE_ID); String clusterName = WebUtils.required(request, CommonParams.CLUSTER_NAME); String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME); String checkPort = WebUtils.required(request, "checkPort"); Service service = serviceManager.getService(namespaceId, serviceName); if (service == null) { throw new NacosException(NacosException.INVALID_PARAM, "service not found:" + serviceName); } Cluster cluster = service.getClusterMap().get(clusterName); if (cluster == null) { Loggers.SRV_LOG.warn("[UPDATE-CLUSTER] cluster not exist, will create it: {}, service: {}", clusterName, serviceName); cluster = new Cluster(clusterName, service); } cluster.setDefCkport(NumberUtils.toInt(checkPort)); cluster.setUseIPPort4Check(BooleanUtils.toBoolean(WebUtils.required(request, "useInstancePort4Check"))); AbstractHealthChecker abstractHealthChecker = HealthCheckerFactory .deserialize(WebUtils.required(request, "healthChecker")); cluster.setHealthChecker(abstractHealthChecker); cluster.setMetadata(UtilsAndCommons.parseMetadata(WebUtils.optional(request, "metadata", StringUtils.EMPTY))); cluster.init(); service.getClusterMap().put(clusterName, cluster); service.setLastModifiedMillis(System.currentTimeMillis()); service.recalculateChecksum(); service.validate(); serviceManager.addOrReplaceService(service); return "ok"; }  @PutMapping @Secured(action = ActionTypes.WRITE) String update(HttpServletRequest request); }
ClusterController { @PutMapping @Secured(action = ActionTypes.WRITE) public String update(HttpServletRequest request) throws Exception { String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID, Constants.DEFAULT_NAMESPACE_ID); String clusterName = WebUtils.required(request, CommonParams.CLUSTER_NAME); String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME); String checkPort = WebUtils.required(request, "checkPort"); Service service = serviceManager.getService(namespaceId, serviceName); if (service == null) { throw new NacosException(NacosException.INVALID_PARAM, "service not found:" + serviceName); } Cluster cluster = service.getClusterMap().get(clusterName); if (cluster == null) { Loggers.SRV_LOG.warn("[UPDATE-CLUSTER] cluster not exist, will create it: {}, service: {}", clusterName, serviceName); cluster = new Cluster(clusterName, service); } cluster.setDefCkport(NumberUtils.toInt(checkPort)); cluster.setUseIPPort4Check(BooleanUtils.toBoolean(WebUtils.required(request, "useInstancePort4Check"))); AbstractHealthChecker abstractHealthChecker = HealthCheckerFactory .deserialize(WebUtils.required(request, "healthChecker")); cluster.setHealthChecker(abstractHealthChecker); cluster.setMetadata(UtilsAndCommons.parseMetadata(WebUtils.optional(request, "metadata", StringUtils.EMPTY))); cluster.init(); service.getClusterMap().put(clusterName, cluster); service.setLastModifiedMillis(System.currentTimeMillis()); service.recalculateChecksum(); service.validate(); serviceManager.addOrReplaceService(service); return "ok"; }  @PutMapping @Secured(action = ActionTypes.WRITE) String update(HttpServletRequest request);  }