Browse Source

[DSIP-26][Audit log] Audit log improvement design (#15554)

3.2.2-prepare
旺阳 9 months ago committed by GitHub
parent
commit
226345512e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 96
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/AuditMessage.java
  2. 92
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/AuditPublishService.java
  3. 39
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/OperatorLog.java
  4. 61
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/OperatorLogAspect.java
  5. 206
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/OperatorUtils.java
  6. 48
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/constants/AuditLogConstants.java
  7. 252
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/enums/AuditType.java
  8. 15
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/operator/AuditOperator.java
  9. 208
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/operator/BaseAuditOperator.java
  10. 31
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/operator/impl/AlertGroupAuditOperatorImpl.java
  11. 43
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/operator/impl/AlertInstanceAuditOperatorImpl.java
  12. 43
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/operator/impl/ClusterAuditOperatorImpl.java
  13. 43
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/operator/impl/DatasourceAuditOperatorImpl.java
  14. 43
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/operator/impl/EnvironmentAuditOperatorImpl.java
  15. 43
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/operator/impl/K8SNamespaceAuditOperatorImpl.java
  16. 77
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/operator/impl/ProcessAuditOperatorImpl.java
  17. 70
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/operator/impl/ProcessInstanceAuditOperatorImpl.java
  18. 46
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/operator/impl/ProjectAuditOperatorImpl.java
  19. 61
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/operator/impl/ResourceAuditOperatorImpl.java
  20. 84
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/operator/impl/ScheduleAuditOperatorImpl.java
  21. 68
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/operator/impl/TaskAuditOperatorImpl.java
  22. 43
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/operator/impl/TaskGroupAuditOperatorImpl.java
  23. 43
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/operator/impl/TaskInstancesAuditOperatorImpl.java
  24. 43
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/operator/impl/TenantAuditOperatorImpl.java
  25. 66
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/operator/impl/TokenAuditOperatorImpl.java
  26. 46
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/operator/impl/UdfFunctionAuditOperatorImpl.java
  27. 43
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/operator/impl/UserAuditOperatorImpl.java
  28. 60
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/operator/impl/WorkerGroupAuditOperatorImpl.java
  29. 43
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/operator/impl/YarnQueueAuditOperatorImpl.java
  30. 8
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/AccessTokenController.java
  31. 5
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/AlertGroupController.java
  32. 5
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/AlertPluginInstanceController.java
  33. 59
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/AuditLogController.java
  34. 5
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ClusterController.java
  35. 5
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/DataSourceController.java
  36. 5
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/EnvironmentController.java
  37. 8
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ExecutorController.java
  38. 4
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/K8sNamespaceController.java
  39. 23
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessDefinitionController.java
  40. 5
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessInstanceController.java
  41. 9
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProjectController.java
  42. 5
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/QueueController.java
  43. 11
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ResourcesController.java
  44. 8
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/SchedulerController.java
  45. 10
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/TaskDefinitionController.java
  46. 12
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/TaskGroupController.java
  47. 3
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/TaskInstanceController.java
  48. 5
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/TenantController.java
  49. 5
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/UsersController.java
  50. 4
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/WorkerGroupController.java
  51. 51
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/AuditDto.java
  52. 59
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/auditLog/AuditModelTypeDto.java
  53. 42
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/auditLog/AuditOperationTypeDto.java
  54. 48
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/AuditService.java
  55. 97
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/AuditServiceImpl.java
  56. 1
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/K8SNamespaceServiceImpl.java
  57. 1
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionServiceImpl.java
  58. 1
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/SchedulerServiceImpl.java
  59. 2
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskGroupServiceImpl.java
  60. 1
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkerGroupServiceImpl.java
  61. 50
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/audit/AuditSubscriberTest.java
  62. 10
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/AccessTokenControllerTest.java
  63. 13
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/AlertPluginInstanceControllerTest.java
  64. 6
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ExecuteFunctionControllerTest.java
  65. 18
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/SchedulerControllerTest.java
  66. 14
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/AuditServiceTest.java
  67. 98
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/enums/AuditModelType.java
  68. 78
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/enums/AuditOperationType.java
  69. 61
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/enums/AuditResourceType.java
  70. 65
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/AuditLog.java
  71. 8
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/AuditLogMapper.java
  72. 33
      dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/AuditLogMapper.xml
  73. 10
      dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_h2.sql
  74. 12
      dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_mysql.sql
  75. 14
      dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_postgresql.sql
  76. 30
      dolphinscheduler-dao/src/main/resources/sql/upgrade/3.2.2_schema/mysql/dolphinscheduler_ddl.sql
  77. 28
      dolphinscheduler-dao/src/main/resources/sql/upgrade/3.2.2_schema/postgresql/dolphinscheduler_ddl.sql
  78. 41
      dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/AuditLogMapperTest.java
  79. 1
      dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessServiceImpl.java
  80. 6
      dolphinscheduler-ui/src/locales/en_US/monitor.ts
  81. 6
      dolphinscheduler-ui/src/locales/zh_CN/monitor.ts
  82. 14
      dolphinscheduler-ui/src/service/modules/audit/index.ts
  83. 18
      dolphinscheduler-ui/src/service/modules/audit/types.ts
  84. 65
      dolphinscheduler-ui/src/views/monitor/statistics/audit-log/index.tsx
  85. 90
      dolphinscheduler-ui/src/views/monitor/statistics/audit-log/use-table.ts

96
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/AuditMessage.java

@ -1,96 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dolphinscheduler.api.audit;
import org.apache.dolphinscheduler.common.enums.AuditOperationType;
import org.apache.dolphinscheduler.common.enums.AuditResourceType;
import org.apache.dolphinscheduler.dao.entity.User;
import java.util.Date;
public class AuditMessage {
private User user;
private Date auditDate;
private AuditResourceType resourceType;
private AuditOperationType operation;
private Integer resourceId;
public AuditMessage(User user, Date auditDate, AuditResourceType resourceType, AuditOperationType operation,
Integer resourceId) {
this.user = user;
this.auditDate = auditDate;
this.resourceType = resourceType;
this.operation = operation;
this.resourceId = resourceId;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public Date getAuditDate() {
return auditDate;
}
public void setAuditDate(Date auditDate) {
this.auditDate = auditDate;
}
public AuditResourceType getResourceType() {
return resourceType;
}
public void setResourceType(AuditResourceType resourceType) {
this.resourceType = resourceType;
}
public AuditOperationType getOperation() {
return operation;
}
public void setOperation(AuditOperationType operation) {
this.operation = operation;
}
public Integer getResourceId() {
return resourceId;
}
public void setResourceId(Integer resourceId) {
this.resourceId = resourceId;
}
@Override
public String toString() {
return "AuditMessage{"
+ "user=" + user
+ ", Date=" + auditDate
+ ", resourceType" + resourceType
+ ", operation=" + operation
+ ", resourceId='" + resourceId + '\'';
}
}

92
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/AuditPublishService.java

@ -1,92 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dolphinscheduler.api.audit;
import org.apache.dolphinscheduler.api.configuration.ApiConfig;
import java.util.List;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import javax.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
@Slf4j
public class AuditPublishService {
private final BlockingQueue<AuditMessage> auditMessageQueue = new LinkedBlockingQueue<>();
@Autowired
private List<AuditSubscriber> subscribers;
@Autowired
private ApiConfig apiConfig;
/**
* create a daemon thread to process the message queue
*/
@PostConstruct
private void init() {
if (apiConfig.isAuditEnable()) {
Thread thread = new Thread(this::doPublish);
thread.setDaemon(true);
thread.setName("Audit-Log-Consume-Thread");
thread.start();
}
}
/**
* publish a new audit message
*
* @param message audit message
*/
public void publish(AuditMessage message) {
if (apiConfig.isAuditEnable() && !auditMessageQueue.offer(message)) {
log.error("Publish audit message failed, message:{}", message);
}
}
/**
* subscribers execute the message processor method
*/
private void doPublish() {
AuditMessage message = null;
while (true) {
try {
message = auditMessageQueue.take();
for (AuditSubscriber subscriber : subscribers) {
try {
subscriber.execute(message);
} catch (Exception e) {
log.error("Consume audit message failed, message:{}", message, e);
}
}
} catch (InterruptedException e) {
log.error("Consume audit message failed, message:{}", message, e);
Thread.currentThread().interrupt();
break;
}
}
}
}

39
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/OperatorLog.java

@ -0,0 +1,39 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dolphinscheduler.api.audit;
import org.apache.dolphinscheduler.api.audit.enums.AuditType;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Custom annotation for logging and auditing operator actions in the system.
* This annotation can be applied to methods to indicate the type of operation, object type,
* and specific parameters to be recorded in the logs.
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface OperatorLog {
AuditType auditType();
}

61
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/OperatorLogAspect.java

@ -0,0 +1,61 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dolphinscheduler.api.audit;
import org.apache.dolphinscheduler.api.audit.operator.AuditOperator;
import org.apache.dolphinscheduler.service.bean.SpringApplicationContext;
import java.lang.reflect.Method;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;
import io.swagger.v3.oas.annotations.Operation;
@Aspect
@Slf4j
@Component
public class OperatorLogAspect {
@Pointcut("@annotation(org.apache.dolphinscheduler.api.audit.OperatorLog)")
public void logPointCut() {
}
@Around("logPointCut()")
public Object around(ProceedingJoinPoint point) throws Throwable {
MethodSignature signature = (MethodSignature) point.getSignature();
Method method = signature.getMethod();
OperatorLog operatorLog = method.getAnnotation(OperatorLog.class);
Operation operation = method.getAnnotation(Operation.class);
if (operation == null) {
log.warn("Operation is null of method: {}", method.getName());
return point.proceed();
}
AuditOperator operator = SpringApplicationContext.getBean(operatorLog.auditType().getOperatorClass());
return operator.recordAudit(point, operation.description(), operatorLog.auditType());
}
}

206
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/OperatorUtils.java

@ -0,0 +1,206 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dolphinscheduler.api.audit;
import org.apache.dolphinscheduler.api.audit.enums.AuditType;
import org.apache.dolphinscheduler.api.enums.ExecuteType;
import org.apache.dolphinscheduler.api.utils.Result;
import org.apache.dolphinscheduler.common.enums.AuditModelType;
import org.apache.dolphinscheduler.common.enums.AuditOperationType;
import org.apache.dolphinscheduler.common.enums.ReleaseState;
import org.apache.dolphinscheduler.dao.entity.AuditLog;
import org.apache.dolphinscheduler.dao.entity.User;
import org.apache.dolphinscheduler.spi.enums.ResourceType;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.reflect.MethodSignature;
@Slf4j
public class OperatorUtils {
protected void changeObjectForVersionRelated(AuditOperationType auditOperationType, Map<String, Object> paramsMap,
List<AuditLog> auditLogList) {
switch (auditOperationType) {
case SWITCH_VERSION:
case DELETE_VERSION:
auditLogList.get(0).setModelName(paramsMap.get("version").toString());
break;
default:
break;
}
}
public static boolean resultFail(Result<?> result) {
return result != null && result.isFailed();
}
public static List<AuditLog> buildAuditLogList(String apiDescription, AuditType auditType, User user) {
List<AuditLog> auditLogList = new ArrayList<>();
AuditLog auditLog = new AuditLog();
auditLog.setUserId(user.getId());
auditLog.setModelType(auditType.getAuditModelType().getName());
auditLog.setOperationType(auditType.getAuditOperationType().getName());
auditLog.setDescription(apiDescription);
auditLog.setTime(new Date());
auditLogList.add(auditLog);
return auditLogList;
}
public static User getUser(Map<String, Object> paramsMap) {
for (Object object : paramsMap.values()) {
if (object instanceof User) {
return (User) object;
}
}
return null;
}
public static Map<String, Object> getParamsMap(ProceedingJoinPoint point, MethodSignature signature) {
Object[] args = point.getArgs();
String[] strings = signature.getParameterNames();
Map<String, Object> paramsMap = new HashMap<>();
for (int i = 0; i < strings.length; i++) {
paramsMap.put(strings[i], args[i]);
}
return paramsMap;
}
public static AuditOperationType modifyReleaseOperationType(AuditType auditType, Map<String, Object> paramsMap) {
switch (auditType.getAuditOperationType()) {
case RELEASE:
ReleaseState releaseState = (ReleaseState) paramsMap.get("releaseState");
if (releaseState == null) {
break;
}
switch (releaseState) {
case ONLINE:
return AuditOperationType.ONLINE;
case OFFLINE:
return AuditOperationType.OFFLINE;
default:
break;
}
break;
case EXECUTE:
ExecuteType executeType = (ExecuteType) paramsMap.get("executeType");
if (executeType == null) {
break;
}
switch (executeType) {
case REPEAT_RUNNING:
return AuditOperationType.RERUN;
case RECOVER_SUSPENDED_PROCESS:
return AuditOperationType.RESUME_PAUSE;
case START_FAILURE_TASK_PROCESS:
return AuditOperationType.RESUME_FAILURE;
case STOP:
return AuditOperationType.STOP;
case PAUSE:
return AuditOperationType.PAUSE;
case EXECUTE_TASK:
return AuditOperationType.EXECUTE;
default:
break;
}
break;
default:
break;
}
return auditType.getAuditOperationType();
}
public static long getObjectIdentityByParma(String[] paramNameArr, Map<String, Object> paramsMap) {
for (String name : paramNameArr) {
if (paramsMap.get(name) instanceof String) {
String param = (String) paramsMap.get(name);
try {
if (param.matches("\\d+")) {
return Long.parseLong(param);
}
} catch (NumberFormatException e) {
return -1;
}
}
}
return -1;
}
public static Map<String, Object> getObjectIfFromReturnObject(Object obj, String[] params) {
Map<String, Object> map = new HashMap<>();
try {
Class<?> clazz = obj.getClass();
if (clazz.equals(Long.class)) {
map.put(params[0], obj);
}
while (clazz != null) {
Field[] fields = clazz.getDeclaredFields();
for (Field field : fields) {
field.setAccessible(true);
if (field.getName().equals(params[0])) {
map.put(params[0], field.get(obj));
}
}
clazz = clazz.getSuperclass();
}
} catch (Exception e) {
log.error("get object if from return object error", e);
}
return map;
}
public static boolean isUdfResource(Map<String, Object> paramsMap) {
ResourceType resourceType = (ResourceType) paramsMap.get("type");
return resourceType != null && resourceType.equals(ResourceType.UDF);
}
public static boolean isFolder(String name) {
return name != null && name.endsWith("/");
}
public static String getFileAuditObject(AuditType auditType, Map<String, Object> paramsMap, String name) {
boolean isUdfResource = isUdfResource(paramsMap);
boolean isFolder = auditType == AuditType.FOLDER_CREATE || isFolder(name);
if (isUdfResource) {
return isFolder ? AuditModelType.UDF_FOLDER.getName() : AuditModelType.UDF_FILE.getName();
} else {
return isFolder ? AuditModelType.FOLDER.getName() : AuditModelType.FILE.getName();
}
}
}

48
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/constants/AuditLogConstants.java

@ -0,0 +1,48 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dolphinscheduler.api.audit.constants;
public final class AuditLogConstants {
private AuditLogConstants() {
throw new UnsupportedOperationException("Construct Constants");
}
public static final String CODE = "code";
public static final String CODES = "codes";
public static final String VERSION = "version";
public static final String PROCESS_DEFINITION_CODE = "processDefinitionCode";
public static final String PROCESS_DEFINITION_CODES = "processDefinitionCodes";
public static final String PROCESS_INSTANCE_IDS = "processInstanceIds";
public static final String PROCESS_INSTANCE_ID = "processInstanceId";
public static final String WORKFLOW_DEFINITION_CODE = "workflowDefinitionCode";
public static final String TYPE = "type";
public static final String NAME = "name";
public static final String ID = "id";
public static final String USER_ID = "userId";
public static final String QUEUE_ID = "queueId";
public static final String PRIORITY = "priority";
public static final String CLUSTER_CODE = "clusterCode";
public static final String ENVIRONMENT_CODE = "environmentCode";
public static final String ALIAS = "alias";
public static final String FILE_NAME = "fileName";
public static final String FULL_NAME = "fullName";
public static final String FUNC_NAME = "funcName";
public static final String UDF_FUNC_ID = "udfFuncId";
}

252
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/enums/AuditType.java

@ -0,0 +1,252 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dolphinscheduler.api.audit.enums;
import static org.apache.dolphinscheduler.api.audit.constants.AuditLogConstants.ALIAS;
import static org.apache.dolphinscheduler.api.audit.constants.AuditLogConstants.CLUSTER_CODE;
import static org.apache.dolphinscheduler.api.audit.constants.AuditLogConstants.CODE;
import static org.apache.dolphinscheduler.api.audit.constants.AuditLogConstants.CODES;
import static org.apache.dolphinscheduler.api.audit.constants.AuditLogConstants.ENVIRONMENT_CODE;
import static org.apache.dolphinscheduler.api.audit.constants.AuditLogConstants.FILE_NAME;
import static org.apache.dolphinscheduler.api.audit.constants.AuditLogConstants.FULL_NAME;
import static org.apache.dolphinscheduler.api.audit.constants.AuditLogConstants.FUNC_NAME;
import static org.apache.dolphinscheduler.api.audit.constants.AuditLogConstants.ID;
import static org.apache.dolphinscheduler.api.audit.constants.AuditLogConstants.NAME;
import static org.apache.dolphinscheduler.api.audit.constants.AuditLogConstants.PRIORITY;
import static org.apache.dolphinscheduler.api.audit.constants.AuditLogConstants.PROCESS_DEFINITION_CODE;
import static org.apache.dolphinscheduler.api.audit.constants.AuditLogConstants.PROCESS_DEFINITION_CODES;
import static org.apache.dolphinscheduler.api.audit.constants.AuditLogConstants.PROCESS_INSTANCE_ID;
import static org.apache.dolphinscheduler.api.audit.constants.AuditLogConstants.PROCESS_INSTANCE_IDS;
import static org.apache.dolphinscheduler.api.audit.constants.AuditLogConstants.QUEUE_ID;
import static org.apache.dolphinscheduler.api.audit.constants.AuditLogConstants.TYPE;
import static org.apache.dolphinscheduler.api.audit.constants.AuditLogConstants.UDF_FUNC_ID;
import static org.apache.dolphinscheduler.api.audit.constants.AuditLogConstants.USER_ID;
import static org.apache.dolphinscheduler.api.audit.constants.AuditLogConstants.VERSION;
import static org.apache.dolphinscheduler.api.audit.constants.AuditLogConstants.WORKFLOW_DEFINITION_CODE;
import static org.apache.dolphinscheduler.common.enums.AuditModelType.ALARM_GROUP;
import static org.apache.dolphinscheduler.common.enums.AuditModelType.ALARM_INSTANCE;
import static org.apache.dolphinscheduler.common.enums.AuditModelType.CLUSTER;
import static org.apache.dolphinscheduler.common.enums.AuditModelType.DATASOURCE;
import static org.apache.dolphinscheduler.common.enums.AuditModelType.ENVIRONMENT;
import static org.apache.dolphinscheduler.common.enums.AuditModelType.FILE;
import static org.apache.dolphinscheduler.common.enums.AuditModelType.FOLDER;
import static org.apache.dolphinscheduler.common.enums.AuditModelType.K8S_NAMESPACE;
import static org.apache.dolphinscheduler.common.enums.AuditModelType.PROCESS;
import static org.apache.dolphinscheduler.common.enums.AuditModelType.PROCESS_INSTANCE;
import static org.apache.dolphinscheduler.common.enums.AuditModelType.PROJECT;
import static org.apache.dolphinscheduler.common.enums.AuditModelType.SCHEDULE;
import static org.apache.dolphinscheduler.common.enums.AuditModelType.TASK;
import static org.apache.dolphinscheduler.common.enums.AuditModelType.TASK_GROUP;
import static org.apache.dolphinscheduler.common.enums.AuditModelType.TASK_INSTANCE;
import static org.apache.dolphinscheduler.common.enums.AuditModelType.TENANT;
import static org.apache.dolphinscheduler.common.enums.AuditModelType.TOKEN;
import static org.apache.dolphinscheduler.common.enums.AuditModelType.UDF_FUNCTION;
import static org.apache.dolphinscheduler.common.enums.AuditModelType.USER;
import static org.apache.dolphinscheduler.common.enums.AuditModelType.WORKER_GROUP;
import static org.apache.dolphinscheduler.common.enums.AuditModelType.YARN_QUEUE;
import static org.apache.dolphinscheduler.common.enums.AuditOperationType.BATCH_DELETE;
import static org.apache.dolphinscheduler.common.enums.AuditOperationType.BATCH_RERUN;
import static org.apache.dolphinscheduler.common.enums.AuditOperationType.BATCH_START;
import static org.apache.dolphinscheduler.common.enums.AuditOperationType.CLOSE;
import static org.apache.dolphinscheduler.common.enums.AuditOperationType.COPY;
import static org.apache.dolphinscheduler.common.enums.AuditOperationType.CREATE;
import static org.apache.dolphinscheduler.common.enums.AuditOperationType.DELETE;
import static org.apache.dolphinscheduler.common.enums.AuditOperationType.DELETE_VERSION;
import static org.apache.dolphinscheduler.common.enums.AuditOperationType.EXECUTE;
import static org.apache.dolphinscheduler.common.enums.AuditOperationType.EXPORT;
import static org.apache.dolphinscheduler.common.enums.AuditOperationType.FORCE_SUCCESS;
import static org.apache.dolphinscheduler.common.enums.AuditOperationType.IMPORT;
import static org.apache.dolphinscheduler.common.enums.AuditOperationType.MODIFY;
import static org.apache.dolphinscheduler.common.enums.AuditOperationType.OFFLINE;
import static org.apache.dolphinscheduler.common.enums.AuditOperationType.ONLINE;
import static org.apache.dolphinscheduler.common.enums.AuditOperationType.RELEASE;
import static org.apache.dolphinscheduler.common.enums.AuditOperationType.START;
import static org.apache.dolphinscheduler.common.enums.AuditOperationType.SWITCH_VERSION;
import static org.apache.dolphinscheduler.common.enums.AuditOperationType.UPDATE;
import org.apache.dolphinscheduler.api.audit.operator.AuditOperator;
import org.apache.dolphinscheduler.api.audit.operator.impl.AlertGroupAuditOperatorImpl;
import org.apache.dolphinscheduler.api.audit.operator.impl.AlertInstanceAuditOperatorImpl;
import org.apache.dolphinscheduler.api.audit.operator.impl.ClusterAuditOperatorImpl;
import org.apache.dolphinscheduler.api.audit.operator.impl.DatasourceAuditOperatorImpl;
import org.apache.dolphinscheduler.api.audit.operator.impl.EnvironmentAuditOperatorImpl;
import org.apache.dolphinscheduler.api.audit.operator.impl.K8SNamespaceAuditOperatorImpl;
import org.apache.dolphinscheduler.api.audit.operator.impl.ProcessAuditOperatorImpl;
import org.apache.dolphinscheduler.api.audit.operator.impl.ProcessInstanceAuditOperatorImpl;
import org.apache.dolphinscheduler.api.audit.operator.impl.ProjectAuditOperatorImpl;
import org.apache.dolphinscheduler.api.audit.operator.impl.ResourceAuditOperatorImpl;
import org.apache.dolphinscheduler.api.audit.operator.impl.ScheduleAuditOperatorImpl;
import org.apache.dolphinscheduler.api.audit.operator.impl.TaskAuditOperatorImpl;
import org.apache.dolphinscheduler.api.audit.operator.impl.TaskGroupAuditOperatorImpl;
import org.apache.dolphinscheduler.api.audit.operator.impl.TaskInstancesAuditOperatorImpl;
import org.apache.dolphinscheduler.api.audit.operator.impl.TenantAuditOperatorImpl;
import org.apache.dolphinscheduler.api.audit.operator.impl.TokenAuditOperatorImpl;
import org.apache.dolphinscheduler.api.audit.operator.impl.UdfFunctionAuditOperatorImpl;
import org.apache.dolphinscheduler.api.audit.operator.impl.UserAuditOperatorImpl;
import org.apache.dolphinscheduler.api.audit.operator.impl.WorkerGroupAuditOperatorImpl;
import org.apache.dolphinscheduler.api.audit.operator.impl.YarnQueueAuditOperatorImpl;
import org.apache.dolphinscheduler.common.enums.AuditModelType;
import org.apache.dolphinscheduler.common.enums.AuditOperationType;
import lombok.Getter;
@Getter
public enum AuditType {
PROJECT_CREATE(PROJECT, CREATE, ProjectAuditOperatorImpl.class, new String[]{}, new String[]{CODE}),
PROJECT_UPDATE(PROJECT, UPDATE, ProjectAuditOperatorImpl.class, new String[]{}, new String[]{CODE}),
PROJECT_DELETE(PROJECT, DELETE, ProjectAuditOperatorImpl.class, new String[]{CODE}, new String[]{}),
PROCESS_CREATE(PROCESS, CREATE, ProcessAuditOperatorImpl.class, new String[]{}, new String[]{CODE}),
PROCESS_UPDATE(PROCESS, UPDATE, ProcessAuditOperatorImpl.class, new String[]{}, new String[]{CODE}),
PROCESS_SWITCH_VERSION(PROCESS, SWITCH_VERSION, ProcessAuditOperatorImpl.class, new String[]{CODE, VERSION},
new String[]{}),
PROCESS_DELETE_VERSION(PROCESS, DELETE_VERSION, ProcessAuditOperatorImpl.class, new String[]{CODE, VERSION},
new String[]{}),
PROCESS_RELEASE(PROCESS, RELEASE, ProcessAuditOperatorImpl.class, new String[]{WORKFLOW_DEFINITION_CODE},
new String[]{}),
PROCESS_COPY(PROCESS, COPY, ProcessAuditOperatorImpl.class, new String[]{CODES}, new String[]{}),
PROCESS_EXPORT(PROCESS, EXPORT, ProcessAuditOperatorImpl.class, new String[]{CODES}, new String[]{}),
PROCESS_DELETE(PROCESS, DELETE, ProcessAuditOperatorImpl.class, new String[]{CODE}, new String[]{}),
PROCESS_BATCH_DELETE(PROCESS, BATCH_DELETE, ProcessAuditOperatorImpl.class, new String[]{CODES}, new String[]{}),
PROCESS_START(PROCESS, START, ProcessAuditOperatorImpl.class, new String[]{PROCESS_DEFINITION_CODE},
new String[]{}),
PROCESS_BATCH_START(PROCESS, BATCH_START, ProcessAuditOperatorImpl.class, new String[]{PROCESS_DEFINITION_CODES},
new String[]{}),
PROCESS_BATCH_RERUN(PROCESS, BATCH_RERUN, ProcessInstanceAuditOperatorImpl.class,
new String[]{PROCESS_INSTANCE_IDS},
new String[]{}),
PROCESS_EXECUTE(PROCESS, EXECUTE, ProcessInstanceAuditOperatorImpl.class, new String[]{PROCESS_INSTANCE_ID},
new String[]{}),
PROCESS_IMPORT(PROCESS, IMPORT, ProcessAuditOperatorImpl.class, new String[]{}, new String[]{CODE}),
PROCESS_INSTANCE_UPDATE(PROCESS_INSTANCE, UPDATE, ProcessInstanceAuditOperatorImpl.class, new String[]{ID},
new String[]{}),
PROCESS_INSTANCE_DELETE(PROCESS_INSTANCE, DELETE, ProcessInstanceAuditOperatorImpl.class, new String[]{ID},
new String[]{}),
PROCESS_INSTANCE_BATCH_DELETE(PROCESS_INSTANCE, BATCH_DELETE, ProcessInstanceAuditOperatorImpl.class,
new String[]{PROCESS_INSTANCE_IDS}, new String[]{}),
TASK_CREATE(TASK, CREATE, TaskAuditOperatorImpl.class, new String[]{}, new String[]{CODE}),
TASK_UPDATE(TASK, UPDATE, TaskAuditOperatorImpl.class, new String[]{}, new String[]{CODE}),
TASK_SWITCH_VERSION(TASK, SWITCH_VERSION, TaskAuditOperatorImpl.class, new String[]{CODE, VERSION}, new String[]{}),
TASK_DELETE_VERSION(TASK, DELETE_VERSION, TaskAuditOperatorImpl.class, new String[]{CODE, VERSION}, new String[]{}),
TASK_DELETE(TASK, DELETE, TaskAuditOperatorImpl.class, new String[]{CODE}, new String[]{}),
TASK_RELEASE(TASK, RELEASE, TaskAuditOperatorImpl.class, new String[]{CODE}, new String[]{}),
TASK_START(TASK, START, TaskAuditOperatorImpl.class, new String[]{CODE}, new String[]{}),
TASK_INSTANCE_FORCE_SUCCESS(TASK_INSTANCE, FORCE_SUCCESS, TaskInstancesAuditOperatorImpl.class, new String[]{ID},
new String[]{}),
SCHEDULE_CREATE(SCHEDULE, CREATE, ScheduleAuditOperatorImpl.class, new String[]{PROCESS_DEFINITION_CODE},
new String[]{ID}),
SCHEDULE_UPDATE(SCHEDULE, UPDATE, ScheduleAuditOperatorImpl.class, new String[]{ID}, new String[]{}),
SCHEDULE_ONLINE(SCHEDULE, ONLINE, ScheduleAuditOperatorImpl.class, new String[]{ID}, new String[]{}),
SCHEDULE_OFFLINE(SCHEDULE, OFFLINE, ScheduleAuditOperatorImpl.class, new String[]{ID}, new String[]{}),
SCHEDULE_DELETE(SCHEDULE, DELETE, ScheduleAuditOperatorImpl.class, new String[]{ID}, new String[]{}),
FOLDER_CREATE(FOLDER, CREATE, ResourceAuditOperatorImpl.class, new String[]{TYPE, ALIAS}, new String[]{}),
FILE_CREATE(FILE, CREATE, ResourceAuditOperatorImpl.class, new String[]{TYPE, FILE_NAME, ALIAS}, new String[]{}),
FILE_UPDATE(FILE, UPDATE, ResourceAuditOperatorImpl.class, new String[]{TYPE, FILE_NAME, ALIAS}, new String[]{}),
FILE_DELETE(FILE, DELETE, ResourceAuditOperatorImpl.class, new String[]{FULL_NAME}, new String[]{}),
UDF_FUNCTION_CREATE(UDF_FUNCTION, CREATE, UdfFunctionAuditOperatorImpl.class, new String[]{FUNC_NAME},
new String[]{}),
UDF_FUNCTION_UPDATE(UDF_FUNCTION, UPDATE, UdfFunctionAuditOperatorImpl.class, new String[]{FUNC_NAME},
new String[]{}),
UDF_FUNCTION_DELETE(UDF_FUNCTION, DELETE, UdfFunctionAuditOperatorImpl.class, new String[]{UDF_FUNC_ID},
new String[]{}),
TASK_GROUP_CREATE(TASK_GROUP, CREATE, TaskGroupAuditOperatorImpl.class, new String[]{NAME}, new String[]{}),
TASK_GROUP_UPDATE(TASK_GROUP, UPDATE, TaskGroupAuditOperatorImpl.class, new String[]{}, new String[]{ID}),
TASK_GROUP_CLOSE(TASK_GROUP, CLOSE, TaskGroupAuditOperatorImpl.class, new String[]{ID}, new String[]{}),
TASK_GROUP_START(TASK_GROUP, START, TaskGroupAuditOperatorImpl.class, new String[]{ID}, new String[]{}),
TASK_GROUP_MODIFY(TASK_GROUP, MODIFY, TaskGroupAuditOperatorImpl.class, new String[]{QUEUE_ID, PRIORITY},
new String[]{}),
DATASOURCE_CREATE(DATASOURCE, CREATE, DatasourceAuditOperatorImpl.class, new String[]{}, new String[]{ID}),
DATASOURCE_UPDATE(DATASOURCE, UPDATE, DatasourceAuditOperatorImpl.class, new String[]{}, new String[]{ID}),
DATASOURCE_DELETE(DATASOURCE, DELETE, DatasourceAuditOperatorImpl.class, new String[]{ID}, new String[]{}),
TENANT_CREATE(TENANT, CREATE, TenantAuditOperatorImpl.class, new String[]{}, new String[]{ID}),
TENANT_UPDATE(TENANT, UPDATE, TenantAuditOperatorImpl.class, new String[]{ID}, new String[]{}),
TENANT_DELETE(TENANT, DELETE, TenantAuditOperatorImpl.class, new String[]{ID}, new String[]{}),
USER_CREATE(USER, CREATE, UserAuditOperatorImpl.class, new String[]{}, new String[]{ID}),
USER_UPDATE(USER, UPDATE, UserAuditOperatorImpl.class, new String[]{}, new String[]{ID}),
USER_DELETE(USER, DELETE, UserAuditOperatorImpl.class, new String[]{ID}, new String[]{}),
ALARM_GROUP_CREATE(ALARM_GROUP, CREATE, AlertGroupAuditOperatorImpl.class, new String[]{}, new String[]{ID}),
ALARM_GROUP_UPDATE(ALARM_GROUP, UPDATE, AlertGroupAuditOperatorImpl.class, new String[]{}, new String[]{ID}),
ALARM_GROUP_DELETE(ALARM_GROUP, DELETE, AlertGroupAuditOperatorImpl.class, new String[]{ID}, new String[]{}),
ALARM_INSTANCE_CREATE(ALARM_INSTANCE, CREATE, AlertInstanceAuditOperatorImpl.class, new String[]{},
new String[]{ID}),
ALARM_INSTANCE_UPDATE(ALARM_INSTANCE, UPDATE, AlertInstanceAuditOperatorImpl.class, new String[]{},
new String[]{ID}),
ALARM_INSTANCE_DELETE(ALARM_INSTANCE, DELETE, AlertInstanceAuditOperatorImpl.class, new String[]{ID},
new String[]{}),
WORKER_GROUP_CREATE(WORKER_GROUP, CREATE, WorkerGroupAuditOperatorImpl.class, new String[]{}, new String[]{ID}),
WORKER_GROUP_DELETE(WORKER_GROUP, DELETE, WorkerGroupAuditOperatorImpl.class, new String[]{ID}, new String[]{}),
YARN_QUEUE_CREATE(YARN_QUEUE, CREATE, YarnQueueAuditOperatorImpl.class, new String[]{}, new String[]{ID}),
YARN_QUEUE_UPDATE(YARN_QUEUE, UPDATE, YarnQueueAuditOperatorImpl.class, new String[]{}, new String[]{ID}),
YARN_QUEUE_DELETE(YARN_QUEUE, DELETE, YarnQueueAuditOperatorImpl.class, new String[]{ID}, new String[]{}),
ENVIRONMENT_CREATE(ENVIRONMENT, CREATE, EnvironmentAuditOperatorImpl.class, new String[]{}, new String[]{CODE}),
ENVIRONMENT_UPDATE(ENVIRONMENT, UPDATE, EnvironmentAuditOperatorImpl.class, new String[]{}, new String[]{CODE}),
ENVIRONMENT_DELETE(ENVIRONMENT, DELETE, EnvironmentAuditOperatorImpl.class, new String[]{ENVIRONMENT_CODE},
new String[]{}),
CLUSTER_CREATE(CLUSTER, CREATE, ClusterAuditOperatorImpl.class, new String[]{}, new String[]{CODE}),
CLUSTER_UPDATE(CLUSTER, UPDATE, ClusterAuditOperatorImpl.class, new String[]{}, new String[]{CODE}),
CLUSTER_DELETE(CLUSTER, DELETE, ClusterAuditOperatorImpl.class, new String[]{CLUSTER_CODE}, new String[]{}),
K8S_NAMESPACE_CREATE(K8S_NAMESPACE, CREATE, K8SNamespaceAuditOperatorImpl.class, new String[]{}, new String[]{ID}),
K8S_NAMESPACE_DELETE(K8S_NAMESPACE, DELETE, K8SNamespaceAuditOperatorImpl.class, new String[]{ID}, new String[]{}),
TOKEN_CREATE(TOKEN, CREATE, TokenAuditOperatorImpl.class, new String[]{}, new String[]{USER_ID}),
TOKEN_UPDATE(TOKEN, UPDATE, TokenAuditOperatorImpl.class, new String[]{}, new String[]{USER_ID}),
TOKEN_DELETE(TOKEN, DELETE, TokenAuditOperatorImpl.class, new String[]{ID}, new String[]{}),
;
private final Class<? extends AuditOperator> operatorClass;
private final AuditModelType auditModelType;
private final AuditOperationType auditOperationType;
/**
* The names of the fields in the API request to be recorded.
* Represents an array of key-value pairs, e.g., [ID, "status"].
*/
private final String[] requestParamName;
/**
* The names of the fields in the returned object to be recorded.
* Represents an array of field names, e.g., [ID, CODE].
* Specify the field names to record from the returned object.
*/
private final String[] returnObjectFieldName;
AuditType(AuditModelType auditModelType, AuditOperationType auditOperationType,
Class<? extends AuditOperator> operatorClass, String[] requestParamName, String[] returnObjectFieldName) {
this.auditModelType = auditModelType;
this.auditOperationType = auditOperationType;
this.operatorClass = operatorClass;
this.requestParamName = requestParamName;
this.returnObjectFieldName = returnObjectFieldName;
}
}

15
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/AuditSubscriber.java → dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/operator/AuditOperator.java

@ -15,14 +15,13 @@
* limitations under the License.
*/
package org.apache.dolphinscheduler.api.audit;
package org.apache.dolphinscheduler.api.audit.operator;
public interface AuditSubscriber {
import org.apache.dolphinscheduler.api.audit.enums.AuditType;
/**
* process the audit message
*
* @param message
*/
void execute(AuditMessage message);
import org.aspectj.lang.ProceedingJoinPoint;
public interface AuditOperator {
Object recordAudit(ProceedingJoinPoint point, String describe, AuditType auditType) throws Throwable;
}

208
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/operator/BaseAuditOperator.java

@ -0,0 +1,208 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dolphinscheduler.api.audit.operator;
import org.apache.dolphinscheduler.api.audit.OperatorUtils;
import org.apache.dolphinscheduler.api.audit.enums.AuditType;
import org.apache.dolphinscheduler.api.service.AuditService;
import org.apache.dolphinscheduler.api.utils.Result;
import org.apache.dolphinscheduler.dao.entity.AuditLog;
import org.apache.dolphinscheduler.dao.entity.User;
import org.apache.commons.lang3.math.NumberUtils;
import java.util.List;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.google.common.base.Strings;
@Service
@Slf4j
public abstract class BaseAuditOperator implements AuditOperator {
@Autowired
private AuditService auditService;
@Override
public Object recordAudit(ProceedingJoinPoint point, String describe, AuditType auditType) throws Throwable {
long beginTime = System.currentTimeMillis();
MethodSignature signature = (MethodSignature) point.getSignature();
Map<String, Object> paramsMap = OperatorUtils.getParamsMap(point, signature);
User user = OperatorUtils.getUser(paramsMap);
if (user == null) {
log.error("user is null");
return point.proceed();
}
List<AuditLog> auditLogList = OperatorUtils.buildAuditLogList(describe, auditType, user);
setRequestParam(auditType, auditLogList, paramsMap);
Result<?> result = (Result<?>) point.proceed();
if (OperatorUtils.resultFail(result)) {
log.error("request fail, code {}", result.getCode());
return result;
}
setObjectIdentityFromReturnObject(auditType, result, auditLogList);
modifyAuditOperationType(auditType, paramsMap, auditLogList);
modifyAuditObjectType(auditType, paramsMap, auditLogList);
long latency = System.currentTimeMillis() - beginTime;
auditService.addAudit(auditLogList, latency);
return result;
}
protected void setRequestParam(AuditType auditType, List<AuditLog> auditLogList, Map<String, Object> paramsMap) {
String[] paramNameArr = auditType.getRequestParamName();
if (paramNameArr.length == 0) {
return;
}
modifyRequestParams(paramNameArr, paramsMap, auditLogList);
setObjectByParma(paramNameArr, paramsMap, auditLogList);
if (auditLogList.get(0).getModelId() == null) {
auditLogList.get(0).setModelId(OperatorUtils.getObjectIdentityByParma(paramNameArr, paramsMap));
}
}
protected void setObjectByParma(String[] paramNameArr, Map<String, Object> paramsMap,
List<AuditLog> auditLogList) {
String name = paramNameArr[0];
Object value = paramsMap.get(name);
if (value == null) {
return;
}
String objName = getObjectNameFromReturnIdentity(value);
if (Strings.isNullOrEmpty(objName)) {
auditLogList.get(0).setModelName(value.toString());
return;
}
try {
long objectId = Long.parseLong(value.toString());
auditLogList.get(0).setModelId(objectId);
} catch (NumberFormatException e) {
log.error("value is not long, value: {}", value);
}
auditLogList.get(0).setModelName(objName);
}
protected void setObjectByParmaArr(String[] paramNameArr, Map<String, Object> paramsMap,
List<AuditLog> auditLogList) {
AuditLog auditLog = auditLogList.get(0);
for (String param : paramNameArr) {
if (!paramsMap.containsKey(param)) {
continue;
}
String[] identityArr = ((String) paramsMap.get(param)).split(",");
for (String identityString : identityArr) {
long identity = toLong(identityString);
String value = getObjectNameFromReturnIdentity(identity);
if (value == null) {
continue;
}
auditLog.setModelId(identity);
auditLog.setModelName(value);
auditLogList.add(auditLog);
auditLog = AuditLog.copyNewOne(auditLog);
}
}
auditLogList.remove(0);
}
protected void setObjectIdentityFromReturnObject(AuditType auditType, Result<?> result,
List<AuditLog> auditLogList) {
String[] returnObjectFieldNameArr = auditType.getReturnObjectFieldName();
if (returnObjectFieldNameArr.length == 0) {
return;
}
Map<String, Object> returnObjectMap =
OperatorUtils.getObjectIfFromReturnObject(result.getData(), returnObjectFieldNameArr);
modifyObjectFromReturnObject(returnObjectFieldNameArr, returnObjectMap, auditLogList);
setObjectNameFromReturnIdentity(auditLogList);
}
protected void setObjectNameFromReturnIdentity(List<AuditLog> auditLogList) {
auditLogList
.forEach(auditLog -> auditLog.setModelName(getObjectNameFromReturnIdentity(auditLog.getModelId())));
}
protected void modifyObjectFromReturnObject(String[] params, Map<String, Object> returnObjectMap,
List<AuditLog> auditLogList) {
if (returnObjectMap.isEmpty() || returnObjectMap.get(params[0]) == null) {
return;
}
Long objId = toLong(returnObjectMap.get(params[0]));
if (objId != -1) {
auditLogList.get(0).setModelId(objId);
}
}
protected Long toLong(Object str) {
if (str == null) {
return -1L;
}
return NumberUtils.toLong(str.toString(), -1);
}
protected String getObjectNameFromReturnIdentity(Object identity) {
return identity.toString();
}
protected void modifyRequestParams(String[] paramNameArr, Map<String, Object> paramsMap,
List<AuditLog> auditLogList) {
}
protected void modifyAuditObjectType(AuditType auditType, Map<String, Object> paramsMap,
List<AuditLog> auditLogList) {
}
protected void modifyAuditOperationType(AuditType auditType, Map<String, Object> paramsMap,
List<AuditLog> auditLogList) {
}
}

31
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/AuditSubscriberImpl.java → dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/operator/impl/AlertGroupAuditOperatorImpl.java

@ -15,28 +15,29 @@
* limitations under the License.
*/
package org.apache.dolphinscheduler.api.audit;
package org.apache.dolphinscheduler.api.audit.operator.impl;
import org.apache.dolphinscheduler.dao.entity.AuditLog;
import org.apache.dolphinscheduler.dao.mapper.AuditLogMapper;
import org.apache.dolphinscheduler.api.audit.operator.BaseAuditOperator;
import org.apache.dolphinscheduler.dao.entity.AlertGroup;
import org.apache.dolphinscheduler.dao.mapper.AlertGroupMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
@Component
public class AuditSubscriberImpl implements AuditSubscriber {
@Service
public class AlertGroupAuditOperatorImpl extends BaseAuditOperator {
@Autowired
private AuditLogMapper logMapper;
private AlertGroupMapper alertGroupMapper;
@Override
public void execute(AuditMessage message) {
AuditLog auditLog = new AuditLog();
auditLog.setUserId(message.getUser().getId());
auditLog.setResourceType(message.getResourceType().getCode());
auditLog.setOperation(message.getOperation().getCode());
auditLog.setTime(message.getAuditDate());
auditLog.setResourceId(message.getResourceId());
logMapper.insert(auditLog);
public String getObjectNameFromReturnIdentity(Object identity) {
Long objId = toLong(identity);
if (objId == -1) {
return "";
}
AlertGroup obj = alertGroupMapper.selectById(objId);
return obj == null ? "" : obj.getGroupName();
}
}

43
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/operator/impl/AlertInstanceAuditOperatorImpl.java

@ -0,0 +1,43 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dolphinscheduler.api.audit.operator.impl;
import org.apache.dolphinscheduler.api.audit.operator.BaseAuditOperator;
import org.apache.dolphinscheduler.dao.entity.AlertPluginInstance;
import org.apache.dolphinscheduler.dao.mapper.AlertPluginInstanceMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class AlertInstanceAuditOperatorImpl extends BaseAuditOperator {
@Autowired
private AlertPluginInstanceMapper alertPluginInstanceMapper;
@Override
public String getObjectNameFromReturnIdentity(Object identity) {
Long objId = toLong(identity);
if (objId == -1) {
return "";
}
AlertPluginInstance obj = alertPluginInstanceMapper.selectById(objId);
return obj == null ? "" : obj.getInstanceName();
}
}

43
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/operator/impl/ClusterAuditOperatorImpl.java

@ -0,0 +1,43 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dolphinscheduler.api.audit.operator.impl;
import org.apache.dolphinscheduler.api.audit.operator.BaseAuditOperator;
import org.apache.dolphinscheduler.dao.entity.Cluster;
import org.apache.dolphinscheduler.dao.mapper.ClusterMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class ClusterAuditOperatorImpl extends BaseAuditOperator {
@Autowired
private ClusterMapper clusterMapper;
@Override
public String getObjectNameFromReturnIdentity(Object identity) {
Long objId = toLong(identity);
if (objId == -1) {
return "";
}
Cluster obj = clusterMapper.queryByClusterCode(objId);
return obj == null ? "" : obj.getName();
}
}

43
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/operator/impl/DatasourceAuditOperatorImpl.java

@ -0,0 +1,43 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dolphinscheduler.api.audit.operator.impl;
import org.apache.dolphinscheduler.api.audit.operator.BaseAuditOperator;
import org.apache.dolphinscheduler.dao.entity.DataSource;
import org.apache.dolphinscheduler.dao.mapper.DataSourceMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class DatasourceAuditOperatorImpl extends BaseAuditOperator {
@Autowired
private DataSourceMapper dataSourceMapper;
@Override
public String getObjectNameFromReturnIdentity(Object identity) {
Long objId = toLong(identity);
if (objId == -1) {
return "";
}
DataSource obj = dataSourceMapper.selectById(objId);
return obj == null ? "" : obj.getName();
}
}

43
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/operator/impl/EnvironmentAuditOperatorImpl.java

@ -0,0 +1,43 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dolphinscheduler.api.audit.operator.impl;
import org.apache.dolphinscheduler.api.audit.operator.BaseAuditOperator;
import org.apache.dolphinscheduler.dao.entity.Environment;
import org.apache.dolphinscheduler.dao.mapper.EnvironmentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class EnvironmentAuditOperatorImpl extends BaseAuditOperator {
@Autowired
private EnvironmentMapper environmentMapper;
@Override
public String getObjectNameFromReturnIdentity(Object identity) {
Long objId = toLong(identity);
if (objId == -1) {
return "";
}
Environment obj = environmentMapper.queryByEnvironmentCode(objId);
return obj == null ? "" : obj.getName();
}
}

43
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/operator/impl/K8SNamespaceAuditOperatorImpl.java

@ -0,0 +1,43 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dolphinscheduler.api.audit.operator.impl;
import org.apache.dolphinscheduler.api.audit.operator.BaseAuditOperator;
import org.apache.dolphinscheduler.dao.entity.K8sNamespace;
import org.apache.dolphinscheduler.dao.mapper.K8sNamespaceMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class K8SNamespaceAuditOperatorImpl extends BaseAuditOperator {
@Autowired
private K8sNamespaceMapper k8sNamespaceMapper;
@Override
public String getObjectNameFromReturnIdentity(Object identity) {
Long objId = toLong(identity);
if (objId == -1) {
return "";
}
K8sNamespace obj = k8sNamespaceMapper.selectById(objId);
return obj == null ? "" : obj.getNamespace();
}
}

77
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/operator/impl/ProcessAuditOperatorImpl.java

@ -0,0 +1,77 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dolphinscheduler.api.audit.operator.impl;
import org.apache.dolphinscheduler.api.audit.OperatorUtils;
import org.apache.dolphinscheduler.api.audit.constants.AuditLogConstants;
import org.apache.dolphinscheduler.api.audit.enums.AuditType;
import org.apache.dolphinscheduler.api.audit.operator.BaseAuditOperator;
import org.apache.dolphinscheduler.common.enums.AuditOperationType;
import org.apache.dolphinscheduler.dao.entity.AuditLog;
import org.apache.dolphinscheduler.dao.entity.ProcessDefinition;
import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionMapper;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class ProcessAuditOperatorImpl extends BaseAuditOperator {
@Autowired
private ProcessDefinitionMapper processDefinitionMapper;
@Override
public void modifyAuditOperationType(AuditType auditType, Map<String, Object> paramsMap,
List<AuditLog> auditLogList) {
AuditOperationType auditOperationType = OperatorUtils.modifyReleaseOperationType(auditType, paramsMap);
auditLogList.forEach(auditLog -> auditLog.setOperationType(auditOperationType.getName()));
}
@Override
protected void setObjectByParma(String[] paramNameArr, Map<String, Object> paramsMap,
List<AuditLog> auditLogList) {
if (paramNameArr[0].equals(AuditLogConstants.CODES)
|| paramNameArr[0].equals(AuditLogConstants.PROCESS_DEFINITION_CODES)
|| paramNameArr[0].equals(AuditLogConstants.PROCESS_INSTANCE_IDS)) {
super.setObjectByParmaArr(paramNameArr, paramsMap, auditLogList);
} else {
super.setObjectByParma(paramNameArr, paramsMap, auditLogList);
}
if (paramsMap.containsKey(AuditLogConstants.VERSION)) {
if (paramsMap.get(AuditLogConstants.VERSION) != null) {
auditLogList.get(0).setDetail(paramsMap.get(AuditLogConstants.VERSION).toString());
} else {
auditLogList.get(0).setDetail("latest");
}
}
}
@Override
protected String getObjectNameFromReturnIdentity(Object identity) {
Long objId = toLong(identity);
if (objId == -1) {
return "";
}
ProcessDefinition obj = processDefinitionMapper.queryByCode(objId);
return obj == null ? "" : obj.getName();
}
}

70
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/operator/impl/ProcessInstanceAuditOperatorImpl.java

@ -0,0 +1,70 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dolphinscheduler.api.audit.operator.impl;
import org.apache.dolphinscheduler.api.audit.OperatorUtils;
import org.apache.dolphinscheduler.api.audit.constants.AuditLogConstants;
import org.apache.dolphinscheduler.api.audit.enums.AuditType;
import org.apache.dolphinscheduler.api.audit.operator.BaseAuditOperator;
import org.apache.dolphinscheduler.common.enums.AuditOperationType;
import org.apache.dolphinscheduler.dao.entity.AuditLog;
import org.apache.dolphinscheduler.dao.entity.ProcessInstance;
import org.apache.dolphinscheduler.dao.mapper.ProcessInstanceMapper;
import org.apache.commons.lang3.math.NumberUtils;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class ProcessInstanceAuditOperatorImpl extends BaseAuditOperator {
@Autowired
private ProcessInstanceMapper processInstanceMapper;
@Override
public void modifyAuditOperationType(AuditType auditType, Map<String, Object> paramsMap,
List<AuditLog> auditLogList) {
AuditOperationType auditOperationType = OperatorUtils.modifyReleaseOperationType(auditType, paramsMap);
auditLogList.forEach(auditLog -> auditLog.setOperationType(auditOperationType.getName()));
}
@Override
protected void setObjectByParma(String[] paramNameArr, Map<String, Object> paramsMap,
List<AuditLog> auditLogList) {
if (paramNameArr[0].equals(AuditLogConstants.PROCESS_INSTANCE_IDS)) {
super.setObjectByParmaArr(paramNameArr, paramsMap, auditLogList);
} else {
super.setObjectByParma(paramNameArr, paramsMap, auditLogList);
}
}
@Override
protected String getObjectNameFromReturnIdentity(Object identity) {
int objId = NumberUtils.toInt(identity.toString(), -1);
if (objId == -1) {
return "";
}
ProcessInstance obj = processInstanceMapper.queryDetailById(objId);
return obj == null ? "" : obj.getName();
}
}

46
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/operator/impl/ProjectAuditOperatorImpl.java

@ -0,0 +1,46 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dolphinscheduler.api.audit.operator.impl;
import org.apache.dolphinscheduler.api.audit.operator.BaseAuditOperator;
import org.apache.dolphinscheduler.dao.entity.Project;
import org.apache.dolphinscheduler.dao.mapper.ProjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
@Slf4j
public class ProjectAuditOperatorImpl extends BaseAuditOperator {
@Autowired
private ProjectMapper projectMapper;
@Override
protected String getObjectNameFromReturnIdentity(Object identity) {
Long objId = toLong(identity);
if (objId == -1) {
return "";
}
Project obj = projectMapper.queryByCode(objId);
return obj == null ? "" : obj.getName();
}
}

61
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/operator/impl/ResourceAuditOperatorImpl.java

@ -0,0 +1,61 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
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.BaseAuditOperator;
import org.apache.dolphinscheduler.dao.entity.AuditLog;
import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Service;
@Service
public class ResourceAuditOperatorImpl extends BaseAuditOperator {
@Override
public void modifyAuditObjectType(AuditType auditType, Map<String, Object> paramsMap, List<AuditLog> auditLogList) {
auditLogList.forEach(auditLog -> auditLog
.setModelType(OperatorUtils.getFileAuditObject(auditType, paramsMap, auditLog.getModelName())));
}
@Override
protected void setObjectByParma(String[] paramNameArr, Map<String, Object> paramsMap,
List<AuditLog> auditLogList) {
Object objName = getFileNameFromParam(paramNameArr, paramsMap);
if (objName == null) {
return;
}
auditLogList.get(0).setModelName(objName.toString());
}
private String getFileNameFromParam(String[] paramNameArr, Map<String, Object> paramsMap) {
for (String param : paramNameArr) {
if (!param.equals("type") && paramsMap.containsKey(param)) {
return paramsMap.get(param).toString();
}
}
return null;
}
}

84
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/operator/impl/ScheduleAuditOperatorImpl.java

@ -0,0 +1,84 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dolphinscheduler.api.audit.operator.impl;
import org.apache.dolphinscheduler.api.audit.OperatorUtils;
import org.apache.dolphinscheduler.api.audit.constants.AuditLogConstants;
import org.apache.dolphinscheduler.api.audit.enums.AuditType;
import org.apache.dolphinscheduler.api.audit.operator.BaseAuditOperator;
import org.apache.dolphinscheduler.api.utils.Result;
import org.apache.dolphinscheduler.dao.entity.AuditLog;
import org.apache.dolphinscheduler.dao.entity.ProcessDefinition;
import org.apache.dolphinscheduler.dao.entity.Schedule;
import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionMapper;
import org.apache.dolphinscheduler.dao.mapper.ScheduleMapper;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class ScheduleAuditOperatorImpl extends BaseAuditOperator {
@Autowired
private ScheduleMapper scheduleMapper;
@Autowired
private ProcessDefinitionMapper processDefinitionMapper;
@Override
public void modifyRequestParams(String[] paramNameArr, Map<String, Object> paramsMap, List<AuditLog> auditLogList) {
if (!paramNameArr[0].equals(AuditLogConstants.ID)) {
return;
}
int id = (int) paramsMap.get(paramNameArr[0]);
Schedule schedule = scheduleMapper.selectById(id);
if (schedule != null) {
paramsMap.put(AuditLogConstants.CODE, schedule.getProcessDefinitionCode());
paramNameArr[0] = AuditLogConstants.CODE;
auditLogList.forEach(auditLog -> auditLog.setDetail(String.valueOf(id)));
}
}
@Override
protected void setObjectIdentityFromReturnObject(AuditType auditType, Result<?> result,
List<AuditLog> auditLogList) {
String[] returnObjectFieldNameArr = auditType.getReturnObjectFieldName();
if (returnObjectFieldNameArr.length == 0) {
return;
}
Map<String, Object> returnObjectMap =
OperatorUtils.getObjectIfFromReturnObject(result.getData(), returnObjectFieldNameArr);
auditLogList
.forEach(auditLog -> auditLog.setDetail(returnObjectMap.get(returnObjectFieldNameArr[0]).toString()));
}
@Override
protected String getObjectNameFromReturnIdentity(Object identity) {
Long objId = toLong(identity);
if (objId == -1) {
return "";
}
ProcessDefinition obj = processDefinitionMapper.queryByCode(objId);
return obj == null ? "" : obj.getName();
}
}

68
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/operator/impl/TaskAuditOperatorImpl.java

@ -0,0 +1,68 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dolphinscheduler.api.audit.operator.impl;
import org.apache.dolphinscheduler.api.audit.OperatorUtils;
import org.apache.dolphinscheduler.api.audit.constants.AuditLogConstants;
import org.apache.dolphinscheduler.api.audit.enums.AuditType;
import org.apache.dolphinscheduler.api.audit.operator.BaseAuditOperator;
import org.apache.dolphinscheduler.common.enums.AuditOperationType;
import org.apache.dolphinscheduler.dao.entity.AuditLog;
import org.apache.dolphinscheduler.dao.entity.TaskDefinition;
import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionMapper;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class TaskAuditOperatorImpl extends BaseAuditOperator {
@Autowired
private TaskDefinitionMapper taskDefinitionMapper;
@Override
public void modifyAuditOperationType(AuditType auditType, Map<String, Object> paramsMap,
List<AuditLog> auditLogList) {
AuditOperationType auditOperationType = OperatorUtils.modifyReleaseOperationType(auditType, paramsMap);
auditLogList.forEach(auditLog -> auditLog.setOperationType(auditOperationType.getName()));
}
@Override
protected void setObjectByParma(String[] paramNameArr, Map<String, Object> paramsMap,
List<AuditLog> auditLogList) {
super.setObjectByParma(paramNameArr, paramsMap, auditLogList);
if (paramsMap.containsKey(AuditLogConstants.VERSION)) {
auditLogList.get(0).setDetail(paramsMap.get(AuditLogConstants.VERSION).toString());
}
}
@Override
protected String getObjectNameFromReturnIdentity(Object identity) {
Long objId = toLong(identity);
if (objId == -1) {
return "";
}
TaskDefinition obj = taskDefinitionMapper.queryByCode(objId);
return obj == null ? "" : obj.getName();
}
}

43
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/operator/impl/TaskGroupAuditOperatorImpl.java

@ -0,0 +1,43 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dolphinscheduler.api.audit.operator.impl;
import org.apache.dolphinscheduler.api.audit.operator.BaseAuditOperator;
import org.apache.dolphinscheduler.dao.entity.TaskGroup;
import org.apache.dolphinscheduler.dao.mapper.TaskGroupMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class TaskGroupAuditOperatorImpl extends BaseAuditOperator {
@Autowired
private TaskGroupMapper taskGroupMapper;
@Override
public String getObjectNameFromReturnIdentity(Object identity) {
Long objId = toLong(identity);
if (objId == -1) {
return "";
}
TaskGroup obj = taskGroupMapper.selectById(objId);
return obj == null ? "" : obj.getName();
}
}

43
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/operator/impl/TaskInstancesAuditOperatorImpl.java

@ -0,0 +1,43 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dolphinscheduler.api.audit.operator.impl;
import org.apache.dolphinscheduler.api.audit.operator.BaseAuditOperator;
import org.apache.dolphinscheduler.dao.entity.TaskInstance;
import org.apache.dolphinscheduler.dao.mapper.TaskInstanceMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class TaskInstancesAuditOperatorImpl extends BaseAuditOperator {
@Autowired
private TaskInstanceMapper taskInstanceMapper;
@Override
protected String getObjectNameFromReturnIdentity(Object identity) {
Long objId = toLong(identity);
if (objId == -1) {
return "";
}
TaskInstance obj = taskInstanceMapper.selectById(objId);
return obj == null ? "" : obj.getName();
}
}

43
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/operator/impl/TenantAuditOperatorImpl.java

@ -0,0 +1,43 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dolphinscheduler.api.audit.operator.impl;
import org.apache.dolphinscheduler.api.audit.operator.BaseAuditOperator;
import org.apache.dolphinscheduler.dao.entity.Tenant;
import org.apache.dolphinscheduler.dao.mapper.TenantMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class TenantAuditOperatorImpl extends BaseAuditOperator {
@Autowired
private TenantMapper tenantMapper;
@Override
public String getObjectNameFromReturnIdentity(Object identity) {
Long objId = toLong(identity);
if (objId == -1) {
return "";
}
Tenant obj = tenantMapper.selectById(objId);
return obj == null ? "" : obj.getTenantCode();
}
}

66
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/operator/impl/TokenAuditOperatorImpl.java

@ -0,0 +1,66 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dolphinscheduler.api.audit.operator.impl;
import org.apache.dolphinscheduler.api.audit.constants.AuditLogConstants;
import org.apache.dolphinscheduler.api.audit.enums.AuditType;
import org.apache.dolphinscheduler.api.audit.operator.BaseAuditOperator;
import org.apache.dolphinscheduler.dao.entity.AccessToken;
import org.apache.dolphinscheduler.dao.entity.AuditLog;
import org.apache.dolphinscheduler.dao.entity.User;
import org.apache.dolphinscheduler.dao.mapper.AccessTokenMapper;
import org.apache.dolphinscheduler.dao.mapper.UserMapper;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class TokenAuditOperatorImpl extends BaseAuditOperator {
@Autowired
private AccessTokenMapper accessTokenMapper;
@Autowired
private UserMapper userMapper;
@Override
public void modifyAuditOperationType(AuditType auditType, Map<String, Object> paramsMap,
List<AuditLog> auditLogList) {
if (paramsMap.get(AuditLogConstants.USER_ID) != null) {
User user = userMapper.selectById(paramsMap.get(AuditLogConstants.USER_ID).toString());
auditLogList.forEach(auditLog -> {
auditLog.setModelName(user.getUserName());
auditLog.setModelId(Long.valueOf(user.getId()));
});
}
}
@Override
public String getObjectNameFromReturnIdentity(Object identity) {
Long objId = toLong(identity);
if (objId == -1) {
return "";
}
AccessToken obj = accessTokenMapper.selectById(objId);
return obj == null ? "" : obj.getUserName();
}
}

46
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/operator/impl/UdfFunctionAuditOperatorImpl.java

@ -0,0 +1,46 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dolphinscheduler.api.audit.operator.impl;
import org.apache.dolphinscheduler.api.audit.operator.BaseAuditOperator;
import org.apache.dolphinscheduler.dao.entity.UdfFunc;
import org.apache.dolphinscheduler.dao.mapper.UdfFuncMapper;
import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class UdfFunctionAuditOperatorImpl extends BaseAuditOperator {
@Autowired
private UdfFuncMapper udfFuncMapper;
@Override
protected String getObjectNameFromReturnIdentity(Object identity) {
int objId = NumberUtils.toInt(identity.toString(), -1);
if (objId == -1) {
return "";
}
UdfFunc obj = udfFuncMapper.selectUdfById(objId);
return obj == null ? "" : obj.getFuncName();
}
}

43
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/operator/impl/UserAuditOperatorImpl.java

@ -0,0 +1,43 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dolphinscheduler.api.audit.operator.impl;
import org.apache.dolphinscheduler.api.audit.operator.BaseAuditOperator;
import org.apache.dolphinscheduler.dao.entity.User;
import org.apache.dolphinscheduler.dao.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class UserAuditOperatorImpl extends BaseAuditOperator {
@Autowired
private UserMapper userMapper;
@Override
public String getObjectNameFromReturnIdentity(Object identity) {
Long objId = toLong(identity);
if (objId == -1) {
return "";
}
User obj = userMapper.selectById(objId);
return obj == null ? "" : obj.getUserName();
}
}

60
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/operator/impl/WorkerGroupAuditOperatorImpl.java

@ -0,0 +1,60 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dolphinscheduler.api.audit.operator.impl;
import org.apache.dolphinscheduler.api.audit.constants.AuditLogConstants;
import org.apache.dolphinscheduler.api.audit.enums.AuditType;
import org.apache.dolphinscheduler.api.audit.operator.BaseAuditOperator;
import org.apache.dolphinscheduler.common.enums.AuditOperationType;
import org.apache.dolphinscheduler.dao.entity.AuditLog;
import org.apache.dolphinscheduler.dao.entity.WorkerGroup;
import org.apache.dolphinscheduler.dao.mapper.WorkerGroupMapper;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class WorkerGroupAuditOperatorImpl extends BaseAuditOperator {
@Autowired
private WorkerGroupMapper workerGroupMapper;
@Override
public void modifyAuditOperationType(AuditType auditType, Map<String, Object> paramsMap,
List<AuditLog> auditLogList) {
if (auditType.getAuditOperationType() == AuditOperationType.CREATE
&& paramsMap.get(AuditLogConstants.ID) != null &&
!paramsMap.get(AuditLogConstants.ID).toString().equals("0")) {
auditLogList.forEach(auditLog -> auditLog.setOperationType(AuditOperationType.UPDATE.getName()));
}
}
@Override
public String getObjectNameFromReturnIdentity(Object identity) {
Long objId = toLong(identity);
if (objId == -1) {
return "";
}
WorkerGroup obj = workerGroupMapper.selectById(objId);
return obj == null ? "" : obj.getName();
}
}

43
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/operator/impl/YarnQueueAuditOperatorImpl.java

@ -0,0 +1,43 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dolphinscheduler.api.audit.operator.impl;
import org.apache.dolphinscheduler.api.audit.operator.BaseAuditOperator;
import org.apache.dolphinscheduler.dao.entity.Queue;
import org.apache.dolphinscheduler.dao.mapper.QueueMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class YarnQueueAuditOperatorImpl extends BaseAuditOperator {
@Autowired
private QueueMapper queueMapper;
@Override
public String getObjectNameFromReturnIdentity(Object identity) {
Long objId = toLong(identity);
if (objId == -1) {
return "";
}
Queue obj = queueMapper.selectById(objId);
return obj == null ? "" : obj.getQueueName();
}
}

8
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/AccessTokenController.java

@ -24,6 +24,8 @@ import static org.apache.dolphinscheduler.api.enums.Status.QUERY_ACCESSTOKEN_BY_
import static org.apache.dolphinscheduler.api.enums.Status.QUERY_ACCESSTOKEN_LIST_PAGING_ERROR;
import static org.apache.dolphinscheduler.api.enums.Status.UPDATE_ACCESS_TOKEN_ERROR;
import org.apache.dolphinscheduler.api.audit.OperatorLog;
import org.apache.dolphinscheduler.api.audit.enums.AuditType;
import org.apache.dolphinscheduler.api.exceptions.ApiException;
import org.apache.dolphinscheduler.api.service.AccessTokenService;
import org.apache.dolphinscheduler.api.utils.PageInfo;
@ -83,6 +85,7 @@ public class AccessTokenController extends BaseController {
@PostMapping()
@ResponseStatus(HttpStatus.CREATED)
@ApiException(CREATE_ACCESS_TOKEN_ERROR)
@OperatorLog(auditType = AuditType.TOKEN_CREATE)
public Result<AccessToken> createToken(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "userId") int userId,
@RequestParam(value = "expireTime") String expireTime,
@ -169,13 +172,15 @@ public class AccessTokenController extends BaseController {
* @return delete result code
*/
@Parameter(hidden = true)
@Operation(summary = "deleteToken", description = "DELETE_TOKEN_NOTES")
@DeleteMapping(value = "/{id}")
@ResponseStatus(HttpStatus.OK)
@ApiException(DELETE_ACCESS_TOKEN_ERROR)
@OperatorLog(auditType = AuditType.TOKEN_DELETE)
public Result<Boolean> delAccessTokenById(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@PathVariable(value = "id") int id) {
accessTokenService.deleteAccessTokenById(loginUser, id);
return Result.success(true);
return Result.success(false);
}
/**
@ -198,6 +203,7 @@ public class AccessTokenController extends BaseController {
@PutMapping(value = "/{id}")
@ResponseStatus(HttpStatus.OK)
@ApiException(UPDATE_ACCESS_TOKEN_ERROR)
@OperatorLog(auditType = AuditType.TOKEN_UPDATE)
public Result<AccessToken> updateToken(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@PathVariable(value = "id") int id,
@RequestParam(value = "userId") int userId,

5
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/AlertGroupController.java

@ -24,6 +24,8 @@ import static org.apache.dolphinscheduler.api.enums.Status.QUERY_ALERT_GROUP_ERR
import static org.apache.dolphinscheduler.api.enums.Status.QUERY_ALL_ALERTGROUP_ERROR;
import static org.apache.dolphinscheduler.api.enums.Status.UPDATE_ALERT_GROUP_ERROR;
import org.apache.dolphinscheduler.api.audit.OperatorLog;
import org.apache.dolphinscheduler.api.audit.enums.AuditType;
import org.apache.dolphinscheduler.api.enums.Status;
import org.apache.dolphinscheduler.api.exceptions.ApiException;
import org.apache.dolphinscheduler.api.service.AlertGroupService;
@ -86,6 +88,7 @@ public class AlertGroupController extends BaseController {
@PostMapping()
@ResponseStatus(HttpStatus.CREATED)
@ApiException(CREATE_ALERT_GROUP_ERROR)
@OperatorLog(auditType = AuditType.ALARM_GROUP_CREATE)
public Result<AlertGroup> createAlertGroup(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "groupName") String groupName,
@RequestParam(value = "description", required = false) String description,
@ -195,6 +198,7 @@ public class AlertGroupController extends BaseController {
@PutMapping(value = "/{id}")
@ResponseStatus(HttpStatus.OK)
@ApiException(UPDATE_ALERT_GROUP_ERROR)
@OperatorLog(auditType = AuditType.ALARM_GROUP_UPDATE)
public Result<AlertGroup> updateAlertGroupById(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@PathVariable(value = "id") int id,
@RequestParam(value = "groupName") String groupName,
@ -219,6 +223,7 @@ public class AlertGroupController extends BaseController {
@DeleteMapping(value = "/{id}")
@ResponseStatus(HttpStatus.OK)
@ApiException(DELETE_ALERT_GROUP_ERROR)
@OperatorLog(auditType = AuditType.ALARM_GROUP_DELETE)
public Result<Boolean> deleteAlertGroupById(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@PathVariable(value = "id") int id) {
alertGroupService.deleteAlertGroupById(loginUser, id);

5
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/AlertPluginInstanceController.java

@ -25,6 +25,8 @@ import static org.apache.dolphinscheduler.api.enums.Status.QUERY_ALL_ALERT_PLUGI
import static org.apache.dolphinscheduler.api.enums.Status.SEND_TEST_ALERT_PLUGIN_INSTANCE_ERROR;
import static org.apache.dolphinscheduler.api.enums.Status.UPDATE_ALERT_PLUGIN_INSTANCE_ERROR;
import org.apache.dolphinscheduler.api.audit.OperatorLog;
import org.apache.dolphinscheduler.api.audit.enums.AuditType;
import org.apache.dolphinscheduler.api.enums.Status;
import org.apache.dolphinscheduler.api.exceptions.ApiException;
import org.apache.dolphinscheduler.api.service.AlertPluginInstanceService;
@ -91,6 +93,7 @@ public class AlertPluginInstanceController extends BaseController {
@PostMapping()
@ResponseStatus(HttpStatus.CREATED)
@ApiException(CREATE_ALERT_PLUGIN_INSTANCE_ERROR)
@OperatorLog(auditType = AuditType.ALARM_INSTANCE_CREATE)
public Result<AlertPluginInstance> createAlertPluginInstance(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "pluginDefineId") int pluginDefineId,
@RequestParam(value = "instanceName") String instanceName,
@ -134,6 +137,7 @@ public class AlertPluginInstanceController extends BaseController {
@PutMapping(value = "/{id}")
@ResponseStatus(HttpStatus.OK)
@ApiException(UPDATE_ALERT_PLUGIN_INSTANCE_ERROR)
@OperatorLog(auditType = AuditType.ALARM_INSTANCE_UPDATE)
public Result<AlertPluginInstance> updateAlertPluginInstanceById(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@PathVariable(value = "id") int id,
@RequestParam(value = "instanceName") String instanceName,
@ -158,6 +162,7 @@ public class AlertPluginInstanceController extends BaseController {
@DeleteMapping(value = "/{id}")
@ResponseStatus(HttpStatus.OK)
@ApiException(DELETE_ALERT_PLUGIN_INSTANCE_ERROR)
@OperatorLog(auditType = AuditType.ALARM_INSTANCE_DELETE)
public Result<Boolean> deleteAlertPluginInstance(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@PathVariable(value = "id") int id) {

59
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/AuditLogController.java

@ -20,15 +20,17 @@ package org.apache.dolphinscheduler.api.controller;
import static org.apache.dolphinscheduler.api.enums.Status.QUERY_AUDIT_LOG_LIST_PAGING;
import org.apache.dolphinscheduler.api.dto.AuditDto;
import org.apache.dolphinscheduler.api.dto.auditLog.AuditModelTypeDto;
import org.apache.dolphinscheduler.api.dto.auditLog.AuditOperationTypeDto;
import org.apache.dolphinscheduler.api.exceptions.ApiException;
import org.apache.dolphinscheduler.api.service.AuditService;
import org.apache.dolphinscheduler.api.utils.PageInfo;
import org.apache.dolphinscheduler.api.utils.Result;
import org.apache.dolphinscheduler.common.constants.Constants;
import org.apache.dolphinscheduler.common.enums.AuditOperationType;
import org.apache.dolphinscheduler.common.enums.AuditResourceType;
import org.apache.dolphinscheduler.dao.entity.User;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
@ -57,21 +59,23 @@ public class AuditLogController extends BaseController {
*
* @param loginUser login user
* @param pageNo page number
* @param resourceType resource type
* @param operationType operation type
* @param pageSize page size
* @param modelTypes model types
* @param operationTypes operation types
* @param userName user name
* @param modelName model name
* @param startDate start time
* @param endDate end time
* @param userName user name
* @param pageSize page size
* @return audit log content
*/
@Operation(summary = "queryAuditLogListPaging", description = "QUERY_AUDIT_LOG")
@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 = "resourceType", description = "RESOURCE_TYPE", schema = @Schema(implementation = AuditResourceType.class)),
@Parameter(name = "operationType", description = "OPERATION_TYPE", schema = @Schema(implementation = AuditOperationType.class)),
@Parameter(name = "objectTypes", description = "MODEL_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 = "MODEL_NAME", schema = @Schema(implementation = String.class)),
@Parameter(name = "pageNo", description = "PAGE_NO", required = true, schema = @Schema(implementation = int.class, example = "1")),
@Parameter(name = "pageSize", description = "PAGE_SIZE", required = true, schema = @Schema(implementation = int.class, example = "20"))
})
@ -81,21 +85,48 @@ public class AuditLogController extends BaseController {
public Result<PageInfo<AuditDto>> queryAuditLogListPaging(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("pageNo") Integer pageNo,
@RequestParam("pageSize") Integer pageSize,
@RequestParam(value = "resourceType", required = false) AuditResourceType resourceType,
@RequestParam(value = "operationType", required = false) AuditOperationType operationType,
@RequestParam(value = "modelTypes", required = false) String modelTypes,
@RequestParam(value = "operationTypes", required = false) String operationTypes,
@RequestParam(value = "startDate", required = false) String startDate,
@RequestParam(value = "endDate", required = false) String endDate,
@RequestParam(value = "userName", required = false) String userName) {
@RequestParam(value = "userName", required = false) String userName,
@RequestParam(value = "modelName", required = false) String modelName) {
checkPageParams(pageNo, pageSize);
PageInfo<AuditDto> auditDtoPageInfo = auditService.queryLogListPaging(
loginUser,
resourceType,
operationType,
modelTypes,
operationTypes,
startDate,
endDate,
userName,
modelName,
pageNo,
pageSize);
return Result.success(auditDtoPageInfo);
}
/**
* query audit log operation type list
*
* @return object type list
*/
@Operation(summary = "queryAuditOperationTypeList", description = "QUERY_AUDIT_OPERATION_TYPE_LIST")
@GetMapping(value = "/audit-log-operation-type")
@ResponseStatus(HttpStatus.OK)
@ApiException(QUERY_AUDIT_LOG_LIST_PAGING)
public Result<List<AuditOperationTypeDto>> queryAuditOperationTypeList() {
return Result.success(AuditOperationTypeDto.getOperationTypeDtoList());
}
/**
* query audit log model type list
*
* @return model type list
*/
@Operation(summary = "queryAuditModelTypeList", description = "QUERY_AUDIT_MODEL_TYPE_LIST")
@GetMapping(value = "/audit-log-model-type")
@ResponseStatus(HttpStatus.OK)
@ApiException(QUERY_AUDIT_LOG_LIST_PAGING)
public Result<List<AuditModelTypeDto>> queryAuditModelTypeList() {
return Result.success(AuditModelTypeDto.getModelTypeDtoList());
}
}

5
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ClusterController.java

@ -24,6 +24,8 @@ import static org.apache.dolphinscheduler.api.enums.Status.QUERY_CLUSTER_ERROR;
import static org.apache.dolphinscheduler.api.enums.Status.UPDATE_CLUSTER_ERROR;
import static org.apache.dolphinscheduler.api.enums.Status.VERIFY_CLUSTER_ERROR;
import org.apache.dolphinscheduler.api.audit.OperatorLog;
import org.apache.dolphinscheduler.api.audit.enums.AuditType;
import org.apache.dolphinscheduler.api.dto.ClusterDto;
import org.apache.dolphinscheduler.api.exceptions.ApiException;
import org.apache.dolphinscheduler.api.service.ClusterService;
@ -81,6 +83,7 @@ public class ClusterController extends BaseController {
@PostMapping(value = "/create")
@ResponseStatus(HttpStatus.CREATED)
@ApiException(CREATE_CLUSTER_ERROR)
@OperatorLog(auditType = AuditType.CLUSTER_CREATE)
public Result<Long> createCluster(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("name") String name,
@RequestParam("config") String config,
@ -110,6 +113,7 @@ public class ClusterController extends BaseController {
@PostMapping(value = "/update")
@ResponseStatus(HttpStatus.OK)
@ApiException(UPDATE_CLUSTER_ERROR)
@OperatorLog(auditType = AuditType.CLUSTER_UPDATE)
public Result<Cluster> updateCluster(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("code") Long code,
@RequestParam("name") String name,
@ -181,6 +185,7 @@ public class ClusterController extends BaseController {
@PostMapping(value = "/delete")
@ResponseStatus(HttpStatus.OK)
@ApiException(DELETE_CLUSTER_ERROR)
@OperatorLog(auditType = AuditType.CLUSTER_DELETE)
public Result<Boolean> deleteCluster(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("clusterCode") Long clusterCode) {

5
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/DataSourceController.java

@ -31,6 +31,8 @@ import static org.apache.dolphinscheduler.api.enums.Status.UNAUTHORIZED_DATASOUR
import static org.apache.dolphinscheduler.api.enums.Status.UPDATE_DATASOURCE_ERROR;
import static org.apache.dolphinscheduler.api.enums.Status.VERIFY_DATASOURCE_NAME_FAILURE;
import org.apache.dolphinscheduler.api.audit.OperatorLog;
import org.apache.dolphinscheduler.api.audit.enums.AuditType;
import org.apache.dolphinscheduler.api.enums.Status;
import org.apache.dolphinscheduler.api.exceptions.ApiException;
import org.apache.dolphinscheduler.api.service.DataSourceService;
@ -92,6 +94,7 @@ public class DataSourceController extends BaseController {
@PostMapping()
@ResponseStatus(HttpStatus.CREATED)
@ApiException(CREATE_DATASOURCE_ERROR)
@OperatorLog(auditType = AuditType.DATASOURCE_CREATE)
public Result<DataSource> createDataSource(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@Parameter(name = "dataSourceParam", description = "DATA_SOURCE_PARAM", required = true) @RequestBody String jsonStr) {
BaseDataSourceParamDTO dataSourceParam = DataSourceUtils.buildDatasourceParam(jsonStr);
@ -116,6 +119,7 @@ public class DataSourceController extends BaseController {
@PutMapping(value = "/{id}")
@ResponseStatus(HttpStatus.OK)
@ApiException(UPDATE_DATASOURCE_ERROR)
@OperatorLog(auditType = AuditType.DATASOURCE_UPDATE)
public Result<DataSource> updateDataSource(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@PathVariable(value = "id") Integer id,
@RequestBody String jsonStr) {
@ -250,6 +254,7 @@ public class DataSourceController extends BaseController {
@DeleteMapping(value = "/{id}")
@ResponseStatus(HttpStatus.OK)
@ApiException(DELETE_DATA_SOURCE_FAILURE)
@OperatorLog(auditType = AuditType.DATASOURCE_DELETE)
public Result<Boolean> deleteDataSource(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@PathVariable("id") int id) {
dataSourceService.delete(loginUser, id);

5
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/EnvironmentController.java

@ -24,6 +24,8 @@ import static org.apache.dolphinscheduler.api.enums.Status.QUERY_ENVIRONMENT_ERR
import static org.apache.dolphinscheduler.api.enums.Status.UPDATE_ENVIRONMENT_ERROR;
import static org.apache.dolphinscheduler.api.enums.Status.VERIFY_ENVIRONMENT_ERROR;
import org.apache.dolphinscheduler.api.audit.OperatorLog;
import org.apache.dolphinscheduler.api.audit.enums.AuditType;
import org.apache.dolphinscheduler.api.exceptions.ApiException;
import org.apache.dolphinscheduler.api.service.EnvironmentService;
import org.apache.dolphinscheduler.api.utils.Result;
@ -80,6 +82,7 @@ public class EnvironmentController extends BaseController {
@PostMapping(value = "/create")
@ResponseStatus(HttpStatus.CREATED)
@ApiException(CREATE_ENVIRONMENT_ERROR)
@OperatorLog(auditType = AuditType.ENVIRONMENT_CREATE)
public Result<Long> createEnvironment(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("name") String name,
@RequestParam("config") String config,
@ -111,6 +114,7 @@ public class EnvironmentController extends BaseController {
@PostMapping(value = "/update")
@ResponseStatus(HttpStatus.OK)
@ApiException(UPDATE_ENVIRONMENT_ERROR)
@OperatorLog(auditType = AuditType.ENVIRONMENT_UPDATE)
public Result<Environment> updateEnvironment(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("code") Long code,
@RequestParam("name") String name,
@ -183,6 +187,7 @@ public class EnvironmentController extends BaseController {
@PostMapping(value = "/delete")
@ResponseStatus(HttpStatus.OK)
@ApiException(DELETE_ENVIRONMENT_ERROR)
@OperatorLog(auditType = AuditType.ENVIRONMENT_DELETE)
public Result deleteEnvironment(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("environmentCode") Long environmentCode) {

8
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ExecutorController.java

@ -25,6 +25,8 @@ import static org.apache.dolphinscheduler.api.enums.Status.QUERY_EXECUTING_WORKF
import static org.apache.dolphinscheduler.api.enums.Status.START_PROCESS_INSTANCE_ERROR;
import static org.apache.dolphinscheduler.api.enums.Status.START_TASK_INSTANCE_ERROR;
import org.apache.dolphinscheduler.api.audit.OperatorLog;
import org.apache.dolphinscheduler.api.audit.enums.AuditType;
import org.apache.dolphinscheduler.api.enums.ExecuteType;
import org.apache.dolphinscheduler.api.enums.Status;
import org.apache.dolphinscheduler.api.exceptions.ApiException;
@ -132,6 +134,7 @@ public class ExecutorController extends BaseController {
@PostMapping(value = "start-process-instance")
@ResponseStatus(HttpStatus.OK)
@ApiException(START_PROCESS_INSTANCE_ERROR)
@OperatorLog(auditType = AuditType.PROCESS_START)
public Result startProcessInstance(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@RequestParam(value = "processDefinitionCode") long processDefinitionCode,
@ -229,6 +232,7 @@ public class ExecutorController extends BaseController {
@PostMapping(value = "batch-start-process-instance")
@ResponseStatus(HttpStatus.OK)
@ApiException(BATCH_START_PROCESS_INSTANCE_ERROR)
@OperatorLog(auditType = AuditType.PROCESS_BATCH_START)
public Result batchStartProcessInstance(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@RequestParam(value = "processDefinitionCodes") String processDefinitionCodes,
@ -318,6 +322,7 @@ public class ExecutorController extends BaseController {
@PostMapping(value = "/execute")
@ResponseStatus(HttpStatus.OK)
@ApiException(EXECUTE_PROCESS_INSTANCE_ERROR)
@OperatorLog(auditType = AuditType.PROCESS_EXECUTE)
public Result execute(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@RequestParam("processInstanceId") Integer processInstanceId,
@ -344,6 +349,7 @@ public class ExecutorController extends BaseController {
@PostMapping(value = "/batch-execute")
@ResponseStatus(HttpStatus.OK)
@ApiException(BATCH_EXECUTE_PROCESS_INSTANCE_ERROR)
@OperatorLog(auditType = AuditType.PROCESS_BATCH_RERUN)
public Result batchExecute(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@PathVariable long projectCode,
@RequestParam("processInstanceIds") String processInstanceIds,
@ -440,6 +446,7 @@ public class ExecutorController extends BaseController {
@PostMapping(value = "/task-instance/{code}/start")
@ResponseStatus(HttpStatus.OK)
@ApiException(START_TASK_INSTANCE_ERROR)
@OperatorLog(auditType = AuditType.TASK_START)
public Result<Boolean> startStreamTaskInstance(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@Parameter(name = "code", description = "TASK_CODE", required = true) @PathVariable long code,
@ -482,6 +489,7 @@ public class ExecutorController extends BaseController {
@PostMapping(value = "/execute-task")
@ResponseStatus(HttpStatus.OK)
@ApiException(EXECUTE_PROCESS_INSTANCE_ERROR)
@OperatorLog(auditType = AuditType.PROCESS_EXECUTE)
public Result executeTask(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@RequestParam("processInstanceId") Integer processInstanceId,

4
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/K8sNamespaceController.java

@ -25,6 +25,8 @@ import static org.apache.dolphinscheduler.api.enums.Status.QUERY_K8S_NAMESPACE_L
import static org.apache.dolphinscheduler.api.enums.Status.QUERY_UNAUTHORIZED_NAMESPACE_ERROR;
import static org.apache.dolphinscheduler.api.enums.Status.VERIFY_K8S_NAMESPACE_ERROR;
import org.apache.dolphinscheduler.api.audit.OperatorLog;
import org.apache.dolphinscheduler.api.audit.enums.AuditType;
import org.apache.dolphinscheduler.api.exceptions.ApiException;
import org.apache.dolphinscheduler.api.service.K8sNamespaceService;
import org.apache.dolphinscheduler.api.utils.Result;
@ -107,6 +109,7 @@ public class K8sNamespaceController extends BaseController {
@PostMapping()
@ResponseStatus(HttpStatus.CREATED)
@ApiException(CREATE_K8S_NAMESPACE_ERROR)
@OperatorLog(auditType = AuditType.K8S_NAMESPACE_CREATE)
public Result createNamespace(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "namespace") String namespace,
@RequestParam(value = "clusterCode") Long clusterCode) {
@ -152,6 +155,7 @@ public class K8sNamespaceController extends BaseController {
@PostMapping(value = "/delete")
@ResponseStatus(HttpStatus.OK)
@ApiException(DELETE_K8S_NAMESPACE_BY_ID_ERROR)
@OperatorLog(auditType = AuditType.K8S_NAMESPACE_DELETE)
public Result delNamespaceById(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "id") int id) {
Map<String, Object> result = k8sNamespaceService.deleteNamespaceById(loginUser, id);

23
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessDefinitionController.java

@ -36,6 +36,8 @@ import static org.apache.dolphinscheduler.api.enums.Status.SWITCH_PROCESS_DEFINI
import static org.apache.dolphinscheduler.api.enums.Status.UPDATE_PROCESS_DEFINITION_ERROR;
import static org.apache.dolphinscheduler.api.enums.Status.VERIFY_PROCESS_DEFINITION_NAME_UNIQUE_ERROR;
import org.apache.dolphinscheduler.api.audit.OperatorLog;
import org.apache.dolphinscheduler.api.audit.enums.AuditType;
import org.apache.dolphinscheduler.api.enums.Status;
import org.apache.dolphinscheduler.api.exceptions.ApiException;
import org.apache.dolphinscheduler.api.service.ProcessDefinitionService;
@ -112,6 +114,7 @@ public class ProcessDefinitionController extends BaseController {
@PostMapping()
@ResponseStatus(HttpStatus.CREATED)
@ApiException(CREATE_PROCESS_DEFINITION_ERROR)
@OperatorLog(auditType = AuditType.PROCESS_CREATE)
public Result createProcessDefinition(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@RequestParam(value = "name", required = true) String name,
@ -146,6 +149,7 @@ public class ProcessDefinitionController extends BaseController {
@PostMapping(value = "/batch-copy")
@ResponseStatus(HttpStatus.OK)
@ApiException(BATCH_COPY_PROCESS_DEFINITION_ERROR)
@OperatorLog(auditType = AuditType.PROCESS_COPY)
public Result copyProcessDefinition(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@RequestParam(value = "codes", required = true) String codes,
@ -232,6 +236,7 @@ public class ProcessDefinitionController extends BaseController {
@PutMapping(value = "/{code}")
@ResponseStatus(HttpStatus.OK)
@ApiException(UPDATE_PROCESS_DEFINITION_ERROR)
@OperatorLog(auditType = AuditType.PROCESS_UPDATE)
public Result updateProcessDefinition(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@RequestParam(value = "name", required = true) String name,
@ -307,6 +312,7 @@ public class ProcessDefinitionController extends BaseController {
@GetMapping(value = "/{code}/versions/{version}")
@ResponseStatus(HttpStatus.OK)
@ApiException(SWITCH_PROCESS_DEFINITION_VERSION_ERROR)
@OperatorLog(auditType = AuditType.PROCESS_SWITCH_VERSION)
public Result switchProcessDefinitionVersion(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@PathVariable(value = "code") long code,
@ -333,12 +339,12 @@ public class ProcessDefinitionController extends BaseController {
@DeleteMapping(value = "/{code}/versions/{version}")
@ResponseStatus(HttpStatus.OK)
@ApiException(DELETE_PROCESS_DEFINITION_VERSION_ERROR)
@OperatorLog(auditType = AuditType.PROCESS_DELETE_VERSION)
public Result<Void> deleteProcessDefinitionVersion(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@PathVariable(value = "code") long workflowDefinitionCode,
@PathVariable(value = "version") int workflowDefinitionVersion) {
processDefinitionService.deleteProcessDefinitionVersion(loginUser, projectCode, workflowDefinitionCode,
workflowDefinitionVersion);
@PathVariable(value = "code") long code,
@PathVariable(value = "version") int version) {
processDefinitionService.deleteProcessDefinitionVersion(loginUser, projectCode, code, version);
return Result.success();
}
@ -351,6 +357,7 @@ public class ProcessDefinitionController extends BaseController {
@PostMapping(value = "/{code}/release")
@ResponseStatus(HttpStatus.OK)
@ApiException(RELEASE_PROCESS_DEFINITION_ERROR)
@OperatorLog(auditType = AuditType.PROCESS_RELEASE)
public Result<Boolean> releaseProcessDefinition(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@PathVariable(value = "code", required = true) long workflowDefinitionCode,
@ -611,10 +618,11 @@ public class ProcessDefinitionController extends BaseController {
@DeleteMapping(value = "/{code}")
@ResponseStatus(HttpStatus.OK)
@ApiException(DELETE_PROCESS_DEFINE_BY_CODE_ERROR)
@OperatorLog(auditType = AuditType.PROCESS_DELETE)
public Result deleteProcessDefinitionByCode(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@PathVariable("code") long workflowDefinitionCode) {
processDefinitionService.deleteProcessDefinitionByCode(loginUser, workflowDefinitionCode);
@PathVariable("code") long code) {
processDefinitionService.deleteProcessDefinitionByCode(loginUser, code);
return new Result(Status.SUCCESS);
}
@ -633,6 +641,7 @@ public class ProcessDefinitionController extends BaseController {
@PostMapping(value = "/batch-delete")
@ResponseStatus(HttpStatus.OK)
@ApiException(BATCH_DELETE_PROCESS_DEFINE_BY_CODES_ERROR)
@OperatorLog(auditType = AuditType.PROCESS_BATCH_DELETE)
public Result batchDeleteProcessDefinitionByCodes(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@RequestParam("codes") String codes) {
@ -656,6 +665,7 @@ public class ProcessDefinitionController extends BaseController {
})
@PostMapping(value = "/batch-export")
@ResponseBody
@OperatorLog(auditType = AuditType.PROCESS_EXPORT)
public void batchExportProcessDefinitionByCodes(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@RequestParam("codes") String codes,
@ -699,6 +709,7 @@ public class ProcessDefinitionController extends BaseController {
})
@PostMapping(value = "/import")
@ApiException(IMPORT_PROCESS_DEFINE_ERROR)
@OperatorLog(auditType = AuditType.PROCESS_IMPORT)
public Result importProcessDefinition(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@RequestParam("file") MultipartFile file) {

5
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessInstanceController.java

@ -19,6 +19,8 @@ package org.apache.dolphinscheduler.api.controller;
import static org.apache.dolphinscheduler.api.enums.Status.QUERY_PROCESS_INSTANCE_LIST_PAGING_ERROR;
import org.apache.dolphinscheduler.api.audit.OperatorLog;
import org.apache.dolphinscheduler.api.audit.enums.AuditType;
import org.apache.dolphinscheduler.api.dto.DynamicSubWorkflowDto;
import org.apache.dolphinscheduler.api.enums.Status;
import org.apache.dolphinscheduler.api.exceptions.ApiException;
@ -173,6 +175,7 @@ public class ProcessInstanceController extends BaseController {
@PutMapping(value = "/{id}")
@ResponseStatus(HttpStatus.OK)
@ApiException(Status.UPDATE_PROCESS_INSTANCE_ERROR)
@OperatorLog(auditType = AuditType.PROCESS_INSTANCE_UPDATE)
public Result updateProcessInstance(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@RequestParam(value = "taskRelationJson", required = true) String taskRelationJson,
@ -255,6 +258,7 @@ public class ProcessInstanceController extends BaseController {
@DeleteMapping(value = "/{id}")
@ResponseStatus(HttpStatus.OK)
@ApiException(Status.DELETE_PROCESS_INSTANCE_BY_ID_ERROR)
@OperatorLog(auditType = AuditType.PROCESS_INSTANCE_DELETE)
public Result<Void> deleteProcessInstanceById(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@PathVariable("id") Integer id) {
@ -388,6 +392,7 @@ public class ProcessInstanceController extends BaseController {
@PostMapping(value = "/batch-delete")
@ResponseStatus(HttpStatus.OK)
@ApiException(Status.BATCH_DELETE_PROCESS_INSTANCE_BY_IDS_ERROR)
@OperatorLog(auditType = AuditType.PROCESS_INSTANCE_BATCH_DELETE)
public Result batchDeleteProcessInstanceByIds(@RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@PathVariable long projectCode,
@RequestParam("processInstanceIds") String processInstanceIds) {

9
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProjectController.java

@ -27,7 +27,10 @@ import static org.apache.dolphinscheduler.api.enums.Status.QUERY_PROJECT_DETAILS
import static org.apache.dolphinscheduler.api.enums.Status.QUERY_UNAUTHORIZED_PROJECT_ERROR;
import static org.apache.dolphinscheduler.api.enums.Status.UPDATE_PROJECT_ERROR;
import org.apache.dolphinscheduler.api.audit.OperatorLog;
import org.apache.dolphinscheduler.api.audit.enums.AuditType;
import org.apache.dolphinscheduler.api.exceptions.ApiException;
import org.apache.dolphinscheduler.api.service.AuditService;
import org.apache.dolphinscheduler.api.service.ProjectService;
import org.apache.dolphinscheduler.api.utils.Result;
import org.apache.dolphinscheduler.common.constants.Constants;
@ -67,6 +70,9 @@ public class ProjectController extends BaseController {
@Autowired
private ProjectService projectService;
@Autowired
private AuditService auditService;
/**
* create project
*
@ -83,6 +89,7 @@ public class ProjectController extends BaseController {
@PostMapping()
@ResponseStatus(HttpStatus.CREATED)
@ApiException(CREATE_PROJECT_ERROR)
@OperatorLog(auditType = AuditType.PROJECT_CREATE)
public Result createProject(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("projectName") String projectName,
@RequestParam(value = "description", required = false) String description) {
@ -107,6 +114,7 @@ public class ProjectController extends BaseController {
@PutMapping(value = "/{code}")
@ResponseStatus(HttpStatus.OK)
@ApiException(UPDATE_PROJECT_ERROR)
@OperatorLog(auditType = AuditType.PROJECT_UPDATE)
public Result updateProject(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@PathVariable("code") Long code,
@RequestParam("projectName") String projectName,
@ -207,6 +215,7 @@ public class ProjectController extends BaseController {
@DeleteMapping(value = "/{code}")
@ResponseStatus(HttpStatus.OK)
@ApiException(DELETE_PROJECT_ERROR)
@OperatorLog(auditType = AuditType.PROJECT_DELETE)
public Result deleteProject(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@PathVariable("code") Long code) {
return projectService.deleteProject(loginUser, code);

5
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/QueueController.java

@ -23,6 +23,8 @@ import static org.apache.dolphinscheduler.api.enums.Status.QUERY_QUEUE_LIST_ERRO
import static org.apache.dolphinscheduler.api.enums.Status.UPDATE_QUEUE_ERROR;
import static org.apache.dolphinscheduler.api.enums.Status.VERIFY_QUEUE_ERROR;
import org.apache.dolphinscheduler.api.audit.OperatorLog;
import org.apache.dolphinscheduler.api.audit.enums.AuditType;
import org.apache.dolphinscheduler.api.exceptions.ApiException;
import org.apache.dolphinscheduler.api.service.QueueService;
import org.apache.dolphinscheduler.api.utils.PageInfo;
@ -124,6 +126,7 @@ public class QueueController extends BaseController {
@PostMapping()
@ResponseStatus(HttpStatus.CREATED)
@ApiException(CREATE_QUEUE_ERROR)
@OperatorLog(auditType = AuditType.YARN_QUEUE_CREATE)
public Result<Queue> createQueue(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "queue") String queue,
@RequestParam(value = "queueName") String queueName) {
@ -148,6 +151,7 @@ public class QueueController extends BaseController {
@PutMapping(value = "/{id}")
@ResponseStatus(HttpStatus.CREATED)
@ApiException(UPDATE_QUEUE_ERROR)
@OperatorLog(auditType = AuditType.YARN_QUEUE_UPDATE)
public Result<Queue> updateQueue(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@PathVariable(value = "id") int id,
@RequestParam(value = "queue") String queue,
@ -169,6 +173,7 @@ public class QueueController extends BaseController {
@DeleteMapping(value = "/{id}")
@ResponseStatus(HttpStatus.OK)
@ApiException(DELETE_QUEUE_BY_ID_ERROR)
@OperatorLog(auditType = AuditType.YARN_QUEUE_DELETE)
public Result<Boolean> deleteQueueById(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@PathVariable(value = "id") int id) throws Exception {
queueService.deleteQueueById(loginUser, id);

11
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ResourcesController.java

@ -37,6 +37,8 @@ import static org.apache.dolphinscheduler.api.enums.Status.VERIFY_UDF_FUNCTION_N
import static org.apache.dolphinscheduler.api.enums.Status.VIEW_RESOURCE_FILE_ON_LINE_ERROR;
import static org.apache.dolphinscheduler.api.enums.Status.VIEW_UDF_FUNCTION_ERROR;
import org.apache.dolphinscheduler.api.audit.OperatorLog;
import org.apache.dolphinscheduler.api.audit.enums.AuditType;
import org.apache.dolphinscheduler.api.dto.resources.DeleteDataTransferResponse;
import org.apache.dolphinscheduler.api.exceptions.ApiException;
import org.apache.dolphinscheduler.api.service.ResourcesService;
@ -111,6 +113,7 @@ public class ResourcesController extends BaseController {
@Parameter(name = "currentDir", description = "RESOURCE_CURRENT_DIR", required = true, schema = @Schema(implementation = String.class))})
@PostMapping(value = "/directory")
@ApiException(CREATE_RESOURCE_ERROR)
@OperatorLog(auditType = AuditType.FOLDER_CREATE)
public Result<Object> createDirectory(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "type") ResourceType type,
@RequestParam(value = "name") String alias,
@ -133,6 +136,7 @@ public class ResourcesController extends BaseController {
@Parameter(name = "currentDir", description = "RESOURCE_CURRENT_DIR", required = true, schema = @Schema(implementation = String.class))})
@PostMapping()
@ApiException(CREATE_RESOURCE_ERROR)
@OperatorLog(auditType = AuditType.FILE_CREATE)
public Result<Object> createResource(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "type") ResourceType type,
@RequestParam(value = "name") String alias,
@ -160,6 +164,7 @@ public class ResourcesController extends BaseController {
@Parameter(name = "file", description = "RESOURCE_FILE", required = true, schema = @Schema(implementation = MultipartFile.class))})
@PutMapping()
@ApiException(UPDATE_RESOURCE_ERROR)
@OperatorLog(auditType = AuditType.FILE_UPDATE)
public Result<Object> updateResource(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "fullName") String fullName,
@RequestParam(value = "tenantCode", required = false) String tenantCode,
@ -236,6 +241,7 @@ public class ResourcesController extends BaseController {
@DeleteMapping()
@ResponseStatus(HttpStatus.OK)
@ApiException(DELETE_RESOURCE_ERROR)
@OperatorLog(auditType = AuditType.FILE_DELETE)
public Result<Object> deleteResource(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "fullName") String fullName,
@RequestParam(value = "tenantCode", required = false) String tenantCode) throws Exception {
@ -358,6 +364,7 @@ public class ResourcesController extends BaseController {
@Parameter(name = "currentDir", description = "RESOURCE_CURRENTDIR", required = true, schema = @Schema(implementation = String.class))})
@PostMapping(value = "/online-create")
@ApiException(CREATE_RESOURCE_FILE_ON_LINE_ERROR)
@OperatorLog(auditType = AuditType.FILE_CREATE)
public Result createResourceFile(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "type") ResourceType type,
@RequestParam(value = "fileName") String fileName,
@ -385,6 +392,7 @@ public class ResourcesController extends BaseController {
@Parameter(name = "tenantCode", description = "TENANT_CODE", required = true, schema = @Schema(implementation = String.class))})
@PutMapping(value = "/update-content")
@ApiException(EDIT_RESOURCE_FILE_ON_LINE_ERROR)
@OperatorLog(auditType = AuditType.FILE_UPDATE)
public Result updateResourceContent(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "fullName") String fullName,
@RequestParam(value = "tenantCode") String tenantCode,
@ -445,6 +453,7 @@ public class ResourcesController extends BaseController {
@PostMapping(value = "/udf-func")
@ResponseStatus(HttpStatus.CREATED)
@ApiException(CREATE_UDF_FUNCTION_ERROR)
@OperatorLog(auditType = AuditType.UDF_FUNCTION_CREATE)
public Result createUdfFunc(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "type") UdfType type,
@RequestParam(value = "funcName") String funcName,
@ -502,6 +511,7 @@ public class ResourcesController extends BaseController {
@Parameter(name = "description", description = "UDF_DESC", schema = @Schema(implementation = String.class))})
@PutMapping(value = "/udf-func/{id}")
@ApiException(UPDATE_UDF_FUNCTION_ERROR)
@OperatorLog(auditType = AuditType.UDF_FUNCTION_UPDATE)
public Result updateUdfFunc(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@PathVariable(value = "id") int udfFuncId, @RequestParam(value = "type") UdfType type,
@RequestParam(value = "funcName") String funcName,
@ -590,6 +600,7 @@ public class ResourcesController extends BaseController {
@DeleteMapping(value = "/udf-func/{id}")
@ResponseStatus(HttpStatus.OK)
@ApiException(DELETE_UDF_FUNCTION_ERROR)
@OperatorLog(auditType = AuditType.UDF_FUNCTION_DELETE)
public Result deleteUdfFunc(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@PathVariable(value = "id") int udfFuncId) {
return udfFuncService.delete(loginUser, udfFuncId);

8
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/SchedulerController.java

@ -27,6 +27,8 @@ import static org.apache.dolphinscheduler.api.enums.Status.QUERY_SCHEDULE_LIST_P
import static org.apache.dolphinscheduler.api.enums.Status.UPDATE_SCHEDULE_ERROR;
import static org.apache.dolphinscheduler.common.constants.Constants.SESSION_USER;
import org.apache.dolphinscheduler.api.audit.OperatorLog;
import org.apache.dolphinscheduler.api.audit.enums.AuditType;
import org.apache.dolphinscheduler.api.enums.Status;
import org.apache.dolphinscheduler.api.exceptions.ApiException;
import org.apache.dolphinscheduler.api.service.SchedulerService;
@ -104,6 +106,7 @@ public class SchedulerController extends BaseController {
@PostMapping()
@ResponseStatus(HttpStatus.CREATED)
@ApiException(CREATE_SCHEDULE_ERROR)
@OperatorLog(auditType = AuditType.SCHEDULE_CREATE)
public Result createSchedule(@Parameter(hidden = true) @RequestAttribute(value = SESSION_USER) User loginUser,
@Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@RequestParam(value = "processDefinitionCode") long processDefinitionCode,
@ -161,6 +164,7 @@ public class SchedulerController extends BaseController {
@PutMapping("/{id}")
@ResponseStatus(HttpStatus.OK)
@ApiException(UPDATE_SCHEDULE_ERROR)
@OperatorLog(auditType = AuditType.SCHEDULE_UPDATE)
public Result updateSchedule(@Parameter(hidden = true) @RequestAttribute(value = SESSION_USER) User loginUser,
@Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@PathVariable(value = "id") Integer id,
@ -185,6 +189,7 @@ public class SchedulerController extends BaseController {
})
@PostMapping("/{id}/online")
@ApiException(PUBLISH_SCHEDULE_ONLINE_ERROR)
@OperatorLog(auditType = AuditType.SCHEDULE_ONLINE)
public Result<Boolean> publishScheduleOnline(@Parameter(hidden = true) @RequestAttribute(value = SESSION_USER) User loginUser,
@Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@PathVariable("id") Integer id) {
@ -198,6 +203,7 @@ public class SchedulerController extends BaseController {
})
@PostMapping("/{id}/offline")
@ApiException(OFFLINE_SCHEDULE_ERROR)
@OperatorLog(auditType = AuditType.SCHEDULE_OFFLINE)
public Result<Boolean> offlineSchedule(@Parameter(hidden = true) @RequestAttribute(value = SESSION_USER) User loginUser,
@Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@PathVariable("id") Integer id) {
@ -253,6 +259,7 @@ public class SchedulerController extends BaseController {
@DeleteMapping(value = "/{id}")
@ResponseStatus(HttpStatus.OK)
@ApiException(DELETE_SCHEDULE_BY_ID_ERROR)
@OperatorLog(auditType = AuditType.SCHEDULE_DELETE)
public Result deleteScheduleById(@RequestAttribute(value = SESSION_USER) User loginUser,
@Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@PathVariable("id") Integer id) {
@ -325,6 +332,7 @@ public class SchedulerController extends BaseController {
@PutMapping("/update/{code}")
@ResponseStatus(HttpStatus.OK)
@ApiException(UPDATE_SCHEDULE_ERROR)
@OperatorLog(auditType = AuditType.SCHEDULE_UPDATE)
public Result updateScheduleByProcessDefinitionCode(@Parameter(hidden = true) @RequestAttribute(value = SESSION_USER) User loginUser,
@Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@PathVariable(value = "code") long processDefinitionCode,

10
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/TaskDefinitionController.java

@ -28,6 +28,8 @@ import static org.apache.dolphinscheduler.api.enums.Status.RELEASE_TASK_DEFINITI
import static org.apache.dolphinscheduler.api.enums.Status.SWITCH_TASK_DEFINITION_VERSION_ERROR;
import static org.apache.dolphinscheduler.api.enums.Status.UPDATE_TASK_DEFINITION_ERROR;
import org.apache.dolphinscheduler.api.audit.OperatorLog;
import org.apache.dolphinscheduler.api.audit.enums.AuditType;
import org.apache.dolphinscheduler.api.enums.Status;
import org.apache.dolphinscheduler.api.exceptions.ApiException;
import org.apache.dolphinscheduler.api.service.TaskDefinitionService;
@ -88,6 +90,7 @@ public class TaskDefinitionController extends BaseController {
@PostMapping()
@ResponseStatus(HttpStatus.CREATED)
@ApiException(CREATE_TASK_DEFINITION_ERROR)
@OperatorLog(auditType = AuditType.TASK_CREATE)
public Result createTaskDefinition(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@RequestParam(value = "taskDefinitionJson", required = true) String taskDefinitionJson) {
@ -116,6 +119,7 @@ public class TaskDefinitionController extends BaseController {
@PostMapping("/save-single")
@ResponseStatus(HttpStatus.CREATED)
@ApiException(CREATE_TASK_DEFINITION_ERROR)
@OperatorLog(auditType = AuditType.TASK_CREATE)
public Result createTaskBindsWorkFlow(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@RequestParam(value = "processDefinitionCode", required = true) long processDefinitionCode,
@ -144,6 +148,7 @@ public class TaskDefinitionController extends BaseController {
@PutMapping(value = "/{code}")
@ResponseStatus(HttpStatus.OK)
@ApiException(UPDATE_TASK_DEFINITION_ERROR)
@OperatorLog(auditType = AuditType.TASK_UPDATE)
public Result updateTaskDefinition(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@PathVariable(value = "code") long code,
@ -173,6 +178,7 @@ public class TaskDefinitionController extends BaseController {
@PutMapping(value = "/{code}/with-upstream")
@ResponseStatus(HttpStatus.OK)
@ApiException(UPDATE_TASK_DEFINITION_ERROR)
@OperatorLog(auditType = AuditType.TASK_UPDATE)
public Result updateTaskWithUpstream(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@PathVariable(value = "code") long code,
@ -229,6 +235,7 @@ public class TaskDefinitionController extends BaseController {
@GetMapping(value = "/{code}/versions/{version}")
@ResponseStatus(HttpStatus.OK)
@ApiException(SWITCH_TASK_DEFINITION_VERSION_ERROR)
@OperatorLog(auditType = AuditType.TASK_SWITCH_VERSION)
public Result switchTaskDefinitionVersion(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@PathVariable(value = "code") long code,
@ -254,6 +261,7 @@ public class TaskDefinitionController extends BaseController {
@DeleteMapping(value = "/{code}/versions/{version}")
@ResponseStatus(HttpStatus.OK)
@ApiException(DELETE_TASK_DEFINITION_VERSION_ERROR)
@OperatorLog(auditType = AuditType.TASK_DELETE_VERSION)
public Result deleteTaskDefinitionVersion(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@PathVariable(value = "code") long code,
@ -278,6 +286,7 @@ public class TaskDefinitionController extends BaseController {
@DeleteMapping(value = "/{code}")
@ResponseStatus(HttpStatus.OK)
@ApiException(DELETE_TASK_DEFINE_BY_CODE_ERROR)
@OperatorLog(auditType = AuditType.TASK_DELETE)
public Result deleteTaskDefinitionByCode(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@PathVariable(value = "code") long code) {
@ -384,6 +393,7 @@ public class TaskDefinitionController extends BaseController {
@PostMapping(value = "/{code}/release")
@ResponseStatus(HttpStatus.OK)
@ApiException(RELEASE_TASK_DEFINITION_ERROR)
@OperatorLog(auditType = AuditType.TASK_RELEASE)
public Result releaseTaskDefinition(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@PathVariable(value = "code", required = true) long code,

12
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/TaskGroupController.java

@ -24,6 +24,8 @@ import static org.apache.dolphinscheduler.api.enums.Status.QUERY_TASK_GROUP_QUEU
import static org.apache.dolphinscheduler.api.enums.Status.START_TASK_GROUP_ERROR;
import static org.apache.dolphinscheduler.api.enums.Status.UPDATE_TASK_GROUP_ERROR;
import org.apache.dolphinscheduler.api.audit.OperatorLog;
import org.apache.dolphinscheduler.api.audit.enums.AuditType;
import org.apache.dolphinscheduler.api.exceptions.ApiException;
import org.apache.dolphinscheduler.api.service.TaskGroupQueueService;
import org.apache.dolphinscheduler.api.service.TaskGroupService;
@ -81,6 +83,7 @@ public class TaskGroupController extends BaseController {
@PostMapping(value = "/create")
@ResponseStatus(HttpStatus.CREATED)
@ApiException(CREATE_TASK_GROUP_ERROR)
@OperatorLog(auditType = AuditType.TASK_GROUP_CREATE)
public Result createTaskGroup(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("name") String name,
@RequestParam(value = "projectCode", required = false, defaultValue = "0") Long projectCode,
@ -112,6 +115,7 @@ public class TaskGroupController extends BaseController {
@PostMapping(value = "/update")
@ResponseStatus(HttpStatus.CREATED)
@ApiException(UPDATE_TASK_GROUP_ERROR)
@OperatorLog(auditType = AuditType.TASK_GROUP_UPDATE)
public Result updateTaskGroup(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("id") Integer id,
@RequestParam("name") String name,
@ -214,6 +218,7 @@ public class TaskGroupController extends BaseController {
@PostMapping(value = "/close-task-group")
@ResponseStatus(HttpStatus.CREATED)
@ApiException(CLOSE_TASK_GROUP_ERROR)
@OperatorLog(auditType = AuditType.TASK_GROUP_CLOSE)
public Result closeTaskGroup(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "id", required = false) Integer id) {
@ -235,6 +240,7 @@ public class TaskGroupController extends BaseController {
@PostMapping(value = "/start-task-group")
@ResponseStatus(HttpStatus.CREATED)
@ApiException(START_TASK_GROUP_ERROR)
@OperatorLog(auditType = AuditType.TASK_GROUP_START)
public Result startTaskGroup(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "id", required = false) Integer id) {
Map<String, Object> result = taskGroupService.startTaskGroup(loginUser, id);
@ -255,9 +261,10 @@ public class TaskGroupController extends BaseController {
@PostMapping(value = "/forceStart")
@ResponseStatus(HttpStatus.CREATED)
@ApiException(START_TASK_GROUP_ERROR)
@OperatorLog(auditType = AuditType.TASK_GROUP_START)
public Result forceStart(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "queueId") Integer queueId) {
Map<String, Object> result = taskGroupService.forceStartTask(loginUser, queueId);
@RequestParam(value = "queueId") Integer id) {
Map<String, Object> result = taskGroupService.forceStartTask(loginUser, id);
return returnDataList(result);
}
@ -276,6 +283,7 @@ public class TaskGroupController extends BaseController {
@PostMapping(value = "/modifyPriority")
@ResponseStatus(HttpStatus.CREATED)
@ApiException(START_TASK_GROUP_ERROR)
@OperatorLog(auditType = AuditType.TASK_GROUP_MODIFY)
public Result modifyPriority(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "queueId") Integer queueId,
@RequestParam(value = "priority") Integer priority) {

3
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/TaskInstanceController.java

@ -23,6 +23,8 @@ import static org.apache.dolphinscheduler.api.enums.Status.REMOVE_TASK_INSTANCE_
import static org.apache.dolphinscheduler.api.enums.Status.TASK_SAVEPOINT_ERROR;
import static org.apache.dolphinscheduler.api.enums.Status.TASK_STOP_ERROR;
import org.apache.dolphinscheduler.api.audit.OperatorLog;
import org.apache.dolphinscheduler.api.audit.enums.AuditType;
import org.apache.dolphinscheduler.api.dto.taskInstance.TaskInstanceRemoveCacheResponse;
import org.apache.dolphinscheduler.api.exceptions.ApiException;
import org.apache.dolphinscheduler.api.service.TaskInstanceService;
@ -150,6 +152,7 @@ public class TaskInstanceController extends BaseController {
@PostMapping(value = "/{id}/force-success")
@ResponseStatus(HttpStatus.OK)
@ApiException(FORCE_TASK_SUCCESS_ERROR)
@OperatorLog(auditType = AuditType.TASK_INSTANCE_FORCE_SUCCESS)
public Result forceTaskSuccess(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@Schema(name = "projectCode", required = true) @PathVariable long projectCode,
@PathVariable(value = "id") Integer id) {

5
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/TenantController.java

@ -24,6 +24,8 @@ import static org.apache.dolphinscheduler.api.enums.Status.QUERY_TENANT_LIST_PAG
import static org.apache.dolphinscheduler.api.enums.Status.UPDATE_TENANT_ERROR;
import static org.apache.dolphinscheduler.api.enums.Status.VERIFY_OS_TENANT_CODE_ERROR;
import org.apache.dolphinscheduler.api.audit.OperatorLog;
import org.apache.dolphinscheduler.api.audit.enums.AuditType;
import org.apache.dolphinscheduler.api.exceptions.ApiException;
import org.apache.dolphinscheduler.api.service.TenantService;
import org.apache.dolphinscheduler.api.utils.PageInfo;
@ -83,6 +85,7 @@ public class TenantController extends BaseController {
@PostMapping()
@ResponseStatus(HttpStatus.CREATED)
@ApiException(CREATE_TENANT_ERROR)
@OperatorLog(auditType = AuditType.TENANT_CREATE)
public Result<Tenant> createTenant(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "tenantCode") String tenantCode,
@RequestParam(value = "queueId") int queueId,
@ -155,6 +158,7 @@ public class TenantController extends BaseController {
@PutMapping(value = "/{id}")
@ResponseStatus(HttpStatus.OK)
@ApiException(UPDATE_TENANT_ERROR)
@OperatorLog(auditType = AuditType.TENANT_UPDATE)
public Result<Boolean> updateTenant(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@PathVariable(value = "id") int id,
@RequestParam(value = "tenantCode") String tenantCode,
@ -179,6 +183,7 @@ public class TenantController extends BaseController {
@DeleteMapping(value = "/{id}")
@ResponseStatus(HttpStatus.OK)
@ApiException(DELETE_TENANT_BY_ID_ERROR)
@OperatorLog(auditType = AuditType.TENANT_DELETE)
public Result<Boolean> deleteTenantById(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@PathVariable(value = "id") int id) throws Exception {
tenantService.deleteTenantById(loginUser, id);

5
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/UsersController.java

@ -32,6 +32,8 @@ import static org.apache.dolphinscheduler.api.enums.Status.UPDATE_USER_ERROR;
import static org.apache.dolphinscheduler.api.enums.Status.USER_LIST_ERROR;
import static org.apache.dolphinscheduler.api.enums.Status.VERIFY_USERNAME_ERROR;
import org.apache.dolphinscheduler.api.audit.OperatorLog;
import org.apache.dolphinscheduler.api.audit.enums.AuditType;
import org.apache.dolphinscheduler.api.enums.Status;
import org.apache.dolphinscheduler.api.exceptions.ApiException;
import org.apache.dolphinscheduler.api.service.UsersService;
@ -88,6 +90,7 @@ public class UsersController extends BaseController {
@PostMapping(value = "/create")
@ResponseStatus(HttpStatus.CREATED)
@ApiException(CREATE_USER_ERROR)
@OperatorLog(auditType = AuditType.USER_CREATE)
public Result createUser(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "userName") String userName,
@RequestParam(value = "userPassword") String userPassword,
@ -159,6 +162,7 @@ public class UsersController extends BaseController {
@PostMapping(value = "/update")
@ResponseStatus(HttpStatus.OK)
@ApiException(UPDATE_USER_ERROR)
@OperatorLog(auditType = AuditType.USER_UPDATE)
public Result<User> updateUser(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "id") int id,
@RequestParam(value = "userName") String userName,
@ -196,6 +200,7 @@ public class UsersController extends BaseController {
@PostMapping(value = "/delete")
@ResponseStatus(HttpStatus.OK)
@ApiException(DELETE_USER_BY_ID_ERROR)
@OperatorLog(auditType = AuditType.USER_DELETE)
public Result delUserById(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "id") int id) throws Exception {
Map<String, Object> result = usersService.deleteUserById(loginUser, id);

4
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/WorkerGroupController.java

@ -22,6 +22,8 @@ import static org.apache.dolphinscheduler.api.enums.Status.QUERY_WORKER_ADDRESS_
import static org.apache.dolphinscheduler.api.enums.Status.QUERY_WORKER_GROUP_FAIL;
import static org.apache.dolphinscheduler.api.enums.Status.SAVE_ERROR;
import org.apache.dolphinscheduler.api.audit.OperatorLog;
import org.apache.dolphinscheduler.api.audit.enums.AuditType;
import org.apache.dolphinscheduler.api.exceptions.ApiException;
import org.apache.dolphinscheduler.api.service.WorkerGroupService;
import org.apache.dolphinscheduler.api.utils.Result;
@ -80,6 +82,7 @@ public class WorkerGroupController extends BaseController {
@PostMapping()
@ResponseStatus(HttpStatus.OK)
@ApiException(SAVE_ERROR)
@OperatorLog(auditType = AuditType.WORKER_GROUP_CREATE)
public Result saveWorkerGroup(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "id", required = false, defaultValue = "0") int id,
@RequestParam(value = "name") String name,
@ -147,6 +150,7 @@ public class WorkerGroupController extends BaseController {
@DeleteMapping(value = "/{id}")
@ResponseStatus(HttpStatus.OK)
@ApiException(DELETE_WORKER_GROUP_FAIL)
@OperatorLog(auditType = AuditType.WORKER_GROUP_DELETE)
public Result deleteWorkerGroupById(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@PathVariable("id") Integer id) {
Map<String, Object> result = workerGroupService.deleteWorkerGroupById(loginUser, id);

51
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/AuditDto.java

@ -19,55 +19,26 @@ package org.apache.dolphinscheduler.api.dto;
import java.util.Date;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class AuditDto {
private String userName;
private String resource;
private String modelType;
private String modelName;
private String operation;
private Date time;
private String resourceName;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getResource() {
return resource;
}
public void setResource(String resource) {
this.resource = resource;
}
public String getOperation() {
return operation;
}
public void setOperation(String operation) {
this.operation = operation;
}
public Date getTime() {
return time;
}
public void setTime(Date time) {
this.time = time;
}
private String description;
public String getResourceName() {
return resourceName;
}
private String detail;
public void setResourceName(String resourceName) {
this.resourceName = resourceName;
}
private String latency;
}

59
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/auditLog/AuditModelTypeDto.java

@ -0,0 +1,59 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dolphinscheduler.api.dto.auditLog;
import org.apache.dolphinscheduler.common.enums.AuditModelType;
import java.util.ArrayList;
import java.util.List;
import lombok.Data;
@Data
public class AuditModelTypeDto {
private String name;
private List<AuditModelTypeDto> child = null;
public static List<AuditModelTypeDto> getModelTypeDtoList() {
List<AuditModelTypeDto> dtoList = new ArrayList<>();
transFromEnumListToDto(dtoList, AuditModelType.getAuditModelTreeList());
return dtoList;
}
public static List<AuditModelTypeDto> transFromEnumListToDto(List<AuditModelTypeDto> dtoList,
List<AuditModelType> objectTypeList) {
for (AuditModelType operationType : objectTypeList) {
dtoList.add(transFromEnumToDto(operationType));
}
return dtoList;
}
public static AuditModelTypeDto transFromEnumToDto(AuditModelType operationType) {
AuditModelTypeDto dto = new AuditModelTypeDto();
dto.setName(operationType.getName());
if (!operationType.getChild().isEmpty()) {
dto.setChild(transFromEnumListToDto(new ArrayList<>(), operationType.getChild()));
}
return dto;
}
}

42
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/auditLog/AuditOperationTypeDto.java

@ -0,0 +1,42 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dolphinscheduler.api.dto.auditLog;
import org.apache.dolphinscheduler.common.enums.AuditOperationType;
import java.util.ArrayList;
import java.util.List;
import lombok.Data;
@Data
public class AuditOperationTypeDto {
private String name;
public static List<AuditOperationTypeDto> getOperationTypeDtoList() {
List<AuditOperationTypeDto> dtoList = new ArrayList<>();
for (AuditOperationType operationType : AuditOperationType.getOperationList()) {
AuditOperationTypeDto dto = new AuditOperationTypeDto();
dto.setName(operationType.getName());
dtoList.add(dto);
}
return dtoList;
}
}

48
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/AuditService.java

@ -19,9 +19,9 @@ package org.apache.dolphinscheduler.api.service;
import org.apache.dolphinscheduler.api.dto.AuditDto;
import org.apache.dolphinscheduler.api.utils.PageInfo;
import org.apache.dolphinscheduler.common.enums.AuditOperationType;
import org.apache.dolphinscheduler.common.enums.AuditResourceType;
import org.apache.dolphinscheduler.dao.entity.User;
import org.apache.dolphinscheduler.dao.entity.AuditLog;
import java.util.List;
/**
* audit information service
@ -29,30 +29,36 @@ import org.apache.dolphinscheduler.dao.entity.User;
public interface AuditService {
/**
* add new audit record
* add audit object
*
* @param auditLog auditLog
*/
void addAudit(AuditLog auditLog);
/**
* add audit by list
*
* @param user login user
* @param resourceType resource type
* @param resourceId resource id
* @param operation operation type
* @param auditLogList auditLog list
* @param latency api latency milliseconds
*/
void addAudit(User user, AuditResourceType resourceType, Integer resourceId, AuditOperationType operation);
void addAudit(List<AuditLog> auditLogList, long latency);
/**
* query audit log list
*
* @param loginUser login user
* @param resourceType resource type
* @param operationType operation type
* @param startTime start time
* @param endTime end time
* @param userName query user name
* @param pageNo page number
* @param pageSize page size
* @return audit log string
* @param modelTypes model types
* @param modelName model name
* @param operationTypes operation types
* @param startTime start time
* @param endTime end time
* @param userName query user name
* @param pageNo page number
* @param pageSize page size
* @return audit log string
*/
PageInfo<AuditDto> queryLogListPaging(User loginUser, AuditResourceType resourceType,
AuditOperationType operationType, String startTime,
String endTime, String userName,
PageInfo<AuditDto> queryLogListPaging(String modelTypes,
String operationTypes, String startTime,
String endTime, String userName, String modelName,
Integer pageNo, Integer pageSize);
}

97
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/AuditServiceImpl.java

@ -17,21 +17,24 @@
package org.apache.dolphinscheduler.api.service.impl;
import org.apache.dolphinscheduler.api.audit.AuditMessage;
import org.apache.dolphinscheduler.api.audit.AuditPublishService;
import org.apache.dolphinscheduler.api.dto.AuditDto;
import org.apache.dolphinscheduler.api.service.AuditService;
import org.apache.dolphinscheduler.api.utils.PageInfo;
import org.apache.dolphinscheduler.common.enums.AuditModelType;
import org.apache.dolphinscheduler.common.enums.AuditOperationType;
import org.apache.dolphinscheduler.common.enums.AuditResourceType;
import org.apache.dolphinscheduler.dao.entity.AuditLog;
import org.apache.dolphinscheduler.dao.entity.User;
import org.apache.dolphinscheduler.dao.mapper.AuditLogMapper;
import org.apache.parquet.Strings;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -39,74 +42,77 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@Service
@Slf4j
public class AuditServiceImpl extends BaseServiceImpl implements AuditService {
@Autowired
private AuditLogMapper auditLogMapper;
@Autowired
private AuditPublishService publishService;
@Override
public void addAudit(AuditLog auditLog) {
if (auditLog.getModelId() == null || auditLog.getModelName() == null) {
return;
}
auditLogMapper.insert(auditLog);
}
/**
* add new audit log
*
* @param user login user
* @param resourceType resource type
* @param resourceId resource id
* @param operation operation type
*/
@Override
public void addAudit(User user, AuditResourceType resourceType, Integer resourceId, AuditOperationType operation) {
publishService.publish(new AuditMessage(user, new Date(), resourceType, operation, resourceId));
public void addAudit(List<AuditLog> auditLogList, long latency) {
auditLogList.forEach(auditLog -> {
auditLog.setLatency(latency);
addAudit(auditLog);
});
}
/**
* query audit log paging
*
* @param loginUser login user
* @param resourceType resource type
* @param operationType operation type
* @param startDate start time
* @param endDate end time
* @param userName query user name
* @param pageNo page number
* @param pageSize page size
* @param modelTypes object types
* @param operationTypes operation types
* @param startDate start time
* @param endDate end time
* @param userName query user name
* @param modelName query object name
* @param pageNo page number
* @param pageSize page size
* @return audit log string data
*/
@Override
public PageInfo<AuditDto> queryLogListPaging(User loginUser,
AuditResourceType resourceType,
AuditOperationType operationType,
public PageInfo<AuditDto> queryLogListPaging(String modelTypes,
String operationTypes,
String startDate,
String endDate,
String userName,
String modelName,
Integer pageNo,
Integer pageSize) {
int[] resourceArray = null;
if (resourceType != null) {
resourceArray = new int[]{resourceType.getCode()};
}
int[] opsArray = null;
if (operationType != null) {
opsArray = new int[]{operationType.getCode()};
}
List<String> objectTypeCodeList = convertStringToList(modelTypes);
List<String> operationTypeCodeList = convertStringToList(operationTypes);
Date start = checkAndParseDateParameters(startDate);
Date end = checkAndParseDateParameters(endDate);
IPage<AuditLog> logIPage = auditLogMapper.queryAuditLog(new Page<>(pageNo, pageSize), resourceArray, opsArray,
userName, start, end);
IPage<AuditLog> logIPage =
auditLogMapper.queryAuditLog(new Page<>(pageNo, pageSize), objectTypeCodeList, operationTypeCodeList,
userName, modelName, start, end);
List<AuditDto> auditDtos =
logIPage.getRecords().stream().map(this::transformAuditLog).collect(Collectors.toList());
PageInfo<AuditDto> pageInfo = new PageInfo<>(pageNo, pageSize);
pageInfo.setTotal((int) auditDtos.size());
pageInfo.setTotal((int) logIPage.getTotal());
pageInfo.setTotalList(auditDtos);
return pageInfo;
}
private List<String> convertStringToList(String string) {
if (Strings.isNullOrEmpty(string)) {
return new ArrayList<>();
}
return Arrays.stream(string.split(",")).collect(Collectors.toList());
}
/**
* transform AuditLog to AuditDto
*
@ -115,11 +121,14 @@ public class AuditServiceImpl extends BaseServiceImpl implements AuditService {
*/
private AuditDto transformAuditLog(AuditLog auditLog) {
AuditDto auditDto = new AuditDto();
String resourceType = AuditResourceType.of(auditLog.getResourceType()).getMsg();
auditDto.setResource(resourceType);
auditDto.setOperation(AuditOperationType.of(auditLog.getOperation()).getMsg());
AuditModelType objectType = AuditModelType.of(auditLog.getModelType());
auditDto.setModelType(objectType.getName());
auditDto.setModelName(auditLog.getModelName());
auditDto.setOperation(AuditOperationType.of(auditLog.getOperationType()).getName());
auditDto.setUserName(auditLog.getUserName());
auditDto.setResourceName(auditLogMapper.queryResourceNameByType(resourceType, auditLog.getResourceId()));
auditDto.setLatency(String.valueOf(auditLog.getLatency()));
auditDto.setDetail(auditLog.getDetail());
auditDto.setDescription(auditLog.getDescription());
auditDto.setTime(auditLog.getTime());
return auditDto;
}

1
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/K8SNamespaceServiceImpl.java

@ -173,6 +173,7 @@ public class K8SNamespaceServiceImpl extends BaseServiceImpl implements K8sNames
k8sNamespaceMapper.insert(k8sNamespaceObj);
log.info("K8s namespace create complete, namespace:{}.", k8sNamespaceObj.getNamespace());
result.put(Constants.DATA_LIST, k8sNamespaceObj);
putMsg(result, Status.SUCCESS);
return result;

1
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionServiceImpl.java

@ -1537,6 +1537,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
}
}
result.put(Constants.DATA_LIST, processDefinition);
log.info("Import process definition complete, projectCode:{}, processDefinitionCode:{}.", projectCode,
processDefinition.getCode());
return true;

1
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/SchedulerServiceImpl.java

@ -808,6 +808,7 @@ public class SchedulerServiceImpl extends BaseServiceImpl implements SchedulerSe
log.info("Schedule update complete, projectCode:{}, processDefinitionCode:{}, scheduleId:{}.",
processDefinition.getProjectCode(), processDefinition.getCode(), schedule.getId());
result.put(Constants.DATA_LIST, schedule);
putMsg(result, Status.SUCCESS);
}

2
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskGroupServiceImpl.java

@ -129,6 +129,7 @@ public class TaskGroupServiceImpl extends BaseServiceImpl implements TaskGroupSe
if (taskGroupMapper.insert(taskGroup) > 0) {
log.info("Create task group complete, taskGroupName:{}.", taskGroup.getName());
result.put(Constants.DATA_LIST, taskGroup);
putMsg(result, Status.SUCCESS);
} else {
log.error("Create task group error, taskGroupName:{}.", taskGroup.getName());
@ -194,6 +195,7 @@ public class TaskGroupServiceImpl extends BaseServiceImpl implements TaskGroupSe
int i = taskGroupMapper.updateById(taskGroup);
if (i > 0) {
log.info("Update task group complete, taskGroupId:{}.", id);
result.put(Constants.DATA_LIST, taskGroup);
putMsg(result, Status.SUCCESS);
} else {
log.error("Update task group error, taskGroupId:{}.", id);

1
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkerGroupServiceImpl.java

@ -157,6 +157,7 @@ public class WorkerGroupServiceImpl extends BaseServiceImpl implements WorkerGro
handleDefaultWorkGroup(workerGroupMapper, workerGroup, loginUser, otherParamsJson);
log.info("Worker group save complete, workerGroupName:{}.", workerGroup.getName());
putMsg(result, Status.SUCCESS);
result.put(Constants.DATA_LIST, workerGroup);
return result;
}

50
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/audit/AuditSubscriberTest.java

@ -1,50 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dolphinscheduler.api.audit;
import org.apache.dolphinscheduler.common.enums.AuditOperationType;
import org.apache.dolphinscheduler.common.enums.AuditResourceType;
import org.apache.dolphinscheduler.dao.entity.AuditLog;
import org.apache.dolphinscheduler.dao.entity.User;
import org.apache.dolphinscheduler.dao.mapper.AuditLogMapper;
import java.util.Date;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;
@ExtendWith(MockitoExtension.class)
public class AuditSubscriberTest {
@Mock
private AuditLogMapper logMapper;
@InjectMocks
private AuditSubscriberImpl auditSubscriber;
@Test
public void testExecute() {
Mockito.when(logMapper.insert(Mockito.any(AuditLog.class))).thenReturn(1);
auditSubscriber.execute(
new AuditMessage(new User(), new Date(), AuditResourceType.USER_MODULE, AuditOperationType.CREATE, 1));
}
}

10
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/AccessTokenControllerTest.java

@ -47,7 +47,7 @@ public class AccessTokenControllerTest extends AbstractControllerTest {
@Test
public void testCreateToken() throws Exception {
MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
paramsMap.add("userId", "4");
paramsMap.add("userId", "1");
paramsMap.add("expireTime", "2019-12-18 00:00:00");
paramsMap.add("token", "607f5aeaaa2093dbdff5d5522ce00510");
MvcResult mvcResult = mockMvc.perform(post("/access-tokens")
@ -64,7 +64,7 @@ public class AccessTokenControllerTest extends AbstractControllerTest {
@Test
public void testCreateTokenIfAbsent() throws Exception {
MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
paramsMap.add("userId", "4");
paramsMap.add("userId", "1");
paramsMap.add("expireTime", "2019-12-18 00:00:00");
paramsMap.add("token", null);
@ -101,7 +101,7 @@ public class AccessTokenControllerTest extends AbstractControllerTest {
@Test
public void testGenerateToken() throws Exception {
MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
paramsMap.add("userId", "4");
paramsMap.add("userId", "1");
paramsMap.add("expireTime", "2019-12-28 00:00:00");
MvcResult mvcResult = mockMvc.perform(post("/access-tokens/generate")
.header("sessionId", sessionId)
@ -161,7 +161,7 @@ public class AccessTokenControllerTest extends AbstractControllerTest {
public void testUpdateToken() throws Exception {
testCreateToken();
MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
paramsMap.add("userId", "4");
paramsMap.add("userId", "1");
paramsMap.add("expireTime", "2019-12-20 00:00:00");
paramsMap.add("token", "cxctoken123update");
MvcResult mvcResult = mockMvc.perform(put("/access-tokens/1")
@ -180,7 +180,7 @@ public class AccessTokenControllerTest extends AbstractControllerTest {
this.testCreateTokenIfAbsent();
MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
paramsMap.add("userId", "4");
paramsMap.add("userId", "1");
paramsMap.add("expireTime", "2019-12-20 00:00:00");
paramsMap.add("token", null);

13
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/AlertPluginInstanceControllerTest.java

@ -35,8 +35,10 @@ import org.apache.dolphinscheduler.api.utils.Result;
import org.apache.dolphinscheduler.common.enums.AlertPluginInstanceType;
import org.apache.dolphinscheduler.common.enums.WarningType;
import org.apache.dolphinscheduler.common.utils.JSONUtils;
import org.apache.dolphinscheduler.dao.entity.AlertPluginInstance;
import org.apache.dolphinscheduler.dao.entity.User;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.MediaType;
@ -49,6 +51,7 @@ import org.springframework.util.MultiValueMap;
*/
public class AlertPluginInstanceControllerTest extends AbstractControllerTest {
private static AlertPluginInstance alertPluginInstance = new AlertPluginInstance();
private static final int pluginDefineId = 1;
private static final String instanceName = "instanceName";
private static final String pluginInstanceParams = "pluginInstanceParams";
@ -60,6 +63,12 @@ public class AlertPluginInstanceControllerTest extends AbstractControllerTest {
@MockBean(name = "alertPluginInstanceServiceImpl")
private AlertPluginInstanceService alertPluginInstanceService;
@BeforeAll
public static void initInstance() {
alertPluginInstance.setId(1);
alertPluginInstance.setInstanceName(instanceName);
}
@Test
public void testCreateAlertPluginInstance() throws Exception {
// Given
@ -71,7 +80,7 @@ public class AlertPluginInstanceControllerTest extends AbstractControllerTest {
paramsMap.add("pluginInstanceParams", pluginInstanceParams);
when(alertPluginInstanceService.create(any(User.class), eq(pluginDefineId), eq(instanceName),
eq(pluginInstanceType), eq(warningType), eq(pluginInstanceParams))).thenReturn(null);
eq(pluginInstanceType), eq(warningType), eq(pluginInstanceParams))).thenReturn(alertPluginInstance);
// When
final MvcResult mvcResult = mockMvc.perform(post("/alert-plugin-instances")
@ -122,7 +131,7 @@ public class AlertPluginInstanceControllerTest extends AbstractControllerTest {
paramsMap.add("pluginInstanceParams", pluginInstanceParams);
when(alertPluginInstanceService.updateById(any(User.class), eq(pluginDefineId), eq(instanceName),
eq(warningType), eq(pluginInstanceParams))).thenReturn(null);
eq(warningType), eq(pluginInstanceParams))).thenReturn(alertPluginInstance);
// When
final MvcResult mvcResult = mockMvc.perform(put("/alert-plugin-instances/{id}", pluginDefineId)

6
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ExecuteFunctionControllerTest.java

@ -80,7 +80,7 @@ public class ExecuteFunctionControllerTest extends AbstractControllerTest {
final int dryRun = 7;
final int testFlag = 0;
final ComplementDependentMode complementDependentMode = ComplementDependentMode.OFF_MODE;
final Integer version = null;
final Integer version = 1;
final boolean allLevelDependent = false;
final JsonObject expectResponseContent = gson
.fromJson("{\"code\":0,\"msg\":\"success\",\"data\":\"Test Data\",\"success\":true,\"failed\":false}",
@ -115,6 +115,7 @@ public class ExecuteFunctionControllerTest extends AbstractControllerTest {
paramsMap.add("dryRun", String.valueOf(dryRun));
paramsMap.add("testFlag", String.valueOf(testFlag));
paramsMap.add("executionOrder", String.valueOf(executionOrder));
paramsMap.add("version", String.valueOf(version));
when(executorService.execProcessInstance(any(User.class), eq(projectCode), eq(processDefinitionCode),
eq(scheduleTime), eq(execType), eq(failureStrategy), eq(startNodeList), eq(taskDependType),
@ -162,6 +163,7 @@ public class ExecuteFunctionControllerTest extends AbstractControllerTest {
paramsMap.add("dryRun", String.valueOf(dryRun));
paramsMap.add("testFlag", String.valueOf(testFlag));
paramsMap.add("executionOrder", String.valueOf(executionOrder));
paramsMap.add("version", String.valueOf(version));
when(executorService.execProcessInstance(any(User.class), eq(projectCode), eq(processDefinitionCode),
eq(scheduleTime), eq(execType), eq(failureStrategy), eq(startNodeList), eq(taskDependType),
@ -209,6 +211,7 @@ public class ExecuteFunctionControllerTest extends AbstractControllerTest {
paramsMap.add("dryRun", String.valueOf(dryRun));
paramsMap.add("testFlag", String.valueOf(testFlag));
paramsMap.add("executionOrder", String.valueOf(executionOrder));
paramsMap.add("version", String.valueOf(version));
when(executorService.execProcessInstance(any(User.class), eq(projectCode), eq(processDefinitionCode),
eq(scheduleTime), eq(execType), eq(failureStrategy), eq(startNodeList), eq(taskDependType),
@ -241,6 +244,7 @@ public class ExecuteFunctionControllerTest extends AbstractControllerTest {
paramsMap.add("failureStrategy", String.valueOf(failureStrategy));
paramsMap.add("warningType", String.valueOf(warningType));
paramsMap.add("scheduleTime", scheduleTime);
paramsMap.add("version", String.valueOf(version));
when(executorService.execProcessInstance(any(User.class), eq(projectCode), eq(processDefinitionCode),
eq(scheduleTime), eq(null), eq(failureStrategy), eq(null), eq(null), eq(warningType),

18
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/SchedulerControllerTest.java

@ -30,6 +30,7 @@ import org.apache.dolphinscheduler.api.enums.Status;
import org.apache.dolphinscheduler.api.service.SchedulerService;
import org.apache.dolphinscheduler.api.utils.PageInfo;
import org.apache.dolphinscheduler.api.utils.Result;
import org.apache.dolphinscheduler.common.constants.Constants;
import org.apache.dolphinscheduler.common.enums.FailureStrategy;
import org.apache.dolphinscheduler.common.enums.Priority;
import org.apache.dolphinscheduler.common.enums.WarningType;
@ -38,6 +39,7 @@ import org.apache.dolphinscheduler.dao.entity.Schedule;
import org.apache.dolphinscheduler.dao.entity.User;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.slf4j.Logger;
@ -48,13 +50,25 @@ import org.springframework.test.web.servlet.MvcResult;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import com.google.common.collect.ImmutableMap;
public class SchedulerControllerTest extends AbstractControllerTest {
private static Schedule scheduleObj = new Schedule();
private static final Logger logger = LoggerFactory.getLogger(SchedulerControllerTest.class);
final ImmutableMap<String, Object> result =
ImmutableMap.of(Constants.STATUS, Status.SUCCESS, Constants.DATA_LIST, scheduleObj);
@MockBean(name = "schedulerService")
private SchedulerService schedulerService;
@BeforeAll
public static void initInstance() {
scheduleObj.setId(1);
}
@Test
public void testCreateSchedule() throws Exception {
MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
@ -72,7 +86,7 @@ public class SchedulerControllerTest extends AbstractControllerTest {
Mockito.when(schedulerService.insertSchedule(isA(User.class), isA(Long.class), isA(Long.class),
isA(String.class), isA(WarningType.class), isA(int.class), isA(FailureStrategy.class),
isA(Priority.class), isA(String.class), isA(String.class), isA(Long.class))).thenReturn(success());
isA(Priority.class), isA(String.class), isA(String.class), isA(Long.class))).thenReturn(result);
MvcResult mvcResult = mockMvc.perform(post("/projects/{projectCode}/schedules/", 123)
.header(SESSION_ID, sessionId)
@ -103,7 +117,7 @@ public class SchedulerControllerTest extends AbstractControllerTest {
Mockito.when(schedulerService.updateSchedule(isA(User.class), isA(Long.class), isA(Integer.class),
isA(String.class), isA(WarningType.class), isA(Integer.class), isA(FailureStrategy.class),
isA(Priority.class), isA(String.class), isA(String.class), isA(Long.class))).thenReturn(success());
isA(Priority.class), isA(String.class), isA(String.class), isA(Long.class))).thenReturn(result);
MvcResult mvcResult = mockMvc.perform(put("/projects/{projectCode}/schedules/{id}", 123, 37)
.header(SESSION_ID, sessionId)

14
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/AuditServiceTest.java

@ -21,9 +21,10 @@ import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.when;
import org.apache.dolphinscheduler.api.service.impl.AuditServiceImpl;
import org.apache.dolphinscheduler.common.enums.AuditModelType;
import org.apache.dolphinscheduler.common.enums.AuditOperationType;
import org.apache.dolphinscheduler.common.utils.DateUtils;
import org.apache.dolphinscheduler.dao.entity.AuditLog;
import org.apache.dolphinscheduler.dao.entity.User;
import org.apache.dolphinscheduler.dao.mapper.AuditLogMapper;
import java.util.ArrayList;
@ -66,15 +67,16 @@ public class AuditServiceTest {
page.setRecords(getLists());
page.setTotal(1L);
when(auditLogMapper.queryAuditLog(Mockito.any(Page.class), Mockito.any(), Mockito.any(), Mockito.eq(""),
Mockito.eq(""),
eq(start), eq(end))).thenReturn(page);
Assertions.assertDoesNotThrow(() -> {
auditService.queryLogListPaging(
new User(),
null,
null,
"",
"",
"2020-11-01 00:00:00",
"2020-11-02 00:00:00",
"",
"",
1,
10);
});
@ -89,8 +91,8 @@ public class AuditServiceTest {
private AuditLog getAuditLog() {
AuditLog auditLog = new AuditLog();
auditLog.setUserName("testName");
auditLog.setOperation(0);
auditLog.setResourceType(0);
auditLog.setOperationType(AuditOperationType.CREATE.getName());
auditLog.setModelType(AuditModelType.PROJECT.getName());
return auditLog;
}
}

98
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/enums/AuditModelType.java

@ -0,0 +1,98 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dolphinscheduler.common.enums;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import lombok.Getter;
/**
* Audit Model type
*/
@Getter
public enum AuditModelType {
PROJECT("Project", null), // 1
PROCESS("Process", PROJECT),
PROCESS_INSTANCE("ProcessInstance", PROCESS),
TASK("Task", PROCESS),
TASK_INSTANCE("TaskInstance", TASK),
SCHEDULE("Schedule", PROCESS),
RESOURCE("Resource", null),
FOLDER("Folder", RESOURCE),
FILE("File", FOLDER),
UDF_FOLDER("UDFFolder", RESOURCE),
UDF_FILE("UDFFile", UDF_FOLDER),
UDF_FUNCTION("UDFFunction", RESOURCE),
TASK_GROUP("TaskGroup", RESOURCE),
DATASOURCE("Datasource", null),
SECURITY("Security", null),
TENANT("Tenant", SECURITY),
USER("User", SECURITY),
ALARM_GROUP("AlarmGroup", SECURITY),
ALARM_INSTANCE("AlarmInstance", SECURITY),
WORKER_GROUP("WorkerGroup", SECURITY),
YARN_QUEUE("YarnQueue", SECURITY),
ENVIRONMENT("Environment", SECURITY),
CLUSTER("Cluster", SECURITY),
K8S_NAMESPACE("K8sNamespace", SECURITY),
TOKEN("Token", SECURITY),
;
private final String name;
private final AuditModelType parentType;
private final List<AuditModelType> child = new ArrayList<>();
private static final HashMap<String, AuditModelType> AUDIT_MODEL_MAP = new HashMap<>();
private static final List<AuditModelType> AUDIT_MODEL_TREE_LIST = new ArrayList<>();
static {
for (AuditModelType auditModelType : values()) {
AUDIT_MODEL_MAP.put(auditModelType.name, auditModelType);
}
for (AuditModelType auditModelType : values()) {
if (auditModelType.parentType != null) {
of(auditModelType.parentType.name).child.add(auditModelType);
} else {
AUDIT_MODEL_TREE_LIST.add(auditModelType);
}
}
}
public static List<AuditModelType> getAuditModelTreeList() {
return AUDIT_MODEL_TREE_LIST;
}
public static AuditModelType of(String name) {
if (AUDIT_MODEL_MAP.containsKey(name)) {
return AUDIT_MODEL_MAP.get(name);
}
throw new IllegalArgumentException("invalid audit operation type name " + name);
}
AuditModelType(String name, AuditModelType parentType) {
this.name = name;
this.parentType = parentType;
}
}

78
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/enums/AuditOperationType.java

@ -17,46 +17,80 @@
package org.apache.dolphinscheduler.common.enums;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import lombok.Getter;
/**
* Audit Operation type
*/
@Getter
public enum AuditOperationType {
CREATE(0, "CREATE"),
READ(1, "READ"),
UPDATE(2, "UPDATE"),
DELETE(3, "DELETE");
CREATE("Create"),
UPDATE("Update"),
BATCH_DELETE("BatchDelete"),
BATCH_START("BatchStart"),
DELETE("Delete"),
CLOSE("Close"),
RELEASE("Release"),
ONLINE("Online"),
OFFLINE("Offline"),
RESUME_PAUSE("ResumePause"),
RESUME_FAILURE("ResumeFailure"),
private final int code;
private final String enMsg;
IMPORT("Import"),
EXPORT("Export"),
private static HashMap<Integer, AuditOperationType> AUDIT_OPERATION_MAP = new HashMap<>();
EXECUTE("Execute"),
START("Start"),
MODIFY("Modify"),
RUN("Run"),
RERUN("Rerun"),
BATCH_RERUN("BatchRerun"),
STOP("Stop"),
KILL("Kill"),
PAUSE("Pause"),
MOVE("Move"),
SWITCH_STATUS("SwitchStatus"),
SWITCH_VERSION("SwitchVersion"),
DELETE_VERSION("DeleteVersion"),
FORCE_SUCCESS("ForceSuccess"),
RENAME("Rename"),
UPLOAD("Upload"),
AUTHORIZE("Authorize"),
UN_AUTHORIZE("UnAuthorize"),
COPY("Copy"),
;
private final String name;
AuditOperationType(String name) {
this.name = name;
}
private static final HashMap<String, AuditOperationType> AUDIT_OPERATION_MAP = new HashMap<>();
static {
for (AuditOperationType operationType : AuditOperationType.values()) {
AUDIT_OPERATION_MAP.put(operationType.code, operationType);
AUDIT_OPERATION_MAP.put(operationType.name, operationType);
}
}
AuditOperationType(int code, String enMsg) {
this.code = code;
this.enMsg = enMsg;
public static List<AuditOperationType> getOperationList() {
return new ArrayList<>(AUDIT_OPERATION_MAP.values());
}
public static AuditOperationType of(int status) {
if (AUDIT_OPERATION_MAP.containsKey(status)) {
return AUDIT_OPERATION_MAP.get(status);
public static AuditOperationType of(String name) {
if (AUDIT_OPERATION_MAP.containsKey(name)) {
return AUDIT_OPERATION_MAP.get(name);
}
throw new IllegalArgumentException("invalid audit operation type code " + status);
}
public int getCode() {
return code;
}
public String getMsg() {
return enMsg;
throw new IllegalArgumentException("invalid audit operation type code " + name);
}
}

61
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/enums/AuditResourceType.java

@ -1,61 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dolphinscheduler.common.enums;
import java.util.HashMap;
/**
* Audit Module type
*/
public enum AuditResourceType {
// TODO: add other audit resource enums
USER_MODULE(0, "USER"),
PROJECT_MODULE(1, "PROJECT");
private final int code;
private final String enMsg;
private static HashMap<Integer, AuditResourceType> AUDIT_RESOURCE_MAP = new HashMap<>();
static {
for (AuditResourceType auditResourceType : AuditResourceType.values()) {
AUDIT_RESOURCE_MAP.put(auditResourceType.code, auditResourceType);
}
}
AuditResourceType(int code, String enMsg) {
this.code = code;
this.enMsg = enMsg;
}
public int getCode() {
return this.code;
}
public String getMsg() {
return this.enMsg;
}
public static AuditResourceType of(int status) {
if (AUDIT_RESOURCE_MAP.containsKey(status)) {
return AUDIT_RESOURCE_MAP.get(status);
}
throw new IllegalArgumentException("invalid audit resource type code " + status);
}
}

65
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/AuditLog.java

@ -19,11 +19,16 @@ package org.apache.dolphinscheduler.dao.entity;
import java.util.Date;
import lombok.Data;
import org.springframework.beans.BeanUtils;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
@Data
@TableName("t_ds_audit_log")
public class AuditLog {
@ -39,19 +44,19 @@ public class AuditLog {
private Integer userId;
/**
* resource type
* model type
*/
private Integer resourceType;
private String modelType;
/**
* operation type
*/
private Integer operation;
private String operationType;
/**
* resource id
* model id
*/
private Integer resourceId;
private Long modelId;
/**
* user name
@ -64,51 +69,17 @@ public class AuditLog {
*/
private Date time;
public Integer getUserId() {
return userId;
}
public void setUserId(Integer userId) {
this.userId = userId;
}
public Integer getResourceType() {
return resourceType;
}
public void setResourceType(Integer resourceType) {
this.resourceType = resourceType;
}
public Integer getOperation() {
return operation;
}
public void setOperation(Integer operation) {
this.operation = operation;
}
public Integer getResourceId() {
return resourceId;
}
private String detail;
public void setResourceId(Integer resourceId) {
this.resourceId = resourceId;
}
private String description;
public String getUserName() {
return userName;
}
private String modelName;
public void setUserName(String userName) {
this.userName = userName;
}
public Date getTime() {
return time;
}
private long latency;
public void setTime(Date time) {
this.time = time;
public static AuditLog copyNewOne(AuditLog auditLog) {
AuditLog auditLogNew = new AuditLog();
BeanUtils.copyProperties(auditLog, auditLogNew);
return auditLogNew;
}
}

8
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/AuditLogMapper.java

@ -22,6 +22,7 @@ import org.apache.dolphinscheduler.dao.entity.AuditLog;
import org.apache.ibatis.annotations.Param;
import java.util.Date;
import java.util.List;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
@ -32,12 +33,11 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
public interface AuditLogMapper extends BaseMapper<AuditLog> {
IPage<AuditLog> queryAuditLog(IPage<AuditLog> page,
@Param("resourceType") int[] resourceArray,
@Param("operationType") int[] operationType,
@Param("modelTypeList") List<String> modelTypeList,
@Param("operationTypeList") List<String> operationTypeList,
@Param("userName") String userName,
@Param("modelName") String modelName,
@Param("startDate") Date startDate,
@Param("endDate") Date endDate);
String queryResourceNameByType(@Param("resourceType") String resourceType,
@Param("resourceId") Integer resourceId);
}

33
dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/AuditLogMapper.xml

@ -19,10 +19,10 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="org.apache.dolphinscheduler.dao.mapper.AuditLogMapper">
<sql id="baseSql">
id, user_id, resource_type, operation, resource_id, time
id, user_id, model_type, operation_type, model_id, model_name, time, detail, description, latency
</sql>
<sql id="baseSqlV2">
${alias}.id, ${alias}.user_id, ${alias}.resource_type, ${alias}.operation, ${alias}.resource_id, ${alias}.time
${alias}.id, ${alias}.user_id, ${alias}.model_type, ${alias}.operation_type, ${alias}.model_id, ${alias}.model_name, ${alias}.time, ${alias}.detail, ${alias}.description, ${alias}.latency
</sql>
<select id="queryAuditLog" resultType="org.apache.dolphinscheduler.dao.entity.AuditLog">
@ -38,30 +38,25 @@
<if test="startDate != null">
and log.time > #{startDate} and log.time <![CDATA[ <=]]> #{endDate}
</if>
<if test="resourceType != null and resourceType.length > 0">
and log.resource_type in
<foreach collection="resourceType" index="index" item="i" open="(" separator="," close=")">
#{i}
<if test="modelTypeList != null and modelTypeList.size() > 0">
and log.model_type in
<foreach item="model_type" index="index" collection="modelTypeList" open="(" separator="," close=")">
#{model_type}
</foreach>
</if>
<if test="operationType != null and operationType.length > 0">
and log.operation in
<foreach collection="operationType" index="index" item="j" open="(" separator="," close=")">
#{j}
<if test="operationTypeList != null and operationTypeList.size() > 0">
and log.operation_type in
<foreach item="operation_type" index="index" collection="operationTypeList" open="(" separator="," close=")">
#{operation_type}
</foreach>
</if>
<if test="userName != null and userName != ''">
and u.user_name = #{userName}
and u.user_name like concat ('%', #{userName}, '%')
</if>
<if test="modelName != null and modelName != ''">
and log.model_name like concat ('%', #{modelName}, '%')
</if>
order by log.time desc
</select>
<select id="queryResourceNameByType" resultType="String">
<if test="resourceType != null and resourceType == 'USER'">
select user_name from t_ds_user where id = #{resourceId}
</if>
<if test="resourceType != null and resourceType == 'PROJECT'">
select name from t_ds_project where id = #{resourceId}
</if>
</select>
</mapper>

10
dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_h2.sql

@ -2020,10 +2020,14 @@ CREATE TABLE t_ds_audit_log
(
id int(11) NOT NULL AUTO_INCREMENT,
user_id int(11) NOT NULL,
resource_type int(11) NOT NULL,
operation int(11) NOT NULL,
model_id bigint(20) NOT NULL,
model_name varchar(255) NOT NULL,
model_type varchar(255) NOT NULL,
operation_type varchar(255) NOT NULL,
description varchar(255) NOT NULL,
latency int(11) NOT NULL,
detail varchar(255) DEFAULT NULL,
time timestamp NULL DEFAULT CURRENT_TIMESTAMP,
resource_id int(11) NOT NULL,
PRIMARY KEY (id)
);

12
dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_mysql.sql

@ -2009,10 +2009,14 @@ DROP TABLE IF EXISTS `t_ds_audit_log`;
CREATE TABLE `t_ds_audit_log` (
`id` bigint(11) NOT NULL AUTO_INCREMENT COMMENT'key',
`user_id` int(11) NOT NULL COMMENT 'user id',
`resource_type` int(11) NOT NULL COMMENT 'resource type',
`operation` int(11) NOT NULL COMMENT 'operation',
`time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT 'create time',
`resource_id` int(11) NULL DEFAULT NULL COMMENT 'resource id',
`model_id` bigint(20) DEFAULT NULL COMMENT 'model id',
`model_name` varchar(100) DEFAULT NULL COMMENT 'model name',
`model_type` varchar(100) NOT NULL COMMENT 'model type',
`operation_type` varchar(100) NOT NULL COMMENT 'operation type',
`description` varchar(100) DEFAULT NULL COMMENT 'api description',
`latency` int(11) DEFAULT NULL COMMENT 'api cost milliseconds',
`detail` varchar(100) DEFAULT NULL COMMENT 'object change detail',
`time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT 'operation time',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT= 1 DEFAULT CHARSET=utf8 COLLATE = utf8_bin;

14
dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_postgresql.sql

@ -1993,11 +1993,15 @@ CREATE TABLE t_ds_task_group (
DROP TABLE IF EXISTS t_ds_audit_log;
CREATE TABLE t_ds_audit_log (
id serial NOT NULL,
user_id int NOT NULL,
resource_type int NOT NULL,
operation int NOT NULL,
time timestamp DEFAULT NULL ,
resource_id int NOT NULL,
user_id int NOT NULL,
model_id bigint NOT NULL,
model_name VARCHAR(255) NOT NULL,
model_type VARCHAR(255) NOT NULL,
operation_type VARCHAR(255) NOT NULL,
description VARCHAR(255) NOT NULL,
latency int NOT NULL,
detail VARCHAR(255) DEFAULT NULL,
time timestamp DEFAULT NULL ,
PRIMARY KEY (id)
);

30
dolphinscheduler-dao/src/main/resources/sql/upgrade/3.2.2_schema/mysql/dolphinscheduler_ddl.sql

@ -25,4 +25,32 @@ CREATE TABLE `t_ds_relation_project_worker_group` (
UNIQUE KEY unique_project_worker_group(project_code,worker_group)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COLLATE = utf8_bin;
ALTER TABLE t_ds_project_parameter ADD `operator` int(11) DEFAULT NULL COMMENT 'operator user id';
ALTER TABLE t_ds_project_parameter ADD `operator` int(11) DEFAULT NULL COMMENT 'operator user id';
-- modify_data_t_ds_audit_log_input_entry behavior change
--DROP PROCEDURE if EXISTS modify_data_t_ds_audit_log_input_entry;
DROP PROCEDURE if EXISTS modify_data_t_ds_audit_log_input_entry;
delimiter d//
CREATE PROCEDURE modify_data_t_ds_audit_log_input_entry()
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.COLUMNS
WHERE TABLE_NAME='t_ds_audit_log'
AND TABLE_SCHEMA=(SELECT DATABASE())
AND COLUMN_NAME ='resource_type')
THEN
ALTER TABLE `t_ds_audit_log`
drop resource_type, drop operation, drop resource_id,
add `model_id` bigint(20) DEFAULT NULL COMMENT 'model id',
add `model_name` varchar(100) DEFAULT NULL COMMENT 'model name',
add `model_type` varchar(100) NOT NULL COMMENT 'model type',
add `operation_type` varchar(100) NOT NULL COMMENT 'operation type',
add `description` varchar(100) DEFAULT NULL COMMENT 'api description',
add `latency` int(11) DEFAULT NULL COMMENT 'api cost milliseconds',
add `detail` varchar(100) DEFAULT NULL COMMENT 'object change detail',
MODIFY COLUMN `time` datetime NULL DEFAULT CURRENT_TIMESTAMP COMMENT "operation time";
END IF;
END;
d//
delimiter ;
CALL modify_data_t_ds_audit_log_input_entry;
DROP PROCEDURE modify_data_t_ds_audit_log_input_entry;

28
dolphinscheduler-dao/src/main/resources/sql/upgrade/3.2.2_schema/postgresql/dolphinscheduler_ddl.sql

@ -29,4 +29,30 @@ DROP SEQUENCE IF EXISTS t_ds_relation_project_worker_group_sequence;
CREATE SEQUENCE t_ds_relation_project_worker_group_sequence;
ALTER TABLE t_ds_relation_project_worker_group ALTER COLUMN id SET DEFAULT NEXTVAL('t_ds_relation_project_worker_group_sequence');
ALTER TABLE t_ds_project_parameter ADD COLUMN IF NOT EXISTS operator int;
ALTER TABLE t_ds_project_parameter ADD COLUMN IF NOT EXISTS operator int;
-- modify_data_t_ds_audit_log_input_entry
delimiter d//
CREATE OR REPLACE FUNCTION modify_data_t_ds_audit_log_input_entry() RETURNS void AS $$
BEGIN
IF EXISTS (SELECT 1
FROM information_schema.columns
WHERE table_name = 't_ds_audit_log'
AND column_name = 'resource_type')
THEN
ALTER TABLE t_ds_audit_log
drop resource_type, drop operation, drop resource_id,
add model_id bigint NOT NULL,
add model_name VARCHAR(255) NOT NULL,
add model_type VARCHAR(255) NOT NULL,
add operation_type VARCHAR(255) NOT NULL,
add description VARCHAR(255) NOT NULL,
add latency int NOT NULL,
add detail VARCHAR(255) DEFAULT NULL;
END IF;
END;
$$ LANGUAGE plpgsql;
d//
select modify_data_t_ds_audit_log_input_entry();
DROP FUNCTION IF EXISTS modify_data_t_ds_audit_log_input_entry();

41
dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/AuditLogMapperTest.java

@ -17,12 +17,15 @@
package org.apache.dolphinscheduler.dao.mapper;
import org.apache.dolphinscheduler.common.enums.AuditResourceType;
import org.apache.dolphinscheduler.common.enums.AuditModelType;
import org.apache.dolphinscheduler.common.enums.AuditOperationType;
import org.apache.dolphinscheduler.dao.BaseDaoTest;
import org.apache.dolphinscheduler.dao.entity.AuditLog;
import org.apache.dolphinscheduler.dao.entity.Project;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
@ -30,6 +33,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Lists;
public class AuditLogMapperTest extends BaseDaoTest {
@ -39,13 +43,17 @@ public class AuditLogMapperTest extends BaseDaoTest {
@Autowired
private ProjectMapper projectMapper;
private void insertOne(AuditResourceType resourceType) {
private void insertOne(AuditModelType objectType) {
AuditLog auditLog = new AuditLog();
auditLog.setUserId(1);
auditLog.setModelName("name");
auditLog.setDetail("detail");
auditLog.setLatency(1L);
auditLog.setTime(new Date());
auditLog.setResourceType(resourceType.getCode());
auditLog.setOperation(0);
auditLog.setResourceId(0);
auditLog.setModelType(objectType.getName());
auditLog.setOperationType(AuditOperationType.CREATE.getName());
auditLog.setModelId(1L);
auditLog.setDescription("description");
logMapper.insert(auditLog);
}
@ -65,25 +73,14 @@ public class AuditLogMapperTest extends BaseDaoTest {
*/
@Test
public void testQueryAuditLog() {
insertOne(AuditResourceType.USER_MODULE);
insertOne(AuditResourceType.PROJECT_MODULE);
insertOne(AuditModelType.USER);
insertOne(AuditModelType.PROJECT);
Page<AuditLog> page = new Page<>(1, 3);
int[] resourceType = new int[0];
int[] operationType = new int[0];
List<String> objectTypeList = new ArrayList<>();
List<String> operationTypeList = Lists.newArrayList(AuditOperationType.CREATE.getName());
IPage<AuditLog> logIPage = logMapper.queryAuditLog(page, resourceType, operationType, "", null, null);
IPage<AuditLog> logIPage =
logMapper.queryAuditLog(page, objectTypeList, operationTypeList, "", "", null, null);
Assertions.assertNotEquals(0, logIPage.getTotal());
}
@Test
public void testQueryResourceNameByType() {
String resourceNameByUser = logMapper.queryResourceNameByType(AuditResourceType.USER_MODULE.getMsg(), 1);
Assertions.assertEquals("admin", resourceNameByUser);
Project project = insertProject();
String resourceNameByProject =
logMapper.queryResourceNameByType(AuditResourceType.PROJECT_MODULE.getMsg(), project.getId());
Assertions.assertEquals(project.getName(), resourceNameByProject);
int delete = projectMapper.deleteById(project.getId());
Assertions.assertEquals(delete, 1);
}
}

1
dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessServiceImpl.java

@ -1774,6 +1774,7 @@ public class ProcessServiceImpl implements ProcessService {
if (Boolean.TRUE.equals(syncDefine)) {
if (processDefinition.getId() == null) {
result = processDefineMapper.insert(processDefinitionLog);
processDefinition.setId(processDefinitionLog.getId());
} else {
processDefinitionLog.setId(processDefinition.getId());
result = processDefineMapper.updateById(processDefinitionLog);

6
dolphinscheduler-ui/src/locales/en_US/monitor.ts

@ -60,9 +60,11 @@ export default {
},
audit_log: {
user_name: 'User Name',
resource_type: 'Resource Type',
project_name: 'Project Name',
operation_type: 'Operation Type',
model_type: 'Model Type',
model_name: 'Model Name',
latency: 'Latency',
description: 'Description',
create_time: 'Create Time',
start_time: 'Start Time',
end_time: 'End Time',

6
dolphinscheduler-ui/src/locales/zh_CN/monitor.ts

@ -58,9 +58,11 @@ export default {
},
audit_log: {
user_name: '用户名称',
resource_type: '资源类型',
project_name: '项目名称',
operation_type: '操作类型',
model_type: '模型类型',
model_name: '模型名称',
latency: '耗时',
description: '描述',
create_time: '创建时间',
start_time: '开始时间',
end_time: '结束时间',

14
dolphinscheduler-ui/src/service/modules/audit/index.ts

@ -25,3 +25,17 @@ export function queryAuditLogListPaging(params: AuditListReq): any {
params
})
}
export function queryAuditModelType(): any {
return axios({
url: '/projects/audit/audit-log-model-type',
method: 'get'
})
}
export function queryAuditLogOperationType(): any {
return axios({
url: '/projects/audit/audit-log-operation-type',
method: 'get'
})
}

18
dolphinscheduler-ui/src/service/modules/audit/types.ts

@ -45,4 +45,20 @@ interface AuditListRes {
start: number
}
export { AuditListReq, AuditListRes }
interface AuditModelTypeItem {
code: number
name: string
child: AuditModelTypeItem[] | null
}
interface AuditOperationTypeItem {
code: number
name: string
}
export {
AuditListReq,
AuditListRes,
AuditModelTypeItem,
AuditOperationTypeItem
}

65
dolphinscheduler-ui/src/views/monitor/statistics/audit-log/index.tsx

@ -30,7 +30,8 @@ import {
NButton,
NIcon,
NDataTable,
NPagination
NPagination,
NCascader
} from 'naive-ui'
import { SearchOutlined } from '@vicons/antd'
import { useTable } from './use-table'
@ -40,15 +41,23 @@ import Card from '@/components/card'
const AuditLog = defineComponent({
name: 'audit-log',
setup() {
const { t, variables, getTableData, createColumns } = useTable()
const {
t,
variables,
getTableData,
createColumns,
getModelTypeData,
getOperationTypeData
} = useTable()
const requestTableData = () => {
getTableData({
pageSize: variables.pageSize,
pageNo: variables.page,
resourceType: variables.resourceType,
modelType: variables.modelType,
operationType: variables.operationType,
userName: variables.userName,
modelName: variables.modelName,
datePickerRange: variables.datePickerRange
})
}
@ -67,6 +76,8 @@ const AuditLog = defineComponent({
onMounted(() => {
createColumns(variables)
getModelTypeData()
getOperationTypeData()
requestTableData()
})
@ -97,36 +108,41 @@ const AuditLog = defineComponent({
placeholder={t('monitor.audit_log.user_name')}
clearable
/>
<NSelect
v-model={[this.operationType, 'value']}
<NInput
allowInput={this.trim}
v-model={[this.modelName, 'value']}
size='small'
options={[
{ value: 'CREATE', label: t('monitor.audit_log.create') },
{ value: 'UPDATE', label: t('monitor.audit_log.update') },
{ value: 'DELETE', label: t('monitor.audit_log.delete') },
{ value: 'READ', label: t('monitor.audit_log.read') }
]}
placeholder={t('monitor.audit_log.operation_type')}
placeholder={t('monitor.audit_log.model_name')}
clearable
/>
<NCascader
v-model={[this.modelType, 'value']}
multiple
cascade={false}
size='small'
options={this.ModelTypeData}
placeholder={t('monitor.audit_log.model_type')}
style={{ width: '180px' }}
clearable
filterable
value-field='name'
label-field='name'
children-field='child'
show-path={false}
maxTagCount={1}
/>
<NSelect
v-model={[this.resourceType, 'value']}
v-model={[this.operationType, 'value']}
size='small'
options={[
{
value: 'USER_MODULE',
label: t('monitor.audit_log.user_audit')
},
{
value: 'PROJECT_MODULE',
label: t('monitor.audit_log.project_audit')
}
]}
placeholder={t('monitor.audit_log.resource_type')}
options={this.OperationTypeData}
placeholder={t('monitor.audit_log.operation_type')}
style={{ width: '180px' }}
clearable
filterable
value-field='name'
label-field='name'
/>
<NDatePicker
v-model={[this.datePickerRange, 'value']}
type='datetimerange'
@ -147,6 +163,7 @@ const AuditLog = defineComponent({
<NDataTable
loading={loadingRef}
columns={this.columns}
scrollX={this.tableWidth}
data={this.tableData}
/>
<NSpace justify='center'>

90
dolphinscheduler-ui/src/views/monitor/statistics/audit-log/use-table.ts

@ -18,22 +18,40 @@
import { useI18n } from 'vue-i18n'
import { reactive, ref } from 'vue'
import { useAsyncState } from '@vueuse/core'
import { queryAuditLogListPaging } from '@/service/modules/audit'
import {
queryAuditLogListPaging,
queryAuditModelType,
queryAuditLogOperationType
} from '@/service/modules/audit'
import { format } from 'date-fns'
import { parseTime } from '@/common/common'
import type { AuditListRes } from '@/service/modules/audit/types'
import type {
AuditListRes,
AuditModelTypeItem,
AuditOperationTypeItem
} from '@/service/modules/audit/types'
import {
COLUMN_WIDTH_CONFIG,
calculateTableWidth,
DefaultTableWidth
} from '@/common/column-width-config'
import { sortBy } from 'lodash'
export function useTable() {
const { t } = useI18n()
const variables = reactive({
columns: [],
tableWidth: DefaultTableWidth,
tableData: [],
page: ref(1),
pageSize: ref(10),
resourceType: ref(null),
modelType: ref(null),
operationType: ref(null),
ModelTypeData: [],
OperationTypeData: [],
userName: ref(null),
modelName: ref(null),
datePickerRange: ref(null),
totalPage: ref(1),
loadingRef: ref(false)
@ -44,29 +62,70 @@ export function useTable() {
{
title: '#',
key: 'index',
render: (row: any, index: number) => index + 1
render: (row: any, index: number) => index + 1,
...COLUMN_WIDTH_CONFIG['index']
},
{
title: t('monitor.audit_log.user_name'),
key: 'userName'
key: 'userName',
...COLUMN_WIDTH_CONFIG['userName']
},
{
title: t('monitor.audit_log.resource_type'),
key: 'resource'
title: t('monitor.audit_log.model_type'),
key: 'modelType',
...COLUMN_WIDTH_CONFIG['type']
},
{
title: t('monitor.audit_log.project_name'),
key: 'resourceName'
title: t('monitor.audit_log.model_name'),
key: 'modelName',
...COLUMN_WIDTH_CONFIG['name']
},
{
title: t('monitor.audit_log.operation_type'),
key: 'operation'
key: 'operation',
...COLUMN_WIDTH_CONFIG['type']
},
{
title: t('monitor.audit_log.description'),
key: 'description',
...COLUMN_WIDTH_CONFIG['note']
},
{
title: t('monitor.audit_log.latency') + ' (ms)',
key: 'latency',
...COLUMN_WIDTH_CONFIG['times']
},
{
title: t('monitor.audit_log.create_time'),
key: 'time'
key: 'time',
...COLUMN_WIDTH_CONFIG['time']
}
]
if (variables.tableWidth) {
variables.tableWidth = calculateTableWidth(variables.columns)
}
}
const getModelTypeData = async () => {
try {
variables.ModelTypeData = await queryAuditModelType().then(
(res: AuditModelTypeItem[]) => res || []
)
} catch {
variables.ModelTypeData = []
}
}
const getOperationTypeData = async () => {
try {
variables.OperationTypeData = await queryAuditLogOperationType().then(
(res: AuditOperationTypeItem[]) => sortBy(res, 'name')
)
} catch {
variables.OperationTypeData = []
}
}
const getTableData = (params: any) => {
@ -75,9 +134,10 @@ export function useTable() {
const data = {
pageSize: params.pageSize,
pageNo: params.pageNo,
resourceType: params.resourceType,
operationType: params.operationType,
modelTypes: params.modelType,
operationTypes: params.operationType,
userName: params.userName,
modelName: params.modelName,
startDate: params.datePickerRange
? format(parseTime(params.datePickerRange[0]), 'yyyy-MM-dd HH:mm:ss')
: '',
@ -106,6 +166,8 @@ export function useTable() {
t,
variables,
getTableData,
createColumns
createColumns,
getModelTypeData: getModelTypeData,
getOperationTypeData
}
}

Loading…
Cancel
Save