Exemplo n.º 1
0
    def get(self, request, *args, **kwargs):
        """
        应用详情信息
        ---
        parameters:
            - name: tenantName
              description: 租户名
              required: true
              type: string
              paramType: path
            - name: serviceAlias
              description: 服务别名
              required: true
              type: string
              paramType: path
        """
        bean = dict()
        try:
            # status_map = app_service.get_service_status(self.tenant, self.service)
            # used_resource = app_service.get_service_resource_with_plugin(self.tenant, self.service,
            #                                                              status_map["status"])
            # service_abled_plugins = app_plugin_service.get_service_abled_plugin(self.service)
            # plugin_list = [p.to_dict() for p in service_abled_plugins]
            # bean.update(status_map)
            # bean.update(used_resource)
            # bean.update({"plugin_list": plugin_list})
            service_model = self.service.to_dict()
            group_map = group_service.get_services_group_name(
                [self.service.service_id])
            group_name = group_map.get(self.service.service_id)["group_name"]
            group_id = group_map.get(self.service.service_id)["group_id"]
            service_model["group_name"] = group_name
            service_model["group_id"] = group_id
            if self.service.service_source == AppConstants.DOCKER_COMPOSE:
                if self.service.create_status != "complete":
                    compose_service_relation = compose_service.get_service_compose_id(
                        self.service)
                    if compose_service_relation:
                        service_model[
                            "compose_id"] = compose_service_relation.compose_id
            bean.update({"service": service_model})
            tenant_actions = self.user.actions.tenant_actions
            bean.update({"tenant_actions": tenant_actions})
            service_actions = self.user.actions.service_actions
            bean.update({"service_actions": service_actions})

            event_websocket_url = ws_service.get_event_log_ws(
                self.request, self.response_region)
            # monitor_websocket_uri = ws_service.get_monitor_log_ws(self.request, self.response_region, self.tenant,
            #                                                       self.service)
            bean.update({"event_websocket_url": event_websocket_url})
            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"])
Exemplo n.º 2
0
    def get(self, request, *args, **kwargs):
        """
        组件详情信息
        ---
        parameters:
            - name: tenantName
              description: 租户名
              required: true
              type: string
              paramType: path
            - name: serviceAlias
              description: 组件别名
              required: true
              type: string
              paramType: path
        """
        bean = dict()
        try:
            # status_map = app_service.get_service_status(self.tenant, self.service)
            # used_resource = app_service.get_service_resource_with_plugin(self.tenant, self.service,
            #                                                              status_map["status"])
            # service_abled_plugins = app_plugin_service.get_service_abled_plugin(self.service)
            # plugin_list = [p.to_dict() for p in service_abled_plugins]
            # bean.update(status_map)
            # bean.update(used_resource)
            # bean.update({"plugin_list": plugin_list})
            service_model = self.service.to_dict()
            group_map = group_service.get_services_group_name(
                [self.service.service_id])
            group_name = group_map.get(self.service.service_id)["group_name"]
            group_id = group_map.get(self.service.service_id)["group_id"]
            service_model["group_name"] = group_name
            service_model["group_id"] = group_id
            bean.update({"service": service_model})
            tenant_actions = self.user.actions.tenant_actions
            bean.update({"tenant_actions": tenant_actions})
            service_actions = self.user.actions.service_actions
            bean.update({"service_actions": service_actions})
            event_websocket_url = ws_service.get_event_log_ws(
                self.request, self.service.service_region)
            bean.update({"event_websocket_url": event_websocket_url})
            if self.service.service_source == "market":
                service_source = service_source_repo.get_service_source(
                    self.tenant.tenant_id, self.service.service_id)
                if not service_source:
                    result = general_message(200, "success", "查询成功", bean=bean)
                    return Response(result, status=result["code"])
                rain_app = rainbond_app_repo.get_rainbond_app_by_key_and_version(
                    service_source.group_key, service_source.version)
                if not rain_app:
                    result = general_message(200,
                                             "success",
                                             "当前云市组件已删除",
                                             bean=bean)
                    return Response(result, status=result["code"])
                else:
                    bean.update({"rain_app_name": rain_app.group_name})
                    apps_template = json.loads(rain_app.app_template)
                    apps_list = apps_template.get("apps")
                    for app in apps_list:
                        if app["service_key"] == self.service.service_key:
                            if self.service.deploy_version and int(
                                    app["deploy_version"]) > int(
                                        self.service.deploy_version):
                                self.service.is_upgrate = True
                                self.service.save()
                                bean.update({"service": service_model})
                    try:
                        apps_template = json.loads(rain_app.app_template)
                        apps_list = apps_template.get("apps")
                        service_source = service_source_repo.get_service_source(
                            self.service.tenant_id, self.service.service_id)
                        if service_source and service_source.extend_info:
                            extend_info = json.loads(
                                service_source.extend_info)
                            if extend_info:
                                for app in apps_list:
                                    if "service_share_uuid" in app:
                                        if app["service_share_uuid"] == extend_info[
                                                "source_service_share_uuid"]:
                                            new_version = int(
                                                app["deploy_version"])
                                            old_version = int(extend_info[
                                                "source_deploy_version"])
                                            if new_version > old_version:
                                                self.service.is_upgrate = True
                                                self.service.save()
                                                service_model[
                                                    "is_upgrade"] = True
                                                bean.update(
                                                    {"service": service_model})
                                    elif "service_share_uuid" not in app and "service_key" in app:
                                        if app["service_key"] == extend_info[
                                                "source_service_share_uuid"]:
                                            new_version = int(
                                                app["deploy_version"])
                                            old_version = int(extend_info[
                                                "source_deploy_version"])
                                            if new_version > old_version:
                                                self.service.is_upgrate = True
                                                self.service.save()
                                                service_model[
                                                    "is_upgrade"] = True
                                                bean.update(
                                                    {"service": service_model})

                    except Exception as e:
                        logger.exception(e)

            if self.service.service_source == AppConstants.DOCKER_COMPOSE:
                if self.service.create_status != "complete":
                    compose_service_relation = compose_service.get_service_compose_id(
                        self.service)
                    if compose_service_relation:
                        service_model[
                            "compose_id"] = compose_service_relation.compose_id
                        bean.update({"service": service_model})
            bean["is_third"] = False
            if self.service.service_source == "third_party":
                bean["is_third"] = True
                service_endpoints = service_endpoints_repo.get_service_endpoints_by_service_id(
                    self.service.service_id)
                if service_endpoints:
                    bean["register_way"] = service_endpoints.endpoints_type
                    if service_endpoints.endpoints_type == "api":
                        # 从环境变量中获取域名,没有在从请求中获取
                        host = os.environ.get('DEFAULT_DOMAIN',
                                              request.get_host())
                        bean["api_url"] = "http://" + host + "/console/" + \
                            "third_party/{0}".format(self.service.service_id)
                        key_repo = deploy_repo.get_service_key_by_service_id(
                            service_id=self.service.service_id)
                        if key_repo:
                            bean["api_service_key"] = pickle.loads(
                                base64.b64decode(
                                    key_repo.secret_key)).get("secret_key")
                    if service_endpoints.endpoints_type == "discovery":
                        # 返回类型和key
                        endpoints_info_dict = json.loads(
                            service_endpoints.endpoints_info)

                        bean["discovery_type"] = endpoints_info_dict["type"]
                        bean["discovery_key"] = endpoints_info_dict["key"]

            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"])
