Skip to content

Commit 1fda76d

Browse files
lachezarvalchevnignatov
authored andcommittedNov 28, 2015
Issue #2620026 by lachezar.valchev: Cluster form improvements.
1 parent 2863f8a commit 1fda76d

File tree

2 files changed

+77
-65
lines changed

2 files changed

+77
-65
lines changed
 

‎elasticsearch_connector.admin.inc

+76-64
Original file line numberDiff line numberDiff line change
@@ -303,46 +303,42 @@ function elasticsearch_connector_edit_cluster($form, $form_state, $cluster = NUL
303303
'#type' => 'textfield',
304304
'#title' => t('Administrative cluster name'),
305305
'#default_value' => empty($cluster->name) ? '' : $cluster->name,
306-
'#description' => t('Enter the administrative cluster name that will uniquely define your Elasticsearch cluster'),
306+
'#description' => t('Enter the administrative cluster name that will be your Elasticsearch cluster unique identifier.'),
307307
'#required' => TRUE,
308308
);
309309

310310
$form['cluster_id'] = array(
311311
'#type' => 'machine_name',
312312
'#title' => t('Cluster id'),
313+
'#default_value' => !empty($cluster->cluster_id) ? $cluster->cluster_id : '',
314+
'#maxlength' => 125,
315+
'#description' => t('A unique machine-readable name for this Elasticsearch cluster.'),
313316
'#machine_name' => array(
314317
'exists' => 'elasticsearch_connector_cluster_load',
315318
),
316-
'#default_value' => !empty($cluster->cluster_id) ? $cluster->cluster_id : '',
317-
'#disabled' => !empty($cluster->cluster_id), // Cannot change it once set.
318-
'#description' =>
319-
t('Unique, machine-readable identifier for this Elasticsearch environment.'),
320319
'#required' => TRUE,
320+
'#disabled' => !empty($cluster->cluster_id),
321321
);
322322

323323
$form['url'] = array(
324324
'#type' => 'textfield',
325325
'#title' => t('Server URL'),
326326
'#default_value' => !empty($cluster->url) ? $cluster->url : '',
327-
'#description' => t('Enter the URL and the port of a server (node) in the cluster. Example: http://localhost:9200. Please enter the port also even it is the default one e.g. https://localhost:443'),
327+
'#description' => t(
328+
'URL and port of a server (node) in the cluster. ' .
329+
'Please, always enter the port even if it is default one. ' .
330+
'Nodes will be automatically discovered. ' .
331+
'Examples: http://localhost:9200 or https://localhost:443.'),
328332
'#required' => TRUE,
329-
//'#limit_validation_errors' => array(array('url')),
330333
);
331334

332-
$cluster_info = NULL;
333-
$form_state_active = FALSE;
334-
if (isset($cluster->url) && empty($form_state['input'])) {
335-
$cluster_info = elasticsearch_connector_get_cluster_info($cluster);
336-
$form_state_active = TRUE;
337-
}
338-
339-
$form['status_info'] = elasticsearch_connector_edit_cluster_form_info($cluster_info, $form_state_active);
335+
$form['status_info'] = elasticsearch_connector_edit_cluster_form_info($cluster);
340336

341337
$default = elasticsearch_connector_get_default_connector();
342338
$form['default'] = array(
343339
'#type' => 'checkbox',
344340
'#title' => t('Make this cluster default connection'),
345-
'#description' => t('If no specific cluster connection specified the API will use the default connection.'),
341+
'#description' => t('If the cluster connection is not specified the API will use the default connection.'),
346342
'#default_value' => (empty($default) || (!empty($cluster->cluster_id) && $cluster->cluster_id == $default)) ? '1' : '0',
347343
);
348344

