#!/bin/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 -ev

TRAVIS_DIR=$(dirname $0)
HBASE_DOWNLOAD_ADDRESS="http://archive.apache.org/dist/hbase"
HBASE_VERSION="2.0.2"
HBASE_PACKAGE="hbase-${HBASE_VERSION}"
HBASE_TAR="${HBASE_PACKAGE}-bin.tar.gz"

# download hbase
if [ ! -f $HOME/downloads/${HBASE_TAR} ]; then
  sudo wget -q -O $HOME/downloads/${HBASE_TAR} ${HBASE_DOWNLOAD_ADDRESS}/${HBASE_VERSION}/${HBASE_TAR}
fi

# decompress hbase
sudo cp $HOME/downloads/${HBASE_TAR} ${HBASE_TAR} && tar xzf ${HBASE_TAR}

# using tmpfs for the Hbase data directory reduces travis test runtime
sudo mkdir /mnt/ramdisk
sudo mount -t tmpfs -o size=1024m tmpfs /mnt/ramdisk
sudo ln -s /mnt/ramdisk /tmp/hbase

# config hbase
sudo cp -f $TRAVIS_DIR/hbase-site.xml ${HBASE_PACKAGE}/conf

# start hbase service
sudo ${HBASE_PACKAGE}/bin/start-hbase.sh
