@@ -43,30 +43,51 @@ if [ -z "$CASSANDRA_CONF" -o -z "$CLASSPATH" ]; then
4343 exit 1
4444fi
4545
46- JMX_PORT=" "
47-
48- # Try to parse port from configure_jmx method call, when not commented out
49- if [ -f " $CASSANDRA_CONF /cassandra-env.sh" ]; then
50- jmx_method_call=$( grep " ^configure_jmx \+[0-9]\+$" " $CASSANDRA_CONF /cassandra-env.sh" )
51- if [ ! " x${jmx_method_call} " = " x" ]; then
52- JMX_PORT=$( echo " ${jmx_method_call} " | tr -s " " | cut -d " " -f2)
46+ # Check if protocol is cql (from environment variable)
47+ PROTOCOL_IS_CQL=" "
48+ if [ " x$CASSANDRA_CLI_EXECUTION_PROTOCOL " != " x" ]; then
49+ protocol_lower=$( echo " $CASSANDRA_CLI_EXECUTION_PROTOCOL " | tr ' [:upper:]' ' [:lower:]' )
50+ if [ " $protocol_lower " = " cql" ]; then
51+ PROTOCOL_IS_CQL=" true"
5352 fi
5453fi
5554
56- # In case JMX_PORT is not set (when configure_jmx in cassandra-env.sh is commented out),
57- # try to parse it from cassandra.yaml.
58- if [ " x$JMX_PORT " = " x" ]; then
55+ # Check for cql protocol in system properties to determine if we should parse CQL or JMX port
56+ for arg in " $@ " ; do
57+ case " $arg " in
58+ -Dcassandra.cli.execution.protocol=cql|-Dcassandra.cli.execution.protocol=CQL)
59+ PROTOCOL_IS_CQL=" true"
60+ break
61+ ;;
62+ esac
63+ done
64+
65+ # Parse port from config files based on protocol
66+ CONNECTION_PORT=" "
67+ if [ " $PROTOCOL_IS_CQL " = " true" ]; then
68+ # For CQL, parse native_transport_management_port from cassandra.yaml
5969 if [ -f " $CASSANDRA_CONF /cassandra.yaml" ]; then
60- JMX_PORT=$( grep jmx_port " $CASSANDRA_CONF /cassandra.yaml" | cut -d ' :' -f 2 | tr -d ' [[:space:]]' )
70+ CONNECTION_PORT=$( grep native_transport_management_port " $CASSANDRA_CONF /cassandra.yaml" | cut -d ' :' -f 2 | tr -d ' [[:space:]]' )
71+ fi
72+ else
73+ # For JMX, parse port from configure_jmx method call, when not commented out
74+ if [ -f " $CASSANDRA_CONF /cassandra-env.sh" ]; then
75+ jmx_method_call=$( grep " ^configure_jmx \+[0-9]\+$" " $CASSANDRA_CONF /cassandra-env.sh" )
76+ if [ ! " x${jmx_method_call} " = " x" ]; then
77+ CONNECTION_PORT=$( echo " ${jmx_method_call} " | tr -s " " | cut -d " " -f2)
78+ fi
6179 fi
62- fi
6380
64- # If, by any chance, it is not there either, set it to default.
65- if [ " x$JMX_PORT " = " x" ]; then
66- JMX_PORT=7199
81+ # In case CONNECTION_PORT is not set (when configure_jmx in cassandra-env.sh is commented out),
82+ # try to parse it from cassandra.yaml.
83+ if [ " x$CONNECTION_PORT " = " x" ]; then
84+ if [ -f " $CASSANDRA_CONF /cassandra.yaml" ]; then
85+ CONNECTION_PORT=$( grep jmx_port " $CASSANDRA_CONF /cassandra.yaml" | cut -d ' :' -f 2 | tr -d ' [[:space:]]' )
86+ fi
87+ fi
6788fi
6889
69- # JMX Port passed via cmd line args (-p 9999 / --port 9999 / --port=9999)
90+ # Connection Port passed via cmd line args (-p 9999 / --port 9999 / --port=9999)
7091# should override the value from cassandra-env.sh
7192ARGS=" "
7293JVM_ARGS=" "
7697 if [ ! $1 ]; then break ; fi
7798 case $1 in
7899 -p)
79- JMX_PORT =$2
100+ CONNECTION_PORT =$2
80101 shift
81102 ;;
82103 --port=* )
83- JMX_PORT =$( echo $1 | cut -d ' =' -f 2)
104+ CONNECTION_PORT =$( echo $1 | cut -d ' =' -f 2)
84105 ;;
85106 --port)
86- JMX_PORT =$2
107+ CONNECTION_PORT =$2
87108 shift
88109 ;;
89110 --ssl)
90111 if [ -f $SSL_FILE ]
91- then
112+ then
92113 SSL_ARGS=$( cat $SSL_FILE | tr ' \n' ' ' )
93114 fi
94115 JVM_ARGS=" $JVM_ARGS -Dssl.enable=true $SSL_ARGS "
108129 shift
109130done
110131
132+ if [ " x$CONNECTION_PORT " = " x" ]; then
133+ if [ " $PROTOCOL_IS_CQL " = " true" ]; then
134+ CONNECTION_PORT=11211
135+ else
136+ CONNECTION_PORT=7199
137+ fi
138+ fi
139+
111140if [ " x$MAX_HEAP_SIZE " = " x" ]; then
112141 MAX_HEAP_SIZE=" 128m"
113142fi
@@ -123,7 +152,7 @@ CMD=$(echo "$JAVA" $JAVA_AGENT -ea -cp "$CLASSPATH" $JVM_OPTS -Xmx$MAX_HEAP_SIZE
123152 -Dcassandra.logdir=" $CASSANDRA_LOG_DIR " \
124153 -Dlogback.configurationFile=logback-tools.xml \
125154 $JVM_ARGS \
126- org.apache.cassandra.tools.NodeTool -p $JMX_PORT $ARGS )
155+ org.apache.cassandra.tools.NodeTool -p $CONNECTION_PORT $ARGS )
127156
128157if [ " x$ARCHIVE_COMMAND " != " x" ]
129158then
0 commit comments