From 78a934a835b2111228dd0241308805d9a960ac38 Mon Sep 17 00:00:00 2001 From: zhaoke Date: Wed, 7 Dec 2022 03:51:25 +0000 Subject: [PATCH] * Add heartbeat --- api/v1/entries/zanodeheartbeat.php | 25 +++++++--- module/zahost/control.php | 11 ++--- module/zahost/css/{inithost.css => init.css} | 0 module/zahost/lang/de.php | 9 ++-- module/zahost/lang/en.php | 9 ++-- module/zahost/lang/fr.php | 9 ++-- module/zahost/lang/vi.php | 10 ++-- module/zahost/lang/zh-cn.php | 35 +++++++------- module/zahost/view/inithost.html.php | 16 +++---- module/zanode/control.php | 32 +++++++++++++ module/zanode/css/init.css | 16 +++++++ module/zanode/js/init.js | 25 ++++++++++ module/zanode/lang/de.php | 20 ++++++++ module/zanode/lang/en.php | 22 ++++++++- module/zanode/lang/fr.php | 20 ++++++++ module/zanode/lang/zh-cn.php | 20 ++++++++ module/zanode/model.php | 49 ++++++++++++++++++++ 17 files changed, 273 insertions(+), 55 deletions(-) rename module/zahost/css/{inithost.css => init.css} (100%) create mode 100644 module/zanode/css/init.css create mode 100644 module/zanode/js/init.js diff --git a/api/v1/entries/zanodeheartbeat.php b/api/v1/entries/zanodeheartbeat.php index ebfb8272ae..dc2af26f0f 100644 --- a/api/v1/entries/zanodeheartbeat.php +++ b/api/v1/entries/zanodeheartbeat.php @@ -33,19 +33,19 @@ class zanodeHeartbeatEntry extends baseEntry if(!$status || !$mac) return $this->sendError(400, 'Params error.'); $this->dao = $this->loadModel('common')->dao; - $hostID = $this->dao->select('id')->from(TABLE_ZAHOST) + $host = $this->dao->select('id,extranet')->from(TABLE_ZAHOST) ->beginIF($secret)->where('secret')->eq($secret)->fi() ->beginIF(!$secret)->where('tokenSN')->eq($token) ->andWhere('tokenTime')->gt($now)->fi() - ->fetch('id'); - if(!$hostID) return $this->sendError(400, 'Secret error.'); + ->fetch(); + if(empty($host)) return $this->sendError(400, 'Secret error.'); - $node = $this->dao->select('id')->from(TABLE_ZAHOST) + $node = $this->dao->select('id,parent')->from(TABLE_ZAHOST) ->where('mac')->eq($mac) ->fetch(); - if(empty($node) || ($node->parent != $hostID || $node->id != $hostID)) return $this->sendError(400, 'Secret error.'); + + if(empty($node) || ($node->parent != $host->id && $node->id != $host->id)) return $this->sendError(400, 'Secret error.'); - $node = new stdclass(); $node->zap = $this->requestBody->agentPortOnHost; $node->status = $this->requestBody->status; @@ -57,6 +57,19 @@ class zanodeHeartbeatEntry extends baseEntry $this->dao->update(TABLE_ZAHOST)->data($node)->where('id')->eq($node->id)->exec(); + if($secret) + { + //install services + $node->ip = $host->extranet; + $nodeStatus = $this->loadModel('zanode')->getServiceStatus($node); + if($nodeStatus['ZTF'] != "ready") + { + $node->secret = $secret; + $node->extranet = $host->extranet; + $this->loadModel('zanode')->installService($node, "ZTF"); + } + } + if(!$secret) return $this->sendSuccess(200, 'success'); $node->tokenTimeUnix = strtotime($node->tokenTime); diff --git a/module/zahost/control.php b/module/zahost/control.php index 299128697a..62811fb8cc 100644 --- a/module/zahost/control.php +++ b/module/zahost/control.php @@ -95,13 +95,13 @@ class zahost extends control return $this->send(array('result' => 'fail', 'message' => array("extranet" => array($this->lang->zahost->netError)))); } - $initLink = $this->createLink('zahost', 'inithost', "hostID=$hostID"); + $initLink = $this->createLink('zahost', 'init', "hostID=$hostID"); return print(""); } $this->view->title = $this->lang->zahost->create; - $this->view->notice = $this->lang->zahost->initHostNotice; - $this->view->buttonName = $this->lang->zahost->init; + $this->view->notice = $this->lang->zahost->initNotice; + $this->view->buttonName = $this->lang->zahost->initTitle; $this->display(); } @@ -325,11 +325,11 @@ class zahost extends control * @param int $hostID * @return void */ - public function initHost($hostID) + public function init($hostID) { $imageList = $this->zahost->getImagePairs($hostID); - $this->view->title = $this->lang->zahost->init; + $this->view->title = $this->lang->zahost->initTitle; $this->view->users = $this->loadModel('user')->getPairs('noletter|nodeleted'); $this->view->hostID = $hostID; $this->view->host = $this->zahost->getById($hostID); @@ -344,7 +344,6 @@ class zahost extends control * Check service status by ajax. * * @param int $hostID - * @param int $templateID * @access public * @return void */ diff --git a/module/zahost/css/inithost.css b/module/zahost/css/init.css similarity index 100% rename from module/zahost/css/inithost.css rename to module/zahost/css/init.css diff --git a/module/zahost/lang/de.php b/module/zahost/lang/de.php index 060e3e081d..ef8fe4f36f 100644 --- a/module/zahost/lang/de.php +++ b/module/zahost/lang/de.php @@ -37,7 +37,7 @@ $lang->zahost->os = 'System'; $lang->zahost->imageName = 'Image File'; $lang->zahost->createZanode = 'Create Zanode'; -$lang->zahost->initHostNotice = 'Save successfully, initialize the ZAhost or return list'; +$lang->zahost->initNotice = 'Save successfully, initialize the ZAhost or return list'; $lang->zahost->createZanodeNotice = 'Initialization successful, ready to create the zanode'; $lang->zahost->downloadImageNotice = 'Initialization successful, download the image to create zanode'; $lang->zahost->undeletedNotice = "The host has nodes that cannot be deleted."; @@ -53,9 +53,10 @@ $lang->zahost->initHost->next = "Next"; $lang->zahost->initHost->initFailNoticeTitle = "Initialization failed, check the init script execution log and try the following two solutions:"; $lang->zahost->initHost->initFailNoticeDesc = "1. Re-execute the script
2. Review the initialization FAQ"; -$lang->zahost->initHost->serviceStatus = [ - "kvm" => 'not_install', - "novnc" => 'not_install', +$lang->zahost->init->serviceStatus = [ + "kvm" => 'not_install', + "nginx" => 'not_install', + "novnc" => 'not_install', "websockify" => 'not_install', ]; $lang->zahost->initHost->title = "Initialize Host"; diff --git a/module/zahost/lang/en.php b/module/zahost/lang/en.php index 0e97d396e1..3d181626b3 100644 --- a/module/zahost/lang/en.php +++ b/module/zahost/lang/en.php @@ -37,7 +37,7 @@ $lang->zahost->os = 'System'; $lang->zahost->imageName = 'Image File'; $lang->zahost->createZanode = 'Create Zanode'; -$lang->zahost->initHostNotice = 'Save successfully, initialize the ZAhost or return list'; +$lang->zahost->initNotice = 'Save successfully, initialize the ZAhost or return list'; $lang->zahost->createZanodeNotice = 'Initialization successful, ready to create the zanode'; $lang->zahost->downloadImageNotice = 'Initialization successful, download the image to create zanode'; $lang->zahost->undeletedNotice = "The host has nodes that cannot be deleted."; @@ -53,9 +53,10 @@ $lang->zahost->initHost->next = "Next"; $lang->zahost->initHost->initFailNoticeTitle = "Initialization failed, check the init script execution log and try the following two solutions:"; $lang->zahost->initHost->initFailNoticeDesc = "1. Re-execute the script
2. Review the initialization FAQ"; -$lang->zahost->initHost->serviceStatus = [ - "kvm" => 'not_install', - "novnc" => 'not_install', +$lang->zahost->init->serviceStatus = [ + "kvm" => 'not_install', + "nginx" => 'not_install', + "novnc" => 'not_install', "websockify" => 'not_install', ]; $lang->zahost->initHost->title = "Initialize Host"; diff --git a/module/zahost/lang/fr.php b/module/zahost/lang/fr.php index 0f1387bd4a..73fe73ec20 100644 --- a/module/zahost/lang/fr.php +++ b/module/zahost/lang/fr.php @@ -37,7 +37,7 @@ $lang->zahost->os = 'System'; $lang->zahost->imageName = 'Image File'; $lang->zahost->createZanode = 'Create Zanode'; -$lang->zahost->initHostNotice = 'Save successfully, initialize the ZAhost or return list'; +$lang->zahost->initNotice = 'Save successfully, initialize the ZAhost or return list'; $lang->zahost->createZanodeNotice = 'Initialization successful, ready to create the zanode'; $lang->zahost->downloadImageNotice = 'Initialization successful, download the image to create zanode'; $lang->zahost->undeletedNotice = "The host has nodes that cannot be deleted."; @@ -53,9 +53,10 @@ $lang->zahost->initHost->next = "Next"; $lang->zahost->initHost->initFailNoticeTitle = "Initialization failed, check the init script execution log and try the following two solutions:"; $lang->zahost->initHost->initFailNoticeDesc = "1. Re-execute the script
2. Review the initialization FAQ"; -$lang->zahost->initHost->serviceStatus = [ - "kvm" => 'not_install', - "novnc" => 'not_install', +$lang->zahost->init->serviceStatus = [ + "kvm" => 'not_install', + "nginx" => 'not_install', + "novnc" => 'not_install', "websockify" => 'not_install', ]; $lang->zahost->initHost->title = "Initialize Host"; diff --git a/module/zahost/lang/vi.php b/module/zahost/lang/vi.php index 3ab6b219af..f8ad646fef 100644 --- a/module/zahost/lang/vi.php +++ b/module/zahost/lang/vi.php @@ -40,7 +40,7 @@ $lang->zahost->osLang = 'Language'; $lang->zahost->imageName = 'Image File'; $lang->zahost->createZanode = 'Create Zanode'; -$lang->zahost->initHostNotice = 'Save successfully, initialize the ZAhost or return list'; +$lang->zahost->initNotice = 'Save successfully, initialize the ZAhost or return list'; $lang->zahost->createZanodeNotice = 'Initialization successful, ready to create the zanode'; $lang->zahost->downloadImageNotice = 'Initialization successful, download the image to create zanode'; $lang->zahost->netError = 'Unable to connect to the host, please check the network and try again.'; @@ -56,10 +56,10 @@ $lang->zahost->initHost->initSuccessNotice = "The initialization was successfu $lang->zahost->initHost->initFailNoticeTitle = "Initialization failed, check the init script execution log and try the following two solutions:"; $lang->zahost->initHost->initFailNoticeDesc = "1. Re-execute the script
2. Review the initialization FAQ"; -$lang->zahost->initHost->serviceStatus = [ - "nginx" => 'not_install', - "kvm" => 'not_install', - "novnc" => 'not_install', +$lang->zahost->init->serviceStatus = [ + "kvm" => 'not_install', + "nginx" => 'not_install', + "novnc" => 'not_install', "websockify" => 'not_install', ]; $lang->zahost->initHost->title = "Initialize Host"; diff --git a/module/zahost/lang/zh-cn.php b/module/zahost/lang/zh-cn.php index 97758d02c1..bf08e43c48 100644 --- a/module/zahost/lang/zh-cn.php +++ b/module/zahost/lang/zh-cn.php @@ -37,31 +37,32 @@ $lang->zahost->os = '操作系统'; $lang->zahost->imageName = '镜像文件'; $lang->zahost->createZanode = '创建执行节点'; -$lang->zahost->initHostNotice = '保存成功,请您初始化宿主机或返回列表。'; +$lang->zahost->initNotice = '保存成功,请您初始化宿主机或返回列表。'; $lang->zahost->createZanodeNotice = '初始化成功,您现在可以创建执行节点了。'; $lang->zahost->downloadImageNotice = '初始化成功,请下载镜像用于创建执行节点。'; $lang->zahost->undeletedNotice = "宿主机下存在执行节点无法删除。"; $lang->zahost->netError = '无法连接到宿主机,请检查网络后重试。'; -$lang->zahost->initHost = new stdclass; -$lang->zahost->initHost->statusTitle = "服务状态"; -$lang->zahost->initHost->checkStatus = "检测服务状态"; -$lang->zahost->initHost->not_install = "未安装"; -$lang->zahost->initHost->not_available = "已安装,未启动"; -$lang->zahost->initHost->ready = "已就绪"; -$lang->zahost->initHost->next = "下一步"; +$lang->zahost->init = new stdclass; +$lang->zahost->init->statusTitle = "服务状态"; +$lang->zahost->init->checkStatus = "检测服务状态"; +$lang->zahost->init->not_install = "未安装"; +$lang->zahost->init->not_available = "已安装,未启动"; +$lang->zahost->init->ready = "已就绪"; +$lang->zahost->init->next = "下一步"; -$lang->zahost->initHost->initFailNoticeTitle = "初始化失败,请查看初始化脚本执行日志并尝试以下两种解决方案:"; -$lang->zahost->initHost->initFailNoticeDesc = "1. 重新执行脚本
2. 查看初始化常见问题"; -$lang->zahost->initHost->serviceStatus = [ - "kvm" => 'not_install', - "novnc" => 'not_install', +$lang->zahost->init->initFailNoticeTitle = "初始化失败,请查看初始化脚本执行日志并尝试以下两种解决方案:"; +$lang->zahost->init->initFailNoticeDesc = "1. 重新执行脚本
2. 查看初始化常见问题"; +$lang->zahost->init->serviceStatus = [ + "kvm" => 'not_install', + "nginx" => 'not_install', + "novnc" => 'not_install', "websockify" => 'not_install', ]; -$lang->zahost->initHost->title = "初始化宿主机"; -$lang->zahost->initHost->descTitle = "请根据引导完成宿主机上的初始化: "; -$lang->zahost->initHost->initDesc = "1. 在宿主机上执行:bash <(curl -s -S -L https://pkg.qucheng.com/zenagent/zagent.sh) -k "; -$lang->zahost->initHost->statusTitle = "Service Status"; +$lang->zahost->init->title = "初始化宿主机"; +$lang->zahost->init->descTitle = "请根据引导完成宿主机上的初始化: "; +$lang->zahost->init->initDesc = "1. 在宿主机上执行:bash <(curl -s -S -L https://pkg.qucheng.com/zenagent/zagent.sh) -k "; +$lang->zahost->init->statusTitle = "服务状态"; $lang->zahost->image = new stdclass; $lang->zahost->image->list = '镜像仓库'; diff --git a/module/zahost/view/inithost.html.php b/module/zahost/view/inithost.html.php index 5b60032229..d1ed31ab37 100644 --- a/module/zahost/view/inithost.html.php +++ b/module/zahost/view/inithost.html.php @@ -1,7 +1,7 @@ - -zahost); ?> + +zanode); ?>
-

zahost->initHost->title; ?>

+

zanode->init->title; ?>

-

zahost->initHost->descTitle; ?>

+

zanode->init->descTitle; ?>

- zahost->initHost->initDesc . ' ' . $host->secret . ' -z ' . getWebRoot(true); ?> + zanode->init->initDesc . ' ' . $node->secret . ' -z ' . getWebRoot(true); ?>
@@ -34,10 +34,10 @@
- +
- + diff --git a/module/zanode/control.php b/module/zanode/control.php index a5ef74c9a8..cdb5d2cad5 100644 --- a/module/zanode/control.php +++ b/module/zanode/control.php @@ -123,6 +123,23 @@ class zanode extends control $this->display(); } + /* + * Init node. + * + * @param int $hostID + * @return void + */ + public function init($nodeID) + { + $this->view->title = $this->lang->zanode->initTitle; + $this->view->users = $this->loadModel('user')->getPairs('noletter|nodeleted'); + $this->view->nodeID = $nodeID; + $this->view->node = $this->zanode->getNodeById($nodeID); + // $this->view->modalLink = $imageList ? $this->createLink('zanode', 'create', "nodeID=$nodeID") : $this->createLink('zanode', 'browseImage', "nodeID=$nodeID"); + + $this->display(); + } + /** * Suspend Node. * @@ -329,4 +346,19 @@ class zanode extends control return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess)); } } + + /** + * Check service status by ajax. + * + * @param int $nodeID + * @access public + * @return void + */ + public function ajaxGetServiceStatus($hostID) + { + $node = $this->zanode->getNodeById($hostID); + $serviceStatus = $this->zanode->getServiceStatus($node); + + return $this->send(array('result' => 'success', 'message' => '', 'data' => $serviceStatus)); + } } diff --git a/module/zanode/css/init.css b/module/zanode/css/init.css new file mode 100644 index 0000000000..adb9649d82 --- /dev/null +++ b/module/zanode/css/init.css @@ -0,0 +1,16 @@ +.dot-symbol{ + margin-right: 10px; +} +#statusContainer h5{ + line-height: 20px; +} +.host-desc-container{ + margin-top: 20px; +} +.host-action{ + margin-top: 60px; +} +.host-action .btn{ + margin-left: 20px; + min-width: 100px; +} diff --git a/module/zanode/js/init.js b/module/zanode/js/init.js new file mode 100644 index 0000000000..e59547b527 --- /dev/null +++ b/module/zanode/js/init.js @@ -0,0 +1,25 @@ +$('#checkServiceStatus').click(function(){ + $.get(createLink('zanode', 'ajaxGetServiceStatus', 'nodeID=' + nodeID), function(response) + { + var resultData = JSON.parse(response); + let html = "

" + zanodeLang.init.statusTitle + "

"; + let isSuccess = true + + for (let key in resultData.data) { + if(resultData.data[key] == 'ready'){ + html += "
●" + key + ' ' + zanodeLang.init[resultData.data[key]] + "
" + }else{ + isSuccess = false + html += "
●" + key + ' ' + zanodeLang.init[resultData.data[key]] + "
" + } + }; + + if(!isSuccess){ + html += '

' + zanodeLang.init.initFailNoticeTitle + '

'; + html += '
' + zanodeLang.init.initFailNoticeDesc + 'https://github.com/easysoft/zenagent/
' + } + $('#statusContainer').html(html) + if(isSuccess) showModal(); + }); + return +}) diff --git a/module/zanode/lang/de.php b/module/zanode/lang/de.php index fb5352dff4..5850367805 100644 --- a/module/zanode/lang/de.php +++ b/module/zanode/lang/de.php @@ -4,6 +4,7 @@ $lang->zanode->browse = 'Execution Node List'; $lang->zanode->create = 'Create Execution Node'; $lang->zanode->editAction = 'Edit Execution Node'; $lang->zanode->view = 'View Execution Node'; +$lang->zanode->initTitle = 'Init ZenAgent Node'; $lang->zanode->suspend = 'Suspend Execution Node'; $lang->zanode->destroy = 'Destroy Execution Node'; $lang->zanode->handleVM = 'Restart Execution Node'; @@ -67,3 +68,22 @@ $lang->zanode->statusList['suspend'] = 'Suspend'; $lang->zanode->statusList['offline'] = 'Offline'; $lang->zanode->statusList['destroy'] = 'Destroyed'; $lang->zanode->statusList['destroy_fail'] = 'Destroy Fail'; + +$lang->zanode->init = new stdclass; +$lang->zanode->init->checkStatus = "Check Service Status"; +$lang->zanode->init->not_install = "Not installed"; +$lang->zanode->init->not_available = "Installed, Not Started"; +$lang->zanode->init->ready = "Ready"; +$lang->zanode->init->next = "Next"; + +$lang->zanode->init->initFailNoticeTitle = "Initialization failed, check the init script execution log and try the following two solutions:"; +$lang->zanode->init->initFailNoticeDesc = "1. Re-execute the script
2. Review the initialization FAQ"; + +$lang->zanode->init->serviceStatus = [ + "ZenAgent" => 'not_install', + "ZTF" => 'not_install', +]; +$lang->zanode->init->title = "Initialize Node"; +$lang->zanode->init->descTitle = "Follow these steps to complete the initialization on the node:"; +$lang->zanode->init->initDesc = "Execute the init script on the node: bash <(curl -s -S -L https://pkg.qucheng.com/zenagent/zagent.sh) -s vm "; +$lang->zanode->init->statusTitle = "Service Status"; \ No newline at end of file diff --git a/module/zanode/lang/en.php b/module/zanode/lang/en.php index fb5352dff4..7ba7d6a590 100644 --- a/module/zanode/lang/en.php +++ b/module/zanode/lang/en.php @@ -4,6 +4,7 @@ $lang->zanode->browse = 'Execution Node List'; $lang->zanode->create = 'Create Execution Node'; $lang->zanode->editAction = 'Edit Execution Node'; $lang->zanode->view = 'View Execution Node'; +$lang->zanode->initTitle = 'Init ZenAgent Node'; $lang->zanode->suspend = 'Suspend Execution Node'; $lang->zanode->destroy = 'Destroy Execution Node'; $lang->zanode->handleVM = 'Restart Execution Node'; @@ -48,7 +49,7 @@ $lang->zanode->noVncPort = 'Failed to get vnc port'; $lang->zanode->nameValid = "The name can only be letters, numbers, '-', '_', '.', and cannot start with a symbol"; $lang->zanode->empty = 'No zanode is found'; -$lang->zanode->empty = 'No Execution Node'; +$lang->zanode->empty = 'No ZenAgent Node'; $lang->zanode->createImaging = 'Creating'; $lang->zanode->createImageNotice = 'The system will be created based on the current node,This process requires the execution node to be shut down. Do you want to continue?'; $lang->zanode->createImageSuccess = 'Successed, You can use this image to create node. Created'; @@ -67,3 +68,22 @@ $lang->zanode->statusList['suspend'] = 'Suspend'; $lang->zanode->statusList['offline'] = 'Offline'; $lang->zanode->statusList['destroy'] = 'Destroyed'; $lang->zanode->statusList['destroy_fail'] = 'Destroy Fail'; + +$lang->zanode->init = new stdclass; +$lang->zanode->init->checkStatus = "Check Service Status"; +$lang->zanode->init->not_install = "Not installed"; +$lang->zanode->init->not_available = "Installed, Not Started"; +$lang->zanode->init->ready = "Ready"; +$lang->zanode->init->next = "Next"; + +$lang->zanode->init->initFailNoticeTitle = "Initialization failed, check the init script execution log and try the following two solutions:"; +$lang->zanode->init->initFailNoticeDesc = "1. Re-execute the script
2. Review the initialization FAQ"; + +$lang->zanode->init->serviceStatus = [ + "ZenAgent" => 'not_install', + "ZTF" => 'not_install', +]; +$lang->zanode->init->title = "Initialize Node"; +$lang->zanode->init->descTitle = "Follow these steps to complete the initialization on the node:"; +$lang->zanode->init->initDesc = "Execute the init script on the node: bash <(curl -s -S -L https://pkg.qucheng.com/zenagent/zagent.sh) -s vm "; +$lang->zanode->init->statusTitle = "Service Status"; \ No newline at end of file diff --git a/module/zanode/lang/fr.php b/module/zanode/lang/fr.php index fb5352dff4..5850367805 100644 --- a/module/zanode/lang/fr.php +++ b/module/zanode/lang/fr.php @@ -4,6 +4,7 @@ $lang->zanode->browse = 'Execution Node List'; $lang->zanode->create = 'Create Execution Node'; $lang->zanode->editAction = 'Edit Execution Node'; $lang->zanode->view = 'View Execution Node'; +$lang->zanode->initTitle = 'Init ZenAgent Node'; $lang->zanode->suspend = 'Suspend Execution Node'; $lang->zanode->destroy = 'Destroy Execution Node'; $lang->zanode->handleVM = 'Restart Execution Node'; @@ -67,3 +68,22 @@ $lang->zanode->statusList['suspend'] = 'Suspend'; $lang->zanode->statusList['offline'] = 'Offline'; $lang->zanode->statusList['destroy'] = 'Destroyed'; $lang->zanode->statusList['destroy_fail'] = 'Destroy Fail'; + +$lang->zanode->init = new stdclass; +$lang->zanode->init->checkStatus = "Check Service Status"; +$lang->zanode->init->not_install = "Not installed"; +$lang->zanode->init->not_available = "Installed, Not Started"; +$lang->zanode->init->ready = "Ready"; +$lang->zanode->init->next = "Next"; + +$lang->zanode->init->initFailNoticeTitle = "Initialization failed, check the init script execution log and try the following two solutions:"; +$lang->zanode->init->initFailNoticeDesc = "1. Re-execute the script
2. Review the initialization FAQ"; + +$lang->zanode->init->serviceStatus = [ + "ZenAgent" => 'not_install', + "ZTF" => 'not_install', +]; +$lang->zanode->init->title = "Initialize Node"; +$lang->zanode->init->descTitle = "Follow these steps to complete the initialization on the node:"; +$lang->zanode->init->initDesc = "Execute the init script on the node: bash <(curl -s -S -L https://pkg.qucheng.com/zenagent/zagent.sh) -s vm "; +$lang->zanode->init->statusTitle = "Service Status"; \ No newline at end of file diff --git a/module/zanode/lang/zh-cn.php b/module/zanode/lang/zh-cn.php index a24562f30d..3912a217b0 100644 --- a/module/zanode/lang/zh-cn.php +++ b/module/zanode/lang/zh-cn.php @@ -4,6 +4,7 @@ $lang->zanode->browse = '执行节点列表'; $lang->zanode->create = '创建执行节点'; $lang->zanode->editAction = '编辑执行节点'; $lang->zanode->view = '执行节点详情'; +$lang->zanode->initTitle = '初始化执行节点'; $lang->zanode->suspend = '暂停执行节点'; $lang->zanode->destroy = '销毁执行节点'; $lang->zanode->handleVM = '重启执行节点'; @@ -67,3 +68,22 @@ $lang->zanode->statusList['suspend'] = '暂停'; $lang->zanode->statusList['offline'] = '下线'; $lang->zanode->statusList['destroy'] = '已销毁'; $lang->zanode->statusList['destroy_fail'] = '销毁失败'; + +$lang->zanode->init = new stdclass; +$lang->zanode->init->statusTitle = "服务状态"; +$lang->zanode->init->checkStatus = "检测服务状态"; +$lang->zanode->init->not_install = "未安装"; +$lang->zanode->init->not_available = "已安装,未启动"; +$lang->zanode->init->ready = "已就绪"; +$lang->zanode->init->next = "下一步"; + +$lang->zanode->init->initFailNoticeTitle = "初始化失败,请查看初始化脚本执行日志并尝试以下两种解决方案:"; +$lang->zanode->init->initFailNoticeDesc = "1. 重新执行脚本
2. 查看初始化常见问题"; +$lang->zanode->init->serviceStatus = [ + "ZenAgent" => 'not_install', + "ZTF" => 'not_install', +]; +$lang->zanode->init->title = "初始化执行节点"; +$lang->zanode->init->descTitle = "请根据引导完成执行节点上的初始化: "; +$lang->zanode->init->initDesc = "1. 在执行节点上执行:bash <(curl -s -S -L https://pkg.qucheng.com/zenagent/zagent.sh) -s vm "; +$lang->zanode->init->statusTitle = "Service Status"; \ No newline at end of file diff --git a/module/zanode/model.php b/module/zanode/model.php index b0182c85f5..5407f55889 100644 --- a/module/zanode/model.php +++ b/module/zanode/model.php @@ -576,4 +576,53 @@ class zanodemodel extends model return $menu; } + + /** + * Get service status from ZAgent server. + * + * @param object $node + * @access public + * @return array + */ + public function getServiceStatus($node) + { + $result = json_decode(commonModel::http("http://{$node->ip}:{$node->zap}/api/v1/service/check", json_encode(array("services" => "all")), array(), array("Authorization:$node->tokenSN"))); + if(empty($result->data) || $result->code != 'success') + { + $result = new stdclass; + $result->data = $this->lang->zanode->init->serviceStatus; + } + + return array( + "ZenAgent" => "ready", + "ZTF" => $result->data->ztfStatus, + ); + } + + /** + * Install service. + * + * @param object $node + * @access public + * @return array + */ + public function installService($node, $name) + { + $param = array( + "name" => $name, + "secret" => $node->secret, + "server" => getWebRoot(true), + ); + $result = json_decode(commonModel::http("http://{$node->extranet}:{$node->zap}/api/v1/service/setup", json_encode($param), array(), array("Authorization:$node->tokenSN"))); + if(empty($result->data) || $result->code != 'success') + { + $result = new stdclass; + $result->data = $this->lang->zanode->init->serviceStatus; + } + + return array( + "ZenAgent" => "ready", + "ZTF" => $result->data->ztfStatus, + ); + } }