Пример #1
0
 def post(self, request, team_id, app_id, *args, **kwargs):
     """
     应用复制
     ---
     parameters:
         - name: tenantName
           description: 团队名称
           required: true
           type: string
           paramType: path
         - name: app_id
           description: 应用id
           required: true
           type: int
           paramType: path
     """
     serializers = AppCopyCSerializer(data=request.data)
     serializers.is_valid(raise_exception=True)
     services = serializers.data.get("services")
     tar_team_name = request.data.get("target_team_name")
     tar_region_name = request.data.get("target_region_name")
     tar_app_id = request.data.get("target_app_id")
     tar_team, tar_group = groupapp_copy_service.check_and_get_team_group(request.user, tar_team_name, tar_region_name,
                                                                          tar_app_id)
     services = groupapp_copy_service.copy_group_services(request.user, self.team, self.region_name, tar_team,
                                                          tar_region_name, tar_group, app_id, services)
     services = ServiceBaseInfoSerializer(data=services, many=True)
     services.is_valid()
     serializers = AppCopyCResSerializer(data={"services": services.data})
     serializers.is_valid()
     return Response(serializers.data, status=200)
Пример #2
0
 def get(self, req, app_id, service_id, *args, **kwargs):
     status_list = base_service.status_multi_service(
         region=self.app.region_name,
         tenant_name=self.team.tenant_name,
         service_ids=[self.service.service_id],
         enterprise_id=self.team.enterprise_id)
     self.service.status = status_list[0]["status"]
     serializer = ServiceBaseInfoSerializer(data=self.service.to_dict())
     serializer.is_valid()
     return Response(serializer.data, status=status.HTTP_200_OK)
Пример #3
0
 def get(self, req, app_id, *args, **kwargs):
     app = group_service.get_app_by_id(app_id)
     if not app:
         return Response(None, status.HTTP_404_NOT_FOUND)
     tenant = team_services.get_team_by_team_id(app.tenant_id)
     if not tenant:
         return Response({"msg": "该应用所属团队已被删除"},
                         status=status.HTTP_404_NOT_FOUND)
     appstatus, services = app_service.get_app_status(app)
     used_cpu, used_momory = app_service.get_app_memory_and_cpu_used(
         services)
     appInfo = model_to_dict(app)
     appInfo["service_count"] = app_service.get_app_service_count(app_id)
     appInfo["enterprise_id"] = tenant.enterprise_id
     appInfo[
         "running_service_count"] = app_service.get_app_running_service_count(
             tenant, services)
     appInfo["service_list"] = ServiceBaseInfoSerializer(services,
                                                         many=True).data
     appInfo["status"] = appstatus
     appInfo["team_name"] = tenant.tenant_name
     appInfo["used_cpu"] = used_cpu
     appInfo["used_momory"] = used_momory
     appInfo["app_id"] = app_id
     reapp = AppInfoSerializer(data=appInfo)
     reapp.is_valid()
     return Response(reapp.data, status=status.HTTP_200_OK)
Пример #4
0
class ListAppServicesView(TeamAppAPIView):
    @swagger_auto_schema(
        operation_description="查询应用下组件列表",
        manual_parameters=[
            openapi.Parameter("app_id", openapi.IN_PATH, description="应用id", type=openapi.TYPE_INTEGER),
        ],
        responses={200: ServiceBaseInfoSerializer(many=True)},
        tags=['openapi-apps'],
    )
    def get(self, req, app_id, *args, **kwargs):
        services = app_service.get_app_services_and_status(self.app)
        serializer = ServiceBaseInfoSerializer(data=services, many=True)
        serializer.is_valid()
        return Response(serializer.data, status=status.HTTP_200_OK)
Пример #5
0
 def get(self, req, app_id, *args, **kwargs):
     app = group_service.get_app_by_id(app_id)
     if not app:
         return Response(None, status.HTTP_404_NOT_FOUND)
     tenant = team_services.get_team_by_team_id(app.tenant_id)
     if not tenant:
         raise serializers.ValidationError("指定租户不存在")
     appstatus, services = app_service.get_app_status(app)
     appInfo = model_to_dict(app)
     appInfo["enterprise_id"] = tenant.enterprise_id
     appInfo["service_list"] = ServiceBaseInfoSerializer(services,
                                                         many=True).data
     appInfo["status"] = appstatus
     reapp = AppInfoSerializer(data=appInfo)
     reapp.is_valid()
     return Response(reapp.data, status=status.HTTP_200_OK)
