refactor: 变更业务所用 namespace -> tenantId.

pull/161/head
chen.ma 4 years ago
parent b2a1111035
commit 5241120ae4

@ -81,7 +81,7 @@
<br/>
修改请求如下,**在做示例时不要改动 namespace、itemId、tpId**
修改请求如下,**在做示例时不要改动 tenantId、itemId、tpId**
<br/>
@ -91,7 +91,7 @@ POST http://localhost:6691/v1/cs/configs
```json
{
"namespace": "common",
"tenantId": "common",
"itemId": "message-center",
"tpId": "message-consume",
"coreSize": 3,

@ -36,21 +36,21 @@ public class ThreadPoolManager {
resourcesManager = new ConcurrentHashMap<String, Map<String, Set<ExecutorService>>>(8);
}
public void register(String namespace, String group, ExecutorService executor) {
if (!resourcesManager.containsKey(namespace)) {
public void register(String tenantId, String group, ExecutorService executor) {
if (!resourcesManager.containsKey(tenantId)) {
synchronized (this) {
lockers.put(namespace, new Object());
lockers.put(tenantId, new Object());
}
}
final Object monitor = lockers.get(namespace);
final Object monitor = lockers.get(tenantId);
synchronized (monitor) {
Map<String, Set<ExecutorService>> map = resourcesManager.get(namespace);
Map<String, Set<ExecutorService>> map = resourcesManager.get(tenantId);
if (map == null) {
map = new HashMap(8);
map.put(group, new HashSet());
map.get(group).add(executor);
resourcesManager.put(namespace, map);
resourcesManager.put(tenantId, map);
return;
}
if (!map.containsKey(group)) {

@ -20,7 +20,7 @@ public class GlobalRemotePoolInfo implements Serializable {
/**
*
*/
private String namespace;
private String tenantId;
/**
* ID

@ -9,11 +9,11 @@ package io.dynamic.threadpool.common.model;
public interface PoolParameter {
/**
* namespace
* tenantId
*
* @return
*/
String getNamespace();
String getTenantId();
/**
* itemId

@ -18,7 +18,7 @@ public class PoolParameterInfo implements PoolParameter, Serializable {
/**
*
*/
private String namespace;
private String tenantId;
/**
* Id

@ -29,7 +29,7 @@ public class ContentUtil {
public static String getPoolContent(PoolParameter parameter) {
PoolParameterInfo poolInfo = new PoolParameterInfo();
poolInfo.setNamespace(parameter.getNamespace());
poolInfo.setTenantId(parameter.getTenantId());
poolInfo.setItemId(parameter.getItemId());
poolInfo.setTpId(parameter.getTpId());
poolInfo.setCoreSize(parameter.getCoreSize());
@ -49,7 +49,7 @@ public class ContentUtil {
.append(Constants.GROUP_KEY_DELIMITER)
.append(parameter.getItemId())
.append(Constants.GROUP_KEY_DELIMITER)
.append(parameter.getNamespace())
.append(parameter.getTenantId())
.toString();
return resultStr;
}

@ -10,7 +10,7 @@ import org.springframework.util.StringUtils;
*/
public class ConfigDataChangeEvent extends Event {
public final String namespace;
public final String tenantId;
public final String itemId;
@ -18,12 +18,12 @@ public class ConfigDataChangeEvent extends Event {
public final long lastModifiedTs;
public ConfigDataChangeEvent(String namespace, String itemId, String tpId, Long gmtModified) {
if (StringUtils.isEmpty(namespace) || StringUtils.isEmpty(itemId) || StringUtils.isEmpty(tpId)) {
public ConfigDataChangeEvent(String tenantId, String itemId, String tpId, Long gmtModified) {
if (StringUtils.isEmpty(tenantId) || StringUtils.isEmpty(itemId) || StringUtils.isEmpty(tpId)) {
throw new IllegalArgumentException("dataId is null or group is null");
}
this.namespace = namespace;
this.tenantId = tenantId;
this.itemId = itemId;
this.tpId = tpId;
this.lastModifiedTs = gmtModified;

@ -2,7 +2,6 @@ package io.dynamic.threadpool.config.model;
import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;
@ -26,10 +25,9 @@ public class ConfigInfoBase implements Serializable {
private Integer id;
/**
* namespace
* tenantId
*/
@TableField(value = "tenant_id")
private String namespace;
private String tenantId;
/**
* TpId

@ -1,5 +1,6 @@
package io.dynamic.threadpool.config.model.biz.item;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import java.util.Date;
@ -13,19 +14,45 @@ import java.util.Date;
@Data
public class ItemRespDTO {
/**
* ID
*/
private Integer id;
/**
* ID
*/
private String tenantId;
/**
* ID
*/
private String itemId;
/**
*
*/
private String itemName;
/**
*
*/
private String itemDesc;
/**
*
*/
private String owner;
/**
*
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date gmtCreate;
/**
*
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date gmtModified;
}

@ -11,14 +11,29 @@ import lombok.Data;
@Data
public class ItemSaveReqDTO {
/**
* ID
*/
private String tenantId;
/**
* ID
*/
private String itemId;
/**
*
*/
private String itemName;
/**
*
*/
private String itemDesc;
/**
*
*/
private String owner;
}

@ -11,7 +11,7 @@ import lombok.Data;
@Data
public class ItemUpdateReqDTO {
private String namespace;
private String tenantId;
private String itemId;

@ -1,5 +1,6 @@
package io.dynamic.threadpool.config.model.biz.tenant;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import java.util.Date;
@ -41,10 +42,12 @@ public class TenantRespDTO {
/**
*
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date gmtCreate;
/**
*
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date gmtModified;
}

@ -14,7 +14,7 @@ public class TenantUpdateReqDTO {
/**
* ID
*/
private String namespaceId;
private String tenantId;
/**
*

@ -13,9 +13,9 @@ import lombok.Data;
public class ThreadPoolQueryReqDTO extends Page {
/**
*
* ID
*/
private String namespace;
private String tenantId;
/**
* ID

@ -1,5 +1,6 @@
package io.dynamic.threadpool.config.model.biz.threadpool;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import java.util.Date;
@ -16,7 +17,7 @@ public class ThreadPoolRespDTO {
/**
*
*/
private String namespace;
private String tenantId;
/**
* Id
@ -76,10 +77,12 @@ public class ThreadPoolRespDTO {
/**
*
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date gmtCreate;
/**
*
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date gmtModified;
}

@ -1,7 +1,5 @@
package io.dynamic.threadpool.config.model.biz.threadpool;
import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.TableField;
import lombok.Data;
/**
@ -14,9 +12,9 @@ import lombok.Data;
public class ThreadPoolSaveOrUpdateReqDTO {
/**
* namespace
* tenantId
*/
private String namespace;
private String tenantId;
/**
* TpId

@ -67,7 +67,7 @@ public class ConfigCacheService {
String[] split = groupKey.split("\\+");
ConfigAllInfo config = configService.findConfigAllInfo(split[0], split[1], split[2]);
if (config == null || StringUtils.isEmpty(config.getTpId())) {
String errorMessage = String.format("config is null. tpId :: %s, itemId :: %s, namespace :: %s", split[0], split[1], split[2]);
String errorMessage = String.format("config is null. tpId :: %s, itemId :: %s, tenantId :: %s", split[0], split[1], split[2]);
throw new RuntimeException(errorMessage);
}

@ -13,12 +13,12 @@ public interface ConfigService {
/**
*
*
* @param tpId tpId
* @param itemId itemId
* @param namespace namespace
* @param tpId tpId
* @param itemId itemId
* @param tenantId tenantId
* @return
*/
ConfigAllInfo findConfigAllInfo(String tpId, String itemId, String namespace);
ConfigAllInfo findConfigAllInfo(String tpId, String itemId, String tenantId);
/**
*

@ -30,11 +30,11 @@ public class ConfigServiceImpl implements ConfigService {
private ConfigInfoMapper configInfoMapper;
@Override
public ConfigAllInfo findConfigAllInfo(String tpId, String itemId, String namespace) {
public ConfigAllInfo findConfigAllInfo(String tpId, String itemId, String tenantId) {
LambdaQueryWrapper<ConfigAllInfo> wrapper = Wrappers.lambdaQuery(ConfigAllInfo.class)
.eq(!StringUtils.isBlank(tpId), ConfigAllInfo::getTpId, tpId)
.eq(!StringUtils.isBlank(itemId), ConfigAllInfo::getItemId, itemId)
.eq(!StringUtils.isBlank(namespace), ConfigAllInfo::getNamespace, namespace);
.eq(!StringUtils.isBlank(tenantId), ConfigAllInfo::getTenantId, tenantId);
ConfigAllInfo configAllInfo = configInfoMapper.selectOne(wrapper);
return configAllInfo;
}
@ -69,7 +69,7 @@ public class ConfigServiceImpl implements ConfigService {
LambdaUpdateWrapper<ConfigAllInfo> wrapper = Wrappers.lambdaUpdate(ConfigAllInfo.class)
.eq(ConfigAllInfo::getTpId, config.getTpId())
.eq(ConfigAllInfo::getItemId, config.getItemId())
.eq(ConfigAllInfo::getNamespace, config.getNamespace());
.eq(ConfigAllInfo::getTenantId, config.getTenantId());
config.setGmtCreate(null);
config.setContent(ContentUtil.getPoolContent(config));

@ -27,11 +27,11 @@ public interface ItemService {
/**
* Id
*
* @param namespace
* @param tenantId
* @param itemId
* @return
*/
ItemRespDTO queryItemById(String namespace, String itemId);
ItemRespDTO queryItemById(String tenantId, String itemId);
/**
*
@ -58,8 +58,8 @@ public interface ItemService {
/**
*
*
* @param namespace
* @param tenantId
* @param itemId
*/
void deleteItem(String namespace, String itemId);
void deleteItem(String tenantId, String itemId);
}

@ -50,10 +50,10 @@ public class ItemServiceImpl implements ItemService {
}
@Override
public ItemRespDTO queryItemById(String namespace, String itemId) {
public ItemRespDTO queryItemById(String tenantId, String itemId) {
LambdaQueryWrapper<ItemInfo> queryWrapper = Wrappers
.lambdaQuery(ItemInfo.class)
.eq(ItemInfo::getTenantId, namespace)
.eq(ItemInfo::getTenantId, tenantId)
.eq(ItemInfo::getItemId, itemId);
ItemInfo itemInfo = itemInfoMapper.selectOne(queryWrapper);
@ -87,7 +87,7 @@ public class ItemServiceImpl implements ItemService {
ItemInfo itemInfo = BeanUtil.convert(reqDTO, ItemInfo.class);
int updateResult = itemInfoMapper.update(itemInfo, Wrappers
.lambdaUpdate(ItemInfo.class)
.eq(ItemInfo::getTenantId, reqDTO.getNamespace())
.eq(ItemInfo::getTenantId, reqDTO.getTenantId())
.eq(ItemInfo::getItemId, reqDTO.getItemId()));
boolean retBool = SqlHelper.retBool(updateResult);

@ -15,40 +15,40 @@ import io.dynamic.threadpool.config.model.biz.tenant.TenantUpdateReqDTO;
public interface TenantService {
/**
* Id 线
* Id
*
* @param namespaceId
* @param tenantIdId
* @return
*/
TenantRespDTO getNameSpaceById(String namespaceId);
TenantRespDTO getTenantById(String tenantIdId);
/**
* 线
*
*
* @param reqDTO
* @return
*/
IPage<TenantRespDTO> queryNameSpacePage(TenantQueryReqDTO reqDTO);
IPage<TenantRespDTO> queryTenantPage(TenantQueryReqDTO reqDTO);
/**
* 线
*
*
* @param reqDTO
*/
void saveNameSpace(TenantSaveReqDTO reqDTO);
void saveTenant(TenantSaveReqDTO reqDTO);
/**
* 线
*
*
* @param reqDTO
*/
void updateNameSpace(TenantUpdateReqDTO reqDTO);
void updateTenant(TenantUpdateReqDTO reqDTO);
/**
* Id 线
* Id
*
* @param namespaceId
* @param tenantId
*/
void deleteNameSpaceById(String namespaceId);
void deleteTenantById(String tenantId);
}

@ -39,9 +39,9 @@ public class TenantServiceImpl implements TenantService {
private TenantInfoMapper tenantInfoMapper;
@Override
public TenantRespDTO getNameSpaceById(String namespaceId) {
public TenantRespDTO getTenantById(String tenantId) {
LambdaQueryWrapper<TenantInfo> queryWrapper = Wrappers
.lambdaQuery(TenantInfo.class).eq(TenantInfo::getTenantId, namespaceId);
.lambdaQuery(TenantInfo.class).eq(TenantInfo::getTenantId, tenantId);
TenantInfo tenantInfo = tenantInfoMapper.selectOne(queryWrapper);
TenantRespDTO result = BeanUtil.convert(tenantInfo, TenantRespDTO.class);
@ -49,7 +49,7 @@ public class TenantServiceImpl implements TenantService {
}
@Override
public IPage<TenantRespDTO> queryNameSpacePage(TenantQueryReqDTO reqDTO) {
public IPage<TenantRespDTO> queryTenantPage(TenantQueryReqDTO reqDTO) {
LambdaQueryWrapper<TenantInfo> wrapper = Wrappers.lambdaQuery(TenantInfo.class)
.eq(!StringUtils.isEmpty(reqDTO.getTenantId()), TenantInfo::getTenantId, reqDTO.getTenantId())
.eq(!StringUtils.isEmpty(reqDTO.getTenantName()), TenantInfo::getTenantName, reqDTO.getTenantName())
@ -60,7 +60,7 @@ public class TenantServiceImpl implements TenantService {
}
@Override
public void saveNameSpace(TenantSaveReqDTO reqDTO) {
public void saveTenant(TenantSaveReqDTO reqDTO) {
TenantInfo tenantInfo = BeanUtil.convert(reqDTO, TenantInfo.class);
int insertResult = tenantInfoMapper.insert(tenantInfo);
@ -71,10 +71,10 @@ public class TenantServiceImpl implements TenantService {
}
@Override
public void updateNameSpace(TenantUpdateReqDTO reqDTO) {
public void updateTenant(TenantUpdateReqDTO reqDTO) {
TenantInfo tenantInfo = BeanUtil.convert(reqDTO, TenantInfo.class);
int updateResult = tenantInfoMapper.update(tenantInfo, Wrappers
.lambdaUpdate(TenantInfo.class).eq(TenantInfo::getTenantId, reqDTO.getNamespaceId()));
.lambdaUpdate(TenantInfo.class).eq(TenantInfo::getTenantId, reqDTO.getTenantId()));
boolean retBool = SqlHelper.retBool(updateResult);
if (!retBool) {
throw new RuntimeException("修改失败.");
@ -82,9 +82,9 @@ public class TenantServiceImpl implements TenantService {
}
@Override
public void deleteNameSpaceById(String namespaceId) {
public void deleteTenantById(String tenantId) {
ItemQueryReqDTO reqDTO = new ItemQueryReqDTO();
reqDTO.setTenantId(namespaceId);
reqDTO.setTenantId(tenantId);
List<ItemRespDTO> itemList = itemService.queryItem(reqDTO);
if (CollectionUtils.isNotEmpty(itemList)) {
throw new RuntimeException("业务线包含项目引用, 删除失败.");
@ -92,7 +92,7 @@ public class TenantServiceImpl implements TenantService {
int updateResult = tenantInfoMapper.update(new TenantInfo(),
Wrappers.lambdaUpdate(TenantInfo.class)
.eq(TenantInfo::getTenantId, namespaceId)
.eq(TenantInfo::getTenantId, tenantId)
.set(TenantInfo::getDelFlag, DelEnum.DELETE.getIntCode()));
boolean retBool = SqlHelper.retBool(updateResult);
if (!retBool) {

@ -34,7 +34,7 @@ public class ThreadPoolServiceImpl implements ThreadPoolService {
@Override
public IPage<ThreadPoolRespDTO> queryThreadPoolPage(ThreadPoolQueryReqDTO reqDTO) {
LambdaQueryWrapper<ConfigAllInfo> wrapper = Wrappers.lambdaQuery(ConfigAllInfo.class)
.eq(!StringUtils.isBlank(reqDTO.getNamespace()), ConfigAllInfo::getNamespace, reqDTO.getNamespace())
.eq(!StringUtils.isBlank(reqDTO.getItemId()), ConfigAllInfo::getTenantId, reqDTO.getItemId())
.eq(!StringUtils.isBlank(reqDTO.getItemId()), ConfigAllInfo::getItemId, reqDTO.getItemId())
.eq(!StringUtils.isBlank(reqDTO.getTpId()), ConfigAllInfo::getTpId, reqDTO.getTpId());
return configInfoMapper.selectPage(reqDTO, wrapper).convert(each -> BeanUtil.convert(each, ThreadPoolRespDTO.class));
@ -42,7 +42,7 @@ public class ThreadPoolServiceImpl implements ThreadPoolService {
@Override
public ThreadPoolRespDTO getThreadPool(ThreadPoolQueryReqDTO reqDTO) {
ConfigAllInfo configAllInfo = configService.findConfigAllInfo(reqDTO.getTpId(), reqDTO.getItemId(), reqDTO.getNamespace());
ConfigAllInfo configAllInfo = configService.findConfigAllInfo(reqDTO.getTpId(), reqDTO.getItemId(), reqDTO.getItemId());
return BeanUtil.convert(configAllInfo, ThreadPoolRespDTO.class);
}

@ -30,9 +30,9 @@ public class ItemController {
return Results.success(itemService.queryItemPage(reqDTO));
}
@GetMapping("/item/query/{namespace}/{itemId}")
public Result queryItemById(@PathVariable("namespace") String namespace, @PathVariable("itemId") String itemId) {
return Results.success(itemService.queryItemById(namespace, itemId));
@GetMapping("/item/query/{tenantId}/{itemId}")
public Result queryItemById(@PathVariable("tenantId") String tenantId, @PathVariable("itemId") String itemId) {
return Results.success(itemService.queryItemById(tenantId, itemId));
}
@PostMapping("/item/save")
@ -47,9 +47,9 @@ public class ItemController {
return Results.success();
}
@DeleteMapping("/item/delete/{namespace}/{itemId}")
public Result deleteItem(@PathVariable("namespace") String namespace, @PathVariable("itemId") String itemId) {
itemService.deleteItem(namespace, itemId);
@DeleteMapping("/item/delete/{tenantId}/{itemId}")
public Result deleteItem(@PathVariable("tenantId") String tenantId, @PathVariable("itemId") String itemId) {
itemService.deleteItem(tenantId, itemId);
return Results.success();
}
}

@ -19,37 +19,37 @@ import org.springframework.web.bind.annotation.*;
* @date 2021/6/25 18:31
*/
@RestController
@RequestMapping(Constants.BASE_PATH)
@RequestMapping(Constants.BASE_PATH + "/tenant")
public class TenantController {
@Autowired
private TenantService tenantService;
@PostMapping("/namespace/query/page")
@PostMapping("/query/page")
public Result<IPage<TenantRespDTO>> queryNameSpacePage(@RequestBody TenantQueryReqDTO reqDTO) {
return Results.success(tenantService.queryNameSpacePage(reqDTO));
return Results.success(tenantService.queryTenantPage(reqDTO));
}
@GetMapping("/namespace/query/{namespaceId}")
public Result<TenantRespDTO> queryNameSpace(@PathVariable("namespaceId") String namespaceId) {
return Results.success(tenantService.getNameSpaceById(namespaceId));
@GetMapping("/query/{tenantId}")
public Result<TenantRespDTO> queryNameSpace(@PathVariable("tenantId") String tenantId) {
return Results.success(tenantService.getTenantById(tenantId));
}
@PostMapping("/namespace/save")
@PostMapping("/save")
public Result saveNameSpace(@RequestBody TenantSaveReqDTO reqDTO) {
tenantService.saveNameSpace(reqDTO);
tenantService.saveTenant(reqDTO);
return Results.success();
}
@PostMapping("/namespace/update")
@PostMapping("/update")
public Result updateNameSpace(@RequestBody TenantUpdateReqDTO reqDTO) {
tenantService.updateNameSpace(reqDTO);
tenantService.updateTenant(reqDTO);
return Results.success();
}
@DeleteMapping("/namespace/delete/{namespaceId}")
public Result deleteNameSpace(@PathVariable("namespaceId") String namespaceId) {
tenantService.deleteNameSpaceById(namespaceId);
@DeleteMapping("/delete/{tenantId}")
public Result deleteNameSpace(@PathVariable("tenantId") String tenantId) {
tenantService.deleteTenantById(tenantId);
return Results.success();
}
}

@ -25,12 +25,12 @@ public class DynamicThreadPoolProperties {
private String serverAddr;
/**
*
* ID
*/
private String namespace;
/**
* Id
* ID
*/
private String itemId;

@ -22,7 +22,7 @@ public class CacheData {
public volatile String content;
public final String namespace;
public final String tenantId;
public final String itemId;
@ -34,8 +34,8 @@ public class CacheData {
private final CopyOnWriteArrayList<ManagerListenerWrap> listeners;
public CacheData(String namespace, String itemId, String tpId) {
this.namespace = namespace;
public CacheData(String tenantId, String itemId, String tpId) {
this.tenantId = tenantId;
this.itemId = itemId;
this.tpId = tpId;
this.content = ContentUtil.getPoolContent(GlobalThreadPoolManage.getPoolParameter(tpId));

@ -13,12 +13,12 @@ public interface ConfigService {
/**
* , , 使
*
* @param namespace
* @param tenantId
* @param itemId
* @param tpId
* @param listener
*/
void addListener(String namespace, String itemId, String tpId, Listener listener);
void addListener(String tenantId, String itemId, String tpId, Listener listener);
/**
*

@ -26,8 +26,8 @@ public class ThreadPoolConfigService implements ConfigService {
}
@Override
public void addListener(String namespace, String itemId, String tpId, Listener listener) {
clientWorker.addTenantListeners(namespace, itemId, tpId, Arrays.asList(listener));
public void addListener(String tenantId, String itemId, String tpId, Listener listener) {
clientWorker.addTenantListeners(tenantId, itemId, tpId, Arrays.asList(listener));
}
@Override

@ -159,7 +159,7 @@ public class ClientWorker {
sb.append(cacheData.tpId).append(WORD_SEPARATOR);
sb.append(cacheData.itemId).append(WORD_SEPARATOR);
sb.append(cacheData.getMd5()).append(WORD_SEPARATOR);
sb.append(cacheData.namespace).append(LINE_SEPARATOR);
sb.append(cacheData.tenantId).append(LINE_SEPARATOR);
}
return checkUpdateTpIds(sb.toString());

@ -22,7 +22,7 @@ public interface HttpAgent {
*
* @return
*/
String getNameSpace();
String getTenantId();
/**
*

@ -47,7 +47,7 @@ public class ServerHttpAgent implements HttpAgent {
}
@Override
public String getNameSpace() {
public String getTenantId() {
return dynamicThreadPoolProperties.getNamespace();
}

@ -16,7 +16,7 @@ import java.util.concurrent.ThreadPoolExecutor;
@Data
public class DynamicThreadPoolWrap {
private String namespace;
private String tenantId;
private String itemId;

Loading…
Cancel
Save