Skip to content

Commit

Permalink
chore(client): update protogen and fix client
Browse files Browse the repository at this point in the history
  • Loading branch information
joremysh committed Oct 21, 2024
1 parent 954f94b commit 2536887
Show file tree
Hide file tree
Showing 4 changed files with 166 additions and 9 deletions.
77 changes: 75 additions & 2 deletions instill/clients/artifact.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
# pylint: disable=no-member,wrong-import-position,too-many-lines,no-name-in-module
from datetime import datetime
from typing import Callable, List, Optional

# common
from google.protobuf import timestamp_pb2

# artifact
import instill.protogen.artifact.artifact.v1alpha.artifact_pb2 as artifact_interface
import instill.protogen.artifact.artifact.v1alpha.artifact_public_service_pb2_grpc as artifact_service
import instill.protogen.artifact.artifact.v1alpha.chunk_pb2 as chunk_interface
import instill.protogen.artifact.artifact.v1alpha.file_catalog_pb2 as file_catalog_interface
import instill.protogen.artifact.artifact.v1alpha.object_pb2 as object_interface
import instill.protogen.artifact.artifact.v1alpha.qa_pb2 as qa_interface

# common
import instill.protogen.common.healthcheck.v1beta.healthcheck_pb2 as healthcheck
from instill.clients.base import Client, RequestFactory
from instill.clients.instance import InstillInstance
Expand Down Expand Up @@ -520,3 +523,73 @@ def get_file_catalog(
),
metadata=self.host.metadata + self.metadata,
).send_sync()

@grpc_handler
def get_object_upload_url(
self,
namespace_id: str,
object_name: str,
url_expire_days: int,
last_modified_time: datetime,
object_expire_days: int,
async_enabled: bool = False,
) -> object_interface.GetObjectUploadURLResponse:
timestamp = timestamp_pb2.Timestamp()
timestamp.FromDatetime(last_modified_time)

if async_enabled:
return RequestFactory(
method=self.host.async_client.GetObjectUploadURL,
request=object_interface.GetObjectUploadURLRequest(
namespace_id=namespace_id,
object_name=object_name,
url_expire_days=url_expire_days,
last_modified_time=timestamp,
object_expire_days=object_expire_days,
),
metadata=self.host.metadata + self.metadata,
).send_async()

return RequestFactory(
method=self.host.client.GetObjectUploadURL,
request=object_interface.GetObjectUploadURLRequest(
namespace_id=namespace_id,
object_name=object_name,
url_expire_days=url_expire_days,
last_modified_time=timestamp,
object_expire_days=object_expire_days,
),
metadata=self.host.metadata + self.metadata,
).send_sync()

@grpc_handler
def get_object_download_url(
self,
namespace_id: str,
object_uid: str,
object_name: str,
url_expire_days: int,
async_enabled: bool = False,
) -> object_interface.GetObjectDownloadURLResponse:
if async_enabled:
return RequestFactory(
method=self.host.async_client.GetObjectDownloadURL,
request=object_interface.GetObjectDownloadURLRequest(
namespace_id=namespace_id,
object_uid=object_uid,
object_name=object_name,
url_expire_days=url_expire_days,
),
metadata=self.host.metadata + self.metadata,
).send_async()

return RequestFactory(
method=self.host.client.GetObjectDownloadURL,
request=object_interface.GetObjectDownloadURLRequest(
namespace_id=namespace_id,
object_uid=object_uid,
object_name=object_name,
url_expire_days=url_expire_days,
),
metadata=self.host.metadata + self.metadata,
).send_sync()
48 changes: 45 additions & 3 deletions instill/clients/model.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# pylint: disable=no-member,wrong-import-position,too-many-lines,no-name-in-module
from datetime import datetime
from typing import Callable, List, Optional

from google.protobuf import field_mask_pb2
from google.protobuf import field_mask_pb2, timestamp_pb2
from google.protobuf.struct_pb2 import Struct

