Source code for ads.jobs.builders.infrastructure.base
#!/usr/bin/env python# -*- coding: utf-8; -*-# Copyright (c) 2021, 2024 Oracle and/or its affiliates.# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/fromads.commonimportutilsascommon_utilsfromads.common.decorator.utilsimportclass_or_instance_methodfromads.jobs.builders.baseimportBuilderfromads.jobs.builders.runtimes.baseimportRuntimeimportlogginglogger=logging.getLogger(__name__)
[docs]classInfrastructure(Builder):"""Base class for job infrastructure"""@propertydefkind(self)->str:"""Kind of the object to be stored in YAML. All runtimes will have "infrastructure" as kind. Subclass will have different types. """return"infrastructure"@propertydefname(self)->str:"""The name of the job from the infrastructure."""raiseNotImplementedError()def_assert_runtime_compatible(self,runtime:Runtime)->None:""" Check if a runtime is compatible with an engine. Raise an error if not. Parameters ---------- runtime: `Runtime` a runtime object Returns ------- None """
[docs]defcreate(self,runtime:Runtime,**kwargs):""" Create/deploy a job on the infrastructure. Parameters ---------- runtime: `Runtime` a runtime object kwargs: dict additional arguments """raiseNotImplementedError()
[docs]defrun(self,name:str=None,args:str=None,env_var:dict=None,freeform_tags:dict=None,defined_tags:dict=None,wait:bool=False,):"""Runs a job on the infrastructure. Parameters ---------- name : str, optional The name of the job run, by default None args : str, optional Command line arguments for the job run, by default None. env_var : dict, optional Environment variable for the job run, by default None. freeform_tags : dict, optional Freeform tags for the job run, by default None. defined_tags : dict, optional Defined tags for the job run, by default None. wait : bool, optional Indicate if this method should wait for the run to finish before it returns, by default False. """raiseNotImplementedError()
[docs]defdelete(self):"""Deletes a job from the infrastructure."""raiseNotImplementedError()
[docs]defupdate(self,runtime:Runtime):"""Updates a job. Parameters ---------- runtime a runtime object """raiseNotImplementedError()
[docs]@class_or_instance_methoddeflist_jobs(cls,**kwargs)->list:""" List jobs from the infrastructure. Parameters ---------- kwargs: keyword arguments for filtering the results Returns ------- list list of infrastructure objects, each representing a job from the infrastructure. """raiseNotImplementedError()
[docs]defcreate(self):"""Create a RunInstance Object."""raiseNotImplementedError()
@propertydefstatus(self):"""Return status of the run."""raiseNotImplementedError()
[docs]defwatch(self):"""Show logs of a run."""raiseNotImplementedError()
[docs]defdelete(self):"""Delete a run."""raiseNotImplementedError()
[docs]defcancel(self):"""Cancel a run."""raiseNotImplementedError()
@propertydefrun_details_link(self)->str:""" Link to run details page in OCI console Returns ------- str The link to the details page in OCI console. """ifnotself._DETAILS_LINK:return""try:returnself._DETAILS_LINK.format(region=common_utils.extract_region(),id=self.id)exceptExceptionasex:print(str(ex))logger.info("Error occurred in attempt to extract the link to the resource. "f"Details: {ex}")return""