Пример #6
0
class AppServicesView(TeamAppServiceAPIView):
    @swagger_auto_schema(
        operation_description="查询组件信息",
        manual_parameters=[
            openapi.Parameter("app_id", openapi.IN_PATH, description="应用id", type=openapi.TYPE_INTEGER),
        ],
        responses={200: ServiceBaseInfoSerializer()},
        tags=['openapi-apps'],
    )
    def get(self, req, app_id, service_id, *args, **kwargs):
        status_list = base_service.status_multi_service(
            region=self.app.region_name,
            tenant_name=self.team.tenant_name,
            service_ids=[self.service.service_id],
            enterprise_id=self.team.enterprise_id)
        self.service.status = status_list[0]["status"]
        serializer = ServiceBaseInfoSerializer(data=self.service.to_dict())
        serializer.is_valid()
        return Response(serializer.data, status=status.HTTP_200_OK)

    @swagger_auto_schema(
        operation_description="删除组件",
        manual_parameters=[
            openapi.Parameter("force", openapi.IN_QUERY, description="强制删除", type=openapi.TYPE_INTEGER, enum=[0, 1]),
            openapi.Parameter("app_id", openapi.IN_PATH, description="应用id", type=openapi.TYPE_INTEGER),
        ],
        responses={},
        tags=['openapi-apps'],
    )
    def delete(self, req, app_id, service_id, *args, **kwargs):
        try:
            force = int(req.GET.get("force", 0))
        except ValueError:
            raise ServiceHandleException(msg='force value error', msg_show="参数错误")
        code, msg = app_manage_service.delete(self.user, self.team, self.service, True)
        if code != 200 and force:
            app_manage_service.delete_again(self.user, self.team, self.service, is_force=True)
        msg_dict = dict()
        msg_dict['status'] = code
        msg_dict['msg'] = msg
        msg_dict['service_id'] = self.service.service_id
        msg_dict['service_cname'] = self.service.service_cname
        if code != 200:
            raise ServiceHandleException(msg="delete error", msg_show=msg, status_code=code)
        return Response(None, status=status.HTTP_200_OK)
Пример #7
0
 def post(self, request, *args, **kwargs):
     serializer = MarketInstallSerializer(data=request.data)
     serializer.is_valid(raise_exception=True)
     data = serializer.data
     logger.info(data)
     app = group_service.get_app_by_id(data["app_id"])
     if not app:
         return Response(FailSerializer(
             {"msg": "install target app not found"}),
                         status=status.HTTP_400_BAD_REQUEST)
     tenant = team_services.get_team_by_team_id(app.tenant_id)
     # TODO: get app info by order id
     token = market_sycn_service.get_enterprise_access_token(
         tenant.enterprise_id, "market")
     if token:
         market_client = get_market_client(token.access_id,
                                           token.access_token,
                                           token.access_url)
         app_version = market_client.download_app_by_order(
             order_id=data["order_id"])
         if not app_version:
             return Response(FailSerializer(
                 {"msg": "download app metadata failure"}),
                             status=status.HTTP_400_BAD_REQUEST)
         rainbond_app, rainbond_app_version = market_app_service.conversion_cloud_version_to_app(
             app_version)
         market_app_service.install_service(tenant, app.region_name,
                                            request.user, app.ID,
                                            rainbond_app,
                                            rainbond_app_version, True,
                                            True)
         services = group_service.get_group_services(data["app_id"])
         appInfo = model_to_dict(app)
         appInfo["enterprise_id"] = tenant.enterprise_id
         appInfo["service_list"] = ServiceBaseInfoSerializer(services,
                                                             many=True).data
         reapp = AppInfoSerializer(data=appInfo)
         reapp.is_valid()
         return Response(reapp.data, status=status.HTTP_200_OK)
     else:
         return Response(FailSerializer(
             {"msg": "not support install from market, not bound"}),
                         status=status.HTTP_400_BAD_REQUEST)
Пример #8
0
class AppCopyCResSerializer(serializers.Serializer):
    services = ServiceBaseInfoSerializer(many=True)

    def to_internal_value(self, data):
        return data
Пример #9
0
 def get(self, req, app_id, *args, **kwargs):
     services = app_service.get_app_services_and_status(self.app)
     serializer = ServiceBaseInfoSerializer(data=services, many=True)
     serializer.is_valid()
     return Response(serializer.data, status=status.HTTP_200_OK)