Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XHyve based native docker support for Mac #131

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions ambari-agent/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ MAINTAINER Hortonworks
ADD ambari.repo /etc/yum.repos.d/

RUN yum install -y ambari-agent && yum clean all
#RUN find /etc/rc.d/rc* -name "*ambari-agent" | xargs rm -v

# add a custom folder to the hadoop classpath
RUN mkdir -p /usr/lib/hadoop/lib
Expand All @@ -23,9 +22,6 @@ RUN sed -i "s/\"ifconfig\"/\"ifconfig eth0\"/" /usr/lib/python2.6/site-packages/
ADD dash-azure-storage-2.2.0.jar /usr/lib/hadoop/lib/
ADD gcs-connector-latest-hadoop2.jar /usr/lib/hadoop/lib/

ADD init/init-agent.sh /opt/ambari-agent/init-agent.sh
RUN chmod u+x /opt/ambari-agent/init-agent.sh

ADD init/ambari-agent.service /etc/systemd/system/ambari-agent.service

RUN systemctl enable ambari-agent
Expand Down
2 changes: 2 additions & 0 deletions ambari-agent/docker_shared/etc/resolv.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
nameserver 172.17.0.2
search service.consul node.dc1.consul
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,6 @@ debug() {
[[ "DEBUG" ]] && echo "[DEBUG] $@" 1>&2
}

get_nameserver_addr() {
if [[ "$NAMESERVER_ADDR" ]]; then
echo $NAMESERVER_ADDR
else
if ip addr show docker0 &> /dev/null; then
ip addr show docker0 | grep "inet\b" | awk '{print $2}' | cut -d/ -f1
else
ip ro | grep default | cut -d" " -f 3
fi
fi
}

# --dns isn't available for: docker run --net=host
# sed -i /etc/resolf.conf fails:
# sed: cannot rename /etc/sedU9oCRy: Device or resource busy
# here comes the tempfile workaround ...
local_nameserver() {
cat>/etc/resolv.conf<<EOF
nameserver $(get_nameserver_addr)
search service.consul node.dc1.consul
EOF
}

ambari_server_addr() {
sed -i "s/^hostname=.*/hostname=${AMBARI_SERVER_ADDR}/" /etc/ambari-agent/conf/ambari-agent.ini
}
Expand All @@ -46,6 +23,9 @@ reorder_dns_lookup() {
}

