#!/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 -ex
. `dirname $0`/bigtop.bom

export _JAVA_OPTIONS="-Xmx2048m -Djava.awt.headless=true"

. /etc/os-release
OS="$ID"
ARCH=`uname -m`
RPM_DIR=../../../../../output/ambari

mvn clean package -DskipTests -Drat.skip

# BIGTOP-3800:
# Build Ambari-mertics RPMs for Mpack deployment;
# Ambari DO NOT support debian deployment in current version (2.7.5);
# So just only add x86 RPMs support for Bigtop 3.2+ Mpack (Centos-7).
if [ $HOSTTYPE = "x86_64" ] ; then
if [ "${OS}" = "centos" ]; then
  mkdir -p ${RPM_DIR}/${ARCH}
  cd ambari-metrics
  mvn clean package -Dbuild-rpm -DskipTests
  cd -
  cp ambari-metrics/ambari-metrics-assembly/target/rpm/ambari-metrics-collector/RPMS/${ARCH}/ambari-metrics-collector*.rpm ${RPM_DIR}/${ARCH}
  cp ambari-metrics/ambari-metrics-assembly/target/rpm/ambari-metrics-monitor/RPMS/${ARCH}/ambari-metrics-monitor*.rpm ${RPM_DIR}/${ARCH}
  cp ambari-metrics/ambari-metrics-assembly/target/rpm/ambari-metrics-hadoop-sink/RPMS/${ARCH}/ambari-metrics-hadoop-sink*.rpm ${RPM_DIR}/${ARCH}
  cp ambari-metrics/ambari-metrics-assembly/target/rpm/ambari-metrics-grafana/RPMS/${ARCH}/ambari-metrics-grafana*.rpm ${RPM_DIR}/${ARCH}
fi
fi

(cd contrib/management-packs/odpi-ambari-mpack ; mvn clean package -DskipTests -Drat.skip)
