Skip to content

Commit 9f589ef

Browse files
authored
Added support for mounting object storage service for job. (#204)
2 parents 628843e + f1f2cb2 commit 9f589ef

File tree

3 files changed

+309
-7
lines changed

3 files changed

+309
-7
lines changed

ads/common/dsc_file_system.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from dataclasses import dataclass
1111

1212
FILE_STORAGE_TYPE = "FILE_STORAGE"
13+
OBJECT_STORAGE_TYPE = "OBJECT_STORAGE"
1314

1415

1516
@dataclass
@@ -182,9 +183,53 @@ def update_from_dsc_model(cls, dsc_model) -> dict:
182183
"dest" : dsc_model.destination_directory_name
183184
}
184185

186+
@dataclass
187+
class OCIObjectStorage(DSCFileSystem):
188+
189+
storage_type: str = OBJECT_STORAGE_TYPE
190+
191+
def update_to_dsc_model(self) -> dict:
192+
arguments = {
193+
"destinationDirectoryName" : self.dest,
194+
"storageType" : self.storage_type
195+
}
196+
src_list = self.src.split("@")
197+
bucket_segment = src_list[0]
198+
namespace_segment = src_list[1].strip("/")
199+
arguments["bucket"] = bucket_segment[6:]
200+
if "/" in namespace_segment:
201+
first_slash_index = namespace_segment.index("/")
202+
arguments["namespace"] = namespace_segment[:first_slash_index]
203+
arguments["prefix"] = namespace_segment[first_slash_index+1:]
204+
else:
205+
arguments["namespace"] = namespace_segment
206+
return arguments
207+
208+
@classmethod
209+
def update_from_dsc_model(cls, dsc_model) -> dict:
210+
if not dsc_model.namespace:
211+
raise ValueError(
212+
"Missing parameter `namespace` from service. Check service log to see the error."
213+
)
214+
if not dsc_model.bucket:
215+
raise ValueError(
216+
"Missing parameter `bucket` from service. Check service log to see the error."
217+
)
218+
if not dsc_model.destination_directory_name:
219+
raise ValueError(
220+
"Missing parameter `destination_directory_name` from service. Check service log to see the error."
221+
)
222+
223+
return {
224+
"src" : f"oci://{dsc_model.bucket}@{dsc_model.namespace}/{dsc_model.prefix or ''}",
225+
"dest" : dsc_model.destination_directory_name
226+
}
227+
185228

186229
class DSCFileSystemManager:
187230

231+
storage_mount_dest = set()
232+
188233
@classmethod
189234
def initialize(cls, arguments: dict) -> dict:
190235
"""Initialize and update arguments to dsc model.
@@ -204,6 +249,16 @@ def initialize(cls, arguments: dict) -> dict:
204249
"Parameter `dest` is required for mounting file storage system."
205250
)
206251

252+
if arguments["dest"] in cls.storage_mount_dest:
253+
raise ValueError(
254+
"Duplicate `dest` found. Please specify different `dest` for each file system to be mounted."
255+
)
256+
cls.storage_mount_dest.add(arguments["dest"])
257+
258+
# case oci://bucket@namespace/prefix
259+
if arguments["src"].startswith("oci://") and "@" in arguments["src"]:
260+
return OCIObjectStorage(**arguments).update_to_dsc_model()
261+
207262
first_segment = arguments["src"].split(":")[0]
208263
# case <mount_target_id>:<export_id>
209264
if first_segment.startswith("ocid"):

ads/jobs/builders/infrastructure/dsc_job.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,15 @@
3535
from ads.jobs.builders.runtimes.container_runtime import ContainerRuntime
3636
from ads.jobs.builders.runtimes.python_runtime import GitPythonRuntime
3737

38-
from ads.common.dsc_file_system import OCIFileStorage, DSCFileSystemManager
38+
from ads.common.dsc_file_system import OCIFileStorage, DSCFileSystemManager, OCIObjectStorage
3939

4040
logger = logging.getLogger(__name__)
4141

4242
SLEEP_INTERVAL = 3
4343
WAIT_SECONDS_AFTER_FINISHED = 90
4444
MAXIMUM_MOUNT_COUNT = 5
4545
FILE_STORAGE_TYPE = "FILE_STORAGE"
46+
OBJECT_STORAGE_TYPE = "OBJECT_STORAGE"
4647

4748

4849
class DSCJob(OCIDataScienceMixin, oci.data_science.models.Job):
@@ -911,7 +912,10 @@ class DataScienceJob(Infrastructure):
911912
v.split(".", maxsplit=1)[-1]: k for k, v in payload_attribute_map.items()
912913
}
913914

914-
storage_mount_type_dict = {FILE_STORAGE_TYPE: OCIFileStorage}
915+
storage_mount_type_dict = {
916+
FILE_STORAGE_TYPE: OCIFileStorage,
917+
OBJECT_STORAGE_TYPE: OCIObjectStorage,
918+
}
915919

916920
@staticmethod
917921
def standardize_spec(spec):

0 commit comments

Comments
 (0)