Skip to content

Commit 3c910c5

Browse files
authored
Merge pull request #12 from KavinKrishnan/main
Adding Ability to Retrieve Job Operator Details
2 parents d919cf7 + dd1c2ab commit 3c910c5

File tree

5 files changed

+41
-9
lines changed

5 files changed

+41
-9
lines changed

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ $ python3 -m pip install claraclient
5050
>>> job_list = jobs_client.list_jobs(job_filter=job_filter)
5151
[<job_types.JobInfo object at 0x058908E0>, <job_types.JobInfo object at 0x063208E0>]
5252

53-
# Identifier of created pipeline (ex. HQS)
54-
>>> hqs_pipeline_id = "dd05c5b79461402cb0a610d4f0fce36f"
53+
# Identifier of created pipeline (ex. colon tumor segmentation)
54+
>>> colon_tumor_pipeline_id = "dd05c5b79461402cb0a610d4f0fce36f"
5555

5656
# Create Job
57-
>>> job_info = jobs_client.create_job(job_name="hqstest",pipeline_id=pipeline_types.PipelineId(hqs_pipeline_id))
57+
>>> job_info = jobs_client.create_job(job_name="colontumor",pipeline_id=pipeline_types.PipelineId(colon_tumor_pipeline_id))
5858
<job_types.JobInfo object at 0x05369B78>
5959

6060
>>> job_info.job_id.value
@@ -70,6 +70,10 @@ $ python3 -m pip install claraclient
7070
>>> job_token.job_status
7171
1
7272

73+
# Gets List of Operators
74+
>>> job_details.operator_details.keys()
75+
["colon-tumor-segmentation","dicom-reader","dicom-writer","register-dicom-output","register-volume-images-for-rendering"]
76+
7377
# Get Status of Job from Identifier
7478
>>> job_details = jobs_client.get_status(job_id=job_token.job_id)
7579
<job_types.JobDetails object at 0x05373B78>

examples/jobs_client_example.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@
2929
job_list = jobs_client.list_jobs(job_filter=job_filter)
3030
print(job_list)
3131

32-
# Identifier of created pipeline (ex. HQS)
33-
hqs_pipeline_id = "f9a843935e654a30beb9d1b8352bfaac"
32+
# Identifier of created pipeline (ex. colon tumor segmentation)
33+
colon_tumor_pipeline_id = "f9a843935e654a30beb9d1b8352bfaac"
3434

3535
# Create Job
36-
job_info = jobs_client.create_job(job_name="hqstest",pipeline_id=pipeline_types.PipelineId(hqs_pipeline_id))
36+
job_info = jobs_client.create_job(job_name="colontumor",pipeline_id=pipeline_types.PipelineId(colon_tumor_pipeline_id))
3737
print(job_info.job_id.value)
3838

3939
# Start Job
@@ -47,6 +47,9 @@
4747
print(job_details.job_state)
4848
print(job_details.job_status)
4949

50+
# Gets List of Operators
51+
print(job_details.operator_details.keys())
52+
5053
# Try Canceling Job (if still running)
5154
try:
5255
job_details = jobs_client.cancel_job(job_id=job_token.job_id)

nvidia_clara/job_types.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@
1414

1515
from datetime import datetime
1616
from enum import Enum
17-
from typing import List
17+
from typing import List, Mapping, TypeVar
1818
from nvidia_clara.grpc import common_pb2, jobs_pb2
1919
import nvidia_clara.payload_types as payload_types
2020
import nvidia_clara.pipeline_types as pipeline_types
2121

22+
T = TypeVar('T')
23+
2224

2325
class JobPriority(Enum):
2426
"""
@@ -346,7 +348,8 @@ class JobDetails(JobInfo):
346348
def __init__(self, job_id: JobId = None, job_state: JobState = None, job_status: JobStatus = None,
347349
job_priority: JobPriority = None, date_created: datetime = None, date_started: datetime = None,
348350
date_stopped: datetime = None, name: str = None, payload_id: payload_types.PayloadId = None,
349-
pipeline_id: pipeline_types.PipelineId = None, messages: List[str] = None):
351+
pipeline_id: pipeline_types.PipelineId = None, operator_details: Mapping[str, Mapping[str, T]] = None,
352+
messages: List[str] = None):
350353
super().__init__(
351354
job_id=job_id,
352355
job_state=job_state,
@@ -360,6 +363,7 @@ def __init__(self, job_id: JobId = None, job_state: JobState = None, job_status:
360363
pipeline_id=pipeline_id
361364
)
362365
self._messages = messages
366+
self._operator_details = operator_details
363367

364368
@property
365369
def messages(self) -> List[str]:
@@ -370,3 +374,13 @@ def messages(self) -> List[str]:
370374
def messages(self, messages: List[str]):
371375
"""List of messages reported by the job."""
372376
self._messages = messages
377+
378+
@property
379+
def operator_details(self) -> Mapping[str, Mapping[str, T]]:
380+
"""Dictionary mapping operator names to operator details"""
381+
return self._operator_details
382+
383+
@operator_details.setter
384+
def operator_details(self, operator_details: Mapping[str, Mapping[str, T]]):
385+
"""Dictionary mapping operator names to operator details"""
386+
self._operator_details = operator_details

nvidia_clara/jobs_client.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,16 @@ def get_status(self, job_id: job_types.JobId, timeout=None) -> job_types.JobDeta
327327

328328
self.check_response_header(header=response.header)
329329

330+
resp_operator_details = response.operator_details
331+
operator_details = {}
332+
333+
for item in resp_operator_details:
334+
operator_details[item.name] = {}
335+
operator_details[item.name]["created"] = item.created
336+
operator_details[item.name]["started"] = item.started
337+
operator_details[item.name]["stopped"] = item.stopped
338+
operator_details[item.name]["status"] = item.status
339+
330340
result = job_types.JobDetails(
331341
job_id=job_types.JobId(response.job_id.value),
332342
job_priority=response.priority,
@@ -338,6 +348,7 @@ def get_status(self, job_id: job_types.JobId, timeout=None) -> job_types.JobDeta
338348
date_created=self.get_timestamp(response.created),
339349
date_started=self.get_timestamp(response.started),
340350
date_stopped=self.get_timestamp(response.stopped),
351+
operator_details=operator_details,
341352
messages=response.messages
342353
)
343354

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
setuptools.setup(
2121
name="claraclient",
22-
version="0.7.6",
22+
version="0.7.7",
2323
author="NVIDIA Clara Deploy",
2424
description="Python package to interact with Clara Platform Server API",
2525
license='Apache Software License (http://www.apache.org/licenses/LICENSE-2.0)',

0 commit comments

Comments
 (0)