Skip to content

Commit 2e94a33

Browse files
committed
Merge branch 'fix_bug_start_stop_api' into 'master'
Fix bug start stop api See merge request oceanbase/ob-deploy!478
2 parents e89e482 + 7d13a70 commit 2e94a33

3 files changed

Lines changed: 76 additions & 23 deletions

File tree

service/api/v1/deployments.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,18 @@ async def start(name: str, background_tasks: BackgroundTasks):
123123
return response_utils.new_internal_server_error_exception(ex)
124124
return response_utils.new_ok_response("")
125125

126+
@router.get("/deployments/{name}/start",
127+
response_model=OBResponse[TaskInfo],
128+
description='query start status',
129+
operation_id='queryStartStatus',
130+
tags=['Deployments'])
131+
async def get_start_status(name: str = Path(description='deployment name')):
132+
handler = handler_utils.new_deployment_handler()
133+
task_info = handler.get_start_task_info(name)
134+
if task_info is None:
135+
return response_utils.new_not_found_exception("task {0} not found".format(name))
136+
return response_utils.new_ok_response(task_info)
137+
126138
@router.get("/deployments/{name}/start/log",
127139
response_model=OBResponse[InstallLog],
128140
description='query start log',
@@ -154,6 +166,18 @@ async def stop(name: str, background_tasks: BackgroundTasks):
154166
return response_utils.new_internal_server_error_exception(ex)
155167
return response_utils.new_ok_response("")
156168

169+
@router.get("/deployments/{name}/stop",
170+
response_model=OBResponse[TaskInfo],
171+
description='query stop status',
172+
operation_id='queryStopStatus',
173+
tags=['Deployments'])
174+
async def get_start_status(name: str = Path(description='deployment name')):
175+
handler = handler_utils.new_deployment_handler()
176+
task_info = handler.get_stop_task_info(name)
177+
if task_info is None:
178+
return response_utils.new_not_found_exception("task {0} not found".format(name))
179+
return response_utils.new_ok_response(task_info)
180+
157181
@router.get("/deployments/{name}/stop/log",
158182
response_model=OBResponse[InstallLog],
159183
description='query stop log',

service/common/const.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
DESTROY_PLUGIN = "destroy"
4949
INIT_PLUGINS = ("init",)
5050
START_PLUGINS = ("start_check_pre", "start", "connect", "health_check", "display")
51+
STOP_PLUGINS = ("stop",)
5152
DEL_COMPONENT_PLUGINS = ("stop", "destroy")
5253
CHANGED_COMPONENTS = ('obproxy-ce', 'obagent', 'ob-configserver', 'prometheus', 'grafana')
5354
UPGRADE_PLUGINS = ("upgrade")
@@ -64,3 +65,6 @@
6465

6566
GRACEFUL_TIMEOUT = 5
6667

68+
TASK_TYPE_INSTALL = 'install'
69+
TASK_TYPE_START = 'start'
70+
TASK_TYPE_STOP = 'stop'

service/handler/deployment_handler.py

Lines changed: 48 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ def _do_start(self, name):
573573
LocalClient.execute_command_background("nohup obd telemetry post %s --data='%s' > /dev/null &" % (name, json.dumps(data)))
574574

575575
def get_start_task_info(self, name):
576-
return self.get_task_info_log(name, "start")
576+
return self.get_task_info_log_by_type(name, "start")
577577

578578
@serial("stop")
579579
def stop(self, name, background_tasks):
@@ -585,7 +585,7 @@ def stop(self, name, background_tasks):
585585
background_tasks.add_task(self._do_stop, name)
586586

587587
def get_stop_task_info(self, name):
588-
return self.get_task_info_log(name, "stop")
588+
return self.get_task_info_log_by_type(name, "stop")
589589

590590
@auto_register("stop")
591591
def _do_stop(self, name):
@@ -603,43 +603,68 @@ def _do_stop(self, name):
603603
data[component] = _.get_variable('run_result')
604604
LocalClient.execute_command_background("nohup obd telemetry post %s --data='%s' > /dev/null &" % (name, json.dumps(data)))
605605

606-
def get_task_info_log(self, name, task_type):
606+
def get_task_info_log_by_type(self, name, task_type):
607607
task_info = task.get_task_manager().get_task_info(name, task_type=task_type)
608608
if task_info is None:
609609
raise Exception("task {0} not found".format(name))
610610
deploy = self.get_deploy(name)
611611
components = deploy.deploy_config.components
612-
total_count = (len(const.START_PLUGINS) + len(const.INIT_PLUGINS)) * len(components)
612+
total_count = 0
613+
if task_type == const.TASK_TYPE_INSTALL:
614+
total_count = (len(const.START_PLUGINS) + len(const.INIT_PLUGINS)) * len(components)
615+
elif task_type == const.TASK_TYPE_START:
616+
total_count = len(const.START_PLUGINS) * len(components)
617+
elif task_type == const.TASK_TYPE_STOP:
618+
total_count = len(const.STOP_PLUGINS) * len(components)
613619
finished_count = 0
614620
current = ""
615621
task_result = TaskResult.RUNNING
616622
info_dict = dict()
617623

618624
for component in components:
619-
info_dict[component] = ComponentInfo(component=component, status=TaskStatus.PENDING,
620-
result=TaskResult.RUNNING)
621-
if component in self.obd.namespaces:
622-
for plugin in const.INIT_PLUGINS:
625+
info_dict[component] = ComponentInfo(component=component, status=TaskStatus.PENDING,
626+
result=TaskResult.RUNNING)
627+
628+
if task_type == const.TASK_TYPE_INSTALL:
629+
for component in components:
630+
if component in self.obd.namespaces:
631+
for plugin in const.INIT_PLUGINS:
632+
if self.obd.namespaces[component].get_return(plugin) is not None:
633+
info_dict[component].status = TaskStatus.RUNNING
634+
finished_count += 1
635+
current = "{0}: {1} finished".format(component, plugin)
636+
if not self.obd.namespaces[component].get_return(plugin):
637+
info_dict[component].result = TaskResult.FAILED
638+
639+
if task_type == const.TASK_TYPE_INSTALL or task_type == const.TASK_TYPE_START:
640+
for component in components:
641+
for plugin in const.START_PLUGINS:
642+
if component not in self.obd.namespaces:
643+
break
623644
if self.obd.namespaces[component].get_return(plugin) is not None:
624645
info_dict[component].status = TaskStatus.RUNNING
625646
finished_count += 1
626647
current = "{0}: {1} finished".format(component, plugin)
627648
if not self.obd.namespaces[component].get_return(plugin):
628649
info_dict[component].result = TaskResult.FAILED
629-
630-
for component in components:
631-
for plugin in const.START_PLUGINS:
632-
if component not in self.obd.namespaces:
633-
break
634-
if self.obd.namespaces[component].get_return(plugin) is not None:
635-
info_dict[component].status = TaskStatus.RUNNING
636-
finished_count += 1
637-
current = "{0}: {1} finished".format(component, plugin)
638-
if not self.obd.namespaces[component].get_return(plugin):
639-
info_dict[component].result = TaskResult.FAILED
640-
else:
641-
if plugin == const.START_PLUGINS[-1]:
642-
info_dict[component].result = TaskResult.SUCCESSFUL
650+
else:
651+
if plugin == const.START_PLUGINS[-1]:
652+
info_dict[component].result = TaskResult.SUCCESSFUL
653+
654+
if task_type == const.TASK_TYPE_STOP:
655+
for component in components:
656+
for plugin in const.STOP_PLUGINS:
657+
if component not in self.obd.namespaces:
658+
break
659+
if self.obd.namespaces[component].get_return(plugin) is not None:
660+
info_dict[component].status = TaskStatus.RUNNING
661+
finished_count += 1
662+
current = "{0}: {1} finished".format(component, plugin)
663+
if not self.obd.namespaces[component].get_return(plugin):
664+
info_dict[component].result = TaskResult.FAILED
665+
else:
666+
if plugin == const.STOP_PLUGINS[-1]:
667+
info_dict[component].result = TaskResult.SUCCESSFUL
643668

644669
if task_info.status == TaskStatus.FINISHED:
645670
task_result = task_info.result
@@ -655,7 +680,7 @@ def get_task_info_log(self, name, task_type):
655680
msg=msg)
656681

657682
def get_install_task_info(self, name):
658-
return self.get_task_info_log(name, "install")
683+
return self.get_task_info_log_by_type(name, "install")
659684

660685
def __build_connection_info(self, component, info):
661686
if info is None:

0 commit comments

Comments
 (0)