Return-Path: Delivered-To: apmail-incubator-cassandra-commits-archive@minotaur.apache.org Received: (qmail 32616 invoked from network); 2 Mar 2009 14:23:57 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 2 Mar 2009 14:23:57 -0000 Received: (qmail 32625 invoked by uid 500); 2 Mar 2009 14:23:57 -0000 Delivered-To: apmail-incubator-cassandra-commits-archive@incubator.apache.org Received: (qmail 32612 invoked by uid 500); 2 Mar 2009 14:23:57 -0000 Mailing-List: contact cassandra-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: cassandra-dev@incubator.apache.org Delivered-To: mailing list cassandra-commits@incubator.apache.org Delivered-To: moderator for cassandra-commits@incubator.apache.org Received: (qmail 35983 invoked by uid 99); 2 Mar 2009 07:58:19 -0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r749218 [2/34] - in /incubator/cassandra: branches/ dist/ nightly/ site/ tags/ trunk/ trunk/lib/ trunk/src/ trunk/src/org/ trunk/src/org/apache/ trunk/src/org/apache/cassandra/ trunk/src/org/apache/cassandra/analytics/ trunk/src/org/apache/... Date: Mon, 02 Mar 2009 07:57:31 -0000 To: cassandra-commits@incubator.apache.org From: pmalik@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090302075743.C6A5F2388A95@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Added: incubator/cassandra/trunk/src/org/apache/cassandra/analytics/VMAnalyticsSource.java URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/org/apache/cassandra/analytics/VMAnalyticsSource.java?rev=749218&view=auto ============================================================================== --- incubator/cassandra/trunk/src/org/apache/cassandra/analytics/VMAnalyticsSource.java (added) +++ incubator/cassandra/trunk/src/org/apache/cassandra/analytics/VMAnalyticsSource.java Mon Mar 2 07:57:22 2009 @@ -0,0 +1,86 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.cassandra.analytics; + +import java.lang.management.ManagementFactory; +import java.lang.management.MemoryMXBean; +import java.lang.management.MemoryUsage; +import java.util.HashMap; +import java.util.Map; + +import org.apache.cassandra.config.DatabaseDescriptor; +import org.apache.cassandra.service.StorageService; +import org.apache.cassandra.utils.LogUtil; +import org.apache.log4j.Logger; + + +/** + * This class sets up the analytics package to report metrics into + * Ganglia for VM heap utilization. + * + * Author : Avinash Lakshman ( alakshman@facebook.com) & Prashant Malik ( pmalik@facebook.com ) & Karthik Ranganathan ( kranganathan@facebook.com ) + */ + +public class VMAnalyticsSource implements IAnalyticsSource +{ + private static final String METRIC_MEMUSAGE = "VM Heap Utilization"; + private static final String RECORD_MEMUSAGE = "MemoryUsageRecord"; + private static final String TAG_MEMUSAGE = "MemoryUsageTag"; + private static final String TAG_MEMUSAGE_MEMUSED = "MemoryUsedTagValue"; + + /** + * Setup the Ganglia record to display the VM heap utilization. + */ + public VMAnalyticsSource() + { + // set the units for the metric type + AnalyticsContext.instance().setAttribute("units." + METRIC_MEMUSAGE, "MB"); + // create the record + AnalyticsContext.instance().createRecord(RECORD_MEMUSAGE); + } + + /** + * Update the VM heap utilization record with the relevant data. + * + * @param context the reference to the context which has called this callback + */ + public void doUpdates(AnalyticsContext context) + { + // update the memory used record + MetricsRecord memUsageRecord = context.getMetricsRecord(RECORD_MEMUSAGE); + if(memUsageRecord != null) + { + updateUsedMemory(memUsageRecord); + } + } + + private void updateUsedMemory(MetricsRecord memUsageRecord) + { + memUsageRecord.setTag(TAG_MEMUSAGE, TAG_MEMUSAGE_MEMUSED); + memUsageRecord.setMetric(METRIC_MEMUSAGE, getMemoryUsed()); + memUsageRecord.update(); + } + + private float getMemoryUsed() + { + MemoryMXBean memoryMxBean = ManagementFactory.getMemoryMXBean(); + MemoryUsage memUsage = memoryMxBean.getHeapMemoryUsage(); + return (float)memUsage.getUsed()/(1024 * 1024); + } +} Added: incubator/cassandra/trunk/src/org/apache/cassandra/cli/Cli.g URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/org/apache/cassandra/cli/Cli.g?rev=749218&view=auto ============================================================================== --- incubator/cassandra/trunk/src/org/apache/cassandra/cli/Cli.g (added) +++ incubator/cassandra/trunk/src/org/apache/cassandra/cli/Cli.g Mon Mar 2 07:57:22 2009 @@ -0,0 +1,234 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// +// ANTLR Grammar for the Cassandra Command Line Interface (CLI). +// +// Note: This grammar handles all but the CQL statements. CQL +// statements are detected separately (based on the first token) +// and directly sent to server-side for processing. +// + +grammar Cli; + +options { + output=AST; + ASTLabelType=CommonTree; + backtrack=true; +} + +// +// Nodes in the AST +// +tokens { + // + // Top-level nodes. These typically correspond to + // various top-level CLI statements. + // + NODE_CONNECT; + NODE_DESCRIBE_TABLE; + NODE_EXIT; + NODE_HELP; + NODE_NO_OP; + NODE_SHOW_CLUSTER_NAME; + NODE_SHOW_CONFIG_FILE; + NODE_SHOW_VERSION; + NODE_SHOW_TABLES; + NODE_THRIFT_GET; + NODE_THRIFT_SET; + + // Internal Nodes. + NODE_COLUMN_ACCESS; + NODE_ID_LIST; +} + +@parser::header { +package com.facebook.infrastructure.cli; +} + +@lexer::header { +package com.facebook.infrastructure.cli; +} + +// +// Parser Section +// + +// the root node +root: stmt SEMICOLON? EOF -> stmt; + +stmt + : connectStmt + | exitStmt + | describeTable + | getStmt + | helpStmt + | setStmt + | showStmt + | -> ^(NODE_NO_OP) + ; + +connectStmt + : K_CONNECT host SLASH port -> ^(NODE_CONNECT host port) + ; + +helpStmt + : K_HELP -> ^(NODE_HELP) + | '?' -> ^(NODE_HELP) + ; + +exitStmt + : K_QUIT -> ^(NODE_EXIT) + | K_EXIT -> ^(NODE_EXIT) + ; + +getStmt + : K_THRIFT K_GET columnFamilyExpr -> ^(NODE_THRIFT_GET columnFamilyExpr) + ; + +setStmt + : K_THRIFT K_SET columnFamilyExpr '=' value -> ^(NODE_THRIFT_SET columnFamilyExpr value) + ; + +showStmt + : showClusterName + | showVersion + | showConfigFile + | showTables + ; + +showClusterName + : K_SHOW K_CLUSTER K_NAME -> ^(NODE_SHOW_CLUSTER_NAME) + ; + +showConfigFile + : K_SHOW K_CONFIG K_FILE -> ^(NODE_SHOW_CONFIG_FILE) + ; + +showVersion + : K_SHOW K_VERSION -> ^(NODE_SHOW_VERSION) + ; + +showTables + : K_SHOW K_TABLES -> ^(NODE_SHOW_TABLES) + ; + +describeTable + : K_DESCRIBE K_TABLE table -> ^(NODE_DESCRIBE_TABLE table); + +columnFamilyExpr + : table DOT columnFamily '[' rowKey ']' + ( '[' a+=columnOrSuperColumn ']' + ('[' a+=columnOrSuperColumn ']')? + )? + -> ^(NODE_COLUMN_ACCESS table columnFamily rowKey ($a+)?) + ; + +table: Identifier; + +columnFamily: Identifier; + +rowKey: StringLiteral; + +value: StringLiteral; + +columnOrSuperColumn: StringLiteral; + +host: id+=Identifier (id+=DOT id+=Identifier)* -> ^(NODE_ID_LIST $id+); + +port: IntegerLiteral; + +// +// Lexer Section +// + +// +// Keywords (in alphabetical order for convenience) +// +// CLI is case-insensitive with respect to these keywords. +// However, they MUST be listed in upper case here. +// +K_CONFIG: 'CONFIG'; +K_CONNECT: 'CONNECT'; +K_CLUSTER: 'CLUSTER'; +K_DESCRIBE: 'DESCRIBE'; +K_GET: 'GET'; +K_HELP: 'HELP'; +K_EXIT: 'EXIT'; +K_FILE: 'FILE'; +K_NAME: 'NAME'; +K_QUIT: 'QUIT'; +K_SET: 'SET'; +K_SHOW: 'SHOW'; +K_TABLE: 'TABLE'; +K_TABLES: 'TABLES'; +K_THRIFT: 'THRIFT'; +K_VERSION: 'VERSION'; + +// private syntactic rules +fragment +Letter + : 'a'..'z' + | 'A'..'Z' + ; + +fragment +Digit + : '0'..'9' + ; + +// syntactic Elements +Identifier + : Letter ( Letter | Digit | '_')* + ; + + +// literals +StringLiteral + : + '\'' (~'\'')* '\'' ( '\'' (~'\'')* '\'' )* + ; + +IntegerLiteral + : Digit+; + + +// +// syntactic elements +// + +DOT + : '.' + ; + +SLASH + : '/' + ; + +SEMICOLON + : ';' + ; + +WS + : (' '|'\r'|'\t'|'\n') {$channel=HIDDEN;} // whitepace + ; + +COMMENT + : '--' (~('\n'|'\r'))* { $channel=HIDDEN; } + | '/*' (options {greedy=false;} : .)* '*/' { $channel=HIDDEN; } + ; Added: incubator/cassandra/trunk/src/org/apache/cassandra/cli/Cli.tokens URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/org/apache/cassandra/cli/Cli.tokens?rev=749218&view=auto ============================================================================== --- incubator/cassandra/trunk/src/org/apache/cassandra/cli/Cli.tokens (added) +++ incubator/cassandra/trunk/src/org/apache/cassandra/cli/Cli.tokens Mon Mar 2 07:57:22 2009 @@ -0,0 +1,43 @@ +NODE_SHOW_CONFIG_FILE=10 +K_TABLES=32 +K_VERSION=31 +K_EXIT=22 +NODE_EXIT=6 +K_FILE=30 +K_GET=24 +K_CONNECT=18 +K_CONFIG=29 +SEMICOLON=17 +Digit=40 +Identifier=36 +NODE_THRIFT_GET=13 +K_SET=25 +StringLiteral=37 +NODE_HELP=7 +NODE_NO_OP=8 +NODE_THRIFT_SET=14 +K_DESCRIBE=33 +NODE_SHOW_VERSION=11 +NODE_ID_LIST=16 +WS=41 +NODE_CONNECT=4 +SLASH=19 +K_THRIFT=23 +NODE_SHOW_TABLES=12 +K_CLUSTER=27 +K_HELP=20 +K_SHOW=26 +NODE_DESCRIBE_TABLE=5 +K_TABLE=34 +IntegerLiteral=38 +NODE_SHOW_CLUSTER_NAME=9 +COMMENT=42 +DOT=35 +K_NAME=28 +Letter=39 +NODE_COLUMN_ACCESS=15 +K_QUIT=21 +'?'=43 +'='=44 +'['=45 +']'=46 Added: incubator/cassandra/trunk/src/org/apache/cassandra/cli/CliClient.java URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/org/apache/cassandra/cli/CliClient.java?rev=749218&view=auto ============================================================================== --- incubator/cassandra/trunk/src/org/apache/cassandra/cli/CliClient.java (added) +++ incubator/cassandra/trunk/src/org/apache/cassandra/cli/CliClient.java Mon Mar 2 07:57:22 2009 @@ -0,0 +1,323 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cassandra.cli; + +import com.facebook.thrift.*; + +import org.antlr.runtime.tree.*; +import org.apache.cassandra.cql.common.Utils; +import org.apache.cassandra.service.Cassandra; +import org.apache.cassandra.service.CassandraException; +import org.apache.cassandra.service.CqlResult_t; +import org.apache.cassandra.service.column_t; +import org.apache.cassandra.service.Cassandra.Client; +import org.apache.cassandra.utils.LogUtil; + +import java.util.*; + +// Cli Client Side Library +public class CliClient +{ + private Cassandra.Client thriftClient_ = null; + private CliSessionState css_ = null; + + public CliClient(CliSessionState css, Cassandra.Client thriftClient) + { + css_ = css; + thriftClient_ = thriftClient; + } + + // Execute a CLI Statement + public void executeCLIStmt(String stmt) throws TException + { + CommonTree ast = null; + + ast = CliCompiler.compileQuery(stmt); + + switch (ast.getType()) { + case CliParser.NODE_EXIT: + cleanupAndExit(); + break; + case CliParser.NODE_THRIFT_GET: + executeGet(ast); + break; + case CliParser.NODE_HELP: + printCmdHelp(); + break; + case CliParser.NODE_THRIFT_SET: + executeSet(ast); + break; + case CliParser.NODE_SHOW_CLUSTER_NAME: + executeShowProperty(ast, "cluster name"); + break; + case CliParser.NODE_SHOW_CONFIG_FILE: + executeShowProperty(ast, "config file"); + break; + case CliParser.NODE_SHOW_VERSION: + executeShowProperty(ast, "version"); + break; + case CliParser.NODE_SHOW_TABLES: + executeShowTables(ast); + break; + case CliParser.NODE_DESCRIBE_TABLE: + executeDescribeTable(ast); + break; + case CliParser.NODE_CONNECT: + executeConnect(ast); + break; + case CliParser.NODE_NO_OP: + // comment lines come here; they are treated as no ops. + break; + default: + css_.err.println("Invalid Statement (Type: " + ast.getType() + ")"); + break; + } + } + + private void printCmdHelp() + { + css_.out.println("List of all CLI commands:"); + css_.out.println("? Same as help."); + css_.out.println("connect / Connect to Cassandra's thrift service."); + css_.out.println("describe table Describe table."); + css_.out.println("exit Exit CLI."); + css_.out.println("explain plan [||