feat: support get origin driver file name

This commit is contained in:
vran 2022-04-27 23:01:45 +08:00
parent 15a9f4ae18
commit defebb1490
52 changed files with 151 additions and 151 deletions

View File

@ -6,7 +6,6 @@ spring.datasource.password=${databasir.db.password}
spring.datasource.url=jdbc:mysql://${databasir.db.url}/${databasir.db.name:databasir}
spring.servlet.multipart.max-file-size=100MB
spring.servlet.multipart.max-request-size=100MB
spring.web.resources.static-locations=
# jooq
spring.jooq.sql-dialect=mysql
# flyway

View File

@ -0,0 +1 @@
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1651035498375" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1963" width="64" height="64" xmlns:xlink="http://www.w3.org/1999/xlink"><defs><style type="text/css"></style></defs><path d="M558.08 472.064c48.128 53.248-13.312 103.424-13.312 103.424s119.808-61.44 65.536-139.264c-51.2-71.68-91.136-107.52 122.88-232.448 0 1.024-335.872 86.016-175.104 268.288" fill="#FF0000" p-id="1964"></path><path d="M610.304 5.12s101.376 101.376-96.256 258.048C356.352 389.12 478.208 460.8 514.048 543.744 420.864 459.776 354.304 386.048 399.36 317.44 463.872 216.064 651.264 166.912 610.304 5.12" fill="#FF0000" p-id="1965"></path><path d="M720.896 757.76c183.296-95.232 98.304-188.416 39.936-175.104-15.36 3.072-21.504 5.12-21.504 5.12s5.12-8.192 16.384-11.264c117.76-40.96 207.872 120.832-37.888 186.368-1.024 0 2.048-3.072 3.072-5.12m-337.92 38.912s-37.888 21.504 26.624 29.696c76.8 8.192 117.76 8.192 202.752-8.192 0 0 23.552 15.36 53.248 26.624-191.488 80.896-433.152-5.12-282.624-48.128m-23.552-106.496s-43.008 31.744 23.552 37.888c82.944 8.192 149.504 10.24 261.12-13.312 0 0 16.384 16.384 40.96 24.576-231.424 68.608-490.496 5.12-325.632-49.152" fill="#6699FF" p-id="1966"></path><path d="M811.008 876.544s27.648 23.552-31.744 40.96c-111.616 34.816-460.8 45.056-558.08 2.048-34.816-15.36 31.744-35.84 51.2-40.96 21.504-5.12 34.816-3.072 34.816-3.072-38.912-28.672-251.904 52.224-107.52 75.776 390.144 62.464 712.704-28.672 611.328-74.752M400.384 578.56s-178.176 43.008-63.488 56.32c49.152 6.144 146.432 5.12 235.52-3.072 73.728-6.144 147.456-19.456 147.456-19.456s-26.624 11.264-45.056 24.576c-181.248 48.128-530.432 26.624-430.08-23.552 88.064-39.936 155.648-34.816 155.648-34.816" fill="#6699FF" p-id="1967"></path><path d="M418.816 1015.808c176.128 11.264 446.464-6.144 453.632-90.112 0 0-13.312 31.744-146.432 56.32-150.528 27.648-336.896 24.576-446.464 6.144 2.048 1.024 24.576 20.48 139.264 27.648" fill="#6699FF" p-id="1968"></path></svg>

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

