Exemple #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
     rules = domain_service.get_http_rules_by_app_id(app_id)
     re = HTTPGatewayRuleSerializer(rules, many=True)
     return Response(re.data, status=status.HTTP_200_OK)
Exemple #2
0
 def get(self, req, app_id, *args, **kwargs):
     app = group_service.get_app_by_id(app_id)
     if not app:
         return Response({"msg": "app is not exist"}, status=status.HTTP_404_NOT_FOUND)
     rules = domain_service.get_http_rules_by_app_id(app_id)
     re = HTTPGatewayRuleSerializer(rules, many=True)
     return Response(re.data, status=status.HTTP_200_OK)
Exemple #3
0
 def post(self, request, app_id, *args, **kwargs):
     sos = ServiceGroupOperationsSerializer(data=request.data)
     sos.is_valid(raise_exception=True)
     app = group_service.get_app_by_id(self.team, self.region_name, app_id)
     if not app:
         raise ErrAppNotFound
     service_ids = sos.data.get("service_ids", None)
     if not service_ids or len(service_ids) == 0:
         service_ids = app_service.get_group_services_by_id(app_id)
     # TODO: Check the amount of resources used
     action = sos.data.get("action")
     if action == "stop":
         self.has_perms([300006, 400008])
     if action == "start":
         self.has_perms([300005, 400006])
     if action == "upgrade":
         self.has_perms([300007, 400009])
     if action == "deploy":
         self.has_perms([300008, 400010])
     code, msg = app_manage_service.batch_operations(self.team, request.user, action, service_ids, None)
     if code != 200:
         result = {"msg": "batch operation error"}
         rst_serializer = FailSerializer(data=result)
         rst_serializer.is_valid()
         return Response(rst_serializer.data, status=status.HTTP_400_BAD_REQUEST)
     else:
         result = {"msg": msg}
         rst_serializer = SuccessSerializer(data=result)
         rst_serializer.is_valid()
         return Response(rst_serializer.data, status=status.HTTP_200_OK)
 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)
Exemple #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:
         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)
Exemple #6
0
 def initial(self, request, *args, **kwargs):
     super(TeamAppAPIView, self).initial(request, *args, **kwargs)
     app_id = kwargs.get("app_id")
     if app_id:
         self.app = group_service.get_app_by_id(self.team, self.region_name, app_id)
     if not self.app:
         raise ServiceHandleException(msg_show="应用不存在", msg="no found app", status_code=404)
    def post(self, request, app_id, *args, **kwargs):
        ads = PostHTTPGatewayRuleSerializer(data=request.data)
        ads.is_valid(raise_exception=True)
        app = group_service.get_app_by_id(self.team, self.region_name, app_id)
        if not app:
            raise ErrAppNotFound
        httpdomain = ads.data
        # Compatible history code
        httpdomain["domain_heander"] = httpdomain.get("domain_header", None)
        httpdomain["domain_type"] = DomainType.WWW
        protocol = "http"
        if httpdomain.get("certificate_id", None):
            protocol = "https"
        httpdomain["protocol"] = protocol
        service = service_repo.get_service_by_tenant_and_id(
            self.team.tenant_id, httpdomain["service_id"])
        if not service:
            rst = {"msg": "组件不存在"}
            return Response(rst, status=status.HTTP_400_BAD_REQUEST)
        if domain_service.check_domain_exist(
                httpdomain["service_id"], httpdomain["container_port"],
                httpdomain["domain_name"], protocol,
                httpdomain.get("domain_path"),
                httpdomain.get("rule_extensions")):
            rst = {"msg": "策略已存在"}
            return Response(rst, status=status.HTTP_400_BAD_REQUEST)

        if service.service_source == "third_party":
            msg, msg_show, code = port_service.check_domain_thirdpart(
                self.team, service)
            if code != 200:
                logger.exception(msg, msg_show)
                return Response({
                    "msg": msg,
                    "msg_show": msg_show
                },
                                status=code)
        if httpdomain.get("whether_open", True):
            tenant_service_port = port_service.get_service_port_by_port(
                service, httpdomain["container_port"])
            # 仅开启对外端口
            code, msg, data = port_service.manage_port(
                self.team, service, service.service_region,
                int(tenant_service_port.container_port), "only_open_outer",
                tenant_service_port.protocol, tenant_service_port.port_alias)
            if code != 200:
                return Response({"msg": "change port fail"}, status=code)
        tenant_service_port = port_service.get_service_port_by_port(
            service, httpdomain["container_port"])
        if not tenant_service_port.is_outer_service:
            return Response({"msg": "没有开启对外端口"},
                            status=status.HTTP_400_BAD_REQUEST)
        data = domain_service.bind_httpdomain(self.team, self.request.user,
                                              service, httpdomain, True)
        serializer = HTTPGatewayRuleSerializer(data=data.to_dict())
        serializer.is_valid()
        return Response(serializer.data, status=status.HTTP_201_CREATED)
Exemple #8
0
    def put(self, request, app_id, rule_id, *args, **kwargs):
        ads = UpdatePostHTTPGatewayRuleSerializer(data=request.data)
        ads.is_valid(raise_exception=True)
        app = group_service.get_app_by_id(self.team, self.region_name, app_id)
        if not app:
            raise ErrAppNotFound
        httpdomain = ads.data
        service = service_repo.get_service_by_tenant_and_id(self.team.tenant_id, httpdomain["service_id"])
        if not service:
            rst = {"msg": "组件不存在"}
            return Response(rst, status=status.HTTP_400_BAD_REQUEST)
        data = domain_service.update_httpdomain(self.team, service, rule_id, ads.data, True)

        re = HTTPGatewayRuleSerializer(data=model_to_dict(data))
        re.is_valid()
        return Response(re.data, status=status.HTTP_200_OK)
Exemple #9
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)
Exemple #10
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)