You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@whirr.apache.org by jo...@apache.org on 2011/01/05 05:48:26 UTC

svn commit: r1055295 - in /incubator/whirr/trunk: scripts/apache/cassandra/ services/cassandra/src/main/java/org/apache/whirr/service/cassandra/

Author: johan
Date: Wed Jan  5 04:48:26 2011
New Revision: 1055295

URL: http://svn.apache.org/viewvc?rev=1055295&view=rev
Log:
WHIRR-155. Support multiple versions of Cassandra. Contributed by Stu Hood.

Added:
    incubator/whirr/trunk/scripts/apache/cassandra/nodetool
    incubator/whirr/trunk/scripts/apache/cassandra/start
    incubator/whirr/trunk/scripts/apache/cassandra/stop
    incubator/whirr/trunk/scripts/apache/cassandra/wipe-state
Modified:
    incubator/whirr/trunk/scripts/apache/cassandra/install
    incubator/whirr/trunk/scripts/apache/cassandra/post-configure
    incubator/whirr/trunk/services/cassandra/src/main/java/org/apache/whirr/service/cassandra/CassandraClusterActionHandler.java

Modified: incubator/whirr/trunk/scripts/apache/cassandra/install
URL: http://svn.apache.org/viewvc/incubator/whirr/trunk/scripts/apache/cassandra/install?rev=1055295&r1=1055294&r2=1055295&view=diff
==============================================================================
--- incubator/whirr/trunk/scripts/apache/cassandra/install (original)
+++ incubator/whirr/trunk/scripts/apache/cassandra/install Wed Jan  5 04:48:26 2011
@@ -21,48 +21,53 @@
 set -x
 set -e
 
