Skip to content

Commit

Permalink
V2.8.0 (#194)
Browse files Browse the repository at this point in the history
  • Loading branch information
frf12 authored Apr 19, 2024
1 parent 16f14f5 commit be46c65
Show file tree
Hide file tree
Showing 28 changed files with 5,959 additions and 193 deletions.
26 changes: 26 additions & 0 deletions _cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ def _process_short_opts(self, rargs, values):
else:
raise e

def print_usage(self, file=None):
print(self.format_help(OptionHelpFormatter()), file=file)

class BaseCommand(object):

Expand Down Expand Up @@ -721,6 +723,29 @@ def _do_command(self, obd):
return self._show_help()


class ClusterTakeoverCommand(ClusterMirrorCommand):

def __init__(self):
super(ClusterTakeoverCommand, self).__init__('takeover', 'Takeover oceanbase cluster')
self.parser.remove_option('-h')
self.parser.add_option('--help', action='callback', callback=self._show_help, help='Show help and exit.')
self.parser.add_option('-h', '--host', type='string', help="db connection host, default: 127.0.0.1", default='127.0.0.1')
self.parser.add_option('-P', '--mysql-port', type='int', help="mysql port, default: 2881", default=2881)
self.parser.add_option('-p', '--root-password', type='string', help="password of root@sys user, default: ''", default='')
self.parser.add_option('--ssh-user', type='string', help="ssh user, default: current user")
self.parser.add_option('--ssh-password', type='string', help="ssh password, default: ''", default='')
self.parser.add_option('--ssh-port', type='int', help="ssh port, default: 22")
self.parser.add_option('-t', '--ssh-timeout', type='int', help="ssh connection timeout (second), default: 30")
self.parser.add_option('--ssh-key-file', type='string', help="ssh key file")


def _do_command(self, obd):
if self.cmds:
return obd.takeover(self.cmds[0])
else:
return self._show_help()


class DemoCommand(ClusterMirrorCommand):

def __init__(self):
Expand Down Expand Up @@ -1248,6 +1273,7 @@ def __init__(self):
self.register_command(ClusterTenantCommand())
self.register_command(ClusterScaleoutCommand())
self.register_command(ClusterComponentMajorCommand())
self.register_command(ClusterTakeoverCommand())


class TestMirrorCommand(ObdCommand):
Expand Down
8 changes: 4 additions & 4 deletions _errno.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ class InitDirFailedErrorMessage(object):
EC_OCP_SERVER_JAVA_VERSION_ERROR = OBDErrorCodeTemplate(4359, "{server}: ocp-server need java with version {version} and update release must greater than 161")
EC_OCP_SERVER_JAVA_NOT_FOUND = OBDErrorCodeTemplate(4359, "{server}: failed to query java version, you may not have java installed")
EC_OCP_SERVER_CLOCKDIFF_NOT_EXISTS = OBDErrorCodeTemplate(4360, "{server}: clockdiff not exists. Please install clockdiff manually")
EC_OCP_SERVER_TENANT_ALREADY_EXISTS = OBDErrorCodeTemplate(4361, "tenant({tenant_name}) alread exist")
EC_OCP_SERVER_TENANT_ALREADY_EXISTS = OBDErrorCodeTemplate(4361, "tenant({tenant_name}) already exist")
EC_OCP_SERVER_DIR_ACCESS_FORBIDE = OBDErrorCodeTemplate(4362, "{server}:{path} access failed for current user, {server}:{cur_path} access succeed, please run `chmod -R 755 {cur_path}` ")
EC_OCP_SERVER_DEPENDS_COMP_VERSION = OBDErrorCodeTemplate(4363, 'OCP server {ocp_server_version} needs to use {comp} with version {comp_version} or above')
EC_OCP_SERVER_NOT_ENOUGH_MEMORY_AVAILABLE = OBDErrorCodeTemplate(4364, '({ip}) not enough memory. (Available: {available}, Need: {need})')
Expand Down Expand Up @@ -247,7 +247,7 @@ class InitDirFailedErrorMessage(object):
EC_OBDIAG_NOT_FOUND = OBDErrorCodeTemplate(6000, 'Failed to executable obdiag command, you may not have obdiag installed')
EC_OBDIAG_NOT_CONTAIN_DEPEND_COMPONENT = OBDErrorCodeTemplate(6001, 'obdiag must contain depend components {components}')
EC_OBDIAG_OPTIONS_FORMAT_ERROR = OBDErrorCodeTemplate(6002, 'obdiag options {option} format error, please check the value : {value}')
EC_OBDIAG_FUCYION_FAILED = OBDErrorCodeTemplate(6003, 'Failed to excute obdiag function {fuction}')
EC_OBDIAG_FUCYION_FAILED = OBDErrorCodeTemplate(6003, 'Failed to execute obdiag function {fuction}')

# Unexpected exceptions code
EC_UNEXPECTED_EXCEPTION = OBDErrorCodeTemplate(9999, 'Unexpected exception: need to be posted on "https://ask.oceanbase.com", and we will help you resolve them.')
Expand Down Expand Up @@ -276,15 +276,15 @@ class InitDirFailedErrorMessage(object):
SUG_CONNECT_EXCEPT = OBDErrorSuggestionTemplate('Connection exception or unsupported OS. Please retry or contact us.')
SUG_UNSUPPORT_OS = OBDErrorSuggestionTemplate('It may be an unsupported OS, please contact us for assistance')
SUG_OBSERVER_SYS_MEM_TOO_LARGE = OBDErrorSuggestionTemplate('`system_memory` should be less than {factor} * memory_limit/memory_limit_percentage.', fix_eval=[FixEval(FixEval.DEL, 'system_memory')])
SUG_OBSERVER_NOT_ENOUGH_MEMORY_ALAILABLE = OBDErrorSuggestionTemplate('Please execute `echo 1 > /proc/sys/vm/drop_caches` as root in {ip} to rlease cached.')
SUG_OBSERVER_NOT_ENOUGH_MEMORY_ALAILABLE = OBDErrorSuggestionTemplate('Please execute `echo 1 > /proc/sys/vm/drop_caches` as root in {ip} to release cached.')
SUG_OBSERVER_REDUCE_MEM = OBDErrorSuggestionTemplate('Please reduce the `memory_limit` or `memory_limit_percentage`', fix_eval=[FixEval(FixEval.DEL, 'memory_limit'), FixEval(FixEval.DEL, 'system_memory'), FixEval(FixEval.DEL, 'memory_limit_percentage')])
SUG_OBSERVER_SAME_DISK = OBDErrorSuggestionTemplate('Configure `redo_dir` and `data_dir` to different disks')
SUG_OBSERVER_NOT_ENOUGH_DISK = OBDErrorSuggestionTemplate('Please reduce the `datafile_size` or `datafile_disk_percentage`', fix_eval=[FixEval(FixEval.DEL, 'datafile_size'), FixEval(FixEval.DEL, 'datafile_disk_percentage')])
SUG_OBSERVER_REDUCE_REDO = OBDErrorSuggestionTemplate('Please reduce the `log_disk_size` or `log_disk_percentage`', fix_eval=[FixEval(FixEval.DEL, 'log_disk_size'), FixEval(FixEval.DEL, 'log_disk_percentage')])
SUG_OBSERVER_NOT_ENOUGH_DISK_4_CLOG = OBDErrorSuggestionTemplate('Please increase the `clog_disk_utilization_threshold` and `clog_disk_usage_limit_percentage`', fix_eval=[FixEval(FixEval.DEL, 'clog_disk_utilization_threshold'), FixEval(FixEval.DEL, 'clog_disk_usage_limit_percentage')])
SUG_OBSERVER_TIME_OUT_OF_SYNC = OBDErrorSuggestionTemplate('Please enable clock synchronization service')
SUG_OCP_EXPRESS_INSTALL_JAVA_WITH_VERSION = OBDErrorSuggestionTemplate('Please install java with version {version}. If java is already installed, please set `java_bin` to the expected java binary path')
SUG_OCP_EXPRESS_NOT_ENOUGH_MEMORY_AVALIABLE = OBDErrorSuggestionTemplate('Please execute `echo 1 > /proc/sys/vm/drop_caches` as root in {ip} to rlease cached.')
SUG_OCP_EXPRESS_NOT_ENOUGH_MEMORY_AVALIABLE = OBDErrorSuggestionTemplate('Please execute `echo 1 > /proc/sys/vm/drop_caches` as root in {ip} to release cached.')
SUG_OCP_EXPRESS_REDUCE_MEM = OBDErrorSuggestionTemplate('Please reduce the `memory_size`', fix_eval=[FixEval(FixEval.DEL, 'memory_size')])
SUG_OCP_EXPRESS_REDUCE_DISK = OBDErrorSuggestionTemplate('Please reduce the `logging_file_total_size_cap`', fix_eval=[FixEval(FixEval.DEL, 'logging_file_total_size_cap')])
SUG_OCP_EXPRESS_COMP_VERSION = OBDErrorSuggestionTemplate('Please use {comp} with version {version} or above')
Expand Down
103 changes: 56 additions & 47 deletions _mirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,38 +48,55 @@


_ARCH = getArchList()
_RELEASE = None
SUP_MAP = {
'ubuntu': {'16': 7},
'debian': {'9': 7},
'opensuse-leap': {'15': 7},
'sles': {'15.2': 7},
'fedora': {'33': 7},
'uos': {'20': 8},
'anolis': {'23': 7},
'openEuler': {'22.03': 7},
'kylin': {'V10': 8},
'alinux': {'2': 7, '3': 8}
}
_SERVER_VARS = {
'basearch': getBaseArch(),
}
with FileUtil.open('/etc/os-release') as f:
for line in f.readlines():
line = line.strip()
if not line:
continue
try:
k, v = line.split('=', 1)
_SERVER_VARS[k] = v.strip('"').strip("'")
except:
pass
if 'VERSION_ID' in _SERVER_VARS:
m = re.match('\d+', _SERVER_VARS['VERSION_ID'])
if m:
_RELEASE = m.group(0)
_SERVER_VARS['releasever'] = _RELEASE

_NO_LSE = 'amd64' in _ARCH and LocalClient.execute_command("grep atomics /proc/cpuinfo").stdout.strip() == ''

def get_use_centos_release(stdio=None):
_RELEASE = None
SUP_MAP = {
'ubuntu': {'16': 7},
'debian': {'9': 7},
'opensuse-leap': {'15': 7},
'sles': {'15.2': 7},
'fedora': {'33': 7},
'uos': {'20': 8},
'anolis': {'23': 7},
'openEuler': {'22.03': 7},
'kylin': {'V10': 8},
'alinux': {'2': 7, '3': 8}
}
_SERVER_VARS = {
'basearch': getBaseArch(),
}
with FileUtil.open('/etc/os-release') as f:
for line in f.readlines():
line = line.strip()
if not line:
continue
try:
k, v = line.split('=', 1)
_SERVER_VARS[k] = v.strip('"').strip("'")
except:
pass
if 'VERSION_ID' in _SERVER_VARS:
m = re.match('\d+', _SERVER_VARS['VERSION_ID'])
if m:
_RELEASE = m.group(0)
_SERVER_VARS['releasever'] = _RELEASE

server_vars = deepcopy(_SERVER_VARS)
linux_id = server_vars.get('ID')
if linux_id in SUP_MAP:
version_id = server_vars.get('VERSION_ID', '')
sorted_versions = sorted([Version(key) for key in SUP_MAP[linux_id]], reverse=True)
for version in sorted_versions:
if Version(version_id) >= version:
server_vars['releasever'] = SUP_MAP[linux_id][str(version)]
break
else:
server_vars['releasever'] = SUP_MAP[linux_id][str(version)]
stdio and getattr(stdio, 'warn', print)('Use centos %s remote mirror repository for %s %s' % (server_vars['releasever'], linux_id, server_vars.get('VERSION_ID')))
use_release = server_vars.get('releasever')
return use_release, server_vars


class MirrorRepositoryType(Enum):
Expand Down Expand Up @@ -567,10 +584,14 @@ def match_score(self, info, name, arch, version=None, min_version=None, max_vers
if max_version and Version(info_version) > Version(max_version):
return [0 ,]
if release and info.release != release:
raise Exception ('break')
return [0 ,]

c = [len(name) / len(info.name), info]
if _NO_LSE:
lse_score = 'nonlse' in info.release
else:
lse_score = True

c = [len(name) / len(info.name), lse_score, info]
return c

@staticmethod
Expand Down Expand Up @@ -979,22 +1000,10 @@ def _get_section(self, section_name):
def get_remote_mirrors(self, is_enabled=True):
self._lock()
mirrors = []
server_vars = deepcopy(_SERVER_VARS)
linux_id = server_vars.get('ID')
if linux_id in SUP_MAP:
version_id = server_vars.get('VERSION_ID', '')
sorted_versions = sorted([Version(key) for key in SUP_MAP[linux_id]], reverse=True)
for version in sorted_versions:
if Version(version_id) >= version:
server_vars['releasever'] = SUP_MAP[linux_id][str(version)]
break
else:
server_vars['releasever'] = SUP_MAP[linux_id][str(version)]
self.stdio and getattr(self.stdio, 'warn', print)('Use centos %s remote mirror repository for %s %s' % (
server_vars['releasever'], linux_id, server_vars.get('VERSION_ID')))
for mirror_section in self._get_sections():
if is_enabled is not None and is_enabled != mirror_section.is_enabled:
continue
_, server_vars = get_use_centos_release(self.stdio)
mirrors.append(mirror_section.get_mirror(server_vars, self.stdio))
return mirrors

Expand Down
7 changes: 7 additions & 0 deletions const.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,18 @@
COMP_OCEANBASE_DIAGNOSTIC_TOOL = "oceanbase-diagnostic-tool"
COMP_OBDIAG = "obdiag"
COMP_JRE = 'openjdk-jre'

# ocp
COMP_OCP_EXPRESS = 'ocp-express'
COMP_OCP_SERVER = 'ocp-server'
COMP_OCP_SERVER_CE = 'ocp-server-ce'
COMPS_OCP = [COMP_OCP_SERVER, COMP_OCP_SERVER_CE]

# ob
COMP_OB = "oceanbase"
COMP_OB_CE = "oceanbase-ce"
COMPS_OB = [COMP_OB, COMP_OB_CE]

# service docs url
DISABLE_SWAGGER = '<DISABLE_SWAGGER>'

Expand Down
Loading

0 comments on commit be46c65

Please sign in to comment.