{#
# 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.
#}
{
  "name": "ats-hbase",
  "version": "1.0.0",
  "lifetime": "-1",
  "queue": "{{service_queue_name}}",
  "artifact": {
    "id": "{{app_hdfs_path}}",
    "type": "TARBALL"
  },
  "configuration": {
    "env": {
      "HBASE_IDENT_STRING": "${USER}",
      "HBASE_LOG_DIR": "<LOG_DIR>",
      "HBASE_CONF_DIR": "$PWD/conf",
      "HBASE_PID_DIR": "$PWD/pids",
      "JAVA_HOME": "{{java64_home}}",
      "HBASE_ROOT_LOGGER": "INFO,RFA",
      "SERVER_GC_OPTS": "-verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -Xloggc:${HBASE_LOG_DIR}/gc.log-`date +'%Y%m%d%H%M'`",
      "HBASE_OPTS": "-XX:+UseConcMarkSweepGC -XX:ErrorFile=${HBASE_LOG_DIR}/hs_err_pid%p.log -Djava.io.tmpdir=/tmp",
      "HADOOP_HOME": "$PWD/lib/hadoop",
      "HADOOP_YARN_HOME": "$PWD/lib/hadoop",
      "HBASE_HOME": "$PWD/lib/hbase"
    },
    "files": [
      {
        "type": "TEMPLATE",
        "dest_file": "log4j.properties",
        "src_file": "{{user_version_home}}/log4j.properties"
      },
      {
        "type": "TEMPLATE",
        "dest_file": "hbase-site.xml",
        "src_file": "{{user_version_home}}/hbase-site.xml"
      },
      {
        "type": "TEMPLATE",
        "dest_file": "hbase-policy.xml",
        "src_file": "{{user_version_home}}/hbase-policy.xml"
      },
      {
        "type": "TEMPLATE",
        "dest_file": "core-site.xml",
        "src_file": "{{user_version_home}}/core-site.xml"
      }
    ]
  },
  "components": [
    {
      "name": "master",
      "number_of_containers": {{number_of_containers_master}},
      "launch_command": "$HBASE_HOME/bin/hbase master start",
      "readiness_check": {
        "type": "HTTP",
        "properties": {
          "url": "http://${THIS_HOST}:{{master_info_port}}/master-status"
        }
      },
      "resource": {
        "cpus": {{number_of_cpus_master}},
        "memory": "{{memory_mb_master}}"
      },
      "configuration": {
        "env": {
          "HBASE_LOG_PREFIX": "hbase-$HBASE_IDENT_STRING-master-$HOSTNAME",
          "HBASE_LOGFILE": "$HBASE_LOG_PREFIX.log",
          "HBASE_MASTER_OPTS": "-Xms{{master_heapsize}} -Xmx{{master_heapsize}} -Djava.security.auth.login.config={{master_jaas_file}}"
        }
      },
      "placement_policy": {
        "constraints": [
          {
            "type": "ANTI_AFFINITY",
            "scope": "NODE",
            "target_tags": [
                  "master"
            ]
          }
        ]
      }
    },
    {
      "name": "regionserver",
      "number_of_containers": {{number_of_containers_rs}},
      "launch_command": "$HBASE_HOME/bin/hbase regionserver start",
      "readiness_check": {
        "type": "HTTP",
        "properties": {
          "url": "http://${THIS_HOST}:{{regionserver_info_port}}/rs-status"
        }
      },
      "resource": {
        "cpus": {{number_of_cpus_rs}},
        "memory": "{{memory_mb_rs}}"
      },
      "configuration": {
        "env": {
          "HBASE_LOG_PREFIX": "hbase-$HBASE_IDENT_STRING-regionserver-$HOSTNAME",
          "HBASE_LOGFILE": "$HBASE_LOG_PREFIX.log",
          "HBASE_REGIONSERVER_OPTS": "-XX:CMSInitiatingOccupancyFraction=70 -XX:ReservedCodeCacheSize=256m -Xms{{regionserver_heapsize}} -Xmx{{regionserver_heapsize}} -Djava.security.auth.login.config={{regionserver_jaas_file}}"
        }
      },
      "placement_policy": {
        "constraints": [
          {
            "type": "ANTI_AFFINITY",
            "scope": "NODE",
            "target_tags": [
                  "regionserver"
            ]
          }
        ]
      }
    },
    {
      "name": "hbaseclient",
      "number_of_containers": {{number_of_containers_client}},
      "launch_command": "sleep 10;export HBASE_CLASSPATH_PREFIX=$HADOOP_HOME/share/hadoop/yarn/timelineservice/*;{{kinit_cmd}} $HBASE_HOME/bin/hbase {{class_name}}; {{kinit_cmd}} $HBASE_HOME/bin/hbase shell {{grant_premissions_file}};sleep infinity",
      "dependencies": [ "master", "regionserver" ],
      "resource": {
        "cpus": {{number_of_cpus_client}},
        "memory": "{{memory_mb_client}}"
      },
      "configuration": {
        "env": {
          "HBASE_LOG_PREFIX": "hbase-$HBASE_IDENT_STRING-hbaseclient-$HOSTNAME",
          "HBASE_LOGFILE": "$HBASE_LOG_PREFIX.log"
        }
      },
      "placement_policy": {
        "constraints": [
          {
            "type": "ANTI_AFFINITY",
            "scope": "NODE",
            "target_tags": [
                  "hbaseclient"
            ]
          }
        ]
      }
    }
  ],
  "kerberos_principal" : {
    "principal_name" : "{{yarn_ats_hbase_principal_name}}",
    "keytab" : "{{yarn_ats_hbase_keytab}}"
  }
}