Skip to content

Commit 3c9a5e7

Browse files
elekanuengineer
authored andcommitted
HDDS-1635. Maintain docker entrypoint and envtoconf inside ozone project (#894)
1 parent 2263ead commit 3c9a5e7

File tree

4 files changed

+417
-0
lines changed

4 files changed

+417
-0
lines changed

hadoop-ozone/dist/dev-support/bin/dist-layout-stitching

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ run cp "${ROOT}/hadoop-hdds/common/src/main/resources/network-topology-nodegroup
9696
run cp "${ROOT}/hadoop-common-project/hadoop-common/src/main/bin/hadoop" "bin/"
9797
run cp "${ROOT}/hadoop-common-project/hadoop-common/src/main/bin/hadoop.cmd" "bin/"
9898
run cp "${ROOT}/hadoop-ozone/common/src/main/bin/ozone" "bin/"
99+
run cp -r "${ROOT}/hadoop-ozone/dist/src/main/dockerbin" "bin/"
99100

100101
run cp "${ROOT}/hadoop-common-project/hadoop-common/src/main/bin/hadoop-config.sh" "libexec/"
101102
run cp "${ROOT}/hadoop-common-project/hadoop-common/src/main/bin/hadoop-config.cmd" "libexec/"
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
#!/usr/bin/env bash
2+
##
3+
# Licensed to the Apache Software Foundation (ASF) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The ASF licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
##
19+
set -e
20+
21+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
22+
23+
if [ -n "$SLEEP_SECONDS" ]; then
24+
echo "Sleeping for $SLEEP_SECONDS seconds"
25+
sleep "$SLEEP_SECONDS"
26+
fi
27+
28+
#
29+
# You can wait for an other TCP port with these settings.
30+
#
31+
# Example:
32+
#
33+
# export WAITFOR=localhost:9878
34+
#
35+
# With an optional parameter, you can also set the maximum
36+
# time of waiting with (in seconds) with WAITFOR_TIMEOUT.
37+
# (The default is 300 seconds / 5 minutes.)
38+
if [ -n "$WAITFOR" ]; then
39+
echo "Waiting for the service $WAITFOR"
40+
WAITFOR_HOST=$(printf "%s\n" "$WAITFOR"| cut -d : -f 1)
41+
WAITFOR_PORT=$(printf "%s\n" "$WAITFOR"| cut -d : -f 2)
42+
for i in $(seq "${WAITFOR_TIMEOUT:-300}" -1 0) ; do
43+
set +e
44+
nc -z "$WAITFOR_HOST" "$WAITFOR_PORT" > /dev/null 2>&1
45+
result=$?
46+
set -e
47+
if [ $result -eq 0 ] ; then
48+
break
49+
fi
50+
sleep 1
51+
done
52+
if [ "$i" -eq 0 ]; then
53+
echo "Waiting for service $WAITFOR is timed out." >&2
54+
exit 1
55+
f
56+
fi
57+
fi
58+
59+
if [ -n "$KERBEROS_ENABLED" ]; then
60+
echo "Setting up kerberos!!"
61+
KERBEROS_SERVER=${KERBEROS_SERVER:-krb5}
62+
ISSUER_SERVER=${ISSUER_SERVER:-$KERBEROS_SERVER\:8081}
63+
echo "KDC ISSUER_SERVER => $ISSUER_SERVER"
64+
65+
if [ -n "$SLEEP_SECONDS" ]; then
66+
echo "Sleeping for $(SLEEP_SECONDS) seconds"
67+
sleep "$SLEEP_SECONDS"
68+
fi
69+
70+
if [ -z "$KEYTAB_DIR" ]; then
71+
KEYTAB_DIR='/etc/security/keytabs'
72+
fi
73+
while true
74+
do
75+
set +e
76+
STATUS=$(curl -s -o /dev/null -w '%{http_code}' http://"$ISSUER_SERVER"/keytab/test/test)
77+
set -e
78+
if [ "$STATUS" -eq 200 ]; then
79+
echo "Got 200, KDC service ready!!"
80+
break
81+
else
82+
echo "Got $STATUS :( KDC service not ready yet..."
83+
fi
84+
sleep 5
85+
done
86+
87+
HOST_NAME=$(hostname -f)
88+
export HOST_NAME
89+
for NAME in ${KERBEROS_KEYTABS}; do
90+
echo "Download $NAME/$HOSTNAME@EXAMPLE.COM keytab file to $KEYTAB_DIR/$NAME.keytab"
91+
wget "http://$ISSUER_SERVER/keytab/$HOST_NAME/$NAME" -O "$KEYTAB_DIR/$NAME.keytab"
92+
klist -kt "$KEYTAB_DIR/$NAME.keytab"
93+
KERBEROS_ENABLED=true
94+
done
95+
96+
#Optional: let's try to adjust the krb5.conf
97+
sudo sed -i "s/krb5/$KERBEROS_SERVER/g" "/etc/krb5.conf" || true
98+
fi
99+
100+
CONF_DESTINATION_DIR="${HADOOP_CONF_DIR:-/opt/hadoop/etc/hadoop}"
101+
102+
#Try to copy the defaults
103+
set +e
104+
if [[ -d "/opt/ozone/etc/hadoop" ]]; then
105+
cp /opt/hadoop/etc/hadoop/* "$CONF_DESTINATION_DIR/" > /dev/null 2>&1
106+
elif [[ -d "/opt/hadoop/etc/hadoop" ]]; then
107+
cp /opt/hadoop/etc/hadoop/* "$CONF_DESTINATION_DIR/" > /dev/null 2>&1
108+
fi
109+
set -e
110+
111+
"$DIR"/envtoconf.py --destination "$CONF_DESTINATION_DIR"
112+
113+
if [ -n "$ENSURE_SCM_INITIALIZED" ]; then
114+
if [ ! -f "$ENSURE_SCM_INITIALIZED" ]; then
115+
# Improve om and scm start up options
116+
/opt/hadoop/bin/ozone scm --init || /opt/hadoop/bin/ozone scm -init
117+
fi
118+
fi
119+
120+
if [ -n "$ENSURE_OM_INITIALIZED" ]; then
121+
if [ ! -f "$ENSURE_OM_INITIALIZED" ]; then
122+
# Improve om and scm start up options
123+
/opt/hadoop/bin/ozone om --init || /opt/hadoop/bin/ozone om -createObjectStore
124+
fi
125+
fi
126+
127+
# Supports byteman script to instrument hadoop process with byteman script
128+
#
129+
#
130+
if [ -n "$BYTEMAN_SCRIPT" ] || [ -n "$BYTEMAN_SCRIPT_URL" ]; then
131+
132+
export PATH=$PATH:$BYTEMAN_DIR/bin
133+
134+
if [ -n "$BYTEMAN_SCRIPT_URL" ]; then
135+
wget "$BYTEMAN_SCRIPT_URL" -O /tmp/byteman.btm
136+
export BYTEMAN_SCRIPT=/tmp/byteman.btm
137+
fi
138+
139+
if [ ! -f "$BYTEMAN_SCRIPT" ]; then
140+
echo "ERROR: The defined $BYTEMAN_SCRIPT does not exist!!!"
141+
exit 255
142+
fi
143+
144+
AGENT_STRING="-javaagent:/opt/byteman.jar=script:$BYTEMAN_SCRIPT"
145+
export HADOOP_OPTS="$AGENT_STRING $HADOOP_OPTS"
146+
echo "Process is instrumented with adding $AGENT_STRING to HADOOP_OPTS"
147+
fi
148+
149+
exec "$@"
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
#!/usr/bin/python
2+
#
3+
# Licensed to the Apache Software Foundation (ASF) under one or more
4+
# contributor license agreements. See the NOTICE file distributed with
5+
# this work for additional information regarding copyright ownership.
6+
# The ASF licenses this file to You under the Apache License, Version 2.0
7+
# (the "License"); you may not use this file except in compliance with
8+
# the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
19+
"""convert environment variables to config"""
20+
21+
import os
22+
import re
23+
24+
import argparse
25+
26+
import sys
27+
import transformation
28+
29+
class Simple(object):
30+
"""Simple conversion"""
31+
def __init__(self, args):
32+
parser = argparse.ArgumentParser()
33+
parser.add_argument("--destination", help="Destination directory", required=True)
34+
self.args = parser.parse_args(args=args)
35+
# copy the default files to file.raw in destination directory
36+
37+
self.known_formats = ['xml', 'properties', 'yaml', 'yml', 'env', "sh", "cfg", 'conf']
38+
self.output_dir = self.args.destination
39+
self.excluded_envs = ['HADOOP_CONF_DIR']
40+
self.configurables = {}
41+
42+
def destination_file_path(self, name, extension):
43+
"""destination file path"""
44+
return os.path.join(self.output_dir, "{}.{}".format(name, extension))
45+
46+
def write_env_var(self, name, extension, key, value):
47+
"""Write environment variables"""
48+
with open(self.destination_file_path(name, extension) + ".raw", "a") as myfile:
49+
myfile.write("{}: {}\n".format(key, value))
50+
51+
def process_envs(self):
52+
"""Process environment variables"""
53+
for key in os.environ.keys():
54+
if key in self.excluded_envs:
55+
continue
56+
pattern = re.compile("[_\\.]")
57+
parts = pattern.split(key)
58+
extension = None
59+
name = parts[0].lower()
60+
if len(parts) > 1:
61+
extension = parts[1].lower()
62+
config_key = key[len(name) + len(extension) + 2:].strip()
63+
if extension and "!" in extension:
64+
splitted = extension.split("!")
65+
extension = splitted[0]
66+
fmt = splitted[1]
67+
config_key = key[len(name) + len(extension) + len(fmt) + 3:].strip()
68+
else:
69+
fmt = extension
70+
71+
if extension and extension in self.known_formats:
72+
if name not in self.configurables.keys():
73+
with open(self.destination_file_path(name, extension) + ".raw", "w") as myfile:
74+
myfile.write("")
75+
self.configurables[name] = (extension, fmt)
76+
self.write_env_var(name, extension, config_key, os.environ[key])
77+
else:
78+
for configurable_name in self.configurables:
79+
if key.lower().startswith(configurable_name.lower()):
80+
self.write_env_var(configurable_name,
81+
self.configurables[configurable_name],
82+
key[len(configurable_name) + 1:],
83+
os.environ[key])
84+
85+
def transform(self):
86+
"""transform"""
87+
for configurable_name in self.configurables:
88+
name = configurable_name
89+
extension, fmt = self.configurables[name]
90+
91+
destination_path = self.destination_file_path(name, extension)
92+
93+
with open(destination_path + ".raw", "r") as myfile:
94+
content = myfile.read()
95+
transformer_func = getattr(transformation, "to_" + fmt)
96+
content = transformer_func(content)
97+
with open(destination_path, "w") as myfile:
98+
myfile.write(content)
99+
100+
def main(self):
101+
"""main"""
102+
103+
# add the
104+
self.process_envs()
105+
106+
# copy file.ext.raw to file.ext in the destination directory, and
107+
# transform to the right format (eg. key: value ===> XML)
108+
self.transform()
109+
110+
111+
def main():
112+
"""main"""
113+
Simple(sys.argv[1:]).main()
114+
115+
116+
if __name__ == '__main__':
117+
Simple(sys.argv[1:]).main()

0 commit comments

Comments
 (0)