diff --git a/columnfamily_action.php b/columnfamily_action.php index cf27baa..b858542 100644 --- a/columnfamily_action.php +++ b/columnfamily_action.php @@ -664,7 +664,7 @@ $vw_vars['current_offset_key'] = $offset_key; - if ($offset_key == '') { + if (empty($offset_key)) { $_SESSION['browse_data_offset_key'] = array(); $_SESSION['browse_data_offset_key'][] = ''; } diff --git a/counters.php b/counters.php index 2711842..85f23b7 100644 --- a/counters.php +++ b/counters.php @@ -22,11 +22,11 @@ echo getHTML('header.php'); // Make sure a keyspace name has been specified - if ($keyspace_name == '') { + if (empty($keyspace_name)) { echo displayErrorMessage('keyspace_name_must_be_specified'); } else { - if ($columnfamily_name == '') { + if (empty($columnfamily_name)) { echo displayErrorMessage('columnfamily_name_must_be_specified'); } else { @@ -44,7 +44,7 @@ } // Error - if (isset($_GET['error']) == 1) { + if (isset($_GET['error'])) { $vw_vars['error_message'] = displayErrorMessage('something_wrong_happened',array('message' => $_SESSION['message'])); } diff --git a/describe_columnfamily.php b/describe_columnfamily.php index 619efbc..badfb34 100644 --- a/describe_columnfamily.php +++ b/describe_columnfamily.php @@ -24,11 +24,11 @@ echo getHTML('header.php'); // Make sure a keyspace name has been specified - if ($keyspace_name == '') { + if (empty($keyspace_name)) { echo displayErrorMessage('keyspace_name_must_be_specified'); } else { - if ($columnfamily_name == '') { + if (empty($columnfamily_name)) { echo displayErrorMessage('columnfamily_name_must_be_specified'); } else { diff --git a/describe_keyspace.php b/describe_keyspace.php index 213a7b3..04b44fe 100644 --- a/describe_keyspace.php +++ b/describe_keyspace.php @@ -19,7 +19,7 @@ $vw_vars = array(); - if ($keyspace_name == '') { + if (empty($keyspace_name)) { echo displayErrorMessage('keyspace_name_must_be_specified'); } else { @@ -28,7 +28,7 @@ // CF created successfully $vw_vars['added_cf'] = ''; - if (isset($_GET['create_cf']) == 1) { + if (isset($_GET['create_cf'])) { $columnfamily_name = $_SESSION['message']; $query_time = $_SESSION['query_time']; $vw_vars['added_cf'] = displaySuccessMessage('create_columnfamily',array('columnfamily_name' => $columnfamily_name,'query_time' => $query_time)); diff --git a/helper/ClusterHelper.php b/helper/ClusterHelper.php index e98cc95..3a0f666 100644 --- a/helper/ClusterHelper.php +++ b/helper/ClusterHelper.php @@ -11,6 +11,11 @@ class ClusterHelper { private $cassandra_clusters = array(); + /* + Constructor + + @param $cassandra_clusters The array of Cassandra nodes to manage + */ public function __construct($cassandra_clusters) { $this->cassandra_clusters = $cassandra_clusters; } @@ -28,6 +33,8 @@ public function getClusterIndex() { /* Get the name of the cluster at $index + + @param $index Index of the cluster name to get */ public function getClusterNameForIndex($index) { try { @@ -54,6 +61,8 @@ public function getArrayOfNodesForCurrentCluster() { /* Get a random Cassandra node at $index + + @param $index Index of the cluster to get a random node from */ public function getRandomNodeForIndex($index) { $all_nodes = $this->cassandra_clusters[$index]['nodes']; @@ -71,6 +80,8 @@ public function getRandomNodeForCurrentCluster() { /* Get the Cassandra cluster credentials at $index + + @param $index Get the specified credentials for the cluster at the specified index */ public function getCredentialsForIndex($index) { $cluster = $this->cassandra_clusters[$index]; diff --git a/helper/ColumnFamilyHelper.php b/helper/ColumnFamilyHelper.php index 98b8979..69b7628 100644 --- a/helper/ColumnFamilyHelper.php +++ b/helper/ColumnFamilyHelper.php @@ -11,6 +11,9 @@ class ColumnFamilyHelper { /* Return the column family definition for the specified keyspace name and column family name + + @param $keyspace_name The keyspace name that the column family is in + @param $columnfamily_name The column family name to get */ public static function getCFInKeyspace($keyspace_name,$columnfamily_name) { global $sys_manager; @@ -66,6 +69,13 @@ public static function getKeyspacesAndColumnFamiliesDetails() { /* Display a row out of a column family + + @param $row_key The key of the row to display + @param $keyspace_name The keyspace name that row was in + @param $columnfamily_name The column family name that row was in + @param $row The complete row + @param $scf_key The key of the super column family, if it apply + @param $is_counter_column True if the column family is a counter column, false otherwise */ public static function displayCFRow($row_key,$keyspace_name,$columnfamily_name,$row,$scf_key = null,$is_counter_column = false) { $vw_vars['scf_key'] = $scf_key; @@ -85,6 +95,12 @@ public static function displayCFRow($row_key,$keyspace_name,$columnfamily_name,$ /* Display a row out of a super column family + + @param $row_key The key of the row to display + @param $keyspace_name The keyspace name that row was in + @param $columnfamily_name The column family name that row was in + @param $row The complete row + @param $is_counter_column True if the column family is a counter column, false otherwise */ public static function displaySCFRow($row_key,$keyspace_name,$columnfamily_name,$row,$is_counter_column = false) { $output = ''; diff --git a/helper/MX4J.php b/helper/MX4J.php index a99619c..05730c4 100644 --- a/helper/MX4J.php +++ b/helper/MX4J.php @@ -1,30 +1,54 @@ host = $host; $this->port = $port; } + /* + Return the current MX4J url + */ private function getUrl() { return 'http://'.$this->host.':'.$this->port; } + /* + Helper function used to call the MX4J instance and return the result + + @param $url The URL to be called + @param $return_as_array True if the result should be an array, false otherwise + */ private function doCall($url,$return_as_array = true) { $ch = curl_init(); - - curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_HEADER, false); - curl_setopt($ch, CURLOPT_NOBODY, false); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_HEADER, false); + curl_setopt($ch, CURLOPT_NOBODY, false); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, 3); - $data = curl_exec($ch); - $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); - - curl_close($ch); - + $data = curl_exec($ch); + $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); + + curl_close($ch); + // Convert XML to Array if ($return_as_array) { libxml_use_internal_errors(true); @@ -37,6 +61,11 @@ private function doCall($url,$return_as_array = true) { return $data; } + /* + Extract the RAM usage info from a string + + @param $memory_string String to extract the info from + */ private function extractMemoryInfo($memory_string) { // Extract memory info preg_match('/contents={.*}/',$memory_string,$matches); @@ -53,16 +82,29 @@ private function extractMemoryInfo($memory_string) { return $memory_output; } + /* + Helper function to extract the value of a property + + @param $data The array of data + @param $index The index that the attribute is in + @param $name The name of the attribute to get + */ private function extractProperty($data,$index,$name) { if (isset($data['Attribute'][$index]['@attributes']) && $data['Attribute'][$index]['@attributes']['name'] == $name) { return $data['Attribute'][$index]['@attributes']['value']; } } + /* + Return true if MX4J is active, false otherwise + */ public function isActive() { return $this->doCall($this->getUrl(),false) != ''; } + /* + Return the heap memory usage of the current MX4J instance + */ public function getHeapMemoryUsage() { $data = $this->doCall($this->getUrl().'/mbean?objectname=java.lang%3Atype%3DMemory&template=identity'); @@ -73,6 +115,9 @@ public function getHeapMemoryUsage() { } } + /* + Return the non-heap memory usage of the current MX4J instance + */ public function getNonHeapMemoryUsage() { $data = $this->doCall($this->getUrl().'/mbean?objectname=java.lang%3Atype%3DMemory&template=identity'); @@ -83,12 +128,18 @@ public function getNonHeapMemoryUsage() { } } + /* + Return the number of loaded class for the current MX4J instance + */ public function getLoadedClassCount() { $data = $this->doCall($this->getUrl().'/mbean?objectname=java.lang%3Atype%3DClassLoading&template=identity'); return $this->extractProperty($data,1,'TotalLoadedClassCount'); } + /* + Return the TP stats information for the current MX4J instance + */ public function getTpStats() { $tp_stats = array(); @@ -218,6 +269,9 @@ public function getTpStats() { return $tp_stats; } + /* + Trigger the garbage collection for the current MX4J instance + */ public function triggerGarbageCollection() { $data = $this->doCall($this->getUrl().'/invoke?operation=gc&objectname=java.lang%3Atype%3DMemory&template=identity'); @@ -228,6 +282,12 @@ public function triggerGarbageCollection() { } } + /* + Return details about a column family + + @param $keyspace_name The keyspace the column family is in + @param columnfamily_name The column family to get the detials for + */ public function getColumnFamilyDetails($keyspace_name,$columnfamily_name) { $data = $this->doCall($this->getUrl().'/mbean?objectname=org.apache.cassandra.db:type=ColumnFamilies,keyspace='.$keyspace_name.',columnfamily='.$columnfamily_name.'&template=identity'); @@ -243,6 +303,12 @@ public function getColumnFamilyDetails($keyspace_name,$columnfamily_name) { return $return; } + /* + Return details about key cache of a column family + + @param $keyspace_name The keyspace the column family is in + @param columnfamily_name The column family to get the key cache detials for + */ public function getColumnFamilyKeyCacheDetails($keyspace_name,$columnfamily_name) { $data = $this->doCall($this->getUrl().'/mbean?objectname=org.apache.cassandra.db:type=Caches,keyspace='.$keyspace_name.',cache='.$columnfamily_name.'KeyCache&template=identity'); @@ -258,6 +324,12 @@ public function getColumnFamilyKeyCacheDetails($keyspace_name,$columnfamily_name return $return; } + /* + Return details about row cache of a column family + + @param $keyspace_name The keyspace the column family is in + @param columnfamily_name The column family to get the row cache detials for + */ public function getColumnFamilyRowCacheDetails($keyspace_name,$columnfamily_name) { $data = $this->doCall($this->getUrl().'/mbean?objectname=org.apache.cassandra.db:type=Caches,keyspace='.$keyspace_name.',cache='.$columnfamily_name.'RowCache&template=identity'); @@ -273,6 +345,12 @@ public function getColumnFamilyRowCacheDetails($keyspace_name,$columnfamily_name return $return; } + /* + Force a major compaction for the specified column family + + @param $keyspace_name The keyspace the column family is in + @param columnfamily_name The column family to force major compaction + */ public function forceMajorCompaction($keyspace_name,$columnfamily_name) { $data = $this->doCall($this->getUrl().'/invoke?operation=forceMajorCompaction&objectname=org.apache.cassandra.db:type=ColumnFamilies,keyspace='.$keyspace_name.',columnfamily='.$columnfamily_name.'&template=identity'); @@ -283,6 +361,12 @@ public function forceMajorCompaction($keyspace_name,$columnfamily_name) { } } + /* + Invalidate the key cache for the specified column family + + @param $keyspace_name The keyspace the column family is in + @param columnfamily_name The column family invalide key cache + */ public function invalidateKeyCache($keyspace_name,$columnfamily_name) { $data = $this->doCall($this->getUrl().'/invoke?operation=invalidateKeyCache&objectname=org.apache.cassandra.db:type=ColumnFamilies,keyspace='.$keyspace_name.',columnfamily='.$columnfamily_name.'&template=identity'); @@ -293,6 +377,12 @@ public function invalidateKeyCache($keyspace_name,$columnfamily_name) { } } + /* + Invalidate the row cache for the specified column family + + @param $keyspace_name The keyspace the column family is in + @param columnfamily_name The column family invalide row cache + */ public function invalidateRowCache($keyspace_name,$columnfamily_name) { $data = $this->doCall($this->getUrl().'/invoke?operation=invalidateRowCache&objectname=org.apache.cassandra.db:type=ColumnFamilies,keyspace='.$keyspace_name.',columnfamily='.$columnfamily_name.'&template=identity'); @@ -303,6 +393,12 @@ public function invalidateRowCache($keyspace_name,$columnfamily_name) { } } + /* + Force a flush of the specified column family + + @param $keyspace_name The keyspace the column family is in + @param columnfamily_name The column family to flush + */ public function forceFlush($keyspace_name,$columnfamily_name) { $data = $this->doCall($this->getUrl().'/invoke?operation=forceFlush&objectname=org.apache.cassandra.db:type=ColumnFamilies,keyspace='.$keyspace_name.',columnfamily='.$columnfamily_name.'&template=identity'); @@ -313,6 +409,12 @@ public function forceFlush($keyspace_name,$columnfamily_name) { } } + /* + Disable auto compaction for the specified column family + + @param $keyspace_name The keyspace the column family is in + @param columnfamily_name The column family to disable auto compaction + */ public function disableAutoCompaction($keyspace_name,$columnfamily_name) { $data = $this->doCall($this->getUrl().'/invoke?operation=disableAutoCompaction&objectname=org.apache.cassandra.db:type=ColumnFamilies,keyspace='.$keyspace_name.',columnfamily='.$columnfamily_name.'&template=identity'); @@ -323,6 +425,12 @@ public function disableAutoCompaction($keyspace_name,$columnfamily_name) { } } + /* + Get an estimated number of keys for the specified column family + + @param $keyspace_name The keyspace the column family is in + @param columnfamily_name The column family to estimate the number of keys + */ public function estimateKeys($keyspace_name,$columnfamily_name) { $data = $this->doCall($this->getUrl().'/invoke?operation=estimateKeys&objectname=org.apache.cassandra.db:type=ColumnFamilies,keyspace='.$keyspace_name.',columnfamily='.$columnfamily_name.'&template=identity');