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