1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
clustercache.php
См. документацию.
1<?php
2namespace Bitrix\Cluster;
3
5{
6 protected static string $type = 'memcache';
7
8 public static function getList(): ?\CDBResult
9 {
10 $res = new \CDBResult;
11 $res->InitFromArray(ClusterCacheConfig::getInstance(static::$type)->getConfig());
12 return $res;
13 }
14
15 public static function getServerList(): array
16 {
17 return ClusterCacheConfig::getInstance(static::$type)->getServers();
18 }
19
20 public static function getByID(int $id): array
21 {
22 $servers = ClusterCacheConfig::getInstance(static::$type)->getConfig();
23 return is_array($servers[$id]) ? $servers[$id] : [];
24 }
25
26 public static function delete(int $id): bool
27 {
28 $servers = ClusterCacheConfig::getInstance(static::$type)->getConfig();
29 if (array_key_exists($id, $servers))
30 {
31 unset($servers[$id]);
32 static::saveConfig($servers);
33 }
34 return true;
35 }
36
37 public static function pause(int|array $ids): void
38 {
39 $ob = new static();
40 $ob->update($ids, ['STATUS' => 'READY']);
41 }
42
43 public static function resume(int|array $ids): void
44 {
45 $ob = new static();
46 $ob->update($ids, ['STATUS' => 'ONLINE']);
47 }
48
49 public function add($fields): int
50 {
51 if (!$this->checkFields($fields, false))
52 {
53 return 0;
54 }
55
56 $servers = ClusterCacheConfig::getInstance(static::$type)->getConfig();
57
58 $id = 1;
59 foreach ($servers as $server)
60 {
61 if ($server['ID'] >= $id)
62 {
63 $id = $server['ID'] + 1;
64 }
65 }
66
67 $status = static::getStatus($fields);
68 $servers[$id] = [
69 'ID' => $id,
70 'GROUP_ID' => intval($fields['GROUP_ID']),
71 'STATUS' => 'READY',
72 'WEIGHT' => $fields['WEIGHT'] ?? 100,
73 'HOST' => $fields['HOST'],
74 'PORT' => $fields['PORT'],
75 'MODE' => strtoupper($status['redis_mode'] ?? ''),
76 'ROLE' => strtoupper($status['role'] ?? ''),
77 ];
78
79 static::saveConfig($servers);
80 return $id;
81 }
82
83 public function update($serverID, $fields): bool
84 {
85 if (!is_array($serverID))
86 {
87 $serverID = [0 => (int) $serverID];
88 }
89
90 $servers = ClusterCacheConfig::getInstance(static::$type)->getConfig();
91 foreach ($serverID as $id)
92 {
93 if (!array_key_exists($id, $servers))
94 {
95 return 0;
96 }
97
98 $status = $this->checkFields($servers[$id]);
99 if (empty($status) || $status['message'] !== null || intval($status['uptime']) <= 0)
100 {
101 return false;
102 }
103
104 $servers[$id] = [
105 'ID' => $id,
106 'GROUP_ID' => $servers[$id]['GROUP_ID'],
107 'STATUS' => $fields['STATUS'] ?? $servers[$id]['STATUS'],
108 'HOST' => $fields['HOST'] ?? $servers[$id]['HOST'],
109 'PORT' => $fields['PORT'] ?? $servers[$id]['PORT'],
110 'MODE' => strtoupper($servers[$id]['MODE'] ?? ''),
111 'ROLE' => strtoupper($servers[$id]['ROLE'] ?? '')
112 ];
113 }
114
115 static::saveConfig($servers);
116 return true;
117 }
118
119 public function checkFields(&$fields): array
120 {
121 $error = [];
122 $status = [];
123
124 $fields['WEIGHT'] = (int) ($fields['WEIGHT'] ?? 100);
125 if ($fields['WEIGHT'] < 0)
126 {
127 $fields['WEIGHT'] = 0;
128 }
129 elseif ($fields['WEIGHT'] > 100)
130 {
131 $fields['WEIGHT'] = 100;
132 }
133
134 $fields['PORT'] = (int) $fields['PORT'];
135 if (isset($fields['HOST']))
136 {
137 $status = static::getStatus($fields);
138
139 if ($status['message'] !== null)
140 {
141 $error[] = [
142 'id' => $fields['HOST'],
143 'text' => Loc:: getMessage('CLU_' . strtoupper(static::$type) . '_CANNOT_CONNECT')
144 ];
145 }
146 }
147
148 if (!empty($error))
149 {
150 global $APPLICATION;
151 $e = new CAdminException($error);
152 $APPLICATION->ThrowException($e);
153 return [];
154 }
155
156 return $status;
157 }
158
159 public static function getServerStatus(int $id): array
160 {
161 $server = static::getByID($id);
162 return static::getStatus($server);
163 }
164
165 static function getStatus(array $server): array
166 {
167 }
168
169 static function saveConfig(array $servers): void
170 {
171 }
172}
global $APPLICATION
Определения include.php:80
static resume(int|array $ids)
Определения clustercache.php:43
update($serverID, $fields)
Определения clustercache.php:83
static getStatus(array $server)
Определения clustercache.php:165
checkFields(&$fields)
Определения clustercache.php:119
static getByID(int $id)
Определения clustercache.php:20
static string $type
Определения clustercache.php:6
static pause(int|array $ids)
Определения clustercache.php:37
static saveConfig(array $servers)
Определения clustercache.php:169
static getServerStatus(int $id)
Определения clustercache.php:159
static getServerList()
Определения clustercache.php:15
static getList()
Определения clustercache.php:8
add($fields)
Определения clustercache.php:49
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$res
Определения filter_act.php:7
$status
Определения session.php:10
Определения clustercache.php:2
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$error
Определения subscription_card_product.php:20
$fields
Определения yandex_run.php:501