Unverified Commit 824c28f6 authored by ZackYoung's avatar ZackYoung Committed by GitHub

[Refactor][admin]Refactor system settings, include python env and ds into system…

[Refactor][admin]Refactor system settings, include python env and ds into system settings respectively (#2002)
parent 1c5b198d
...@@ -49,6 +49,7 @@ public class Dinky { ...@@ -49,6 +49,7 @@ public class Dinky {
ConfigurableApplicationContext application = app.run(args); ConfigurableApplicationContext application = app.run(args);
Environment env = application.getEnvironment(); Environment env = application.getEnvironment();
String port = env.getProperty("server.port"); String port = env.getProperty("server.port");
System.setProperty("dinkyAddr", ipAddress + ":" + port);
log.info( log.info(
"\n----------------------------------------------------------\n\t" "\n----------------------------------------------------------\n\t"
+ "Application 'Dinky' is running! Access URLs:\n\t" + "Application 'Dinky' is running! Access URLs:\n\t"
......
...@@ -22,9 +22,9 @@ package org.dinky.controller; ...@@ -22,9 +22,9 @@ package org.dinky.controller;
import org.dinky.common.result.Result; import org.dinky.common.result.Result;
import org.dinky.init.SystemInit; import org.dinky.init.SystemInit;
import org.dinky.model.Catalogue; import org.dinky.model.Catalogue;
import org.dinky.model.SystemConfiguration;
import org.dinky.scheduler.client.ProcessClient; import org.dinky.scheduler.client.ProcessClient;
import org.dinky.scheduler.client.TaskClient; import org.dinky.scheduler.client.TaskClient;
import org.dinky.scheduler.config.DolphinSchedulerProperties;
import org.dinky.scheduler.enums.ReleaseState; import org.dinky.scheduler.enums.ReleaseState;
import org.dinky.scheduler.exception.SchedulerException; import org.dinky.scheduler.exception.SchedulerException;
import org.dinky.scheduler.model.DagData; import org.dinky.scheduler.model.DagData;
...@@ -68,7 +68,6 @@ import lombok.RequiredArgsConstructor; ...@@ -68,7 +68,6 @@ import lombok.RequiredArgsConstructor;
@RequiredArgsConstructor @RequiredArgsConstructor
public class SchedulerController { public class SchedulerController {
private final DolphinSchedulerProperties dolphinSchedulerProperties;
private final ProcessClient processClient; private final ProcessClient processClient;
private final TaskClient taskClient; private final TaskClient taskClient;
private final CatalogueService catalogueService; private final CatalogueService catalogueService;
...@@ -155,7 +154,7 @@ public class SchedulerController { ...@@ -155,7 +154,7 @@ public class SchedulerController {
@Valid @RequestBody TaskRequest taskRequest) { @Valid @RequestBody TaskRequest taskRequest) {
DinkyTaskParams dinkyTaskParams = new DinkyTaskParams(); DinkyTaskParams dinkyTaskParams = new DinkyTaskParams();
dinkyTaskParams.setTaskId(dinkyTaskId.toString()); dinkyTaskParams.setTaskId(dinkyTaskId.toString());
dinkyTaskParams.setAddress(dolphinSchedulerProperties.getAddress()); dinkyTaskParams.setAddress(SystemConfiguration.getInstances().getDinkyAddr().getValue());
taskRequest.setTaskParams(JSONUtil.parseObj(dinkyTaskParams).toString()); taskRequest.setTaskParams(JSONUtil.parseObj(dinkyTaskParams).toString());
taskRequest.setTaskType("DINKY"); taskRequest.setTaskType("DINKY");
......
...@@ -21,6 +21,7 @@ package org.dinky.controller; ...@@ -21,6 +21,7 @@ package org.dinky.controller;
import org.dinky.common.result.ProTableResult; import org.dinky.common.result.ProTableResult;
import org.dinky.common.result.Result; import org.dinky.common.result.Result;
import org.dinky.model.Configuration;
import org.dinky.model.SysConfig; import org.dinky.model.SysConfig;
import org.dinky.service.SysConfigService; import org.dinky.service.SysConfigService;
...@@ -100,7 +101,7 @@ public class SysConfigController { ...@@ -100,7 +101,7 @@ public class SysConfigController {
/** 获取所有配置 */ /** 获取所有配置 */
@GetMapping("/getAll") @GetMapping("/getAll")
public Result<Map<String, Object>> getAll() { public Result<Map<String, List<Configuration<?>>>> getAll() {
return Result.succeed(sysConfigService.getAll(), "获取成功"); return Result.succeed(sysConfigService.getAll(), "获取成功");
} }
......
...@@ -27,9 +27,9 @@ import org.dinky.function.constant.PathConstant; ...@@ -27,9 +27,9 @@ import org.dinky.function.constant.PathConstant;
import org.dinky.function.pool.UdfCodePool; import org.dinky.function.pool.UdfCodePool;
import org.dinky.job.FlinkJobTask; import org.dinky.job.FlinkJobTask;
import org.dinky.model.JobInstance; import org.dinky.model.JobInstance;
import org.dinky.model.SystemConfiguration;
import org.dinky.model.Tenant; import org.dinky.model.Tenant;
import org.dinky.scheduler.client.ProjectClient; import org.dinky.scheduler.client.ProjectClient;
import org.dinky.scheduler.config.DolphinSchedulerProperties;
import org.dinky.scheduler.exception.SchedulerException; import org.dinky.scheduler.exception.SchedulerException;
import org.dinky.scheduler.model.Project; import org.dinky.scheduler.model.Project;
import org.dinky.service.GitProjectService; import org.dinky.service.GitProjectService;
...@@ -72,7 +72,6 @@ public class SystemInit implements ApplicationRunner { ...@@ -72,7 +72,6 @@ public class SystemInit implements ApplicationRunner {
private final JobInstanceService jobInstanceService; private final JobInstanceService jobInstanceService;
private final TaskService taskService; private final TaskService taskService;
private final TenantService tenantService; private final TenantService tenantService;
private final DolphinSchedulerProperties dolphinSchedulerProperties;
private final GitProjectService gitProjectService; private final GitProjectService gitProjectService;
private static Project project; private static Project project;
...@@ -102,7 +101,11 @@ public class SystemInit implements ApplicationRunner { ...@@ -102,7 +101,11 @@ public class SystemInit implements ApplicationRunner {
/** init DolphinScheduler */ /** init DolphinScheduler */
private void initDolphinScheduler() { private void initDolphinScheduler() {
if (dolphinSchedulerProperties.isEnabled()) { SystemConfiguration systemConfiguration = SystemConfiguration.getInstances();
systemConfiguration.setInitMethod(
c -> {
if (c == systemConfiguration.getDolphinschedulerEnable()) {
if (systemConfiguration.getDolphinschedulerEnable().getValue()) {
try { try {
project = projectClient.getDinkyProject(); project = projectClient.getDinkyProject();
if (Asserts.isNull(project)) { if (Asserts.isNull(project)) {
...@@ -113,6 +116,8 @@ public class SystemInit implements ApplicationRunner { ...@@ -113,6 +116,8 @@ public class SystemInit implements ApplicationRunner {
} }
} }
} }
});
}
/** /**
* get dolphinscheduler's project * get dolphinscheduler's project
......
...@@ -20,8 +20,10 @@ ...@@ -20,8 +20,10 @@
package org.dinky.service; package org.dinky.service;
import org.dinky.db.service.ISuperService; import org.dinky.db.service.ISuperService;
import org.dinky.model.Configuration;
import org.dinky.model.SysConfig; import org.dinky.model.SysConfig;
import java.util.List;
import java.util.Map; import java.util.Map;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
...@@ -33,7 +35,7 @@ import com.fasterxml.jackson.databind.JsonNode; ...@@ -33,7 +35,7 @@ import com.fasterxml.jackson.databind.JsonNode;
*/ */
public interface SysConfigService extends ISuperService<SysConfig> { public interface SysConfigService extends ISuperService<SysConfig> {
Map<String, Object> getAll(); Map<String, List<Configuration<?>>> getAll();
void initSysConfig(); void initSysConfig();
......
...@@ -22,14 +22,15 @@ package org.dinky.service.impl; ...@@ -22,14 +22,15 @@ package org.dinky.service.impl;
import org.dinky.assertion.Asserts; import org.dinky.assertion.Asserts;
import org.dinky.db.service.impl.SuperServiceImpl; import org.dinky.db.service.impl.SuperServiceImpl;
import org.dinky.mapper.SysConfigMapper; import org.dinky.mapper.SysConfigMapper;
import org.dinky.model.Configuration;
import org.dinky.model.SysConfig; import org.dinky.model.SysConfig;
import org.dinky.model.SystemConfiguration; import org.dinky.model.SystemConfiguration;
import org.dinky.service.SysConfigService; import org.dinky.service.SysConfigService;
import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -49,19 +50,19 @@ public class SysConfigServiceImpl extends SuperServiceImpl<SysConfigMapper, SysC ...@@ -49,19 +50,19 @@ public class SysConfigServiceImpl extends SuperServiceImpl<SysConfigMapper, SysC
private static final ObjectMapper mapper = new ObjectMapper(); private static final ObjectMapper mapper = new ObjectMapper();
@Override @Override
public Map<String, Object> getAll() { public Map<String, List<Configuration<?>>> getAll() {
Map<String, Object> map = new HashMap<>(); return SystemConfiguration.getInstances().addConfiguration();
List<SysConfig> sysConfigs = list();
for (SysConfig item : sysConfigs) {
map.put(item.getName(), item.getValue());
}
SystemConfiguration.getInstances().addConfiguration(map);
return map;
} }
@Override @Override
public void initSysConfig() { public void initSysConfig() {
SystemConfiguration.getInstances().setConfiguration(mapper.valueToTree(getAll())); SystemConfiguration.getInstances()
.setConfiguration(
mapper.valueToTree(
list().stream()
.collect(
Collectors.toMap(
SysConfig::getName, SysConfig::getValue))));
} }
@Override @Override
......
...@@ -20,9 +20,9 @@ ...@@ -20,9 +20,9 @@
package org.dinky.sse.git; package org.dinky.sse.git;
import org.dinky.dto.GitAnalysisJarDTO; import org.dinky.dto.GitAnalysisJarDTO;
import org.dinky.function.data.model.Env;
import org.dinky.function.util.UDFUtil; import org.dinky.function.util.UDFUtil;
import org.dinky.model.GitProject; import org.dinky.model.GitProject;
import org.dinky.model.SystemConfiguration;
import org.dinky.sse.StepSse; import org.dinky.sse.StepSse;
import java.io.File; import java.io.File;
...@@ -54,7 +54,9 @@ public class AnalysisUdfPythonStepSse extends StepSse { ...@@ -54,7 +54,9 @@ public class AnalysisUdfPythonStepSse extends StepSse {
File zipFile = (File) params.get("zipFile"); File zipFile = (File) params.get("zipFile");
File projectFile = (File) params.get("projectFile"); File projectFile = (File) params.get("projectFile");
List<String> pythonUdfList = List<String> pythonUdfList =
UDFUtil.getPythonUdfList(Env.getPath(), projectFile.getAbsolutePath()); UDFUtil.getPythonUdfList(
SystemConfiguration.getInstances().getPythonHome(),
projectFile.getAbsolutePath());
GitAnalysisJarDTO gitAnalysisJarDTO = new GitAnalysisJarDTO(); GitAnalysisJarDTO gitAnalysisJarDTO = new GitAnalysisJarDTO();
gitAnalysisJarDTO.setJarPath(zipFile.getAbsolutePath()); gitAnalysisJarDTO.setJarPath(zipFile.getAbsolutePath());
gitAnalysisJarDTO.setClassList(pythonUdfList); gitAnalysisJarDTO.setClassList(pythonUdfList);
......
...@@ -15,7 +15,7 @@ spring: ...@@ -15,7 +15,7 @@ spring:
# If you use pgsql database, please configure pgsql database connection information in application-pgsql.yml # If you use pgsql database, please configure pgsql database connection information in application-pgsql.yml
# If you use the h2 database, please configure the h2 database connection information in application-h2.yml, # If you use the h2 database, please configure the h2 database connection information in application-h2.yml,
# note: the h2 database is only for experience use, and the related data that has been created cannot be migrated, please use it with caution # note: the h2 database is only for experience use, and the related data that has been created cannot be migrated, please use it with caution
active: h2 #[h2,mysql,pgsql] active: mysql #[h2,mysql,pgsql]
# mvc config # mvc config
mvc: mvc:
...@@ -149,24 +149,20 @@ sa-token: ...@@ -149,24 +149,20 @@ sa-token:
knife4j: knife4j:
enable: true enable: true
################################################################################################################# ##################################################################################################################
################################################# DolphinScheduler Config ####################################### ################################################## DolphinScheduler Config #######################################
################################################################################################################# ##################################################################################################################
dinky: #dinky:
dolphinscheduler: # dolphinscheduler:
# If you enable the integrated DolphinScheduler, you need to configure the following configuration items # # If you enable the integrated DolphinScheduler, you need to configure the following configuration items
enabled: false # enabled: false
# DolphinScheduler Address # # DolphinScheduler Address
# Note: The address must be the same as the address configured in the DolphinScheduler background , eg: http://127.0.0.1:12345/dolphinscheduler # # Note: The address must be the same as the address configured in the DolphinScheduler background , eg: http://127.0.0.1:12345/dolphinscheduler
url: http://127.0.0.1:5173/dolphinscheduler # url: http://127.0.0.1:5173/dolphinscheduler
# DolphinScheduler's Token , Please create a token in DolphinScheduler's Security Center -> Token Management, and modify the following configuration # # DolphinScheduler's Token , Please create a token in DolphinScheduler's Security Center -> Token Management, and modify the following configuration
token: ad54eb8f57fadea95f52763517978b26 # token: ad54eb8f57fadea95f52763517978b26
# The project name specified in DolphinScheduler, case insensitive # # The project name specified in DolphinScheduler, case insensitive
project-name: Dinky # project-name: Dinky
# DolphinScheduler DinkyTask Address , eg: http://127.0.0.1:8888 # # DolphinScheduler DinkyTask Address , eg: http://127.0.0.1:8888
# note: the address must be the same as the address configured in the Dinky Application background url # # note: the address must be the same as the address configured in the Dinky Application background url
address: http://127.0.0.1:8888 # address: http://127.0.0.1:8888
# The python execution environment needed by python udf
python:
path: python
/*
*
* 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.dinky.model;
import java.util.Date;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonIgnore;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.Assert;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
public class Configuration<T> {
private final String key;
@JsonIgnore private final transient Class<T> type;
private final String frontType;
private String note;
private final T defaultValue;
private T value;
private static final List<Class<?>> NUMBER_LIST =
CollUtil.newArrayList(Double.class, Float.class, Integer.class);
public Configuration<T> note(String note) {
this.note = note;
return this;
}
public void setValue(Object value) {
this.value = type.isInstance(value) ? (T) value : Convert.convert(getType(), value);
}
public Configuration(String key, Class<T> type, String note, T defaultValue) {
this.key = key;
this.type = type;
this.note = note;
this.defaultValue = defaultValue;
if (type.equals(String.class)) {
this.frontType = "string";
} else if (type.equals(Boolean.class)) {
this.frontType = "boolean";
} else if (type.equals(Date.class)) {
this.frontType = "date";
} else if (NUMBER_LIST.contains(type)) {
this.frontType = "number";
} else {
this.frontType = type.getSimpleName();
}
}
@AllArgsConstructor
public static class ValueType<T> {
private final String key;
private final Class<T> clazz;
public Configuration<T> defaultValue(T value) {
return new Configuration<>(key, clazz, "", value);
}
}
public static OptionBuilder key(String key) {
Assert.notNull(key);
return new OptionBuilder(key);
}
public static class OptionBuilder {
private final String key;
public OptionBuilder(String key) {
this.key = key;
}
public ValueType<Boolean> booleanType() {
return new ValueType<>(key, Boolean.class);
}
public ValueType<Integer> intType() {
return new ValueType<>(key, Integer.class);
}
public ValueType<Double> doubleType() {
return new ValueType<>(key, Double.class);
}
public ValueType<Float> floatType() {
return new ValueType<>(key, Float.class);
}
public ValueType<String> stringType() {
return new ValueType<>(key, String.class);
}
public ValueType<Date> dateType() {
return new ValueType<>(key, Date.class);
}
}
}
...@@ -19,203 +19,187 @@ ...@@ -19,203 +19,187 @@
package org.dinky.model; package org.dinky.model;
import org.dinky.assertion.Asserts; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.TreeMap;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.collect.Lists;
import cn.hutool.core.lang.Opt;
import cn.hutool.core.util.ReflectUtil;
import cn.hutool.core.util.StrUtil;
import lombok.Getter;
/** /**
* SystemConfiguration * SystemConfiguration
* *
* @since 2021/11/18 * @since 2021/11/18
*/ */
@Getter
public class SystemConfiguration { public class SystemConfiguration {
private static volatile SystemConfiguration systemConfiguration = new SystemConfiguration(); private static final SystemConfiguration systemConfiguration = new SystemConfiguration();
public static SystemConfiguration getInstances() { public static SystemConfiguration getInstances() {
return systemConfiguration; return systemConfiguration;
} }
private static final List<Configuration> CONFIGURATION_LIST = private Consumer<Configuration<?>> initMethod = null;
Lists.newArrayList(
systemConfiguration.useRestAPI, public static Configuration.OptionBuilder key(String key) {
systemConfiguration.sqlSeparator, return new Configuration.OptionBuilder(key);
systemConfiguration.jobIdWait, }
systemConfiguration.mavenSettings,
systemConfiguration.mavenRepository, private static final List<Configuration<?>> CONFIGURATION_LIST =
systemConfiguration.mavenRepositoryUser, Arrays.stream(
systemConfiguration.mavenRepositoryPassword); ReflectUtil.getFields(
SystemConfiguration.class,
private Configuration useRestAPI = f -> f.getType() == Configuration.class))
new Configuration( .map(f -> (Configuration<?>) ReflectUtil.getFieldValue(systemConfiguration, f))
"useRestAPI", .collect(Collectors.toList());
"使用 RestAPI",
ValueType.BOOLEAN, private Configuration<Boolean> useRestAPI =
true, key("flink.settings.useRestAPI")
"在运维 Flink 任务时是否使用 RestAPI"); .booleanType()
private Configuration sqlSeparator = .defaultValue(true)
new Configuration( .note("在运维 Flink 任务时是否使用 RestAPI");
"sqlSeparator", "FlinkSQL语句分割符", ValueType.STRING, ";\n", "Flink SQL 的语句分割符"); private Configuration<String> sqlSeparator =
private Configuration jobIdWait = key("flink.settings.sqlSeparator")
new Configuration( .stringType()
"jobIdWait", .defaultValue(";\n")
"获取 Job ID 的最大等待时间(秒)", .note("FlinkSQL语句分割符");
ValueType.INT, private Configuration<Integer> jobIdWait =
30, key("flink.settings.jobIdWait")
"提交 Application 或 PerJob 任务时获取 Job ID 的最大等待时间(秒)"); .intType()
.defaultValue(30)
private Configuration mavenSettings = .note("提交 Application 或 PerJob 任务时获取 Job ID 的最大等待时间(秒)");
new Configuration(
"mavenSettings", private Configuration<String> mavenSettings =
"Maven Settings 文件路径", key("maven.settings.settingsFilePath")
ValueType.STRING, .stringType()
"", .defaultValue("")
"Maven Settings File Path"); .note("Maven Settings 文件路径");
private Configuration mavenRepository = private Configuration<String> mavenRepository =
new Configuration( key("maven.settings.repository")
"mavenRepository", .stringType()
"Maven Central Repository", .defaultValue("https://maven.aliyun.com/nexus/content/repositories/central")
ValueType.STRING, .note("Maven private server address");
"https://maven.aliyun.com/nexus/content/repositories/central",
"Maven private server address"); private Configuration<String> mavenRepositoryUser =
key("maven.settings.repositoryUser")
private Configuration mavenRepositoryUser = .stringType()
new Configuration( .defaultValue("")
"mavenRepositoryUser", .note("Maven private server authentication username");
"Maven Central Repository Auth User",
ValueType.STRING, private Configuration<String> mavenRepositoryPassword =
"", key("maven.settings.repositoryUser")
"Maven private server authentication username"); .stringType()
.defaultValue("")
private Configuration mavenRepositoryPassword = .note("Maven Central Repository Auth Password");
new Configuration(
"mavenRepositoryPassword", private Configuration<String> pythonHome =
"Maven Central Repository Auth Password", key("env.settings.pythonHome").stringType().defaultValue("python3").note("PYTHON HOME");
ValueType.STRING,
"", private Configuration<String> dinkyAddr =
"Maven private server authentication password"); key("env.settings.dinkyAddr")
.stringType()
.defaultValue(System.getProperty("dinkyAddr"))
.note(
"the address must be the same as the address configured in the Dinky Application background url");
private Configuration<Boolean> dolphinschedulerEnable =
key("dolphinscheduler.settings.enable")
.booleanType()
.defaultValue(false)
.note("Dolphinscheduler ON-OFF");
private Configuration<String> dolphinschedulerUrl =
key("dolphinscheduler.settings.url")
.stringType()
.defaultValue("")
.note(
"The address must be the same as the address configured in the DolphinScheduler background , eg: http://127.0.0.1:12345/dolphinscheduler");
private Configuration<String> dolphinschedulerToken =
key("dolphinscheduler.settings.token")
.stringType()
.defaultValue("")
.note(
"DolphinScheduler's Token , Please create a token in DolphinScheduler's Security Center -> Token Management, and modify the following configuration");
private Configuration<String> dolphinschedulerProjectName =
key("dolphinscheduler.settings.projectName")
.stringType()
.defaultValue("Dinky")
.note("The project name specified in DolphinScheduler, case insensitive");
public void setConfiguration(JsonNode jsonNode) { public void setConfiguration(JsonNode jsonNode) {
CONFIGURATION_LIST.stream() CONFIGURATION_LIST.forEach(
.filter(t -> jsonNode.has(t.getName()))
.forEach(
item -> { item -> {
final JsonNode value = jsonNode.get(item.getName()); final JsonNode value = jsonNode.get(item.getKey());
switch (item.getType()) { if (value == null || value.isNull()) {
case BOOLEAN: item.setValue(item.getDefaultValue());
item.setValue(value.asBoolean()); return;
break;
case INT:
item.setValue(value.asInt());
break;
default:
item.setValue(value.asText());
} }
item.setValue(value);
});
// initRun
CONFIGURATION_LIST.forEach(
c -> Opt.ofNullable(this.initMethod).ifPresent(x -> x.accept(c)));
}
public Map<String, List<Configuration<?>>> addConfiguration() {
Map<String, List<Configuration<?>>> data = new TreeMap<>();
for (Configuration<?> item : CONFIGURATION_LIST) {
final String name = item.getKey();
String k = StrUtil.split(name, ".").get(0);
Opt.ofBlankAble(k)
.ifPresent(
key -> {
data.computeIfAbsent(k, x -> new ArrayList<>());
data.get(k).add(item);
}); });
} }
return data;
public void addConfiguration(Map<String, Object> map) {
for (Configuration item : CONFIGURATION_LIST) {
final String name = item.getName();
if (!map.containsKey(name)) {
map.put(name, item.getValue());
continue;
} }
if (item.getType().equals(ValueType.BOOLEAN)) { public void setInitMethod(Consumer<Configuration<?>> initMethod) {
map.put(name, Asserts.isEqualsIgnoreCase("true", map.get(name).toString())); this.initMethod = initMethod;
}
}
} }
public boolean isUseRestAPI() { public boolean isUseRestAPI() {
return (boolean) useRestAPI.getValue(); return useRestAPI.getValue();
}
public void setUseRestAPI(boolean useRestAPI) {
this.useRestAPI.setValue(useRestAPI);
} }
public String getSqlSeparator() { public String getSqlSeparator() {
return sqlSeparator.getValue().toString(); return sqlSeparator.getValue();
}
public void setSqlSeparator(String sqlSeparator) {
this.sqlSeparator.setValue(sqlSeparator);
} }
public int getJobIdWait() { public int getJobIdWait() {
return (int) jobIdWait.getValue(); return jobIdWait.getValue();
}
public void setJobIdWait(Configuration jobIdWait) {
this.jobIdWait.setValue(jobIdWait);
} }
public String getMavenSettings() { public String getMavenSettings() {
return (String) mavenSettings.getValue();
return mavenSettings.getValue();
} }
public String getMavenRepository() { public String getMavenRepository() {
return (String) mavenRepository.getValue(); return mavenRepository.getValue();
} }
public String getMavenRepositoryUser() { public String getMavenRepositoryUser() {
return (String) mavenRepositoryUser.getValue(); return mavenRepositoryUser.getValue();
} }
public String getMavenRepositoryPassword() { public String getMavenRepositoryPassword() {
return (String) mavenRepositoryPassword.getValue(); return mavenRepositoryPassword.getValue();
} }
enum ValueType { public String getPythonHome() {
STRING, return pythonHome.getValue();
INT,
DOUBLE,
FLOAT,
BOOLEAN,
DATE
}
public class Configuration {
private final String label;
private final Object defaultValue;
private final String note;
private String name;
private ValueType type;
private Object value;
public Configuration(
String name, String label, ValueType type, Object defaultValue, String note) {
this.name = name;
this.label = label;
this.type = type;
this.defaultValue = defaultValue;
this.value = defaultValue;
this.note = note;
}
public void setValue(Object value) {
this.value = value;
}
public Object getValue() {
return value;
}
public ValueType getType() {
return type;
}
public String getName() {
return name;
}
} }
} }
...@@ -35,7 +35,6 @@ import org.dinky.executor.Executor; ...@@ -35,7 +35,6 @@ import org.dinky.executor.Executor;
import org.dinky.executor.ExecutorSetting; import org.dinky.executor.ExecutorSetting;
import org.dinky.explainer.Explainer; import org.dinky.explainer.Explainer;
import org.dinky.function.constant.PathConstant; import org.dinky.function.constant.PathConstant;
import org.dinky.function.data.model.Env;
import org.dinky.function.data.model.UDF; import org.dinky.function.data.model.UDF;
import org.dinky.function.util.UDFUtil; import org.dinky.function.util.UDFUtil;
import org.dinky.gateway.Gateway; import org.dinky.gateway.Gateway;
...@@ -339,7 +338,7 @@ public class JobManager { ...@@ -339,7 +338,7 @@ public class JobManager {
Set<File> pyUdfFile = FlinkUdfPathContextHolder.getPyUdfFile(); Set<File> pyUdfFile = FlinkUdfPathContextHolder.getPyUdfFile();
executor.initPyUDF( executor.initPyUDF(
Env.getPath(), SystemConfiguration.getInstances().getPythonHome(),
pyUdfFile.stream().map(File::getAbsolutePath).toArray(String[]::new)); pyUdfFile.stream().map(File::getAbsolutePath).toArray(String[]::new));
if (GATEWAY_TYPE_MAP.get(YARN).contains(runMode)) { if (GATEWAY_TYPE_MAP.get(YARN).contains(runMode)) {
config.getGatewayConfig().setJarPaths(ArrayUtil.append(jarPaths, pyPaths)); config.getGatewayConfig().setJarPaths(ArrayUtil.append(jarPaths, pyPaths));
......
...@@ -21,10 +21,10 @@ package org.dinky.function.compiler; ...@@ -21,10 +21,10 @@ package org.dinky.function.compiler;
import org.dinky.assertion.Asserts; import org.dinky.assertion.Asserts;
import org.dinky.function.constant.PathConstant; import org.dinky.function.constant.PathConstant;
import org.dinky.function.data.model.Env;
import org.dinky.function.data.model.UDF; import org.dinky.function.data.model.UDF;
import org.dinky.function.util.UDFUtil; import org.dinky.function.util.UDFUtil;
import org.dinky.function.util.ZipWriter; import org.dinky.function.util.ZipWriter;
import org.dinky.model.SystemConfiguration;
import org.dinky.process.context.ProcessContextHolder; import org.dinky.process.context.ProcessContextHolder;
import org.dinky.process.model.ProcessEntity; import org.dinky.process.model.ProcessEntity;
...@@ -79,8 +79,12 @@ public class PythonFunction implements FunctionCompiler, FunctionPackage { ...@@ -79,8 +79,12 @@ public class PythonFunction implements FunctionCompiler, FunctionPackage {
try { try {
Configuration configuration = new Configuration((Configuration) conf); Configuration configuration = new Configuration((Configuration) conf);
configuration.set(PythonOptions.PYTHON_FILES, zipFile.getAbsolutePath()); configuration.set(PythonOptions.PYTHON_FILES, zipFile.getAbsolutePath());
configuration.set(PythonOptions.PYTHON_CLIENT_EXECUTABLE, Env.getPath()); configuration.set(
configuration.set(PythonOptions.PYTHON_EXECUTABLE, Env.getPath()); PythonOptions.PYTHON_CLIENT_EXECUTABLE,
SystemConfiguration.getInstances().getPythonHome());
configuration.set(
PythonOptions.PYTHON_EXECUTABLE,
SystemConfiguration.getInstances().getPythonHome());
PythonFunctionFactory.getPythonFunction(udf.getClassName(), configuration, null); PythonFunctionFactory.getPythonFunction(udf.getClassName(), configuration, null);
process.info("Python udf编译成功 ; className:" + udf.getClassName()); process.info("Python udf编译成功 ; className:" + udf.getClassName());
......
/*
*
* 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.dinky.function.data.model;
import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
/** @since 0.6.8 */
@Component
public class Env {
@Value("${dinky.python.path}")
private String path;
private static String PATH;
public static String getPath() {
return PATH;
}
@PostConstruct
public void init() {
PATH = path == null ? "python" : path;
}
}
...@@ -53,6 +53,10 @@ ...@@ -53,6 +53,10 @@
<groupId>com.github.xiaoymin</groupId> <groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId> <artifactId>knife4j-spring-boot-starter</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.dinky</groupId>
<artifactId>dinky-common</artifactId>
</dependency>
<!-- test dependencies --> <!-- test dependencies -->
<dependency> <dependency>
<groupId>org.junit.jupiter</groupId> <groupId>org.junit.jupiter</groupId>
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
package org.dinky.scheduler.client; package org.dinky.scheduler.client;
import org.dinky.scheduler.config.DolphinSchedulerProperties; import org.dinky.model.SystemConfiguration;
import org.dinky.scheduler.constant.Constants; import org.dinky.scheduler.constant.Constants;
import org.dinky.scheduler.model.DagData; import org.dinky.scheduler.model.DagData;
import org.dinky.scheduler.model.ProcessDefinition; import org.dinky.scheduler.model.ProcessDefinition;
...@@ -36,7 +36,6 @@ import java.util.Map; ...@@ -36,7 +36,6 @@ import java.util.Map;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import cn.hutool.core.lang.TypeReference; import cn.hutool.core.lang.TypeReference;
...@@ -50,8 +49,6 @@ public class ProcessClient { ...@@ -50,8 +49,6 @@ public class ProcessClient {
private static final Logger logger = LoggerFactory.getLogger(TaskClient.class); private static final Logger logger = LoggerFactory.getLogger(TaskClient.class);
@Autowired private DolphinSchedulerProperties dolphinSchedulerProperties;
/** /**
* 查询工作流定义 * 查询工作流定义
* *
...@@ -62,15 +59,20 @@ public class ProcessClient { ...@@ -62,15 +59,20 @@ public class ProcessClient {
public List<ProcessDefinition> getProcessDefinition(Long projectCode, String processName) { public List<ProcessDefinition> getProcessDefinition(Long projectCode, String processName) {
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
map.put("projectCode", projectCode); map.put("projectCode", projectCode);
String format = String format =
StrUtil.format( StrUtil.format(
dolphinSchedulerProperties.getUrl() SystemConfiguration.getInstances().getDolphinschedulerUrl().getValue()
+ "/projects/{projectCode}/process-definition", + "/projects/{projectCode}/process-definition",
map); map);
String content = String content =
HttpRequest.get(format) HttpRequest.get(format)
.header(Constants.TOKEN, dolphinSchedulerProperties.getToken()) .header(
Constants.TOKEN,
SystemConfiguration.getInstances()
.getDolphinschedulerToken()
.getValue())
.form(ParamUtil.getPageParams(processName)) .form(ParamUtil.getPageParams(processName))
.timeout(5000) .timeout(5000)
.execute() .execute()
...@@ -118,13 +120,17 @@ public class ProcessClient { ...@@ -118,13 +120,17 @@ public class ProcessClient {
map.put("code", processCode); map.put("code", processCode);
String format = String format =
StrUtil.format( StrUtil.format(
dolphinSchedulerProperties.getUrl() SystemConfiguration.getInstances().getDolphinschedulerUrl().getValue()
+ "/projects/{projectCode}/process-definition/{code}", + "/projects/{projectCode}/process-definition/{code}",
map); map);
String content = String content =
HttpRequest.get(format) HttpRequest.get(format)
.header(Constants.TOKEN, dolphinSchedulerProperties.getToken()) .header(
Constants.TOKEN,
SystemConfiguration.getInstances()
.getDolphinschedulerToken()
.getValue())
.timeout(5000) .timeout(5000)
.execute() .execute()
.body(); .body();
...@@ -146,7 +152,7 @@ public class ProcessClient { ...@@ -146,7 +152,7 @@ public class ProcessClient {
map.put("projectCode", projectCode); map.put("projectCode", projectCode);
String format = String format =
StrUtil.format( StrUtil.format(
dolphinSchedulerProperties.getUrl() SystemConfiguration.getInstances().getDolphinschedulerUrl().getValue()
+ "/projects/{projectCode}/process-definition", + "/projects/{projectCode}/process-definition",
map); map);
...@@ -165,7 +171,11 @@ public class ProcessClient { ...@@ -165,7 +171,11 @@ public class ProcessClient {
String content = String content =
HttpRequest.post(format) HttpRequest.post(format)
.header(Constants.TOKEN, dolphinSchedulerProperties.getToken()) .header(
Constants.TOKEN,
SystemConfiguration.getInstances()
.getDolphinschedulerToken()
.getValue())
.form(params) .form(params)
.timeout(5000) .timeout(5000)
.execute() .execute()
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
package org.dinky.scheduler.client; package org.dinky.scheduler.client;
import org.dinky.scheduler.config.DolphinSchedulerProperties; import org.dinky.model.SystemConfiguration;
import org.dinky.scheduler.constant.Constants; import org.dinky.scheduler.constant.Constants;
import org.dinky.scheduler.model.Project; import org.dinky.scheduler.model.Project;
import org.dinky.scheduler.result.Result; import org.dinky.scheduler.result.Result;
...@@ -31,7 +31,6 @@ import java.util.Map; ...@@ -31,7 +31,6 @@ import java.util.Map;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import cn.hutool.core.lang.TypeReference; import cn.hutool.core.lang.TypeReference;
...@@ -43,8 +42,6 @@ public class ProjectClient { ...@@ -43,8 +42,6 @@ public class ProjectClient {
private static final Logger logger = LoggerFactory.getLogger(TaskClient.class); private static final Logger logger = LoggerFactory.getLogger(TaskClient.class);
@Autowired private DolphinSchedulerProperties dolphinSchedulerProperties;
/** /**
* 创建项目 * 创建项目
* *
...@@ -52,12 +49,22 @@ public class ProjectClient { ...@@ -52,12 +49,22 @@ public class ProjectClient {
*/ */
public Project createDinkyProject() { public Project createDinkyProject() {
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
map.put("projectName", dolphinSchedulerProperties.getProjectName()); map.put(
"projectName",
SystemConfiguration.getInstances().getDolphinschedulerProjectName().getValue());
map.put("description", "自动创建"); map.put("description", "自动创建");
String content = String content =
HttpRequest.post(dolphinSchedulerProperties.getUrl() + "/projects") HttpRequest.post(
.header(Constants.TOKEN, dolphinSchedulerProperties.getToken()) SystemConfiguration.getInstances()
.getDolphinschedulerUrl()
.getValue()
+ "/projects")
.header(
Constants.TOKEN,
SystemConfiguration.getInstances()
.getDolphinschedulerToken()
.getValue())
.form(map) .form(map)
.timeout(5000) .timeout(5000)
.execute() .execute()
...@@ -74,14 +81,28 @@ public class ProjectClient { ...@@ -74,14 +81,28 @@ public class ProjectClient {
public Project getDinkyProject() { public Project getDinkyProject() {
String content = String content =
HttpRequest.get(dolphinSchedulerProperties.getUrl() + "/projects") HttpRequest.get(
.header(Constants.TOKEN, dolphinSchedulerProperties.getToken()) SystemConfiguration.getInstances()
.form(ParamUtil.getPageParams(dolphinSchedulerProperties.getProjectName())) .getDolphinschedulerUrl()
.getValue()
+ "/projects")
.header(
Constants.TOKEN,
SystemConfiguration.getInstances()
.getDolphinschedulerToken()
.getValue())
.form(
ParamUtil.getPageParams(
SystemConfiguration.getInstances()
.getDolphinschedulerProjectName()
.getValue()))
.timeout(5000) .timeout(5000)
.execute() .execute()
.body(); .body();
return MyJSONUtil.toPageBeanAndFindByName( return MyJSONUtil.toPageBeanAndFindByName(
content, dolphinSchedulerProperties.getProjectName(), Project.class); content,
SystemConfiguration.getInstances().getDolphinschedulerProjectName().getValue(),
Project.class);
} }
} }
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
package org.dinky.scheduler.client; package org.dinky.scheduler.client;
import org.dinky.scheduler.config.DolphinSchedulerProperties; import org.dinky.model.SystemConfiguration;
import org.dinky.scheduler.constant.Constants; import org.dinky.scheduler.constant.Constants;
import org.dinky.scheduler.exception.SchedulerException; import org.dinky.scheduler.exception.SchedulerException;
import org.dinky.scheduler.model.TaskDefinition; import org.dinky.scheduler.model.TaskDefinition;
...@@ -39,7 +39,6 @@ import java.util.Map; ...@@ -39,7 +39,6 @@ import java.util.Map;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import cn.hutool.core.lang.TypeReference; import cn.hutool.core.lang.TypeReference;
...@@ -53,8 +52,6 @@ public class TaskClient { ...@@ -53,8 +52,6 @@ public class TaskClient {
private static final Logger logger = LoggerFactory.getLogger(TaskClient.class); private static final Logger logger = LoggerFactory.getLogger(TaskClient.class);
@Autowired private DolphinSchedulerProperties dolphinSchedulerProperties;
/** /**
* 查询任务定义 * 查询任务定义
* *
...@@ -87,7 +84,7 @@ public class TaskClient { ...@@ -87,7 +84,7 @@ public class TaskClient {
map.put("projectCode", projectCode); map.put("projectCode", projectCode);
String format = String format =
StrUtil.format( StrUtil.format(
dolphinSchedulerProperties.getUrl() SystemConfiguration.getInstances().getDolphinschedulerUrl().getValue()
+ "/projects/{projectCode}/task-definition", + "/projects/{projectCode}/task-definition",
map); map);
...@@ -98,7 +95,11 @@ public class TaskClient { ...@@ -98,7 +95,11 @@ public class TaskClient {
String content = String content =
HttpRequest.get(format) HttpRequest.get(format)
.header(Constants.TOKEN, dolphinSchedulerProperties.getToken()) .header(
Constants.TOKEN,
SystemConfiguration.getInstances()
.getDolphinschedulerToken()
.getValue())
.form(pageParams) .form(pageParams)
.timeout(5000) .timeout(5000)
.execute() .execute()
...@@ -131,13 +132,17 @@ public class TaskClient { ...@@ -131,13 +132,17 @@ public class TaskClient {
map.put("code", taskCode); map.put("code", taskCode);
String format = String format =
StrUtil.format( StrUtil.format(
dolphinSchedulerProperties.getUrl() SystemConfiguration.getInstances().getDolphinschedulerUrl().getValue()
+ "/projects/{projectCode}/task-definition/{code}", + "/projects/{projectCode}/task-definition/{code}",
map); map);
String content = String content =
HttpRequest.get(format) HttpRequest.get(format)
.header(Constants.TOKEN, dolphinSchedulerProperties.getToken()) .header(
Constants.TOKEN,
SystemConfiguration.getInstances()
.getDolphinschedulerToken()
.getValue())
.timeout(5000) .timeout(5000)
.execute() .execute()
.body(); .body();
...@@ -162,7 +167,7 @@ public class TaskClient { ...@@ -162,7 +167,7 @@ public class TaskClient {
map.put("projectCode", projectCode); map.put("projectCode", projectCode);
String format = String format =
StrUtil.format( StrUtil.format(
dolphinSchedulerProperties.getUrl() SystemConfiguration.getInstances().getDolphinschedulerUrl().getValue()
+ "/projects/{projectCode}/task-definition/save-single", + "/projects/{projectCode}/task-definition/save-single",
map); map);
...@@ -176,7 +181,11 @@ public class TaskClient { ...@@ -176,7 +181,11 @@ public class TaskClient {
String content = String content =
HttpRequest.post(format) HttpRequest.post(format)
.header(Constants.TOKEN, dolphinSchedulerProperties.getToken()) .header(
Constants.TOKEN,
SystemConfiguration.getInstances()
.getDolphinschedulerToken()
.getValue())
.form(pageParams) .form(pageParams)
.timeout(5000) .timeout(5000)
.execute() .execute()
...@@ -201,7 +210,7 @@ public class TaskClient { ...@@ -201,7 +210,7 @@ public class TaskClient {
map.put("code", taskCode); map.put("code", taskCode);
String format = String format =
StrUtil.format( StrUtil.format(
dolphinSchedulerProperties.getUrl() SystemConfiguration.getInstances().getDolphinschedulerUrl().getValue()
+ "/projects/{projectCode}/task-definition/{code}/with-upstream", + "/projects/{projectCode}/task-definition/{code}/with-upstream",
map); map);
...@@ -211,7 +220,11 @@ public class TaskClient { ...@@ -211,7 +220,11 @@ public class TaskClient {
String content = String content =
HttpRequest.put(format) HttpRequest.put(format)
.header(Constants.TOKEN, dolphinSchedulerProperties.getToken()) .header(
Constants.TOKEN,
SystemConfiguration.getInstances()
.getDolphinschedulerToken()
.getValue())
.form(params) .form(params)
.timeout(5000) .timeout(5000)
.execute() .execute()
...@@ -232,14 +245,18 @@ public class TaskClient { ...@@ -232,14 +245,18 @@ public class TaskClient {
map.put("projectCode", projectCode); map.put("projectCode", projectCode);
String format = String format =
StrUtil.format( StrUtil.format(
dolphinSchedulerProperties.getUrl() SystemConfiguration.getInstances().getDolphinschedulerUrl().getValue()
+ "/projects/{projectCode}/task-definition/gen-task-codes", + "/projects/{projectCode}/task-definition/gen-task-codes",
map); map);
Map<String, Object> params = new HashMap<>(); Map<String, Object> params = new HashMap<>();
params.put("genNum", genNum); params.put("genNum", genNum);
String content = String content =
HttpRequest.get(format) HttpRequest.get(format)
.header(Constants.TOKEN, dolphinSchedulerProperties.getToken()) .header(
Constants.TOKEN,
SystemConfiguration.getInstances()
.getDolphinschedulerToken()
.getValue())
.form(params) .form(params)
.timeout(5000) .timeout(5000)
.execute() .execute()
......
/*
*
* 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.dinky.scheduler.config;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import lombok.Data;
/**
* DolphinSchedulerProperties
*
* @since 2022/9/25 12:57
*/
@Data
@Component
@ConfigurationProperties(prefix = "dinky.dolphinscheduler")
public class DolphinSchedulerProperties {
private boolean enabled;
private String url;
private String token;
private String projectName;
private String address;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment