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: body description: 配置内容 required: true type: string paramType: body """ try: config = json.loads(request.body) config_group = config if not config_group: return Response(general_message(400, "params error", "参数配置不可为空"), status=400) plugin_svc.del_service_plugin_attrs(self.service.service_id, plugin_id) plugin_svc.updateALLTenantServicePluginAttr( config_group, plugin_id, self.service.service_id) complex, normal = plugin_svc.createAttrsJsonForRegion( self.service.service_id, self.service.service_alias, 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 region_api.putPluginAttr(self.service.service_region, self.tenant.tenant_name, self.service.service_alias, plugin_id, body) result = general_message(200, "config success", "配置成功") return Response(result, result["code"]) except Exception as e: logger.exception(e) result = error_message(e.message) return Response(result, result["code"])
def put(self, request, *args, **kwargs): result = {} config = json.loads(request.body) logger.debug("plugin.relation", "in PluginServiceComplexAttr put method params is {}".format(config)) plugin_id = config.get("plugin_id", None) service_id = config.get("service_id", None) try: config_group = config.get("config_group", []) if len(config_group) == 0: result["success"] = False result["code"] = 400 result['msg'] = "参数配置不可为空" result = oldResultSuitGeneralMessage(result, "params canot be null", "") return JsonResponse(result, status=200) plugin_svc.del_service_plugin_attrs(self.service.service_id, plugin_id) plugin_svc.updateALLTenantServicePluginAttr(config_group, plugin_id, self.service.service_id) 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 logger.debug("plugin.relation", "--< config_envs is {}".format(config_envs)) body = {} body["tenant_id"] = self.tenant.tenant_id body["service_id"] = self.service.service_id body["config_envs"] = config_envs res, resultBody = region_api.putPluginAttr(self.response_region, self.tenant.tenant_name, self.serviceAlias, plugin_id, body) if res.status == 200: 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, "add plugin attr error", "") return JsonResponse(result, status=200) except Exception, e: logger.error("plugin.relation", 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 attr error", "") return JsonResponse(result, status=200)