示例#1
0
 def get(self, req, app_id, *args, **kwargs):
     app = group_service.get_app_by_id(self.team, self.region_name, app_id)
     if not app:
         raise ErrAppNotFound
     services = app_service.get_app_services_and_status(app)
     used_cpu, used_momory = app_service.get_app_memory_and_cpu_used(
         services)
     app_info = model_to_dict(app)
     app_info["service_count"] = app_service.get_app_service_count(app_id)
     app_info["enterprise_id"] = self.enterprise.enterprise_id
     running_count = app_service.get_app_running_service_count(
         self.team, services)
     app_info["running_service_count"] = running_count
     app_status = "closed"
     if running_count > 0 and running_count < len(services):
         app_status = "part_running"
     if running_count > 0 and running_count == len(services):
         app_status = "running"
     app_info["status"] = app_status
     app_info["team_name"] = self.team.tenant_name
     app_info["used_cpu"] = used_cpu
     app_info["used_momory"] = used_momory
     app_info["app_id"] = app_id
     reapp = AppInfoSerializer(data=app_info)
     reapp.is_valid()
     return Response(reapp.data, status=status.HTTP_200_OK)
示例#2
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)
示例#3
0
class AppInfoView(BaseOpenAPIView):
    @swagger_auto_schema(
        operation_description="应用详情",
        responses={200: AppInfoSerializer()},
        tags=['openapi-apps'],
    )
    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
 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)
示例#5
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)
示例#6
0
class AppInfoView(BaseOpenAPIView):
    @swagger_auto_schema(
        operation_description="应用详情",
        responses={200: AppInfoSerializer()},
        tags=['openapi-apps'],
    )
    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)
示例#7
0
class AppInfoView(TeamAppAPIView):
    @swagger_auto_schema(
        operation_description="应用详情",
        manual_parameters=[
            openapi.Parameter("app_id", openapi.IN_PATH, description="应用id", type=openapi.TYPE_INTEGER),
        ],
        responses={200: AppInfoSerializer()},
        tags=['openapi-apps'],
    )
    def get(self, req, app_id, *args, **kwargs):
        app = group_service.get_app_by_id(self.team, self.region_name, app_id)
        if not app:
            raise ErrAppNotFound
        services = app_service.get_app_services_and_status(app)
        used_cpu, used_momory = app_service.get_app_memory_and_cpu_used(services)
        app_info = model_to_dict(app)
        app_info["service_count"] = app_service.get_app_service_count(app_id)
        app_info["enterprise_id"] = self.enterprise.enterprise_id
        running_count = app_service.get_app_running_service_count(self.team, services)
        app_info["running_service_count"] = running_count
        app_status = "closed"
        if running_count > 0 and running_count < len(services):
            app_status = "part_running"
        if running_count > 0 and running_count == len(services):
            app_status = "running"
        app_info["status"] = app_status
        app_info["team_name"] = self.team.tenant_name
        app_info["used_cpu"] = used_cpu
        app_info["used_momory"] = used_momory
        app_info["app_id"] = app_id
        reapp = AppInfoSerializer(data=app_info)
        reapp.is_valid()
        return Response(reapp.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, *args, **kwargs):
        msg_list = []
        try:
            force = int(req.GET.get("force", 0))
        except ValueError:
            raise ServiceHandleException(msg='force value error', msg_show="参数错误")
        service_ids = app_service.get_group_services_by_id(self.app.ID)
        services = service_repo.get_services_by_service_ids(service_ids)
        if services:
            status_list = base_service.status_multi_service(
                region=self.app.region_name,
                tenant_name=self.team.tenant_name,
                service_ids=service_ids,
                enterprise_id=self.team.enterprise_id)
            status_list = [x for x in [x["status"] for x in status_list] if x not in ["closed", "undeploy"]]
            if len(status_list) > 0:
                raise ServiceHandleException(
                    msg="There are running components under the current application", msg_show="当前应用下有运行态的组件,不可删除")
            else:
                code_status = 200
                for service in services:
                    code, msg = app_manage_service.batch_delete(self.user, self.team, service, is_force=True)
                    msg_dict = dict()
                    msg_dict['status'] = code
                    msg_dict['msg'] = msg
                    msg_dict['service_id'] = service.service_id
                    msg_dict['service_cname'] = service.service_cname
                    msg_list.append(msg_dict)
                    if code != 200:
                        code_status = code
                        if force:
                            code_status = 200
                            app_manage_service.delete_again(self.user, self.team, service, is_force=True)
                if code_status != 200:
                    raise ServiceHandleException(msg=msg_list, msg_show="请求错误")
                else:
                    code, msg, data = group_service.delete_group_no_service(self.app.ID)
                    if code != 200:
                        raise ServiceHandleException(msg=msg, msg_show="请求错误")
                    return Response(None, status=code)
        code, msg, data = group_service.delete_group_no_service(self.app.ID)
        if code != 200:
            raise ServiceHandleException(msg=msg, msg_show="请求错误")
        return Response(None, status=code)