@ -1 +1 @@
<!doctype html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="/favicon.ico"><title>databasir</title><script defer="defer" type="module" src="/js/chunk-vendors.9effab81.js"></script><script defer="defer" type="module" src="/js/app.75e63a52.js"></script><link href="/css/chunk-vendors.81898547.css" rel="stylesheet"><link href="/css/app.15b40a89.css" rel="stylesheet"><script defer="defer" src="/js/chunk-vendors-legacy.fb0c8458.js" nomodule></script><script defer="defer" src="/js/app-legacy.cf3474d2.js" nomodule></script></head><body><noscript><strong>We're sorry but databasir doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div></body></html>
<!doctype html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="/favicon.ico"><title>databasir</title><script defer="defer" type="module" src="/js/chunk-vendors.9effab81.js"></script><script defer="defer" type="module" src="/js/app.bc6973d3.js"></script><link href="/css/chunk-vendors.81898547.css" rel="stylesheet"><link href="/css/app.15b40a89.css" rel="stylesheet"><script defer="defer" src="/js/chunk-vendors-legacy.fb0c8458.js" nomodule></script><script defer="defer" src="/js/app-legacy.f8c04b90.js" nomodule></script></head><body><noscript><strong>We're sorry but databasir doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div></body></html>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,2 +1,2 @@
"use strict";(self["webpackChunkdatabasir"]=self["webpackChunkdatabasir"]||[]).push([[17],{5430:function(e,a,t){t.d(a,{v:function(){return r}});var o=t(3872);const n="/api/v1.0/operation_logs",r=e=>o.Z.get(n,{params:e})},6017:function(e,a,t){t.r(a),t.d(a,{default:function(){return j}});var o=t(6252),n=t(3577);const r={key:0},l=(0,o.Uk)("成功"),u={key:1},i=(0,o.Uk)("失败"),p={key:0},g={key:1},s={key:1},c={key:1},d={key:1};function w(e,a,t,w,m,P){const h=(0,o.up)("el-table-column"),f=(0,o.up)("arrow-down"),j=(0,o.up)("el-icon"),L=(0,o.up)("el-dropdown-item"),k=(0,o.up)("el-dropdown-menu"),v=(0,o.up)("el-dropdown"),b=(0,o.up)("el-tag"),y=(0,o.up)("el-link"),O=(0,o.up)("el-table"),C=(0,o.up)("el-main"),W=(0,o.up)("el-pagination"),_=(0,o.up)("el-footer"),D=(0,o.up)("el-container");return(0,o.wg)(),(0,o.j4)(D,null,{default:(0,o.w5)((()=>[(0,o.Wm)(C,null,{default:(0,o.w5)((()=>[(0,o.Wm)(O,{data:m.projectOperationLogPageData.data},{default:(0,o.w5)((()=>[(0,o.Wm)(h,{prop:"id",label:""}),(0,o.Wm)(h,{prop:"operationModule",label:"系统模块"}),(0,o.Wm)(h,{prop:"operatorNickname",label:"操作人"}),(0,o.Wm)(h,{prop:"operationName",label:"操作"}),(0,o.Wm)(h,{label:"状态"},{header:(0,o.w5)((()=>[(0,o.Wm)(v,null,{dropdown:(0,o.w5)((()=>[(0,o.Wm)(k,null,{default:(0,o.w5)((()=>[((0,o.wg)(!0),(0,o.iD)(o.HY,null,(0,o.Ko)(m.logStatusMap,((e,a)=>((0,o.wg)(),(0,o.j4)(L,{key:a,onClick:a=>P.onLogStatusFilter(e),icon:e.icon},{default:(0,o.w5)((()=>[(0,o.Uk)((0,n.zw)(e.text),1)])),_:2},1032,["onClick","icon"])))),128))])),_:1})])),default:(0,o.w5)((()=>[(0,o._)("span",null,[(0,o.Uk)((0,n.zw)(m.logStatusColumnLabel)+" ",1),(0,o.Wm)(j,null,{default:(0,o.w5)((()=>[(0,o.Wm)(f)])),_:1})])])),_:1})])),default:(0,o.w5)((e=>[e.row.isSuccess?((0,o.wg)(),(0,o.iD)("span",r,[(0,o.Wm)(b,{type:"success"},{default:(0,o.w5)((()=>[l])),_:1})])):((0,o.wg)(),(0,o.iD)("span",u,[(0,o.Wm)(b,{type:"danger"},{default:(0,o.w5)((()=>[i])),_:1})]))])),_:1}),(0,o.Wm)(h,{label:"错误信息"},{default:(0,o.w5)((e=>[e.row.isSuccess?((0,o.wg)(),(0,o.iD)("span",p)):((0,o.wg)(),(0,o.iD)("span",g,(0,n.zw)(e.row.operationResponse.errMessage),1))])),_:1}),(0,o.Wm)(h,{label:"涉及分组"},{default:(0,o.w5)((e=>[e.row.involvedGroup?((0,o.wg)(),(0,o.j4)(y,{key:0},{default:(0,o.w5)((()=>[(0,o.Uk)((0,n.zw)(e.row.involvedGroup.name),1)])),_:2},1024)):((0,o.wg)(),(0,o.iD)("span",s," - "))])),_:1}),(0,o.Wm)(h,{label:"涉及项目"},{default:(0,o.w5)((e=>[e.row.involvedProject?((0,o.wg)(),(0,o.j4)(y,{key:0},{default:(0,o.w5)((()=>[(0,o.Uk)((0,n.zw)(e.row.involvedProject.name),1)])),_:2},1024)):((0,o.wg)(),(0,o.iD)("span",c," - "))])),_:1}),(0,o.Wm)(h,{label:"涉及用户"},{default:(0,o.w5)((e=>[e.row.involvedUser?((0,o.wg)(),(0,o.j4)(y,{key:0},{default:(0,o.w5)((()=>[(0,o.Uk)((0,n.zw)(e.row.involvedUser.nickname),1)])),_:2},1024)):((0,o.wg)(),(0,o.iD)("span",d," - "))])),_:1}),(0,o.Wm)(h,{prop:"createAt",label:"记录时间"})])),_:1},8,["data"])])),_:1}),(0,o.Wm)(_,null,{default:(0,o.w5)((()=>[(0,o.Wm)(W,{layout:"prev, pager, next","hide-on-single-page":!1,currentPage:m.projectOperationLogPageData.number,"page-size":m.projectOperationLogPageData.size,"page-count":m.projectOperationLogPageData.totalPages,onCurrentChange:P.onProjectOperationLogCurrentPageChange},null,8,["currentPage","page-size","page-count","onCurrentChange"])])),_:1})])),_:1})}var m=t(5430),P={data(){return{projectOperationLogPageData:{data:[],number:1,size:10,totalElements:0,totalPages:1},projectOperationLogPageQuery:{page:0,size:10,isSuccess:null,involveProjectId:null,module:null},logStatusColumnLabel:"全部",logStatusMap:[{text:"全部",icon:"List",value:null},{text:"成功",icon:"CircleCheck",value:!0},{text:"失败",icon:"CircleClose",value:!1}]}},created(){this.fetchProjectOperationLogs()},methods:{fetchProjectOperationLogs(e){this.projectOperationLogPageQuery.page=e?e-1:null,(0,m.v)(this.projectOperationLogPageQuery).then((e=>{e.errCode||(this.projectOperationLogPageData.data=e.data.content,this.projectOperationLogPageData.number=e.data.number+1,this.projectOperationLogPageData.size=e.data.size,this.projectOperationLogPageData.totalPages=e.data.totalPages,this.projectOperationLogPageData.totalElements=e.data.totalElements)}))},onProjectOperationLogCurrentPageChange(e){e&&e-1!=this.projectOperationLogPageQuery.page&&(this.projectOperationLogPageQuery.page=e-1,this.fetchProjectOperationLogs(e))},onQuery(){this.fetchProjectOperationLogs()},onLogStatusFilter(e){this.projectOperationLogPageQuery.isSuccess=e.value,null==e.value?this.logStatusColumnLabel="状态":this.logStatusColumnLabel=e.text,this.onQuery()}}},h=t(3744);const f=(0,h.Z)(P,[["render",w]]);var j=f}}]);
//# sourceMappingURL=17.177f76a3.js.map
//# sourceMappingURL=17.f8914b9e.js.map

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -106,7 +106,7 @@ public class DatabaseTypeService {
if (StringUtils.isNoneBlank(localPath)) {
result = driverResources.loadFromLocal(localPath);
} else {
result = driverResources.loadFromRemote(remoteUrl);
result = driverResources.tempLoadFromRemote(remoteUrl);
}
driverResources.validateDriverJar(result.getDriverFile(), className);
return result;

View File

@ -87,7 +87,7 @@ public class CustomDatabaseConnectionFactory implements DatabaseConnectionFactor
return driverResources.loadFromLocal(type.getJdbcDriverFilePath()).getDriverFile();
}
if (StringUtils.isNotBlank(type.getJdbcDriverFileUrl())) {
File remoteFile = driverResources.loadFromRemote(type.getJdbcDriverFileUrl()).getDriverFile();
File remoteFile = driverResources.tempLoadFromRemote(type.getJdbcDriverFileUrl()).getDriverFile();
driverResources.validateDriverJar(remoteFile, type.getJdbcDriverClassName());
String targetFile = driverResources.copyToStandardDirectory(remoteFile, type.getDatabaseType());
return Paths.get(targetFile).toFile();

View File

@ -3,8 +3,10 @@ package com.databasir.core.infrastructure.driver;
import com.databasir.core.domain.DomainErrors;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.ClassUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Component;
@ -20,7 +22,6 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.UUID;
import java.util.jar.JarFile;
@Component
@ -42,54 +43,53 @@ public class DriverResources {
}
}
public DriverResult loadFromRemote(String remoteUrl) {
String targetFile = "temp/" + System.currentTimeMillis() + ".jar";
File file = download(remoteUrl, targetFile);
return new DriverResult(targetFile, file);
public DriverResult tempLoadFromRemote(String remoteUrl) {
Path dirPath;
try {
dirPath = Files.createTempDirectory("databasir-drivers");
} catch (IOException e) {
log.error("load driver error cause create temp dir failed", e);
throw DomainErrors.DOWNLOAD_DRIVER_ERROR.exception();
}
File file = download(remoteUrl, dirPath.toString());
return new DriverResult(file.getAbsolutePath(), file);
}
public DriverResult load(String driverFilePath, String driverFileUrl, String databaseType) {
if (driverFilePath == null) {
String targetFile = targetDriverFile(databaseType);
File file = download(driverFileUrl, targetFile);
return new DriverResult(targetFile, file);
}
File driverFile = Paths.get(driverFilePath).toFile();
if (driverFile.exists()) {
return new DriverResult(driverFilePath, driverFile);
} else {
String targetFile = targetDriverFile(databaseType);
File file = download(driverFileUrl, targetFile);
return new DriverResult(targetFile, file);
}
}
private File download(String driverFileUrl, String targetFile) {
Path path = Path.of(targetFile);
// create parent directory
if (Files.notExists(path)) {
path.getParent().toFile().mkdirs();
try {
Files.createFile(path);
} catch (IOException e) {
log.error("create file error " + targetFile, e);
throw DomainErrors.DOWNLOAD_DRIVER_ERROR.exception(e.getMessage());
}
private File download(String driverFileUrl, String parentDir) {
Path parentDirPath = Paths.get(parentDir);
try {
Files.createDirectories(parentDirPath);
} catch (IOException e) {
log.error("下载驱动时创建目录失败", e);
throw DomainErrors.DOWNLOAD_DRIVER_ERROR.exception(e);
}
// download
try {
return restTemplate.execute(driverFileUrl, HttpMethod.GET, null, response -> {
if (response.getStatusCode().is2xxSuccessful()) {
File file = path.toFile();
FileOutputStream out = new FileOutputStream(file);
String prefix = System.currentTimeMillis() + "";
String originFileName = response.getHeaders().getContentDisposition().getFilename();
String filename;
if (originFileName == null) {
URL url = new URL(driverFileUrl);
String nameFromUrl = FilenameUtils.getName(url.getPath());
if (StringUtils.endsWith(nameFromUrl, ".jar")) {
filename = prefix + "-" + nameFromUrl;
} else {
filename = prefix + ".jar";
}
} else {
filename = prefix + "-" + originFileName;
}
File targetFile = Paths.get(parentDir, filename).toFile();
FileOutputStream out = new FileOutputStream(targetFile);
StreamUtils.copy(response.getBody(), out);
IOUtils.closeQuietly(out, ex -> log.error("close file error", ex));
log.info("{} download success ", targetFile);
return file;
return targetFile;
} else {
log.error("{} download error from {}: {} ", targetFile, driverFileUrl, response);
log.error("{} download error from {}: {} ", parentDir, driverFileUrl, response);
throw DomainErrors.DOWNLOAD_DRIVER_ERROR.exception("驱动下载失败:"
+ response.getStatusCode()
+ ", "
@ -97,7 +97,7 @@ public class DriverResources {
}
});
} catch (RestClientException e) {
log.error(targetFile + " download driver error", e);
log.error(parentDir + " download driver error", e);
throw DomainErrors.DOWNLOAD_DRIVER_ERROR.exception(e.getMessage());
}
}
@ -122,13 +122,13 @@ public class DriverResources {
}
public String resolveDriverClassNameFromRemote(String driverFileUrl) {
String tempFilePath = "temp/" + UUID.randomUUID() + ".jar";
File driverFile = download(driverFileUrl, tempFilePath);
DriverResult driverResult = tempLoadFromRemote(driverFileUrl);
File driverFile = driverResult.getDriverFile();
String className = resolveDriverClassName(driverFile);
try {
Files.deleteIfExists(driverFile.toPath());
} catch (IOException e) {
log.error("delete driver error " + tempFilePath, e);
log.error("delete driver error from " + driverResult.getDriverFilePath(), e);
}
return className;
}
@ -202,7 +202,7 @@ public class DriverResources {
}
public String copyToStandardDirectory(File sourceFile, String databaseType) {
String targetFile = targetDriverFile(databaseType);
String targetFile = targetDriverFile(databaseType, sourceFile.getName());
try {
Path target = Paths.get(targetFile);
Files.createDirectories(target.getParent());
@ -214,9 +214,9 @@ public class DriverResources {
}
}
private String targetDriverFile(String databaseType) {
private String targetDriverFile(String databaseType, String fileName) {
return driverBaseDirectory
+ "/" + databaseType
+ "/" + System.currentTimeMillis() + ".jar";
+ "/" + fileName;
}
}

View File

@ -38,7 +38,7 @@ class DatabaseTypeServiceTest extends BaseTest {
Mockito.doNothing().when(driverResources).validateDriverJar(any(), anyString());
Mockito.when(driverResources.load(any(), anyString(), anyString()))
.thenReturn(new DriverResult("", null));
Mockito.when(driverResources.loadFromRemote(any()))
Mockito.when(driverResources.tempLoadFromRemote(any()))
.thenReturn(new DriverResult("", null));
Mockito.when(driverResources.loadFromLocal(any()))
.thenReturn(new DriverResult("", null));

@ -1 +1 @@
Subproject commit 2c50a58ba5bcbbe28b8e7d76a66589c27454b6dc
Subproject commit 6dac399b514868bc6be0209da9c4cbb0f8759ca0