コード例 #1
0
    def post(self, request, *args, **kwargs):
        """
        创建插件新版本
        ---
        parameters:
            - name: tenantName
              description: 租户名
              required: true
              type: string
              paramType: path
            - name: plugin_id
              description: 插件ID
              required: true
              type: string
              paramType: path
        """
        try:
            plugin_versions = plugin_version_service.get_plugin_versions(
                self.plugin.plugin_id)

            if not plugin_versions:
                return Response(general_message(412,
                                                "current version not exist",
                                                "插件不存在任何版本,无法创建"),
                                status=412)
            if self.plugin.origin != "source_code":
                return Response(general_message(
                    412, "market plugin can not create new version",
                    "云市插件不能创建版本"),
                                status=412)
            pbv = plugin_versions[0]
            if pbv.build_status != "build_success":
                return Response(general_message(412,
                                                "no useable plugin version",
                                                "您的插件构建未成功,无法创建新版本"),
                                status=412)

            new_version = datetime.datetime.now().strftime('%Y%m%d%H%M%S')
            plugin_version_service.copy_build_version_info(
                pbv.plugin_id, pbv.build_version, new_version)
            plugin_config_service.copy_config_group(pbv.plugin_id,
                                                    pbv.build_version,
                                                    new_version)
            plugin_config_service.copy_group_items(pbv.plugin_id,
                                                   pbv.build_version,
                                                   new_version)

            pbv.plugin_version_status = "fixed"
            pbv.save()
            bean = {
                "plugin_id": self.plugin.plugin_id,
                "new_version": new_version
            }
            result = general_message(200, "success", "操作成功", bean=bean)

        except Exception as e:
            logger.exception(e)
            result = error_message(e.message)
        return Response(result, status=result["code"])
コード例 #2
0
    def get(self, request, *args, **kwargs):
        """
        插件构建历史信息展示
        ---
        parameters:
            - name: tenantName
              description: 租户名
              required: true
              type: string
              paramType: path
            - name: plugin_id
              description: 插件ID
              required: true
              type: string
              paramType: path
            - name: page
              description: 当前页
              required: true
              type: string
              paramType: query
            - name: page_size
              description: 每页大小,默认为8
              required: true
              type: string
              paramType: query
        """
        try:
            page = request.GET.get("page", 1)
            page_size = request.GET.get("page_size", 8)
            pbvs = plugin_version_service.get_plugin_versions(
                self.plugin.plugin_id)
            paginator = JuncheePaginator(pbvs, int(page_size))
            show_pbvs = paginator.page(int(page))

            update_status_thread = threading.Thread(
                target=plugin_version_service.update_plugin_build_status,
                args=(self.response_region, self.tenant))
            update_status_thread.start()

            data = [pbv.to_dict() for pbv in show_pbvs]
            result = general_message(200,
                                     "success",
                                     "查询成功",
                                     list=data,
                                     total=paginator.count,
                                     current_page=int(page),
                                     next_page=int(page) + 1)

        except Exception as e:
            logger.exception(e)
            result = error_message(e.message)
        return Response(result, status=result["code"])