MetaUpdate extends AbstractConsoleController { @RequestMapping(value = "/cluster", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE) public RetMessage updateCluster(@RequestBody ClusterCreateInfo clusterInfo) { return updateSingleCluster(clusterInfo); }  @RequestMapping(value = "/stats", method = RequestMethod.GET) Map<String, Integer> getStats(); @RequestMapping(value = "/clusters", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE) RetMessage createCluster(@RequestBody ClusterCreateInfo outerClusterCreateInfo); @RequestMapping(value = "/cluster/" + CLUSTER_NAME_PATH_VARIABLE, method = RequestMethod.DELETE) RetMessage deleteCluster(@PathVariable String clusterName); @RequestMapping(value = "/cluster", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE) RetMessage updateCluster(@RequestBody ClusterCreateInfo clusterInfo); @RequestMapping(value = "/clusters", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE) RetMessage updateClusters(@RequestBody List<ClusterCreateInfo> clusterInfos); @RequestMapping(value = "/clusters", method = RequestMethod.GET) List<ClusterCreateInfo> getClusters(
            @RequestParam(required=false, defaultValue = "one_way", name = "type") String clusterType); @RequestMapping(value = "/cluster/" + CLUSTER_NAME_PATH_VARIABLE, method = RequestMethod.GET) ClusterCreateInfo getCluster(@PathVariable String clusterName); @RequestMapping(value = "/shards/" + CLUSTER_NAME_PATH_VARIABLE, method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE) RetMessage createShards(@PathVariable String clusterName, @RequestBody List<ShardCreateInfo> shards); @RequestMapping(value = "/shards/" + CLUSTER_NAME_PATH_VARIABLE, method = RequestMethod.GET) List<ShardCreateInfo> getShards(@PathVariable String clusterName); @RequestMapping(value = "/shards/" + CLUSTER_NAME_PATH_VARIABLE + "/" + SHARD_NAME_PATH_VARIABLE, method = RequestMethod.POST) RetMessage createShard(@PathVariable String clusterName, @PathVariable String shardName,
                                  @RequestBody List<RedisCreateInfo> redisCreateInfos); @RequestMapping(value = "/shards/" + CLUSTER_NAME_PATH_VARIABLE + "/" + SHARD_NAME_PATH_VARIABLE + "/{monitor}", method = RequestMethod.POST) RetMessage createShard(@PathVariable String clusterName, @PathVariable String shardName,
                                  @PathVariable String monitorName,
                                  @RequestBody List<RedisCreateInfo> redisCreateInfos); @RequestMapping(value = "/shards/" + CLUSTER_NAME_PATH_VARIABLE + "/" + SHARD_NAME_PATH_VARIABLE, method = RequestMethod.DELETE) RetMessage deleteShard(@PathVariable String clusterName, @PathVariable String shardName); @RequestMapping(value = "/shards/" + CLUSTER_NAME_PATH_VARIABLE + "/" + SHARD_NAME_PATH_VARIABLE + "/sync", method = RequestMethod.DELETE) RetMessage syncDeleteShard(@PathVariable String clusterName, @PathVariable String shardName);  }
@Test public void updateCluster() throws Exception { String CLUSTER_NAME = "cluster-name"; int SUCCESS_STATE = RetMessage.SUCCESS_STATE; long ORG_ID = 5L; ClusterTbl clusterTbl = new ClusterTbl().setClusterName(CLUSTER_NAME) .setClusterType(ClusterType.ONE_WAY.toString()) .setClusterDescription("") .setActivedcId(1) .setIsXpipeInterested(true) .setStatus("normal") .setClusterLastModifiedTime(DateTimeUtils.currentTimeAsString()); clusterDao.createCluster(clusterTbl); ClusterCreateInfo clusterInfo = new ClusterCreateInfo(); clusterInfo.setClusterName(CLUSTER_NAME); clusterInfo.setClusterAdminEmails("test@ctrip.com"); clusterInfo.setOrganizationId(ORG_ID); RetMessage retMessage = clusterController.updateCluster(clusterInfo); logger.info("{}", retMessage.getMessage()); Assert.assertEquals(SUCCESS_STATE, retMessage.getState()); ClusterTbl cluster = clusterDao.findClusterAndOrgByName(CLUSTER_NAME); Assert.assertEquals(ORG_ID, cluster.getOrganizationInfo().getOrgId()); }
@Test public void testUpdateClusterWithNoClusterFound() throws Exception { String CLUSTER_NAME = "cluster-not-exist"; String EXPECTED_MESSAGE = String.format("cluster not found: %s", CLUSTER_NAME); ClusterCreateInfo clusterCreateInfo = new ClusterCreateInfo(); clusterCreateInfo.setClusterName(CLUSTER_NAME); RetMessage retMessage = clusterController.updateCluster(clusterCreateInfo); logger.info("{}", retMessage.getMessage()); Assert.assertEquals(RetMessage.FAIL_STATE, retMessage.getState()); Assert.assertEquals(EXPECTED_MESSAGE, retMessage.getMessage()); }