Skip to content

Commit

Permalink
Fix template bugs and address review comments.
Browse files Browse the repository at this point in the history
Signed-off-by: mehmettokgoz <mehmet.tokgoz@hazelcast.com>
  • Loading branch information
mehmettokgoz committed Mar 22, 2023
1 parent 8ad15ac commit dad8fc4
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ In order to use [Hazelcast](https://hazelcast.com) as online store, you need to
You can create a cluster using Hazelcast Viridian Serverless easily or deploy one on your local/remote machine.
See this [getting started](https://hazelcast.com/get-started/) page for more details.

Hazelcast online store provides capability to connect TLS/SSL enabled cluster or Hazelcast Viridian Serverless cluster.
Following is an example to connect local cluster named "dev" running on port 5701 with SSL enabled.
Hazelcast online store provides capability to connect local/remote or Hazelcast Viridian Serverless cluster.
Following is an example to connect local cluster named "dev" running on port 5701 with TLS/SSL enabled.

```yaml
[...]
Expand All @@ -48,7 +48,8 @@ online_store:
ssl_cafile_path: /path/to/ca/file
ssl_certfile_path: /path/to/cert/file
ssl_keyfile_path: /path/to/key/file
ssl_password: <YOUR_SSL_PASSWORD>
ssl_password: ${SSL_PASSWORD} # The password will be read form the `SSL_PASSWORD` environment variable.
key_ttl_seconds: 86400 # The default is 0 and means infinite.
```
If you want to connect your Hazelcast Viridian cluster instead of local/remote one, specify your configuration as follows:
Expand All @@ -57,12 +58,13 @@ If you want to connect your Hazelcast Viridian cluster instead of local/remote o
[...]
online_store:
type: hazelcast
cluster_name: <YOUR_CLUSTER_ID>
discovery_token: <YOUR_DISCOVERY_TOKEN>
cluster_name: YOUR_CLUSTER_ID
discovery_token: YOUR_DISCOVERY_TOKEN
ssl_cafile_path: /path/to/ca/file
ssl_certfile_path: /path/to/cert/file
ssl_keyfile_path: /path/to/key/file
ssl_password: <YOUR_SSL_PASSWORD>
ssl_password: ${SSL_PASSWORD} # The password will be read form the `SSL_PASSWORD` environment variable.
key_ttl_seconds: 86400 # The default is 0 and means infinite.
```
#### TTL configuration
Expand All @@ -78,7 +80,7 @@ Its default value is 0, which means infinite.
[...]
online_store:
[...]
key_ttl_seconds: 36000
key_ttl_seconds: 86400
```
### More info
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import pytz
from hazelcast.client import HazelcastClient
from hazelcast.core import HazelcastJsonValue
from hazelcast.discovery import HazelcastCloudDiscovery
from pydantic import StrictStr

from feast import Entity, FeatureView, RepoConfig
Expand Down Expand Up @@ -110,11 +111,14 @@ def _get_client(self, config: HazelcastOnlineStoreConfig):
with self._lock:
if self._client is None:
if config.discovery_token != "":
HazelcastCloudDiscovery._CLOUD_URL_BASE = (
"api.viridian.hazelcast.com"
)
self._client = HazelcastClient(
cluster_name=config.cluster_name,
cloud_discovery_token=config.discovery_token,
statistics_enabled=True,
ssl_enabled=True,
cloud_discovery_token=config.discovery_token,
ssl_cafile=config.ssl_cafile_path,
ssl_certfile=config.ssl_certfile_path,
ssl_keyfile=config.ssl_keyfile_path,
Expand Down Expand Up @@ -161,7 +165,7 @@ def online_write_batch(
entity_key_str = base64.b64encode(
serialize_entity_key(
entity_key,
entity_key_serialization_version=config.entity_key_serialization_version,
entity_key_serialization_version=2,
)
).decode("utf-8")
event_ts_utc = pytz.utc.localize(event_ts, is_dst=None).timestamp()
Expand Down Expand Up @@ -213,7 +217,7 @@ def online_read(
entity_key_str = base64.b64encode(
serialize_entity_key(
entity_key,
entity_key_serialization_version=config.entity_key_serialization_version,
entity_key_serialization_version=2,
)
).decode("utf-8")
if requested_features:
Expand Down
49 changes: 24 additions & 25 deletions sdk/python/feast/templates/hazelcast/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,21 @@

import click

from feast.file_utils import replace_str_in_file, write_setting_or_remove
from feast.file_utils import (
remove_lines_from_file,
replace_str_in_file,
write_setting_or_remove,
)


def collect_hazelcast_online_store_settings():
c_cluster_name = ""
c_cluster_name = None
c_members = None
c_ca_path = None
c_cert_path = None
c_key_path = None
c_ssl_password = None
c_discovery_token = None
c_ttl_seconds = 0
c_ttl_seconds = None

cluster_type = click.prompt(
"Would you like to connect a [L]ocal cluster or [V]iridian cluster?",
Expand All @@ -46,23 +49,20 @@ def collect_hazelcast_online_store_settings():
c_ca_path = click.prompt("CA file path: ")
c_cert_path = click.prompt("CERT file path: ")
c_key_path = click.prompt("Key file path: ")
c_ssl_password = click.prompt("SSL password: ")
else:
c_cluster_name = click.prompt(
"Cluster_name: ",
"Cluster name: ",
default="dev",
)
c_members = click.prompt(
"Cluster members:",
default="localhost:5701",
)

needs_ssl = click.confirm("Use TLS/SSL?", default=False)
if needs_ssl:
c_ca_path = click.prompt("CA file path: ")
c_cert_path = click.prompt("CERT file path: ")
c_key_path = click.prompt("Key file path: ")
c_ssl_password = click.prompt("SSL password: ")

c_ttl_seconds = click.prompt(
"Key TTL seconds: ",
Expand All @@ -74,14 +74,12 @@ def collect_hazelcast_online_store_settings():
"c_ca_path": c_ca_path,
"c_cert_path": c_cert_path,
"c_key_path": c_key_path,
"c_ssl_password": c_ssl_password,
"c_discovery_token": c_discovery_token,
"c_ttl_seconds": c_ttl_seconds,
}


def apply_cassandra_store_settings(config_file, settings):

def apply_hazelcast_store_settings(config_file, settings):
write_setting_or_remove(
config_file,
settings["c_cluster_name"],
Expand All @@ -91,16 +89,18 @@ def apply_cassandra_store_settings(config_file, settings):
#
write_setting_or_remove(
config_file,
"[" + settings["c_members"] + "]",
"cluster_members",
"c_members",
settings["c_discovery_token"],
"discovery_token",
"c_discovery_token",
)
#
if settings["c_members"] is not None:
settings["c_members"] = "[" + settings["c_members"] + "]"
write_setting_or_remove(
config_file,
settings["c_discovery_token"],
"discovery_token",
"c_discovery_token",
settings["c_members"],
"cluster_members",
"c_members",
)
#
write_setting_or_remove(
Expand All @@ -123,13 +123,12 @@ def apply_cassandra_store_settings(config_file, settings):
"ssl_keyfile_path",
"c_key_path",
)
#
write_setting_or_remove(
config_file,
settings["c_ssl_password"],
"ssl_password",
"c_ssl_password",
)
if settings["c_ca_path"] is None:
remove_lines_from_file(
config_file,
"ssl_password: ${SSL_PASSWORD}",
True,
)
#
replace_str_in_file(
config_file,
Expand Down Expand Up @@ -170,7 +169,7 @@ def bootstrap():

# store config yaml, interact with user and then customize file:
settings = collect_hazelcast_online_store_settings()
apply_cassandra_store_settings(config_file, settings)
apply_hazelcast_store_settings(config_file, settings)


if __name__ == "__main__":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ online_store:
ssl_cafile_path: c_ca_path
ssl_certfile_path: c_cert_path
ssl_keyfile_path: c_key_path
ssl_password: c_ssl_password
ssl_password: ${SSL_PASSWORD} # This value will be read form the `SSL_PASSWORD` environment variable.
key_ttl_seconds: c_ttl_seconds
entity_key_serialization_version: 2

0 comments on commit dad8fc4

Please sign in to comment.