You are here

class DESConnector81 in Elasticsearch Connector 8

Drupal Elasticsearch Interface.

@package Drupal\elasticsearch_connector

Hierarchy

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\DESConnector
View 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

Namesort descending Modifiers Type Description Overrides
DESConnector81::$client protected property Overrides DESConnector::$client
DESConnector81::$instances protected static property Overrides DESConnector::$instances
DESConnector81::buildClusterUrl public static function Builds the proper cluster URL based on the provided options.
DESConnector81::CLUSTER_STATUS_GREEN constant Overrides DESConnector::CLUSTER_STATUS_GREEN
DESConnector81::CLUSTER_STATUS_RED constant Overrides DESConnector::CLUSTER_STATUS_RED
DESConnector81::CLUSTER_STATUS_YELLOW constant Overrides DESConnector::CLUSTER_STATUS_YELLOW
DESConnector81::getInstance public static function Initializes the needed client. Overrides DESConnector::getInstance
DESConnector81::setAuthentication public static function Sets the HTTP authentication options.
DESConnector81::__clone private function Singleton clone. Overrides DESConnector::__clone
DESConnector81::__construct private function Singleton constructor. Overrides DESConnector::__construct
DESConnector81::__sleep private function Singleton sleep. Overrides DESConnector::__sleep
DESConnector81::__wakeup private function Singleton wakeup. Overrides DESConnector::__wakeup
DESConnector::bulk public function
DESConnector::clusterIsOk public function Check if we have a connection the cluster.
DESConnector::getClient protected function
DESConnector::getCluster public function
DESConnector::getClusterHealth public function Get cluster health.
DESConnector::getClusterInfo public function Return cluster info.
DESConnector::getClusterState public function Get cluster state.
DESConnector::getClusterStats public function Get cluster stats.
DESConnector::getClusterStatus public function Check if we have a connection the cluster.
DESConnector::getIndices public function
DESConnector::getNodes public function
DESConnector::getNodesInfo public function Get nodes info.
DESConnector::getNodesProperties public function Return nodes info.
DESConnector::getNodesStats public function Get nodes stats.
DESConnector::info public function Elasticsearch info function.
DESConnector::ping public function Elasticsearch ping function.
DESConnector::__call public function Magic method call.