def put(self, request, *args, **kwargs): """插件启停""" result = {} config = QueryDict(request.body) logger.debug( "plugin.relation", "in PluginServiceRelation put method params is {}".format(config)) try: plugin_id = config.get("plugin_id", None) switch = config.get("is_switch", True) switch = plugin_svc.chargeSwtich(switch) relations = plugin_svc.get_tenant_service_plugin_relation_by_plugin( self.service.service_id, plugin_id) if relations > 0: build_version = relations[0].build_version else: result["success"] = False result["code"] = 404 result['msg'] = u"未找到关联插件的构建版本" result = oldResultSuitGeneralMessage(result, "success", "") return JsonResponse(result, status=200) body_relation = {} body_relation["plugin_id"] = plugin_id body_relation["switch"] = switch body_relation["version_id"] = build_version logger.debug("plugin.relation", "is_switch body is {}".format(body_relation)) res, resultBody = region_api.updatePluginServiceRelation( self.response_region, self.tenant.tenant_name, self.serviceAlias, body_relation) if res.status == 200: plugin_svc.update_service_plugin_relation( self.service.service_id, plugin_id, build_version, switch) result["success"] = True result["code"] = 200 result['msg'] = u"操作成功" result = oldResultSuitGeneralMessage(result, "success", "") return JsonResponse(result, status=200) else: result["success"] = False result["code"] = res.status result['msg'] = resultBody result = oldResultSuitGeneralMessage( result, "update plugin status error", "") return JsonResponse(result, status=200) except Exception, e: logger.error("plugin.relation", e) result["success"] = False result["code"] = 500 result["msg"] = u"操作失败" result = oldResultSuitGeneralMessage(result, "update plugin status error", "") return JsonResponse(result, status=200)
def put(self, request, plugin_id, *args, **kwargs): """ 启停用组件插件 --- parameters: - name: tenantName description: 租户名 required: true type: string paramType: path - name: serviceAlias description: 组件别名 required: true type: string paramType: path - name: plugin_id description: 插件ID required: true type: string paramType: path - name: is_switch description: 插件启停状态 required: true type: boolean paramType: form """ try: if not plugin_id: return Response(general_message(400, "params error", "参数异常"), status=400) switch = request.data.get("is_switch", True) switch = plugin_svc.chargeSwtich(switch) relations = plugin_svc.get_tenant_service_plugin_relation_by_plugin(self.service.service_id, plugin_id) if relations > 0: build_version = relations[0].build_version else: return Response(general_message(404, "params error", "未找到关联插件的构建版本"), status=400) body_relation = {} body_relation["plugin_id"] = plugin_id body_relation["switch"] = switch body_relation["version_id"] = build_version logger.debug("plugin.relation", "is_switch body is {}".format(body_relation)) res, resultBody = region_api.updatePluginServiceRelation(self.service.service_region, self.tenant.tenant_name, self.service.service_alias, body_relation) if res.status == 200: plugin_svc.update_service_plugin_relation(self.service.service_id, plugin_id, build_version, switch) return Response(general_message(200, "success", "操作成功"), status=200) else: result = general_message(500, "update plugin status error", "系统异常") return Response(result, result["code"]) except Exception, e: logger.exception(e) result = error_message(e.message) return Response(result, status=result["code"])
def put(self, request, *args, **kwargs): result = {} config = QueryDict(request.body) logger.debug("plugin.relation", "in PluginServiceRelation put method params is {}".format(config)) plugin_id = config.get("plugin_id", None) build_version = config.get("build_version", "newest") switch = config.get("switch", True) switch = plugin_svc.chargeSwtich(switch) if not plugin_id or not build_version: logger.error("plugin.relation", u'参数错误,plugin_id and version_id') data = {"success":False, "code":400, 'msg':u'参数错误'} result = oldResultSuitGeneralMessage(data, "params error", "") return JsonResponse(result, status=200) try: body_relation = {} body_relation["plugin_id"] = plugin_id body_relation["switch"] = switch versionList = plugin_svc.get_tenant_plugin_newest_versions(self.response_region, self.tenant, plugin_id) if versionList > 0: body_relation["version_id"] = versionList[0].build_version build_version = versionList[0].build_version logger.debug("plugin.relation", "body_relation is {0}, build_version is {1}".format(body_relation, build_version)) else: result["success"] = False result["code"] = 404 result["msg"] = u"未找到插件的最新版本" result = oldResultSuitGeneralMessage(result, "cant find newest plugin", "") return JsonResponse(result, status=200) res, resultBody = region_api.delPluginServiceRelation( self.response_region, self.tenant.tenant_name, plugin_id, self.serviceAlias) if res.status == 200: pass else: result["success"] = False result["code"] = res.status result['msg'] = resultBody result = oldResultSuitGeneralMessage(result, "update plugin relation error", "") return JsonResponse(result, status=res.status) res, resultBody = region_api.pluginServiceRelation( self.response_region, self.tenant.tenant_name, self.serviceAlias, body_relation) if res.status == 200: plugin_svc.update_service_plugin_relation(self.service.service_id, plugin_id, build_version, switch) pass else: result["success"] = False result["code"] = res.status result['msg'] = resultBody result = oldResultSuitGeneralMessage(result, "update plugin relation error", "") return JsonResponse(result, status=res.status) complex, normal = plugin_svc.createAttrsJsonForRegion(self.service.service_id, self.serviceAlias, plugin_id) config_envs = {} config_envs["normal_envs"] = normal config_envs["complex_envs"] = complex body = {} body["tenant_id"] = self.tenant.tenant_id body["service_id"] = self.service.service_id body["config_envs"] = config_envs res, resultBody = region_api.postPluginAttr(self.response_region, self.tenant.tenant_name, self.serviceAlias, plugin_id, body) if res.status == 200: result["config_group"] = self.useDefaultAttr(plugin_id, build_version, "post") result["success"] = True result["code"] = 200 result["msg"] = u"操作成功" result["bean"] = {"build_version": model_to_dict(versionList[0])} result = general_message(200, "success", u"操作成功", result["bean"], result["config_group"]) return JsonResponse(result, status=200) else: result["success"] = False result["code"] = res.status result['msg'] = resultBody result = oldResultSuitGeneralMessage(result, "update plugin relation error", "") return JsonResponse(result, status=200) except Exception, e: result["success"] = False result['code']=500 result['msg']=u'更新插件关联失败' logger.error("plugin.relation", u'更新插件关联失败') logger.exception("plugin.relation", e) result = oldResultSuitGeneralMessage(result, "update plugin relation error", "") return JsonResponse(result, status=200)