You are here

function elasticsearch_connector_load_library in Elasticsearch Connector 7

Same name and namespace in other branches
  1. 7.5 elasticsearch_connector.module \elasticsearch_connector_load_library()
  2. 7.2 elasticsearch_connector.module \elasticsearch_connector_load_library()

Parameters

string $url:

6 calls to elasticsearch_connector_load_library()
elasticsearch_connector_cluster_indices_add in ./elasticsearch_connector.admin.inc
Create new index in the cluster with shard settings and other settings.
elasticsearch_connector_cluster_indices_add_submit in ./elasticsearch_connector.admin.inc
Submit the values of index create form.
elasticsearch_connector_cluster_indices_delete_submit in ./elasticsearch_connector.admin.inc
Delete an index.
elasticsearch_connector_get_client_by_id in ./elasticsearch_connector.module
Return the cluster object based on Cluster ID.
elasticsearch_connector_get_cluster_info in ./elasticsearch_connector.module
Return cluster info.

... See full list

File

./elasticsearch_connector.module, line 784
This module provide an interface to connecting to the elasticsearch cluster and implementing the official Elasticsearch library.

Code

function elasticsearch_connector_load_library($cluster) {
  static $clients;
  if (!isset($clients[$cluster->cluster_id])) {
    $clients[$cluster->cluster_id] = FALSE;

    // TODO: Handle cluster connection. This should be accomplished if the setting is enabled.
    // If enabled, discover all the nodes in the cluster initialize the Pool connection.
    if (valid_url($cluster->url)) {
      $options = array(
        'hosts' => array(
          $cluster->url,
        ),
        'guzzleOptions' => array(
          'curl.options' => array(
            CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4,
            CURLOPT_CONNECTTIMEOUT => !empty($cluster->options['timeout']) ? $cluster->options['timeout'] : ELASTICSEARCH_CONNECTOR_DEFAULT_TIMEOUT,
          ),
        ),
      );
      if (!empty($cluster->options['use_authentication'])) {
        $options['connectionParams'] = array(
          'auth' => array(
            $cluster->options['username'],
            $cluster->options['password'],
            $cluster->options['authentication_type'],
          ),
        );
      }
      try {
        if (!class_exists('\\Elasticsearch\\Client') && module_exists('composer_manager')) {

          // If the class doesn't exists try to explicitly load the classes!
          // The issues is in update.php where search api call this function, but the function
          // has not been invoked.
          composer_manager_register_autoloader();
        }
        if (!class_exists('\\Elasticsearch\\Client')) {

          // No library available!
          return FALSE;
        }
        drupal_alter('elasticsearch_connector_load_library_options', $options, $cluster);
        $clients[$cluster->cluster_id] = new \Elasticsearch\Client($options);
      } catch (Exception $e) {
        drupal_set_message($e
          ->getMessage(), 'error');
      }
    }
  }
  return $clients[$cluster->cluster_id];
}