예제 #1
0
    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: false
              type: boolean
              paramType: form
            - name: min_memory
              description: 插件内存
              required: false
              type: boolean
              paramType: form
        """
        if not plugin_id:
            return Response(general_message(400, "not found plugin_id", "参数异常"), status=400)
        is_active = request.data.get("is_switch", True)
        service_plugin_relation = app_plugin_service.get_service_plugin_relation(self.service.service_id, plugin_id)
        if not service_plugin_relation:
            return Response(general_message(404, "not found plugin relation", "未找到组件使用的插件"), status=404)
        else:
            build_version = service_plugin_relation.build_version
        # 更新内存和cpu
        memory = request.data.get("min_memory")
        cpu = request.data.get("min_cpu")

        data = dict()
        data["plugin_id"] = plugin_id
        data["switch"] = is_active
        data["version_id"] = build_version
        if memory is not None:
            data["plugin_memory"] = int(memory)
        if cpu is not None:
            data["plugin_cpu"] = int(cpu)
        # 更新数据中心数据参数
        region_api.update_plugin_service_relation(self.response_region, self.tenant.tenant_name, self.service.service_alias,
                                                  data)
        # 更新本地数据
        app_plugin_service.start_stop_service_plugin(self.service.service_id, plugin_id, is_active, cpu, memory)
        result = general_message(200, "success", "操作成功")
        return Response(result, status=result["code"])
예제 #2
0
 def get(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: build_version
           description: 插件版本
           required: true
           type: string
           paramType: query
     """
     build_version = request.GET.get("build_version", None)
     if not plugin_id or not build_version:
         logger.error("plugin.relation", '参数错误,plugin_id and version_id')
         return Response(general_message(400, "params error", "请指定插件版本"),
                         status=400)
     result_bean = app_plugin_service.get_service_plugin_config(
         self.tenant, self.service, plugin_id, build_version)
     svc_plugin_relation = app_plugin_service.get_service_plugin_relation(
         self.service.service_id, plugin_id)
     pbv = plugin_version_service.get_by_id_and_version(
         self.tenant.tenant_id, plugin_id, build_version)
     if pbv:
         result_bean["build_info"] = pbv.update_info
         result_bean[
             "memory"] = svc_plugin_relation.min_memory if svc_plugin_relation else pbv.min_memory
     result = general_message(200, "success", "查询成功", bean=result_bean)
     return Response(result, result["code"])
예제 #3
0
    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: false
              type: boolean
              paramType: form
            - name: min_memory
              description: 插件内存
              required: false
              type: boolean
              paramType: form
        """
        try:
            if not plugin_id:
                return Response(general_message(400, "params error", "参数异常"), status=400)
            is_active = request.data.get("is_switch", True)
            service_plugin_relation = app_plugin_service.get_service_plugin_relation(self.service.service_id, plugin_id)
            if not service_plugin_relation:
                return Response(general_message(404, "params error", "未找到关联插件的构建版本"), status=404)
            else:
                build_version = service_plugin_relation.build_version
            pbv = plugin_version_service.get_by_id_and_version(plugin_id,build_version)
            # 更新内存和cpu
            min_memory = request.data.get("min_memory", pbv.min_memory)
            min_cpu = common_services.calculate_cpu(self.service.service_region, min_memory)

            data = dict()
            data["plugin_id"] = plugin_id
            data["switch"] = is_active
            data["version_id"] = build_version
            data["plugin_memory"] = min_memory
            data["plugin_cpu"] = min_cpu
            # 更新数据中心数据参数
            region_api.update_plugin_service_relation(self.response_region, self.tenant.tenant_name,
                                                      self.service.service_alias, data)
            # 更新本地数据
            app_plugin_service.start_stop_service_plugin(self.service.service_id, plugin_id, is_active)
            pbv.min_memory = min_memory
            pbv.min_cpu = min_cpu
            pbv.save()
            result = general_message(200, "success", "操作成功")
        except Exception, e:
            logger.exception(e)
            result = error_message(e.message)