Skip to content

Commit 974dffe

Browse files
committed
Merge branch '300_release' into 'master'
300 release See merge request oceanbase/ob-deploy!267
2 parents a12282c + a1fa963 commit 974dffe

File tree

641 files changed

+23720
-34100
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

641 files changed

+23720
-34100
lines changed

Docker/Dockerfile

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
FROM registry.openanolis.cn/openanolis/anolisos:8.9
2+
ENV PATH="/opt/miniconda/bin:$PATH"
3+
ENV TZ=UTC-8
4+
ENV CRYPTOGRAPHY_OPENSSL_NO_LEGACY=1
5+
6+
ADD Docker/ob_build /usr/bin/
7+
ADD Docker/python-env-activate.sh /usr/bin/py-env-activate
8+
9+
RUN yum install -y wget \
10+
&& wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo \
11+
&& yum -y install libffi-devel bzip2-devel readline readline-devel jq which bison ncurses-devel libaio autoconf automake libtool perl-CPAN gettext-devel perl-devel openssl-devel zlib-devel curl-devel xz-devel \
12+
expat-devel asciidoc xmlto rpm-build cmake make gcc gcc-c++ python2-devel python3-devel sudo git mysql-devel \
13+
&& yum clean all
14+
15+
RUN wget https://repo.anaconda.com/miniconda/Miniconda2-py27_4.8.3-Linux-x86_64.sh --no-check-certificate\
16+
&& bash Miniconda2-py27_4.8.3-Linux-x86_64.sh -p /opt/miniconda -b \
17+
&& rm -rf Miniconda2-py27_4.8.3-Linux-x86_64.sh \
18+
&& conda clean --all -y
19+
20+
COPY requirements3.txt /workspaces/obd/requirements3.txt
21+
COPY service/service-requirements.txt workspaces/obd/service-requirements.txt
22+
23+
RUN conda create -n py27 -y python=2.7 \
24+
&& source /opt/miniconda/bin/activate base \
25+
&& pip config set global.index-url https://mirrors.aliyun.com/pypi/simple \
26+
&& pip config set global.trusted-host mirrors.aliyun.com \
27+
&& pip install pyinstaller==3.6 \
28+
&& rm -rf ~/.cache/pip \
29+
&& conda clean -a -y
30+
31+
RUN conda create -n py38 -y python=3.8 \
32+
&& source /opt/miniconda/bin/activate py38 \
33+
&& pip config set global.index-url https://mirrors.aliyun.com/pypi/simple \
34+
&& pip config set global.trusted-host mirrors.aliyun.com \
35+
&& pip install -r /workspaces/obd/requirements3.txt \
36+
&& pip install -r /workspaces/obd/service-requirements.txt \
37+
&& pip install pyinstaller==3.6 \
38+
&& pip cache purge \
39+
&& echo "source /opt/miniconda/bin/activate py38" >> ~/.bashrc \
40+
&& /opt/miniconda/bin/conda clean -a -y \
41+
&& rm -rf /workspaces/obd
42+
43+
# install nodejs and yarn
44+
RUN wget https://rpm.nodesource.com/setup_16.x \
45+
&& touch /etc/redhat-release \
46+
&& bash setup_16.x \
47+
&& rm -f /etc/redhat-release \
48+
&& yum install -y nodejs \
49+
&& yum clean all
50+
51+
RUN npm install -g yarn \
52+
&& yarn config delete registry --global \
53+
&& yarn config set registry https://registry.npmmirror.com/ --global \
54+
&& npm cache clean --force

