* Refactor zanodeModel::installService.
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
+26
-4
@@ -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,);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user