You are here

function elasticsearch_connector_cluster_indices in Elasticsearch Connector 7

Same name and namespace in other branches
  1. 7.5 elasticsearch_connector.admin.inc \elasticsearch_connector_cluster_indices()
  2. 7.2 elasticsearch_connector.admin.inc \elasticsearch_connector_cluster_indices()

Elasticsearch Connector display all indices in cluster.

Parameters

object:

Return value

array

1 string reference to 'elasticsearch_connector_cluster_indices'
elasticsearch_connector_menu in ./elasticsearch_connector.module
Implements hook_menu().

File

./elasticsearch_connector.admin.inc, line 82
Created on Dec 23, 2013

Code

function elasticsearch_connector_cluster_indices($cluster) {
  $headers = array(
    array(
      'data' => t('Index name'),
    ),
    array(
      'data' => t('Docs'),
    ),
    array(
      'data' => t('Size'),
    ),
    array(
      'data' => t('Operations'),
    ),
  );
  $rows = array();
  $cluster_info = elasticsearch_connector_get_cluster_info($cluster);
  $client = $cluster_info['client'];
  if ($client && !empty($cluster_info['info']) && elasticsearch_connector_check_status($cluster_info['info'])) {
    $indices = $client
      ->indices()
      ->stats();
    foreach ($indices['indices'] as $index_name => $index_info) {
      $row = array();
      $operations = theme('links__ctools_dropbutton', array(
        'links' => array(
          array(
            'title' => t('Edit'),
            'href' => elasticsearch_connector_main_settings_path() . '/clusters/' . $cluster->cluster_id . '/indices/' . $index_name . '/edit',
          ),
          array(
            'title' => t('Aliases'),
            'href' => elasticsearch_connector_main_settings_path() . '/clusters/' . $cluster->cluster_id . '/indices/' . $index_name . '/aliases',
          ),
          array(
            'title' => t('Delete'),
            'href' => elasticsearch_connector_main_settings_path() . '/clusters/' . $cluster->cluster_id . '/indices/' . $index_name . '/delete',
          ),
        ),
        'attributes' => array(
          'class' => array(
            'links',
            'inline',
          ),
        ),
      ));
      $row[] = $index_name;
      $row[] = $index_info['total']['docs']['count'];
      $row[] = format_size($index_info['total']['store']['size_in_bytes']);
      $row[] = $operations;
      $rows[] = $row;
    }
  }
  else {
    drupal_set_message(t('The cluster cannot be connected for some reason.'), 'error');
  }
  $output['elasticsearch_connector']['table'] = array(
    '#theme' => 'table',
    '#header' => $headers,
    '#rows' => $rows,
    '#attributes' => array(
      'class' => array(
        'admin-elasticsearch-connector-indices',
      ),
    ),
  );
  return $output;
}