Exemplo n.º 3
0
 def get(self, request, *args, **kwargs):
     """
     应用详情信息
     ---
     parameters:
         - name: tenantName
           description: 租户名
           required: true
           type: string
           paramType: path
         - name: serviceAlias
           description: 服务别名
           required: true
           type: string
           paramType: path
     """
     bean = dict()
     try:
         # status_map = app_service.get_service_status(self.tenant, self.service)
         # used_resource = app_service.get_service_resource_with_plugin(self.tenant, self.service,
         #                                                              status_map["status"])
         # service_abled_plugins = app_plugin_service.get_service_abled_plugin(self.service)
         # plugin_list = [p.to_dict() for p in service_abled_plugins]
         # bean.update(status_map)
         # bean.update(used_resource)
         # bean.update({"plugin_list": plugin_list})
         service_model = self.service.to_dict()
         group_map = group_service.get_services_group_name(
             [self.service.service_id])
         group_name = group_map.get(self.service.service_id)["group_name"]
         group_id = group_map.get(self.service.service_id)["group_id"]
         service_model["group_name"] = group_name
         service_model["group_id"] = group_id
         bean.update({"service": service_model})
         tenant_actions = self.user.actions.tenant_actions
         bean.update({"tenant_actions": tenant_actions})
         service_actions = self.user.actions.service_actions
         bean.update({"service_actions": service_actions})
         event_websocket_url = ws_service.get_event_log_ws(
             self.request, self.service.service_region)
         bean.update({"event_websocket_url": event_websocket_url})
         if self.service.service_source == "market":
             group_obj = tenant_service_group_repo.get_group_by_service_group_id(
                 self.service.tenant_service_group_id)
             if not group_obj:
                 result = general_message(200, "success", "查询成功", bean=bean)
                 return Response(result, status=result["code"])
             rain_app = rainbond_app_repo.get_rainbond_app_by_key_and_version(
                 group_obj.group_key, group_obj.group_version)
             if not rain_app:
                 result = general_message(200,
                                          "success",
                                          "当前云市应用已删除",
                                          bean=bean)
                 return Response(result, status=result["code"])
             else:
                 apps_template = json.loads(rain_app.app_template)
                 apps_list = apps_template.get("apps")
                 for app in apps_list:
                     if app["service_key"] == self.service.service_key:
                         if app["deploy_version"] > self.service.deploy_version:
                             self.service.is_upgrate = True
                             self.service.save()
                             bean.update({"service": service_model})
         if self.service.service_source == AppConstants.DOCKER_COMPOSE:
             if self.service.create_status != "complete":
                 compose_service_relation = compose_service.get_service_compose_id(
                     self.service)
                 if compose_service_relation:
                     service_model[
                         "compose_id"] = compose_service_relation.compose_id
                     bean.update({"service": service_model})
         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"])