def get_service_event(self, tenant, service, page, page_size, start_time_str): # 前端传入时间到分钟,默认会加上00,这样一来刚部署的应用的日志无法查询到,所有将当前时间添加一分钟 if start_time_str: start_time = str_to_time(start_time_str, fmt="%Y-%m-%d %H:%M") start_time_str = time_to_str(start_time + datetime.timedelta(minutes=1)) events = event_repo.get_events_before_specify_time( tenant.tenant_id, service.service_id, start_time_str) event_paginator = JuncheePaginator(events, int(page_size)) total = event_paginator.count page_events = event_paginator.page(page) has_next = True if page_size * page >= total: has_next = False self.__sync_region_service_event_status(service.service_region, tenant.tenant_name, page_events) re_events = [] for event in list(page_events): event_re = event.to_dict() # codeVersion = "版本:4c042b9 上传者:黄峻贤 Commit:Merge branch 'developer' into 'test'" version_info = self.wrapper_code_version(service, event) if version_info: event_re["code_version"] = version_info type_cn = self.translate_event_type(event.type) event_re["type_cn"] = type_cn re_events.append(event_re) return re_events, has_next
def get(self, request, *args, **kwargs): """ 获取服务的构建版本 --- parameters: - name: tenantName description: 租户名 required: true type: string paramType: path - name: serviceAlias description: 服务别名 required: true type: string paramType: path """ try: body = region_api.get_service_build_versions(self.response_region, self.tenant.tenant_name, self.service.service_alias) events = event_repo.get_events_before_specify_time(self.tenant.tenant_id, self.service.service_id, current_time_str(fmt="%Y-%m-%d %H:%M:%S")).filter(type="deploy") version_user_map = {event.deploy_version: event.user_name for event in events} versions_info = body["list"] version_list = [] for info in versions_info: version_list.append({ "build_version": info["BuildVersion"], "kind": BUILD_KIND_MAP.get(info["Kind"]), "service_type": info["DeliveredType"], "image_url": info["ImageName"], "repo_url": info["RepoURL"], "commit_msg": info["CommitMsg"], "author": info["Author"], "create_time": info["CreatedAt"], "status": info["FinalStatus"], "build_user": version_user_map.get(info["BuildVersion"], "未知") }) res_versions = sorted(version_list, key=lambda version: version["build_version"], reverse=True) result = general_message(200, "success", "查询成功", list=res_versions) except Exception as e: logger.exception(e) result = error_message(e.message) return Response(result, status=result["code"])
def get(self, request, *args, **kwargs): """ 获取服务的构建版本 --- parameters: - name: tenantName description: 租户名 required: true type: string paramType: path - name: serviceAlias description: 服务别名 required: true type: string paramType: path """ try: page = request.GET.get("page_num", 1) page_size = request.GET.get("page_size", 10) body = region_api.get_service_build_versions( self.response_region, self.tenant.tenant_name, self.service.service_alias) build_version_sort = body["list"] build_version_sort.sort(key=operator.itemgetter('BuildVersion'), reverse=True) paginator = Paginator(build_version_sort, page_size) build_version_list = paginator.page(int(page)).object_list events = event_repo.get_events_before_specify_time( self.tenant.tenant_id, self.service.service_id, current_time_str(fmt="%Y-%m-%d %H:%M:%S")).filter( type="deploy") version_user_map = { event.deploy_version: event.user_name for event in events } versions_info = build_version_list version_list = [] for info in versions_info: version_list.append({ "build_version": info["BuildVersion"], "kind": BUILD_KIND_MAP.get(info["Kind"]), "service_type": info["DeliveredType"], "image_url": info["ImageName"], "repo_url": info["RepoURL"], "commit_msg": info["CommitMsg"], "author": info["Author"], "create_time": info["CreatedAt"], "status": info["FinalStatus"], "build_user": version_user_map.get(info["BuildVersion"], "未知") }) res_versions = sorted(version_list, key=lambda version: version["build_version"], reverse=True) # try: # result = paginator.page(page).object_list # except PageNotAnInteger: # result = paginator.page(1).object_list # except EmptyPage: # result = paginator.page(paginator.num_pages).object_list result = general_message(200, "success", "查询成功", list=res_versions, total=paginator.count) return Response(result, status=result["code"]) except Exception as e: result = error_message(e.message) return Response(result, status=500)
def get(self, request, *args, **kwargs): """ 获取服务的构建版本 --- parameters: - name: tenantName description: 租户名 required: true type: string paramType: path - name: serviceAlias description: 服务别名 required: true type: string paramType: path """ try: page = request.GET.get("page_num", 1) page_size = request.GET.get("page_size", 10) body = region_api.get_service_build_versions( self.response_region, self.tenant.tenant_name, self.service.service_alias) logger.debug('---------body------>{0}'.format(body)) build_version_sort = body["bean"]["list"] run_version = body["bean"]["deploy_version"] total_num_list = list() for build_version_info in build_version_sort: if build_version_info["FinalStatus"] in ("success", "failure"): total_num_list.append(build_version_info) total_num = len(total_num_list) success_num = 0 failure_num = 0 for build_info in build_version_sort: if build_info["FinalStatus"]: if build_info["FinalStatus"] == "success": success_num += 1 else: failure_num += 1 logger.debug( '---------------build_version_sort---------->{0}'.format( build_version_sort)) build_version_sort.sort(key=operator.itemgetter('BuildVersion'), reverse=True) paginator = Paginator(build_version_sort, page_size) build_version_list = paginator.page(int(page)).object_list events = event_repo.get_events_before_specify_time( self.tenant.tenant_id, self.service.service_id, current_time_str(fmt="%Y-%m-%d %H:%M:%S")).filter( type="deploy") version_user_map = { event.event_id: event.user_name for event in events } versions_info = build_version_list version_list = [] for info in versions_info: version_list.append({ "build_version": info["BuildVersion"], "kind": BUILD_KIND_MAP.get(info["Kind"]), "service_type": info["DeliveredType"], "image_url": info["ImageName"], "repo_url": info["RepoURL"], "commit_msg": info["CommitMsg"], "author": info["Author"], "create_time": info["CreatedAt"], "status": info["FinalStatus"], "build_user": version_user_map.get(info["EventID"], "未知") }) res_versions = sorted(version_list, key=lambda version: version["build_version"], reverse=True) for res_version in res_versions: # get deploy version from region if int(res_version["build_version"]) > int(run_version): upgrade_or_rollback = 1 elif int(res_version["build_version"]) == int(run_version): upgrade_or_rollback = 0 else: upgrade_or_rollback = -1 res_version.update( {"upgrade_or_rollback": upgrade_or_rollback}) # try: # result = paginator.page(page).object_list # except PageNotAnInteger: # result = paginator.page(1).object_list # except EmptyPage: # result = paginator.page(paginator.num_pages).object_list is_upgrade = False if res_versions: latest_version = res_versions[0]["build_version"] if int(latest_version) > int(run_version): is_upgrade = True bean = { "is_upgrade": is_upgrade, "current_version": run_version, "success_num": str(success_num), "failure_num": str(failure_num) } result = general_message(200, "success", "查询成功", bean=bean, list=res_versions, total=str(total_num)) return Response(result, status=result["code"]) except Exception as e: logger.exception(e) result = error_message(e.message) return Response(result, status=500)