|
14 | 14 | # limitations under the License.
|
15 | 15 | #
|
16 | 16 |
|
| 17 | +import os |
| 18 | + |
17 | 19 | from hsml.core import native_hdfs_api
|
18 |
| -from hsml import constants |
| 20 | +from hsml import client |
19 | 21 |
|
20 | 22 |
|
21 | 23 | class HopsworksEngine:
|
22 | 24 | def __init__(self):
|
23 | 25 | self._native_hdfs_api = native_hdfs_api.NativeHdfsApi()
|
24 | 26 |
|
25 |
| - def mkdir(self, model_instance): |
26 |
| - model_version_dir_hdfs = "/Projects/{}/{}/{}/{}".format( |
27 |
| - model_instance.project_name, |
28 |
| - constants.MODEL_SERVING.MODELS_DATASET, |
29 |
| - model_instance.name, |
30 |
| - str(model_instance.version), |
31 |
| - ) |
32 |
| - self._native_hdfs_api.mkdir(model_version_dir_hdfs) |
33 |
| - self._native_hdfs_api.chmod(model_version_dir_hdfs, "ug+rwx") |
34 |
| - |
35 |
| - def delete(self, model_instance): |
36 |
| - model_version_dir_hdfs = "/Projects/{}/{}/{}/{}".format( |
37 |
| - model_instance.project_name, |
38 |
| - constants.MODEL_SERVING.MODELS_DATASET, |
39 |
| - model_instance.name, |
40 |
| - str(model_instance.version), |
41 |
| - ) |
42 |
| - self._native_hdfs_api.delete(model_version_dir_hdfs) |
| 27 | + def mkdir(self, remote_path: str): |
| 28 | + remote_path = self._prepend_project_path(remote_path) |
| 29 | + self._native_hdfs_api.mkdir(remote_path) |
| 30 | + self._native_hdfs_api.chmod(remote_path, "ug+rwx") |
| 31 | + |
| 32 | + def delete(self, remote_path: str): |
| 33 | + remote_path = self._prepend_project_path(remote_path) |
| 34 | + self._native_hdfs_api.rm(remote_path) |
| 35 | + |
| 36 | + def upload(self, local_path: str, remote_path: str): |
| 37 | + local_path = self._get_abs_path(local_path) |
| 38 | + remote_path = self._prepend_project_path(remote_path) |
| 39 | + self._native_hdfs_api.upload(local_path, remote_path) |
| 40 | + self._native_hdfs_api.chmod(remote_path, "ug+rwx") |
| 41 | + |
| 42 | + def download(self, remote_path: str, local_path: str): |
| 43 | + local_path = self._get_abs_path(local_path) |
| 44 | + remote_path = self._prepend_project_path(remote_path) |
| 45 | + self._native_hdfs_api.download(remote_path, local_path) |
| 46 | + |
| 47 | + def copy(self, source_path: str, destination_path: str): |
| 48 | + # both paths are hdfs paths |
| 49 | + source_path = self._prepend_project_path(source_path) |
| 50 | + destination_path = self._prepend_project_path(destination_path) |
| 51 | + self._native_hdfs_api.copy(source_path, destination_path) |
| 52 | + |
| 53 | + def move(self, source_path: str, destination_path: str): |
| 54 | + source_path = self._prepend_project_path(source_path) |
| 55 | + destination_path = self._prepend_project_path(destination_path) |
| 56 | + self._native_hdfs_api.move(source_path, destination_path) |
| 57 | + |
| 58 | + def _get_abs_path(self, local_path: str): |
| 59 | + return local_path if os.path.isabs(local_path) else os.path.abspath(local_path) |
| 60 | + |
| 61 | + def _prepend_project_path(self, remote_path: str): |
| 62 | + if not remote_path.startswith("/Projects/"): |
| 63 | + _client = client.get_instance() |
| 64 | + remote_path = "/Projects/{}/{}".format(_client._project_name, remote_path) |
| 65 | + return remote_path |
0 commit comments