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 = {
@@ -1235,9 +1241,7 @@ def log_group_id(self) -> str:
12351241 """
12361242 return self .get_spec (self .CONST_LOG_GROUP_ID )
12371243
1238- def with_storage_mount (
1239- self , * storage_mount : List [dict ]
1240- ) -> DataScienceJob :
1244+ def with_storage_mount (self , * storage_mount : List [dict ]) -> DataScienceJob :
12411245 """Sets the file systems to be mounted for the data science job.
12421246 A maximum number of 5 file systems are allowed to be mounted for a single data science job.
12431247
@@ -1275,6 +1279,36 @@ def storage_mount(self) -> List[dict]:
12751279 """
12761280 return self .get_spec (self .CONST_STORAGE_MOUNT , [])
12771281
1282+ def with_freeform_tag (self , ** kwargs ) -> DataScienceJob :
1283+ """Sets freeform tags
1284+
1285+ Returns
1286+ -------
1287+ DataScienceJob
1288+ The DataScienceJob instance (self)
1289+ """
1290+ return self .set_spec (self .CONST_FREEFORM_TAGS , kwargs )
1291+
1292+ def with_defined_tag (self , ** kwargs ) -> DataScienceJob :
1293+ """Sets defined tags
1294+
1295+ Returns
1296+ -------
1297+ DataScienceJob
1298+ The DataScienceJob instance (self)
1299+ """
1300+ return self .set_spec (self .CONST_DEFINED_TAGS , kwargs )
1301+
1302+ @property
1303+ def freeform_tags (self ) -> dict :
1304+ """Freeform tags"""
1305+ return self .get_spec (self .CONST_FREEFORM_TAGS , {})
1306+
1307+ @property
1308+ def defined_tags (self ) -> dict :
1309+ """Defined tags"""
1310+ return self .get_spec (self .CONST_DEFINED_TAGS , {})
1311+
12781312 def _prepare_log_config (self ) -> dict :
12791313 if not self .log_group_id and not self .log_id :
12801314 return None
@@ -1429,7 +1463,8 @@ def _update_job_infra(self, dsc_job: DSCJob) -> DataScienceJob:
14291463 "Storage mount hasn't been supported in the current OCI SDK installed."
14301464 )
14311465 dsc_job .job_storage_mount_configuration_details_list = [
1432- DSCFileSystemManager .initialize (file_system ) for file_system in self .storage_mount
1466+ DSCFileSystemManager .initialize (file_system )
1467+ for file_system in self .storage_mount
14331468 ]
14341469 return self
14351470
@@ -1486,6 +1521,10 @@ def create(self, runtime, **kwargs) -> DataScienceJob:
14861521
14871522 payload ["display_name" ] = display_name
14881523 payload ["job_log_configuration_details" ] = self ._prepare_log_config ()
1524+ if not payload .get ("freeform_tags" ):
1525+ payload ["freeform_tags" ] = self .freeform_tags
1526+ if not payload .get ("defined_tags" ):
1527+ payload ["defined_tags" ] = self .defined_tags
14891528
14901529 self .dsc_job = DSCJob (** payload )
14911530 # Set Job infra to user values after DSCJob initialized the defaults
@@ -1496,7 +1535,13 @@ def create(self, runtime, **kwargs) -> DataScienceJob:
14961535 return self
14971536
14981537 def run (
1499- self , name = None , args = None , env_var = None , freeform_tags = None , wait = False
1538+ self ,
1539+ name = None ,
1540+ args = None ,
1541+ env_var = None ,
1542+ freeform_tags = None ,
1543+ defined_tags = None ,
1544+ wait = False ,
15001545 ) -> DataScienceJobRun :
15011546 """Runs a job on OCI Data Science job
15021547
@@ -1510,6 +1555,8 @@ def run(
15101555 Environment variable for the job run, by default None
15111556 freeform_tags : dict, optional
15121557 Freeform tags for the job run, by default None
1558+ defined_tags : dict, optional
1559+ Defined tags for the job run, by default None
15131560 wait : bool, optional
15141561 Indicate if this method should wait for the run to finish before it returns, by default False.
15151562
@@ -1524,11 +1571,18 @@ def run(
15241571 raise RuntimeError (
15251572 "Job is not created. Call create() to create the job first."
15261573 )
1527- tags = self .runtime .freeform_tags
1528- if not tags :
1529- tags = {}
1530- if freeform_tags :
1531- tags .update (freeform_tags )
1574+
1575+ if not freeform_tags :
1576+ freeform_tags = {}
1577+ runtime_freeform_tags = self .runtime .freeform_tags
1578+ if runtime_freeform_tags :
1579+ freeform_tags .update (runtime_freeform_tags )
1580+
1581+ if not defined_tags :
1582+ defined_tags = {}
1583+ runtime_defined_tags = self .runtime .defined_tags
1584+ if runtime_defined_tags :
1585+ defined_tags .update (runtime_defined_tags )
15321586
15331587 if name :
15341588 envs = self .runtime .envs
@@ -1540,7 +1594,8 @@ def run(
15401594 display_name = name ,
15411595 command_line_arguments = args ,
15421596 environment_variables = env_var ,
1543- freeform_tags = tags ,
1597+ freeform_tags = freeform_tags ,
1598+ defined_tags = defined_tags ,
15441599 wait = wait ,
15451600 )
15461601
0 commit comments