class DESConnector81 in Elasticsearch Connector 8
Drupal Elasticsearch Interface.
@package Drupal\elasticsearch_connector
Hierarchy
- class \Drupal\elasticsearch_connector\DESConnector\DESConnector implements DESConnectorInterface
- class \Drupal\elasticsearch_connector\DESConnector\DESConnector81 implements DESConnectorInterface
Expanded class hierarchy of DESConnector81
File
- src/
DESConnector/ DESConnector81.php, line 20 - Provides Elasticsearch Client for Drupal's Elasticsearch Connector module.
Namespace
Drupal\elasticsearch_connector\DESConnectorView source
class DESConnector81 extends 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() {
}
/**
* 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) {
$hash_hosts = array();
foreach ($hosts as $host) {
$hash_hosts[] = $host['url'];
}
$hash = md5(implode(':', $hash_hosts));
if (!isset($instances[$hash])) {
foreach ($hosts as $host) {
$cluster_url = self::buildClusterUrl($host['url'], $host['options']);
$options['hosts'][] = $cluster_url;
self::setAuthentication($options, $host);
}
// TODO: Remove this from the abstraction!
// It should be passed via parameter.
\Drupal::moduleHandler()
->alter('elasticsearch_connector_load_library_options', $options);
$builder = new Client($options);
$instances[$hash] = new DESConnector81($builder);
}
return $instances[$hash];
}
/**
* Builds the proper cluster URL based on the provided options.
*
* @param $cluster
*
* @return string
*/
public static function buildClusterUrl($cluster_url, $options) {
return $cluster_url;
}
/**
* Sets the HTTP authentication options.
*
* @param array $options
* Array with the options to pass to the Elasticsearch Client.
* @param array $host
* Array with the host options as provided from the Cluster form.
*/
public static function setAuthentication(&$options, $host) {
if (!empty($host['options']['use_authentication'])) {
$options['connectionParams'] = array(
'auth' => array(
$host['options']['username'],
$host['options']['password'],
$host['options']['authentication_type'],
),
);
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DESConnector81:: |
protected | property |
Overrides DESConnector:: |
|
DESConnector81:: |
protected static | property |
Overrides DESConnector:: |
|
DESConnector81:: |
public static | function | Builds the proper cluster URL based on the provided options. | |
DESConnector81:: |
constant |
Overrides DESConnector:: |
||
DESConnector81:: |
constant |
Overrides DESConnector:: |
||
DESConnector81:: |
constant |
Overrides DESConnector:: |
||
DESConnector81:: |
public static | function |
Initializes the needed client. Overrides DESConnector:: |
|
DESConnector81:: |
public static | function | Sets the HTTP authentication options. | |
DESConnector81:: |
private | function |
Singleton clone. Overrides DESConnector:: |
|
DESConnector81:: |
private | function |
Singleton constructor. Overrides DESConnector:: |
|
DESConnector81:: |
private | function |
Singleton sleep. Overrides DESConnector:: |
|
DESConnector81:: |
private | function |
Singleton wakeup. Overrides DESConnector:: |
|
DESConnector:: |
public | function | ||
DESConnector:: |
public | function | Check if we have a connection the cluster. | |
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 | 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. |