Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
provider.php
1<?php
2
3namespace Bitrix\Scale;
4
5use \Bitrix\Main\Localization\Loc;
6Loc::loadMessages(__FILE__);
7
8use \Bitrix\Main\ArgumentNullException;
9
14class Provider {
15
20 public static function getList($params = array())
21 {
22 $result = array();
23 $shellAdapter = new ShellAdapter();
24 $execRes = $shellAdapter->syncExec("sudo -u root /opt/webdir/bin/bx-provider -a list -o json");
25 $jsonData = $shellAdapter->getLastOutput();
26
27 if($execRes)
28 {
29 $arData = json_decode($jsonData, true);
30
31 if(isset($arData["params"]) && isset($arData["params"]["providers"]) && is_array($arData["params"]["providers"]))
32 $result = $arData["params"]["providers"];
33
34 if(isset($params["filter"]) && is_array($params["filter"]))
35 {
36 foreach($params["filter"] as $filterKey => $filterValue)
37 {
38 foreach($result as $providerId => $providerParams)
39 {
40 if(!array_key_exists($filterKey, $providerParams) || $providerParams[$filterKey] != $filterValue)
41 {
42 unset($result[$providerId]);
43 }
44 }
45 }
46 }
47
48 }
49
50 return $result;
51 }
52
58 public static function getStatus($providerId)
59 {
60 if($providerId == '' )
61 throw new ArgumentNullException("providerId");
62
63 $result = array();
64
65 $shellAdapter = new ShellAdapter();
66 $execRes = $shellAdapter->syncExec("sudo -u root /opt/webdir/bin/bx-provider -a status --provider ".$providerId." -o json");
67 $jsonData = $shellAdapter->getLastOutput();
68
69 if($execRes)
70 {
71 $arData = json_decode($jsonData, true);
72
73 if(isset($arData["params"]["provider_options"][$providerId]) && is_array($arData["params"]["provider_options"][$providerId]))
74 $result = $arData["params"]["provider_options"][$providerId];
75 }
76
77 return $result;
78 }
79
85 public static function getConfigs($providerId)
86 {
87 if($providerId == '' )
88 throw new ArgumentNullException("providerId");
89
90 $result = array();
91 $shellAdapter = new ShellAdapter();
92 $execRes = $shellAdapter->syncExec("sudo -u root /opt/webdir/bin/bx-provider -a configs --provider ".$providerId." -o json");
93 $jsonData = $shellAdapter->getLastOutput();
94
95 if($execRes)
96 {
97 $arData = json_decode($jsonData, true);
98
99 if(isset($arData["params"]["provider_configs"][$providerId]["configurations"]) && is_array($arData["params"]["provider_configs"][$providerId]["configurations"]))
100 $result = $arData["params"]["provider_configs"][$providerId]["configurations"];
101 }
102
103 return $result;
104 }
105
112 public static function sendOrder($providerId, $configId)
113 {
114 if($providerId == '' )
115 throw new ArgumentNullException("providerId");
116
117 if($configId == '' )
118 throw new ArgumentNullException("configId");
119
120 $result = "";
121 $shellAdapter = new ShellAdapter();
122 $execRes = $shellAdapter->syncExec("sudo -u root /opt/webdir/bin/bx-provider -a order --provider ".$providerId." --config_id ".$configId." -o json");
123 $jsonData = $shellAdapter->getLastOutput();
124
125 if($execRes)
126 {
127 $arData = json_decode($jsonData, true);
128
129 if(isset($arData["params"]["provider_order"][$providerId]["task_id"]))
130 $result = $arData["params"]["provider_order"][$providerId]["task_id"];
131 }
132
133 if($result <> '')
134 {
135 $logLevel = Logger::LOG_LEVEL_INFO;
136 $description = Loc::getMessage("SCALE_PROVIDER_SEND_ORDER_SUCCESS");
137 }
138 else
139 {
140 $logLevel = Logger::LOG_LEVEL_ERROR;
141 $description = Loc::getMessage("SCALE_PROVIDER_SEND_ORDER_ERROR");
142 }
143
144 $description = str_replace(
145 array("##PROVIDER##", "##CONFIG_ID##", "##ORDER_ID##"),
146 array($providerId, $configId, $result),
147 $description
148 );
149
151 $logLevel,
152 "SCALE_PROVIDER_SEND_ORDER",
153 $providerId."::".$configId,
154 $description);
155
156 return $result;
157 }
158
159
166 public static function getOrderStatus($providerId, $taskId)
167 {
168 if($providerId == '' )
169 throw new ArgumentNullException("providerId");
170
171 if($taskId == '' )
172 throw new ArgumentNullException("taskId");
173
174 $result = array();
175 $shellAdapter = new ShellAdapter();
176 $execRes = $shellAdapter->syncExec("sudo -u root /opt/webdir/bin/bx-provider -a order_status --provider ".$providerId." --task_id ".$taskId." -o json");
177 $jsonData = $shellAdapter->getLastOutput();
178
179 if($execRes)
180 {
181 $arData = json_decode($jsonData, true);
182
183 if(isset($arData["params"]["provider_order"][$providerId]))
184 $result = $arData["params"]["provider_order"][$providerId];
185 }
186
187 return $result;
188 }
189
195 public static function getOrdersList($providerId = "")
196 {
197 $result = array();
198 $shellAdapter = new ShellAdapter();
199 $execRes = $shellAdapter->syncExec("sudo -u root /opt/webdir/bin/bx-provider -a orders_list".($providerId <> '' ? " --provider ".$providerId : "")." -o json");
200 $jsonData = $shellAdapter->getLastOutput();
201
202 if($execRes)
203 {
204 $arData = json_decode($jsonData, true);
205
206 if(isset($arData["params"]["provider_order_list"]))
207 $result = $arData["params"]["provider_order_list"];
208 }
209
210 return $result;
211 }
212
220 public static function addToPullFromOrder($providerId, $taskId)
221 {
222 if($providerId == '' )
223 throw new ArgumentNullException("providerId");
224
225 if($taskId == '' )
226 throw new ArgumentNullException("taskId");
227
228 $result = false;
229 $shellAdapter = new ShellAdapter();
230 $execRes = $shellAdapter->syncExec("sudo -u root /opt/webdir/bin/bx-provider -a order_to_host --provider ".$providerId." --task_id ".$taskId." -o json");
231 $jsonData = $shellAdapter->getLastOutput();
232
233 if($execRes)
234 {
235 $result = json_decode($jsonData, true);
236 }
237
238 return $result;
239 }
240}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static addRecord($level, $auditType, $itemId, $description)
Definition logger.php:26
const LOG_LEVEL_ERROR
Definition logger.php:15
static getStatus($providerId)
Definition provider.php:58
static getConfigs($providerId)
Definition provider.php:85
static addToPullFromOrder($providerId, $taskId)
Definition provider.php:220
static getOrdersList($providerId="")
Definition provider.php:195
static getList($params=array())
Definition provider.php:20
static sendOrder($providerId, $configId)
Definition provider.php:112
static getOrderStatus($providerId, $taskId)
Definition provider.php:166