@@ -353,8 +349,8 @@ function elasticsearch_connector_edit_cluster($form, $form_state, $cluster = NUL
353349
$form['options']['multiple_nodes_connection'] = array(
354350
'#type' => 'checkbox',
355351
'#title' => t('Use multiple nodes connection'),
356-
'#description' => t('It will automatically discover all nodes and use them in the connection to the cluster. ' .
357-
'The Elasticsearch client can then randomise the query execution between nodes.'),
352+
'#description' => t('Automatically discover all nodes and use them in the cluster connection. ' .
353+
'Then the Elasticsearch client can distribute the query execution on random base between nodes.'),
358354
'#default_value' => (!empty($cluster->options['multiple_nodes_connection']) ? 1 : 0),
359355
);
360356

@@ -397,7 +393,7 @@ function elasticsearch_connector_edit_cluster($form, $form_state, $cluster = NUL
397393
$form['options']['username'] = array(
398394
'#type' => 'textfield',
399395
'#title' => t('Username'),
400-
'#description' => t('The username for the authentication.'),
396+
'#description' => t('The username for authentication.'),
401397
'#default_value' => (!empty($cluster->options['username']) ? $cluster->options['username'] : ''),
402398
'#states' => array (
403399
'visible' => array(
@@ -409,7 +405,7 @@ function elasticsearch_connector_edit_cluster($form, $form_state, $cluster = NUL
409405
$form['options']['password'] = array(
410406
'#type' => 'textfield',
411407
'#title' => t('Password'),
412-
'#description' => t('The password for the authentication.'),
408+
'#description' => t('The password for authentication.'),
413409
'#default_value' => (!empty($cluster->options['password']) ? $cluster->options['password'] : ''),
414410
'#states' => array (
415411
'visible' => array(
@@ -424,7 +420,7 @@ function elasticsearch_connector_edit_cluster($form, $form_state, $cluster = NUL
424420
'#size' => 20,
425421
'#required' => TRUE,
426422
'#element_validate' => array('element_validate_number'),
427-
'#description' => t('The seconds in which the connection will timeout if no connection with Elasticsearch.'),
423+
'#description' => t('After how many seconds the connection should timeout if there is no connection to Elasticsearch.'),
428424
'#default_value' => (!empty($cluster->options['timeout']) ? $cluster->options['timeout'] : ELASTICSEARCH_CONNECTOR_DEFAULT_TIMEOUT),
429425
);
430426

@@ -598,50 +594,66 @@ function elasticsearch_connector_cluster_indices_add_submit($form, &$form_state)
598594
* @param bool $ajax
599595
* @return array
600596
*/
601-
function elasticsearch_connector_edit_cluster_form_info($cluster_info = NULL, $ajax = NULL) {
602-
$headers = array(
603-
array('data' => t('Cluster name')),
604-
array('data' => t('Status')),
605-
array('data' => t('Number of nodes')),
606-
);
607-
608-
$rows = $element = array();
609-
610-
if (isset($cluster_info['state'])) {
611-
$rows = array(array(
612-
$cluster_info['health']['cluster_name'],
613-
$cluster_info['health']['status'],
614-
$cluster_info['health']['number_of_nodes'],
615-
));
616-
617-
$element = array(
618-
'#theme' => 'table',
619-
'#header' => $headers,
620-
'#rows' => $rows,
621-
'#attributes' => array(
622-
'class' => array('admin-elasticsearch-connector'),
623-
'id' => 'cluster-info'),
624-
);
625-
}
626-
elseif (!empty($ajax)) {
627-
$rows = array(array(
628-
t('Unknown'),
629-
t('Unavailable'),
630-
'',
631-
));
597+
function elasticsearch_connector_edit_cluster_form_info($cluster) {
598+
$element = array();
632599

633-
$element = array(
634-
'#theme' => 'table',
635-
'#header' => $headers,
636-
'#rows' => $rows,
637-
'#attributes' => array(
638-
'class' => array('admin-elasticsearch-connector'),
639-
'id' => 'cluster-info'),
640-
);
641-
}
642-
else {
643-
$element['#type'] = 'markup';
644-
$element['#markup'] = '<div id="cluster-info">&nbsp;</div>';
600+
if (isset($cluster->url)) {
601+
try {
602+
$cluster_info = elasticsearch_connector_get_cluster_info($cluster);
603+
if ($cluster_info) {
604+
$headers = array(
605+
array('data' => t('Cluster name')),
606+
array('data' => t('Status')),
607+
array('data' => t('Number of nodes')),
608+
);
609+
610+
if (isset($cluster_info['state'])) {
611+
$rows = array(
612+
array(
613+
$cluster_info['health']['cluster_name'],
614+
$cluster_info['health']['status'],
615+
$cluster_info['health']['number_of_nodes'],
616+
)
617+
);
618+
619+
$element = array(
620+
'#theme' => 'table',
621+
'#header' => $headers,
622+
'#rows' => $rows,
623+
'#attributes' => array(
624+
'class' => array('admin-elasticsearch-connector'),
625+
'id' => 'cluster-info'
626+
),
627+
);
628+
}
629+
else {
630+
$rows = array(
631+
array(
632+
t('Unknown'),
633+
t('Unavailable'),
634+
'',
635+
)
636+
);
637+
638+
$element = array(
639+
'#theme' => 'table',
640+
'#header' => $headers,
641+
'#rows' => $rows,
642+
'#attributes' => array(
643+
'class' => array('admin-elasticsearch-connector'),
644+
'id' => 'cluster-info'
645+
),
646+
);
647+
}
648+
}
649+
else {
650+
$element['#type'] = 'markup';
651+
$element['#markup'] = '<div id="cluster-info">&nbsp;</div>';
652+
}
653+
}
654+
catch (\Exception $e) {
655+
drupal_set_message($e->getMessage(), 'error');
656+
}
645657
}
646658

647659
return $element;

‎elasticsearch_connector.module

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
define('ELASTICSEARCH_CONNECTOR_STATUS_INACTIVE', '0');
1313
define('ELASTICSEARCH_CONNECTOR_STATUS_ACTIVE', '1');
1414
define('ELASTICSEARCH_CONNECTOR_CLUSTER_STATUS_OK', '200');
15-
define('ELASTICSEARCH_CONNECTOR_DEFAULT_TIMEOUT', '3');
15+
define('ELASTICSEARCH_CONNECTOR_DEFAULT_TIMEOUT', '3');
1616

1717
/**
1818
* Implements hook_help().

0 commit comments

Comments
 (0)
Please sign in to comment.