| #!/bin/bash |
| |
| # @@@ START COPYRIGHT @@@ |
| # |
| # (C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P. |
| # |
| # Licensed 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. |
| # |
| # @@@ END COPYRIGHT @@@ |
| |
| # |
| # This script will configure HBase with HBase-trx |
| # and co-processors needed for Trafodion. It uses |
| # Ambari's configs.sh script to do this. |
| # |
| # NOTE: Only for Ambari installations |
| |
| TRAF_CONFIG=/etc/trafodion/trafodion_config |
| source $TRAF_CONFIG |
| |
| #===================================== |
| # copy Trafodion hbase trx jar to /usr/lib/hbase/lib |
| |
| cd $UNTAR_DIR |
| |
| PORT=`echo $URL | sed 's/.*://'` |
| echo $PORT |
| AMBARI_HOST=$(echo $URL | sed 's@:.*@@') |
| echo $AMBARI_HOST |
| |
| # determine java version and choose corresponding jar files |
| echo "***INFO: Detected JAVA version $JAVA_VERSION" |
| if [ "$JAVA_VERSION" == "1.6" ]; then |
| echo "***ERROR: JAVA 1.6 not supported for Trafodion HBase 0.98" |
| exit -1 |
| elif [ "$JAVA_VERSION" == "1.7" ]; then |
| if [[ $CDH_5_3_HDP_2_2_SUPPORT == "N" ]]; then |
| hbase_trx_jar="hbase-trx-hdp2_1-${TRAF_VERSION}.jar" |
| else |
| hbase_trx_jar="hbase-trx-hdp2_2-${TRAF_VERSION}.jar" |
| fi |
| else |
| echo "***ERROR: unable to determine Hadoop's java version" |
| exit -1 |
| fi |
| |
| # The permissions the Trafodion build process creates on the hbase-trx jar |
| # files does not work well with the installation process so we change them |
| sudo chmod -R 777 $UNTAR_DIR/export/lib |
| |
| if [ ! -f $UNTAR_DIR/export/lib/$hbase_trx_jar ]; then |
| echo "***ERROR: unable to find $UNTAR_DIR/export/lib/$hbase_trx_jar" |
| exit -1 |
| fi |
| |
| # if more than one node then copy to all nodes |
| echo "***INFO: copying $hbase_trx_jar to all nodes" |
| if [ $node_count -ne 1 ]; then |
| pdsh $MY_NODES sudo rm -rf /usr/lib/hbase/lib/hbase-trx* 2>/dev/null |
| pdsh $MY_NODES sudo rm -rf /usr/hdp/current/hbase-regionserver/lib/hbase-trx* 2>/dev/null |
| pdsh $MY_NODES sudo rm -rf /usr/share/cmf/lib/plugins/hbase-trx* 2>/dev/null |
| pdsh $MY_NODES sudo rm -rf /usr/lib/hbase/lib/trafodion* 2>/dev/null |
| pdsh $MY_NODES sudo rm -rf /usr/hdp/current/hbase-regionserver/lib/trafodion* 2>/dev/null |
| pdsh $MY_NODES sudo rm -rf /usr/share/cmf/lib/plugins/trafodion* 2>/dev/null |
| pdsh $MY_NODES mkdir -p $LOCAL_WORKDIR 2>/dev/null |
| cp $UNTAR_DIR/export/lib/$hbase_trx_jar $LOCAL_WORKDIR |
| pdcp $MY_NODES $LOCAL_WORKDIR/$hbase_trx_jar $LOCAL_WORKDIR |
| |
| if [[ $CDH_5_3_HDP_2_2_SUPPORT == "N" ]]; then |
| pdsh $MY_NODES sudo cp $LOCAL_WORKDIR/$hbase_trx_jar /usr/lib/hbase/lib |
| pdsh $MY_NODES sudo chmod 644 /usr/lib/hbase/lib/$hbase_trx_jar |
| else |
| pdsh $MY_NODES sudo cp $LOCAL_WORKDIR/$hbase_trx_jar /usr/hdp/current/hbase-regionserver/lib |
| pdsh $MY_NODES sudo chmod 644 /usr/hdp/current/hbase-regionserver/lib/$hbase_trx_jar |
| fi |
| |
| pdsh $MY_NODES rm $LOCAL_WORKDIR/$hbase_trx_jar 2>/dev/null |
| else |
| sudo rm -rf /usr/lib/hbase/lib/hbase-trx* 2>/dev/null |
| sudo rm -rf /usr/share/cmf/lib/plugins/hbase-trx* 2>/dev/null |
| sudo rm -rf /usr/lib/hbase/lib/trafodion* 2>/dev/null |
| sudo rm -rf /usr/share/cmf/lib/plugins/trafodion* 2>/dev/null |
| |
| if [[ $CDH_5_3_HDP_2_2_SUPPORT == "N" ]]; then |
| sudo cp $UNTAR_DIR/export/lib/$hbase_trx_jar /usr/lib/hbase/lib |
| sudo chmod 644 /usr/lib/hbase/lib/$hbase_trx_jar |
| else |
| sudo cp $UNTAR_DIR/export/lib/$hbase_trx_jar /usr/hdp/current/hbase-regionserver/lib |
| sudo chmod 644 /usr/hdp/current/hbase-regionserver/lib/$hbase_trx_jar |
| fi |
| fi |
| |
| #===================================== |
| # create new directories for bulkload and lobs if not already there |
| rm $LOCAL_WORKDIR/traf_temp_output 2>/dev/null |
| |
| sudo su $HDFS_USER --command "hadoop fs -mkdir /hbase-staging" 2> $LOCAL_WORKDIR/traf_temp_output |
| if [ $? != 0 ]; then |
| # ok if directory already exists |
| dir_exists=$(grep "File exists" $LOCAL_WORKDIR/traf_temp_output | wc -l) |
| if [ $dir_exists -eq 0 ]; then |
| echo "***ERROR: 'hadoop fs -mkdir /hbase-staging' command failed" |
| echo "***ERROR: $(cat $LOCAL_WORKDIR/traf_temp_output)" |
| exit -1 |
| fi |
| fi |
| sudo su $HDFS_USER --command "hadoop fs -chown -R $HBASE_USER:$HBASE_GROUP /hbase-staging" |
| sudo su $HDFS_USER --command "hadoop fs -mkdir /bulkload" 2> $LOCAL_WORKDIR/traf_temp_output |
| if [ $? != 0 ]; then |
| # ok if directory already exists |
| dir_exists=$(grep "File exists" $LOCAL_WORKDIR/traf_temp_output | wc -l) |
| if [ $dir_exists -eq 0 ]; then |
| echo "***ERROR: 'hadoop fs -mkdir /bulkload' command failed" |
| echo "***ERROR: $(cat $LOCAL_WORKDIR/traf_temp_output)" |
| exit -1 |
| fi |
| fi |
| sudo su $HDFS_USER --command "hadoop fs -chown -R $TRAF_USER:trafodion /bulkload" |
| |
| # Create lobs directory |
| sudo su hdfs --command "hadoop fs -mkdir /lobs" 2> $LOCAL_WORKDIR/traf_temp_output |
| if [ $? != 0 ]; then |
| # ok if directory already exists |
| dir_exists=$(grep "File exists" $LOCAL_WORKDIR/traf_temp_output | wc -l) |
| if [ $dir_exists -eq 0 ]; then |
| echo "***ERROR: 'hadoop fs -mkdir /lobs' command failed" |
| echo "***ERROR: $(cat $LOCAL_WORKDIR/traf_temp_output)" |
| exit -1 |
| fi |
| fi |
| sudo su hdfs --command "hadoop fs -chown -R $TRAF_USER:trafodion /lobs" |
| |
| #===================================== |
| # change the hbase configuration using Ambari's script |
| |
| AMBARI_DIR=/var/lib/ambari-server/resources/scripts |
| cd $LOCAL_WORKDIR |
| |
| $AMBARI_DIR/configs.sh -port $PORT set $AMBARI_HOST $CLUSTER_NAME hbase-site hbase.master.distributed.log.splitting false |
| if [ $? != 0 ]; then |
| echo "***ERROR: unable to modify hbase.master.distributed.log.splitting through Ambari's configs.sh script." |
| echo "***ERROR: Check if Ambari URL is correct, may need to enter external IP address." |
| echo "***ERROR: Check if iptables/firewall is configured correctly and ports a |
| re enabled." |
| echo "***ERROR: Check that HBase is running without error." |
| exit -1 |
| fi |
| sleep 2 |
| $AMBARI_DIR/configs.sh -port $PORT set $AMBARI_HOST $CLUSTER_NAME hbase-site hbase.coprocessor.region.classes "org.apache.hadoop.hbase.coprocessor.transactional.TrxRegionObserver,org.apache.hadoop.hbase.coprocessor.transactional.TrxRegionEndpoint,org.apache.hadoop.hbase.coprocessor.AggregateImplementation" |
| if [ $? != 0 ]; then |
| echo "***ERROR: unable to modify hbase.coprocessor.region.classes through Ambari's configs.sh script." |
| exit -1 |
| fi |
| sleep 2 |
| $AMBARI_DIR/configs.sh -port $PORT set $AMBARI_HOST $CLUSTER_NAME hbase-site hbase.hregion.impl org.apache.hadoop.hbase.regionserver.transactional.TransactionalRegion |
| if [ $? != 0 ]; then |
| echo "***ERROR: unable to modify hbase.hregion.impl through Ambari's configs.sh script." |
| exit -1 |
| fi |
| sleep 2 |
| $AMBARI_DIR/configs.sh -port $PORT set $AMBARI_HOST $CLUSTER_NAME hbase-site hbase.regionserver.region.split.policy org.apache.hadoop.hbase.regionserver.ConstantSizeRegionSplitPolicy |
| if [ $? != 0 ]; then |
| echo "***ERROR: unable to modify hbase.regionserver.region.split.policy through Ambari's configs.sh script." |
| exit -1 |
| fi |
| sleep 2 |
| $AMBARI_DIR/configs.sh -port $PORT set $AMBARI_HOST $CLUSTER_NAME hbase-site hbase.snapshot.enabled true |
| if [ $? != 0 ]; then |
| echo "***ERROR: unable to modify hbase.snapshot.enabled through Ambari's configs.sh script." |
| exit -1 |
| fi |
| sleep 2 |
| $AMBARI_DIR/configs.sh -port $PORT set $AMBARI_HOST $CLUSTER_NAME hbase-site hbase.bulkload.staging.dir /hbase-staging |
| if [ $? != 0 ]; then |
| echo "***ERROR: unable to modify hbase.bulkload.staging.dir through Ambari's configs.sh script." |
| exit -1 |
| fi |
| sleep 2 |
| $AMBARI_DIR/configs.sh -port $PORT set $AMBARI_HOST $CLUSTER_NAME hbase-site hbase.regionserver.region.transactional.tlog true |
| if [ $? != 0 ]; then |
| echo "***ERROR: unable to modify hbase.regionserver.region.transactional.tlog through Ambari's configs.sh script." |
| exit -1 |
| fi |
| sleep 2 |
| $AMBARI_DIR/configs.sh -port $PORT set $AMBARI_HOST $CLUSTER_NAME hbase-site hbase.snapshot.master.timeoutMillis 600000 |
| if [ $? != 0 ]; then |
| echo "***ERROR: unable to modify hbase.snapshot.master.timeoutMillis through Ambari's configs.sh script." |
| exit -1 |
| fi |
| sleep 2 |
| $AMBARI_DIR/configs.sh -port $PORT set $AMBARI_HOST $CLUSTER_NAME hbase-site hbase.snapshot.region.timeout 600000 |
| if [ $? != 0 ]; then |
| echo "***ERROR: unable to modify hbase.snapshot.region.timeout through Ambari's configs.sh script." |
| exit -1 |
| fi |
| sleep 2 |
| $AMBARI_DIR/configs.sh -port $PORT set $AMBARI_HOST $CLUSTER_NAME hdfs-site dfs.namenode.acls.enabled true |
| if [ $? != 0 ]; then |
| echo "***ERROR: unable to modify dfs.namenode.acls.enabled through Ambari's configs.sh script." |
| exit -1 |
| fi |
| sleep 2 |
| $AMBARI_DIR/configs.sh -port $PORT set $AMBARI_HOST $CLUSTER_NAME hbase-site hbase.client.scanner.timeout.period 600000 |
| if [ $? != 0 ]; then |
| echo "***ERROR: unable to modify hbase.client.scanner.timeout.period through Ambari's configs.sh script." |
| exit -1 |
| fi |
| sleep 2 |
| echo |
| |
| #===================================== |
| # stop HBase to restart HDFS and pick up all the changes just made |
| |
| poll_time=30 |
| echo "***INFO: Restarting HBase to pick up config changes for Trafodion" |
| echo "***INFO: Stopping HBase..." |
| curl -u $ADMIN:$PASSWORD \ |
| -H "X-Requested-By: Trafodion" \ |
| -X PUT -d '{"ServiceInfo": { "state" : "INSTALLED" }}' \ |
| http://$URL/api/v1/clusters/$CLUSTER_NAME/services/HBASE > $TRAF_WORKDIR/traf_hbase_restart_temp |
| |
| if [ $? != 0 ]; then |
| echo "***ERROR: Unable to stop HBase" |
| echo "***ERROR: Please manually restart HBase through the Ambari web GUI" |
| fi |
| |
| # in most cases curl does not return an error |
| # so curl's actual output needs to be checked, too |
| curl_error=$(grep TITLE $TRAF_WORKDIR/traf_hbase_restart_temp | grep Error | wc -l) |
| |
| if [ $curl_error -ne 0 ]; then |
| echo "***ERROR: Unable to stop HBase" |
| echo "***ERROR: Please manually restart HBase through the Ambari web GUI" |
| fi |
| |
| echo "***INFO: ...polling every $poll_time seconds until HBase stop is completed." |
| command_id=$(cat $TRAF_WORKDIR/traf_hbase_restart_temp | grep id | awk '{print $3}' | sed -e 's@,@@' ) |
| echo "***DEBUG: Ambari command_id=$command_id" |
| |
| # poll until stop is completed as a stop can take a while |
| completed=0 |
| while [ $completed -eq 0 ]; do |
| sleep $poll_time |
| curl -u $ADMIN:$PASSWORD \ |
| http://$URL/api/v1/clusters/$CLUSTER_NAME/requests/$command_id \ |
| > $LOCAL_WORKDIR/hbase_restart_status_temp |
| cat $LOCAL_WORKDIR/hbase_restart_status_temp |
| echo "***INFO: ...polling every $poll_time seconds until HBase stop is completed." |
| # if stop command is completed then completed will not equal 0 |
| completed=$(cat $LOCAL_WORKDIR/hbase_restart_status_temp | grep '"request_status" : "COMPLETED"' | wc -l) |
| done |
| |
| echo "***INFO: HBase stop completed" |
| |
| #===================================== |
| # restart HDFS to pick up all the changes just made |
| |
| echo "***INFO: Restarting HDFS to pick up config changes for Trafodion" |
| echo "***INFO: Stopping HDFS..." |
| curl --user $ADMIN:$PASSWORD \ |
| -H "X-Requested-By: Trafodion" \ |
| -X PUT -d '{"ServiceInfo": { "state" : "INSTALLED" }}' \ |
| http://$URL/api/v1/clusters/$CLUSTER_NAME/services/HDFS > $TRAF_WORKDIR/traf_hdfs_restart_temp |
| |
| if [ $? != 0 ]; then |
| echo "***ERROR: Unable to restart HDFS" |
| echo "***ERROR: Please manually restart HDFS through the Ambari web GUI" |
| fi |
| |
| # in most cases curl does not return an error |
| # so curl's actual output needs to be checked, too |
| curl_error=$(grep TITLE $TRAF_WORKDIR/traf_hdfs_restart_temp | grep Error | wc -l) |
| |
| if [ $curl_error -ne 0 ]; then |
| echo "***ERROR: Unable to restart HDFS" |
| echo "***ERROR: Please manually restart HDFS through the Ambari web GUI" |
| fi |
| |
| echo "***INFO: ...polling every $poll_time seconds until HDFS stop is completed." |
| command_id=$(cat $TRAF_WORKDIR/traf_hdfs_restart_temp | grep id | awk '{print $3}' | sed -e 's@,@@' ) |
| echo "***DEBUG: Ambari command_id=$command_id" |
| |
| # poll until stop is completed as a stop can take a while |
| completed=0 |
| while [ $completed -eq 0 ]; do |
| sleep $poll_time |
| curl --user $ADMIN:$PASSWORD \ |
| http://$URL/api/v1/clusters/$CLUSTER_NAME/requests/$command_id \ |
| > $LOCAL_WORKDIR/traf_hdfs_restart_temp |
| cat $LOCAL_WORKDIR/traf_hdfs_restart_temp |
| echo "***INFO: ...polling every $poll_time seconds until HDFS stop is completed." |
| # if stop command is completed then completed will not equal 0 |
| completed=$(cat $LOCAL_WORKDIR/traf_hdfs_restart_temp | grep '"request_status" : "COMPLETED"' | wc -l) |
| done |
| |
| echo "***INFO: Starting HDFS..." |
| curl --user $ADMIN:$PASSWORD \ |
| -H "X-Requested-By: Trafodion" \ |
| -X PUT -d '{"ServiceInfo": { "state" : "STARTED" }}' \ |
| http://$URL/api/v1/clusters/$CLUSTER_NAME/services/HDFS > $TRAF_WORKDIR/traf_hdfs_restart_temp |
| |
| if [ $? != 0 ]; then |
| echo "***ERROR: Unable to restart HDFS" |
| echo "***ERROR: Please manually restart HDFS through the Ambari web GUI" |
| fi |
| |
| # in most cases curl does not return an error |
| # so curl's actual output needs to be checked, too |
| curl_error=$(grep TITLE $TRAF_WORKDIR/traf_hdfs_restart_temp | grep Error | wc -l) |
| if [ $curl_error -ne 0 ]; then |
| echo "***ERROR: Unable to restart HDFS" |
| echo "***ERROR: Please manually restart HDFS through the Ambari web GUI" |
| fi |
| |
| echo "***INFO: ...polling every $poll_time seconds until HDFS start is completed." |
| command_id=$(cat $TRAF_WORKDIR/traf_hdfs_restart_temp | grep id | awk '{print $3}' | sed -e 's@,@@' ) |
| echo "***DEBUG: Ambari command_id=$command_id" |
| |
| # poll until start is completed as a start can take a while |
| completed=0 |
| while [ $completed -eq 0 ]; do |
| sleep $poll_time |
| curl --user $ADMIN:$PASSWORD \ |
| http://$URL/api/v1/clusters/$CLUSTER_NAME/requests/$command_id \ |
| > $LOCAL_WORKDIR/traf_hdfs_restart_temp |
| cat $LOCAL_WORKDIR/traf_hdfs_restart_temp |
| echo "***INFO: ...polling every $poll_time seconds until HDFS start is completed." |
| # if start command is completed then completed will not equal 0 |
| completed=$(cat $LOCAL_WORKDIR/traf_hdfs_restart_temp | grep '"request_status" : "COMPLETED"' | wc -l) |
| done |
| |
| echo "***INFO: HDFS restart completed" |
| |
| # wait to make sure HDFS is fully restarted and out of safemode |
| echo "***INFO: waiting for HDFS to exit safemode" |
| sudo su hdfs --command "hdfs dfsadmin -safemode wait" |
| |
| #===================================== |
| # restart HBase to pick up all the changes just made |
| |
| echo "***INFO: Restarting HBase to pick up config changes for Trafodion" |
| echo "***INFO: Starting HBase..." |
| curl -u $ADMIN:$PASSWORD \ |
| -H "X-Requested-By: Trafodion" \ |
| -X PUT -d '{"ServiceInfo": { "state" : "STARTED" }}' \ |
| http://$URL/api/v1/clusters/$CLUSTER_NAME/services/HBASE > $TRAF_WORKDIR/traf_hbase_restart_temp |
| |
| if [ $? != 0 ]; then |
| echo "***ERROR: Unable to restart HBase" |
| echo "***ERROR: Please manually restart HBase through the Ambari web GUI" |
| fi |
| |
| # in most cases curl does not return an error |
| # so curl's actual output needs to be checked, too |
| curl_error=$(grep TITLE $TRAF_WORKDIR/traf_hbase_restart_temp | grep Error | wc -l) |
| if [ $curl_error -ne 0 ]; then |
| echo "***ERROR: Unable to restart HBase" |
| echo "***ERROR: Please manually restart HBase through the Ambari web GUI" |
| fi |
| |
| echo "***INFO: ...polling every $poll_time seconds until HBase start is completed." |
| command_id=$(cat $TRAF_WORKDIR/traf_hbase_restart_temp | grep id | awk '{print $3}' | sed -e 's@,@@' ) |
| echo "***DEBUG: Ambari command_id=$command_id" |
| |
| # poll until start is completed as a start can take a while |
| completed=0 |
| while [ $completed -eq 0 ]; do |
| sleep $poll_time |
| curl -u $ADMIN:$PASSWORD \ |
| http://$URL/api/v1/clusters/$CLUSTER_NAME/requests/$command_id \ |
| > $LOCAL_WORKDIR/hbase_restart_status_temp |
| cat $LOCAL_WORKDIR/hbase_restart_status_temp |
| echo "***INFO: ...polling every $poll_time seconds until HBase start is completed." |
| # if start command is completed then completed will not equal 0 |
| completed=$(cat $LOCAL_WORKDIR/hbase_restart_status_temp | grep '"request_status" : "COMPLETED"' | wc -l) |
| done |
| |
| echo "***INFO: HBase restart completed" |
| |
| #===================================== |
| # NOTE: These command must be done AFTER acls are |
| # enabled and HDFS has been restarted |
| echo "***INFO: Setting HDFS ACLs for snapshot scan support" |
| sudo su hdfs --command "hdfs dfs -mkdir -p /apps/hbase/data/archive" |
| if [ $? != 0 ]; then |
| echo "***ERROR: (hdfs dfs -mkdir -p /apps/hbase/data/archive) command failed" |
| exit -1 |
| fi |
| sudo su hdfs --command "hdfs dfs -chown hbase:hdfs /apps/hbase/data/archive" |
| if [ $? != 0 ]; then |
| echo "***ERROR: (hdfs dfs -chown hbase:hdfs /apps/hbase/data/archive) command failed" |
| exit -1 |
| fi |
| sudo su hdfs --command "hdfs dfs -setfacl -R -m user:$TRAF_USER:rwx /apps/hbase/data/archive" |
| if [ $? != 0 ]; then |
| echo "***ERROR: (hdfs dfs -setfacl -R -m mask::rwx /apps/hbase/data/archive) command failed" |
| exit -1 |
| fi |
| sudo su hdfs --command "hdfs dfs -setfacl -R -m default:user:$TRAF_USER:rwx /apps/hbase/data/archive" |
| if [ $? != 0 ]; then |
| echo "***ERROR: (hdfs dfs -setfacl -R -m mask::rwx /apps/hbase/data/archive) command failed" |
| exit -1 |
| fi |
| sudo su hdfs --command "hdfs dfs -setfacl -R -m mask::rwx /apps/hbase/data/archive" |
| if [ $? != 0 ]; then |
| echo "***ERROR: (hdfs dfs -setfacl -R -m mask::rwx /apps/hbase/data/archive) command failed" |
| exit -1 |
| fi |
| |
| |
| # clean up files generated by Ambari's config.sh script |
| rm $LOCAL_WORKDIR/doSet_version* |
| |
| exit |