|
33 | 33 | from ads.common.extended_enum import ExtendedEnumMeta |
34 | 34 | from ads.common.object_storage_details import ObjectStorageDetails |
35 | 35 | from ads.common.oci_resource import SEARCH_TYPE, OCIResource |
36 | | -from ads.common.utils import get_console_link, upload_to_os |
| 36 | +from ads.common.utils import get_console_link, upload_to_os, copy_file |
37 | 37 | from ads.config import AQUA_SERVICE_MODELS_BUCKET, CONDA_BUCKET_NS, TENANCY_OCID |
38 | 38 | from ads.model import DataScienceModel, ModelVersionSet |
39 | 39 |
|
@@ -100,6 +100,23 @@ def get_status(evaluation_status: str, job_run_status: str = None): |
100 | 100 | JobRun.LIFECYCLE_STATE_NEEDS_ATTENTION: "Missing jobrun information.", |
101 | 101 | } |
102 | 102 |
|
| 103 | +CONSOLE_LINK_RESOURCE_TYPE_MAPPING = dict( |
| 104 | + datasciencemodel="models", |
| 105 | + datasciencemodeldeployment="model-deployments", |
| 106 | + datasciencemodeldeploymentdev="model-deployments", |
| 107 | + datasciencemodeldeploymentint="model-deployments", |
| 108 | + datasciencemodeldeploymentpre="model-deployments", |
| 109 | + datasciencejob="jobs", |
| 110 | + datasciencejobrun="job-runs", |
| 111 | + datasciencejobrundev="job-runs", |
| 112 | + datasciencejobrunint="job-runs", |
| 113 | + datasciencejobrunpre="job-runs", |
| 114 | + datasciencemodelversionset="model-version-sets", |
| 115 | + datasciencemodelversionsetpre="model-version-sets", |
| 116 | + datasciencemodelversionsetint="model-version-sets", |
| 117 | + datasciencemodelversionsetdev="model-version-sets", |
| 118 | +) |
| 119 | + |
103 | 120 |
|
104 | 121 | def random_color_generator(word: str): |
105 | 122 | seed = sum([ord(c) for c in word]) % 13 |
@@ -227,12 +244,10 @@ def is_valid_ocid(ocid: str) -> bool: |
227 | 244 | bool: |
228 | 245 | Whether the given ocid is valid. |
229 | 246 | """ |
230 | | - # TODO: revisit pattern |
231 | | - pattern = ( |
232 | | - r"^ocid1\.([a-z0-9_]+)\.([a-z0-9]+)\.([a-z0-9-]*)(\.[^.]+)?\.([a-z0-9_]+)$" |
233 | | - ) |
234 | | - match = re.match(pattern, ocid) |
235 | | - return True |
| 247 | + |
| 248 | + if not ocid: |
| 249 | + return False |
| 250 | + return ocid.lower().startswith("ocid") |
236 | 251 |
|
237 | 252 |
|
238 | 253 | def get_resource_type(ocid: str) -> str: |
@@ -557,7 +572,7 @@ def fetch_service_compartment() -> Union[str, None]: |
557 | 572 | config_file_name=CONTAINER_INDEX, |
558 | 573 | ) |
559 | 574 | except Exception as e: |
560 | | - logger.error( |
| 575 | + logger.debug( |
561 | 576 | f"Config file {config_file_name}/{CONTAINER_INDEX} to fetch service compartment OCID could not be found. " |
562 | 577 | f"\n{str(e)}." |
563 | 578 | ) |
@@ -824,3 +839,51 @@ def get_combined_params(params1: str = None, params2: str = None) -> str: |
824 | 839 | ] |
825 | 840 |
|
826 | 841 | return " ".join(combined_params) |
| 842 | + |
| 843 | + |
| 844 | +def copy_model_config(artifact_path: str, os_path: str, auth: dict = None): |
| 845 | + """Copies the aqua model config folder from the artifact path to the user provided object storage path. |
| 846 | + The config folder is overwritten if the files already exist at the destination path. |
| 847 | +
|
| 848 | + Parameters |
| 849 | + ---------- |
| 850 | + artifact_path: |
| 851 | + Path of the aqua model where config folder is available. |
| 852 | + os_path: |
| 853 | + User provided path where config folder will be copied. |
| 854 | + auth: (Dict, optional). Defaults to None. |
| 855 | + The default authentication is set using `ads.set_auth` API. If you need to override the |
| 856 | + default, use the `ads.common.auth.api_keys` or `ads.common.auth.resource_principal` to create appropriate |
| 857 | + authentication signer and kwargs required to instantiate IdentityClient object. |
| 858 | +
|
| 859 | + Returns |
| 860 | + ------- |
| 861 | + None |
| 862 | + Nothing. |
| 863 | + """ |
| 864 | + |
| 865 | + try: |
| 866 | + source_dir = ObjectStorageDetails( |
| 867 | + AQUA_SERVICE_MODELS_BUCKET, |
| 868 | + CONDA_BUCKET_NS, |
| 869 | + f"{os.path.dirname(artifact_path).rstrip('/')}/config", |
| 870 | + ).path |
| 871 | + dest_dir = f"{os_path.rstrip('/')}/config" |
| 872 | + |
| 873 | + oss_details = ObjectStorageDetails.from_path(source_dir) |
| 874 | + objects = oss_details.list_objects(fields="name").objects |
| 875 | + |
| 876 | + for obj in objects: |
| 877 | + source_path = ObjectStorageDetails( |
| 878 | + AQUA_SERVICE_MODELS_BUCKET, CONDA_BUCKET_NS, obj.name |
| 879 | + ).path |
| 880 | + destination_path = os.path.join(dest_dir, os.path.basename(obj.name)) |
| 881 | + copy_file( |
| 882 | + uri_src=source_path, |
| 883 | + uri_dst=destination_path, |
| 884 | + force_overwrite=True, |
| 885 | + auth=auth, |
| 886 | + ) |
| 887 | + except Exception as ex: |
| 888 | + logger.debug(ex) |
| 889 | + logger.debug(f"Failed to copy config folder from {artifact_path} to {os_path}.") |
0 commit comments