-
Notifications
You must be signed in to change notification settings - Fork 59
/
Agent.php
111 lines (87 loc) · 2.82 KB
/
Agent.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
namespace Consul\Services;
use Consul\Client;
use Consul\ClientInterface;
use Consul\ConsulResponse;
use Consul\OptionsResolver;
final class Agent
{
private ClientInterface $client;
public function __construct(?ClientInterface $client = null)
{
$this->client = $client ?: new Client();
}
public function checks(): ConsulResponse
{
return $this->client->get('/v1/agent/checks');
}
public function services(): ConsulResponse
{
return $this->client->get('/v1/agent/services');
}
public function members(array $options = []): ConsulResponse
{
$params = [
'query' => OptionsResolver::resolve($options, ['wan']),
];
return $this->client->get('/v1/agent/members', $params);
}
public function self(): ConsulResponse
{
return $this->client->get('/v1/agent/self');
}
public function join(string $address, array $options = []): ConsulResponse
{
$params = [
'query' => OptionsResolver::resolve($options, ['wan']),
];
return $this->client->get('/v1/agent/join/'.$address, $params);
}
public function forceLeave(string $node): ConsulResponse
{
return $this->client->get('/v1/agent/force-leave/'.$node);
}
public function registerCheck(array $check): ConsulResponse
{
$params = [
'json' => $check,
];
return $this->client->put('/v1/agent/check/register', $params);
}
public function deregisterCheck(string $checkId): ConsulResponse
{
return $this->client->put('/v1/agent/check/deregister/'.$checkId);
}
public function passCheck(string $checkId, array $options = []): ConsulResponse
{
$params = [
'query' => OptionsResolver::resolve($options, ['note']),
];
return $this->client->put('/v1/agent/check/pass/'.$checkId, $params);
}
public function warnCheck(string $checkId, array $options = []): ConsulResponse
{
$params = [
'query' => OptionsResolver::resolve($options, ['note']),
];
return $this->client->put('/v1/agent/check/warn/'.$checkId, $params);
}
public function failCheck(string $checkId, array $options = []): ConsulResponse
{
$params = [
'query' => OptionsResolver::resolve($options, ['note']),
];
return $this->client->put('/v1/agent/check/fail/'.$checkId, $params);
}
public function registerService(array $service): ConsulResponse
{
$params = [
'json' => $service,
];
return $this->client->put('/v1/agent/service/register', $params);
}
public function deregisterService(string $serviceId): ConsulResponse
{
return $this->client->put('/v1/agent/service/deregister/'.$serviceId);
}
}