diff --git a/src/spaceone/inventory_v2/interface/grpc/__init__.py b/src/spaceone/inventory_v2/interface/grpc/__init__.py index 3e9d281..45857a9 100644 --- a/src/spaceone/inventory_v2/interface/grpc/__init__.py +++ b/src/spaceone/inventory_v2/interface/grpc/__init__.py @@ -2,8 +2,7 @@ from .region import Region from .collector import Collector from .job import Job - -# from .job_task import JobTask +from .job_task import JobTask _all_ = ["app"] @@ -11,4 +10,4 @@ app.add_service(Region) app.add_service(Collector) app.add_service(Job) -# app.add_service(JobTask) +app.add_service(JobTask) diff --git a/src/spaceone/inventory_v2/interface/grpc/job_task.py b/src/spaceone/inventory_v2/interface/grpc/job_task.py new file mode 100644 index 0000000..ee32f7a --- /dev/null +++ b/src/spaceone/inventory_v2/interface/grpc/job_task.py @@ -0,0 +1,39 @@ +from spaceone.api.inventory_v2.v1 import job_task_pb2, job_task_pb2_grpc +from spaceone.core.pygrpc import BaseAPI + +from spaceone.inventory_v2.service.job_task_service import JobTaskService + + +class JobTask(BaseAPI, job_task_pb2_grpc.JobTaskServicer): + pb2 = job_task_pb2 + pb2_grpc = job_task_pb2_grpc + + def delete(self, request, context): + params, metadata = self.parse_request(request, context) + job_task_svc = JobTaskService(metadata) + job_task_svc.delete(params) + return self.empty() + + def get(self, request, context): + params, metadata = self.parse_request(request, context) + job_task_svc = JobTaskService(metadata) + response = job_task_svc.get(params) + return self.dict_to_message(response) + + def get_detail(self, request, context): + params, metadata = self.parse_request(request, context) + job_task_svc = JobTaskService(metadata) + response = job_task_svc.get_detail(params) + return self.dict_to_message(response) + + def list(self, request, context): + params, metadata = self.parse_request(request, context) + job_task_svc = JobTaskService(metadata) + response = job_task_svc.list(params) + return self.dict_to_message(response) + + def stat(self, request, context): + params, metadata = self.parse_request(request, context) + job_task_svc = JobTaskService(metadata) + response = job_task_svc.stat(params) + return self.dict_to_message(response) diff --git a/src/spaceone/inventory_v2/manager/job_task_detail_manager.py b/src/spaceone/inventory_v2/manager/job_task_detail_manager.py new file mode 100644 index 0000000..c4ad8cd --- /dev/null +++ b/src/spaceone/inventory_v2/manager/job_task_detail_manager.py @@ -0,0 +1,60 @@ +import logging +from typing import Tuple + +from spaceone.core.manager import BaseManager +from spaceone.core.model.mongo_model import QuerySet + +from spaceone.inventory_v2.model.job_task.database import JobTask, JobTaskDetail + +_LOGGER = logging.getLogger(__name__) + + +class JobTaskDetailManager(BaseManager): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.job_task_detail_model = JobTaskDetail + self.job_task_model = JobTask + + def create_job_task_detail_by_task_vo(self, job_task_vo: JobTask) -> JobTaskDetail: + def _rollback(vo: JobTaskDetail): + _LOGGER.info(f"[ROLLBACK] Delete job task detail: {vo.job_task_id}") + vo.delete() + + params = { + "job_task_id": job_task_vo.job_task_id, + "job_id": job_task_vo.job_id, + } + job_task_detail_vo: JobTaskDetail = self.job_task_detail_model.create(params) + + self.transaction.add_rollback(_rollback, job_task_vo) + + return job_task_detail_vo + + def get_job_task_detail( + self, + job_task_id: str, + domain_id: str, + workspace_id: str = None, + user_projects: list = None, + ) -> JobTaskDetail: + conditions = { + "job_task_id": job_task_id, + "domain_id": domain_id, + } + + if workspace_id: + conditions["workspace_id"] = workspace_id + + if user_projects: + conditions["project_id"] = user_projects + + return self.job_task_detail_model.get(**conditions) + + def filter_job_task_details(self, **conditions) -> QuerySet: + return self.job_task_detail_model.filter(**conditions) + + def list_job_task_details(self, query: dict) -> Tuple[QuerySet, int]: + return self.job_task_detail_model.query(**query) + + def stat_job_task_details(self, query: dict) -> dict: + return self.job_task_detail_model.stat(**query) diff --git a/src/spaceone/inventory_v2/manager/job_task_manager.py b/src/spaceone/inventory_v2/manager/job_task_manager.py index f07d55e..364566c 100644 --- a/src/spaceone/inventory_v2/manager/job_task_manager.py +++ b/src/spaceone/inventory_v2/manager/job_task_manager.py @@ -1,9 +1,8 @@ -import copy import logging -import json from typing import Tuple, Union from jsonschema import validate from datetime import datetime + from spaceone.core import config, queue, utils from spaceone.core.manager import BaseManager from spaceone.core.scheduler.task_schema import SPACEONE_TASK_SCHEMA @@ -11,9 +10,7 @@ from spaceone.inventory_v2.manager.cleanup_manager import CleanupManager from spaceone.inventory_v2.manager.job_manager import JobManager - -# from spaceone.inventory.manager.cleanup_manager import CleanupManager -from spaceone.inventory_v2.model.job_task.database import JobTask +from spaceone.inventory_v2.model.job_task.database import JobTask, JobTaskDetail _LOGGER = logging.getLogger(__name__) @@ -22,6 +19,7 @@ class JobTaskManager(BaseManager): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.job_task_model = JobTask + self.job_task_detail_model = JobTaskDetail def create_job_task(self, params: dict) -> JobTask: def _rollback(vo: JobTask): @@ -32,7 +30,21 @@ def _rollback(vo: JobTask): self.transaction.add_rollback(_rollback, job_task_vo) return job_task_vo - def get( + def create_job_task_detail(self, job_task_vo: JobTask) -> JobTaskDetail: + def _rollback(vo: JobTaskDetail): + _LOGGER.info(f"[ROLLBACK] Delete job task detail: {vo.job_task_id}") + vo.delete() + + params = { + "job_task_id": job_task_vo.job_task_id, + "job_id": job_task_vo.job_id, + } + job_task_detail_vo: JobTaskDetail = self.job_task_detail_model.create(params) + self.transaction.add_rollback(_rollback, job_task_vo) + + return job_task_detail_vo + + def get_job_task( self, job_task_id: str, domain_id: str, diff --git a/src/spaceone/inventory_v2/model/__init__.py b/src/spaceone/inventory_v2/model/__init__.py index ef7405a..3602513 100644 --- a/src/spaceone/inventory_v2/model/__init__.py +++ b/src/spaceone/inventory_v2/model/__init__.py @@ -8,4 +8,4 @@ from spaceone.inventory_v2.model.metric_data.database import MetricData from spaceone.inventory_v2.model.metric_example.database import MetricExample from spaceone.inventory_v2.model.job.database import Job -from spaceone.inventory_v2.model.job_task.database import JobTask +from spaceone.inventory_v2.model.job_task.database import JobTask, JobTaskDetail diff --git a/src/spaceone/inventory_v2/model/collector/request.py b/src/spaceone/inventory_v2/model/collector/request.py index 8c0bd6e..1cbd1e1 100644 --- a/src/spaceone/inventory_v2/model/collector/request.py +++ b/src/spaceone/inventory_v2/model/collector/request.py @@ -83,6 +83,6 @@ class CollectorStatQueryRequest(BaseModel): class CollectorCollectRequest(BaseModel): collector_id: str - secret_id: str + secret_id: Union[str, None] = None workspace_id: Union[list, str, None] = None domain_id: str diff --git a/src/spaceone/inventory_v2/model/job_task/database.py b/src/spaceone/inventory_v2/model/job_task/database.py index 43e218f..442a1db 100644 --- a/src/spaceone/inventory_v2/model/job_task/database.py +++ b/src/spaceone/inventory_v2/model/job_task/database.py @@ -2,12 +2,6 @@ from spaceone.core.model.mongo_model import MongoModel -class Error(EmbeddedDocument): - error_code = StringField() - message = StringField() - additional = DictField() - - class JobTask(MongoModel): job_task_id = StringField(max_length=40, generate_id="job-task", unique=True) status = StringField( @@ -15,7 +9,6 @@ class JobTask(MongoModel): default="PENDING", choices=("PENDING", "CANCELED", "IN_PROGRESS", "SUCCESS", "FAILURE"), ) - provider = StringField(max_length=40, default=None, null=True) total_sub_tasks = IntField(default=0) remained_sub_tasks = IntField(default=0) created_count = IntField(default=0) @@ -24,7 +17,6 @@ class JobTask(MongoModel): disconnected_count = IntField(default=0) failure_count = IntField(default=0) total_count = IntField(default=0) - errors = ListField(EmbeddedDocumentField(Error, default=None, null=True)) job_id = StringField(max_length=40) secret_id = StringField(max_length=40) collector_id = StringField(max_length=40) @@ -33,21 +25,21 @@ class JobTask(MongoModel): workspace_id = StringField(max_length=40) domain_id = StringField(max_length=40) created_at = DateTimeField(auto_now_add=True) + updated_at = DateTimeField(auto_now=True) started_at = DateTimeField(default=None, null=True) finished_at = DateTimeField(default=None, null=True) meta = { "updatable_fields": [ "status", - "provider", "remained_sub_tasks", "created_count", "updated_count", "deleted_count", "disconnected_count", "failure_count", - "errors", "started_at", + "updated_at", "finished_at", ], "minimal_fields": [ @@ -90,3 +82,34 @@ class JobTask(MongoModel): "domain_id", ], } + + +class JobTaskDetail(MongoModel): + job_task_id = StringField(max_length=40, unique_with=["job_task_id", "job_id"]) + created_info = DictField(default=None, null=True) + updated_info = DictField(default=None, null=True) + failure_info = DictField(default=None, null=True) + deleted_info = DictField(default=None, null=True) + disconnected_info = DictField(default=None, null=True) + job_id = StringField(max_length=40) + project_id = StringField(max_length=40) + workspace_id = StringField(max_length=40) + domain_id = StringField(max_length=40) + created_at = DateTimeField(auto_now_add=True) + + meta = { + "updatable_fields": [ + "created_info", + "updated_info", + "deleted_info", + "disconnected_info", + ], + "minimal_fields": ["job_task_id", "created_info", "job_id"], + "ordering": ["-created_at"], + "indexes": [ + "job_task_id", + "job_id", + "project_id", + "workspace_id", + ], + } diff --git a/src/spaceone/inventory_v2/model/job_task/request.py b/src/spaceone/inventory_v2/model/job_task/request.py new file mode 100644 index 0000000..35d27c7 --- /dev/null +++ b/src/spaceone/inventory_v2/model/job_task/request.py @@ -0,0 +1,53 @@ +from typing import Union, Literal, List +from pydantic import BaseModel + +__all__ = [ + "JobTaskDeleteRequest", + "JobTaskGetRequest", + "JobTaskGetDetailRequest", + "JobTaskSearchQueryRequest", + "JobTaskStatQueryRequest", + "Status", +] + +Status = Literal["PENDING", "IN_PROGRESS", "SUCCESS", "FAILURE", "CANCELLED"] + + +class JobTaskDeleteRequest(BaseModel): + job_task_id: str + workspace_id: Union[str, None] + domain_id: str + + +class JobTaskGetRequest(BaseModel): + job_task_id: str + workspace_id: Union[str, None] + domain_id: str + user_projects: Union[List[str], None] + + +class JobTaskGetDetailRequest(BaseModel): + job_task_id: str + workspace_id: Union[str, None] + domain_id: str + user_projects: Union[List[str], None] + + +class JobTaskSearchQueryRequest(BaseModel): + query: dict + job_task_id: Union[str, None] + status: Union[Status, None] + provider: Union[str, None] + job_id: Union[str, None] + secret_id: Union[str, None] + service_account_id: Union[str, None] + project_id: Union[str, None] + workspace_id: Union[str, None] + domain_id: str + + +class JobTaskStatQueryRequest(BaseModel): + query: dict + workspace_id: Union[str, None] = None + domain_id: str + user_projects: Union[List[str], None] = None diff --git a/src/spaceone/inventory_v2/model/job_task/response.py b/src/spaceone/inventory_v2/model/job_task/response.py new file mode 100644 index 0000000..ee1c88e --- /dev/null +++ b/src/spaceone/inventory_v2/model/job_task/response.py @@ -0,0 +1,62 @@ +from datetime import datetime +from typing import Union, Literal, List +from pydantic import BaseModel + +from spaceone.core import utils + +from spaceone.inventory_v2.model.job_task.request import Status + +__all__ = ["JobTaskResponse", "JobTasksResponse", "JobTaskDetailResponse"] + + +class JobTaskResponse(BaseModel): + job_task_id: Union[str, None] = None + status: Union[Status, None] = None + provider: Union[str, None] = None + created_count: Union[int, None] = None + updated_count: Union[int, None] = None + failure_count: Union[int, None] = None + deleted_count: Union[int, None] = None + disconnected_count: Union[int, None] = None + job_id: Union[str, None] = None + secret_id: Union[str, None] = None + service_account_id: Union[str, None] = None + collector_id: Union[str, None] = None + project_id: Union[str, None] = None + workspace_id: Union[str, None] = None + domain_id: Union[str, None] = None + created_at: Union[datetime, None] = None + started_at: Union[datetime, None] = None + updated_at: Union[datetime, None] = None + finished_at: Union[datetime, None] = None + + def dict(self, *args, **kwargs): + data = super().dict(*args, **kwargs) + data["created_at"] = utils.datetime_to_iso8601(data["created_at"]) + data["started_at"] = utils.datetime_to_iso8601(data.get("started_at")) + data["updated_at"] = utils.datetime_to_iso8601(data.get("updated_at")) + data["finished_at"] = utils.datetime_to_iso8601(data.get("finished_at")) + return data + + +class JobTaskDetailResponse(BaseModel): + job_task_id: Union[str, None] = None + created_info: Union[dict, None] = None + updated_info: Union[dict, None] = None + failure_info: Union[dict, None] = None + deleted_info: Union[dict, None] = None + disconnected_info: Union[dict, None] = None + job_id: Union[str, None] = None + project_id: Union[str, None] = None + workspace_id: Union[str, None] = None + domain_id: Union[str, None] = None + created_at: Union[datetime, None] = None + + def dict(self, *args, **kwargs): + data = super().dict(*args, **kwargs) + data["created_at"] = utils.datetime_to_iso8601(data["created_at"]) + + +class JobTasksResponse(BaseModel): + results: List[JobTaskResponse] + total_count: Union[int, None] = None diff --git a/src/spaceone/inventory_v2/service/collector_service.py b/src/spaceone/inventory_v2/service/collector_service.py index 6d3a92e..50befd2 100644 --- a/src/spaceone/inventory_v2/service/collector_service.py +++ b/src/spaceone/inventory_v2/service/collector_service.py @@ -17,6 +17,7 @@ from spaceone.inventory_v2.manager.collector_rule_manager import CollectorRuleManager from spaceone.inventory_v2.manager.identity_manager import IdentityManager from spaceone.inventory_v2.manager.job_manager import JobManager +from spaceone.inventory_v2.manager.job_task_detail_manager import JobTaskDetailManager from spaceone.inventory_v2.manager.job_task_manager import JobTaskManager from spaceone.inventory_v2.manager.plugin_manager import PluginManager from spaceone.inventory_v2.manager.repository_manager import RepositoryManager @@ -202,7 +203,7 @@ def update(self, params: CollectorUpdateRequest) -> Union[CollectorResponse, dic ) @convert_model def update_plugin( - self, params: CollectorUpdatePluginRequest + self, params: CollectorUpdatePluginRequest ) -> Union[CollectorResponse, dict]: """Update plugin info of collector Args: @@ -405,7 +406,7 @@ def get(self, params: CollectorGetRequest) -> Union[CollectorResponse, dict]: @change_value_by_rule("APPEND", "workspace_id", "*") @convert_model def list( - self, params: CollectorSearchQueryRequest + self, params: CollectorSearchQueryRequest ) -> Union[CollectorsResponse, dict]: """List collectors Args: @@ -475,9 +476,10 @@ def collect(self, params: CollectorCollectRequest) -> Union[JobResponse, dict]: job_vo (object) """ - plugin_mgr: PluginManager = self.locator.get_manager(PluginManager) - job_mgr: JobManager = self.locator.get_manager(JobManager) - job_task_mgr: JobTaskManager = self.locator.get_manager(JobTaskManager) + plugin_mgr = PluginManager() + job_mgr = JobManager() + job_task_mgr = JobTaskManager() + task_detail_mgr = JobTaskDetailManager() collector_id = params.collector_id domain_id = params.domain_id @@ -566,6 +568,9 @@ def collect(self, params: CollectorCollectRequest) -> Union[JobResponse, dict]: try: # create job task job_task_vo = job_task_mgr.create_job_task(create_params) + task_detail_vo = task_detail_mgr.create_job_task_detail_by_task_vo( + job_task_vo + ) task.update({"job_task_id": job_task_vo.job_task_id}) if len(sub_tasks) > 0: @@ -599,15 +604,15 @@ def collect(self, params: CollectorCollectRequest) -> Union[JobResponse, dict]: return JobResponse(**job_vo.to_dict()) def _get_tasks( - self, - params: dict, - endpoint: str, - collector_id: str, - collector_provider: str, - plugin_info: dict, - secret_filter: dict, - domain_id: str, - collector_workspace_id: str = None, + self, + params: dict, + endpoint: str, + collector_id: str, + collector_provider: str, + plugin_info: dict, + secret_filter: dict, + domain_id: str, + collector_workspace_id: str = None, ) -> list: secret_mgr: SecretManager = self.locator.get_manager(SecretManager) collector_plugin_mgr = CollectorPluginManager() @@ -644,7 +649,7 @@ def _get_tasks( @staticmethod def _check_secrets( - secret_mgr: SecretManager, secret_ids: list, provider: str, domain_id: str + secret_mgr: SecretManager, secret_ids: list, provider: str, domain_id: str ) -> None: query = { "filter": [ @@ -664,10 +669,10 @@ def _check_secrets( @staticmethod def _check_service_accounts( - identity_mgr: IdentityManager, - service_account_ids: list, - provider: str, - domain_id: str, + identity_mgr: IdentityManager, + service_account_ids: list, + provider: str, + domain_id: str, ) -> None: query = { "filter": [ @@ -692,10 +697,10 @@ def _check_service_accounts( @staticmethod def _check_schemas( - identity_mgr: IdentityManager, - schema_ids: list, - provider: str, - domain_id: str, + identity_mgr: IdentityManager, + schema_ids: list, + provider: str, + domain_id: str, ) -> None: query = { "filter": [ @@ -719,12 +724,12 @@ def _check_schemas( ) def _validate_secret_filter( - self, - identity_mgr: IdentityManager, - secret_mgr: SecretManager, - secret_filter: dict, - provider: str, - domain_id: str, + self, + identity_mgr: IdentityManager, + secret_mgr: SecretManager, + secret_filter: dict, + provider: str, + domain_id: str, ) -> None: if "secrets" in secret_filter: self._check_secrets( @@ -760,11 +765,11 @@ def _validate_secret_filter( ) def _update_collector_plugin( - self, - endpoint: str, - updated_version: str, - plugin_info: dict, - collector_vo: Collector, + self, + endpoint: str, + updated_version: str, + plugin_info: dict, + collector_vo: Collector, ) -> Collector: collector_plugin_mgr = CollectorPluginManager() plugin_response = collector_plugin_mgr.init_plugin( @@ -794,12 +799,12 @@ def _update_collector_plugin( return collector_vo def _get_secret_ids_from_filter( - self, - secret_filter: dict, - provider: str, - domain_id: str, - secret_id: str = None, - workspace_id: str = None, + self, + secret_filter: dict, + provider: str, + domain_id: str, + secret_id: str = None, + workspace_id: str = None, ) -> list: secret_manager: SecretManager = self.locator.get_manager(SecretManager) @@ -846,11 +851,11 @@ def _get_plugin_from_repository(plugin_id: str) -> dict: @staticmethod def create_collector_rules_by_metadata( - collector_rules: list, - collector_id: str, - resource_group: str, - domain_id: str, - workspace_id: str = None, + collector_rules: list, + collector_id: str, + resource_group: str, + domain_id: str, + workspace_id: str = None, ): collector_rule_mgr = CollectorRuleManager() @@ -877,10 +882,10 @@ def delete_collector_rules(collector_id: str, domain_id: str) -> None: @staticmethod def _make_secret_filter( - secret_filter: dict, - provider: str, - secret_id: str = None, - workspace_id: str = None, + secret_filter: dict, + provider: str, + secret_id: str = None, + workspace_id: str = None, ) -> list: _filter = [{"k": "provider", "v": provider, "o": "eq"}] @@ -906,7 +911,7 @@ def _make_secret_filter( _filter.append({"k": "secret_id", "v": exclude_secrets, "o": "not_in"}) if exclude_service_accounts := secret_filter.get( - "exclude_service_accounts" + "exclude_service_accounts" ): _filter.append( { diff --git a/src/spaceone/inventory_v2/service/job_task_service.py b/src/spaceone/inventory_v2/service/job_task_service.py new file mode 100644 index 0000000..a9a236a --- /dev/null +++ b/src/spaceone/inventory_v2/service/job_task_service.py @@ -0,0 +1,172 @@ +from typing import Union + +from spaceone.core.service import * + +from spaceone.inventory_v2.manager.job_task_detail_manager import JobTaskDetailManager +from spaceone.inventory_v2.manager.job_task_manager import JobTaskManager +from spaceone.inventory_v2.model.job_task.database import JobTask +from spaceone.inventory_v2.model.job_task.request import * +from spaceone.inventory_v2.model.job_task.response import * + + +@authentication_handler +@authorization_handler +@mutation_handler +@event_handler +class JobTaskService(BaseService): + resource = "JobTask" + + def __init__(self, metadata): + super().__init__(metadata) + self.job_task_mgr = JobTaskManager() + self.job_task_detail_mgr = JobTaskDetailManager() + + @transaction( + permission="inventory-v2:JobTask.write", + role_types=["DOMAIN_ADMIN", "WORKSPACE_OWNER"], + ) + @convert_model + def delete(self, params: JobTaskDeleteRequest) -> None: + """ + Args: + params (dict): { + 'job_task_id': 'str', # required + 'workspace_id': 'str', # injected from auth + 'domain_id': 'str' # injected from auth (required) + } + + Returns: + None + """ + + job_task_id = params.job_task_id + domain_id = params.domain_id + workspace_id = params.workspace_id + + job_task_vo: JobTask = self.job_task_mgr.get( + job_task_id, domain_id, workspace_id + ) + self.job_task_mgr.delete_job_task_by_vo(job_task_vo) + + @transaction( + permission="inventory-v2:JobTask.read", + role_types=["DOMAIN_ADMIN", "WORKSPACE_OWNER", "WORKSPACE_MEMBER"], + ) + @convert_model + def get(self, params: JobTaskGetRequest) -> Union[JobTaskResponse, dict]: + """ + Args: + params (dict): { + 'job_task_id': 'str', # required + 'workspace_id': 'str', # injected from auth + 'domain_id': 'str', # injected from auth (required) + 'user_projects': 'list' # injected from auth + } + + Returns: + job_task_vo (object) + """ + + job_task_vo = self.job_task_mgr.get_job_task( + params.job_task_id, + params.domain_id, + params.workspace_id, + params.user_projects, + ) + + return JobTaskResponse(**job_task_vo.to_dict()) + + @transaction( + permission="inventory-v2:JobTask.read", + role_types=["DOMAIN_ADMIN", "WORKSPACE_OWNER", "WORKSPACE_MEMBER"], + ) + @convert_model + def get_detail( + self, params: JobTaskGetDetailRequest + ) -> Union[JobTaskDetailResponse, dict]: + """ + Args: + params (dict): { + } + Returns: + job_task_detail_vo (object) + """ + + job_task_detail_vo = self.job_task_detail_mgr.get_job_task_detail( + params.job_task_id, + params.domain_id, + params.workspace_id, + params.user_projects, + ) + return JobTaskDetailResponse(**job_task_detail_vo.to_dict()) + + @transaction( + permission="inventory-v2:JobTask.read", + role_types=["DOMAIN_ADMIN", "WORKSPACE_OWNER", "WORKSPACE_MEMBER"], + ) + @append_query_filter( + [ + "job_task_id", + "status", + "provider", + "job_id", + "secret_id", + "service_account_id", + "project_id", + "workspace_id", + "domain_id", + "user_projects", + ] + ) + @append_keyword_filter(["job_task_id"]) + @convert_model + def list(self, params: JobTaskSearchQueryRequest) -> Union[JobTasksResponse, dict]: + """ + Args: + params (dict): { + 'query': 'dict (spaceone.api.core.v2.Query)', + 'job_task_id': 'str', + 'status': 'str', + 'job_id': 'str', + 'secret_id': 'str', + 'provider': 'str', + 'service_account_id': 'str', + 'project_id': 'str', + 'workspace_id': 'str', # injected from auth + 'domain_id ': 'str', # injected from auth (required) + 'user_projects': 'list', # injected from auth + } + + Returns: + results (list) + total_count (int) + """ + query = params.query or {} + + job_task_vos, total_count = self.job_task_mgr.list(query) + + job_task_infos = [job_task_vo.to_dict() for job_task_vo in job_task_vos] + return JobTasksResponse(results=job_task_infos, total_count=total_count) + + @transaction( + permission="inventory-v2:JobTask.read", + role_types=["DOMAIN_ADMIN", "WORKSPACE_OWNER", "WORKSPACE_MEMBER"], + ) + @append_keyword_filter(["job_task_id"]) + @convert_model + def stat(self, params: JobTaskStatQueryRequest) -> dict: + """ + Args: + params (dict): { + 'query': 'dict (spaceone.api.core.v1.StatisticsQuery)', # required + 'workspace_id': 'str', # injected from auth + 'domain_id': 'str', # injected from auth (required) + 'user_projects': 'list', # injected from auth + } + + Returns: + values (list) : 'list of statistics data' + """ + + query = params.query or {} + return self.job_task_mgr.stat(query)