Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] fix scala/java udf compiler, add error messages, clear cached classes before publish #4049

Open
wants to merge 18 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,6 @@ extends/*
.idea
.idea/vcs.xml
dinky-web/package-lock.json


**/.flattened-pom.xml
3 changes: 3 additions & 0 deletions dinky-admin/src/main/java/org/dinky/Dinky.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@
import org.dinky.data.constant.DirConstant;
import org.dinky.security.NoExitSecurityManager;

import org.dinky.ltpa.config.LtpaTokenProperties;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.freemarker.FreeMarkerAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.transaction.annotation.EnableTransactionManagement;

Expand All @@ -41,6 +43,7 @@
@EnableTransactionManagement
@SpringBootApplication(exclude = FreeMarkerAutoConfiguration.class)
@EnableCaching
@EnableConfigurationProperties(LtpaTokenProperties.class)
public class Dinky {

static {
Expand Down
25 changes: 18 additions & 7 deletions dinky-admin/src/main/java/org/dinky/configure/AppConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,23 @@

package org.dinky.configure;

import cn.dev33.satoken.exception.StopMatchException;
import cn.dev33.satoken.interceptor.SaInterceptor;
import cn.dev33.satoken.router.SaRouter;
import cn.dev33.satoken.stp.StpUtil;
import org.dinky.data.constant.BaseConstant;
import org.dinky.interceptor.LocaleChangeInterceptor;
import org.dinky.interceptor.TenantInterceptor;

import java.util.Locale;

import org.dinky.ltpa.interceptor.LtpaTokenInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.i18n.CookieLocaleResolver;

import cn.dev33.satoken.exception.StopMatchException;
import cn.dev33.satoken.interceptor.SaInterceptor;
import cn.dev33.satoken.router.SaRouter;
import cn.dev33.satoken.stp.StpUtil;
import javax.annotation.Resource;
import java.util.Locale;

/**
* AppConfiguration
Expand All @@ -44,6 +44,10 @@
*/
@Configuration
public class AppConfig implements WebMvcConfigurer {
@Resource
private LtpaTokenInterceptor ltpaTokenInterceptor;


/**
* Cookie
*
Expand Down Expand Up @@ -73,6 +77,13 @@ public LocaleChangeInterceptor localeChangeInterceptor() {
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(localeChangeInterceptor());
// 注册 LTPA Token 拦截器
registry.addInterceptor(ltpaTokenInterceptor)
// .addPathPatterns("/**")
.addPathPatterns("/api/**", "/openapi/**")
.excludePathPatterns("/api/login", "/api/ldap/ldapEnableStatus", "/download/**", "/druid/**");
;

// 注册Sa-Token的路由拦截器
registry.addInterceptor(new SaInterceptor(handler -> {
SaRouter.match("/openapi/**", r -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.dinky.controller;

import org.apache.commons.beanutils.BeanUtils;
import org.dinky.DinkyVersion;
import org.dinky.data.annotations.Log;
import org.dinky.data.dto.APISavePointTaskDTO;
Expand All @@ -39,13 +40,9 @@
import org.dinky.service.TaskService;

import java.util.List;
import java.util.Map;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
Expand Down Expand Up @@ -76,10 +73,11 @@ public Result<String> getVersionInfo() {
return Result.succeed(DinkyVersion.getVersion(), Status.QUERY_SUCCESS);
}

@PostMapping("/submitTask")
@RequestMapping(value = "/submitTask", method = {RequestMethod.POST, RequestMethod.GET})
@ApiOperation("Submit Task")
// @Log(title = "Submit Task", businessType = BusinessType.SUBMIT)
public Result<JobResult> submitTask(@RequestBody TaskSubmitDto submitDto) throws Exception {
public Result<JobResult> submitTask(@RequestBody(required = false) TaskSubmitDto submitDto, @RequestParam(required = false) Map<String, ?> params) throws Exception {
BeanUtils.populate(submitDto= submitDto==null ? new TaskSubmitDto() : submitDto, params);
taskService.initTenantByTaskId(submitDto.getId());
JobResult jobResult = taskService.submitTask(submitDto);
if (jobResult.isSuccess()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,12 @@ public Result<String> upload(MultipartFile file, @PathVariable Integer id) {
required = true,
dataType = "Catalogue",
dataTypeClass = Catalogue.class)
public Result<Void> saveOrUpdateCatalogue(@RequestBody Catalogue catalogue) {
public Result<Catalogue> saveOrUpdateCatalogue(@RequestBody Catalogue catalogue) {
if (catalogueService.checkNameIsExistByParentId(catalogue)) {
return Result.failed(Status.NAME_IS_EXIST);
}
if (catalogueService.saveOrUpdateOrRename(catalogue)) {
return Result.succeed(Status.SAVE_SUCCESS);
return Result.succeed(catalogue, Status.SAVE_SUCCESS);
} else {
return Result.failed(Status.SAVE_FAILED);
}
Expand Down
17 changes: 13 additions & 4 deletions dinky-admin/src/main/java/org/dinky/controller/TaskController.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.dinky.controller;

import org.apache.commons.lang3.exception.ExceptionUtils;
import org.dinky.data.annotations.CheckTaskOwner;
import org.dinky.data.annotations.ExecuteProcess;
import org.dinky.data.annotations.Log;
Expand All @@ -32,6 +33,7 @@
import org.dinky.data.enums.JobLifeCycle;
import org.dinky.data.enums.ProcessType;
import org.dinky.data.enums.Status;
import org.dinky.data.enums.CodeEnum;
import org.dinky.data.exception.NotSupportExplainExcepition;
import org.dinky.data.exception.SqlExplainExcepition;
import org.dinky.data.model.JarSubmitParam;
Expand Down Expand Up @@ -174,11 +176,18 @@ public Result<SavePointResult> savepoint(@TaskId @RequestParam Integer taskId, @
@CheckTaskOwner(checkParam = TaskId.class, checkInterface = TaskService.class)
public Result<Boolean> changeTaskLife(@TaskId @RequestParam Integer taskId, @RequestParam Integer lifeCycle)
throws SqlExplainExcepition {
if (taskService.changeTaskLifeRecyle(taskId, JobLifeCycle.get(lifeCycle))) {
return Result.succeed(lifeCycle == 2 ? Status.PUBLISH_SUCCESS : Status.OFFLINE_SUCCESS);
} else {
return Result.failed(lifeCycle == 2 ? Status.PUBLISH_FAILED : Status.OFFLINE_FAILED);
// 返回UDF编译错误原因,以便前端排除
String msg="";
try {
if (taskService.changeTaskLifeRecyle(taskId, JobLifeCycle.get(lifeCycle))) {
return Result.succeed(true, lifeCycle == 2 ? Status.PUBLISH_SUCCESS : Status.OFFLINE_SUCCESS);
}
} catch (Exception e) {
e.printStackTrace();
msg = ExceptionUtils.getStackTrace(e);
}
return Result.of(false, CodeEnum.ERROR.getCode(),
String.format("%s.\n%s", (lifeCycle == 2 ? Status.PUBLISH_FAILED : Status.OFFLINE_FAILED).getMessage(), msg));
}

@PostMapping("/explainSql")
Expand Down
3 changes: 2 additions & 1 deletion dinky-admin/src/main/java/org/dinky/init/SystemInit.java
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ public static Project getProject() {
public void registerUDF() {
List<Task> allUDF = taskService.getReleaseUDF();
if (CollUtil.isNotEmpty(allUDF)) {
UdfCodePool.registerPool(allUDF.stream().map(UDFUtils::taskToUDF).collect(Collectors.toList()));
// 启动只打印错误
UdfCodePool.registerPool(allUDF.stream().map(UDFUtils::taskToUDFSilent).collect(Collectors.toList()));
}
UdfCodePool.updateGitPool(gitProjectService.getGitPool());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@

package org.dinky.job.handler;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import lombok.Builder;
import org.dinky.assertion.Asserts;
import org.dinky.data.model.ClusterInstance;
import org.dinky.data.model.job.History;
Expand All @@ -32,10 +37,6 @@
import java.util.List;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import lombok.Builder;

@Builder
public class ClearJobHistoryHandler {
private JobInstanceService jobInstanceService;
Expand All @@ -45,7 +46,8 @@ public class ClearJobHistoryHandler {

/**
* Clears job history records based on the specified criteria.
* @param maxRetainDays The maximum number of days to retain job history.
*
* @param maxRetainDays The maximum number of days to retain job history.
* @param maxRetainCount The maximum count to retain job history.
*/
public void clearJobHistory(Integer maxRetainDays, Integer maxRetainCount) {
Expand Down Expand Up @@ -107,7 +109,8 @@ public void clearJobHistory(Integer maxRetainDays, Integer maxRetainCount) {

/**
* Clears dinky history records based on the specified criteria.
* @param maxRetainDays The maximum number of days to retain dinky history.
*
* @param maxRetainDays The maximum number of days to retain dinky history.
* @param maxRetainCount The maximum count to retain dinky history.
*/
public void clearDinkyHistory(Integer maxRetainDays, Integer maxRetainCount) {
Expand All @@ -122,17 +125,14 @@ public void clearDinkyHistory(Integer maxRetainDays, Integer maxRetainCount) {
for (History history : historyList) {
// Check if the count exceeds the maximum retain count
if (history.getCount() > maxRetainCount) {
List<History> reservedHistory = historyService
.lambdaQuery()
.eq(History::getTaskId, history.getTaskId())
List<History> reservedHistory = eq(historyService.lambdaQuery(), History::getTaskId, history.getTaskId())
.orderByDesc(History::getId)
.last("limit " + maxRetainCount)
.list();
// Create a query wrapper to delete history records older than the maximum retain days
QueryWrapper<History> deleteWrapper = new QueryWrapper<>();
deleteWrapper
.lambda()
.eq(History::getTaskId, history.getTaskId())
eq(deleteWrapper
.lambda(), History::getTaskId, history.getTaskId())
.lt(History::getStartTime, LocalDateTime.now().minusDays(maxRetainDays))
.notIn(
true,
Expand All @@ -142,4 +142,12 @@ public void clearDinkyHistory(Integer maxRetainDays, Integer maxRetainCount) {
}
}
}

public static <T, R> LambdaQueryWrapper<T> eq(LambdaQueryWrapper<T> wrapper, SFunction<T, R> column, Object val) {
return val == null ? wrapper.isNull(column) : wrapper.eq(true, column, val);
}

public static <T, R> LambdaQueryChainWrapper<T> eq(LambdaQueryChainWrapper<T> wrapper, SFunction<T, R> column, Object val) {
return val == null ? wrapper.isNull(column) : wrapper.eq(true, column, val);
}
}
45 changes: 45 additions & 0 deletions dinky-admin/src/main/java/org/dinky/ltpa/config/LtpaSetting.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.dinky.ltpa.config;

/**
* Author: lwjhn
* Date: 2023/7/3 15:08
* Description:
*/
public class LtpaSetting {
protected String secret = "2OqzZkZ//RvOLF+X1HqNJWcCBHE="; // 秘钥
protected long expiration = 43200L; // 默认过期-LTPA_Validity时间为43200秒(12小时)
protected long transition = 300L; // 过渡时间-LTPA_TokenExpiration.保证各服务时间不同步时的误差,过期后的这个时间内仍然有效,默认300秒(5分钟)
// protected String version="00010203"; //LtpaToken 版本(长度4),Domino的固定为[0x00][0x01][0x02][0x03]

public String getSecret() {
return secret;
}

public void setSecret(String secret) {
this.secret = secret;
}

public long getExpiration() {
return expiration;
}

public void setExpiration(long expiration) {
this.expiration = expiration;
}

public long getTransition() {
return transition;
}

public void setTransition(long transition) {
this.transition = transition;
}

// public String getVersion() {
// return version;
// }
//
// public void setVersion(String version) {
// this.version = version;
// }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.dinky.ltpa.config;

import org.springframework.boot.context.properties.ConfigurationProperties;

import java.util.HashMap;

/**
* Author: lwjhn
* Date: 2023/6/30 11:21
* Description:
*/
@ConfigurationProperties(prefix = "ltpa", ignoreInvalidFields = true)
public class LtpaTokenProperties extends HashMap<String, LtpaTokenSetting> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package org.dinky.ltpa.config;

import java.util.List;
import java.util.regex.Pattern;

/**
* Author: lwjhn
* Date: 2023/6/30 14:23
* Description:
*/
public class LtpaTokenSetting extends LtpaSetting {
private Pattern originRegExp;

private String originRegVal;

private Pattern targetRegExp;

private String targetRegVal;
private String domain;

private List<String> clearCookies;

public Pattern getOriginRegExp() {
return originRegExp;
}

public void setOriginRegExp(Pattern originRegExp) {
this.originRegExp = originRegExp;
}

public String getOriginRegVal() {
return originRegVal;
}

public void setOriginRegVal(String originRegVal) {
this.originRegVal = originRegVal;
}

public Pattern getTargetRegExp() {
return targetRegExp;
}

public void setTargetRegExp(Pattern targetRegExp) {
this.targetRegExp = targetRegExp;
}

public String getTargetRegVal() {
return targetRegVal;
}

public void setTargetRegVal(String targetRegVal) {
this.targetRegVal = targetRegVal;
}

public String getDomain() {
return domain;
}

public void setDomain(String domain) {
this.domain = domain;
}

public List<String> getClearCookies() {
return clearCookies;
}

public void setClearCookies(List<String> clearCookies) {
this.clearCookies = clearCookies;
}
}
Loading