# common
Expand Down Expand Up @@ -952,7 +953,6 @@ def list_model_runs(
return RequestFactory(
method=self.host.async_client.ListModelRuns,
request=model_interface.ListModelRunsRequest(
view=model_definition_interface.VIEW_FULL,
namespace_id=namespace_id,
model_id=model_id,
page_size=page_size,
Expand All @@ -966,7 +966,6 @@ def list_model_runs(
return RequestFactory(
method=self.host.client.ListModelRuns,
request=model_interface.ListModelRunsRequest(
view=model_definition_interface.VIEW_FULL,
namespace_id=namespace_id,
model_id=model_id,
page_size=page_size,
Expand All @@ -976,3 +975,46 @@ def list_model_runs(
),
metadata=self.host.metadata + self.metadata,
).send_sync()

@grpc_handler
def list_model_runs_by_credit_owner(
self,
start: datetime,
stop: datetime,
page_size: int = 10,
page: int = 0,
order_by: str = "",
filter_str: str = "",
async_enabled: bool = False,
) -> model_interface.ListModelRunsByCreditOwnerResponse:
start_timestamp = timestamp_pb2.Timestamp()
start_timestamp.FromDatetime(start)
stop_timestamp = timestamp_pb2.Timestamp()
stop_timestamp.FromDatetime(stop)

if async_enabled:
return RequestFactory(
method=self.host.async_client.ListModelRunsByCreditOwner,
request=model_interface.ListModelRunsByCreditOwnerRequest(
start=start_timestamp,
stop=stop_timestamp,
page_size=page_size,
page=page,
order_by=order_by,
filter=filter_str,
),
metadata=self.host.metadata + self.metadata,
).send_async()

return RequestFactory(
method=self.host.client.ListModelRunsByCreditOwner,
request=model_interface.ListModelRunsByCreditOwnerRequest(
start=start_timestamp,
stop=stop_timestamp,
page_size=page_size,
page=page,
order_by=order_by,
filter=filter_str,
),
metadata=self.host.metadata + self.metadata,
).send_sync()
48 changes: 45 additions & 3 deletions instill/clients/pipeline.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# pylint: disable=no-member,wrong-import-position,too-many-lines,no-name-in-module
from datetime import datetime
from typing import Callable, List, Optional

from google.protobuf import field_mask_pb2
from google.protobuf import field_mask_pb2, timestamp_pb2
from google.protobuf.struct_pb2 import Struct

# common
Expand Down Expand Up @@ -1329,7 +1330,6 @@ def list_pipeline_runs(
request=pipeline_interface.ListPipelineRunsRequest(
namespace_id=namespace_id,
pipeline_id=pipeline_id,
view=pipeline_interface.Pipeline.VIEW_RECIPE,
page=page,
page_size=total_size,
filter=filter_str,
Expand All @@ -1343,7 +1343,6 @@ def list_pipeline_runs(
request=pipeline_interface.ListPipelineRunsRequest(
namespace_id=namespace_id,
pipeline_id=pipeline_id,
view=pipeline_interface.Pipeline.VIEW_RECIPE,
page=page,
page_size=total_size,
filter=filter_str,
Expand Down Expand Up @@ -1389,6 +1388,49 @@ def list_component_runs(
metadata=self.host.metadata + self.metadata,
).send_sync()

@grpc_handler
def list_pipeline_runs_by_credit_owner(
self,
start: datetime,
stop: datetime,
page: int = 0,
total_size: int = 10,
filter_str: str = "",
order_by: str = "",
async_enabled: bool = False,
) -> pipeline_interface.ListPipelineRunsByCreditOwnerResponse:
start_timestamp = timestamp_pb2.Timestamp()
start_timestamp.FromDatetime(start)
stop_timestamp = timestamp_pb2.Timestamp()
stop_timestamp.FromDatetime(stop)

if async_enabled:
return RequestFactory(
method=self.host.async_client.ListPipelineRunsByCreditOwner,
request=pipeline_interface.ListPipelineRunsByCreditOwnerRequest(
start=start_timestamp,
stop=stop_timestamp,
page=page,
page_size=total_size,
filter=filter_str,
order_by=order_by,
),
metadata=self.host.metadata + self.metadata,
).send_async()

return RequestFactory(
method=self.host.client.ListPipelineRunsByCreditOwner,
request=pipeline_interface.ListPipelineRunsByCreditOwnerRequest(
start=start_timestamp,
stop=stop_timestamp,
page=page,
page_size=total_size,
filter=filter_str,
order_by=order_by,
),
metadata=self.host.metadata + self.metadata,
).send_sync()

@grpc_handler
def list_connections(
self,
Expand Down

0 comments on commit 2536887

Please sign in to comment.