/** * @param QueryOptions|null $queryOptions * @return array( * @type \DCarbone\PHPConsulAPI\Operator\RaftConfiguration|null Current Raft Configuration or null on error * @type \DCarbone\PHPConsulAPI\QueryMeta query metadata * @type \DCarbone\PHPConsulAPI\Error error, if any * ) */ public function raftGetConfiguration(QueryOptions $queryOptions = null) { $r = new Request('get', 'v1/operator/raft/configuration', $this->c); $r->setQueryOptions($queryOptions); /** @var \Psr\Http\Message\ResponseInterface $response */ list($duration, $response, $err) = $this->requireOK($this->doRequest($r)); $qm = $this->buildQueryMeta($duration, $response, $r->getUri()); if (null !== $err) { return [null, $qm, $err]; } list($data, $err) = $this->decodeBody($response->getBody()); if (null !== $err) { return [null, $qm, $err]; } return [new RaftConfiguration($data), $qm, $err]; }
/** * @param \DCarbone\PHPConsulAPI\QueryOptions|null $queryOptions * @return array( * @type \DCarbone\PHPConsulAPI\Coordinate\CoordinateEntry[]|null coordinate list or null on error * @type \DCarbone\PHPConsulAPI\QueryMeta query metadata * @type \DCarbone\PHPConsulAPI\Error|null error, if any * ) */ public function nodes(QueryOptions $queryOptions = null) { $r = new Request('get', 'v1/coordinate/nodes', $this->c); $r->setQueryOptions($queryOptions); /** @var \Psr\Http\Message\ResponseInterface $response */ list($duration, $response, $err) = $this->requireOK($this->doRequest($r)); $qm = $this->buildQueryMeta($duration, $response, $r->getUri()); if (null !== $err) { return [null, $qm, $err]; } list($data, $err) = $this->decodeBody($response->getBody()); if (null !== $err) { return [null, $qm, $err]; } $coordinates = array(); foreach ($data as $coord) { $coordinates[] = new CoordinateEntry($coord); } return [$coordinates, $qm, null]; }
/** * @param string $name * @param \DCarbone\PHPConsulAPI\QueryOptions|null $queryOptions * @return array( * @type UserEvent[] list of user events or null on error * @type \DCarbone\PHPConsulAPI\QueryMeta query metadata * @type \DCarbone\PHPConsulAPI\Error error, if any * ) */ public function eventList($name = '', QueryOptions $queryOptions = null) { $r = new Request('get', 'v1/event/list', $this->c); if ('' !== (string) $name) { $r->params->set('name', $name); } $r->setQueryOptions($queryOptions); /** @var \Psr\Http\Message\ResponseInterface $response */ list($duration, $response, $err) = $this->requireOK($this->doRequest($r)); $qm = $this->buildQueryMeta($duration, $response, $r->getUri()); if (null !== $err) { return [null, $qm, $err]; } list($data, $err) = $this->decodeBody($response->getBody()); if (null !== $err) { return [null, $qm, $err]; } $events = array(); foreach ($data as $event) { $events[] = new UserEvent($event); } return [$events, $qm, null]; }
/** * @param string $node * @param \DCarbone\PHPConsulAPI\QueryOptions|null $queryOptions * @return array( * @type CatalogNode node or null on error * @type \DCarbone\PHPConsulAPI\QueryMeta query metadata * @type \DCarbone\PHPConsulAPI\Error|null error, if any * ) */ public function node($node, QueryOptions $queryOptions = null) { $r = new Request('get', sprintf('v1/catalog/node/%s', $node), $this->c); $r->setQueryOptions($queryOptions); /** @var \Psr\Http\Message\ResponseInterface $response */ list($duration, $response, $err) = $this->requireOK($this->doRequest($r)); $qm = $this->buildQueryMeta($duration, $response, $r->getUri()); if (null !== $err) { return [null, $qm, $err]; } list($data, $err) = $this->decodeBody($response->getBody()); if (null !== $err) { return [null, $qm, $err]; } return [new CatalogNode($data), $qm, null]; }
/** * @param QueryOptions|null $queryOptions * @return array( * @type \DCarbone\PHPConsulAPI\Session\SessionEntry[]|null list of session entries or null on error * @type \DCarbone\PHPConsulAPI\QueryMeta query metadata * @type \DCarbone\PHPConsulAPI\Error|null error, if any * ) */ public function listSessions(QueryOptions $queryOptions = null) { $r = new Request('get', 'v1/session/list', $this->c); $r->setQueryOptions($queryOptions); /** @var \Psr\Http\Message\ResponseInterface $response */ list($duration, $response, $err) = $this->requireOK($this->doRequest($r)); $qm = $this->buildQueryMeta($duration, $response, $r->getUri()); if (null !== $err) { return [null, $qm, $err]; } list($data, $err) = $this->decodeBody($response->getBody()); if (null !== $err) { return [null, $qm, $err]; } return [$this->_hydrateEntries($data), $qm, null]; }
/** * @param string $state * @param \DCarbone\PHPConsulAPI\QueryOptions|null $queryOptions * @return array( * @type HealthCheck[]|null array of heath checks or null on error * @type \DCarbone\PHPConsulAPI\QueryMeta|null query metadata or null on error * @type \DCarbone\PHPConsulAPI\Error|null error, if any * ) */ public function state($state, QueryOptions $queryOptions = null) { static $validStates = array('any', 'warning', 'critical', 'passing', 'unknown'); if (!is_string($state) || !in_array($state, $validStates, true)) { return [null, null, new Error(sprintf('%s::state - "$state" must be string with value of ["%s"]. %s seen.', get_class($this), implode('", "', $validStates), is_string($state) ? $state : gettype($state)))]; } $r = new Request('get', sprintf('v1/health/state/%s', $state), $this->c); $r->setQueryOptions($queryOptions); /** @var \Psr\Http\Message\ResponseInterface $response */ list($duration, $response, $err) = $this->requireOK($this->doRequest($r)); $qm = $this->buildQueryMeta($duration, $response, $r->getUri()); if (null !== $err) { return [null, $qm, $err]; } list($data, $err) = $this->decodeBody($response->getBody()); if (null !== $err) { return [null, $qm, $err]; } $checks = array(); foreach ($data as $check) { $checks[] = new HealthCheck($check); } return [$checks, $qm, null]; }
/** * @param string $queryIDOrName * @param QueryOptions|null $queryOptions * @return array( * @type \DCarbone\PHPConsulAPI\PreparedQuery\PreparedQueryExecuteResponse|null prepared query response or null * @type \DCarbone\PHPConsulAPI\QueryMeta Query meta data * @type \DCarbone\PHPConsulAPI\Error|null error, if any * ) */ public function execute($queryIDOrName, QueryOptions $queryOptions = null) { $r = new Request('GET', sprintf('v1/query/%s', $queryIDOrName), $this->c); $r->setQueryOptions($queryOptions); /** @var \Psr\Http\Message\ResponseInterface $response */ list($duration, $response, $err) = $this->requireOK($this->doRequest($r)); $qm = $this->buildQueryMeta($duration, $response, $r->getUri()); if (null !== $err) { return [null, $qm, $err]; } list($body, $err) = $this->decodeBody($response->getBody()); if (null !== $err) { return [null, $qm, $err]; } return [new PreparedQueryExecuteResponse($body), $qm, null]; }
/** * @param QueryOptions|null $queryOptions * @return array( * @type \DCarbone\PHPConsulAPI\ACL\ACLEntry[] acl entries or null on error * @type \DCarbone\PHPConsulAPI\QueryMeta query meta data * @type \DCarbone\PHPConsulAPI\Error|null error, if any * ) */ public function listACLs(QueryOptions $queryOptions = null) { $r = new Request('GET', 'v1/acl/list', $this->c); $r->setQueryOptions($queryOptions); /** @var \Psr\Http\Message\ResponseInterface $response */ list($duration, $response, $err) = $this->requireOK($this->doRequest($r)); $qm = $this->buildQueryMeta($duration, $response, $r->getUri()); if (null !== $err) { return [null, $qm, $err]; } list($data, $err) = $this->decodeBody($response->getBody()); if (null !== $err) { return [null, $qm, $err]; } $entries = []; foreach ($data as $entry) { $entries[] = new ACLEntry($entry); } return [$entries, $qm, null]; }
/** * @param string $prefix Prefix to search for. Null returns all keys. * @param \DCarbone\PHPConsulAPI\QueryOptions $queryOptions * @return array( * @type string[]|null list of keys * @type \DCarbone\PHPConsulAPI\QueryMeta|null query metadata * @type \DCarbone\PHPConsulAPI\Error|null error, if any * ) */ public function keys($prefix = null, QueryOptions $queryOptions = null) { if (null !== $prefix && !is_string($prefix)) { return [null, null, new Error(sprintf('%s::keys - Prefix expected to be empty or string, %s seen.', get_class($this), gettype($prefix)))]; } if (null === $prefix) { $r = new Request('get', 'v1/kv/', $this->c); } else { $r = new Request('get', sprintf('v1/kv/%s', $prefix), $this->c); } $r->setQueryOptions($queryOptions); $r->params->set('keys', true); /** @var \Psr\Http\Message\ResponseInterface $response */ list($duration, $response, $err) = $this->requireOK($this->doRequest($r)); $qm = $this->buildQueryMeta($duration, $response, $r->getUri()); if (null !== $err) { return [null, $qm, $err]; } list($data, $err) = $this->decodeBody($response->getBody()); return [$data, $qm, $err]; }