diff --git a/app/Console/Commands/Cluster/Log.php b/app/Console/Commands/Cluster/Log.php index 7d925e1..70bd078 100644 --- a/app/Console/Commands/Cluster/Log.php +++ b/app/Console/Commands/Cluster/Log.php @@ -2,7 +2,7 @@ namespace App\Console\Commands\Cluster; -use App\Support\Cluster; +use App\Support\ClusterSupport; use Illuminate\Console\Command; use Symfony\Component\Console\Command\Command as CommandAlias; @@ -29,7 +29,7 @@ class Log extends Command */ public function handle(): int { - Cluster::listen('*', function ($event, $message) { + ClusterSupport::listen('*', function ($event, $message) { $this->format($event, $message); }, false); @@ -55,7 +55,7 @@ public function switch($event, $message = []): string|null 'node.ok' => '此节点初始化成功,并且已经加入集群。', 'node.online' => '此节点已经上线。', 'node.offline' => '将不再处理任何任务。', - 'cluster_ready.ok' => 'Cluster Ready 就绪了,已经可以处理请求了。', + 'cluster_ready.ok' => 'ClusterSupport Ready 就绪了,已经可以处理请求了。', 'config.updated' => '集群配置文件已经更新,请所有 slave 节点下载。', 'config.synced' => '我已下载配置文件。', 'edge.deployed' => '已成功根据集群节点生成配置文件并应用。', diff --git a/app/Console/Commands/Cluster/Restart.php b/app/Console/Commands/Cluster/Restart.php index 41f2a1d..6537bc3 100644 --- a/app/Console/Commands/Cluster/Restart.php +++ b/app/Console/Commands/Cluster/Restart.php @@ -2,7 +2,7 @@ namespace App\Console\Commands\Cluster; -use App\Support\Cluster; +use App\Support\ClusterSupport; use Illuminate\Console\Command; use Symfony\Component\Console\Command\Command as CommandAlias; @@ -37,7 +37,7 @@ public function handle(): int return CommandAlias::FAILURE; } - Cluster::publish('cluster.restart.' . $service); + ClusterSupport::publish('cluster.restart.' . $service); $this->info('已经向集群广播重启命令,等待集群响应。'); diff --git a/app/Console/Commands/Cluster/Sync.php b/app/Console/Commands/Cluster/Sync.php index 249a332..019a619 100644 --- a/app/Console/Commands/Cluster/Sync.php +++ b/app/Console/Commands/Cluster/Sync.php @@ -2,7 +2,7 @@ namespace App\Console\Commands\Cluster; -use App\Support\Cluster; +use App\Support\ClusterSupport; use Illuminate\Console\Command; use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Storage; @@ -54,12 +54,12 @@ public function handle(): int } $cache_key = "master_config_zip"; - $config = Cluster::get($cache_key); + $config = ClusterSupport::get($cache_key); if ($config) { $this->info('检查下载目录的 MD5 值。'); $config_md5_key = "master_config_zip_md5"; - $config_md5 = Cluster::get($config_md5_key, ''); + $config_md5 = ClusterSupport::get($config_md5_key, ''); $md5 = md5($config); if ($md5 !== $config_md5) { @@ -97,8 +97,8 @@ public function handle(): int $env_cache_key = "{$node_type}_env"; $env_md5_key = "{$node_type}_env_md5"; - $env = Cluster::get($env_cache_key); - $env_md5 = Cluster::get($env_md5_key); + $env = ClusterSupport::get($env_cache_key); + $env_md5 = ClusterSupport::get($env_md5_key); $this->info('检查 .env 文件的 MD5 值。'); if (md5($env) !== $env_md5) { @@ -136,7 +136,7 @@ public function handle(): int Artisan::call('optimize'); // 上报消息 - Cluster::publish('synced'); + ClusterSupport::publish('synced'); } else { $this->error('没有找到缓存。请尝试从其他节点重新同步。'); return CommandAlias::FAILURE; diff --git a/app/Console/Commands/Cluster/Upload.php b/app/Console/Commands/Cluster/Upload.php index 1d75a4b..a04daea 100644 --- a/app/Console/Commands/Cluster/Upload.php +++ b/app/Console/Commands/Cluster/Upload.php @@ -2,7 +2,7 @@ namespace App\Console\Commands\Cluster; -use App\Support\Cluster; +use App\Support\ClusterSupport; use Illuminate\Console\Command; use Illuminate\Support\Facades\Artisan; use Symfony\Component\Console\Command\Command as CommandAlias; @@ -68,7 +68,7 @@ public function handle(): int unlink(base_path('.env.temp')); } - Cluster::publish('config.updated'); + ClusterSupport::publish('config.updated'); $this->info('节点初始化完成。'); @@ -100,12 +100,12 @@ public function upload($node_type) $this->info('正在上传 config 目录。'); $cache_key = "{$node_type}_config_zip"; - Cluster::forever($cache_key, file_get_contents($cacheZip)); + ClusterSupport::forever($cache_key, file_get_contents($cacheZip)); // md5 $this->info('正在报告 cache 目录的 MD5 值。'); $cache_md5_key = "{$node_type}_config_zip_md5"; - Cluster::forever($cache_md5_key, md5_file($cacheZip)); + ClusterSupport::forever($cache_md5_key, md5_file($cacheZip)); unlink($cacheZip); } @@ -113,12 +113,12 @@ public function upload($node_type) // 上传 .env 文件 $this->info('正在上传 .env 文件。'); $env_key = "{$node_type}_env"; - Cluster::forever($env_key, file_get_contents(base_path('.env'))); + ClusterSupport::forever($env_key, file_get_contents(base_path('.env'))); // 上传 .env 文件的 MD5 $this->info('正在报告 .env 文件的 MD5 值。'); $env_md5_key = "{$node_type}_env_md5"; - Cluster::forever($env_md5_key, md5_file(base_path('.env'))); + ClusterSupport::forever($env_md5_key, md5_file(base_path('.env'))); $this->info('完成。'); } diff --git a/app/Console/Commands/Cluster/Work.php b/app/Console/Commands/Cluster/Work.php index 66e7d86..7ae1078 100644 --- a/app/Console/Commands/Cluster/Work.php +++ b/app/Console/Commands/Cluster/Work.php @@ -2,7 +2,7 @@ namespace App\Console\Commands\Cluster; -use App\Support\Cluster; +use App\Support\ClusterSupport; use Illuminate\Console\Command; use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Str; @@ -101,7 +101,7 @@ public function handle(): int // redis 创建一个 hash $this->info('正在注册节点。'); - Cluster::registerThisNode(); + ClusterSupport::registerThisNode(); $this->info('初始化完成。'); @@ -176,7 +176,7 @@ private function report(): void $cpu = $this->getCpuUsage(); while (1) { - Cluster::publish('system_usage', [ + ClusterSupport::publish('system_usage', [ 'cpu' => $cpu, ]); @@ -195,8 +195,8 @@ private function work(): void { $this->info('正在监听任务。'); - Cluster::publish('node.online'); - Cluster::listen('*', function ($event, $message) { + ClusterSupport::publish('node.online'); + ClusterSupport::listen('*', function ($event, $message) { $this->dispatchEvent($event, $message); }, false); } @@ -220,7 +220,7 @@ private function dispatchEvent($event, $message = []): void exec('php artisan octane:reload'); - Cluster::publish('cluster.restarted.web'); + ClusterSupport::publish('cluster.restarted.web'); $this->info('Web 重启完成。'); }, @@ -229,7 +229,7 @@ private function dispatchEvent($event, $message = []): void $this->pipeCommand('supervisorctl restart all'); - Cluster::publish('cluster.restarted.all'); + ClusterSupport::publish('cluster.restarted.all'); $this->info('整个莱云 重启完成。'); }, diff --git a/app/Http/Controllers/Api/ServerController.php b/app/Http/Controllers/Api/ServerController.php index 0a98c61..fa2ec8a 100644 --- a/app/Http/Controllers/Api/ServerController.php +++ b/app/Http/Controllers/Api/ServerController.php @@ -3,7 +3,7 @@ namespace App\Http\Controllers\Api; use App\Http\Controllers\Controller; -use App\Support\Cluster; +use App\Support\ClusterSupport; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Illuminate\Support\Facades\Cache; @@ -26,9 +26,9 @@ public function module_reports(Request $request): JsonResponse public function nodes(): JsonResponse { - $nodes = Cluster::nodes(true); + $nodes = ClusterSupport::nodes(true); - $current_node_id = Cluster::currentNode()['id']; + $current_node_id = ClusterSupport::currentNode()['id']; return $this->success([ 'nodes' => $nodes, diff --git a/app/Support/Cluster.php b/app/Support/ClusterSupport.php similarity index 97% rename from app/Support/Cluster.php rename to app/Support/ClusterSupport.php index f9aea42..6c210d9 100644 --- a/app/Support/Cluster.php +++ b/app/Support/ClusterSupport.php @@ -4,7 +4,7 @@ use Illuminate\Support\Facades\Redis; -class Cluster +class ClusterSupport { public static string $prefix = 'cluster:'; @@ -45,7 +45,7 @@ public static function registerThisNode($report = true): void { $node_id = config('settings.node.id'); - Cluster::hset('nodes', $node_id, [ + ClusterSupport::hset('nodes', $node_id, [ 'type' => config('settings.node.type'), 'id' => $node_id, 'ip' => config('settings.node.ip'), @@ -54,7 +54,7 @@ public static function registerThisNode($report = true): void ]); if ($report) { - Cluster::publish('node.ok'); + ClusterSupport::publish('node.ok'); } }