diff --git a/Protos/V1/filters_common.proto b/Protos/V1/filters_common.proto index 73a602c30..d711d7519 100644 --- a/Protos/V1/filters_common.proto +++ b/Protos/V1/filters_common.proto @@ -2,6 +2,7 @@ syntax = "proto3"; package armonik.api.grpc.v1; +import "google/protobuf/duration.proto"; import "google/protobuf/timestamp.proto"; option csharp_namespace = "ArmoniK.Api.gRPC.V1"; @@ -71,3 +72,17 @@ message FilterBoolean { bool value = 1; FilterBooleanOperator operator = 2; } + +enum FilterDurationOperator { + FILTER_DURATION_OPERATOR_EQUAL = 0; /** Equal */ + FILTER_DURATION_OPERATOR_NOT_EQUAL = 1; /** Not equal */ + FILTER_DURATION_OPERATOR_SHORTER_THAN = 2; /** Shorter than */ + FILTER_DURATION_OPERATOR_SHORTER_THAN_OR_EQUAL = 3; /** Shorter than or equal */ + FILTER_DURATION_OPERATOR_LONGER_THAN_OR_EQUAL = 4; /** Longer than or equal */ + FILTER_DURATION_OPERATOR_LONGER_THAN = 5; /** Longer than */ +} + +message FilterDuration { + google.protobuf.Duration value = 1; + FilterDurationOperator operator = 2; +} diff --git a/Protos/V1/sessions_filters.proto b/Protos/V1/sessions_filters.proto index b03b3d0a2..fc7157767 100644 --- a/Protos/V1/sessions_filters.proto +++ b/Protos/V1/sessions_filters.proto @@ -22,6 +22,7 @@ message FilterField { FilterStatus filter_status = 5; FilterDate filter_date = 6; FilterArray filter_array = 7; + FilterDuration filter_duration = 8; } } diff --git a/Protos/V1/tasks_filters.proto b/Protos/V1/tasks_filters.proto index c4d01e2ae..887f959f8 100644 --- a/Protos/V1/tasks_filters.proto +++ b/Protos/V1/tasks_filters.proto @@ -22,6 +22,7 @@ message FilterField { FilterStatus filter_status = 5; FilterDate filter_date = 6; FilterArray filter_array = 7; + FilterDuration filter_duration = 8; } } diff --git a/packages/python/src/armonik/client/tasks.py b/packages/python/src/armonik/client/tasks.py index d6fb6876a..18f7c3478 100644 --- a/packages/python/src/armonik/client/tasks.py +++ b/packages/python/src/armonik/client/tasks.py @@ -3,7 +3,7 @@ from typing import cast, Tuple, List from ..common import Task, Direction -from ..common.filter import StringFilter, StatusFilter, DateFilter, NumberFilter, Filter +from ..common.filter import StringFilter, StatusFilter, DateFilter, NumberFilter, Filter, DurationFilter from ..protogen.client.tasks_service_pb2_grpc import TasksStub from ..protogen.common.tasks_common_pb2 import GetTaskRequest, GetTaskResponse, ListTasksRequest, ListTasksDetailedResponse from ..protogen.common.tasks_filters_pb2 import Filters as rawFilters, FiltersAnd as rawFilterAnd, FilterField as rawFilterField, FilterStatus as rawFilterStatus @@ -25,12 +25,15 @@ class TaskFieldFilter: SUBMITTED_AT = DateFilter(TaskField(task_summary_field=TaskSummaryField(field=TASK_SUMMARY_ENUM_FIELD_SUBMITTED_AT)), rawFilters, rawFilterAnd, rawFilterField) STARTED_AT = DateFilter(TaskField(task_summary_field=TaskSummaryField(field=TASK_SUMMARY_ENUM_FIELD_STARTED_AT)), rawFilters, rawFilterAnd, rawFilterField) ENDED_AT = DateFilter(TaskField(task_summary_field=TaskSummaryField(field=TASK_SUMMARY_ENUM_FIELD_ENDED_AT)), rawFilters, rawFilterAnd, rawFilterField) + CREATION_TO_END_DURATION = DurationFilter(TaskField(task_summary_field=TaskSummaryField(field=TASK_SUMMARY_ENUM_FIELD_CREATION_TO_END_DURATION)), rawFilters, rawFilterAnd, rawFilterField) + PROCESSING_TO_END_DURATION = DurationFilter(TaskField(task_summary_field=TaskSummaryField(field=TASK_SUMMARY_ENUM_FIELD_PROCESSING_TO_END_DURATION)), rawFilters, rawFilterAnd, rawFilterField) POD_TTL = DateFilter(TaskField(task_summary_field=TaskSummaryField(field=TASK_SUMMARY_ENUM_FIELD_POD_TTL)), rawFilters, rawFilterAnd, rawFilterField) POD_HOSTNAME = StringFilter(TaskField(task_summary_field=TaskSummaryField(field=TASK_SUMMARY_ENUM_FIELD_POD_HOSTNAME)), rawFilters, rawFilterAnd, rawFilterField) RECEIVED_AT = DateFilter(TaskField(task_summary_field=TaskSummaryField(field=TASK_SUMMARY_ENUM_FIELD_RECEIVED_AT)), rawFilters, rawFilterAnd, rawFilterField) ACQUIRED_AT = DateFilter(TaskField(task_summary_field=TaskSummaryField(field=TASK_SUMMARY_ENUM_FIELD_ACQUIRED_AT)), rawFilters, rawFilterAnd, rawFilterField) ERROR = StringFilter(TaskField(task_summary_field=TaskSummaryField(field=TASK_SUMMARY_ENUM_FIELD_ERROR)), rawFilters, rawFilterAnd, rawFilterField) + MAX_DURATION = DurationFilter(TaskField(task_option_field=TaskOptionField(field=TASK_OPTION_ENUM_FIELD_MAX_DURATION)), rawFilters, rawFilterAnd, rawFilterField) MAX_RETRIES = NumberFilter(TaskField(task_option_field=TaskOptionField(field=TASK_OPTION_ENUM_FIELD_MAX_RETRIES)), rawFilters, rawFilterAnd, rawFilterField) PRIORITY = NumberFilter(TaskField(task_option_field=TaskOptionField(field=TASK_OPTION_ENUM_FIELD_PRIORITY)), rawFilters, rawFilterAnd, rawFilterField) PARTITION_ID = StringFilter(TaskField(task_option_field=TaskOptionField(field=TASK_OPTION_ENUM_FIELD_PARTITION_ID)), rawFilters, rawFilterAnd, rawFilterField) diff --git a/packages/python/src/armonik/common/filter.py b/packages/python/src/armonik/common/filter.py index d80ccd312..728f9a0bc 100644 --- a/packages/python/src/armonik/common/filter.py +++ b/packages/python/src/armonik/common/filter.py @@ -3,6 +3,7 @@ from typing import List, Any, Type, Optional, Dict from google.protobuf.message import Message import google.protobuf.timestamp_pb2 as timestamp +import google.protobuf.duration_pb2 as duration from ..protogen.common.filters_common_pb2 import * import json @@ -265,7 +266,9 @@ def to_basic_message(self) -> Message: class DateFilter(Filter): - """Filter for timestamp comparison""" + """ + Filter for timestamp comparison + """ eq_ = FILTER_DATE_OPERATOR_EQUAL ne_ = FILTER_DATE_OPERATOR_NOT_EQUAL lt_ = FILTER_DATE_OPERATOR_BEFORE @@ -282,7 +285,9 @@ def to_basic_message(self) -> Message: class NumberFilter(Filter): - """Filter for int comparison""" + """ + Filter for int comparison + """ eq_ = FILTER_NUMBER_OPERATOR_EQUAL ne_ = FILTER_NUMBER_OPERATOR_NOT_EQUAL lt_ = FILTER_NUMBER_OPERATOR_LESS_THAN @@ -331,3 +336,22 @@ def __init__(self, field: Optional[Message], disjunction_message_type: Type[Mess def to_basic_message(self) -> Message: return self.message_type(field=self.field, filter_array=self.inner_message_type(value=self.value, operator=self.operator)) + + +class DurationFilter(Filter): + """ + Filter for duration comparison + """ + eq_ = FILTER_DURATION_OPERATOR_EQUAL + ne_ = FILTER_DURATION_OPERATOR_NOT_EQUAL + lt_ = FILTER_DURATION_OPERATOR_SHORTER_THAN + le_ = FILTER_DURATION_OPERATOR_SHORTER_THAN_OR_EQUAL + gt_ = FILTER_DURATION_OPERATOR_LONGER_THAN + ge_ = FILTER_DURATION_OPERATOR_LONGER_THAN_OR_EQUAL + value_type_ = duration.Duration + + def __init__(self, field: Optional[Message], disjunction_message_type: Type[Message], conjunction_message_type: Type[Message], message_type: Type[Message], inner_message_type: Optional[Type[Message]] = FilterDuration, filters: Optional[List[List["Filter"]]] = None, value=None, operator=None): + super().__init__(field, disjunction_message_type, conjunction_message_type, message_type, inner_message_type, filters, value, operator) + + def to_basic_message(self) -> Message: + return self.message_type(field=self.field, filter_duration=self.inner_message_type(value=self.value, operator=self.operator))