Example #1
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)
Example #2
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)
Example #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:
         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)
Example #4
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)