实现了服务的增删改查、设备增加
This commit is contained in:
@@ -7,6 +7,7 @@ use Workerman\Protocols\Http\Response;
|
||||
require_once __DIR__ . '/vendor/autoload.php';
|
||||
|
||||
use EdgeManager\EDataCapture\{ EDataCapture, ENodeConfigure };
|
||||
use EdgeManager\EController\EConfigure;
|
||||
|
||||
$options = getopt('h::', ['no_dup_code', 'server_name:', 'port::', 'user:', 'password:', 'help::']);
|
||||
|
||||
@@ -108,7 +109,48 @@ $worker -> onMessage = function(TcpConnection $connection, Request $request) {
|
||||
'msg' => '服务器内部逻辑错误,请联系开发者!'
|
||||
)));
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (
|
||||
str_ends_with($post -> action, 'server')
|
||||
or str_ends_with($post -> action, 'device')
|
||||
) {
|
||||
$action = $post -> action;
|
||||
unset($post -> action);
|
||||
|
||||
if ($action === 'add_server') {
|
||||
$task_connection = new AsyncTcpConnection('Text://127.0.0.1:1888');
|
||||
$task_data = array(
|
||||
'action' => 'add_server',
|
||||
'data' => $post,
|
||||
);
|
||||
$task_connection -> send(json_encode($task_data));
|
||||
$task_connection -> onMessage = function(AsyncTcpConnection $task_connection, $task_result) use ($connection) {
|
||||
$task_connection -> close();
|
||||
$connection -> send($task_result);
|
||||
};
|
||||
// 执行异步连接
|
||||
$task_connection->connect();
|
||||
} else {
|
||||
$e_configure = new EConfigure($dbconn, post: $post);
|
||||
$res = $e_configure -> $action();
|
||||
|
||||
if ($res === true)
|
||||
$connection -> send(json_encode(array(
|
||||
'code' => 0,
|
||||
'msg' => 'Success'
|
||||
)));
|
||||
else if ($res === "REMAINING") {
|
||||
$connection -> send(json_encode(array(
|
||||
'code' => 1,
|
||||
'msg' => '该服务中仍有关联的设备,不允许删除!'
|
||||
)));
|
||||
} else if ($res === false) {
|
||||
$connection -> send(json_encode(array(
|
||||
'code' => 1,
|
||||
'msg' => '服务器内部逻辑错误,请联系开发者!'
|
||||
)));
|
||||
}
|
||||
}
|
||||
} else if ($post -> action === 'set_node_data') {
|
||||
$data_capture = new EDataCapture($dbconn, no_dup_code: $options['no_dup_code'] ?? true, post: $post);
|
||||
if ($data_capture -> check_res === 'WRONG_WORKING_SUBCLASS') {
|
||||
@@ -176,7 +218,7 @@ $worker -> onMessage = function(TcpConnection $connection, Request $request) {
|
||||
if (is_null($nodes))
|
||||
$connection -> send(json_encode(array(
|
||||
'code' => 1,
|
||||
'msg' => 'no node data yet'
|
||||
'msg' => '未添加过节点!'
|
||||
)));
|
||||
else
|
||||
$connection -> send(json_encode(array(
|
||||
@@ -227,6 +269,19 @@ $worker -> onMessage = function(TcpConnection $connection, Request $request) {
|
||||
'code' => 0,
|
||||
'data' => $data
|
||||
)));
|
||||
} else if ($get['query'] == 'servers') {
|
||||
$e_configure = new EConfigure($dbconn, get: $get);
|
||||
$nodes = $e_configure -> get_servers();
|
||||
if (is_null($nodes))
|
||||
$connection -> send(json_encode(array(
|
||||
'code' => 1,
|
||||
'msg' => '未添加过服务!'
|
||||
)));
|
||||
else
|
||||
$connection -> send(json_encode(array(
|
||||
'code' => 0,
|
||||
'data' => $nodes
|
||||
)));
|
||||
} else {
|
||||
$connection -> send(json_encode(array(
|
||||
'code' => 1,
|
||||
@@ -273,6 +328,26 @@ $consumer -> onMessage = function(TcpConnection $connection, $task_data) {
|
||||
'msg' => '服务器内部逻辑错误,请联系开发者!'
|
||||
)));
|
||||
}
|
||||
} else if ($task_data -> action === 'add_server') {
|
||||
$e_configure = new EConfigure($consumer_dbconn, post: $task_data -> data);
|
||||
$res = $e_configure -> add_server();
|
||||
|
||||
if ($res === true)
|
||||
$connection -> send(json_encode(array(
|
||||
'code' => 0,
|
||||
'msg' => 'Success'
|
||||
)));
|
||||
else if ($res === "REPLICATED")
|
||||
$connection -> send(json_encode(array(
|
||||
'code' => 1,
|
||||
'msg' => '该地址或名称已注册过服务!'
|
||||
)));
|
||||
else if ($res === false) {
|
||||
$connection -> send(json_encode(array(
|
||||
'code' => 1,
|
||||
'msg' => '服务器内部逻辑错误,请联系开发者!'
|
||||
)));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user