Skip to content

Commit 0335597

Browse files
committed
Added support for mounting object storage service for job.
1 parent a2b6437 commit 0335597

File tree

3 files changed

+75
-4
lines changed

3 files changed

+75
-4
lines changed

ads/common/dsc_file_system.py

Lines changed: 47 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,6 +183,48 @@ 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

@@ -204,6 +247,10 @@ def initialize(cls, arguments: dict) -> dict:
204247
"Parameter `dest` is required for mounting file storage system."
205248
)
206249

250+
# case oci://bucket@namespace/prefix
251+
if arguments["src"].startswith("oci://") and "@" in arguments["src"]:
252+
return OCIObjectStorage(**arguments).update_to_dsc_model()
253+
207254
first_segment = arguments["src"].split(":")[0]
208255
# case <mount_target_id>:<export_id>
209256
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):

tests/unitary/default_setup/jobs/test_jobs_mount_file_system.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,11 @@
8383
{
8484
"src" : "2.2.2.2:test_export_path_two",
8585
"dest" : "test_mount_two",
86-
},
86+
},
87+
{
88+
"src" : "oci://bucket_name@namespace/synthetic/",
89+
"dest" : "test_mount_three",
90+
}
8791
)
8892
)
8993
.with_runtime(
@@ -111,6 +115,8 @@
111115
dest: test_mount_one
112116
- src: 2.2.2.2:test_export_path_two
113117
dest: test_mount_two
118+
- src: oci://bucket_name@namespace/synthetic/
119+
dest: test_mount_three
114120
subnetId: ocid1.subnet.oc1.iad.xxxx
115121
type: dataScienceJob
116122
name: My Job
@@ -141,6 +147,11 @@ def test_data_science_job_initialize(self):
141147
assert dsc_file_storage_two["src"] == "2.2.2.2:test_export_path_two"
142148
assert dsc_file_storage_two["dest"] == "test_mount_two"
143149

150+
dsc_object_storage = job.infrastructure.storage_mount[2]
151+
assert isinstance(dsc_object_storage, dict)
152+
assert dsc_object_storage["src"] == "oci://bucket_name@namespace/synthetic/"
153+
assert dsc_object_storage["dest"] == "test_mount_three"
154+
144155
def test_data_science_job_from_yaml(self):
145156
job_from_yaml = Job.from_yaml(job_yaml_string)
146157

@@ -155,6 +166,11 @@ def test_data_science_job_from_yaml(self):
155166
assert dsc_file_storage_two["src"] == "2.2.2.2:test_export_path_two"
156167
assert dsc_file_storage_two["dest"] == "test_mount_two"
157168

169+
dsc_object_storage = job.infrastructure.storage_mount[2]
170+
assert isinstance(dsc_object_storage, dict)
171+
assert dsc_object_storage["src"] == "oci://bucket_name@namespace/synthetic/"
172+
assert dsc_object_storage["dest"] == "test_mount_three"
173+
158174
def test_data_science_job_to_dict(self):
159175
assert job.to_dict() == {
160176
"kind": "job",
@@ -189,6 +205,10 @@ def test_data_science_job_to_dict(self):
189205
"src" : "2.2.2.2:test_export_path_two",
190206
"dest" : "test_mount_two",
191207
},
208+
{
209+
"src" : "oci://bucket_name@namespace/synthetic/",
210+
"dest" : "test_mount_three",
211+
}
192212
],
193213
},
194214
},
@@ -265,7 +285,7 @@ def test_update_job_infra(
265285

266286
assert (
267287
len(dsc_job_payload_copy.job_storage_mount_configuration_details_list)
268-
== 2
288+
== 3
269289
)
270290
assert dsc_job_payload_copy.job_storage_mount_configuration_details_list[
271291
0

0 commit comments

Comments
 (0)