Docker/ob_build

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/bin/bash
2+
set -x
3+
set -e
4+
5+
if [ $# -lt 4 ]; then
6+
echo "no enough parameters. Please provide project_name, version and release."
7+
exit 1
8+
fi
9+
10+
# Get system release
11+
os_release=$(grep -Po '(?<=^ID=")[^"]*' /etc/os-release || true)
12+
13+
if [ -z "$os_release" ]; then
14+
os_release=$(grep -Po '^ID=\K[^ ]+' /etc/os-release)
15+
fi
16+
17+
set +e
18+
source /etc/profile
19+
set -e
20+
21+
project_dir=$1
22+
project_name=$2
23+
version=$3
24+
release=$4
25+
rpm_work_dir=${5:-rpm}
26+
ob_build_script=${project_name}-build.sh
27+
ob_build_spec=${project_name}.spec
28+
ob_build_deps=${project_name}.deps
29+
cur_dir=`pwd`
30+
echo "cur dir: $cur_dir"
31+
# check rpm work dir
32+
if [ ! -d "${cur_dir}/${rpm_work_dir}" ]; then
33+
echo "rpm work dir (${rpm_work_dir}) missing! Please create ${rpm_work_dir} in source code dir and place the packaging related files in the ${rpm_work_dir} dir."
34+
exit 1
35+
fi
36+
37+
# trigger building
38+
echo "trigger building, current dir: "
39+
pwd
40+
cd $rpm_work_dir
41+
ABS_PATH=`pwd`
42+
43+
if [[ x"$os_release" == x"alios" && x"$AONE_COMPATIBLE_AUTO_DEP_CREATE" == x"on" ]]; then
44+
if [ -e "$ob_build_deps" ]; then
45+
echo "execute dep_create for alios"
46+
dep_create $ob_build_deps
47+
echo "execute sw for alios"
48+
sw
49+
fi
50+
fi
51+
52+
if [ -e "$ob_build_script" ]; then
53+
bash $ob_build_script $project_dir $project_name $version $release
54+
elif [ -e "$ob_build_spec" ]; then
55+
if [[ x"$os_release" == x"alios" ]]; then
56+
rpm_create $ob_build_spec -v $version -r $release
57+
else
58+
TOP_DIR=".rpm_create"
59+
RPM_MACROS=$HOME/.rpmmacros
60+
if [ -e $RPM_MACROS ]; then
61+
mv -f $RPM_MACROS $RPM_MACROS.bak
62+
fi
63+
64+
# prepare rpm build dirs
65+
mkdir -p $TOP_DIR/BUILD
66+
mkdir -p $TOP_DIR/RPMS
67+
mkdir -p $TOP_DIR/SRPMS
68+
69+
echo "%_topdir $ABS_PATH/$TOP_DIR" > $RPM_MACROS
70+
rpmbuild -bb $ob_build_spec
71+
find $TOP_DIR/ -name "*.rpm" -exec mv {} . 2>/dev/null \;
72+
fi
73+
else
74+
echo "packaging files missing! Please provide $ob_build_script or $ob_build_spec"
75+
exit 1
76+
fi

Docker/python-env-activate.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
eval "$(conda shell.bash hook)"
2+
if [[ -z $1 ]]; then
3+
echo "Please input proper python env"
4+
exit 1
5+
fi
6+
conda activate $1

_cmd.py

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import time
2727
import textwrap
2828
import json
29+
import glob
30+
import datetime
2931
from uuid import uuid1 as uuid, UUID
3032
from optparse import OptionParser, BadOptionError, Option, IndentedHelpFormatter
3133

@@ -39,8 +41,8 @@
3941
from ssh import LocalClient
4042
from const import (
4143
CONST_OBD_HOME,
42-
VERSION, REVISION, BUILD_BRANCH, BUILD_TIME, FORBIDDEN_VARS,
43-
COMP_OCEANBASE_DIAGNOSTIC_TOOL, PKG_RPM_FILE,PKG_REPO_FILE
44+
VERSION, REVISION, BUILD_BRANCH, BUILD_TIME, FORBIDDEN_VARS, COMP_OB_CE, COMP_ODP_CE, COMP_ODP, COMP_OCP_SERVER_CE,
45+
COMP_OCEANBASE_DIAGNOSTIC_TOOL, PKG_RPM_FILE,PKG_REPO_FILE, BUILD_PLUGIN_LIST
4446
)
4547

4648

@@ -197,12 +199,50 @@ def init_home(self):
197199
if not COMMAND_ENV.get(ENV.ENV_OBD_ID):
198200
COMMAND_ENV.set(ENV.ENV_OBD_ID, uuid())
199201
if VERSION != version:
200-
for part in ['plugins', 'config_parser', 'optimize', 'mirror/remote']:
202+
for part in ['workflows', 'plugins', 'config_parser', 'optimize', 'mirror/remote']:
201203
obd_part_dir = os.path.join(self.OBD_PATH, part)
204+
root_part_path = os.path.join(self.OBD_INSTALL_PATH, part)
202205
if DirectoryUtil.mkdir(self.OBD_PATH):
203-
root_part_path = os.path.join(self.OBD_INSTALL_PATH, part)
204-
if os.path.exists(root_part_path):
205-
DirectoryUtil.copy(root_part_path, obd_part_dir, ROOT_IO)
206+
if part != 'mirror/remote':
207+
if os.path.exists(obd_part_dir):
208+
backup_path = os.path.join(self.OBD_PATH, '.backup_plugin', VERSION + '_' + REVISION, part)
209+
if DirectoryUtil.mkdir(backup_path):
210+
DirectoryUtil.copy(obd_part_dir, backup_path, ROOT_IO)
211+
os.chdir(obd_part_dir)
212+
if part != 'config_parser':
213+
for file in glob.glob('*/*/*'):
214+
if COMP_OB_CE in file or COMP_OCP_SERVER_CE in file or (COMP_ODP_CE in file and 'file_map.yaml' in file):
215+
continue
216+
if file not in BUILD_PLUGIN_LIST:
217+
FileUtil.rm(file)
218+
else:
219+
for file in glob.glob('*/*'):
220+
if file not in BUILD_PLUGIN_LIST:
221+
FileUtil.rm(file)
222+
223+
if os.path.exists(root_part_path):
224+
os.chdir(root_part_path)
225+
if part != 'config_parser':
226+
for file in glob.glob('*/*/*'):
227+
if COMP_OB_CE in file or COMP_OCP_SERVER_CE in file or (COMP_ODP_CE in file and 'file_map.yaml' in file):
228+
continue
229+
if file not in BUILD_PLUGIN_LIST:
230+
if file.replace(COMP_ODP_CE, COMP_ODP).replace('3.2.1', '3.1.0') in BUILD_PLUGIN_LIST:
231+
continue
232+
FileUtil.rm(file)
233+
else:
234+
for file in glob.glob('*/*'):
235+
if file not in BUILD_PLUGIN_LIST:
236+
FileUtil.rm(file)
237+
if os.path.exists(root_part_path):
238+
DirectoryUtil.copy(root_part_path, obd_part_dir, ROOT_IO)
239+
240+
backup_path = os.path.join(self.OBD_PATH, '.backup_plugin')
241+
if os.path.exists(backup_path):
242+
dir_list = [os.path.join(backup_path, f) for f in os.listdir(backup_path)]
243+
sorted_dir_list = sorted(dir_list, key=lambda dir: datetime.datetime.fromtimestamp(os.path.getmtime(dir)))
244+
for dir in sorted_dir_list[12:]:
245+
DirectoryUtil.rm(dir)
206246
version_fobj.seek(0)
207247
version_fobj.truncate()
208248
version_fobj.write(VERSION)
@@ -1208,7 +1248,8 @@ def init(self, cmd, args):
12081248

12091249
def _do_command(self, obd):
12101250
if len(self.cmds) == 2:
1211-
return obd.failover_decouple_tenant(self.cmds[0], self.cmds[1], 'failover')
1251+
self.cmds.append('failover')
1252+
return obd.failover_decouple_tenant(self.cmds[0], self.cmds[1], self.cmds[2])
12121253
else:
12131254
return self._show_help()
12141255

@@ -1226,7 +1267,8 @@ def init(self, cmd, args):
12261267

12271268
def _do_command(self, obd):
12281269
if len(self.cmds) == 2:
1229-
return obd.failover_decouple_tenant(self.cmds[0], self.cmds[1], 'decouple')
1270+
self.cmds.append('decouple')
1271+
return obd.failover_decouple_tenant(self.cmds[0], self.cmds[1], self.cmds[2])
12301272
else:
12311273
return self._show_help()
12321274

@@ -1652,7 +1694,7 @@ def do_command(self):
16521694
return super(UpdateCommand, self).do_command()
16531695

16541696
def _do_command(self, obd):
1655-
return obd.update_obd(VERSION, self.OBD_INSTALL_PRE)
1697+
return obd.update_obd(VERSION, self.OBD_INSTALL_PRE, self.OBD_INSTALL_PATH)
16561698

16571699

16581700
class DisplayTraceCommand(ObdCommand):

_deploy.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,6 +1096,27 @@ def enable_mem_mode(self):
10961096
def disable_mem_mode(self):
10971097
self._mem_mode = False
10981098

1099+
@property
1100+
def sorted_components(self):
1101+
available_depends = list(self.components.keys())
1102+
unsort_components = available_depends
1103+
sorted_components = []
1104+
while unsort_components:
1105+
components = unsort_components
1106+
unsort_components = []
1107+
for component in components:
1108+
cluster_config = self.components[component]
1109+
for component_name in cluster_config.depends:
1110+
if component_name not in available_depends:
1111+
continue
1112+
if component_name not in sorted_components:
1113+
unsort_components.append(component)
1114+
break
1115+
else:
1116+
sorted_components.append(component)
1117+
return sorted_components
1118+
1119+
10991120
@property
11001121
def user(self):
11011122
return self._user

_plugin.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ def __init__(self, spacename):
7777
self._variables = {}
7878
self._return = {}
7979

80+
@property
81+
def all_plugin_ret(self):
82+
return self._return
83+
8084
@property
8185
def variables(self):
8286
return self._variables
@@ -198,9 +202,6 @@ def __init__(self, stdio):
198202
self.stdio = getattr(stdio, 'sub_io', lambda: None)()
199203
self._func = {}
200204

201-
def __del__(self):
202-
self.before_close()
203-
204205
def _temp_function(self, *arg, **kwargs):
205206
pass
206207

@@ -262,6 +263,9 @@ def before_do(
262263

263264
def after_do(self, stdio, *arg, **kwargs):
264265
self._export(stdio)
266+
if self.context.stdio.sync_obj:
267+
self.context.stdio.warn("%s has animation not been closed" % self)
268+
del self.context.stdio
265269
self.context = None
266270

267271

@@ -385,6 +389,7 @@ class Null(object):
385389
def __init__(self):
386390
pass
387391

392+
388393
class ParamPlugin(Plugin):
389394

390395

@@ -807,13 +812,14 @@ def requirement_list(self, package_info):
807812
class ComponentPluginLoader(object):
808813

809814
PLUGIN_TYPE = None
815+
MODULE_NAME = __name__
810816

811817
def __init__(self, home_path, plugin_type=PLUGIN_TYPE, dev_mode=False, stdio=None):
812818
if plugin_type:
813819
self.PLUGIN_TYPE = plugin_type
814820
if not self.PLUGIN_TYPE:
815821
raise NotImplementedError
816-
self.plguin_cls = getattr(sys.modules[__name__], self.PLUGIN_TYPE.value, False)
822+
self.plguin_cls = getattr(sys.modules[self.MODULE_NAME], self.PLUGIN_TYPE.value, False)
817823
if not self.plguin_cls:
818824
raise ImportError(self.PLUGIN_TYPE.value)
819825
self.dev_mode = dev_mode

0 commit comments

Comments
 (0)