Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
L
loit-build-common
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
loit-Infrastructure
loit-build-common
Commits
3b445100
提交
3b445100
authored
5月 28, 2021
作者:
杨文彬
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
【修改】 实例sql脚本生产
上级
377a4bcd
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
148 行增加
和
0 行删除
+148
-0
GeneratorInstanceSQL.java
...ain/java/com/loit/common/script/GeneratorInstanceSQL.java
+148
-0
没有找到文件。
loit-build-component/loit-build-deploy-env/src/main/java/com/loit/common/script/GeneratorInstanceSQL.java
0 → 100644
浏览文件 @
3b445100
package
com
.
loit
.
common
.
script
;
import
com.loit.common.script.dto.BackendFrontEnum
;
import
com.loit.common.script.dto.DeployInfoDataDTO
;
import
com.loit.common.script.dto.FrontGroupEnum
;
import
com.loit.common.script.dto.FrontInstanceDto
;
import
com.loit.common.utils.DateUtils
;
import
com.loit.common.utils.ListUtil
;
import
com.loit.common.utils.StringUtils
;
import
com.loit.common.utils.excel.ImportExcel
;
import
com.loit.common.utils.file.FileUtils
;
import
com.loit.common.utils.freemarker.FreeMarkerUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.http.entity.ContentType
;
import
org.springframework.mock.web.MockMultipartFile
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileWriter
;
import
java.io.IOException
;
import
java.util.*
;
@Slf4j
public
class
GeneratorInstanceSQL
{
protected
static
String
root_path
=
"D:\\gitwork\\loit-build-common\\loit-build-component\\loit-build-deploy-env\\src\\main\\resources\\bin"
;
protected
static
String
root_path_full
=
root_path
+
"\\instance"
;
protected
static
String
sqlFile
=
root_path_full
+
"\\instancesql.sql"
;
private
static
Map
<
String
,
FrontInstanceDto
>
frontInstanceDtoMap
=
new
LinkedHashMap
<>();
public
static
void
main
(
String
[]
args
)
{
try
{
//String filePathStr = Thread.currentThread().getContextClassLoader().getResource("deployInfo.xlsx").getPath();
String
filePathStr
=
"D:\\gitwork\\loit-build-common\\loit-build-component\\loit-build-deploy-env\\src\\main\\resources\\deployInfo.xlsx"
;
File
pdfFile
=
new
File
(
filePathStr
);
FileInputStream
fileInputStream
=
new
FileInputStream
(
pdfFile
);
MultipartFile
multipartFile
=
new
MockMultipartFile
(
pdfFile
.
getName
(),
pdfFile
.
getName
(),
ContentType
.
APPLICATION_OCTET_STREAM
.
toString
(),
fileInputStream
);
ImportExcel
ei
=
new
ImportExcel
(
multipartFile
,
1
,
0
);
List
<
DeployInfoDataDTO
>
grayVersionDataDTOList
=
ei
.
getDataList
(
DeployInfoDataDTO
.
class
);
if
(
ListUtil
.
isEmpty
(
grayVersionDataDTOList
))
{
return
;
}
clearInfoForFile
(
sqlFile
);
for
(
DeployInfoDataDTO
grayVersionDataDTO
:
grayVersionDataDTOList
)
{
buildInstanceSQL
(
grayVersionDataDTO
);
}
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
}
}
/**
* 生成实例初始化脚本
*/
private
static
void
buildInstanceSQL
(
DeployInfoDataDTO
grayVersionDataDTO
)
throws
IOException
{
String
serviceName
=
grayVersionDataDTO
.
getServiceName
();
String
fixedIp
=
grayVersionDataDTO
.
getFixedIp
();
String
port
=
grayVersionDataDTO
.
getPort
();
String
nacosServiceName
=
grayVersionDataDTO
.
getNacosServiceName
();
String
backendFrontType
=
grayVersionDataDTO
.
getBackendFrontType
();
if
(
StringUtils
.
isBlank
(
serviceName
))
{
return
;
}
String
modelId
=
grayVersionDataDTO
.
getModelId
();
String
frontGroup
=
grayVersionDataDTO
.
getFrontGroup
();
String
instance_id
=
""
;
if
(
BackendFrontEnum
.
BACKEND
.
getCode
().
equals
(
backendFrontType
))
{
instance_id
=
fixedIp
+
"#"
+
port
+
"#DEFAULT#DEFAULT_GROUP@@"
+
nacosServiceName
;
frontGroup
=
""
;
}
String
jenkinsJobName
=
createJenkinsJobName
(
grayVersionDataDTO
);
String
dateTime
=
DateUtils
.
formatDate
(
new
Date
(),
"yyyy-MM-dd HH:mm:ss"
);
String
needCreateInstanceSql
=
grayVersionDataDTO
.
getNeedCreateInstanceSql
();
if
(!
"no"
.
equals
(
needCreateInstanceSql
))
{
String
sql
=
"insert into loit_gray_instance ( model_id, group_name, instance_id, instance_ip, instance_port, instance_version, instance_status, jenkins_job_name, jenkins_job_url, jenkins_job_check_url, restart_status, create_time, create_user, restart_time, restart_user, restart_log, down_jenkins_job_name, down_jenkins_job_url, down_jenkins_job_check_url, down_instance_user, down_instance_log, try_jenkins_count, try_down_jenkins_count, del_flag, network_key, instance_network_type) "
+
"values('"
+
modelId
+
"','"
+
frontGroup
+
"','"
+
instance_id
+
"','"
+
fixedIp
+
"','"
+
port
+
"','1.0.0','0','"
+
jenkinsJobName
+
"',NULL,NULL,'3','"
+
dateTime
+
"',NULL,NULL,NULL,'','',NULL,NULL,NULL,NULL,'0','0','0','net1','net1');"
;
FileUtils
.
appendNewLine
(
sqlFile
,
sql
);
}
}
private
static
String
createJenkinsJobName
(
DeployInfoDataDTO
grayVersionDataDTO
)
{
String
serviceName
=
grayVersionDataDTO
.
getServiceName
();
String
floatingIp
=
grayVersionDataDTO
.
getFloatingIp
();
String
fixedIp
=
grayVersionDataDTO
.
getFixedIp
();
String
port
=
grayVersionDataDTO
.
getPort
();
if
(
"getway"
.
equals
(
serviceName
))
{
serviceName
=
"gateway"
;
}
BackendFrontEnum
backendFrontType
=
BackendFrontEnum
.
getEnumByCode
(
grayVersionDataDTO
.
getBackendFrontType
());
String
[]
fIps
=
floatingIp
.
split
(
"\\."
);
String
fIp
=
fIps
[
3
];
String
[]
fixIps
=
fixedIp
.
split
(
"\\."
);
String
fixIp
=
fixIps
[
3
];
String
jenkinsJobName
=
""
;
if
(
BackendFrontEnum
.
BACKEND
.
equals
(
backendFrontType
))
{
jenkinsJobName
=
"loit-deploy-"
+
serviceName
+
"-"
+
port
+
"-"
+
fIp
+
"-"
+
fixIp
;
}
if
(!
BackendFrontEnum
.
BACKEND
.
equals
(
backendFrontType
))
{
jenkinsJobName
=
"loit-front-deploy-"
+
serviceName
+
"-"
+
port
+
"-"
+
fIp
+
"-"
+
fixIp
;
}
return
jenkinsJobName
;
}
public
static
void
clearInfoForFile
(
String
fileName
)
{
File
file
=
new
File
(
fileName
);
try
{
if
(!
file
.
exists
())
{
file
.
createNewFile
();
}
FileWriter
fileWriter
=
new
FileWriter
(
file
);
fileWriter
.
write
(
""
);
fileWriter
.
flush
();
fileWriter
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论