/** * @param string $address * @param WriteOptions|null $writeOptions * @return \DCarbone\PHPConsulAPI\Error|null error, if any */ public function raftRemovePeerByAddress($address, WriteOptions $writeOptions = null) { $r = new Request('delete', 'v1/operator/raft/peer', $this->c); $r->setWriteOptions($writeOptions); $r->params->set('address', (string) $address); list($_, $_, $err) = $this->requireOK($this->doRequest($r)); return $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 KVPair $p * @param \DCarbone\PHPConsulAPI\WriteOptions $writeOptions * @return array( * @type \DCarbone\PHPConsulAPI\WriteMeta write metadata * @type \DCarbone\PHPConsulAPI\Error|null error, if any * ) */ public function release(KVPair $p, WriteOptions $writeOptions = null) { $r = new Request('put', sprintf('v1/kv/%s', $p->Key), $this->c); $r->setWriteOptions($writeOptions); $r->params->set('release', $p->Session); if (0 !== $p->Flags) { $r->params->set('flags', $p->Flags); } list($duration, $_, $err) = $this->requireOK($this->doRequest($r)); $wm = $this->buildWriteMeta($duration); return [$wm, $err]; }