Agent.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * This file is part of Hyperf.
  5. *
  6. * @link https://www.hyperf.io
  7. * @document https://hyperf.wiki
  8. * @contact group@hyperf.io
  9. * @license https://github.com/hyperf/hyperf/blob/master/LICENSE
  10. */
  11. namespace Hyperf\Consul;
  12. class Agent extends Client implements AgentInterface
  13. {
  14. public function checks(): ConsulResponse
  15. {
  16. return $this->request('GET', '/v1/agent/checks');
  17. }
  18. public function services(): ConsulResponse
  19. {
  20. return $this->request('GET', '/v1/agent/services');
  21. }
  22. public function members(array $options = []): ConsulResponse
  23. {
  24. $params = [
  25. 'query' => $this->resolveOptions($options, ['wan']),
  26. ];
  27. return $this->request('GET', '/v1/agent/members', $params);
  28. }
  29. public function self(): ConsulResponse
  30. {
  31. return $this->request('GET', '/v1/agent/self');
  32. }
  33. public function join($address, array $options = []): ConsulResponse
  34. {
  35. $params = [
  36. 'query' => $this->resolveOptions($options, ['wan']),
  37. ];
  38. return $this->request('GET', '/v1/agent/join/' . $address, $params);
  39. }
  40. public function forceLeave($node): ConsulResponse
  41. {
  42. return $this->request('PUT', '/v1/agent/force-leave/' . $node);
  43. }
  44. public function registerCheck($check): ConsulResponse
  45. {
  46. $params = [
  47. 'body' => json_encode($check),
  48. ];
  49. return $this->request('PUT', '/v1/agent/check/register', $params);
  50. }
  51. public function deregisterCheck($checkId): ConsulResponse
  52. {
  53. return $this->request('PUT', '/v1/agent/check/deregister/' . $checkId);
  54. }
  55. public function passCheck($checkId, array $options = []): ConsulResponse
  56. {
  57. $params = [
  58. 'query' => $this->resolveOptions($options, ['note']),
  59. ];
  60. return $this->request('PUT', '/v1/agent/check/pass/' . $checkId, $params);
  61. }
  62. public function warnCheck($checkId, array $options = []): ConsulResponse
  63. {
  64. $params = [
  65. 'query' => $this->resolveOptions($options, ['note']),
  66. ];
  67. return $this->request('PUT', '/v1/agent/check/warn/' . $checkId, $params);
  68. }
  69. public function failCheck($checkId, array $options = []): ConsulResponse
  70. {
  71. $params = [
  72. 'query' => $this->resolveOptions($options, ['note']),
  73. ];
  74. return $this->request('PUT', '/v1/agent/check/fail/' . $checkId, $params);
  75. }
  76. public function registerService(array $service): ConsulResponse
  77. {
  78. $params = [
  79. 'body' => json_encode($service),
  80. ];
  81. return $this->request('PUT', '/v1/agent/service/register', $params);
  82. }
  83. public function deregisterService($serviceId): ConsulResponse
  84. {
  85. return $this->request('PUT', '/v1/agent/service/deregister/' . $serviceId);
  86. }
  87. }