Skip to content

Commit 210c6f8

Browse files
junhaoliaokirkrodrigues
authored andcommitted
feat: Replace existing webui codebase with new-webui. (#939)
Co-authored-by: kirkrodrigues <2454684+kirkrodrigues@users.noreply.github.com>
1 parent 18ebff6 commit 210c6f8

File tree

250 files changed

+509
-12834
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

250 files changed

+509
-12834
lines changed

components/clp-package-utils/clp_package_utils/general.py

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
CLP_DEFAULT_CREDENTIALS_FILE_PATH,
1616
CLPConfig,
1717
DB_COMPONENT_NAME,
18-
LOG_VIEWER_WEBUI_COMPONENT_NAME,
1918
QUEUE_COMPONENT_NAME,
2019
REDIS_COMPONENT_NAME,
2120
REDUCER_COMPONENT_NAME,
@@ -514,34 +513,17 @@ def validate_worker_config(clp_config: CLPConfig):
514513

515514

516515
def validate_webui_config(
517-
clp_config: CLPConfig, logs_dir: pathlib.Path, settings_json_path: pathlib.Path
516+
clp_config: CLPConfig,
517+
client_settings_json_path: pathlib.Path,
518+
server_settings_json_path: pathlib.Path,
518519
):
519-
if not settings_json_path.exists():
520-
raise ValueError(
521-
f"{WEBUI_COMPONENT_NAME} {settings_json_path} is not a valid path to Meteor settings.json"
522-
)
523-
524-
try:
525-
validate_path_could_be_dir(logs_dir)
526-
except ValueError as ex:
527-
raise ValueError(f"{WEBUI_COMPONENT_NAME} logs directory is invalid: {ex}")
520+
for path in [client_settings_json_path, server_settings_json_path]:
521+
if not path.exists():
522+
raise ValueError(f"{WEBUI_COMPONENT_NAME} {path} is not a valid path to settings.json")
528523

529524
validate_port(f"{WEBUI_COMPONENT_NAME}.port", clp_config.webui.host, clp_config.webui.port)
530525

531526

532-
def validate_log_viewer_webui_config(clp_config: CLPConfig, settings_json_path: pathlib.Path):
533-
if not settings_json_path.exists():
534-
raise ValueError(
535-
f"{WEBUI_COMPONENT_NAME} {settings_json_path} is not a valid path to settings.json"
536-
)
537-
538-
validate_port(
539-
f"{LOG_VIEWER_WEBUI_COMPONENT_NAME}.port",
540-
clp_config.log_viewer_webui.host,
541-
clp_config.log_viewer_webui.port,
542-
)
543-
544-
545527
def validate_path_for_container_mount(path: pathlib.Path) -> None:
546528
RESTRICTED_PREFIXES: List[pathlib.Path] = [
547529
CONTAINER_AWS_CONFIG_DIRECTORY,

components/clp-package-utils/clp_package_utils/scripts/start_clp.py

Lines changed: 46 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
CONTROLLER_TARGET_NAME,
2525
DB_COMPONENT_NAME,
2626
FILES_TABLE_SUFFIX,
27-
LOG_VIEWER_WEBUI_COMPONENT_NAME,
2827
QUERY_JOBS_TABLE_NAME,
2928
QUERY_SCHEDULER_COMPONENT_NAME,
3029
QUERY_WORKER_COMPONENT_NAME,
@@ -57,7 +56,6 @@
5756
validate_and_load_queue_credentials_file,
5857
validate_and_load_redis_credentials_file,
5958
validate_db_config,
60-
validate_log_viewer_webui_config,
6159
validate_queue_config,
6260
validate_redis_config,
6361
validate_reducer_config,
@@ -843,132 +841,62 @@ def read_and_update_settings_json(settings_file_path: pathlib.Path, updates: Dic
843841
return settings_object
844842

845843

846-
def start_webui(instance_id: str, clp_config: CLPConfig, mounts: CLPDockerMounts):
844+
def start_webui(
845+
instance_id: str,
846+
clp_config: CLPConfig,
847+
container_clp_config: CLPConfig,
848+
mounts: CLPDockerMounts,
849+
):
847850
component_name = WEBUI_COMPONENT_NAME
848851
logger.info(f"Starting {component_name}...")
849852

850853
container_name = f"clp-{component_name}-{instance_id}"
851854
if container_exists(container_name):
852855
return
853856

854-
webui_logs_dir = clp_config.logs_directory / component_name
855857
container_webui_dir = CONTAINER_CLP_HOME / "var" / "www" / "webui"
856-
node_path = str(container_webui_dir / "programs" / "server" / "npm" / "node_modules")
857-
settings_json_path = get_clp_home() / "var" / "www" / "webui" / "settings.json"
858-
859-
validate_webui_config(clp_config, webui_logs_dir, settings_json_path)
860-
861-
# Create directories
862-
webui_logs_dir.mkdir(exist_ok=True, parents=True)
858+
node_path = str(container_webui_dir / "server" / "node_modules")
859+
client_settings_json_path = (
860+
get_clp_home() / "var" / "www" / "webui" / "client" / "settings.json"
861+
)
862+
server_settings_json_path = (
863+
get_clp_home() / "var" / "www" / "webui" / "server" / "dist" / "server" / "settings.json"
864+
)
863865

864-
container_webui_logs_dir = pathlib.Path("/") / "var" / "log" / component_name
866+
validate_webui_config(clp_config, client_settings_json_path, server_settings_json_path)
865867

866-
# Read and update settings.json
868+
# Read, update, and write back client's and server's settings.json
867869
clp_db_connection_params = clp_config.database.get_clp_connection_params_and_type(True)
868870
table_prefix = clp_db_connection_params["table_prefix"]
869871
if StorageEngine.CLP_S == clp_config.package.storage_engine:
870872
table_prefix = f"{table_prefix}{CLP_DEFAULT_DATASET_NAME}_"
871-
meteor_settings_updates = {
872-
"private": {
873-
"SqlDbHost": clp_config.database.host,
874-
"SqlDbPort": clp_config.database.port,
875-
"SqlDbName": clp_config.database.name,
876-
"SqlDbClpArchivesTableName": f"{table_prefix}{ARCHIVES_TABLE_SUFFIX}",
877-
"SqlDbClpFilesTableName": f"{table_prefix}{FILES_TABLE_SUFFIX}",
878-
"SqlDbCompressionJobsTableName": COMPRESSION_JOBS_TABLE_NAME,
879-
"SqlDbQueryJobsTableName": QUERY_JOBS_TABLE_NAME,
880-
},
881-
"public": {
882-
"ClpStorageEngine": clp_config.package.storage_engine,
883-
"LogViewerWebuiUrl": (
884-
f"http://{clp_config.log_viewer_webui.host}:{clp_config.log_viewer_webui.port}",
885-
),
886-
},
873+
client_settings_json_updates = {
874+
"ClpStorageEngine": clp_config.package.storage_engine,
875+
"MongoDbSearchResultsMetadataCollectionName": clp_config.webui.results_metadata_collection_name,
876+
"SqlDbClpArchivesTableName": f"{table_prefix}{ARCHIVES_TABLE_SUFFIX}",
877+
"SqlDbClpFilesTableName": f"{table_prefix}{FILES_TABLE_SUFFIX}",
878+
"SqlDbCompressionJobsTableName": COMPRESSION_JOBS_TABLE_NAME,
887879
}
888-
meteor_settings = read_and_update_settings_json(settings_json_path, meteor_settings_updates)
889-
890-
# Start container
891-
# fmt: off
892-
container_cmd = [
893-
"docker", "run",
894-
"-d",
895-
"--network", "host",
896-
"--name", container_name,
897-
"--log-driver", "local",
898-
"-u", f"{os.getuid()}:{os.getgid()}",
899-
]
900-
# fmt: on
901-
env_vars = [
902-
f"NODE_PATH={node_path}",
903-
f"MONGO_URL={clp_config.results_cache.get_uri()}",
904-
f"PORT={clp_config.webui.port}",
905-
f"ROOT_URL=http://{clp_config.webui.host}",
906-
f"METEOR_SETTINGS={json.dumps(meteor_settings)}",
907-
f"CLP_DB_USER={clp_config.database.username}",
908-
f"CLP_DB_PASS={clp_config.database.password}",
909-
f"WEBUI_LOGS_DIR={container_webui_logs_dir}",
910-
f"WEBUI_LOGGING_LEVEL={clp_config.webui.logging_level}",
911-
]
912-
necessary_mounts = [
913-
mounts.clp_home,
914-
DockerMount(DockerMountType.BIND, webui_logs_dir, container_webui_logs_dir),
915-
]
916-
append_docker_options(container_cmd, necessary_mounts, env_vars)
917-
container_cmd.append(clp_config.execution_container)
918-
919-
node_cmd = [
920-
str(CONTAINER_CLP_HOME / "bin" / "node-14"),
921-
str(container_webui_dir / "launcher.js"),
922-
str(container_webui_dir / "main.js"),
923-
]
924-
cmd = container_cmd + node_cmd
925-
subprocess.run(cmd, stdout=subprocess.DEVNULL, check=True)
926-
927-
logger.info(f"Started {component_name}.")
928-
929-
930-
def start_log_viewer_webui(
931-
instance_id: str,
932-
clp_config: CLPConfig,
933-
container_clp_config: CLPConfig,
934-
mounts: CLPDockerMounts,
935-
):
936-
component_name = LOG_VIEWER_WEBUI_COMPONENT_NAME
937-
logger.info(f"Starting {component_name}...")
938-
939-
container_name = f"clp-{component_name}-{instance_id}"
940-
if container_exists(container_name):
941-
return
942-
943-
container_log_viewer_webui_dir = CONTAINER_CLP_HOME / "var" / "www" / "log-viewer-webui"
944-
node_path = str(container_log_viewer_webui_dir / "server" / "node_modules")
945-
settings_json_path = (
946-
get_clp_home()
947-
/ "var"
948-
/ "www"
949-
/ "log-viewer-webui"
950-
/ "server"
951-
/ "dist"
952-
/ "server"
953-
/ "settings.json"
880+
client_settings_json = read_and_update_settings_json(
881+
client_settings_json_path, client_settings_json_updates
954882
)
883+
with open(client_settings_json_path, "w") as client_settings_json_file:
884+
client_settings_json_file.write(json.dumps(client_settings_json))
955885

956-
validate_log_viewer_webui_config(clp_config, settings_json_path)
957-
958-
# Read, update, and write back settings.json
959-
settings_json_updates = {
886+
server_settings_json_updates = {
960887
"SqlDbHost": clp_config.database.host,
961888
"SqlDbPort": clp_config.database.port,
962889
"SqlDbName": clp_config.database.name,
963890
"SqlDbQueryJobsTableName": QUERY_JOBS_TABLE_NAME,
964891
"MongoDbHost": clp_config.results_cache.host,
965892
"MongoDbPort": clp_config.results_cache.port,
966893
"MongoDbName": clp_config.results_cache.db_name,
894+
"MongoDbSearchResultsMetadataCollectionName": clp_config.webui.results_metadata_collection_name,
967895
"MongoDbStreamFilesCollectionName": clp_config.results_cache.stream_collection_name,
968-
"ClientDir": str(container_log_viewer_webui_dir / "client"),
896+
"ClientDir": str(container_webui_dir / "client"),
897+
"LogViewerDir": str(container_webui_dir / "yscope-log-viewer"),
969898
"StreamFilesDir": str(container_clp_config.stream_output.get_directory()),
970899
"StreamTargetUncompressedSize": container_clp_config.stream_output.target_uncompressed_size,
971-
"LogViewerDir": str(container_log_viewer_webui_dir / "yscope-log-viewer"),
972900
}
973901

974902
container_cmd_extra_opts = []
@@ -977,23 +905,25 @@ def start_log_viewer_webui(
977905
if StorageType.S3 == stream_storage.type:
978906
s3_config = stream_storage.s3_config
979907

980-
settings_json_updates["StreamFilesS3Region"] = s3_config.region_code
981-
settings_json_updates["StreamFilesS3PathPrefix"] = (
908+
server_settings_json_updates["StreamFilesS3Region"] = s3_config.region_code
909+
server_settings_json_updates["StreamFilesS3PathPrefix"] = (
982910
f"{s3_config.bucket}/{s3_config.key_prefix}"
983911
)
984912
auth = s3_config.aws_authentication
985913
if AwsAuthType.profile == auth.type:
986-
settings_json_updates["StreamFilesS3Profile"] = auth.profile
914+
server_settings_json_updates["StreamFilesS3Profile"] = auth.profile
987915
else:
988-
settings_json_updates["StreamFilesS3Profile"] = None
916+
server_settings_json_updates["StreamFilesS3Profile"] = None
989917
elif StorageType.FS == stream_storage.type:
990-
settings_json_updates["StreamFilesS3Region"] = None
991-
settings_json_updates["StreamFilesS3PathPrefix"] = None
992-
settings_json_updates["StreamFilesS3Profile"] = None
918+
server_settings_json_updates["StreamFilesS3Region"] = None
919+
server_settings_json_updates["StreamFilesS3PathPrefix"] = None
920+
server_settings_json_updates["StreamFilesS3Profile"] = None
993921

994-
settings_json = read_and_update_settings_json(settings_json_path, settings_json_updates)
995-
with open(settings_json_path, "w") as settings_json_file:
996-
settings_json_file.write(json.dumps(settings_json))
922+
server_settings_json = read_and_update_settings_json(
923+
server_settings_json_path, server_settings_json_updates
924+
)
925+
with open(server_settings_json_path, "w") as settings_json_file:
926+
settings_json_file.write(json.dumps(server_settings_json))
997927

998928
# fmt: off
999929
container_cmd = [
@@ -1009,8 +939,8 @@ def start_log_viewer_webui(
1009939

1010940
necessary_env_vars = [
1011941
f"NODE_PATH={node_path}",
1012-
f"HOST={clp_config.log_viewer_webui.host}",
1013-
f"PORT={clp_config.log_viewer_webui.port}",
942+
f"HOST={clp_config.webui.host}",
943+
f"PORT={clp_config.webui.port}",
1014944
f"CLP_DB_USER={clp_config.database.username}",
1015945
f"CLP_DB_PASS={clp_config.database.password}",
1016946
f"NODE_ENV=production",
@@ -1027,7 +957,7 @@ def start_log_viewer_webui(
1027957
necessary_env_vars.append(f"AWS_SECRET_ACCESS_KEY={credentials.secret_access_key}")
1028958
else:
1029959
aws_mount, aws_env_vars = generate_container_auth_options(
1030-
clp_config, LOG_VIEWER_WEBUI_COMPONENT_NAME
960+
clp_config, WEBUI_COMPONENT_NAME
1031961
)
1032962
if aws_mount:
1033963
necessary_mounts.append(mounts.aws_config_dir)
@@ -1038,7 +968,7 @@ def start_log_viewer_webui(
1038968

1039969
node_cmd = [
1040970
str(CONTAINER_CLP_HOME / "bin" / "node-22"),
1041-
str(container_log_viewer_webui_dir / "server" / "dist" / "server" / "src" / "main.js"),
971+
str(container_webui_dir / "server" / "dist" / "server" / "src" / "main.js"),
1042972
]
1043973
cmd = container_cmd + node_cmd
1044974
subprocess.run(cmd, stdout=subprocess.DEVNULL, check=True)
@@ -1147,7 +1077,6 @@ def main(argv):
11471077
reducer_server_parser = component_args_parser.add_parser(REDUCER_COMPONENT_NAME)
11481078
add_num_workers_argument(reducer_server_parser)
11491079
component_args_parser.add_parser(WEBUI_COMPONENT_NAME)
1150-
component_args_parser.add_parser(LOG_VIEWER_WEBUI_COMPONENT_NAME)
11511080

11521081
parsed_args = args_parser.parse_args(argv[1:])
11531082

@@ -1175,7 +1104,6 @@ def main(argv):
11751104
COMPRESSION_SCHEDULER_COMPONENT_NAME,
11761105
QUERY_SCHEDULER_COMPONENT_NAME,
11771106
WEBUI_COMPONENT_NAME,
1178-
LOG_VIEWER_WEBUI_COMPONENT_NAME,
11791107
):
11801108
validate_and_load_db_credentials_file(clp_config, clp_home, True)
11811109
if target in (
@@ -1271,9 +1199,7 @@ def main(argv):
12711199
if target in (ALL_TARGET_NAME, REDUCER_COMPONENT_NAME):
12721200
start_reducer(instance_id, clp_config, container_clp_config, num_workers, mounts)
12731201
if target in (ALL_TARGET_NAME, WEBUI_COMPONENT_NAME):
1274-
start_webui(instance_id, clp_config, mounts)
1275-
if target in (ALL_TARGET_NAME, LOG_VIEWER_WEBUI_COMPONENT_NAME):
1276-
start_log_viewer_webui(instance_id, clp_config, container_clp_config, mounts)
1202+
start_webui(instance_id, clp_config, container_clp_config, mounts)
12771203

12781204
except Exception as ex:
12791205
if type(ex) == ValueError:

components/clp-package-utils/clp_package_utils/scripts/stop_clp.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
COMPRESSION_WORKER_COMPONENT_NAME,
1212
CONTROLLER_TARGET_NAME,
1313
DB_COMPONENT_NAME,
14-
LOG_VIEWER_WEBUI_COMPONENT_NAME,
1514
QUERY_SCHEDULER_COMPONENT_NAME,
1615
QUERY_WORKER_COMPONENT_NAME,
1716
QUEUE_COMPONENT_NAME,
@@ -85,7 +84,6 @@ def main(argv):
8584
component_args_parser.add_parser(COMPRESSION_WORKER_COMPONENT_NAME)
8685
component_args_parser.add_parser(QUERY_WORKER_COMPONENT_NAME)
8786
component_args_parser.add_parser(WEBUI_COMPONENT_NAME)
88-
component_args_parser.add_parser(LOG_VIEWER_WEBUI_COMPONENT_NAME)
8987

9088
parsed_args = args_parser.parse_args(argv[1:])
9189

@@ -104,7 +102,6 @@ def main(argv):
104102
ALL_TARGET_NAME,
105103
CONTROLLER_TARGET_NAME,
106104
DB_COMPONENT_NAME,
107-
LOG_VIEWER_WEBUI_COMPONENT_NAME,
108105
):
109106
validate_and_load_db_credentials_file(clp_config, clp_home, False)
110107
if target in (
@@ -133,9 +130,6 @@ def main(argv):
133130

134131
already_exited_containers = []
135132
force = parsed_args.force
136-
if target in (ALL_TARGET_NAME, LOG_VIEWER_WEBUI_COMPONENT_NAME):
137-
container_name = f"clp-{LOG_VIEWER_WEBUI_COMPONENT_NAME}-{instance_id}"
138-
stop_running_container(container_name, already_exited_containers, force)
139133
if target in (ALL_TARGET_NAME, WEBUI_COMPONENT_NAME):
140134
container_name = f"clp-{WEBUI_COMPONENT_NAME}-{instance_id}"
141135
stop_running_container(container_name, already_exited_containers, force)

0 commit comments

Comments
 (0)