-C_VERSION=${1:-0.6.2}
-CASSANDRA_HOME=/usr/local/apache-cassandra-$C_VERSION
+C_MAJOR_VERSION=${1:-0.7}
+C_TAR_URL=${2:-http://www.apache.org/dist/cassandra/0.7.0/apache-cassandra-0.7.0-rc3-bin.tar.gz}
+
+c_tar_file=`basename $C_TAR_URL`
+c_tar_dir=`echo $c_tar_file | awk -F '-bin' '{print $1}'`
+
+CASSANDRA_HOME=/usr/local/$c_tar_dir
 C_CONF_DIR=/etc/cassandra/conf
 C_LOG_DIR=/var/log/cassandra
 
-c_tar_url=http://www.apache.org/dist/cassandra/$C_VERSION/apache-cassandra-$C_VERSION-bin.tar.gz
-c_tar_file=`basename $c_tar_url`
-c_tar_md5_file=`basename $c_tar_url.md5`
-
 curl="curl --retry 3 --silent --show-error --fail"
 for i in `seq 1 3`;
 do
-  $curl -O $c_tar_url
-  $curl -O $c_tar_url.md5
-  if md5sum -c $c_tar_md5_file; then
+  $curl -O $C_TAR_URL
+  if tar zxf $c_tar_file -C /usr/local ; then
     break;
   else
-    rm -f $c_tar_file $c_tar_md5_file
+    rm -f $c_tar_file
   fi
 done
 
 if [ ! -e $c_tar_file ]; then
-  echo "Failed to download $c_tar_url. Aborting."
+  echo "Failed to download $C_TAR_URL. Aborting."
   exit 1
 fi
 
-tar zxf $c_tar_file -C /usr/local
-rm -f $c_tar_file $c_tar_md5_file
 
 echo "export CASSANDRA_HOME=$CASSANDRA_HOME" >> /etc/profile
+echo "export CASSANDRA_CONF=$C_CONF_DIR" >> /etc/profile
 echo 'export PATH=$CASSANDRA_HOME/bin:$PATH' >> /etc/profile
 
 mkdir -p /mnt/cassandra/logs
 ln -s /mnt/cassandra/logs $C_LOG_DIR
 mkdir -p $C_CONF_DIR
-cp $CASSANDRA_HOME/conf/log4j.properties $C_CONF_DIR
-cp $CASSANDRA_HOME/conf/storage-conf.xml $C_CONF_DIR
-
-sed -i -e "s|CASSANDRA_CONF=\$cassandra_home/conf|CASSANDRA_CONF=$C_CONF_DIR|" $CASSANDRA_HOME/bin/cassandra.in.sh
+cp $CASSANDRA_HOME/conf/log4j*.properties $C_CONF_DIR
+if [[ "0.6" == "$C_MAJOR_VERSION" ]] ; then 
+  cp $CASSANDRA_HOME/conf/storage-conf.xml $C_CONF_DIR
+  sed -i -e "s|CASSANDRA_CONF=\$cassandra_home/conf|CASSANDRA_CONF=$C_CONF_DIR|" $CASSANDRA_HOME/bin/cassandra.in.sh
+else
+  cp $CASSANDRA_HOME/conf/cassandra.yaml $C_CONF_DIR
+  cp $CASSANDRA_HOME/conf/cassandra-env.sh $C_CONF_DIR
+  # FIXME: this is only necessary because CASSANDRA_CONF/HOME are not in root's environment as they should be
+  sed -i -e "s|CASSANDRA_CONF=\$CASSANDRA_HOME/conf|CASSANDRA_CONF=$C_CONF_DIR|" $CASSANDRA_HOME/bin/cassandra.in.sh
+fi
 
 # Ensure Cassandra starts on boot
 sed -i -e "s/exit 0//" /etc/rc.local
 cat >> /etc/rc.local <<EOF
 $CASSANDRA_HOME/bin/cassandra > /dev/null 2>&1 &
-EOF
\ No newline at end of file
+EOF

Added: incubator/whirr/trunk/scripts/apache/cassandra/nodetool
URL: http://svn.apache.org/viewvc/incubator/whirr/trunk/scripts/apache/cassandra/nodetool?rev=1055295&view=auto
==============================================================================
--- incubator/whirr/trunk/scripts/apache/cassandra/nodetool (added)
+++ incubator/whirr/trunk/scripts/apache/cassandra/nodetool Wed Jan  5 04:48:26 2011
@@ -0,0 +1,27 @@
+#!/usr/bin/env bash
+#
+# 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.
+#
+
+set -x
+set -e
+
+. /etc/profile
+
+nodetool -h localhost $1
+RESULT=$?
+sleep 2
+exit $RESULT

Modified: incubator/whirr/trunk/scripts/apache/cassandra/post-configure
URL: http://svn.apache.org/viewvc/incubator/whirr/trunk/scripts/apache/cassandra/post-configure?rev=1055295&r1=1055294&r2=1055295&view=diff
==============================================================================
--- incubator/whirr/trunk/scripts/apache/cassandra/post-configure (original)
+++ incubator/whirr/trunk/scripts/apache/cassandra/post-configure Wed Jan  5 04:48:26 2011
@@ -21,6 +21,8 @@
 set -x
 set -e
 
+. /etc/profile
+
 CLOUD_PROVIDER=
 while getopts "c:" OPTION; do
   case $OPTION in
@@ -46,18 +48,39 @@ case $CLOUD_PROVIDER in
     ;;
 esac
 
-config_file=/etc/cassandra/conf/storage-conf.xml
-
-seeds=""
-
-for server in "$@"; do
-  seeds="${seeds}<Seed>${server}</Seed>"
-done
+OH_SIX_CONFIG="/etc/cassandra/conf/storage-conf.xml"
 
-#TODO set replication
-sed -i -e "s|<Seed>127.0.0.1</Seed>|$seeds|" $config_file
-sed -i -e "s|<ListenAddress>localhost</ListenAddress>|<ListenAddress>$PRIVATE_SELF_HOST</ListenAddress>|" $config_file
-sed -i -e "s|<ThriftAddress>localhost</ThriftAddress>|<ThriftAddress>$PUBLIC_SELF_HOST</ThriftAddress>|" $config_file
+if [[ -e "$OH_SIX_CONFIG" ]] ; then 
+  config_file=$OH_SIX_CONFIG
+  seeds=""
+  for server in "$@"; do
+    seeds="${seeds}<Seed>${server}</Seed>"
+  done
+
+  #TODO set replication
+  sed -i -e "s|<Seed>127.0.0.1</Seed>|$seeds|" $config_file
+  sed -i -e "s|<ListenAddress>localhost</ListenAddress>|<ListenAddress>$PRIVATE_SELF_HOST</ListenAddress>|" $config_file
+  sed -i -e "s|<ThriftAddress>localhost</ThriftAddress>|<ThriftAddress>$PUBLIC_SELF_HOST</ThriftAddress>|" $config_file
+else
+  config_file="/etc/cassandra/conf/cassandra.yaml"
+  if [[ "x"`grep -e '^seeds:' $config_file` == "x" ]]; then
+    seeds="$1" # 08 format seeds
+    shift
+    for server in "$@"; do
+      seeds="${seeds},${server}"
+    done
+    sed -i -e "s|- seeds: \"127.0.0.1\"|- seeds: \"${seeds}\"|" $config_file
+  else
+    seeds="" # 07 format seeds
+    for server in "$@"; do
+      seeds="${seeds}\n    - ${server}"
+    done
+    sed -i -e "/^seeds:/,/^/d" $config_file ; echo -e "seeds:${seeds}" >> $config_file
+  fi
+
+  sed -i -e "s|listen_address: localhost|listen_address: $PRIVATE_SELF_HOST|" $config_file
+  sed -i -e "s|rpc_address: localhost|rpc_address: $PUBLIC_SELF_HOST|" $config_file
+fi
 
 # Now that it's configured, start Cassandra
-nohup /etc/rc.local &
\ No newline at end of file
+nohup /etc/rc.local &

Added: incubator/whirr/trunk/scripts/apache/cassandra/start
URL: http://svn.apache.org/viewvc/incubator/whirr/trunk/scripts/apache/cassandra/start?rev=1055295&view=auto
==============================================================================
--- incubator/whirr/trunk/scripts/apache/cassandra/start (added)
+++ incubator/whirr/trunk/scripts/apache/cassandra/start Wed Jan  5 04:48:26 2011
@@ -0,0 +1,26 @@
+#!/usr/bin/env bash
+#
+# 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.
+#
+
+set -x
+set -e
+
+. /etc/profile
+
+# launch using the script created by install
+nohup /etc/rc.local &
+sleep 2

Added: incubator/whirr/trunk/scripts/apache/cassandra/stop
URL: http://svn.apache.org/viewvc/incubator/whirr/trunk/scripts/apache/cassandra/stop?rev=1055295&view=auto
==============================================================================
--- incubator/whirr/trunk/scripts/apache/cassandra/stop (added)
+++ incubator/whirr/trunk/scripts/apache/cassandra/stop Wed Jan  5 04:48:26 2011
@@ -0,0 +1,28 @@
+#!/usr/bin/env bash
+#
+# 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.
+#
+
+set -x
+set -e
+
+. /etc/profile
+
+# assume we are the only java process FIXME: unsafe assumption
+killall java
+RESULT=$?
+sleep 2
+exit $RESULT

Added: incubator/whirr/trunk/scripts/apache/cassandra/wipe-state
URL: http://svn.apache.org/viewvc/incubator/whirr/trunk/scripts/apache/cassandra/wipe-state?rev=1055295&view=auto
==============================================================================
--- incubator/whirr/trunk/scripts/apache/cassandra/wipe-state (added)
+++ incubator/whirr/trunk/scripts/apache/cassandra/wipe-state Wed Jan  5 04:48:26 2011
@@ -0,0 +1,28 @@
+#!/usr/bin/env bash
+#
+# 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.
+#
+
+set -x
+set -e
+
+. /etc/profile
+
+DD=/var/lib/cassandra
+rm -Rf $DD/data $DD/commitlog $DD/saved_caches
+RESULT=$?
+sleep 2
+exit $RESULT

Modified: incubator/whirr/trunk/services/cassandra/src/main/java/org/apache/whirr/service/cassandra/CassandraClusterActionHandler.java
URL: http://svn.apache.org/viewvc/incubator/whirr/trunk/services/cassandra/src/main/java/org/apache/whirr/service/cassandra/CassandraClusterActionHandler.java?rev=1055295&r1=1055294&r2=1055295&view=diff
==============================================================================
--- incubator/whirr/trunk/services/cassandra/src/main/java/org/apache/whirr/service/cassandra/CassandraClusterActionHandler.java (original)
+++ incubator/whirr/trunk/services/cassandra/src/main/java/org/apache/whirr/service/cassandra/CassandraClusterActionHandler.java Wed Jan  5 04:48:26 2011
@@ -26,6 +26,7 @@ import java.io.IOException;
 import java.util.List;
 import java.util.Set;
 
+import org.apache.commons.configuration.Configuration;
 import org.apache.whirr.service.Cluster;
 import org.apache.whirr.service.Cluster.Instance;
 import org.apache.whirr.service.ClusterActionEvent;
@@ -46,6 +47,9 @@ public class CassandraClusterActionHandl
   public static final int CLIENT_PORT = 9160;
   public static final int JMX_PORT = 8080;
 
+  public static final String BIN_TARBALL = "whirr.cassandra.tarball.url";
+  public static final String MAJOR_VERSION = "whirr.cassandra.version.major";
+
   @Override
   public String getRole() {
     return CASSANDRA_ROLE;
@@ -54,7 +58,13 @@ public class CassandraClusterActionHandl
   @Override
   protected void beforeBootstrap(ClusterActionEvent event) throws IOException {
     addRunUrl(event, "sun/java/install");
-    addRunUrl(event, "apache/cassandra/install");
+    Configuration config = event.getClusterSpec().getConfiguration();
+    String tarball = config.getString(BIN_TARBALL, null);
+    String major = config.getString(MAJOR_VERSION, null);
+    if (tarball != null && major != null)
+      addRunUrl(event, String.format("apache/cassandra/install %s %s", major, tarball));
+    else
+      addRunUrl(event, "apache/cassandra/install");
   }
 
   @Override