@@ -11,7 +11,7 @@ |
||
11 | 11 | * Elasticsearch B.V licenses this file to you under the MIT License. |
12 | 12 | * See the LICENSE file in the project root for more information. |
13 | 13 | */ |
14 | -declare (strict_types=1); |
|
14 | +declare(strict_types=1); |
|
15 | 15 | namespace OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\Exception; |
16 | 16 | |
17 | 17 | use Throwable; |
@@ -15,6 +15,5 @@ |
||
15 | 15 | namespace OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\Exception; |
16 | 16 | |
17 | 17 | use Throwable; |
18 | -interface TransportException extends Throwable |
|
19 | -{ |
|
18 | +interface TransportException extends Throwable { |
|
20 | 19 | } |
@@ -26,83 +26,83 @@ |
||
26 | 26 | use Throwable; |
27 | 27 | class TransportBuilder |
28 | 28 | { |
29 | - protected ClientInterface $client; |
|
30 | - protected NodePoolInterface $nodePool; |
|
31 | - protected LoggerInterface $logger; |
|
32 | - protected array $hosts = []; |
|
33 | - public final function __construct() |
|
34 | - { |
|
35 | - } |
|
36 | - public static function create() : TransportBuilder |
|
37 | - { |
|
38 | - return new static(); |
|
39 | - } |
|
40 | - public function setClient(ClientInterface $client) : self |
|
41 | - { |
|
42 | - $this->client = $client; |
|
43 | - return $this; |
|
44 | - } |
|
45 | - public function getClient() : ClientInterface |
|
46 | - { |
|
47 | - if (empty($this->client)) { |
|
48 | - $this->client = Psr18ClientDiscovery::find(); |
|
49 | - } |
|
50 | - return $this->client; |
|
51 | - } |
|
52 | - public function setNodePool(NodePoolInterface $nodePool) : self |
|
53 | - { |
|
54 | - $this->nodePool = $nodePool; |
|
55 | - return $this; |
|
56 | - } |
|
57 | - public function getNodePool() : NodePoolInterface |
|
58 | - { |
|
59 | - if (empty($this->nodePool)) { |
|
60 | - $this->nodePool = new SimpleNodePool(new RoundRobin(), new NoResurrect()); |
|
61 | - } |
|
62 | - return $this->nodePool; |
|
63 | - } |
|
64 | - public function setLogger(LoggerInterface $logger) : self |
|
65 | - { |
|
66 | - $this->logger = $logger; |
|
67 | - return $this; |
|
68 | - } |
|
69 | - public function getLogger() : LoggerInterface |
|
70 | - { |
|
71 | - if (empty($this->logger)) { |
|
72 | - $this->logger = new NullLogger(); |
|
73 | - } |
|
74 | - return $this->logger; |
|
75 | - } |
|
76 | - public function setHosts(array $hosts) : self |
|
77 | - { |
|
78 | - $this->hosts = $hosts; |
|
79 | - return $this; |
|
80 | - } |
|
81 | - public function getHosts() : array |
|
82 | - { |
|
83 | - return $this->hosts; |
|
84 | - } |
|
85 | - public function setCloudId(string $cloudId) : self |
|
86 | - { |
|
87 | - $this->hosts = [$this->parseElasticCloudId($cloudId)]; |
|
88 | - return $this; |
|
89 | - } |
|
90 | - public function build() : Transport |
|
91 | - { |
|
92 | - return new Transport($this->getClient(), $this->getNodePool()->setHosts($this->hosts), $this->getLogger()); |
|
93 | - } |
|
94 | - /** |
|
95 | - * Return the URL of Elastic Cloud from the Cloud ID |
|
96 | - */ |
|
97 | - private function parseElasticCloudId(string $cloudId) : string |
|
98 | - { |
|
99 | - try { |
|
100 | - list($name, $encoded) = \explode(':', $cloudId); |
|
101 | - list($uri, $uuids) = \explode('$', \base64_decode($encoded)); |
|
102 | - list($es, ) = \explode(':', $uuids); |
|
103 | - return \sprintf("https://%s.%s", $es, $uri); |
|
104 | - } catch (Throwable $t) { |
|
105 | - throw new Exception\CloudIdParseException('Cloud ID not valid'); |
|
106 | - } |
|
107 | - } |
|
29 | + protected ClientInterface $client; |
|
30 | + protected NodePoolInterface $nodePool; |
|
31 | + protected LoggerInterface $logger; |
|
32 | + protected array $hosts = []; |
|
33 | + public final function __construct() |
|
34 | + { |
|
35 | + } |
|
36 | + public static function create() : TransportBuilder |
|
37 | + { |
|
38 | + return new static(); |
|
39 | + } |
|
40 | + public function setClient(ClientInterface $client) : self |
|
41 | + { |
|
42 | + $this->client = $client; |
|
43 | + return $this; |
|
44 | + } |
|
45 | + public function getClient() : ClientInterface |
|
46 | + { |
|
47 | + if (empty($this->client)) { |
|
48 | + $this->client = Psr18ClientDiscovery::find(); |
|
49 | + } |
|
50 | + return $this->client; |
|
51 | + } |
|
52 | + public function setNodePool(NodePoolInterface $nodePool) : self |
|
53 | + { |
|
54 | + $this->nodePool = $nodePool; |
|
55 | + return $this; |
|
56 | + } |
|
57 | + public function getNodePool() : NodePoolInterface |
|
58 | + { |
|
59 | + if (empty($this->nodePool)) { |
|
60 | + $this->nodePool = new SimpleNodePool(new RoundRobin(), new NoResurrect()); |
|
61 | + } |
|
62 | + return $this->nodePool; |
|
63 | + } |
|
64 | + public function setLogger(LoggerInterface $logger) : self |
|
65 | + { |
|
66 | + $this->logger = $logger; |
|
67 | + return $this; |
|
68 | + } |
|
69 | + public function getLogger() : LoggerInterface |
|
70 | + { |
|
71 | + if (empty($this->logger)) { |
|
72 | + $this->logger = new NullLogger(); |
|
73 | + } |
|
74 | + return $this->logger; |
|
75 | + } |
|
76 | + public function setHosts(array $hosts) : self |
|
77 | + { |
|
78 | + $this->hosts = $hosts; |
|
79 | + return $this; |
|
80 | + } |
|
81 | + public function getHosts() : array |
|
82 | + { |
|
83 | + return $this->hosts; |
|
84 | + } |
|
85 | + public function setCloudId(string $cloudId) : self |
|
86 | + { |
|
87 | + $this->hosts = [$this->parseElasticCloudId($cloudId)]; |
|
88 | + return $this; |
|
89 | + } |
|
90 | + public function build() : Transport |
|
91 | + { |
|
92 | + return new Transport($this->getClient(), $this->getNodePool()->setHosts($this->hosts), $this->getLogger()); |
|
93 | + } |
|
94 | + /** |
|
95 | + * Return the URL of Elastic Cloud from the Cloud ID |
|
96 | + */ |
|
97 | + private function parseElasticCloudId(string $cloudId) : string |
|
98 | + { |
|
99 | + try { |
|
100 | + list($name, $encoded) = \explode(':', $cloudId); |
|
101 | + list($uri, $uuids) = \explode('$', \base64_decode($encoded)); |
|
102 | + list($es, ) = \explode(':', $uuids); |
|
103 | + return \sprintf("https://%s.%s", $es, $uri); |
|
104 | + } catch (Throwable $t) { |
|
105 | + throw new Exception\CloudIdParseException('Cloud ID not valid'); |
|
106 | + } |
|
107 | + } |
|
108 | 108 | } |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | * Elasticsearch B.V licenses this file to you under the MIT License. |
12 | 12 | * See the LICENSE file in the project root for more information. |
13 | 13 | */ |
14 | -declare (strict_types=1); |
|
14 | +declare(strict_types=1); |
|
15 | 15 | namespace OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport; |
16 | 16 | |
17 | 17 | use OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\NodePool\NodePoolInterface; |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | try { |
100 | 100 | list($name, $encoded) = \explode(':', $cloudId); |
101 | 101 | list($uri, $uuids) = \explode('$', \base64_decode($encoded)); |
102 | - list($es, ) = \explode(':', $uuids); |
|
102 | + list($es,) = \explode(':', $uuids); |
|
103 | 103 | return \sprintf("https://%s.%s", $es, $uri); |
104 | 104 | } catch (Throwable $t) { |
105 | 105 | throw new Exception\CloudIdParseException('Cloud ID not valid'); |
@@ -24,8 +24,7 @@ |
||
24 | 24 | use Psr\Log\LoggerInterface; |
25 | 25 | use Psr\Log\NullLogger; |
26 | 26 | use Throwable; |
27 | -class TransportBuilder |
|
28 | -{ |
|
27 | +class TransportBuilder { |
|
29 | 28 | protected ClientInterface $client; |
30 | 29 | protected NodePoolInterface $nodePool; |
31 | 30 | protected LoggerInterface $logger; |
@@ -20,25 +20,25 @@ |
||
20 | 20 | use function substr; |
21 | 21 | class Node |
22 | 22 | { |
23 | - protected UriInterface $uri; |
|
24 | - protected bool $alive = \true; |
|
25 | - public function __construct(string $host) |
|
26 | - { |
|
27 | - if (substr($host, 0, 5) !== 'http:' && substr($host, 0, 6) !== 'https:') { |
|
28 | - $host = sprintf("http://%s", $host); |
|
29 | - } |
|
30 | - $this->uri = Psr17FactoryDiscovery::findUriFactory()->createUri($host); |
|
31 | - } |
|
32 | - public function markAlive(bool $alive) : void |
|
33 | - { |
|
34 | - $this->alive = $alive; |
|
35 | - } |
|
36 | - public function isAlive() : bool |
|
37 | - { |
|
38 | - return $this->alive; |
|
39 | - } |
|
40 | - public function getUri() : UriInterface |
|
41 | - { |
|
42 | - return $this->uri; |
|
43 | - } |
|
23 | + protected UriInterface $uri; |
|
24 | + protected bool $alive = \true; |
|
25 | + public function __construct(string $host) |
|
26 | + { |
|
27 | + if (substr($host, 0, 5) !== 'http:' && substr($host, 0, 6) !== 'https:') { |
|
28 | + $host = sprintf("http://%s", $host); |
|
29 | + } |
|
30 | + $this->uri = Psr17FactoryDiscovery::findUriFactory()->createUri($host); |
|
31 | + } |
|
32 | + public function markAlive(bool $alive) : void |
|
33 | + { |
|
34 | + $this->alive = $alive; |
|
35 | + } |
|
36 | + public function isAlive() : bool |
|
37 | + { |
|
38 | + return $this->alive; |
|
39 | + } |
|
40 | + public function getUri() : UriInterface |
|
41 | + { |
|
42 | + return $this->uri; |
|
43 | + } |
|
44 | 44 | } |
@@ -11,7 +11,7 @@ |
||
11 | 11 | * Elasticsearch B.V licenses this file to you under the MIT License. |
12 | 12 | * See the LICENSE file in the project root for more information. |
13 | 13 | */ |
14 | -declare (strict_types=1); |
|
14 | +declare(strict_types=1); |
|
15 | 15 | namespace OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\NodePool; |
16 | 16 | |
17 | 17 | use OCA\FullTextSearch_Elasticsearch\Vendor\Http\Discovery\Psr17FactoryDiscovery; |
@@ -18,8 +18,7 @@ |
||
18 | 18 | use OCA\FullTextSearch_Elasticsearch\Vendor\Psr\Http\Message\UriInterface; |
19 | 19 | use function sprintf; |
20 | 20 | use function substr; |
21 | -class Node |
|
22 | -{ |
|
21 | +class Node { |
|
23 | 22 | protected UriInterface $uri; |
24 | 23 | protected bool $alive = \true; |
25 | 24 | public function __construct(string $host) |
@@ -16,9 +16,9 @@ |
||
16 | 16 | |
17 | 17 | interface NodePoolInterface |
18 | 18 | { |
19 | - public function nextNode() : Node; |
|
20 | - /** |
|
21 | - * @param string[] $hosts |
|
22 | - */ |
|
23 | - public function setHosts(array $hosts) : self; |
|
19 | + public function nextNode() : Node; |
|
20 | + /** |
|
21 | + * @param string[] $hosts |
|
22 | + */ |
|
23 | + public function setHosts(array $hosts) : self; |
|
24 | 24 | } |
@@ -11,7 +11,7 @@ |
||
11 | 11 | * Elasticsearch B.V licenses this file to you under the MIT License. |
12 | 12 | * See the LICENSE file in the project root for more information. |
13 | 13 | */ |
14 | -declare (strict_types=1); |
|
14 | +declare(strict_types=1); |
|
15 | 15 | namespace OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\NodePool; |
16 | 16 | |
17 | 17 | interface NodePoolInterface |
@@ -14,8 +14,7 @@ |
||
14 | 14 | declare (strict_types=1); |
15 | 15 | namespace OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\NodePool; |
16 | 16 | |
17 | -interface NodePoolInterface |
|
18 | -{ |
|
17 | +interface NodePoolInterface { |
|
19 | 18 | public function nextNode() : Node; |
20 | 19 | /** |
21 | 20 | * @param string[] $hosts |
@@ -17,13 +17,13 @@ |
||
17 | 17 | use OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\NodePool\Node; |
18 | 18 | interface SelectorInterface |
19 | 19 | { |
20 | - public function nextNode() : Node; |
|
21 | - /** |
|
22 | - * @param Node[] $nodes |
|
23 | - */ |
|
24 | - public function setNodes(array $nodes) : void; |
|
25 | - /** |
|
26 | - * @return Node[] |
|
27 | - */ |
|
28 | - public function getNodes() : array; |
|
20 | + public function nextNode() : Node; |
|
21 | + /** |
|
22 | + * @param Node[] $nodes |
|
23 | + */ |
|
24 | + public function setNodes(array $nodes) : void; |
|
25 | + /** |
|
26 | + * @return Node[] |
|
27 | + */ |
|
28 | + public function getNodes() : array; |
|
29 | 29 | } |
@@ -11,7 +11,7 @@ |
||
11 | 11 | * Elasticsearch B.V licenses this file to you under the MIT License. |
12 | 12 | * See the LICENSE file in the project root for more information. |
13 | 13 | */ |
14 | -declare (strict_types=1); |
|
14 | +declare(strict_types=1); |
|
15 | 15 | namespace OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\NodePool\Selector; |
16 | 16 | |
17 | 17 | use OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\NodePool\Node; |
@@ -15,8 +15,7 @@ |
||
15 | 15 | namespace OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\NodePool\Selector; |
16 | 16 | |
17 | 17 | use OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\NodePool\Node; |
18 | -interface SelectorInterface |
|
19 | -{ |
|
18 | +interface SelectorInterface { |
|
20 | 19 | public function nextNode() : Node; |
21 | 20 | /** |
22 | 21 | * @param Node[] $nodes |
@@ -18,17 +18,17 @@ |
||
18 | 18 | use OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\Exception\NoNodeAvailableException; |
19 | 19 | class RoundRobin implements SelectorInterface |
20 | 20 | { |
21 | - use SelectorTrait; |
|
22 | - public function nextNode() : Node |
|
23 | - { |
|
24 | - if (empty($this->getNodes())) { |
|
25 | - $className = \substr(__CLASS__, \strrpos(__CLASS__, '\\') + 1); |
|
26 | - throw new NoNodeAvailableException(\sprintf("No node available. Please use %s::setNodes() before calling %s::nextNode().", $className, $className)); |
|
27 | - } |
|
28 | - $node = \current($this->nodes); |
|
29 | - if (\false === \next($this->nodes)) { |
|
30 | - \reset($this->nodes); |
|
31 | - } |
|
32 | - return $node; |
|
33 | - } |
|
21 | + use SelectorTrait; |
|
22 | + public function nextNode() : Node |
|
23 | + { |
|
24 | + if (empty($this->getNodes())) { |
|
25 | + $className = \substr(__CLASS__, \strrpos(__CLASS__, '\\') + 1); |
|
26 | + throw new NoNodeAvailableException(\sprintf("No node available. Please use %s::setNodes() before calling %s::nextNode().", $className, $className)); |
|
27 | + } |
|
28 | + $node = \current($this->nodes); |
|
29 | + if (\false === \next($this->nodes)) { |
|
30 | + \reset($this->nodes); |
|
31 | + } |
|
32 | + return $node; |
|
33 | + } |
|
34 | 34 | } |
@@ -16,8 +16,7 @@ |
||
16 | 16 | |
17 | 17 | use OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\NodePool\Node; |
18 | 18 | use OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\Exception\NoNodeAvailableException; |
19 | -class RoundRobin implements SelectorInterface |
|
20 | -{ |
|
19 | +class RoundRobin implements SelectorInterface { |
|
21 | 20 | use SelectorTrait; |
22 | 21 | public function nextNode() : Node |
23 | 22 | { |
@@ -11,7 +11,7 @@ |
||
11 | 11 | * Elasticsearch B.V licenses this file to you under the MIT License. |
12 | 12 | * See the LICENSE file in the project root for more information. |
13 | 13 | */ |
14 | -declare (strict_types=1); |
|
14 | +declare(strict_types=1); |
|
15 | 15 | namespace OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\NodePool\Selector; |
16 | 16 | |
17 | 17 | use OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\NodePool\Node; |
@@ -18,18 +18,18 @@ |
||
18 | 18 | use OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\Exception\InvalidArrayException; |
19 | 19 | trait SelectorTrait |
20 | 20 | { |
21 | - protected array $nodes = []; |
|
22 | - public function setNodes(array $nodes) : void |
|
23 | - { |
|
24 | - foreach ($nodes as $node) { |
|
25 | - if (!$node instanceof Node) { |
|
26 | - throw new InvalidArrayException(\sprintf("The nodes array must contain only %s objects", Node::class)); |
|
27 | - } |
|
28 | - } |
|
29 | - $this->nodes = $nodes; |
|
30 | - } |
|
31 | - public function getNodes() : array |
|
32 | - { |
|
33 | - return $this->nodes; |
|
34 | - } |
|
21 | + protected array $nodes = []; |
|
22 | + public function setNodes(array $nodes) : void |
|
23 | + { |
|
24 | + foreach ($nodes as $node) { |
|
25 | + if (!$node instanceof Node) { |
|
26 | + throw new InvalidArrayException(\sprintf("The nodes array must contain only %s objects", Node::class)); |
|
27 | + } |
|
28 | + } |
|
29 | + $this->nodes = $nodes; |
|
30 | + } |
|
31 | + public function getNodes() : array |
|
32 | + { |
|
33 | + return $this->nodes; |
|
34 | + } |
|
35 | 35 | } |
@@ -16,8 +16,7 @@ |
||
16 | 16 | |
17 | 17 | use OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\NodePool\Node; |
18 | 18 | use OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\Exception\InvalidArrayException; |
19 | -trait SelectorTrait |
|
20 | -{ |
|
19 | +trait SelectorTrait { |
|
21 | 20 | protected array $nodes = []; |
22 | 21 | public function setNodes(array $nodes) : void |
23 | 22 | { |
@@ -11,7 +11,7 @@ |
||
11 | 11 | * Elasticsearch B.V licenses this file to you under the MIT License. |
12 | 12 | * See the LICENSE file in the project root for more information. |
13 | 13 | */ |
14 | -declare (strict_types=1); |
|
14 | +declare(strict_types=1); |
|
15 | 15 | namespace OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\NodePool\Selector; |
16 | 16 | |
17 | 17 | use OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\NodePool\Node; |
@@ -22,49 +22,49 @@ |
||
22 | 22 | use function sprintf; |
23 | 23 | class SimpleNodePool implements NodePoolInterface |
24 | 24 | { |
25 | - /** |
|
26 | - * @var array |
|
27 | - */ |
|
28 | - protected $nodes = []; |
|
29 | - /** |
|
30 | - * @var SelectorInterface |
|
31 | - */ |
|
32 | - protected $selector; |
|
33 | - /** |
|
34 | - * @var ResurrectInterface |
|
35 | - */ |
|
36 | - protected $resurrect; |
|
37 | - public function __construct(SelectorInterface $selector, ResurrectInterface $resurrect) |
|
38 | - { |
|
39 | - $this->selector = $selector; |
|
40 | - $this->resurrect = $resurrect; |
|
41 | - } |
|
42 | - public function setHosts(array $hosts) : self |
|
43 | - { |
|
44 | - $this->nodes = []; |
|
45 | - foreach ($hosts as $host) { |
|
46 | - $this->nodes[] = new Node($host); |
|
47 | - } |
|
48 | - shuffle($this->nodes); |
|
49 | - // randomize for use different hosts on each execution |
|
50 | - $this->selector->setNodes($this->nodes); |
|
51 | - return $this; |
|
52 | - } |
|
53 | - public function nextNode() : Node |
|
54 | - { |
|
55 | - $totNodes = count($this->nodes); |
|
56 | - $dead = 0; |
|
57 | - while ($dead < $totNodes) { |
|
58 | - $next = $this->selector->nextNode(); |
|
59 | - if ($next->isAlive()) { |
|
60 | - return $next; |
|
61 | - } |
|
62 | - if ($this->resurrect->ping($next)) { |
|
63 | - $next->markAlive(\true); |
|
64 | - return $next; |
|
65 | - } |
|
66 | - $dead++; |
|
67 | - } |
|
68 | - throw new NoNodeAvailableException(sprintf('No alive nodes. All the %d nodes seem to be down.', $totNodes)); |
|
69 | - } |
|
25 | + /** |
|
26 | + * @var array |
|
27 | + */ |
|
28 | + protected $nodes = []; |
|
29 | + /** |
|
30 | + * @var SelectorInterface |
|
31 | + */ |
|
32 | + protected $selector; |
|
33 | + /** |
|
34 | + * @var ResurrectInterface |
|
35 | + */ |
|
36 | + protected $resurrect; |
|
37 | + public function __construct(SelectorInterface $selector, ResurrectInterface $resurrect) |
|
38 | + { |
|
39 | + $this->selector = $selector; |
|
40 | + $this->resurrect = $resurrect; |
|
41 | + } |
|
42 | + public function setHosts(array $hosts) : self |
|
43 | + { |
|
44 | + $this->nodes = []; |
|
45 | + foreach ($hosts as $host) { |
|
46 | + $this->nodes[] = new Node($host); |
|
47 | + } |
|
48 | + shuffle($this->nodes); |
|
49 | + // randomize for use different hosts on each execution |
|
50 | + $this->selector->setNodes($this->nodes); |
|
51 | + return $this; |
|
52 | + } |
|
53 | + public function nextNode() : Node |
|
54 | + { |
|
55 | + $totNodes = count($this->nodes); |
|
56 | + $dead = 0; |
|
57 | + while ($dead < $totNodes) { |
|
58 | + $next = $this->selector->nextNode(); |
|
59 | + if ($next->isAlive()) { |
|
60 | + return $next; |
|
61 | + } |
|
62 | + if ($this->resurrect->ping($next)) { |
|
63 | + $next->markAlive(\true); |
|
64 | + return $next; |
|
65 | + } |
|
66 | + $dead++; |
|
67 | + } |
|
68 | + throw new NoNodeAvailableException(sprintf('No alive nodes. All the %d nodes seem to be down.', $totNodes)); |
|
69 | + } |
|
70 | 70 | } |
@@ -11,7 +11,7 @@ |
||
11 | 11 | * Elasticsearch B.V licenses this file to you under the MIT License. |
12 | 12 | * See the LICENSE file in the project root for more information. |
13 | 13 | */ |
14 | -declare (strict_types=1); |
|
14 | +declare(strict_types=1); |
|
15 | 15 | namespace OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\NodePool; |
16 | 16 | |
17 | 17 | use OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\NodePool\Resurrect\ResurrectInterface; |
@@ -20,8 +20,7 @@ |
||
20 | 20 | use function count; |
21 | 21 | use function shuffle; |
22 | 22 | use function sprintf; |
23 | -class SimpleNodePool implements NodePoolInterface |
|
24 | -{ |
|
23 | +class SimpleNodePool implements NodePoolInterface { |
|
25 | 24 | /** |
26 | 25 | * @var array |
27 | 26 | */ |
@@ -22,30 +22,30 @@ |
||
22 | 22 | use OCA\FullTextSearch_Elasticsearch\Vendor\Psr\Http\Message\RequestFactoryInterface; |
23 | 23 | class ElasticsearchResurrect implements ResurrectInterface |
24 | 24 | { |
25 | - protected ClientInterface $client; |
|
26 | - protected RequestFactoryInterface $requestFactory; |
|
27 | - public function ping(Node $node) : bool |
|
28 | - { |
|
29 | - $request = $this->getRequestFactory()->createRequest("HEAD", $node->getUri()); |
|
30 | - try { |
|
31 | - $response = $this->getClient()->sendRequest($request); |
|
32 | - return $response->getStatusCode() === 200; |
|
33 | - } catch (Exception $e) { |
|
34 | - return \false; |
|
35 | - } |
|
36 | - } |
|
37 | - public function getClient() : ClientInterface |
|
38 | - { |
|
39 | - if (empty($this->client)) { |
|
40 | - $this->client = Psr18ClientDiscovery::find(); |
|
41 | - } |
|
42 | - return $this->client; |
|
43 | - } |
|
44 | - public function getRequestFactory() : RequestFactoryInterface |
|
45 | - { |
|
46 | - if (empty($this->requestFactory)) { |
|
47 | - $this->requestFactory = Psr17FactoryDiscovery::findRequestFactory(); |
|
48 | - } |
|
49 | - return $this->requestFactory; |
|
50 | - } |
|
25 | + protected ClientInterface $client; |
|
26 | + protected RequestFactoryInterface $requestFactory; |
|
27 | + public function ping(Node $node) : bool |
|
28 | + { |
|
29 | + $request = $this->getRequestFactory()->createRequest("HEAD", $node->getUri()); |
|
30 | + try { |
|
31 | + $response = $this->getClient()->sendRequest($request); |
|
32 | + return $response->getStatusCode() === 200; |
|
33 | + } catch (Exception $e) { |
|
34 | + return \false; |
|
35 | + } |
|
36 | + } |
|
37 | + public function getClient() : ClientInterface |
|
38 | + { |
|
39 | + if (empty($this->client)) { |
|
40 | + $this->client = Psr18ClientDiscovery::find(); |
|
41 | + } |
|
42 | + return $this->client; |
|
43 | + } |
|
44 | + public function getRequestFactory() : RequestFactoryInterface |
|
45 | + { |
|
46 | + if (empty($this->requestFactory)) { |
|
47 | + $this->requestFactory = Psr17FactoryDiscovery::findRequestFactory(); |
|
48 | + } |
|
49 | + return $this->requestFactory; |
|
50 | + } |
|
51 | 51 | } |
@@ -11,7 +11,7 @@ |
||
11 | 11 | * Elasticsearch B.V licenses this file to you under the MIT License. |
12 | 12 | * See the LICENSE file in the project root for more information. |
13 | 13 | */ |
14 | -declare (strict_types=1); |
|
14 | +declare(strict_types=1); |
|
15 | 15 | namespace OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\NodePool\Resurrect; |
16 | 16 | |
17 | 17 | use OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\NodePool\Node; |
@@ -20,8 +20,7 @@ |
||
20 | 20 | use OCA\FullTextSearch_Elasticsearch\Vendor\Http\Discovery\Psr17FactoryDiscovery; |
21 | 21 | use OCA\FullTextSearch_Elasticsearch\Vendor\Http\Discovery\Psr18ClientDiscovery; |
22 | 22 | use OCA\FullTextSearch_Elasticsearch\Vendor\Psr\Http\Message\RequestFactoryInterface; |
23 | -class ElasticsearchResurrect implements ResurrectInterface |
|
24 | -{ |
|
23 | +class ElasticsearchResurrect implements ResurrectInterface { |
|
25 | 24 | protected ClientInterface $client; |
26 | 25 | protected RequestFactoryInterface $requestFactory; |
27 | 26 | public function ping(Node $node) : bool |