Skip to content

Commit

Permalink
Resolve the issues of codestyle of nacos-config module for phase1 (al…
Browse files Browse the repository at this point in the history
…ibaba#3250)

* [ISSUE#3249]Resolve the part issues of codestyle for nacos-config module(package:aspect/auth/configuration).

* [ISSUE#3249]Resolve the part issues of codestyle for nacos-config module(package:constant/controller).

* [ISSUE#3249]translate Chinese comments into English.

* [ISSUE#3249]fix typo.
  • Loading branch information
zongtanghu authored Jul 6, 2020
1 parent 2f5fb23 commit c40de72
Show file tree
Hide file tree
Showing 28 changed files with 352 additions and 156 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.springframework.scheduling.annotation.EnableScheduling;

/**
* Config main
* Config main.
*
* @author Nacos
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import java.nio.charset.Charset;

/**
* 容量管理切面:批量写入、更新暂不处理
* Capacity management aspect: batch write and update but don't process it.
*
* @author hexu.hxy
* @date 2018/3/13
Expand All @@ -61,7 +61,7 @@ public class CapacityManagementAspect {
private PersistService persistService;

/**
* 更新也需要判断content内容是否超过大小限制
* Need to judge the size of content whether to exceed the limination.
*/
@Around(SYNC_UPDATE_CONFIG_ALL)
public Object aroundSyncUpdateConfigAll(ProceedingJoinPoint pjp, HttpServletRequest request,
Expand All @@ -74,22 +74,22 @@ public Object aroundSyncUpdateConfigAll(ProceedingJoinPoint pjp, HttpServletRequ
String betaIps = request.getHeader("betaIps");
if (StringUtils.isBlank(betaIps)) {
if (StringUtils.isBlank(tag)) {
// 只对写入或更新config_info表的做容量管理的限制检验
// do capacity management limination check for writting or updating config_info table.
if (persistService.findConfigInfo(dataId, group, tenant) == null) {
// 写入操作
// Write operation.
return do4Insert(pjp, request, response, group, tenant, content);
}
// 更新操作
// Update operation.
return do4Update(pjp, request, response, dataId, group, tenant, content);
}
}
return pjp.proceed();
}

/**
* 更新操作:开启容量管理的限制检验功能,会检验"content的大小"是否超过限制
* Update operation: open the limination of capacity management and it will check the size of content.
*
* @throws Throwable "实际操作"抛出的异常
* @throws Throwable Throws Exception when actually operate.
*/
private Object do4Update(ProceedingJoinPoint pjp, HttpServletRequest request, HttpServletResponse response,
String dataId, String group, String tenant, String content) throws Throwable {
Expand All @@ -109,23 +109,25 @@ private Object do4Update(ProceedingJoinPoint pjp, HttpServletRequest request, Ht
}

/**
* 写入操作:1. 无论是否开启容量管理的限制检验功能都会计数(usage) 2.开启容量管理的限制检验功能,会检验"限额"和"content的大小"
* Write operation.
* Step 1: count whether to open the limination checking funtion for capacity management;
* Step 2: open limination checking capacity management and check size of content and quota;
*
* @throws Throwable "实际操作"抛出的异常
* @throws Throwable Expcetion.
*/
private Object do4Insert(ProceedingJoinPoint pjp, HttpServletRequest request, HttpServletResponse response,
String group, String tenant, String content) throws Throwable {
LOGGER.info("[capacityManagement] do4Insert");
CounterMode counterMode = CounterMode.INCREMENT;
boolean hasTenant = hasTenant(tenant);
if (PropertyUtil.isCapacityLimitCheck()) {
// 先写入或更新:usage + 1
// Write or update: usage + 1
LimitType limitType = getLimitType(counterMode, group, tenant, content, hasTenant);
if (limitType != null) {
return response4Limit(request, response, limitType);
}
} else {
// 先写入或更新:usage + 1
// Write or update: usage + 1
insertOrUpdateUsage(group, tenant, counterMode, hasTenant);
}
return getResult(pjp, response, group, tenant, counterMode, hasTenant);
Expand All @@ -141,7 +143,7 @@ private boolean hasTenant(String tenant) {
}

/**
* 无论是否开启容量管理的限制检验功能,删除时候,计数模块中容量信息表中的usage都得减一
* The usage of capacity table for counting module will subtracte one whether open the limination check of capacity management.
*/
@Around(DELETE_CONFIG)
public Object aroundDeleteConfig(ProceedingJoinPoint pjp, HttpServletRequest request, HttpServletResponse response,
Expand All @@ -158,22 +160,31 @@ public Object aroundDeleteConfig(ProceedingJoinPoint pjp, HttpServletRequest req
}

/**
* @throws Throwable "实际操作"抛出的异常
* Delete Operation.
*
* @throws Throwable Expcetion.
*/
private Object do4Delete(ProceedingJoinPoint pjp, HttpServletResponse response, String group, String tenant,
ConfigInfo configInfo) throws Throwable {
boolean hasTenant = hasTenant(tenant);
if (configInfo == null) {
// "configInfo == null"有2种可能:
// 1. 并发删除;2. 先是新增子配置,后来删除了所有子配置,这时合并写入到configInfo的task(异步)还没执行
// 关于第2点,那么接下会顺序执行"合并写入config_info的task","删除config_info的task"
// 主动修正usage,当刚好在上述的"合并写入config_info的task"执行完时修正usage,此时usage=1
// 而后面个"删除config_info的task"执行时并不会把usage-1,因为请求已经返回了。
// 因此还是需要定时修正usage的Job
// "configInfo == null", has two possible points.
// 1. Concurrently deletion.
// 2. First, new sub configurations are added, and then all sub configurations are deleted.
// At this time, the task (asynchronous) written to configinfo has not been executed.
//
// About 2 point, then it will execute to merge to write config_info's task orderly, and delete config_info's task.
// Active modification of usage, when it happens to be in the above "merging to write config_info's task".
// Modify usage when the task of info is finished, and usage = 1.
// The following "delete config_info" task will not be executed with usage-1, because the request has already returned.
// Therefore, it is necessary to modify the usage job regularly.
correctUsage(group, tenant, hasTenant);
return pjp.proceed();
}
// 并发删除同一个记录,可能同时走到这里,加上这个接口是异步删除的(提交MergeDataTask给MergeTaskProcessor处理),可能导致usage不止减一。因此还是需要定时修正usage的Job

// The same record can be deleted concurrently. This interface can be deleted asynchronously(submit MergeDataTask
// to MergeTaskProcessor for processing), It may lead to more than one decrease in usage.
// Therefore, it is necessary to modify the usage job regularly.
CounterMode counterMode = CounterMode.DECREMENT;
insertOrUpdateUsage(group, tenant, counterMode, hasTenant);
return getResult(pjp, response, group, tenant, counterMode, hasTenant);
Expand All @@ -196,9 +207,9 @@ private void correctUsage(String group, String tenant, boolean hasTenant) {
private Object getResult(ProceedingJoinPoint pjp, HttpServletResponse response, String group, String tenant,
CounterMode counterMode, boolean hasTenant) throws Throwable {
try {
// 执行实际操作
// Execute operation actually.
Object result = pjp.proceed();
// 根据执行结果判定是否需要回滚
// Execute whether to callback based on the sql operation result.
doResult(counterMode, response, group, tenant, result, hasTenant);
return result;
} catch (Throwable throwable) {
Expand All @@ -210,7 +221,7 @@ private Object getResult(ProceedingJoinPoint pjp, HttpServletResponse response,
}

/**
* usage计数器服务:无论容量管理的限制检验功能是否开启,都会进行计数
* Usage counting service: it will count whether the limination check funtion will be open.
*/
private void insertOrUpdateUsage(String group, String tenant, CounterMode counterMode, boolean hasTenant) {
try {
Expand Down Expand Up @@ -249,7 +260,7 @@ private LimitType getLimitType(CounterMode counterMode, String group, String ten
}

/**
* 编码字节数
* Get and return the byte size of encoding.
*/
private int getCurrentSize(String content) {
try {
Expand Down Expand Up @@ -322,13 +333,13 @@ private boolean isSizeLimited(String group, String tenant, int currentSize, bool
if (capacity != null) {
Integer maxSize = getMaxSize(isAggr, capacity);
if (maxSize == 0) {
// 已经存在容量信息记录,maxSize=0,则使用"默认maxSize限制值"进行比较
// If there exists capacity info and maxSize = 0, then it uses maxSize limination default value to compare.
return isOverSize(group, tenant, currentSize, defaultMaxSize, hasTenant);
}
// 已经存在容量信息记录,maxSize!=0
// If there exists capacity info, then maxSize!=0.
return isOverSize(group, tenant, currentSize, maxSize, hasTenant);
}
// 不已经存在容量信息记录,使用"默认maxSize限制值"进行比较
// If there no exists capacity info, then it uses maxSize limination default value to compare.
return isOverSize(group, tenant, currentSize, defaultMaxSize, hasTenant);
}

Expand Down Expand Up @@ -409,13 +420,13 @@ private void rollbackClusterUsage(CounterMode counterMode) {
}

/**
* limit tyep
* limit tyep.
*
* @author Nacos
* @author Nacos.
*/
public enum LimitType {
/**
* over limit
* over limit.
*/
OVER_CLUSTER_QUOTA("超过集群配置个数上限", 429),
OVER_GROUP_QUOTA("超过该Group配置个数上限", 429),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,29 +41,29 @@
public class RequestLogAspect {

/**
* publish config
* Publish config.
*/
private static final String CLIENT_INTERFACE_PUBLISH_SINGLE_CONFIG =
"execution(* com.alibaba.nacos.config.server.controller.ConfigController.publishConfig(..)) && args"
+ "(request,response,dataId,group,tenant,content,..)";

/**
* get config
* Get config.
*/
private static final String CLIENT_INTERFACE_GET_CONFIG =
"execution(* com.alibaba.nacos.config.server.controller.ConfigController.getConfig(..)) && args(request,"
+ "response,dataId,group,tenant,..)";

/**
* remove config
* Remove config.
*/
private static final String CLIENT_INTERFACE_REMOVE_ALL_CONFIG =
"execution(* com.alibaba.nacos.config.server.controller.ConfigController.deleteConfig(..)) && args(request,"
+ "response,dataId,group,tenant,..)";


/**
* publishSingle
* PublishSingle.
*/
@Around(CLIENT_INTERFACE_PUBLISH_SINGLE_CONFIG)
public Object interfacePublishSingle(ProceedingJoinPoint pjp, HttpServletRequest request,
Expand All @@ -74,7 +74,7 @@ public Object interfacePublishSingle(ProceedingJoinPoint pjp, HttpServletRequest
}

/**
* removeAll
* RemoveAll.
*/
@Around(CLIENT_INTERFACE_REMOVE_ALL_CONFIG)
public Object interfaceRemoveAll(ProceedingJoinPoint pjp, HttpServletRequest request, HttpServletResponse response,
Expand All @@ -83,7 +83,7 @@ public Object interfaceRemoveAll(ProceedingJoinPoint pjp, HttpServletRequest req
}

/**
* getConfig
* GetConfig.
*/
@Around(CLIENT_INTERFACE_GET_CONFIG)
public Object interfaceGetConfig(ProceedingJoinPoint pjp, HttpServletRequest request, HttpServletResponse response,
Expand All @@ -95,7 +95,7 @@ public Object interfaceGetConfig(ProceedingJoinPoint pjp, HttpServletRequest req
}

/**
* client api request log rt | status | requestIp | opType | dataId | group | datumId | md5
* Client api request log rt | status | requestIp | opType | dataId | group | datumId | md5.
*/
private Object logClientRequest(String requestType, ProceedingJoinPoint pjp, HttpServletRequest request,
HttpServletResponse response, String dataId, String group, String tenant, String md5) throws Throwable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.apache.commons.lang3.StringUtils;

/**
* Config resource parser
* Config resource parser.
*
* @author nkorange
* @since 1.2.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import static com.alibaba.nacos.config.server.service.repository.RowMapperManager.PERMISSION_ROW_MAPPER;

/**
* There is no self-augmented primary key
* There is no self-augmented primary key.
*
* @author <a href="mailto:[email protected]">liaochuntao</a>
*/
Expand Down Expand Up @@ -70,12 +70,26 @@ public Page<PermissionInfo> getPermissions(String role, int pageNo, int pageSize
return pageInfo;
}

/**
* Execute ddd user permission operation.
*
* @param role role info string value.
* @param resource resource info string value.
* @param action action info string value.
*/
public void addPermission(String role, String resource, String action) {
String sql = "INSERT into permissions (role, resource, action) VALUES (?, ?, ?)";
EmbeddedStorageContextUtils.addSqlContext(sql, role, resource, action);
databaseOperate.blockUpdate();
}

/**
* Execute delete user permission operation.
*
* @param role role info string value.
* @param resource resource info string value.
* @param action action info string value.
*/
public void deletePermission(String role, String resource, String action) {
String sql = "DELETE from permissions WHERE role=? and resource=? and action=?";
EmbeddedStorageContextUtils.addSqlContext(sql, role, resource, action);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import static com.alibaba.nacos.config.server.service.repository.RowMapperManager.ROLE_INFO_ROW_MAPPER;

/**
* There is no self-augmented primary key
* There is no self-augmented primary key.
*
* @author <a href="mailto:[email protected]">liaochuntao</a>
*/
Expand Down Expand Up @@ -85,6 +85,12 @@ public Page<RoleInfo> getRolesByUserName(String username, int pageNo, int pageSi

}

/**
* Add user role.
*
* @param role role string value.
* @param userName username string value.
*/
public void addRole(String role, String userName) {

String sql = "INSERT into roles (role, username) VALUES (?, ?)";
Expand All @@ -97,6 +103,11 @@ public void addRole(String role, String userName) {
}
}

/**
* Delete user role.
*
* @param role role string value.
*/
public void deleteRole(String role) {
String sql = "DELETE from roles WHERE role=?";
try {
Expand All @@ -107,6 +118,12 @@ public void deleteRole(String role) {
}
}

/**
* Execute delete role sql operation.
*
* @param role role string value.
* @param username user string value.
*/
public void deleteRole(String role, String username) {
String sql = "DELETE from roles WHERE role=? and username=?";
try {
Expand Down
Loading

0 comments on commit c40de72

Please sign in to comment.