Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
qingwli committed Mar 11, 2024
1 parent 0f17a77 commit 963825b
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public abstract class BaseOperator implements Operator {
@Autowired
private AuditService auditService;

@Override
public Object recordAudit(ProceedingJoinPoint point, String describe, AuditType auditType) throws Throwable {
long beginTime = System.currentTimeMillis();

Expand All @@ -68,7 +69,7 @@ public Object recordAudit(ProceedingJoinPoint point, String describe, AuditType
setObjectIdentityFromReturnObject(auditType, result, auditLogList);

modifyAuditOperationType(auditType, paramsMap, auditLogList);
modifyAuditObjectType(auditType, paramsMap, auditLogList);
modifyAuditObjectType(paramsMap, auditLogList);

long latency = System.currentTimeMillis() - beginTime;
auditService.addAudit(auditLogList, latency);
Expand Down Expand Up @@ -171,7 +172,7 @@ protected void modifyRequestParams(String[] paramNameArr, Map<String, Object> pa
List<AuditLog> auditLogList) {
}

protected void modifyAuditObjectType(AuditType auditType, Map<String, Object> paramsMap,
protected void modifyAuditObjectType(Map<String, Object> paramsMap,
List<AuditLog> auditLogList) {

}
Expand All @@ -187,7 +188,18 @@ protected void modifyObjectFromReturnObject(String[] params, Map<String, Object>
return;
}

auditLogList
.forEach(auditLog -> auditLog.setObjectId(Long.parseLong(returnObjectMap.get(params[0]).toString())));
Long objId = checkNum(returnObjectMap.get(params[0]).toString());

if (objId != -1) {
auditLogList.get(0).setObjectId(objId);
}
}

protected Long checkNum(String str) {
if (str.matches("\\d+")) {
return Long.parseLong(str);
}

return -1L;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ public class AlertGroupOperatorImpl extends BaseOperator {

@Override
public String getObjectNameFromReturnIdentity(Object identity) {
AlertGroup obj = alertGroupMapper.selectById(Long.parseLong(identity.toString()));
Long objId = checkNum(identity.toString());
if (objId == -1) {
return "";
}

AlertGroup obj = alertGroupMapper.selectById(objId);
return obj == null ? "" : obj.getGroupName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ public class AlertInstanceOperatorImpl extends BaseOperator {

@Override
public String getObjectNameFromReturnIdentity(Object identity) {
AlertPluginInstance obj = alertPluginInstanceMapper.selectById(Long.parseLong(identity.toString()));
Long objId = checkNum(identity.toString());
if (objId == -1) {
return "";
}

AlertPluginInstance obj = alertPluginInstanceMapper.selectById(objId);
return obj == null ? "" : obj.getInstanceName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ public class K8sNamespaceOperatorImpl extends BaseOperator {

@Override
public String getObjectNameFromReturnIdentity(Object identity) {
K8sNamespace obj = k8sNamespaceMapper.selectById(Long.parseLong(identity.toString()));
Long objId = checkNum(identity.toString());
if (objId == -1) {
return "";
}

K8sNamespace obj = k8sNamespaceMapper.selectById(objId);
return obj == null ? "" : obj.getNamespace();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package org.apache.dolphinscheduler.api.audit.operator.impl;

import org.apache.dolphinscheduler.api.audit.OperatorUtils;
import org.apache.dolphinscheduler.api.audit.enums.AuditType;
import org.apache.dolphinscheduler.api.audit.operator.BaseOperator;
import org.apache.dolphinscheduler.common.enums.AuditObjectType;
import org.apache.dolphinscheduler.dao.entity.AuditLog;
Expand All @@ -32,7 +31,7 @@
public class ResourceOperatorImpl extends BaseOperator {

@Override
public void modifyAuditObjectType(AuditType auditType, Map<String, Object> paramsMap, List<AuditLog> auditLogList) {
public void modifyAuditObjectType(Map<String, Object> paramsMap, List<AuditLog> auditLogList) {
if (OperatorUtils.isUdfResource(paramsMap)) {
auditLogList.forEach(auditLog -> auditLog.setObjectType(AuditObjectType.UDF_FOLDER.getName()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ public class TaskInstanceOperatorImpl extends BaseOperator {

@Override
protected String getObjectNameFromReturnIdentity(Object identity) {
TaskInstance obj = taskInstanceMapper.selectById(Integer.parseInt(identity.toString()));
Long objId = checkNum(identity.toString());
if (objId == -1) {
return "";
}

TaskInstance obj = taskInstanceMapper.selectById(objId);
return obj == null ? "" : obj.getName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ public class UserOperatorImpl extends BaseOperator {

@Override
public String getObjectNameFromReturnIdentity(Object identity) {
User obj = userMapper.selectById(Long.parseLong(identity.toString()));
Long objId = checkNum(identity.toString());
if (objId == -1) {
return "";
}

User obj = userMapper.selectById(objId);
return obj == null ? "" : obj.getUserName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ public class YarnQueueOperatorImpl extends BaseOperator {

@Override
public String getObjectNameFromReturnIdentity(Object identity) {
Queue obj = queueMapper.selectById(Long.parseLong(identity.toString()));
Long objId = checkNum(identity.toString());
if (objId == -1) {
return "";
}

Queue obj = queueMapper.selectById(objId);
return obj == null ? "" : obj.getQueueName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public class AuditLogController extends BaseController {
*
* @param loginUser login user
* @param pageNo page number
* @param objectTypeCodes object type codes
* @param operationTypeCodes operation type codes
* @param objectTypes object types
* @param operationTypes operation types
* @param startDate start time
* @param endDate end time
* @param userName user name
Expand All @@ -71,8 +71,8 @@ public class AuditLogController extends BaseController {
@Parameters({
@Parameter(name = "startDate", description = "START_DATE", schema = @Schema(implementation = String.class)),
@Parameter(name = "endDate", description = "END_DATE", schema = @Schema(implementation = String.class)),
@Parameter(name = "objectTypeCodes", description = "OBJECT_TYPE_CODES", schema = @Schema(implementation = String.class)),
@Parameter(name = "operationTypeCodes", description = "OPERATION_TYPE_CODES", schema = @Schema(implementation = String.class)),
@Parameter(name = "objectTypes", description = "OBJECT_TYPES", schema = @Schema(implementation = String.class)),
@Parameter(name = "operationTypes", description = "OPERATION_TYPES", schema = @Schema(implementation = String.class)),
@Parameter(name = "userName", description = "USER_NAME", schema = @Schema(implementation = String.class)),
@Parameter(name = "objectName", description = "OBJECT_NAME", schema = @Schema(implementation = String.class)),
@Parameter(name = "pageNo", description = "PAGE_NO", required = true, schema = @Schema(implementation = int.class, example = "1")),
Expand Down

0 comments on commit 963825b

Please sign in to comment.