Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/DataLinkDC/dinky into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Nov 27, 2024
2 parents 8bd2ff5 + fa16032 commit 36f505d
Show file tree
Hide file tree
Showing 13 changed files with 5,061 additions and 432 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ public class WebExceptionHandler {
@ExceptionHandler
@ResponseBody
public Result<Void> busException(BusException e) {
log.error("BusException:", e);
return Result.failed(e.getMsg());
log.error(e.getMessage(), e);
return Result.failed(e.getMessage());
}

private static final Map<String, Status> ERR_CODE_MAPPING = MapUtil.<String, Status>builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.springframework.web.bind.annotation.RestController;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.hutool.core.lang.Singleton;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
Expand All @@ -45,14 +46,13 @@
@SaCheckLogin
@RequiredArgsConstructor
public class FlinkController {

protected static final CheckpointRead INSTANCE = new CheckpointRead();
private final FlinkService flinkService;

@GetMapping("/readCheckPoint")
@ApiOperation("Read Checkpoint")
public Result<Map<String, Map<String, CheckPointReadTable>>> readCheckPoint(String path, String operatorId) {
return Result.data(INSTANCE.readCheckpoint(path, operatorId));
CheckpointRead checkpointRead = Singleton.get(CheckpointRead.class);
return Result.data(checkpointRead.readCheckpoint(path, operatorId));
}

@GetMapping("/configOptions")
Expand Down
36 changes: 23 additions & 13 deletions dinky-admin/src/main/java/org/dinky/init/SystemInit.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,30 @@ public class SystemInit implements ApplicationRunner {

@Override
public void run(ApplicationArguments args) {
TenantContextHolder.ignoreTenant();
initResources();
List<Tenant> tenants = tenantService.list();
sysConfigService.initSysConfig();
sysConfigService.initExpressionVariables();

for (Tenant tenant : tenants) {
taskService.initDefaultFlinkSQLEnv(tenant.getId());
try {
TenantContextHolder.ignoreTenant();
initResources();
List<Tenant> tenants = tenantService.list();
sysConfigService.initSysConfig();
sysConfigService.initExpressionVariables();

for (Tenant tenant : tenants) {
taskService.initDefaultFlinkSQLEnv(tenant.getId());
}
initDaemon();
initDolphinScheduler();
registerUDF();
updateGitBuildState();
registerURL();
} catch (NoClassDefFoundError e) {
if (e.getMessage().contains("org/apache/flink")) {
log.error(
"No Flink Jar dependency detected, please put the Flink Jar dependency into the DInky program first. (未检测到有 Flink Jar依赖,请先放入 Flink Jar 依赖到 DInky程序里)",
e);
} else {
log.error("", e);
}
}
initDaemon();
initDolphinScheduler();
registerUDF();
updateGitBuildState();
registerURL();
}

private void registerURL() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

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

Expand All @@ -73,7 +74,6 @@
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

Expand Down Expand Up @@ -558,12 +558,17 @@ public UserDTO buildUserInfo(Integer userId) {
// query role menu
List<RoleMenu> roleMenus =
roleMenuService.list(new LambdaQueryWrapper<RoleMenu>().eq(RoleMenu::getRoleId, role.getId()));
roleMenus.forEach(roleMenu -> {
Menu menu = menuService.getById(roleMenu.getMenuId());
if (Asserts.isNotNull(menu) && !StrUtil.equals("M", menu.getType())) {
menuList.add(menu);
}
});
List<Integer> collect =
roleMenus.stream().map(RoleMenu::getMenuId).collect(Collectors.toList());
if (CollectionUtils.isEmpty(collect)) {
return;
}
List<Menu> list = menuService.list(new LambdaQueryWrapper<Menu>()
.in(
Menu::getId,
roleMenus.stream().map(RoleMenu::getMenuId).collect(Collectors.toList()))
.ne(Menu::getType, "M"));
menuList.addAll(list);
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class RsURLConnection extends URLConnection {
public void connect() {
BaseResourceManager instance = BaseResourceManager.getInstance();
if (instance == null) {
throw BusException.valueOf("ResourceManager is disabled");
throw BusException.of("ResourceManager is disabled");
}
inputStream = instance.readFile(getURL().getPath());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ public void remove(String path) {
try {
boolean isSuccess = FileUtil.del(getFilePath(path));
if (!isSuccess) {
throw new BusException("remove file failed,reason unknown");
throw BusException.of(Status.RESOURCE_FILE_DELETE_FAILED, "unknown");
}
} catch (IORuntimeException e) {
throw new BusException(Status.RESOURCE_FILE_DELETE_FAILED, e);
throw BusException.of(e, Status.RESOURCE_FILE_DELETE_FAILED);
}
}

Expand All @@ -67,7 +67,7 @@ public void rename(String path, String newPath) {
String newName = FileUtil.getName(newPath);
FileUtil.rename(new File(getFilePath(path)), newName, true);
} catch (Exception e) {
throw new BusException(Status.RESOURCE_FILE_RENAME_FAILED, e);
throw BusException.of(e, Status.RESOURCE_FILE_RENAME_FAILED);
}
}

Expand All @@ -76,7 +76,7 @@ public void putFile(String path, InputStream fileStream) {
try {
FileUtil.writeFromStream(fileStream, getFilePath(path));
} catch (Exception e) {
throw new BusException(Status.RESOURCE_FILE_UPLOAD_FAILED, e);
throw BusException.of(e, Status.RESOURCE_FILE_UPLOAD_FAILED);
}
}

Expand Down Expand Up @@ -125,7 +125,7 @@ public List<ResourcesVO> getFullDirectoryStructure(int rootId) {
.filter(Objects::nonNull)
.collect(Collectors.toList());
} catch (IOException e) {
throw new BusException(Status.RESOURCE_FILE_PATH_VISIT_FAILED, e);
throw BusException.of(e, Status.RESOURCE_FILE_PATH_VISIT_FAILED);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class RsURLConnection extends URLConnection {
public void connect() {
BaseResourceManager instance = BaseResourceManager.getInstance();
if (instance == null) {
throw BusException.valueOf("ResourceManager is disabled");
throw BusException.of("ResourceManager is disabled");
}
inputStream = instance.readFile(getURL().getPath());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

import org.dinky.data.enums.Status;

import javax.annotation.Nullable;

import cn.hutool.core.util.StrUtil;
import lombok.Getter;
import lombok.Setter;
Expand All @@ -39,69 +41,92 @@
@Setter
public class BusException extends RuntimeException {

private static final long serialVersionUID = -2955156471454043812L;
private static final long serialVersionUID = 1L;

/** 异常信息的code码 */
/** Exception status code */
private Status code;

/** 异常信息的参数 */
/** Exception parameters */
private Object[] errorArgs;

/** 如果有值得话,将不会取i18n里面的错误信息 */
private String msg;

/**
* Constructs a BusException with the specified message.
*
* @param message the detail message
*/
public BusException(String message) {
super(message);
setMsg(message);
}

public BusException(Status status) {
super(status.getMessage());
setCode(status);
setMsg(status.getMessage());
}

/**
* Constructs a BusException with the specified status and error arguments.
*
* @param status the status code representing the exception
* @param errorArgs the arguments used for error message formatting
*/
public BusException(Status status, Object... errorArgs) {
super(status.getMessage());
setCode(status);
setMsg(StrUtil.format(status.getMessage(), errorArgs));
super(formatMessage(null, status, errorArgs));
this.code = status;
this.errorArgs = errorArgs;
}

/**
* An exception that gets the error message through i 18n
* Constructs a BusException with the specified cause, status, and error arguments.
*
* @param message code
* @param e e
* @return {@link BusException}
* @param cause the cause of the exception
* @param status the status code representing the exception
* @param errorArgs the arguments used for error message formatting
*/
public static BusException valueOf(String message, Throwable e) {
log.error(message, e);
return new BusException(message + e.getMessage());
public BusException(Throwable cause, Status status, Object... errorArgs) {
super(formatMessage(cause.getMessage(), status, errorArgs), cause);
this.code = status;
this.errorArgs = errorArgs;
}

public static BusException valueOf(Status code, Throwable e) {
log.error(code.getMessage(), e);
return new BusException(code, e.getMessage());
/**
* Creates a BusException instance with the specified message.
*
* @param message the detail message
* @return a new BusException instance
*/
public static BusException of(String message) {
return new BusException(message);
}

/**
* An exception that gets the error message through i 18n
* Creates a BusException instance with the specified status, and error arguments.
*
* @param code code
* @param errorArgs errorArgs
* @return {@link BusException}
* @param status the status code representing the exception
* @param errorArgs the arguments used for error message formatting
* @return a new BusException instance
*/
public static BusException valueOf(Status code, Object... errorArgs) {
return new BusException(code, errorArgs);
public static BusException of(Status status, Object... errorArgs) {
return new BusException(status, errorArgs);
}

/**
* Without passing the exception to i 18n, it is directly returned to the msg past
* Creates a BusException instance with the specified cause, status, and error arguments.
*
* @param msg msg
* @return {@link BusException}
* @param cause the cause of the exception
* @param status the status code representing the exception
* @param errorArgs the arguments used for error message formatting
* @return a new BusException instance
*/
public static BusException valueOf(String msg) {
return new BusException(msg);
public static BusException of(Throwable cause, Status status, Object... errorArgs) {
return new BusException(cause, status, errorArgs);
}

/** Formats the exception message with optional cause message and error arguments. */
private static String formatMessage(@Nullable String causeMessage, Status status, Object... errorArgs) {
Object[] args = errorArgs == null ? new Object[0] : errorArgs;

if (causeMessage != null) {
Object[] extendedArgs = new Object[args.length + 1];
System.arraycopy(args, 0, extendedArgs, 0, args.length);
extendedArgs[args.length] = causeMessage;
args = extendedArgs;
}

return StrUtil.format(status.getMessage(), args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,10 @@ role.binding.row.permission=Role Already Binding Row Permission , Can Not Delete
# dinky-admin
unknown.i18n=Unknown i18n information, please check. . .

file.upload.failed=File upload failed, reason: {0}
file.rename.failed=File rename failed, reason: {0}
file.delete.failed=File delete failed, reason: {0}
file.read.failed=File read failed, reason: {0}
file.upload.failed=File upload failed, reason: {}
file.rename.failed=File rename failed, reason: {}
file.delete.failed=File delete failed, reason: {}
file.read.failed=File read failed, reason: {}

catalogue.sort.value.first_letter=First Letter
catalogue.sort.value.create_time=Create Time
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,10 @@ role.binding.row.permission=该角色已绑定行权限,无法删除
# dinky-admin
unknown.i18n=未知 i18n 信息,请检查. . .

file.upload.failed=文件上传失败, 原因: {0}
file.rename.failed=文件重命名失败, 原因: {0}
file.delete.failed=文件删除失败, 原因: {0}
file.read.failed=文件读取失败, 原因: {0}
file.upload.failed=文件上传失败, 原因: {}
file.rename.failed=文件重命名失败, 原因: {}
file.delete.failed=文件删除失败, 原因: {}
file.read.failed=文件读取失败, 原因: {}

daemon.task.config.not.exist=线程任务配置不能为空
daemon.task.not.support=不支持线程任务类型:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,5 @@ public class K8sConfig {
dataType = "Map<String, String>",
example = "{\"key1\": \"value1\", \"key2\": \"value2\"}",
notes = "Ingress configuration properties")
private Map<String, String> ingressConfig = Maps.newHashMap();
private Map<String, Object> ingressConfig = Maps.newHashMap();
}
Original file line number Diff line number Diff line change
Expand Up @@ -363,11 +363,14 @@ private String getIngressUrl(Ingress ingress, String namespace, String clusterId
* @return ingress domain
*/
private String checkUseIngress() {
Map<String, String> ingressConfig = k8sConfig.getIngressConfig();
Map<String, Object> ingressConfig = k8sConfig.getIngressConfig();
if (MapUtils.isNotEmpty(ingressConfig)) {
boolean ingressEnable =
Boolean.parseBoolean(ingressConfig.getOrDefault(DINKY_K8S_INGRESS_ENABLED_KEY, "false"));
String ingressDomain = ingressConfig.getOrDefault(DINKY_K8S_INGRESS_DOMAIN_KEY, StringUtils.EMPTY);
boolean ingressEnable = Boolean.parseBoolean(ingressConfig
.getOrDefault(DINKY_K8S_INGRESS_ENABLED_KEY, "false")
.toString());
String ingressDomain = ingressConfig
.getOrDefault(DINKY_K8S_INGRESS_DOMAIN_KEY, StringUtils.EMPTY)
.toString();
if (ingressEnable && StringUtils.isNotEmpty(ingressDomain)) {
return ingressDomain;
}
Expand Down
Loading

0 comments on commit 36f505d

Please sign in to comment.