-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathbootstrap.py
More file actions
178 lines (159 loc) · 4.89 KB
/
bootstrap.py
File metadata and controls
178 lines (159 loc) · 4.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#
# Copyright 2019 The Feast Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import pathlib
from datetime import datetime, timedelta
import click
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 = None
c_members = None
c_ca_path = None
c_cert_path = None
c_key_path = None
c_discovery_token = None
c_ttl_seconds = None
cluster_type = click.prompt(
"Would you like to connect a [L]ocal cluster or [V]iridian cluster?",
type=click.Choice(["L", "V"]),
show_choices=False,
default="L",
)
is_viridian = cluster_type == "V"
if is_viridian:
c_cluster_name = click.prompt("Cluster ID: ")
c_discovery_token = click.prompt("Discovery Token: ")
c_ca_path = click.prompt("CA file path: ")
c_cert_path = click.prompt("CERT file path: ")
c_key_path = click.prompt("Key file path: ")
else:
c_cluster_name = click.prompt(
"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_ttl_seconds = click.prompt(
"Key TTL seconds: ",
default=0,
)
return {
"c_cluster_name": c_cluster_name,
"c_members": c_members,
"c_ca_path": c_ca_path,
"c_cert_path": c_cert_path,
"c_key_path": c_key_path,
"c_discovery_token": c_discovery_token,
"c_ttl_seconds": c_ttl_seconds,
}
def apply_hazelcast_store_settings(config_file, settings):
write_setting_or_remove(
config_file,
settings["c_cluster_name"],
"cluster_name",
"c_cluster_name",
)
#
write_setting_or_remove(
config_file,
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_members"],
"cluster_members",
"c_members",
)
#
write_setting_or_remove(
config_file,
settings["c_ca_path"],
"ssl_cafile_path",
"c_ca_path",
)
#
write_setting_or_remove(
config_file,
settings["c_cert_path"],
"ssl_certfile_path",
"c_cert_path",
)
#
write_setting_or_remove(
config_file,
settings["c_key_path"],
"ssl_keyfile_path",
"c_key_path",
)
if settings["c_ca_path"] is None:
remove_lines_from_file(
config_file,
"ssl_password: ${SSL_PASSWORD}",
True,
)
#
replace_str_in_file(
config_file,
"c_ttl_seconds",
f"{settings['c_ttl_seconds']}",
)
def bootstrap():
"""
Bootstrap() will automatically be called
from the init_repo() during `feast init`.
"""
from feast.driver_test_data import create_driver_hourly_stats_df
repo_path = pathlib.Path(__file__).parent.absolute() / "feature_repo"
config_file = repo_path / "feature_store.yaml"
data_path = repo_path / "data"
data_path.mkdir(exist_ok=True)
end_date = datetime.now().replace(microsecond=0, second=0, minute=0)
start_date = end_date - timedelta(days=15)
#
driver_entities = [1001, 1002, 1003, 1004, 1005]
driver_df = create_driver_hourly_stats_df(
driver_entities,
start_date,
end_date,
)
#
driver_stats_path = data_path / "driver_stats.parquet"
driver_df.to_parquet(path=str(driver_stats_path), allow_truncated_timestamps=True)
# feature_definitions.py
example_py_file = repo_path / "feature_definitions.py"
replace_str_in_file(
example_py_file, "%PARQUET_PATH%", str(driver_stats_path.relative_to(repo_path))
)
# store config yaml, interact with user and then customize file:
settings = collect_hazelcast_online_store_settings()
apply_hazelcast_store_settings(config_file, settings)
if __name__ == "__main__":
bootstrap()