main() {
ln -s /docker_shared/etc/resolv.conf /tmp/resolv.conf
cp /tmp/resolv.conf /etc/resolv.conf

[[ "$USE_CONSUL_DNS" == "true" ]] && local_nameserver
ambari_server_addr
reorder_dns_lookup
Expand Down
2 changes: 1 addition & 1 deletion ambari-agent/init/ambari-agent.service
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ IgnoreSIGPIPE=no
KillMode=process
GuessMainPID=no
RemainAfterExit=yes
ExecStartPre=/opt/ambari-agent/init-agent.sh
ExecStartPre=/docker_shared/init-agent.sh
ExecStart=/etc/rc.d/init.d/ambari-agent start
ExecStop=/etc/rc.d/init.d/ambari-agent stop
138 changes: 122 additions & 16 deletions ambari-functions
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@ curl -Lo .amb j.mp/docker-ambari && . .amb
full documentation: https://github.com/sequenceiq/docker-ambari
USAGE

: ${WORK_DIR:="/tmp/work_dir/"}
: ${AMBARI_SERVER_SHARED:="${WORK_DIR}/ambari_server_shared"}
: ${AMBARI_AGENT_SHARED:="${WORK_DIR}/ambari_agent_shared"}
: ${KERBEROS:="kerberos"}
: ${KERBEROS_SHARED:="${WORK_DIR}/kerberos_shared"}
: ${NODE_PREFIX=amb}
: ${AMBARI_SERVER_NAME:=${NODE_PREFIX}-server}
: ${AMBARI_SERVER_IMAGE:="hortonworks/ambari-server:latest"}
: ${AMBARI_AGENT_IMAGE:="hortonworks/ambari-agent:latest"}
: ${KERBEROS_IMAGE:="sequenceiq/kerberos:latest"}
: ${DOCKER_OPTS:=""}
: ${CONSUL:="${NODE_PREFIX}-consul"}
: ${CONSUL_IMAGE:="sequenceiq/consul:v0.5.0-v6"}
Expand All @@ -20,6 +26,31 @@ USAGE
: ${EXPOSE_DNS:=false}
: ${DRY_RUN:=false}


init() {
mkdir -p $WORK_DIR
mkdir -p $AMBARI_SERVER_SHARED

rm -rf {ambari-server,ambari-agent,docker-kerberos}/docker_shared/
cp -r docker_shared/etc {ambari-server,ambari-agent,docker-kerberos}/docker_shared/

cp -rf ambari-server/docker_shared/ $AMBARI_SERVER_SHARED
cp -rf ambari-agent/docker_shared/ $AMBARI_AGENT_SHARED
cp -rf docker-kerberos/docker_shared/ $KERBEROS_SHARED
}

update-nameserver() {
cat>$WORK_DIR/ambari_server_shared/etc/resolv.conf<<EOF
nameserver $(get-consul-ip)
search service.consul node.dc1.consul
EOF

cat>$WORK_DIR/ambari_agent_shared/etc/resolv.conf<<EOF
nameserver $(get-consul-ip)
search service.consul node.dc1.consul
EOF
}

run-command() {
CMD="$@"
if [[ "$DRY_RUN" == "false" ]]; then
Expand All @@ -43,13 +74,17 @@ get-consul-ip() {
get-host-ip $CONSUL
}

get-consul-base-url() {
echo "http://127.0.0.1:8500"
}

get-host-ip() {
HOST=$1
docker inspect --format="{{.NetworkSettings.IPAddress}}" ${HOST}
}

amb-members() {
curl http://$(get-consul-ip):8500/v1/catalog/nodes | sed -e 's/,{"Node":"ambari-8080.*}//g' -e 's/,{"Node":"consul.*}//g'
curl $(get-consul-base-url)/v1/catalog/nodes | sed -e 's/,{"Node":"ambari-8080.*}//g' -e 's/,{"Node":"consul.*}//g'
}

amb-settings() {
Expand Down Expand Up @@ -82,6 +117,30 @@ docker-psa() {
docker inspect --format="{{.Name}} {{.NetworkSettings.IPAddress}} {{.Config.Image}} {{.Config.Entrypoint}} {{.Config.Cmd}}" $(docker ps -qa)
}

amb-restart-cluster() {
update-nameserver
local act_cluster_size=$1
: ${act_cluster_size:=$CLUSTER_SIZE}
echo starting an ambari cluster with: $act_cluster_size nodes

local CONSUL_IP=$(get-consul-ip)

docker restart ${AMBARI_SERVER_NAME}

[ $act_cluster_size -gt 1 ] && for i in $(seq $((act_cluster_size - 1))); do
docker restart ${NODE_PREFIX}${i}
done

echo "Waiting for containers to start..."
sleep 5

docker exec ${AMBARI_SERVER_NAME} /bin/bash -c "ex '+%s/nameserver.*/nameserver $CONSUL_IP/g' '+:wq' /etc/resolv.conf"

[ $act_cluster_size -gt 1 ] && for i in $(seq $((act_cluster_size - 1))); do
docker exec ${NODE_PREFIX}${i} /bin/bash -c "ex '+%s/nameserver.*/nameserver $CONSUL_IP/g' '+:wq' /etc/resolv.conf"
done
}

amb-start-cluster() {
local act_cluster_size=$1
: ${act_cluster_size:=$CLUSTER_SIZE}
Expand All @@ -98,8 +157,9 @@ _amb_run_shell() {
: ${COMMAND:? required}
get-ambari-server-ip
EXPECTED_HOST_COUNT=$(docker inspect --format="{{.Config.Image}} {{.Name}}" $(docker ps -q)|grep $AMBARI_AGENT_IMAGE|grep $NODE_PREFIX|wc -l|xargs)
run-command docker run -it --rm -e EXPECTED_HOST_COUNT=$EXPECTED_HOST_COUNT -e BLUEPRINT=$BLUEPRINT --link ${AMBARI_SERVER_NAME}:ambariserver \
--entrypoint /bin/sh $AMBARI_SERVER_IMAGE -c $COMMAND
cd ambari-server/ && run-command docker run -v $AMBARI_SERVER_SHARED:/docker_shared -it --rm -e EXPECTED_HOST_COUNT=$EXPECTED_HOST_COUNT -e BLUEPRINT=$BLUEPRINT --link ${AMBARI_SERVER_NAME}:ambariserver \
--entrypoint /bin/sh $AMBARI_SERVER_IMAGE -c $COMMAND && cd ..

}

amb-shell() {
Expand All @@ -118,27 +178,73 @@ amb-deploy-cluster() {

: ${BLUEPRINT:?" required (single-node-hdfs-yarn / multi-node-hdfs-yarn / hdp-singlenode-default / hdp-multinode-default)"}

init
amb-start-cluster $act_cluster_size
_amb_run_shell /tmp/install-cluster.sh
}

amb-start-first() {
amb-consul-start() {
local dns_port_command=""
if [[ "$EXPOSE_DNS" == "true" ]]; then
dns_port_command="-p 53:$DNS_PORT/udp"
fi
run-command docker run -d $dns_port_command --name $CONSUL -h $CONSUL.service.consul $CONSUL_IMAGE -server -bootstrap
run-command docker run -p 8500:8500 -d $dns_port_command --name $CONSUL -h $CONSUL.service.consul $CONSUL_IMAGE -server -bootstrap-expect=1
sleep 5

run-command docker run -d $DOCKER_OPTS --privileged --name $AMBARI_SERVER_NAME -h $AMBARI_SERVER_NAME.service.consul $AMBARI_SERVER_IMAGE \
systemd.setenv=NAMESERVER_ADDR=$(get-consul-ip)
update-nameserver
}


amb-reregister-service() {
get-ambari-server-ip
: ${AMBARI_SERVER_IP:?"AMBARI_SERVER_IP is needed"}
NUMBER=${1:?"please enter number of nodes to be re-registered"}
if [[ $# -eq 1 ]]; then
MORE_OPTIONS="-d"
else
shift
MORE_OPTIONS="$@"
fi

echo reregistering an ambari cluster on consul with: $act_cluster_size nodes

echo "Registering Ambari Server $AMBARI_SERVER_NAME $AMBARI_SERVER_IP on consul: " $(_consul-register-service $AMBARI_SERVER_NAME $AMBARI_SERVER_IP)

echo "Registering Ambari Service ambari-8080 on consul: " $(_consul-register-service ambari-8080 $AMBARI_SERVER_IP)

local act_cluster_size=$1
: ${act_cluster_size:=$CLUSTER_SIZE}

[ $act_cluster_size -gt 1 ] && for i in $(seq $((act_cluster_size - 1))); do
echo Registering ${NODE_PREFIX}${i} : $(_consul-register-service ${NODE_PREFIX}${i} $(get-host-ip ${NODE_PREFIX}${i}))
done
}

amb-start-first() {
local dns_port_command=""
if [[ "$EXPOSE_DNS" == "true" ]]; then
dns_port_command="-p 53:$DNS_PORT/udp"
fi

amb-consul-start

cd ambari-server && run-command docker run -v $AMBARI_SERVER_SHARED:/docker_shared -p 8080:8080 -d $DOCKER_OPTS --privileged --name $AMBARI_SERVER_NAME -h $AMBARI_SERVER_NAME.service.consul $AMBARI_SERVER_IMAGE && cd ..

get-ambari-server-ip

_consul-register-service $AMBARI_SERVER_NAME $AMBARI_SERVER_IP
_consul-register-service ambari-8080 $AMBARI_SERVER_IP
}

kerberos-start-first() {
echo run-command docker run -v $KERBEROS_SHARED:/docker_shared -v /dev/urandom:/dev/random -h kerberos.service.consul --name $KERBEROS -e BOOTSTRAP=0 --security-opt seccomp=unconfined -dt $DOCKER_OPTS --entrypoint /docker_shared/init-kerberos.sh $KERBEROS_IMAGE
run-command docker run -v $KERBEROS_SHARED:/docker_shared -v /dev/urandom:/dev/random -h kerberos.service.consul --name $KERBEROS -e BOOTSTRAP=0 --security-opt seccomp=unconfined -dt $DOCKER_OPTS --entrypoint /docker_shared/init-kerberos.sh $KERBEROS_IMAGE
sleep 10
kerberos_ip=$(get-host-ip $KERBEROS)
echo "Kerberos running on" $kerberos_ip
_consul-register-service $KERBEROS $kerberos_ip
}

amb-copy-to-hdfs() {
get-ambari-server-ip
FILE_PATH=${1:?"usage: <FILE_PATH> <NEW_FILE_NAME_ON_HDFS> <HDFS_PATH>"}
Expand Down Expand Up @@ -174,18 +280,18 @@ amb-start-node() {
MORE_OPTIONS="$@"
fi

run-command docker run $MORE_OPTIONS $DOCKER_OPTS --privileged --name ${NODE_PREFIX}$NUMBER -h ${NODE_PREFIX}${NUMBER}.service.consul $AMBARI_AGENT_IMAGE \
systemd.setenv=NAMESERVER_ADDR=$(get-consul-ip)
cd ambari-agent && run-command docker run -v $AMBARI_AGENT_SHARED:/docker_shared $MORE_OPTIONS $DOCKER_OPTS --privileged --name ${NODE_PREFIX}$NUMBER -h ${NODE_PREFIX}${NUMBER}.service.consul $AMBARI_AGENT_IMAGE && cd ..

_consul-register-service ${NODE_PREFIX}${NUMBER} $(get-host-ip ${NODE_PREFIX}$NUMBER)
}

_consul-register-service() {
curl -X PUT -d "{
\"Node\": \"$1\",
\"Address\": \"$2\",
\"Service\": {
\"Service\": \"$1\"
}
}" http://$(get-consul-ip):8500/v1/catalog/register
echo "Dummy Registration"
# curl -X PUT -d "{
# \"Node\": \"$1\",
# \"Address\": \"$2\",
# \"Service\": {
# \"Service\": \"$1\"
# }
#}" $(get-consul-base-url)/v1/catalog/register
}
3 changes: 0 additions & 3 deletions ambari-server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ ADD shell/ambari-shell.sh /tmp/
ENV PLUGIN_PATH /plugins
WORKDIR /tmp

ADD init/init-server.sh /opt/ambari-server/init-server.sh
RUN chmod u+x /opt/ambari-server/init-server.sh

# add mysql and psql connectors to ambari-server so it can be downloaded by services (e.g.: Ranger)
ADD http://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-5.1.39.tar.gz /var/lib/ambari-server/resources/mysql-jdbc-driver.jar
ADD https://jdbc.postgresql.org/download/postgresql-9.4.1208.jre7.jar /var/lib/ambari-server/resources/postgres-jdbc-driver.jar
Expand Down
2 changes: 2 additions & 0 deletions ambari-server/docker_shared/etc/resolv.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
nameserver 172.17.0.2
search service.consul node.dc1.consul
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,6 @@ debug() {
[[ "DEBUG" ]] && echo "[DEBUG] $@" 1>&2
}

get_nameserver_addr() {
if [[ "$NAMESERVER_ADDR" ]]; then
echo $NAMESERVER_ADDR
else
if ip addr show docker0 &> /dev/null; then
ip addr show docker0 | grep "inet\b" | awk '{print $2}' | cut -d/ -f1
else
ip ro | grep default | cut -d" " -f 3
fi
fi
}

# --dns isn't available for: docker run --net=host
# sed -i /etc/resolf.conf fails:
# sed: cannot rename /etc/sedU9oCRy: Device or resource busy
# here comes the tempfile workaround ...
local_nameserver() {
cat>/etc/resolv.conf<<EOF
nameserver $(get_nameserver_addr)
search service.consul node.dc1.consul
EOF
}

wait_for_db() {
while : ; do
PGPASSWORD=bigdata psql -h $POSTGRES_DB -U ambari -c "select 1"
Expand Down Expand Up @@ -80,6 +57,9 @@ silent_security_setup() {
}

main() {
ln -s /docker_shared/etc/resolv.conf /tmp/resolv.conf
cp /tmp/resolv.conf /etc/resolv.conf

[[ "$USE_CONSUL_DNS" == "true" ]] && local_nameserver
reorder_dns_lookup
if [ ! -f "/var/ambari-init-executed" ]; then
Expand Down
2 changes: 1 addition & 1 deletion ambari-server/init/ambari-server.service
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ KillMode=process
GuessMainPID=no
RemainAfterExit=yes
Environment='AMBARI_JVM_ARGS=-XX:MaxPermSize=512m'
ExecStartPre=/opt/ambari-server/init-server.sh
ExecStartPre=/docker_shared/init-server.sh
ExecStart=/usr/sbin/ambari-server start
ExecStop=/usr/sbin/ambari-server stop
2 changes: 2 additions & 0 deletions build-docker-images.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cd ambari-agent/ && docker build -t hortonworks/ambari-agent:latest . && cd ..
cd ambari-server/ && docker build -t hortonworks/ambari-server:latest . && cd ..
8 changes: 8 additions & 0 deletions docker-kerberos/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM centos:6.6
MAINTAINER SequenceIQ

# EPEL
RUN rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

# kerberos
RUN yum install -y krb5-server krb5-libs krb5-auth-dialog krb5-workstation
Loading