diff --git a/backend/routes/system.go b/backend/routes/system.go index 8c443d2a..a63febb8 100644 --- a/backend/routes/system.go +++ b/backend/routes/system.go @@ -302,6 +302,20 @@ func InstallLang(c *gin.Context) { return } } + } else if reqBody.Lang == constants.Java { + if services.IsMasterNode(nodeId) { + _, err := services.InstallJavaLocalLang() + if err != nil { + HandleError(http.StatusInternalServerError, c, err) + return + } + } else { + _, err := services.InstallJavaRemoteLang(nodeId) + if err != nil { + HandleError(http.StatusInternalServerError, c, err) + return + } + } } else { HandleErrorF(http.StatusBadRequest, c, fmt.Sprintf("%s is not implemented", reqBody.Lang)) return diff --git a/backend/services/rpc.go b/backend/services/rpc.go index 3afaf7cb..6d733e66 100644 --- a/backend/services/rpc.go +++ b/backend/services/rpc.go @@ -54,6 +54,8 @@ func RpcClientInstallLang(nodeId string, lang string) (output string, err error) func RpcServerGetLang(msg RpcMessage) RpcMessage { langName := GetRpcParam("lang", msg.Params) lang := GetLangFromLangNamePlain(langName) + l := GetLangLocal(lang) + lang.InstallStatus = l.InstallStatus // 序列化 resultStr, _ := json.Marshal(lang) diff --git a/backend/services/system.go b/backend/services/system.go index dff4d029..d2eced84 100644 --- a/backend/services/system.go +++ b/backend/services/system.go @@ -139,7 +139,7 @@ func GetLangInstallStatus(nodeId string, lang entity.Lang) (string, error) { } } -func GetLangLocal(lang entity.Lang) entity.Lang{ +func GetLangLocal(lang entity.Lang) entity.Lang { // 检查是否存在执行路径 for _, p := range lang.ExecutablePaths { if utils.Exists(p) { @@ -198,6 +198,8 @@ func IsInstalledDep(installedDepList []entity.Dependency, dep entity.Dependency) return false } +// ========Python======== + // 初始化函数 func InitDepsFetcher() error { c := cron.New(cron.WithSeconds()) @@ -212,10 +214,6 @@ func InitDepsFetcher() error { return nil } -// ========= -// Python -// ========= - type PythonDepJsonData struct { Info PythonDepJsonDataInfo `json:"info"` } @@ -523,10 +521,11 @@ func UninstallPythonRemoteDep(nodeId string, depName string) (string, error) { return output, nil } -// ============== -// Node.js -// ============== +// ========./Python======== +// ========Node.js======== + +// 本地安装Node.js func InstallNodejsLocalLang() (string, error) { cmd := exec.Command("/bin/sh", path.Join("scripts", "install-nodejs.sh")) output, err := cmd.Output() @@ -541,7 +540,7 @@ func InstallNodejsLocalLang() (string, error) { return string(output), nil } -// 获取Node.js远端依赖列表 +// 远端安装Node.js func InstallNodejsRemoteLang(nodeId string) (string, error) { output, err := RpcClientInstallLang(nodeId, constants.Nodejs) if err != nil { @@ -671,3 +670,33 @@ func GetNodejsDepList(nodeId string, searchDepName string) (depList []entity.Dep return depList, nil } + +// ========./Node.js======== + +// ========Java======== + +// 本地安装Java +func InstallJavaLocalLang() (string, error) { + cmd := exec.Command("/bin/sh", path.Join("scripts", "install-java.sh")) + output, err := cmd.Output() + if err != nil { + log.Error(err.Error()) + debug.PrintStack() + return string(output), err + } + + // TODO: check if Java is installed successfully + + return string(output), nil +} + +// 远端安装Java +func InstallJavaRemoteLang(nodeId string) (string, error) { + output, err := RpcClientInstallLang(nodeId, constants.Java) + if err != nil { + return output, err + } + return output, nil +} + +// ========./Java======== diff --git a/frontend/src/components/Node/NodeInstallationMatrix.vue b/frontend/src/components/Node/NodeInstallationMatrix.vue index 0d3f1080..d1c0f195 100644 --- a/frontend/src/components/Node/NodeInstallationMatrix.vue +++ b/frontend/src/components/Node/NodeInstallationMatrix.vue @@ -150,9 +150,11 @@ export default { }, 1000) }, async onInstallAll (langName) { - this.nodeList.map(async n => { - return this.onInstall(n._id, langName) - }) + this.nodeList + .filter(n => n.status === 'online') + .forEach(n => { + this.onInstall(n._id, langName) + }) setTimeout(() => { this.getData() }, 1000)