3535from ads .jobs .builders .runtimes .container_runtime import ContainerRuntime
3636from ads .jobs .builders .runtimes .python_runtime import GitPythonRuntime
3737
38- from ads .common .dsc_file_system import (
39- OCIFileStorage ,
40- DSCFileSystemManager
41- )
38+ from ads .common .dsc_file_system import OCIFileStorage , DSCFileSystemManager
4239
4340logger = logging .getLogger (__name__ )
4441
@@ -445,6 +442,8 @@ def run(self, **kwargs) -> DataScienceJobRun:
445442 * command_line_arguments: str
446443 * maximum_runtime_in_minutes: int
447444 * display_name: str
445+ * freeform_tags: dict(str, str)
446+ * defined_tags: dict(str, dict(str, object))
448447
449448 If display_name is not specified, it will be generated as "<JOB_NAME>-run-<TIMESTAMP>".
450449
@@ -845,9 +844,12 @@ class DataScienceJob(Infrastructure):
845844 .with_storage_mount(
846845 {
847846 "src" : "<mount_target_ip_address>:<export_path>",
848- "dest" : "<destination_directory_name>"
847+ "dest" : "<destination_directory_name>"
849848 }
850849 )
850+ # Tags
851+ .with_freeform_tag(my_tag="my_value")
852+ .with_defined_tag(**{"Operations": {"CostCenter": "42"}})
851853 )
852854
853855 """
@@ -866,6 +868,8 @@ class DataScienceJob(Infrastructure):
866868 CONST_LOG_ID = "logId"
867869 CONST_LOG_GROUP_ID = "logGroupId"
868870 CONST_STORAGE_MOUNT = "storageMount"
871+ CONST_FREEFORM_TAGS = "freeformTags"
872+ CONST_DEFINED_TAGS = "definedTags"
869873
870874 attribute_map = {
871875 CONST_PROJECT_ID : "project_id" ,
@@ -880,6 +884,8 @@ class DataScienceJob(Infrastructure):
880884 CONST_LOG_ID : "log_id" ,
881885 CONST_LOG_GROUP_ID : "log_group_id" ,
882886 CONST_STORAGE_MOUNT : "storage_mount" ,
887+ CONST_FREEFORM_TAGS : "freeform_tags" ,
888+ CONST_DEFINED_TAGS : "defined_tags" ,
883889 }
884890
885891 shape_config_details_attribute_map = {
@@ -1231,9 +1237,7 @@ def log_group_id(self) -> str:
12311237 """
12321238 return self .get_spec (self .CONST_LOG_GROUP_ID )
12331239
1234- def with_storage_mount (
1235- self , * storage_mount : List [dict ]
1236- ) -> DataScienceJob :
1240+ def with_storage_mount (self , * storage_mount : List [dict ]) -> DataScienceJob :
12371241 """Sets the file systems to be mounted for the data science job.
12381242 A maximum number of 5 file systems are allowed to be mounted for a single data science job.
12391243
@@ -1271,6 +1275,36 @@ def storage_mount(self) -> List[dict]:
12711275 """
12721276 return self .get_spec (self .CONST_STORAGE_MOUNT , [])
12731277
1278+ def with_freeform_tag (self , ** kwargs ) -> DataScienceJob :
1279+ """Sets freeform tags
1280+
1281+ Returns
1282+ -------
1283+ DataScienceJob
1284+ The DataScienceJob instance (self)
1285+ """
1286+ return self .set_spec (self .CONST_FREEFORM_TAGS , kwargs )
1287+
1288+ def with_defined_tag (self , ** kwargs ) -> DataScienceJob :
1289+ """Sets defined tags
1290+
1291+ Returns
1292+ -------
1293+ DataScienceJob
1294+ The DataScienceJob instance (self)
1295+ """
1296+ return self .set_spec (self .CONST_DEFINED_TAGS , kwargs )
1297+
1298+ @property
1299+ def freeform_tags (self ) -> dict :
1300+ """Freeform tags"""
1301+ return self .get_spec (self .CONST_FREEFORM_TAGS , {})
1302+
1303+ @property
1304+ def defined_tags (self ) -> dict :
1305+ """Defined tags"""
1306+ return self .get_spec (self .CONST_DEFINED_TAGS , {})
1307+
12741308 def _prepare_log_config (self ) -> dict :
12751309 if not self .log_group_id and not self .log_id :
12761310 return None
@@ -1425,7 +1459,8 @@ def _update_job_infra(self, dsc_job: DSCJob) -> DataScienceJob:
14251459 "Storage mount hasn't been supported in the current OCI SDK installed."
14261460 )
14271461 dsc_job .job_storage_mount_configuration_details_list = [
1428- DSCFileSystemManager .initialize (file_system ) for file_system in self .storage_mount
1462+ DSCFileSystemManager .initialize (file_system )
1463+ for file_system in self .storage_mount
14291464 ]
14301465 return self
14311466
@@ -1467,6 +1502,10 @@ def create(self, runtime, **kwargs) -> DataScienceJob:
14671502
14681503 payload ["display_name" ] = display_name
14691504 payload ["job_log_configuration_details" ] = self ._prepare_log_config ()
1505+ if not payload .get ("freeform_tags" ):
1506+ payload ["freeform_tags" ] = self .freeform_tags
1507+ if not payload .get ("defined_tags" ):
1508+ payload ["defined_tags" ] = self .defined_tags
14701509
14711510 self .dsc_job = DSCJob (** payload )
14721511 # Set Job infra to user values after DSCJob initialized the defaults
@@ -1477,7 +1516,13 @@ def create(self, runtime, **kwargs) -> DataScienceJob:
14771516 return self
14781517
14791518 def run (
1480- self , name = None , args = None , env_var = None , freeform_tags = None , wait = False
1519+ self ,
1520+ name = None ,
1521+ args = None ,
1522+ env_var = None ,
1523+ freeform_tags = None ,
1524+ defined_tags = None ,
1525+ wait = False ,
14811526 ) -> DataScienceJobRun :
14821527 """Runs a job on OCI Data Science job
14831528
@@ -1491,6 +1536,8 @@ def run(
14911536 Environment variable for the job run, by default None
14921537 freeform_tags : dict, optional
14931538 Freeform tags for the job run, by default None
1539+ defined_tags : dict, optional
1540+ Defined tags for the job run, by default None
14941541 wait : bool, optional
14951542 Indicate if this method should wait for the run to finish before it returns, by default False.
14961543
@@ -1505,11 +1552,18 @@ def run(
15051552 raise RuntimeError (
15061553 "Job is not created. Call create() to create the job first."
15071554 )
1508- tags = self .runtime .freeform_tags
1509- if not tags :
1510- tags = {}
1511- if freeform_tags :
1512- tags .update (freeform_tags )
1555+
1556+ if not freeform_tags :
1557+ freeform_tags = {}
1558+ runtime_freeform_tags = self .runtime .freeform_tags
1559+ if runtime_freeform_tags :
1560+ freeform_tags .update (runtime_freeform_tags )
1561+
1562+ if not defined_tags :
1563+ defined_tags = {}
1564+ runtime_defined_tags = self .runtime .defined_tags
1565+ if runtime_defined_tags :
1566+ defined_tags .update (runtime_defined_tags )
15131567
15141568 if name :
15151569 envs = self .runtime .envs
@@ -1521,7 +1575,8 @@ def run(
15211575 display_name = name ,
15221576 command_line_arguments = args ,
15231577 environment_variables = env_var ,
1524- freeform_tags = tags ,
1578+ freeform_tags = freeform_tags ,
1579+ defined_tags = defined_tags ,
15251580 wait = wait ,
15261581 )
15271582
0 commit comments