* [code quality] [nacos-config] [all content] fix the ResponseEntity, the if nest optimize. * [code quality] [nacos-address] [utils] rollback logic
This commit is contained in:
parent
35c8035861
commit
624646980c
@ -103,7 +103,7 @@ public class AddressServerGeneratorManager {
|
||||
|
||||
StringBuilder ips = new StringBuilder();
|
||||
instanceList.forEach(instance -> {
|
||||
ips.append(instance.getIp() + ":" + instance.getPort());
|
||||
ips.append(instance.getIp()).append(":").append(instance.getPort());
|
||||
ips.append("\n");
|
||||
});
|
||||
|
||||
@ -118,7 +118,7 @@ public class AddressServerGeneratorManager {
|
||||
*/
|
||||
public String generateNacosServiceName(String rawServiceName) {
|
||||
|
||||
if (rawServiceName.indexOf(Constants.DEFAULT_GROUP) != -1) {
|
||||
if (rawServiceName.contains(Constants.DEFAULT_GROUP)) {
|
||||
return rawServiceName;
|
||||
}
|
||||
|
||||
|
@ -66,7 +66,7 @@ public class AddressServerClusterController {
|
||||
* @return result of create new cluster
|
||||
*/
|
||||
@RequestMapping(value = "", method = RequestMethod.POST)
|
||||
public ResponseEntity postCluster(@RequestParam(required = false) String product,
|
||||
public ResponseEntity<String> postCluster(@RequestParam(required = false) String product,
|
||||
@RequestParam(required = false) String cluster, @RequestParam(name = "ips") String ips) {
|
||||
|
||||
//1. prepare the storage name for product and cluster
|
||||
@ -78,7 +78,7 @@ public class AddressServerClusterController {
|
||||
String rawClusterName = addressServerManager.getRawClusterName(cluster);
|
||||
Loggers.ADDRESS_LOGGER.info("put cluster node,the cluster name is " + cluster + "; the product name=" + product
|
||||
+ "; the ip list=" + ips);
|
||||
ResponseEntity responseEntity;
|
||||
ResponseEntity<String> responseEntity;
|
||||
try {
|
||||
String serviceName = addressServerGeneratorManager.generateNacosServiceName(productName);
|
||||
|
||||
@ -133,26 +133,22 @@ public class AddressServerClusterController {
|
||||
Service service = serviceManager.getService(Constants.DEFAULT_NAMESPACE_ID, serviceName);
|
||||
|
||||
if (service == null) {
|
||||
responseEntity = ResponseEntity.status(HttpStatus.NOT_FOUND)
|
||||
.body("product=" + rawProductName + " not found.");
|
||||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body("product=" + rawProductName + " not found.");
|
||||
}
|
||||
if (StringUtils.isBlank(ips)) {
|
||||
// delete all ips from the cluster
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("ips must not be empty.");
|
||||
}
|
||||
// delete specified ip list
|
||||
String[] ipArray = addressServerManager.splitIps(ips);
|
||||
String checkResult = IPUtil.checkIPs(ipArray);
|
||||
if (IPUtil.checkOK(checkResult)) {
|
||||
List<Instance> instanceList = addressServerGeneratorManager
|
||||
.generateInstancesByIps(serviceName, rawProductName, clusterName, ipArray);
|
||||
serviceManager.removeInstance(Constants.DEFAULT_NAMESPACE_ID, serviceName, false,
|
||||
instanceList.toArray(new Instance[instanceList.size()]));
|
||||
} else {
|
||||
|
||||
if (StringUtils.isBlank(ips)) {
|
||||
// delete all ips from the cluster
|
||||
responseEntity = ResponseEntity.status(HttpStatus.BAD_REQUEST).body("ips must not be empty.");
|
||||
} else {
|
||||
// delete specified ip list
|
||||
String[] ipArray = addressServerManager.splitIps(ips);
|
||||
String checkResult = IPUtil.checkIPs(ipArray);
|
||||
if (IPUtil.checkOK(checkResult)) {
|
||||
List<Instance> instanceList = addressServerGeneratorManager
|
||||
.generateInstancesByIps(serviceName, rawProductName, clusterName, ipArray);
|
||||
serviceManager.removeInstance(Constants.DEFAULT_NAMESPACE_ID, serviceName, false,
|
||||
instanceList.toArray(new Instance[instanceList.size()]));
|
||||
} else {
|
||||
responseEntity = ResponseEntity.status(HttpStatus.BAD_REQUEST).body(checkResult);
|
||||
}
|
||||
}
|
||||
responseEntity = ResponseEntity.status(HttpStatus.BAD_REQUEST).body(checkResult);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
|
@ -52,7 +52,7 @@ public class ServerListController {
|
||||
* @return result of get
|
||||
*/
|
||||
@RequestMapping(value = "/{product}/{cluster}", method = RequestMethod.GET)
|
||||
public ResponseEntity getCluster(@PathVariable String product, @PathVariable String cluster) {
|
||||
public ResponseEntity<String> getCluster(@PathVariable String product, @PathVariable String cluster) {
|
||||
|
||||
String productName = addressServerBuilderManager.generateProductName(product);
|
||||
String serviceName = addressServerBuilderManager.generateNacosServiceName(productName);
|
||||
|
Loading…
Reference in New Issue
Block a user