Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FSTORE-1605] Add “global” path field in the storage connector #442

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ public static class S3Connector extends StorageConnector {
@Getter @Setter
protected String bucket;

@Getter @Setter
protected String path;

@Getter @Setter
protected String region;

Expand All @@ -138,7 +141,9 @@ public static class S3Connector extends StorageConnector {

@JsonIgnore
public String getPath(String subPath) {
return "s3://" + bucket + "/" + (Strings.isNullOrEmpty(subPath) ? "" : subPath);
return "s3://" + bucket
+ (Strings.isNullOrEmpty(path) ? "" : "/" + path) + "/"
+ (Strings.isNullOrEmpty(subPath) ? "" : subPath);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import com.logicalclocks.hsfs.FeatureStoreException;
import com.logicalclocks.hsfs.StorageConnectorType;
import com.logicalclocks.hsfs.StorageConnector.S3Connector;
import com.logicalclocks.hsfs.metadata.HopsworksClient;
import com.logicalclocks.hsfs.metadata.HopsworksHttpClient;
import com.logicalclocks.hsfs.metadata.Option;
Expand Down Expand Up @@ -245,6 +246,33 @@ void testDefaultPathS3() throws FeatureStoreException, IOException {
// reset
SparkEngine.setInstance(null);
}

@Test
void testGetPath() throws FeatureStoreException, IOException {
// Arrange
S3Connector connector = new S3Connector();
connector.setBucket("testBucket");

// Act
String path = connector.getPath("some/location");

// Assert
Assertions.assertEquals("s3://testBucket/some/location", path);
}

@Test
void testGetPathStorageConnectorWithPath() throws FeatureStoreException, IOException {
// Arrange
S3Connector connector = new S3Connector();
connector.setBucket("testBucket");
connector.setPath("abc/def");

// Act
String path = connector.getPath("some/location");

// Assert
Assertions.assertEquals("s3://testBucket/abc/def/some/location", path);
}
}

@Nested
Expand Down
7 changes: 5 additions & 2 deletions python/hsfs/storage_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import base64
import logging
import os
import posixpath
import re
import warnings
from abc import ABC, abstractmethod
Expand Down Expand Up @@ -276,6 +277,7 @@ def __init__(
server_encryption_algorithm: Optional[str] = None,
server_encryption_key: Optional[str] = None,
bucket: Optional[str] = None,
path: Optional[str] = None,
region: Optional[str] = None,
session_token: Optional[str] = None,
iam_role: Optional[str] = None,
Expand All @@ -290,6 +292,7 @@ def __init__(
self._server_encryption_algorithm = server_encryption_algorithm
self._server_encryption_key = server_encryption_key
self._bucket = bucket
self._path = path
self._region = region
self._session_token = session_token
self._iam_role = iam_role
Expand Down Expand Up @@ -340,7 +343,7 @@ def iam_role(self) -> Optional[str]:
@property
def path(self) -> Optional[str]:
"""If the connector refers to a path (e.g. S3) - return the path of the connector"""
return "s3://" + self._bucket
return posixpath.join("s3://" + self._bucket, *os.path.split(self._path if self._path else ""))

@property
def arguments(self) -> Optional[Dict[str, Any]]:
Expand Down Expand Up @@ -433,7 +436,7 @@ def read(
)

def _get_path(self, sub_path: str) -> str:
return os.path.join(self.path, sub_path)
return posixpath.join(self.path, *os.path.split(sub_path))


class RedshiftConnector(StorageConnector):
Expand Down
24 changes: 24 additions & 0 deletions python/tests/test_storage_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,30 @@ def test_default_path(self, mocker):
# assert
assert "s3://test-bucket" in mock_engine_read.call_args[0][3]

def test_get_path(self, mocker):
mocker.patch("hsfs.engine.get_instance", return_value=spark.Engine())
sc = storage_connector.S3Connector(
id=1, name="test_connector", featurestore_id=1, bucket="test-bucket"
)

# act
result = sc._get_path("some/location")

# assert
assert "s3://test-bucket/some/location" == result

def test_get_path_storage_connector_with_path(self, mocker):
mocker.patch("hsfs.engine.get_instance", return_value=spark.Engine())
sc = storage_connector.S3Connector(
id=1, name="test_connector", featurestore_id=1, bucket="test-bucket", path="abc/def"
)

# act
result = sc._get_path("some/location")

# assert
assert "s3://test-bucket/abc/def/some/location" == result


class TestRedshiftConnector:
def test_from_response_json(self, backend_fixtures):
Expand Down
Loading