class DESConnector in Elasticsearch Connector 8
Drupal Elasticsearch Interface.
@package Drupal\elasticsearch_connector
Hierarchy
- class \Drupal\elasticsearch_connector\DESConnector\DESConnector implements DESConnectorInterface
Expanded class hierarchy of DESConnector
File
- src/
DESConnector/ DESConnector.php, line 19 - Provides Elasticsearch Client for Drupal's Elasticsearch Connector module.
Namespace
Drupal\elasticsearch_connector\DESConnectorView source
class DESConnector implements DESConnectorInterface {
const CLUSTER_STATUS_GREEN = 'green';
const CLUSTER_STATUS_YELLOW = 'yellow';
const CLUSTER_STATUS_RED = 'red';
protected static $instances;
protected $client;
/**
* Singleton constructor.
*/
private function __construct($client) {
// TODO: Validate if we have a valid client.
$this->client = $client;
}
/**
* Singleton clone.
*/
private function __clone() {
}
/**
* Singleton wakeup.
*/
private function __wakeup() {
}
/**
* Singleton sleep.
*/
private function __sleep() {
}
/**
* Magic method call.
*/
public function __call($name, $arguments) {
if (method_exists($this
->getClient(), $name)) {
return call_user_func_array(array(
$this
->getClient(),
$name,
), $arguments);
}
}
/**
* Initializes the needed client.
*
* TODO: We need to check the available options for the ClientBuilder
* and set them after the alter hook.
*
* @param array $hosts
* The URLs of the Elasticsearch hosts.
*
* @return Client
*/
public static function getInstance(array $hosts) {
if (ELASTICSEARCH_CONNECTOR_VERSION < 2) {
return DESConnector81::getInstance($hosts);
}
else {
return DESConnector82::getInstance($hosts);
}
}
/**
* @return mixed
*/
public function getCluster() {
return $this
->getClient()
->cluster();
}
/**
* @return mixed
*/
public function getNodes() {
return $this
->getClient()
->nodes();
}
/**
* @return mixed
*/
public function getIndices() {
return $this
->getClient()
->indices();
}
/**
* @return mixed
*/
public function bulk(array $params) {
return $this
->getClient()
->bulk($params);
}
/**
* @return mixed
*/
protected function getClient() {
return $this->client;
}
/**
* Check if we have a connection the cluster.
*
* @return bool
*/
public function getClusterStatus() {
try {
$health = $this
->getCluster()
->health();
return $health['status'];
} catch (Exception $e) {
return FALSE;
}
}
/**
* Check if we have a connection the cluster.
*
* @return bool
*/
public function clusterIsOk() {
try {
$health = $this
->getCluster()
->health();
if (in_array($health['status'], array(
self::CLUSTER_STATUS_GREEN,
self::CLUSTER_STATUS_YELLOW,
))) {
$status = TRUE;
}
else {
$status = FALSE;
}
} catch (Exception $e) {
$status = FALSE;
}
return $status;
}
/**
* Get cluster health.
*
* @return array
*/
public function getClusterHealth() {
return $this
->getCluster()
->health();
}
/**
* Get cluster state.
*
* @return array
*/
public function getClusterState() {
return $this
->getCluster()
->state();
}
/**
* Get cluster stats.
*
* @return array
*/
public function getClusterStats() {
return $this
->getCluster()
->stats();
}
/**
* Return cluster info.
*
* @return array
* Info array.
*
* @throws \Exception
* Exception().
*/
public function getClusterInfo() {
$result = FALSE;
try {
try {
$result['state'] = $this
->getClusterState();
$result['health'] = $this
->getClusterHealth();
$result['stats'] = $this
->getClusterStats();
} catch (\Exception $e) {
// TODO: Do not set messages or log messages into the abstraction.
drupal_set_message($e
->getMessage(), 'error');
}
} catch (\Exception $e) {
throw $e;
}
return $result;
}
/**
* Get nodes stats.
*
* @return array
*/
public function getNodesStats() {
return $this
->getNodes()
->stats();
}
/**
* Get nodes info.
*
* @return array
*/
public function getNodesInfo() {
return $this
->getNodes()
->info();
}
/**
* Return nodes info.
*
* @return array
* Info array.
*
* @throws \Exception
* Exception().
*/
public function getNodesProperties() {
$result = FALSE;
try {
try {
$result['stats'] = $this
->getNodesStats();
$result['info'] = $this
->getNodesInfo();
} catch (\Exception $e) {
// TODO: Do not set messages or log messages into the abstraction.
drupal_set_message($e
->getMessage(), 'error');
}
} catch (\Exception $e) {
throw $e;
}
return $result;
}
/**
* Elasticsearch info function.
*
* @return array
*/
public function info() {
return $this
->getClient()
->info();
}
/**
* Elasticsearch ping function.
*
* @return array
*/
public function ping() {
return $this
->getClient()
->ping();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DESConnector:: |
protected | property | 2 | |
DESConnector:: |
protected static | property | 2 | |
DESConnector:: |
public | function | ||
DESConnector:: |
public | function | Check if we have a connection the cluster. | |
DESConnector:: |
constant | 2 | ||
DESConnector:: |
constant | 2 | ||
DESConnector:: |
constant | 2 | ||
DESConnector:: |
protected | function | ||
DESConnector:: |
public | function | ||
DESConnector:: |
public | function | Get cluster health. | |
DESConnector:: |
public | function | Return cluster info. | |
DESConnector:: |
public | function | Get cluster state. | |
DESConnector:: |
public | function | Get cluster stats. | |
DESConnector:: |
public | function | Check if we have a connection the cluster. | |
DESConnector:: |
public | function | ||
DESConnector:: |
public static | function |
Initializes the needed client. Overrides DESConnectorInterface:: |
2 |
DESConnector:: |
public | function | ||
DESConnector:: |
public | function | Get nodes info. | |
DESConnector:: |
public | function | Return nodes info. | |
DESConnector:: |
public | function | Get nodes stats. | |
DESConnector:: |
public | function | Elasticsearch info function. | |
DESConnector:: |
public | function | Elasticsearch ping function. | |
DESConnector:: |
public | function | Magic method call. | |
DESConnector:: |
private | function | Singleton clone. | 2 |
DESConnector:: |
private | function | Singleton constructor. | 2 |
DESConnector:: |
private | function | Singleton sleep. | 2 |
DESConnector:: |
private | function | Singleton wakeup. | 2 |