-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2163 from KeRan213539/customNamespaceId
Custom namespace id
- Loading branch information
Showing
5 changed files
with
128 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3173,6 +3173,19 @@ public void insertTenantInfoAtomic(String kp, String tenantId, String tenantName | |
} | ||
} | ||
|
||
/** | ||
* @author klw([email protected]) | ||
* @Description: count tenant_info by tenant_id | ||
* @Date 2019/12/10 17:36 | ||
* @param: tenantId | ||
* @return int | ||
*/ | ||
public int countByTenantId(String tenantId){ | ||
String[] args = new String[1]; | ||
args[0] = tenantId; | ||
return jt.queryForObject("select count(1) from tenant_info where tenant_id = ?", args, Integer.class); | ||
} | ||
|
||
/** | ||
* Update tenantInfo showname | ||
* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ | |
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.UUID; | ||
import java.util.regex.Pattern; | ||
|
||
/** | ||
* namespace service | ||
|
@@ -42,6 +43,10 @@ public class NamespaceController { | |
@Autowired | ||
private PersistService persistService; | ||
|
||
private Pattern namespaceIdCheckPattern = Pattern.compile("^[\\w-]+"); | ||
|
||
private static final int NAMESPACE_ID_MAX_LENGTH = 128; | ||
|
||
/** | ||
* Get namespace list | ||
* | ||
|
@@ -102,15 +107,44 @@ public NamespaceAllInfo getNamespace(HttpServletRequest request, HttpServletResp | |
*/ | ||
@PostMapping | ||
public Boolean createNamespace(HttpServletRequest request, HttpServletResponse response, | ||
@RequestParam("customNamespaceId") String namespaceId, | ||
@RequestParam("namespaceName") String namespaceName, | ||
@RequestParam(value = "namespaceDesc", required = false) String namespaceDesc) { | ||
// TODO 获取用kp | ||
String namespaceId = UUID.randomUUID().toString(); | ||
if(StringUtils.isBlank(namespaceId)){ | ||
namespaceId = UUID.randomUUID().toString(); | ||
} else { | ||
namespaceId = namespaceId.trim(); | ||
if (!namespaceIdCheckPattern.matcher(namespaceId).matches()) { | ||
return false; | ||
} | ||
if (namespaceId.length() > NAMESPACE_ID_MAX_LENGTH) { | ||
return false; | ||
} | ||
if(persistService.countByTenantId(namespaceId) > 0){ | ||
return false; | ||
} | ||
} | ||
persistService.insertTenantInfoAtomic("1", namespaceId, namespaceName, namespaceDesc, "nacos", | ||
System.currentTimeMillis()); | ||
return true; | ||
} | ||
|
||
/** | ||
* @author klw([email protected]) | ||
* @Description: check namespaceId exist | ||
* @Date 2019/12/10 21:41 | ||
* @param: namespaceId | ||
* @return java.lang.Boolean | ||
*/ | ||
@GetMapping(params = "checkNamespaceIdExist=true") | ||
public Boolean checkNamespaceIdExist(@RequestParam("customNamespaceId") String namespaceId){ | ||
if(StringUtils.isBlank(namespaceId)){ | ||
return false; | ||
} | ||
return (persistService.countByTenantId(namespaceId) > 0); | ||
} | ||
|
||
/** | ||
* edit namespace | ||
* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters