Unverified Commit cc00f4d6 authored by zhu-mingye's avatar zhu-mingye Committed by GitHub

[Refactor][admin] delete un use code (#2473)

* delete un use code * delete un use code * delete un use code
parent e506a272
...@@ -21,7 +21,6 @@ package org.dinky.assertion; ...@@ -21,7 +21,6 @@ package org.dinky.assertion;
import org.dinky.data.exception.BusException; import org.dinky.data.exception.BusException;
import org.dinky.data.model.ClusterInstance; import org.dinky.data.model.ClusterInstance;
import org.dinky.data.model.Jar;
import org.dinky.data.model.Task; import org.dinky.data.model.Task;
/** /**
...@@ -48,10 +47,4 @@ public interface Assert { ...@@ -48,10 +47,4 @@ public interface Assert {
throw new BusException("集群地址暂不可用"); throw new BusException("集群地址暂不可用");
} }
} }
static void check(Jar jar) {
if (jar == null) {
throw new BusException("自定义Jar不存在");
}
}
} }
/*
*
* 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.controller;
import org.dinky.data.annotation.Log;
import org.dinky.data.constant.UploadFileConstant;
import org.dinky.data.enums.BusinessType;
import org.dinky.data.result.Result;
import org.dinky.service.FileUploadService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
/** FileUploadController */
@Slf4j
@RestController
@Api(tags = "File Upload Controller")
@RequestMapping("/api/fileUpload")
@RequiredArgsConstructor
public class FileUploadController {
private final FileUploadService fileUploadService;
/**
* Upload file<br>
*
* @param files Multi files
* @param dir Dir, default is empty. If not provide, please provide the 'fileType' value
* @param fileType Please refer {@link UploadFileConstant}, default is -1. If not provide,
* please provide the 'dir' value
* @return {@link Result}
*/
@PostMapping
@Log(title = "Upload Files", businessType = BusinessType.UPLOAD)
@ApiOperation("Upload Files")
public Result<Void> upload(
@RequestPart("files") MultipartFile[] files,
@RequestParam(value = "dir", defaultValue = "", required = false) String dir,
@RequestParam(value = "fileType", defaultValue = "-1", required = false) Byte fileType) {
if (!StringUtils.isEmpty(dir) && fileType != -1) {
return Result.failed("不要同时指定 dir 和 fileType 参数");
} else if (StringUtils.isEmpty(dir) && fileType == -1) {
return Result.failed("dir 和 fileType 参数必选其一");
}
if (StringUtils.isEmpty(dir)) {
fileUploadService.upload(files, fileType);
} else {
fileUploadService.upload(files, dir, fileType);
}
return Result.succeed();
}
/**
* Upload hdfs file<br>
*
* @param files Multi files
* @param dir Dir, default is empty. If not provide, please provide the 'fileType' value
* @param hadoopConfigPath Please refer {@link UploadFileConstant}, default is -1. If not
* provide, please provide the 'dir' value
* @return {@link Result}
*/
@PostMapping(value = "hdfs")
@Log(title = "Upload File to Hdfs", businessType = BusinessType.UPLOAD)
@ApiOperation("Upload File to Hdfs")
public Result<Void> uploadHdfs(
@RequestPart("files") MultipartFile[] files,
@RequestParam(value = "dir", defaultValue = "", required = false) String dir,
@RequestParam(value = "hadoopConfigPath", required = false) String hadoopConfigPath) {
fileUploadService.uploadHdfs(files, dir, hadoopConfigPath);
return Result.succeed();
}
}
...@@ -19,14 +19,11 @@ ...@@ -19,14 +19,11 @@
package org.dinky.controller; package org.dinky.controller;
import org.dinky.data.model.Jar;
import org.dinky.data.model.Task; import org.dinky.data.model.Task;
import org.dinky.data.result.ProTableResult;
import org.dinky.data.result.Result; import org.dinky.data.result.Result;
import org.dinky.function.constant.PathConstant; import org.dinky.function.constant.PathConstant;
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.service.JarService;
import org.dinky.service.TaskService; import org.dinky.service.TaskService;
import org.apache.flink.table.catalog.FunctionLanguage; import org.apache.flink.table.catalog.FunctionLanguage;
...@@ -35,15 +32,10 @@ import java.util.List; ...@@ -35,15 +32,10 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import com.fasterxml.jackson.databind.JsonNode;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
...@@ -62,34 +54,8 @@ import lombok.extern.slf4j.Slf4j; ...@@ -62,34 +54,8 @@ import lombok.extern.slf4j.Slf4j;
@RequiredArgsConstructor @RequiredArgsConstructor
public class JarController { public class JarController {
private final JarService jarService;
private final TaskService taskService; private final TaskService taskService;
/** 新增或者更新 */
@PutMapping
public Result<Void> saveOrUpdate(@RequestBody Jar jar) throws Exception {
if (jarService.saveOrUpdate(jar)) {
return Result.succeed("新增成功");
} else {
return Result.failed("新增失败");
}
}
/** 动态查询列表 */
@PostMapping
public ProTableResult<Jar> listJars(@RequestBody JsonNode para) {
return jarService.selectForProTable(para);
}
/** 获取可用的jar列表 */
@GetMapping("/listEnabledAll")
@ApiOperation("Query jar list enabled all")
public Result<List<Jar>> listEnabledAll() {
List<Jar> jars = jarService.listEnabledAll();
return Result.succeed(jars, "获取成功");
}
@PostMapping("/udf/generateJar") @PostMapping("/udf/generateJar")
@ApiOperation("Generate jar") @ApiOperation("Generate jar")
public Result<Map<String, List<String>>> generateJar() { public Result<Map<String, List<String>>> generateJar() {
......
/*
*
* 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.controller;
import org.dinky.data.model.UploadFileRecord;
import org.dinky.data.result.Result;
import org.dinky.service.UploadFileRecordService;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.hutool.json.JSONUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
/** FileUploadController */
@Slf4j
@Api(tags = "File Upload Controller")
@RestController
@SaCheckLogin
@RequestMapping("/api/uploadFileRecord")
public class UploadFileRecordController {
@Resource
private UploadFileRecordService uploadFileRecordService;
/** @param record {@link UploadFileRecord} */
@PostMapping("/list")
@ApiOperation("Get Upload List")
public Result<String> getUploadFileRecord(@RequestBody UploadFileRecord record) {
List<UploadFileRecord> records = uploadFileRecordService.list(new QueryWrapper<>(record));
return Result.succeed(JSONUtil.toJsonStr(records));
}
}
/*
*
* 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.data.constant;
import org.springframework.boot.system.ApplicationHome;
/** Upload file's some constant. */
public class UploadFileConstant {
// Upload file's type
// constant----------------------------------------------------------------------------------------
/** Not internal upload file type, this value represent upload the file to the specific dir. */
public static final byte TYPE_OTHER = -1;
public static final byte HADOOP_CONF_ID = 1;
public static final String HADOOP_CONF_NAME = "hadoop-conf";
public static final byte FLINK_CONF_ID = 2;
public static final String FLINK_CONF_NAME = "flink-conf";
public static final byte FLINK_LIB_ID = 3;
public static final String FLINK_LIB_NAME = "flink-lib";
public static final byte USER_JAR_ID = 4;
public static final String USER_JAR_NAME = "user-jar";
public static final byte DINKY_JAR_ID = 5;
public static final String DINKY_JAR_NAME = "dinky-jar";
// Upload file's dir
// constant----------------------------------------------------------------------------------------
static {
// Get admin jar's parent absolute path
DINKY_HOME_DIR =
new ApplicationHome(UploadFileConstant.class).getSource().getParent() + "/../";
}
public static final String DINKY_HOME_DIR;
public static final String HDFS_HOME_DIR = "hdfs:///";
public static final String HADOOP_CONF_DIR = DINKY_HOME_DIR + "/config/hadoop-conf";
public static final String FLINK_CONF_DIR = DINKY_HOME_DIR + "/config/flink-conf";
public static final String FLINK_LIB_DIR = HDFS_HOME_DIR + "dinky/jar/flink/lib";
public static final String DINKY_JAR_DIR = HDFS_HOME_DIR + "dinky/jar/dinky";
public static final String USER_JAR_DIR = HDFS_HOME_DIR + "dinky/jar/user";
// Upload file's target
// constant----------------------------------------------------------------------------------------
/** An unidentified upload file type */
public static final byte TARGET_OTHER = -1;
public static final byte TARGET_LOCAL = 1;
public static final byte TARGET_HDFS = 2;
/**
* Get internal upload file type's dir name
*
* @param fileType Upload file type id.
* @return Internal upload file dir name
*/
public static String getDirName(byte fileType) {
switch (fileType) {
case HADOOP_CONF_ID:
return HADOOP_CONF_NAME;
case FLINK_CONF_ID:
return FLINK_CONF_NAME;
case FLINK_LIB_ID:
return FLINK_LIB_NAME;
case USER_JAR_ID:
return USER_JAR_NAME;
case DINKY_JAR_ID:
return DINKY_JAR_NAME;
default:
return null;
}
}
/**
* Get internal upload file type's dir path
*
* @param fileType Upload file type id.
* @return Internal upload file dir path
*/
public static String getDirPath(byte fileType) {
switch (fileType) {
case HADOOP_CONF_ID:
return HADOOP_CONF_DIR;
case FLINK_CONF_ID:
return FLINK_CONF_DIR;
case FLINK_LIB_ID:
return FLINK_LIB_DIR;
case USER_JAR_ID:
return USER_JAR_DIR;
case DINKY_JAR_ID:
return DINKY_JAR_DIR;
default:
return "";
}
}
/**
* Get internal upload file type's target
*
* @param fileType Upload file type id.
* @return Upload file target
*/
public static byte getTarget(byte fileType) {
switch (fileType) {
case HADOOP_CONF_ID:
case FLINK_CONF_ID:
return TARGET_LOCAL;
case FLINK_LIB_ID:
case USER_JAR_ID:
case DINKY_JAR_ID:
return TARGET_HDFS;
default:
return TARGET_OTHER;
}
}
}
/*
*
* 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.data.dto;
import org.dinky.gateway.config.GatewayConfig;
import org.dinky.gateway.enums.SavePointStrategy;
import org.dinky.job.JobConfig;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
/**
* APIExecuteJarDTO
*
* @since 2021/12/12 19:46
*/
@Getter
@Setter
@ApiModel(value = "APIExecuteJarDTO", description = "API Execute JAR Data Transfer Object")
public class APIExecuteJarDTO {
@ApiModelProperty(
value = "Type",
dataType = "String",
example = "Flink",
notes = "The type of the JAR execution (e.g., 'Flink')")
private String type;
@ApiModelProperty(
value = "Job Name",
dataType = "String",
example = "MyJob",
notes = "The name of the job to execute")
private String jobName;
@ApiModelProperty(
value = "Savepoint Path",
dataType = "String",
example = "/path/to/savepoint",
notes = "The path to the savepoint to restore from (if applicable)")
private String savePointPath;
@ApiModelProperty(
value = "Gateway Configuration",
dataType = "GatewayConfig",
notes = "The configuration for the gateway")
private GatewayConfig gatewayConfig;
public JobConfig getJobConfig() {
JobConfig config = new JobConfig();
config.setType(type);
config.setJobName(jobName);
config.setSavePointStrategy(SavePointStrategy.CUSTOM);
config.setSavePointPath(savePointPath);
config.setGatewayConfig(gatewayConfig);
return config;
}
}
...@@ -27,14 +27,10 @@ import org.dinky.data.flink.job.FlinkJobDetailInfo; ...@@ -27,14 +27,10 @@ import org.dinky.data.flink.job.FlinkJobDetailInfo;
import org.dinky.data.model.JobHistory; import org.dinky.data.model.JobHistory;
import org.dinky.data.model.mapping.ClusterConfigurationMapping; import org.dinky.data.model.mapping.ClusterConfigurationMapping;
import org.dinky.data.model.mapping.ClusterInstanceMapping; import org.dinky.data.model.mapping.ClusterInstanceMapping;
import org.dinky.utils.JsonUtils;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import com.fasterxml.jackson.databind.JsonNode;
import cn.hutool.core.lang.Opt; import cn.hutool.core.lang.Opt;
import cn.hutool.json.JSONUtil;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
...@@ -76,9 +72,6 @@ public class JobDataDto { ...@@ -76,9 +72,6 @@ public class JobDataDto {
@ApiModelProperty(value = "JobConfigInfo", notes = "JobConfigInfo representing job configuration") @ApiModelProperty(value = "JobConfigInfo", notes = "JobConfigInfo representing job configuration")
private FlinkJobConfigInfo config; private FlinkJobConfigInfo config;
@ApiModelProperty(value = "Jar Object", notes = "Object representing the JAR used in the job")
private JsonNode jar;
@ApiModelProperty(value = "ClusterInstance Object", notes = "Object representing the cluster") @ApiModelProperty(value = "ClusterInstance Object", notes = "Object representing the cluster")
private ClusterInstanceMapping cluster; private ClusterInstanceMapping cluster;
...@@ -108,7 +101,6 @@ public class JobDataDto { ...@@ -108,7 +101,6 @@ public class JobDataDto {
.checkpointsJson(this.checkpoints) .checkpointsJson(this.checkpoints)
.checkpointsConfigJson(this.checkpointsConfig) .checkpointsConfigJson(this.checkpointsConfig)
.configJson(this.config) .configJson(this.config)
.jarJson(JSONUtil.toJsonStr(getJar()))
.clusterJson(this.cluster) .clusterJson(this.cluster)
.clusterConfigurationJson(this.clusterConfiguration) .clusterConfigurationJson(this.clusterConfiguration)
.updateTime(LocalDateTime.now()) .updateTime(LocalDateTime.now())
...@@ -125,7 +117,6 @@ public class JobDataDto { ...@@ -125,7 +117,6 @@ public class JobDataDto {
.checkpoints(jobHistory.getCheckpointsJson()) .checkpoints(jobHistory.getCheckpointsJson())
.checkpointsConfig(jobHistory.getCheckpointsConfigJson()) .checkpointsConfig(jobHistory.getCheckpointsConfigJson())
.config(jobHistory.getConfigJson()) .config(jobHistory.getConfigJson())
.jar(JsonUtils.parseToJsonNode(jobHistory.getJarJson()))
.cluster(jobHistory.getClusterJson()) .cluster(jobHistory.getClusterJson())
.clusterConfiguration(jobHistory.getClusterConfigurationJson()) .clusterConfiguration(jobHistory.getClusterConfigurationJson())
.build()) .build())
......
...@@ -96,9 +96,6 @@ public class TaskVersionConfigureDTO implements Serializable { ...@@ -96,9 +96,6 @@ public class TaskVersionConfigureDTO implements Serializable {
notes = "The ID of the database source") notes = "The ID of the database source")
private Integer databaseId; private Integer databaseId;
@ApiModelProperty(value = "Jar ID", dataType = "Integer", example = "6", notes = "The ID of the JAR file")
private Integer jarId;
@ApiModelProperty( @ApiModelProperty(
value = "Environment ID", value = "Environment ID",
dataType = "Integer", dataType = "Integer",
......
/*
*
* 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.data.model;
import org.dinky.mybatis.model.SuperEntity;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* Jar
*
* @since 2021/11/13
*/
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("dinky_jar")
@ApiModel(value = "Jar", description = "Jar Information")
public class Jar extends SuperEntity {
private static final long serialVersionUID = 3769276772487490408L;
@ApiModelProperty(value = "Tenant ID", dataType = "Integer", example = "1", notes = "Tenant ID of the Jar")
private Integer tenantId;
@ApiModelProperty(value = "Type", dataType = "String", example = "type", notes = "Type of the Jar")
private String type;
@ApiModelProperty(value = "Path", dataType = "String", example = "/path/to/jar.jar", notes = "Path to the Jar file")
private String path;
@ApiModelProperty(
value = "Main Class",
dataType = "String",
example = "com.example.Main",
notes = "Main class of the Jar")
private String mainClass;
@ApiModelProperty(
value = "Parameters",
dataType = "String",
example = "--param1 value1 --param2 value2",
notes = "Parameters for running the Jar")
private String paras;
@ApiModelProperty(
value = "Note",
dataType = "String",
example = "This is a note about the Jar",
notes = "Additional notes or description")
private String note;
}
...@@ -109,13 +109,6 @@ public class JobHistory implements Serializable { ...@@ -109,13 +109,6 @@ public class JobHistory implements Serializable {
@TableField(typeHandler = JSONObjectHandler.class) @TableField(typeHandler = JSONObjectHandler.class)
private FlinkJobConfigInfo configJson; private FlinkJobConfigInfo configJson;
@ApiModelProperty(
value = "Jar JSON",
dataType = "String",
example = "{\"jarName\": \"example.jar\"}",
notes = "JSON representation of the JAR")
private String jarJson;
@ApiModelProperty( @ApiModelProperty(
value = "ClusterInstance JSON", value = "ClusterInstance JSON",
dataType = "String", dataType = "String",
......
...@@ -114,13 +114,6 @@ public class Task extends SuperEntity<Task> { ...@@ -114,13 +114,6 @@ public class Task extends SuperEntity<Task> {
notes = "ID of the database associated with the task") notes = "ID of the database associated with the task")
private Integer databaseId; private Integer databaseId;
@ApiModelProperty(
value = "JAR ID",
dataType = "Integer",
example = "5001",
notes = "ID of the JAR associated with the task")
private Integer jarId;
@ApiModelProperty( @ApiModelProperty(
value = "Environment ID", value = "Environment ID",
dataType = "Integer", dataType = "Integer",
......
/*
*
* 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.data.model;
import org.dinky.mybatis.model.SuperEntity;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
/** UploadFileRecord */
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("dinky_upload_file_record")
@Deprecated
public class UploadFileRecord extends SuperEntity {
private static final long serialVersionUID = 3769285632787490408L;
/**
* File type id: hadoop-conf(1)、flink-conf(2)、flink-lib(3)、user-jar(4)、dinky-jar(5), -1
* represent no file type.
*/
private Byte fileType = -1;
private String fileName;
/** Where file upload to: local(1)、hdfs(2) */
private Byte target;
private String fileParentPath;
private String fileAbsolutePath;
private Boolean isFile = true;
}
...@@ -36,7 +36,6 @@ import org.dinky.gateway.enums.GatewayType; ...@@ -36,7 +36,6 @@ import org.dinky.gateway.enums.GatewayType;
import org.dinky.service.ClusterConfigurationService; import org.dinky.service.ClusterConfigurationService;
import org.dinky.service.ClusterInstanceService; import org.dinky.service.ClusterInstanceService;
import org.dinky.service.HistoryService; import org.dinky.service.HistoryService;
import org.dinky.service.JarService;
import org.dinky.service.JobHistoryService; import org.dinky.service.JobHistoryService;
import org.dinky.service.JobInstanceService; import org.dinky.service.JobInstanceService;
import org.dinky.service.TaskService; import org.dinky.service.TaskService;
...@@ -57,7 +56,6 @@ public class Job2MysqlHandler implements JobHandler { ...@@ -57,7 +56,6 @@ public class Job2MysqlHandler implements JobHandler {
private static final HistoryService historyService; private static final HistoryService historyService;
private static final ClusterInstanceService clusterInstanceService; private static final ClusterInstanceService clusterInstanceService;
private static final ClusterConfigurationService clusterConfigurationService; private static final ClusterConfigurationService clusterConfigurationService;
private static final JarService jarService;
private static final JobInstanceService jobInstanceService; private static final JobInstanceService jobInstanceService;
private static final JobHistoryService jobHistoryService; private static final JobHistoryService jobHistoryService;
private static final TaskService taskService; private static final TaskService taskService;
...@@ -67,7 +65,6 @@ public class Job2MysqlHandler implements JobHandler { ...@@ -67,7 +65,6 @@ public class Job2MysqlHandler implements JobHandler {
clusterInstanceService = SpringContextUtils.getBean("clusterInstanceServiceImpl", ClusterInstanceService.class); clusterInstanceService = SpringContextUtils.getBean("clusterInstanceServiceImpl", ClusterInstanceService.class);
clusterConfigurationService = clusterConfigurationService =
SpringContextUtils.getBean("clusterConfigurationServiceImpl", ClusterConfigurationService.class); SpringContextUtils.getBean("clusterConfigurationServiceImpl", ClusterConfigurationService.class);
jarService = SpringContextUtils.getBean("jarServiceImpl", JarService.class);
jobInstanceService = SpringContextUtils.getBean("jobInstanceServiceImpl", JobInstanceService.class); jobInstanceService = SpringContextUtils.getBean("jobInstanceServiceImpl", JobInstanceService.class);
jobHistoryService = SpringContextUtils.getBean("jobHistoryServiceImpl", JobHistoryService.class); jobHistoryService = SpringContextUtils.getBean("jobHistoryServiceImpl", JobHistoryService.class);
taskService = SpringContextUtils.getBean("taskServiceImpl", TaskService.class); taskService = SpringContextUtils.getBean("taskServiceImpl", TaskService.class);
...@@ -191,11 +188,6 @@ public class Job2MysqlHandler implements JobHandler { ...@@ -191,11 +188,6 @@ public class Job2MysqlHandler implements JobHandler {
JobHistory jobHistory = jobHistoryBuilder JobHistory jobHistory = jobHistoryBuilder
.id(jobInstance.getId()) .id(jobInstance.getId())
.clusterJson(ClusterInstanceMapping.getClusterInstanceMapping(clusterInstance)) .clusterJson(ClusterInstanceMapping.getClusterInstanceMapping(clusterInstance))
.jarJson(
Asserts.isNotNull(job.getJobConfig().getJarId())
? JsonUtils.toJsonString(
jarService.getById(job.getJobConfig().getJarId()))
: null)
.clusterConfigurationJson( .clusterConfigurationJson(
Asserts.isNotNull(clusterConfigurationId) Asserts.isNotNull(clusterConfigurationId)
? ClusterConfigurationMapping.getClusterConfigurationMapping( ? ClusterConfigurationMapping.getClusterConfigurationMapping(
......
/*
*
* 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.mapper;
import org.dinky.data.model.Jar;
import org.dinky.mybatis.mapper.SuperMapper;
import org.apache.ibatis.annotations.Mapper;
/**
* JarMapper
*
* @since 2021/11/13
*/
@Mapper
public interface JarMapper extends SuperMapper<Jar> {}
/*
*
* 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.mapper;
import org.dinky.data.model.UploadFileRecord;
import org.dinky.mybatis.mapper.SuperMapper;
import org.apache.ibatis.annotations.Mapper;
/** UploadFileRecordMapper */
@Mapper
public interface UploadFileRecordMapper extends SuperMapper<UploadFileRecord> {}
/*
*
* 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.service;
import org.dinky.data.constant.UploadFileConstant;
import org.springframework.web.multipart.MultipartFile;
/** File upload */
public interface FileUploadService {
/**
* Upload one file, if target file exists, will delete it first
*
* @param file {@link MultipartFile} instance
* @param fileType Upload file's type, refer ${@link UploadFileConstant}
*/
void upload(MultipartFile file, Byte fileType);
/**
* Upload multy file, if target file exists, will delete it first
*
* @param files {@link MultipartFile} instance
* @param fileType Upload file's type, refer ${@link UploadFileConstant}
*/
void upload(MultipartFile[] files, Byte fileType);
/**
* Upload one file, if target file exists, will delete it first
*
* @param file {@link MultipartFile} instance
* @param dir Local absolute dir
* @param fileType Upload file's type, refer ${@link UploadFileConstant}
*/
void upload(MultipartFile file, String dir, Byte fileType);
/**
* Upload multy file, if target file exists, will delete it first
*
* @param files {@link MultipartFile} instance
* @param dir Local absolute dir
* @param fileType Upload file's type, refer ${@link UploadFileConstant}
*/
void upload(MultipartFile[] files, String dir, Byte fileType);
/**
* Upload one hdfs file, if target file exists, will delete it first
*
* @param file {@link MultipartFile} instance
* @param hadoopConfigPath core-site.xml,hdfs-site.xml,yarn-site.xml
* @param dir dir
*/
void uploadHdfs(MultipartFile file, String dir, String hadoopConfigPath);
/**
* Upload multy hdfs file, if target file exists, will delete it first
*
* @param files {@link MultipartFile} instance
* @param hadoopConfigPath core-site.xml,hdfs-site.xml,yarn-site.xml
* @param dir dir
*/
void uploadHdfs(MultipartFile[] files, String dir, String hadoopConfigPath);
}
/*
*
* 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.service;
import org.dinky.data.model.Jar;
import org.dinky.mybatis.service.ISuperService;
import java.util.List;
/**
* JarService
*
* @since 2021/11/13
*/
public interface JarService extends ISuperService<Jar> {
/**
* List all enabled jar files.
*
* @return A list of {@link Jar} objects representing all enabled jar files.
*/
List<Jar> listEnabledAll();
}
/*
*
* 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.service;
import org.dinky.data.model.UploadFileRecord;
import org.dinky.mybatis.service.ISuperService;
/** UploadFileRecordService */
public interface UploadFileRecordService extends ISuperService<UploadFileRecord> {
/** Save or update base on file absolute path and file type. */
boolean saveOrUpdateFile(String fileName, String parentPath, String absolutePath, Byte fileType, Byte target);
/** Save or update base on file type. */
boolean saveOrUpdateDir(String parentPath, Byte fileType, Byte target);
}
/*
*
* 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.service.impl;
import org.dinky.assertion.Asserts;
import org.dinky.data.constant.UploadFileConstant;
import org.dinky.data.exception.BusException;
import org.dinky.service.FileUploadService;
import org.dinky.service.UploadFileRecordService;
import org.dinky.utils.FilePathUtil;
import org.dinky.utils.HdfsUtil;
import org.apache.commons.lang3.StringUtils;
import java.io.File;
import java.io.IOException;
import java.util.Objects;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import cn.hutool.core.io.FileUtil;
import lombok.extern.slf4j.Slf4j;
/** FileUploadServiceImpl */
@Slf4j
@Service
public class FileUploadServiceImpl implements FileUploadService {
@Resource
private UploadFileRecordService uploadFileRecordService;
@Override
public void upload(MultipartFile file, String dir, Byte fileType) {
byte target = getTarget(dir, fileType);
if (Objects.equals(target, UploadFileConstant.TARGET_LOCAL)) {
FileUtil.mkdir(dir);
}
String filePath = FilePathUtil.addFileSeparator(dir) + file.getOriginalFilename();
switch (target) {
case UploadFileConstant.TARGET_LOCAL: {
try {
file.transferTo(new File(filePath));
if (uploadFileRecordService.saveOrUpdateFile(
file.getOriginalFilename(), dir, filePath, fileType, UploadFileConstant.TARGET_LOCAL)) {
return;
} else {
throw BusException.valueOfMsg("database exception");
}
} catch (IOException e) {
throw BusException.valueOf("file.upload.failed", e);
}
}
case UploadFileConstant.TARGET_HDFS: {
HdfsUtil.uploadFile(filePath, file);
if (uploadFileRecordService.saveOrUpdateFile(
file.getOriginalFilename(), dir, filePath, fileType, UploadFileConstant.TARGET_HDFS)) {
return;
} else {
throw BusException.valueOfMsg("database exception");
}
}
default:
throw BusException.valueOfMsg("Illegal upload file destination");
}
}
@Override
public void upload(MultipartFile file, Byte fileType) {
String dir = UploadFileConstant.getDirPath(fileType);
if (StringUtils.isEmpty(dir)) {
throw BusException.valueOfMsg("Illegal upload file type");
}
upload(file, dir, fileType);
}
@Override
public void upload(MultipartFile[] files, String dir, Byte fileType) {
if (StringUtils.isEmpty(dir)) {
throw BusException.valueOfMsg("Illegal upload file type");
}
if (files.length > 0) {
for (MultipartFile file : files) {
upload(file, dir, fileType);
}
if (!uploadFileRecordService.saveOrUpdateDir(dir, fileType, getTarget(dir, fileType))) {
throw BusException.valueOfMsg("database exception");
}
} else {
throw BusException.valueOfMsg("No file detected for upload");
}
}
@Override
public void uploadHdfs(MultipartFile file, String dir, String hadoopConfigPath) {
if (Asserts.isNullString(dir)) {
dir = UploadFileConstant.getDirPath(UploadFileConstant.FLINK_LIB_ID);
}
String filePath = FilePathUtil.addFileSeparator(dir) + file.getOriginalFilename();
HdfsUtil.uploadFile(filePath, file, hadoopConfigPath);
if (!uploadFileRecordService.saveOrUpdateFile(
file.getOriginalFilename(),
dir,
filePath,
UploadFileConstant.FLINK_LIB_ID,
UploadFileConstant.TARGET_HDFS)) {
throw BusException.valueOfMsg("database exception");
}
}
@Override
public void uploadHdfs(MultipartFile[] files, String dir, String hadoopConfigPath) {
if (Asserts.isNotNull(files)) {
try {
for (MultipartFile file : files) {
uploadHdfs(file, dir, hadoopConfigPath);
}
if (!uploadFileRecordService.saveOrUpdateDir(
dir, UploadFileConstant.FLINK_LIB_ID, UploadFileConstant.TARGET_HDFS)) {
throw BusException.valueOfMsg("database exception");
}
} catch (Exception e) {
throw BusException.valueOf("unknown.error", e);
}
}
}
@Override
public void upload(MultipartFile[] files, Byte fileType) {
String dir = UploadFileConstant.getDirPath(fileType);
upload(files, dir, fileType);
}
/**
* Get upload file target.
*
* @param dir If null, will return -1
* @param fileType Internal upload file type, refer {@link UploadFileConstant}
* @return Upload file target, refer {@link UploadFileConstant}
*/
private byte getTarget(String dir, byte fileType) {
byte target = UploadFileConstant.getTarget(fileType);
if (target == -1) {
target = FilePathUtil.getDirTarget(dir);
}
return target;
}
}
/*
*
* 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.service.impl;
import org.dinky.data.model.Jar;
import org.dinky.mapper.JarMapper;
import org.dinky.mybatis.service.impl.SuperServiceImpl;
import org.dinky.service.JarService;
import java.util.List;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
/**
* JarServiceImpl
*
* @since 2021/11/13
*/
@Service
public class JarServiceImpl extends SuperServiceImpl<JarMapper, Jar> implements JarService {
@Override
public List<Jar> listEnabledAll() {
return list(new QueryWrapper<Jar>().eq("enabled", 1));
}
}
...@@ -42,7 +42,6 @@ import org.dinky.data.model.Catalogue; ...@@ -42,7 +42,6 @@ import org.dinky.data.model.Catalogue;
import org.dinky.data.model.ClusterConfiguration; import org.dinky.data.model.ClusterConfiguration;
import org.dinky.data.model.ClusterInstance; import org.dinky.data.model.ClusterInstance;
import org.dinky.data.model.DataBase; import org.dinky.data.model.DataBase;
import org.dinky.data.model.Jar;
import org.dinky.data.model.JobInstance; import org.dinky.data.model.JobInstance;
import org.dinky.data.model.JobModelOverview; import org.dinky.data.model.JobModelOverview;
import org.dinky.data.model.JobTypeOverView; import org.dinky.data.model.JobTypeOverView;
...@@ -75,7 +74,6 @@ import org.dinky.service.ClusterConfigurationService; ...@@ -75,7 +74,6 @@ import org.dinky.service.ClusterConfigurationService;
import org.dinky.service.ClusterInstanceService; import org.dinky.service.ClusterInstanceService;
import org.dinky.service.DataBaseService; import org.dinky.service.DataBaseService;
import org.dinky.service.FragmentVariableService; import org.dinky.service.FragmentVariableService;
import org.dinky.service.JarService;
import org.dinky.service.JobInstanceService; import org.dinky.service.JobInstanceService;
import org.dinky.service.SavepointsService; import org.dinky.service.SavepointsService;
import org.dinky.service.TaskService; import org.dinky.service.TaskService;
...@@ -139,7 +137,6 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen ...@@ -139,7 +137,6 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen
private final SavepointsService savepointsService; private final SavepointsService savepointsService;
private final ClusterInstanceService clusterInstanceService; private final ClusterInstanceService clusterInstanceService;
private final ClusterConfigurationService clusterCfgService; private final ClusterConfigurationService clusterCfgService;
private final JarService jarService;
private final DataBaseService dataBaseService; private final DataBaseService dataBaseService;
private final JobInstanceService jobInstanceService; private final JobInstanceService jobInstanceService;
private final AlertGroupService alertGroupService; private final AlertGroupService alertGroupService;
...@@ -613,13 +610,6 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen ...@@ -613,13 +610,6 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen
DataBase dataBase = dataBaseService.getById(task.getDatabaseId()); DataBase dataBase = dataBaseService.getById(task.getDatabaseId());
jsonNode.put("databaseName", Asserts.isNotNull(dataBase) ? dataBase.getName() : null); jsonNode.put("databaseName", Asserts.isNotNull(dataBase) ? dataBase.getName() : null);
} }
// jarName
if (Asserts.isNotNull(task.getJarId())) {
Jar jar = jarService.getById(task.getJarId());
jsonNode.put("jarName", Asserts.isNotNull(jar) ? jar.getName() : null);
}
// envName // envName
if (Asserts.isNotNull(task.getEnvId())) { if (Asserts.isNotNull(task.getEnvId())) {
Task envTask = getById(task.getEnvId()); Task envTask = getById(task.getEnvId());
...@@ -700,13 +690,6 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen ...@@ -700,13 +690,6 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen
} }
} }
if (Asserts.isNotNull(task.getJarName())) {
Jar jar = jarService.getOne(new QueryWrapper<Jar>().eq("name", task.getJarName()));
if (Asserts.isNotNull(jar)) {
task.setJarId(jar.getId());
}
}
if (Asserts.isNotNull(task.getAlertGroupName())) { if (Asserts.isNotNull(task.getAlertGroupName())) {
AlertGroup alertGroup = AlertGroup alertGroup =
alertGroupService.getOne(new QueryWrapper<AlertGroup>().eq("name", task.getAlertGroupName())); alertGroupService.getOne(new QueryWrapper<AlertGroup>().eq("name", task.getAlertGroupName()));
......
/*
*
* 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.service.impl;
import org.dinky.data.constant.UploadFileConstant;
import org.dinky.data.model.UploadFileRecord;
import org.dinky.mapper.UploadFileRecordMapper;
import org.dinky.mybatis.service.impl.SuperServiceImpl;
import org.dinky.service.UploadFileRecordService;
import org.dinky.utils.FilePathUtil;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
/** UploadFileRecordServiceImpl */
@Service
public class UploadFileRecordServiceImpl extends SuperServiceImpl<UploadFileRecordMapper, UploadFileRecord>
implements UploadFileRecordService {
@Override
public boolean saveOrUpdateFile(
String fileName, String parentPath, String absolutePath, Byte fileType, Byte target) {
UploadFileRecord updateWrapper = new UploadFileRecord();
updateWrapper.setFileType(fileType);
updateWrapper.setTarget(target);
updateWrapper.setFileAbsolutePath(absolutePath);
UploadFileRecord entity = new UploadFileRecord();
entity.setFileType(fileType);
entity.setTarget(target);
entity.setName(UploadFileConstant.getDirName(fileType));
entity.setIsFile(true);
entity.setFileName(fileName);
entity.setFileParentPath(FilePathUtil.removeFileSeparator(parentPath));
entity.setFileAbsolutePath(absolutePath);
return saveOrUpdate(entity, new UpdateWrapper<>(updateWrapper));
}
@Override
public boolean saveOrUpdateDir(String parentPath, Byte fileType, Byte target) {
UploadFileRecord updateWrapper = new UploadFileRecord();
updateWrapper.setFileType(fileType);
updateWrapper.setTarget(target);
updateWrapper.setIsFile(false);
UploadFileRecord entity = new UploadFileRecord();
entity.setFileType(fileType);
entity.setTarget(target);
entity.setName(UploadFileConstant.getDirName(fileType));
entity.setIsFile(false);
entity.setFileParentPath(FilePathUtil.removeFileSeparator(parentPath));
return saveOrUpdate(entity, new UpdateWrapper<>(updateWrapper));
}
}
/*
*
* 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.utils;
import org.dinky.data.constant.UploadFileConstant;
import org.apache.commons.lang3.StringUtils;
/** File path handle */
public class FilePathUtil {
/**
* Add a file separator '/' at the end of the file path
*
* @param filePath File path
*/
public static String addFileSeparator(String filePath) {
if (StringUtils.isEmpty(filePath)) {
return filePath;
} else {
if (filePath.endsWith("/")) {
return filePath;
} else {
return filePath + "/";
}
}
}
/**
* Remove a file separator '/' at the end of the file path
*
* @param filePath File path
*/
public static String removeFileSeparator(String filePath) {
if (StringUtils.isEmpty(filePath)) {
return filePath;
} else {
if (filePath.endsWith("/")) {
return filePath.substring(0, filePath.length() - 1);
} else {
return filePath;
}
}
}
/**
* Get dir type, refer {@link UploadFileConstant}
*
* @param dir Directory
* @return Refer {@link UploadFileConstant}
*/
public static byte getDirTarget(String dir) {
if (StringUtils.isEmpty(dir)) {
return UploadFileConstant.TARGET_OTHER;
} else if (dir.contains("hdfs")) {
return UploadFileConstant.TARGET_HDFS;
} else {
return UploadFileConstant.TARGET_LOCAL;
}
}
}
/*
*
* 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.utils;
import org.dinky.assertion.Asserts;
import org.dinky.data.constant.UploadFileConstant;
import org.dinky.data.exception.BusException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import java.io.File;
import java.io.IOException;
import org.springframework.web.multipart.MultipartFile;
import cn.hutool.core.exceptions.ExceptionUtil;
import lombok.extern.slf4j.Slf4j;
/** Hdfs Handle */
@Slf4j
public class HdfsUtil {
/**
* Init internal hdfs client
*
* @param hadoopConfigPath HDFS config path
*/
private static FileSystem init(String hadoopConfigPath) {
FileSystem hdfs;
if (Asserts.isNullString(hadoopConfigPath)) {
hadoopConfigPath = FilePathUtil.removeFileSeparator(UploadFileConstant.HADOOP_CONF_DIR);
}
String coreSiteFilePath = hadoopConfigPath + "/core-site.xml";
String hdfsSiteFilePath = hadoopConfigPath + "/hdfs-site.xml";
if (!new File(coreSiteFilePath).exists() || !new File(hdfsSiteFilePath).exists()) {
throw BusException.valueOf("hdfs.file.lose");
}
try {
final Configuration configuration = new Configuration();
configuration.addResource(new Path(coreSiteFilePath));
configuration.addResource(new Path(hdfsSiteFilePath));
hdfs = FileSystem.get(configuration);
} catch (IOException e) {
String msg = ExceptionUtil.stacktraceToString(e);
log.error(msg);
throw BusException.valueOf("hdfs.init.failed", e);
}
log.info("hdfs client initialized successfully");
return hdfs;
}
/**
* Upload file byte content to HDFS
*
* @param path HDFS path
* @param bytes File byte content
* @param hadoopConfigPath hdfs config path
*/
public static void uploadFile(String path, byte[] bytes, String hadoopConfigPath) {
try (FileSystem hdfs = init(hadoopConfigPath);
FSDataOutputStream stream = hdfs.create(new Path(path), true)) {
stream.write(bytes);
stream.flush();
} catch (IOException e) {
throw BusException.valueOf("file.upload.failed", e);
}
}
/**
* Upload file byte content to HDFS
*
* @param path HDFS path
* @param file MultipartFile instance
*/
public static void uploadFile(String path, MultipartFile file) {
try {
uploadFile(path, file.getBytes(), null);
} catch (IOException e) {
throw BusException.valueOf("file.upload.failed", e);
}
}
/**
* Upload file byte content to HDFS
*
* @param path HDFS path
* @param file MultipartFile instance
* @param hadoopConfigPath hdfs config path
*/
public static void uploadFile(String path, MultipartFile file, String hadoopConfigPath) {
try {
uploadFile(path, file.getBytes(), hadoopConfigPath);
} catch (IOException e) {
throw BusException.valueOf("file.upload.failed", e);
}
}
}
This source diff could not be displayed because it is too large. You can view the blob instead.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.dinky.mapper.JarMapper">
<select id="selectForProTable" resultType="org.dinky.data.model.Jar">
select
a.*
from
dinky_jar a
<where>
1=1
<if test='param.name!=null and param.name!=""'>
and a.name like "%${param.name}%"
</if>
<if test='param.path!=null and param.path!=""'>
and a.path like "%${param.path}%"
</if>
<if test='param.mainClass!=null and param.mainClass!=""'>
and a.main_class like "%${param.mainClass}%"
</if>
<if test='param.createTime!=null and param.createTime!=""'>
and a.create_time <![CDATA[>=]]> str_to_date( #{param.createTime},'%Y-%m-%d %H:%i:%s')
</if>
<if test='param.updateTime!=null and param.updateTime!=""'>
and a.update_time <![CDATA[>=]]> str_to_date( #{param.updateTime},'%Y-%m-%d %H:%i:%s')
</if>
<if test='ew.sqlSegment!=null and ew.sqlSegment!="" and !ew.sqlSegment.startsWith(" ORDER BY")'>
and
</if>
<if test='ew.sqlSegment!=null and ew.sqlSegment!=""'>
${ew.sqlSegment}
</if>
</where>
</select>
</mapper>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.dinky.mapper.UploadFileRecordMapper">
</mapper>
...@@ -144,11 +144,6 @@ unknown.i18n=Unknown i18n information, please check. . . ...@@ -144,11 +144,6 @@ unknown.i18n=Unknown i18n information, please check. . .
file.upload.failed=File upload failed, reason: {0} file.upload.failed=File upload failed, reason: {0}
hdfs.init.failed=Internal hdfs client initialization error, reason: {0}
hdfs.file.lose=The core-site.xml/hdfs-site.xml/yarn-site.xml files were not found in the project root directory, please upload these files first
# dinky-alert # dinky-alert
alert.rule.jobFail=Job Failure alert.rule.jobFail=Job Failure
alert.rule.getJobInfoFail=Get Job Info Fail alert.rule.getJobInfoFail=Get Job Info Fail
......
...@@ -144,9 +144,6 @@ unknown.i18n=\u672A\u77E5 i18n \u4FE1\u606F,\u8BF7\u68C0\u67E5. . . ...@@ -144,9 +144,6 @@ unknown.i18n=\u672A\u77E5 i18n \u4FE1\u606F,\u8BF7\u68C0\u67E5. . .
file.upload.failed=\u6587\u4EF6\u4E0A\u4F20\u5931\u8D25, \u539F\u56E0: {0} file.upload.failed=\u6587\u4EF6\u4E0A\u4F20\u5931\u8D25, \u539F\u56E0: {0}
hdfs.init.failed=\u5185\u90E8hdfs\u4FE1\u606F\u9519\u8BEF, \u539F\u56E0: {0}
hdfs.file.lose= \u5728\u5DE5\u7A0B\u6839\u76EE\u5F55\u4E0B\u6CA1\u6709\u627E\u5230core-site.xml/hdfs-site.xml/yarn-site.xml\u6587\u4EF6, \u8BF7\u5148\u4E0A\u4F20\u8FD9\u4E9B\u6587\u4EF6
daemon.task.config.not.exist=\u7EBF\u7A0B\u4EFB\u52A1\u914D\u7F6E\u4E0D\u80FD\u4E3A\u7A7A daemon.task.config.not.exist=\u7EBF\u7A0B\u4EFB\u52A1\u914D\u7F6E\u4E0D\u80FD\u4E3A\u7A7A
daemon.task.not.support=\u4E0D\u652F\u6301\u7EBF\u7A0B\u4EFB\u52A1\u7C7B\u578B\uFF1A daemon.task.not.support=\u4E0D\u652F\u6301\u7EBF\u7A0B\u4EFB\u52A1\u7C7B\u578B\uFF1A
......
...@@ -816,6 +816,18 @@ ...@@ -816,6 +816,18 @@
<replacement>project</replacement> <replacement>project</replacement>
</replace> </replace>
</pom> </pom>
<typescript>
<includes>
<!-- You have to set the target manually -->
<include>dinky-web/src/**/*.ts</include>
<include>dinky-web/src/**/*.tsx</include>
<include>dinky-web/src/**/*.js</include>
</includes>
<licenseHeader>
<file>style/license_header</file>
<delimiter>(import|const|declare|let|export|export const|export default)</delimiter>
</licenseHeader>
</typescript>
</configuration> </configuration>
<executions> <executions>
<execution> <execution>
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
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