From 2f236ab2e8a609f7171377e57cf1dadb35d3c2e6 Mon Sep 17 00:00:00 2001 From: xieqiyu Date: Wed, 27 Dec 2023 16:31:20 +0800 Subject: [PATCH] * Refactor zanodeModel::installService. --- module/zanode/control.php | 2 +- module/zanode/model.php | 30 ------------------------------ module/zanode/zen.php | 30 ++++++++++++++++++++++++++---- 3 files changed, 27 insertions(+), 35 deletions(-) diff --git a/module/zanode/control.php b/module/zanode/control.php index d268e3e9b0..f288c0b254 100644 --- a/module/zanode/control.php +++ b/module/zanode/control.php @@ -532,7 +532,7 @@ class zanode extends control public function ajaxInstallService(int $nodeID, string $service) { $node = $this->zanode->getNodeById($nodeID); - $result = $this->zanode->installService($node, $service); + $result = $this->zanodeZen->installService($node, $service); return $this->send(array('result' => 'success', 'message' => '', 'data' => $result)); } diff --git a/module/zanode/model.php b/module/zanode/model.php index 8ba2619cbf..687785f6c8 100644 --- a/module/zanode/model.php +++ b/module/zanode/model.php @@ -662,36 +662,6 @@ class zanodemodel extends model return $returnData; } - /** - * 执行节点安装应用(支持ztf,zendata). - * Install service to node by name. - * - * @param object $node - * @param string $name - * @access public - * @return array - */ - public function installService($node, $name) - { - $param = array( - 'name' => strtolower($name), - 'secret' => $node->secret, - 'server' => getWebRoot(true), - ); - $result = json_decode(commonModel::http("http://{$node->ip}:{$node->zap}/api/v1/service/setup", json_encode($param), array(), array("Authorization:$node->tokenSN"))); - - if(empty($result->data) || $result->code != 'success') - { - $result = new stdclass; - return $this->lang->zanode->init->serviceStatus; - } - - return array( - 'ZenAgent' => 'ready', - 'ZTF' => $result->data->ztfStatus, - ); - } - /** * 通过 product id 获取自动化设置。 * Get automation by product id. diff --git a/module/zanode/zen.php b/module/zanode/zen.php index fd212a143c..1aae791911 100644 --- a/module/zanode/zen.php +++ b/module/zanode/zen.php @@ -155,16 +155,38 @@ class zanodeZen extends zanode * Get service status from host. * * @param object $node - * @access public + * @access protected * @return array */ - public function getServiceStatus(object $node): array + protected function getServiceStatus(object $node): array { $result = json_decode(commonModel::http("http://{$node->ip}:{$node->zap}/api/v1/service/check", json_encode(array('services' => 'all')), array(), array("Authorization:$node->tokenSN"), 'data', 'POST', 10)); if(empty($result->data->ztfStatus) || $result->code != 'success') return $this->lang->zanode->init->serviceStatus; - $statusData = array('ZenAgent' => 'ready', 'ZTF' => $result->data->ztfStatus); - return $statusData; + return array('ZenAgent' => 'ready', 'ZTF' => $result->data->ztfStatus); + } + + /** + * 执行节点安装应用(支持ztf,zendata). + * Install service to node by name. + * + * @param object $node + * @param string $name + * @access protected + * @return array + */ + protected function installService(object $node, string $name): array + { + $param = array( + 'name' => strtolower($name), + 'secret' => $node->secret, + 'server' => getWebRoot(true), + ); + $result = json_decode(commonModel::http("http://{$node->ip}:{$node->zap}/api/v1/service/setup", json_encode($param), array(), array("Authorization:$node->tokenSN"))); + + if(empty($result->data) || $result->code != 'success') return $this->lang->zanode->init->serviceStatus; + + return array('ZenAgent' => 'ready', 'ZTF' => $result->data->ztfStatus,); } }