Permalink
Browse files

Added url params validation in describe_keyspace and describe_columnf…

…amily
  • Loading branch information...
1 parent 117dc5c commit 404acf5426cbb3b72bbf95f3a6fb2a1289617f1f @sebgiroux committed Jul 1, 2011
Showing with 120 additions and 81 deletions.
  1. +43 −34 describe_columnfamily.php
  2. +62 −44 describe_keyspace.php
  3. +15 −3 include/kernel.inc.php
View
@@ -15,43 +15,52 @@
$keyspace_name = $_GET['keyspace_name'];
}
- $columnfamily_name = '';
- if (isset($_GET['columnfamily_name'])) {
- $columnfamily_name = $_GET['columnfamily_name'];
+ // Make sure a keyspace name has been specified
+ if ($keyspace_name == '') {
+ echo displayErrorMessage('keyspace_name_must_be_specified');
}
-
- $describe_keyspace = $sys_manager->describe_keyspace($keyspace_name);
-
- $found = false;
-
- foreach ($describe_keyspace->cf_defs as $one_cf) {
- if ($one_cf->name == $columnfamily_name) {
- $found = true;
- break;
+ else {
+ $columnfamily_name = '';
+ if (isset($_GET['columnfamily_name'])) {
+ $columnfamily_name = $_GET['columnfamily_name'];
+ }
+
+ if ($columnfamily_name == '') {
+ echo displayErrorMessage('columnfamily_name_must_be_specified');
+ }
+ else {
+ $one_cf = getCFInKeyspace($keyspace_name,$columnfamily_name);
+
+ // Make sure the column family exists in this keyspace
+ if ($one_cf) {
+ $secondary_indexes = array();
+ foreach ($one_cf->column_metadata as $metadata) {
+ $index_type = $metadata->index_type;
+ if ($metadata->index_type === 0) $index_type = 'Keys';
+
+ $secondary_indexes[] = array('name' => $metadata->name,
+ 'validation_class' => $metadata->validation_class,
+ 'index_type' => $index_type,
+ 'index_name' => $metadata->index_name);
+ }
+
+ $vw_vars['secondary_indexes'] = $secondary_indexes;
+
+ $vw_vars['one_cf'] = $one_cf;
+
+ $vw_vars['cluster_name'] = $sys_manager->describe_cluster_name();
+ $vw_vars['keyspace_name'] = $keyspace_name;
+ $vw_vars['columnfamily_name'] = $columnfamily_name;
+
+ $vw_vars['partitioner'] = $sys_manager->describe_partitioner();
+
+ echo getHTML('describe_columnfamily.php',$vw_vars);
+ }
+ else {
+ echo displayErrorMessage('columnfamily_doesnt_exists',array('column_name' => $columnfamily_name));
+ }
}
}
- $secondary_indexes = array();
- foreach ($one_cf->column_metadata as $metadata) {
- $index_type = $metadata->index_type;
- if ($metadata->index_type === 0) $index_type = 'Keys';
-
- $secondary_indexes[] = array('name' => $metadata->name,
- 'validation_class' => $metadata->validation_class,
- 'index_type' => $index_type,
- 'index_name' => $metadata->index_name);
- }
-
- $vw_vars['secondary_indexes'] = $secondary_indexes;
-
- $vw_vars['one_cf'] = $one_cf;
-
- $vw_vars['cluster_name'] = $sys_manager->describe_cluster_name();
- $vw_vars['keyspace_name'] = $keyspace_name;
- $vw_vars['columnfamily_name'] = $columnfamily_name;
-
- $vw_vars['partitioner'] = $sys_manager->describe_partitioner();
-
- echo getHTML('describe_columnfamily.php',$vw_vars);
echo getHTML('footer.php');
?>
View
@@ -17,53 +17,71 @@
$keyspace_name = $_GET['keyspace_name'];
}
- $describe_keyspace = $sys_manager->describe_keyspace($keyspace_name);
-
- $vw_vars['strategy_class'] = $describe_keyspace->strategy_class;
- $vw_vars['strategy_options'] = $describe_keyspace->strategy_options;
- $vw_vars['replication_factor'] = $describe_keyspace->replication_factor;
-
- $vw_vars['cluster_name'] = $sys_manager->describe_cluster_name();
- $vw_vars['keyspace_name'] = $keyspace_name;
-
- $vw_vars['ring'] = array();
- $vw_vars['list_column_families'] = '';
-
- for ($i = 0; $i < count($describe_keyspace->cf_defs); $i++) {
- $one_cf = $describe_keyspace->cf_defs[$i];
-
- $vw_vars['columnfamily_name'] = $one_cf->name;
- $vw_vars['keyspace_name'] = $keyspace_name;
-
- $vw_vars['column_type'] = $one_cf->column_type;
- $vw_vars['comparator_type'] = $one_cf->comparator_type;
- $vw_vars['subcomparator_type'] = $one_cf->subcomparator_type;
- $vw_vars['comment'] = $one_cf->comment;
- $vw_vars['row_cache_size'] = $one_cf->row_cache_size;
- $vw_vars['key_cache_size'] = $one_cf->key_cache_size;
- $vw_vars['read_repair_chance'] = $one_cf->read_repair_chance;
- $vw_vars['column_metadata'] = $one_cf->column_metadata;
- $vw_vars['gc_grace_seconds'] = $one_cf->gc_grace_seconds;
- $vw_vars['default_validation_class'] = $one_cf->default_validation_class;
- $vw_vars['id'] = $one_cf->id;
- $vw_vars['min_compaction_threshold'] = $one_cf->min_compaction_threshold;
- $vw_vars['max_compaction_threshold'] = $one_cf->max_compaction_threshold;
- $vw_vars['row_cache_save_period_in_seconds'] = $one_cf->row_cache_save_period_in_seconds;
- $vw_vars['key_cache_save_period_in_seconds'] = $one_cf->key_cache_save_period_in_seconds;
- $vw_vars['memtable_flush_after_mins'] = $one_cf->memtable_flush_after_mins;
- $vw_vars['memtable_throughput_in_mb'] = $one_cf->memtable_throughput_in_mb;
- $vw_vars['memtable_operations_in_millions'] = $one_cf->memtable_operations_in_millions;
-
- $vw_vars['list_column_families'] .= getHTML('columnfamily_row.php',$vw_vars);
+ if ($keyspace_name == '') {
+ echo displayErrorMessage('keyspace_name_must_be_specified');
}
+ else {
+ $not_found = false;
+
+ try {
+ $describe_keyspace = $sys_manager->describe_keyspace($keyspace_name);
+ }
+ catch(cassandra_NotFoundException $e) {
+ $not_found = true;
+ }
- try {
- $vw_vars['ring'] = $sys_manager->describe_ring($keyspace_name);
- }
- catch(Exception $e) {
- $vw_vars['ring'] = $e->getMessage();
+ if ($not_found) {
+ echo displayErrorMessage('keyspace_doesnt_exists',array('keyspace_name' => $keyspace_name));
+ }
+ else {
+ $vw_vars['strategy_class'] = $describe_keyspace->strategy_class;
+ $vw_vars['strategy_options'] = $describe_keyspace->strategy_options;
+ $vw_vars['replication_factor'] = $describe_keyspace->replication_factor;
+
+ $vw_vars['cluster_name'] = $sys_manager->describe_cluster_name();
+ $vw_vars['keyspace_name'] = $keyspace_name;
+
+ $vw_vars['ring'] = array();
+ $vw_vars['list_column_families'] = '';
+
+ for ($i = 0; $i < count($describe_keyspace->cf_defs); $i++) {
+ $one_cf = $describe_keyspace->cf_defs[$i];
+
+ $vw_vars['columnfamily_name'] = $one_cf->name;
+ $vw_vars['keyspace_name'] = $keyspace_name;
+
+ $vw_vars['column_type'] = $one_cf->column_type;
+ $vw_vars['comparator_type'] = $one_cf->comparator_type;
+ $vw_vars['subcomparator_type'] = $one_cf->subcomparator_type;
+ $vw_vars['comment'] = $one_cf->comment;
+ $vw_vars['row_cache_size'] = $one_cf->row_cache_size;
+ $vw_vars['key_cache_size'] = $one_cf->key_cache_size;
+ $vw_vars['read_repair_chance'] = $one_cf->read_repair_chance;
+ $vw_vars['column_metadata'] = $one_cf->column_metadata;
+ $vw_vars['gc_grace_seconds'] = $one_cf->gc_grace_seconds;
+ $vw_vars['default_validation_class'] = $one_cf->default_validation_class;
+ $vw_vars['id'] = $one_cf->id;
+ $vw_vars['min_compaction_threshold'] = $one_cf->min_compaction_threshold;
+ $vw_vars['max_compaction_threshold'] = $one_cf->max_compaction_threshold;
+ $vw_vars['row_cache_save_period_in_seconds'] = $one_cf->row_cache_save_period_in_seconds;
+ $vw_vars['key_cache_save_period_in_seconds'] = $one_cf->key_cache_save_period_in_seconds;
+ $vw_vars['memtable_flush_after_mins'] = $one_cf->memtable_flush_after_mins;
+ $vw_vars['memtable_throughput_in_mb'] = $one_cf->memtable_throughput_in_mb;
+ $vw_vars['memtable_operations_in_millions'] = $one_cf->memtable_operations_in_millions;
+
+ $vw_vars['list_column_families'] .= getHTML('columnfamily_row.php',$vw_vars);
+ }
+
+ try {
+ $vw_vars['ring'] = $sys_manager->describe_ring($keyspace_name);
+ }
+ catch(Exception $e) {
+ $vw_vars['ring'] = $e->getMessage();
+ }
+
+ echo getHTML('describe_keyspace.php',$vw_vars);
+ }
}
- echo getHTML('describe_keyspace.php',$vw_vars);
echo getHTML('footer.php');
?>
View
@@ -55,7 +55,7 @@ function redirect($url) {
exit();
}
- function displaySuccessMessage($index,$params) {
+ function displaySuccessMessage($index,$params = array()) {
if ($index == 'create_keyspace') {
return '<div class="success_message">Keyspace '.$params['keyspace_name'].' has been created successfully!</div>';
}
@@ -82,7 +82,7 @@ function displaySuccessMessage($index,$params) {
}
}
- function displayInfoMessage($index,$params) {
+ function displayInfoMessage($index,$params = array()) {
if ($index == 'edit_keyspace_increased_replication_factor') {
return '<div class="info_message">Tips: Looks like you increased the replication factor.<br />You might want to run "nodetool -h localhost repair" on all your Cassandra nodes.</div>';
}
@@ -97,7 +97,7 @@ function displayInfoMessage($index,$params) {
}
}
- function displayErrorMessage($index,$params) {
+ function displayErrorMessage($index,$params = array()) {
if ($index == 'create_keyspace') {
return '<div class="error_message">Keyspace '.$params['keyspace_name'].' couldn\'t be created.<br /> Reason: '.$params['message'].'</div>';
}
@@ -122,6 +122,18 @@ function displayErrorMessage($index,$params) {
elseif ($index == 'create_secondary_index') {
return '<div class="error_message">Couldn\'t create secondary index on column '.$params['column_name'].'<br /> Reason: '.$params['message'].'</div>';
}
+ elseif ($index == 'keyspace_doesnt_exists') {
+ return '<div class="error_message">Keyspace "'.$params['keyspace_name'].'" doesn\'t exists</div>';
+ }
+ elseif ($index == 'columnfamily_doesnt_exists') {
+ return '<div class="error_message">Column family "'.$params['column_name'].'" doesn\'t exists</div>';
+ }
+ elseif ($index == 'keyspace_name_must_be_specified') {
+ return '<div class="error_message">You must specify a keyspace name</div>';
+ }
+ elseif ($index == 'columnfamily_name_must_be_specified') {
+ return '<div class="error_message">You must specify a column family name</div>';
+ }
}
function displayCFRow($row,$scf_key = null) {

0 comments on commit 404acf5

Please sign in to comment.