[ Agent ] [ App ] - add mysql init

This commit is contained in:
zeaslity
2023-11-27 11:09:44 +08:00
parent 95a2da2059
commit 2b53a2d62a
4 changed files with 154 additions and 17 deletions

View File

@@ -3,11 +3,16 @@ package executor
import (
"fmt"
"net"
"os"
"path/filepath"
"sort"
"strings"
"time"
)
type OctopusFunc interface {
Command(baseFuncName string, funcArgs ...string) []string
Exec(baseFuncName string, funcArgs ...string) (bool, []string)
Deploy(appFuncName string, funcArgs ...string) (bool, []string)
@@ -484,7 +489,75 @@ func (op *AgentOsOperator) deployMySQL(funcArgs []string) (bool, []string) {
}
func (op *AgentOsOperator) loadMysqlInitScript(funcArgs []string) (bool, []string) {
return true, nil
// download offline sql list
if len(funcArgs) <= 7 {
return false, []string{
"[loadMysqlInitScript]- MySQL初始化参数有误 无法进行初始化",
}
}
jackeyLove := funcArgs[8]
if !strings.HasSuffix(jackeyLove, "tar.gz") {
return false, []string{
"[loadMysqlInitScript]- jackeyLove 有误!",
}
}
jackeyLoveLocalPrefix := "/root/wdd/jackeylove/"
BasicCreateFolder(jackeyLoveLocalPrefix)
ok, resultLog := BasicDownloadFile(op.OssOfflinePrefix+"jackeyLove", jackeyLoveLocalPrefix+jackeyLove)
if !ok {
return false, append(resultLog, "[loadMysqlInitScript]- jackeyLove 下载失败!")
}
// unzip
if !PureResultSingleExecute([]string{
"tar",
"-vxf",
jackeyLoveLocalPrefix + jackeyLove,
"-C",
jackeyLoveLocalPrefix,
}) {
return false, []string{
"[loadMysqlInitScript]- jackeyLove unzip error ",
}
}
// list all sql file and sort and convert to []string
files, err := os.ReadDir(jackeyLoveLocalPrefix)
if err != nil {
return false, []string{
"[loadMysqlInitScript]- read unzipped jackeylove error ",
}
}
var jackeyLoveFileList []string
for _, file := range files {
if !file.IsDir() && filepath.Ext(file.Name()) == ".sql" {
jackeyLoveFileList = append(jackeyLoveFileList, file.Name())
}
}
sort.Strings(jackeyLoveFileList)
log.InfoF("[loadMysqlInitScript] - all jackey love files are => %v", jackeyLoveFileList)
// dispatch mysql execution command
jackeyLoveIP := funcArgs[0]
parseIP := net.ParseIP(jackeyLoveIP)
if parseIP == nil {
return false, []string{
"[loadMysqlInitScript]- ip config error ",
}
}
load, result := MysqlSqlFileLoad(jackeyLoveFileList)
if !load {
return false, result
}
return true, []string{
"[loadMysqlInitScript] - execute success !",
}
}
func (op *AgentOsOperator) checkMySQL(funcArgs []string) (bool, []string) {
@@ -520,7 +593,7 @@ func (op *AgentOsOperator) deployMiddlewares(funcArgs []string) (bool, []string)
ip := net.ParseIP(funcArgs[0])
if ip == nil {
return false, append(result,
"ip args error !")
"[deployMiddlewares] - ip args error !")
}
if !BasicReplace(k8sMiddlewaresYamlFile, "A1C2IP", funcArgs[0]) {
result = append(result, "替换A1C2IP信息")
@@ -534,7 +607,7 @@ func (op *AgentOsOperator) deployMiddlewares(funcArgs []string) (bool, []string)
// 替换版本号
if !BasicReplace(k8sMiddlewaresYamlFile, "KIMMY", funcArgs[6]) {
log.WarnF("[deployPVC] - pvc config version replace error , expected => %s", funcArgs[6])
log.WarnF("[deployMiddlewares] - pvc config version replace error , expected => %s", funcArgs[6])
}
// 启动服务
@@ -553,14 +626,14 @@ func (op *AgentOsOperator) deployMiddlewares(funcArgs []string) (bool, []string)
for _, podName := range podNameList {
if !K8sCheckPodStatusTimeout(podName, funcArgs[1], 180) {
return false, []string{
fmt.Sprintf("Namepsace [%s] Pod [%s] 启动失败!", funcArgs[1], podName),
fmt.Sprintf("[deployMiddlewares] - Namepsace [%s] Pod [%s] 启动失败!", funcArgs[1], podName),
}
}
}
// 成功启动
return true, append(podNameList,
"中间件部署成功!",
"[deployMiddlewares] - 中间件部署成功!",
)
}