Skip to content

Commit

Permalink
[Feature][Web] Add welcome init page (#3938)
Browse files Browse the repository at this point in the history
Co-authored-by: gaoyan1998 <[email protected]>
  • Loading branch information
gaoyan1998 and gaoyan1998 authored Nov 22, 2024
1 parent be464fa commit 9d5b22d
Show file tree
Hide file tree
Showing 24 changed files with 3,036 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class TaskOperationPermissionAspect {
@Around(value = "@annotation(checkTaskOwner)")
public Object processAround(ProceedingJoinPoint joinPoint, CheckTaskOwner checkTaskOwner) throws Throwable {
if (!TaskOwnerLockStrategyEnum.ALL.equals(
SystemConfiguration.getInstances().getTaskOwnerLockStrategy())
SystemConfiguration.getInstances().GetTaskOwnerLockStrategyValue())
&& BaseConstant.ADMIN_ID != StpUtil.getLoginIdAsInt()) {
Class checkParam = checkTaskOwner.checkParam();
Object param = getParam(joinPoint, checkParam);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,18 @@ public Result<List<Configuration<?>>> getOneTypeByKey(@RequestParam("type") Stri
.collect(Collectors.toList());
return Result.succeed(configList);
}

@GetMapping("/getNeededCfg")
@ApiOperation("Get Needed Config")
@SaIgnore
public Result<Map<String, Object>> getNeededCfg() {
return sysConfigService.getNeededCfg();
}

@PostMapping("/setInitConfig")
@ApiOperation("Get Needed Config")
@SaIgnore
public Result<Void> setInitConfig(@RequestBody Map<String, Object> params) {
return sysConfigService.setInitConfig(params);
}
}
15 changes: 15 additions & 0 deletions dinky-admin/src/main/java/org/dinky/service/SysConfigService.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import org.dinky.data.model.Configuration;
import org.dinky.data.model.SysConfig;
import org.dinky.data.result.Result;
import org.dinky.mybatis.service.ISuperService;

import java.util.List;
Expand Down Expand Up @@ -64,4 +65,18 @@ public interface SysConfigService extends ISuperService<SysConfig> {
* @param value The new value of the configuration.
*/
void updateSysConfigByKv(String key, String value);

/**
* Get needed configurations.
*
* @return A map of string keys to lists of {@link Configuration} objects.
*/
Result<Map<String, Object>> getNeededCfg();

/**
* Set initial configurations.
*
* @param params The parameters for initializing configurations.
*/
Result<Void> setInitConfig(Map<String, Object> params);
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@
import org.dinky.data.model.Configuration;
import org.dinky.data.model.SysConfig;
import org.dinky.data.model.SystemConfiguration;
import org.dinky.data.model.rbac.User;
import org.dinky.data.result.Result;
import org.dinky.mapper.SysConfigMapper;
import org.dinky.mybatis.service.impl.SuperServiceImpl;
import org.dinky.service.SysConfigService;
import org.dinky.service.UserService;
import org.dinky.utils.TextUtil;

import java.util.HashMap;
import java.util.List;
Expand All @@ -37,8 +41,10 @@
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.activerecord.Model;

import cn.dev33.satoken.secure.SaSecureUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
Expand All @@ -48,8 +54,11 @@
*/
@Service
@Slf4j
@RequiredArgsConstructor
public class SysConfigServiceImpl extends SuperServiceImpl<SysConfigMapper, SysConfig> implements SysConfigService {

private final UserService userService;

@Override
public Map<String, List<Configuration<?>>> getAll() {
return SystemConfiguration.getInstances().getAllConfiguration();
Expand Down Expand Up @@ -121,4 +130,59 @@ public void updateSysConfigByKv(String key, String value) {
initExpressionVariables();
}
}

@Override
public Result<Map<String, Object>> getNeededCfg() {
Map<String, Object> result = new HashMap<>();

SystemConfiguration instances = SystemConfiguration.getInstances();

Configuration<Boolean> isFirstSystemIn = instances.getIsFirstSystemIn();
Configuration<Boolean> ldapEnable = instances.getLdapEnable();

result.put(isFirstSystemIn.getKey(), isFirstSystemIn.getValue());
result.put(ldapEnable.getKey(), ldapEnable.getValue());

if (isFirstSystemIn.getValue()) {
result.put(
instances.getDinkyAddr().getKey(), instances.getDinkyAddr().getValue());
result.put(
instances.getTaskOwnerLockStrategy().getKey(),
instances.getTaskOwnerLockStrategy().getValue());
result.put(
instances.getJobIdWait().getKey(), instances.getJobIdWait().getValue());
result.put(
instances.getUseFlinkHistoryServer().getKey(),
instances.getUseFlinkHistoryServer().getValue());
result.put(
instances.getFlinkHistoryServerPort().getKey(),
instances.getFlinkHistoryServerPort().getValue());
}
return Result.succeed(result);
}

@Override
public Result<Void> setInitConfig(Map<String, Object> params) {
SystemConfiguration instances = SystemConfiguration.getInstances();
Configuration<Boolean> isFirstSystemIn = instances.getIsFirstSystemIn();

if (!isFirstSystemIn.getValue()) {
return Result.failed("not first init");
}

if (params.containsKey("password")) {
String password = params.remove("password").toString();
if (!TextUtil.isEmpty(password)) {
User admin = userService.getUserByUsername("admin");
admin.setPassword(SaSecureUtil.md5(password));
userService.modifyUser(admin);
}
}

for (Map.Entry<String, Object> entry : params.entrySet()) {
updateSysConfigByKv(entry.getKey(), entry.getValue().toString());
}
updateSysConfigByKv(instances.getIsFirstSystemIn().getKey(), String.valueOf(false));
return Result.succeed();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1088,10 +1088,10 @@ public List<TaskDTO> getUserTasks(Integer userId) {
private Boolean hasTaskOperatePermission(Integer firstLevelOwner, List<Integer> secondLevelOwners) {
boolean isFirstLevelOwner = firstLevelOwner != null && firstLevelOwner == StpUtil.getLoginIdAsInt();
if (TaskOwnerLockStrategyEnum.OWNER.equals(
SystemConfiguration.getInstances().getTaskOwnerLockStrategy())) {
SystemConfiguration.getInstances().GetTaskOwnerLockStrategyValue())) {
return isFirstLevelOwner;
} else if (TaskOwnerLockStrategyEnum.OWNER_AND_MAINTAINER.equals(
SystemConfiguration.getInstances().getTaskOwnerLockStrategy())) {
SystemConfiguration.getInstances().GetTaskOwnerLockStrategyValue())) {
return isFirstLevelOwner
|| (secondLevelOwners != null && secondLevelOwners.contains(StpUtil.getLoginIdAsInt()));
}
Expand Down
2 changes: 2 additions & 0 deletions dinky-common/src/main/java/org/dinky/data/enums/Status.java
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,8 @@ public enum Status {
/**
* system config
*/
SYS_GLOBAL_IS_FIRST(99, "sys.global.isFirst"),

SYS_FLINK_SETTINGS_USERESTAPI(100, "sys.flink.settings.useRestAPI"),
SYS_FLINK_SETTINGS_USERESTAPI_NOTE(101, "sys.flink.settings.useRestAPI.note"),
SYS_FLINK_SETTINGS_JOBIDWAIT(104, "sys.flink.settings.jobIdWait"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ public static Configuration.OptionBuilder key(Status status) {
.map(f -> (Configuration<?>) ReflectUtil.getFieldValue(systemConfiguration, f))
.collect(Collectors.toList());

private final Configuration<Boolean> isFirstSystemIn =
key(Status.SYS_GLOBAL_IS_FIRST).booleanType().defaultValue(true);

private final Configuration<Boolean> useRestAPI = key(Status.SYS_FLINK_SETTINGS_USERESTAPI)
.booleanType()
.defaultValue(true)
Expand Down Expand Up @@ -391,7 +394,7 @@ public boolean isUseRestAPI() {
return Asserts.isNull(useRestAPI.getValue()) ? useRestAPI.getDefaultValue() : useRestAPI.getValue();
}

public int getJobIdWait() {
public int GetJobIdWaitValue() {
return jobIdWait.getValue();
}

Expand Down Expand Up @@ -428,7 +431,7 @@ public OssProperties getOssProperties() {
.build();
}

public TaskOwnerLockStrategyEnum getTaskOwnerLockStrategy() {
public TaskOwnerLockStrategyEnum GetTaskOwnerLockStrategyValue() {
return taskOwnerLockStrategy.getValue();
}

Expand Down
3 changes: 3 additions & 0 deletions dinky-common/src/main/java/org/dinky/utils/I18n.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ public static void setLocale(Locale l) {

public static String getMessage(String key) {
ResourceBundle bundle = ResourceBundle.getBundle(MESSAGES_BASE);
if (!bundle.containsKey(key)) {
return key;
}
String message = bundle.getString(key);
if (!JDK_ABOVE_1_8) {
message = new String(message.getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public KubernetesResult waitForJmAndJobStart(
KubernetesClient kubernetesClient, Deployment deployment, ClusterClientProvider<String> clusterClient)
throws InterruptedException {
KubernetesResult result = KubernetesResult.build(getType());
long waitSends = SystemConfiguration.getInstances().getJobIdWait() * 1000L;
long waitSends = SystemConfiguration.getInstances().GetJobIdWaitValue() * 1000L;
long startTime = System.currentTimeMillis();

while (System.currentTimeMillis() - startTime < waitSends) {
Expand Down Expand Up @@ -262,7 +262,7 @@ public KubernetesResult waitForJmAndJobStartByIngress(
KubernetesClient kubernetesClient, Deployment deployment, ClusterClientProvider<String> clusterClient)
throws InterruptedException {
KubernetesResult result = KubernetesResult.build(getType());
long waitSends = SystemConfiguration.getInstances().getJobIdWait() * 1000L;
long waitSends = SystemConfiguration.getInstances().GetJobIdWaitValue() * 1000L;
long startTime = System.currentTimeMillis();

while (System.currentTimeMillis() - startTime < waitSends) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ protected YarnClusterDescriptor createInitYarnClusterDescriptor() {
protected String getWebUrl(ClusterClient<ApplicationId> clusterClient, YarnResult result)
throws YarnException, IOException, InterruptedException {
String webUrl;
int counts = SystemConfiguration.getInstances().getJobIdWait();
int counts = SystemConfiguration.getInstances().GetJobIdWaitValue();
while (yarnClient.getApplicationReport(clusterClient.getClusterId()).getYarnApplicationState()
== YarnApplicationState.ACCEPTED
&& counts-- > 0) {
Expand Down
6 changes: 6 additions & 0 deletions dinky-web/config/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
* todo: 如何引入自定义 icon
*/
export default [
{
path: '/welcom',
component: './Other/Welcom',
layout: false,
hideInMenu: true
},
{
path: '/user',
layout: false,
Expand Down
Loading

0 comments on commit 9d5b22d

Please sign in to comment.