@@ -684,7 +684,7 @@ def stop_shell_complete(ctx, param, incomplete) -> List[str]:
684
684
@click .argument ('entity' , default = "" , shell_complete = stop_shell_complete )
685
685
@click .command ("stop" , help = "prometheus | node_exporter | cadvisor | grafana | flask | container-name | "
686
686
"emulation-name | statsmanager | emulation_executions | pgadmin | all | nginx | postgresql "
687
- "| docker | clustermanager | hostmanagers | hostmanager" )
687
+ "| docker | clustermanager | hostmanagers | hostmanager | clientmanager " )
688
688
def stop (entity : str , name : str , id : int = - 1 , ip : str = "" , container_ip : str = "" ) -> None :
689
689
"""
690
690
Stops an entity
@@ -732,6 +732,8 @@ def stop(entity: str, name: str, id: int = -1, ip: str = "", container_ip: str =
732
732
stop_host_managers (ip = ip , emulation = name , ip_first_octet = id )
733
733
elif entity == "hostmanager" :
734
734
stop_host_manager (ip = ip , container_ip = container_ip , emulation = name , ip_first_octet = id )
735
+ elif entity == "clientmanager" :
736
+ stop_client_manager (ip = ip , emulation = name , ip_first_octet = id )
735
737
else :
736
738
container_stopped = False
737
739
for node in config .cluster_config .cluster_nodes :
@@ -905,9 +907,9 @@ def stop_statsmanager(ip: str) -> None:
905
907
906
908
def stop_host_managers (ip : str , emulation : str , ip_first_octet : int ) -> None :
907
909
"""
908
- Utility function for stopping the Docker statsmanager
910
+ Utility function for stopping the host managers
909
911
910
- :param ip: the ip of the node to stop the Docker statsmanager
912
+ :param ip: the ip of the node to stop the host mangers
911
913
:param emulation: the emulation of the execution
912
914
:param ip_first_octet: the ID of the execution
913
915
:return: None
@@ -928,9 +930,9 @@ def stop_host_managers(ip: str, emulation: str, ip_first_octet: int) -> None:
928
930
929
931
def stop_host_manager (ip : str , container_ip : str , emulation : str , ip_first_octet : int ) -> None :
930
932
"""
931
- Utility function for stopping the Docker statsmanager
933
+ Utility function for stopping the host manager
932
934
933
- :param ip: the ip of the node to stop the Docker statsmanager
935
+ :param ip: the ip of the node to stop the host manager
934
936
:param container_ip: the ip of the host to be stopped
935
937
:param emulation: the emulation of the execution
936
938
:param ip_first_octet: the ID of the execution
@@ -953,6 +955,29 @@ def stop_host_manager(ip: str, container_ip: str, emulation: str, ip_first_octet
953
955
bold = False )
954
956
955
957
958
+ def stop_client_manager (ip : str , emulation : str , ip_first_octet : int ) -> None :
959
+ """
960
+ Utility function for stopping the client manager
961
+
962
+ :param ip: the ip of the node to stop the client manger
963
+ :param emulation: the emulation of the execution
964
+ :param ip_first_octet: the ID of the execution
965
+ :return: None
966
+ """
967
+ import csle_common .constants .constants as constants
968
+ from csle_common .metastore .metastore_facade import MetastoreFacade
969
+ config = MetastoreFacade .get_config (id = 1 )
970
+ for node in config .cluster_config .cluster_nodes :
971
+ if node .ip == ip or ip == "" :
972
+ stopped = ClusterController .stop_client_manager (ip = ip , port = constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT ,
973
+ emulation = emulation , ip_first_octet = ip_first_octet )
974
+ if stopped :
975
+ click .secho (f"Stopping client manager on port:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " )
976
+ else :
977
+ click .secho (f"Client manager is not stopped:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " ,
978
+ bold = False )
979
+
980
+
956
981
@click .argument ('max_workers' , default = 10 , type = int )
957
982
@click .argument ('log_file' , default = "docker_statsmanager.log" , type = str )
958
983
@click .argument ('log_dir' , default = "/var/log/csle" , type = str )
@@ -1144,7 +1169,7 @@ def start_shell_complete(ctx, param, incomplete) -> List[str]:
1144
1169
@click .command ("start" , help = "prometheus | node_exporter | grafana | cadvisor | flask | pgadmin | "
1145
1170
"container-name | emulation-name | all | statsmanager | training_job "
1146
1171
"| system_id_job | nginx | postgresql | docker | clustermanager | hostmanagers "
1147
- "| hostmanager" )
1172
+ "| hostmanager | clientmanager " )
1148
1173
def start (entity : str , no_traffic : bool , name : str , id : int , no_clients : bool , no_network : bool , ip : str ,
1149
1174
container_ip : str , no_beats : bool ) -> None :
1150
1175
"""
@@ -1203,6 +1228,8 @@ def start(entity: str, no_traffic: bool, name: str, id: int, no_clients: bool, n
1203
1228
start_host_managers (ip = ip , emulation = name , ip_first_octet = id )
1204
1229
elif entity == "hostmanager" :
1205
1230
start_host_manager (ip = ip , container_ip = container_ip , emulation = name , ip_first_octet = id )
1231
+ elif entity == "clientmanager" :
1232
+ start_client_manager (ip = ip , emulation = name , ip_first_octet = id )
1206
1233
else :
1207
1234
container_started = False
1208
1235
for node in config .cluster_config .cluster_nodes :
@@ -1401,6 +1428,49 @@ def start_host_managers(ip: str, emulation: str, ip_first_octet: int):
1401
1428
bold = False )
1402
1429
1403
1430
1431
+ def start_client_manager (ip : str , emulation : str , ip_first_octet : int ):
1432
+ """
1433
+ Utility function for starting client manager
1434
+
1435
+ :param ip: the ip of the node to start client manager
1436
+ :param emulation: the emulation of the execution
1437
+ :param ip_first_octet: the ID of the execution
1438
+ :return: None
1439
+ """
1440
+ import csle_common .constants .constants as constants
1441
+ from csle_common .metastore .metastore_facade import MetastoreFacade
1442
+ config = MetastoreFacade .get_config (id = 1 )
1443
+ for node in config .cluster_config .cluster_nodes :
1444
+ if node .ip == ip or ip == "" :
1445
+ operation_outcome = ClusterController .start_client_manager (ip = ip ,
1446
+ port = constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT ,
1447
+ emulation = emulation ,
1448
+ ip_first_octet = ip_first_octet )
1449
+ if operation_outcome .outcome :
1450
+ click .secho (f"Starting client manager on port:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " )
1451
+ else :
1452
+ click .secho (f"Client manager is not started:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " ,
1453
+ bold = False )
1454
+
1455
+ operation_outcome = ClusterController .start_client_population (
1456
+ ip = ip , port = constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT , emulation = emulation ,
1457
+ ip_first_octet = ip_first_octet )
1458
+ if operation_outcome .outcome :
1459
+ click .secho (f"Starting client population on port:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " )
1460
+ else :
1461
+ click .secho (f"Client population is not started:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " ,
1462
+ bold = False )
1463
+
1464
+ operation_outcome = ClusterController .start_kafka_client_producer (
1465
+ ip = ip , port = constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT , emulation = emulation ,
1466
+ ip_first_octet = ip_first_octet )
1467
+ if operation_outcome .outcome :
1468
+ click .secho (f"Starting Kafka client producer on port:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " )
1469
+ else :
1470
+ click .secho (f"Kafka client producer is not started:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " ,
1471
+ bold = False )
1472
+
1473
+
1404
1474
def start_host_manager (ip : str , container_ip : str , emulation : str , ip_first_octet : int ):
1405
1475
"""
1406
1476
Utility function for starting host manager
@@ -1715,7 +1785,8 @@ def ls_shell_complete(ctx, param, incomplete) -> List[str]:
1715
1785
1716
1786
@click .command ("ls" , help = "containers | networks | images | emulations | all | environments | prometheus "
1717
1787
"| node_exporter | cadvisor | pgadmin | statsmanager | flask | "
1718
- "simulations | emulation_executions | cluster | nginx | postgresql | docker | hostmanagers" )
1788
+ "simulations | emulation_executions | cluster | nginx | postgresql | docker | hostmanagers | "
1789
+ "clientmanager" )
1719
1790
@click .argument ('entity' , default = 'all' , type = str , shell_complete = ls_shell_complete )
1720
1791
@click .option ('--all' , is_flag = True , help = 'list all' )
1721
1792
@click .option ('--running' , is_flag = True , help = 'list running only (default)' )
@@ -1782,6 +1853,8 @@ def ls(entity: str, all: bool, running: bool, stopped: bool, ip: str, name: str,
1782
1853
list_emulation_executions ()
1783
1854
elif entity == "hostmanagers" :
1784
1855
list_host_managers (ip = ip , emulation = name , ip_first_octet = id )
1856
+ elif entity == "clientmanager" :
1857
+ list_client_manager (ip = ip , emulation = name , ip_first_octet = id )
1785
1858
else :
1786
1859
container = get_running_container (name = entity )
1787
1860
if container is not None :
@@ -1852,6 +1925,68 @@ def list_host_managers(ip: str, emulation: str, ip_first_octet: int) -> None:
1852
1925
click .secho ('+' + '-' * 50 + '+' , fg = 'white' )
1853
1926
1854
1927
1928
+ def list_client_manager (ip : str , emulation : str , ip_first_octet : int ) -> None :
1929
+ """
1930
+ Utility function for listing client managers
1931
+
1932
+ :param ip: the ip of the node to start host manager
1933
+ :param emulation: the emulation of the execution
1934
+ :param ip_first_octet: the ID of the execution
1935
+
1936
+ :return: None
1937
+ """
1938
+ import csle_common .constants .constants as constants
1939
+ from csle_common .metastore .metastore_facade import MetastoreFacade
1940
+ config = MetastoreFacade .get_config (id = 1 )
1941
+ for node in config .cluster_config .cluster_nodes :
1942
+ if node .ip == ip or ip == "" :
1943
+ host_manager_info = ClusterController .get_client_managers_info (
1944
+ ip = ip , port = constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT , emulation = emulation ,
1945
+ ip_first_octet = ip_first_octet )
1946
+
1947
+ click .secho ('+' + '-' * 60 + '+' , fg = 'white' )
1948
+ click .secho (f'|{ "Host IP" :^40} ' , nl = False , fg = 'white' )
1949
+ for i in range (len (host_manager_info .ips )):
1950
+ click .secho ('|' , nl = False , fg = 'white' )
1951
+ click .secho (f'{ host_manager_info .ips [i ]:<19} ' , nl = False , fg = "green" )
1952
+ click .secho ('|' , fg = 'white' )
1953
+ click .secho ('+' + '-' * 60 + '+' , fg = 'white' )
1954
+
1955
+ click .secho (f'|{ "Clients number" :^40} ' , nl = False , fg = 'white' )
1956
+ click .secho ('|' , nl = False , fg = 'white' )
1957
+ click .secho (f'{ host_manager_info .clientManagersStatuses [i ].num_clients :<19} ' , nl = False , fg = "green" )
1958
+ click .secho ('|' , fg = 'white' )
1959
+ click .secho ('+' + '-' * 60 + '+' , fg = 'white' )
1960
+
1961
+ click .secho (f'|{ "Client process active" :^40} ' , nl = False , fg = 'white' )
1962
+ click .secho ('|' , nl = False , fg = 'white' )
1963
+ click .secho (f'{ bool (host_manager_info .clientManagersStatuses [i ].client_process_active ):<19} ' ,
1964
+ nl = False , fg = "green" )
1965
+ click .secho ('|' , fg = 'white' )
1966
+ click .secho ('+' + '-' * 60 + '+' , fg = 'white' )
1967
+
1968
+ click .secho (f'|{ "Procedure active" :^40} ' , nl = False , fg = 'white' )
1969
+ click .secho ('|' , nl = False , fg = 'white' )
1970
+ click .secho (f'{ bool (host_manager_info .clientManagersStatuses [i ].producer_active ):<19} ' ,
1971
+ nl = False , fg = "green" )
1972
+ click .secho ('|' , fg = 'white' )
1973
+ click .secho ('+' + '-' * 60 + '+' , fg = 'white' )
1974
+
1975
+ click .secho (f'|{ "Client time step length in seconds" :^40} ' , nl = False , fg = 'white' )
1976
+ click .secho ('|' , nl = False , fg = 'white' )
1977
+ click .secho (f'{ host_manager_info .clientManagersStatuses [i ].clients_time_step_len_seconds :<19} ' ,
1978
+ nl = False , fg = "green" )
1979
+ click .secho ('|' , fg = 'white' )
1980
+ click .secho ('+' + '-' * 60 + '+' , fg = 'white' )
1981
+
1982
+ click .secho (f'|{ "Producer time step length in seconds" :^40} ' , nl = False , fg = 'white' )
1983
+ click .secho ('|' , nl = False , fg = 'white' )
1984
+ click .secho (f'{ host_manager_info .clientManagersStatuses [i ].producer_time_step_len_seconds :<19} ' ,
1985
+ nl = False , fg = "green" )
1986
+ click .secho ('|' , fg = 'white' )
1987
+ click .secho ('+' + '-' * 60 + '+' , fg = 'white' )
1988
+
1989
+
1855
1990
def print_running_container (container : DockerContainerDTO ) -> None :
1856
1991
"""
1857
1992
Utility function for printing information about a running container
0 commit comments