def post(self, request, *args, **kwargs): """ 创建应用市场应用 --- parameters: - name: tenantName description: 团队名称 required: true type: string paramType: path - name: group_id description: 组id required: true type: string paramType: form - name: app_id description: rainbond app id required: true type: string paramType: form """ try: group_id = request.data.get("group_id", -1) group_key = request.data.get("group_key", None) group_version = request.data.get("group_version", None) is_deploy = request.data.get("is_deploy", True) if not group_key or not group_version: return Response(general_message(400, "app id is null", "请指明需要安装的应用"), status=400) if int(group_id) != -1: code, _, _ = group_service.get_group_by_id(self.tenant, self.response_region, group_id) if code != 200: return Response(general_message(400, "group not exist", "所选组不存在"), status=400) code, app = market_app_service.get_rain_bond_app_by_key_and_version(group_key, group_version) if not app: return Response(general_message(404, "not found", "云市应用不存在"), status=404) market_app_service.check_package_app_resource(self.tenant, self.response_region, app) market_app_service.install_service(self.tenant, self.response_region, self.user, group_id, app, is_deploy) RainbondCenterApp.objects.filter(group_key=group_key, version=group_version).update( install_number=F("install_number") + 1 ) logger.debug("market app create success") result = general_message(200, "success", "创建成功") except ResourceNotEnoughException as re: logger.exception(re) return Response(general_message(10406, "resource is not enough", re.message), status=412) except AccountOverdueException as re: logger.exception(re) return Response(general_message(10406, "resource is not enough", re.message), status=412) except Exception as e: logger.exception(e) result = error_message(e.message) return Response(result, status=result["code"])
def post(self, request, *args, **kwargs): """ 应用上下线 --- parameters: - name: app_id description: rainbond app id required: true type: string paramType: form - name: action description: 操作类型 online|offline required: true type: string paramType: form """ try: if not self.user.is_sys_admin: if not user_services.is_user_admin_in_current_enterprise(self.user, self.tenant.enterprise_id): return Response(general_message(403, "current user is not enterprise admin", "非企业管理员无法进行此操作"), status=403) group_key = request.data.get("group_key", None) group_version_list = request.data.get("group_version_list", []) action = request.data.get("action", None) if not group_key: return Response(general_message(400, "group_key is null", "请指明需要安装应用的group_key"), status=400) if not group_version_list: return Response(general_message(400, "group_version_list is null", "请指明需要安装应用的版本"), status=400) if not action: return Response(general_message(400, "action is not specified", "操作类型未指定"), status=400) if action not in ("online", "offline"): return Response(general_message(400, "action is not allow", "不允许的操作类型"), status=400) for group_version in group_version_list: code, app = market_app_service.get_rain_bond_app_by_key_and_version(group_key, group_version) if not app: return Response(general_message(404, "not found", "云市应用不存在"), status=404) if app.enterprise_id == "public": if not self.user.is_sys_admin: return Response(general_message(403, "only system admin can manage public app", "非平台管理员无权操作"), status=403) if action == "online": app.is_complete = True else: app.is_complete = False app.save() result = general_message(200, "success", "操作成功") 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 """ try: group_key = request.GET.get("group_key", None) group_version = request.GET.get("group_version", None) if not group_key or not group_version: return Response(general_message(400, "app id is null", "请指明需要查询的应用"), status=400) result_list = [] group_version_list = group_version.split("#") for version in group_version_list: code, app = market_app_service.get_rain_bond_app_by_key_and_version( group_key, version) if not app: return Response(general_message(404, "not found", "云市应用不存在"), status=404) code, msg, result = export_service.get_export_status( self.tenant, app) if code != 200: return Response(general_message(code, "get export info error ", msg), status=code) result_list.append(result) result = general_message(200, "success", "查询成功", list=result_list) except Exception as e: logger.exception(e) result = error_message(e.message) return Response(result, status=result["code"])
def post(self, request, *args, **kwargs): """ 导出应用市场应用 --- parameters: - name: tenantName description: 团队名称 required: true type: string paramType: path - name: format description: 导出类型 rainbond-app | docker-compose required: true type: string paramType: form """ try: group_key = request.data.get("group_key", None) group_version = request.data.get("group_version", []) export_format = request.data.get("format", None) if not group_key or not group_version: return Response(general_message(400, "app id is null", "请指明需要导出的应用"), status=400) if not export_format or export_format not in ( "rainbond-app", "docker-compose", ): return Response(general_message(400, "export format is illegal", "请指明导出格式"), status=400) new_export_record_list = [] for version in group_version: code, app = market_app_service.get_rain_bond_app_by_key_and_version( group_key, version) if not app: return Response(general_message(404, "not found", "云市应用不存在"), status=404) code, msg, new_export_record = export_service.export_current_app( self.tenant, export_format, app) if code != 200: return Response(general_message(code, "export error", msg), status=code) new_export_record_list.append(new_export_record.to_dict()) result = general_message(200, "success", "操作成功,正在导出", list=new_export_record_list) except ResourceNotEnoughException as re: raise re except AccountOverdueException as re: logger.exception(re) return Response(general_message(10410, "resource is not enough", re.message), status=412) except Exception as e: logger.exception(e) result = error_message(e.message) return Response(result, status=result["code"])