@@ -679,11 +679,12 @@ def stop_shell_complete(ctx, param, incomplete) -> List[str]:
679
679
680
680
@click .option ('--ip' , default = "" , type = str )
681
681
@click .argument ('id' , default = - 1 )
682
+ @click .argument ('name' , default = "" , type = str )
682
683
@click .argument ('entity' , default = "" , shell_complete = stop_shell_complete )
683
684
@click .command ("stop" , help = "prometheus | node_exporter | cadvisor | grafana | flask | container-name | "
684
685
"emulation-name | statsmanager | emulation_executions | pgadmin | all | nginx | postgresql "
685
- "| docker | clustermanager" )
686
- def stop (entity : str , id : int = - 1 , ip : str = "" ) -> None :
686
+ "| docker | clustermanager | hostmanagers " )
687
+ def stop (entity : str , name : str , id : int = - 1 , ip : str = "" ) -> None :
687
688
"""
688
689
Stops an entity
689
690
@@ -726,6 +727,8 @@ def stop(entity: str, id: int = -1, ip: str = "") -> None:
726
727
stop_statsmanager (ip = ip )
727
728
elif entity == "emulation_executions" :
728
729
stop_emulation_executions ()
730
+ elif entity == "hostmanager" :
731
+ stop_host_managers (ip = ip , emulation = name , ip_first_octet = id )
729
732
else :
730
733
container_stopped = False
731
734
for node in config .cluster_config .cluster_nodes :
@@ -897,6 +900,30 @@ def stop_statsmanager(ip: str) -> None:
897
900
ClusterController .stop_docker_statsmanager (ip = node .ip , port = constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT )
898
901
899
902
903
+ def stop_host_managers (ip : str , emulation : str , ip_first_octet : int ) -> None :
904
+ """
905
+ Utility function for stopping the Docker statsmanager
906
+
907
+ :param ip: the ip of the node to stop the Docker statsmanager
908
+ :param emulation: the emulation of the execution
909
+ :param ip_first_octet: the ID of the execution
910
+ :return: None
911
+ """
912
+ import csle_common .constants .constants as constants
913
+ from csle_common .metastore .metastore_facade import MetastoreFacade
914
+ config = MetastoreFacade .get_config (id = 1 )
915
+ for node in config .cluster_config .cluster_nodes :
916
+ if node .ip == ip or ip == "" :
917
+ stopped = ClusterController .stop_host_managers (ip = ip , port = constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT ,
918
+ emulation = emulation , ip_first_octet = ip_first_octet )
919
+ if stopped :
920
+ click .secho (f"Stopping host managers on port:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " )
921
+ else :
922
+ click .secho (f"Host managers are not stopped:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " ,
923
+ bold = False )
924
+
925
+
926
+
900
927
@click .argument ('max_workers' , default = 10 , type = int )
901
928
@click .argument ('log_file' , default = "docker_statsmanager.log" , type = str )
902
929
@click .argument ('log_dir' , default = "/var/log/csle" , type = str )
@@ -1086,7 +1113,7 @@ def start_shell_complete(ctx, param, incomplete) -> List[str]:
1086
1113
@click .argument ('entity' , default = "" , type = str , shell_complete = start_shell_complete )
1087
1114
@click .command ("start" , help = "prometheus | node_exporter | grafana | cadvisor | flask | pgadmin | "
1088
1115
"container-name | emulation-name | all | statsmanager | training_job "
1089
- "| system_id_job | nginx | postgresql | docker | clustermanager" )
1116
+ "| system_id_job | nginx | postgresql | docker | clustermanager | hostmanager " )
1090
1117
def start (entity : str , no_traffic : bool , name : str , id : int , no_clients : bool , no_network : bool , ip : str ,
1091
1118
no_beats : bool ) -> None :
1092
1119
"""
@@ -1140,6 +1167,8 @@ def start(entity: str, no_traffic: bool, name: str, id: int, no_clients: bool, n
1140
1167
data_collection_job = system_id_job )
1141
1168
elif entity == "flask" :
1142
1169
start_flask (ip = ip )
1170
+ elif entity == "hostmanager" :
1171
+ start_host_manager (ip = ip , emulation = name , ip_first_octet = id )
1143
1172
else :
1144
1173
container_started = False
1145
1174
for node in config .cluster_config .cluster_nodes :
@@ -1312,6 +1341,24 @@ def start_statsmanager(ip: str) -> None:
1312
1341
if node .ip == ip or ip == "" :
1313
1342
ClusterController .start_docker_statsmanager (ip = node .ip , port = constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT )
1314
1343
1344
+ def start_host_manager (ip : str , emulation : str , ip_first_octet : int ):
1345
+ """
1346
+ Utility function for starting host manager
1347
+
1348
+ :param ip: the ip of the node to start host manager
1349
+ :param emulation: the emulation of the execution
1350
+ :param ip_first_octet: the ID of the execution
1351
+
1352
+ :return: None
1353
+ """
1354
+ import csle_common .constants .constants as constants
1355
+ from csle_common .metastore .metastore_facade import MetastoreFacade
1356
+ config = MetastoreFacade .get_config (id = 1 )
1357
+ for node in config .cluster_config .cluster_nodes :
1358
+ if node .ip == ip or ip == "" :
1359
+ ClusterController .start_host_managers (ip = ip , port = constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT ,
1360
+ emulation = emulation , ip_first_octet = ip_first_octet )
1361
+
1315
1362
1316
1363
def run_image (image : str , name : str , create_network : bool = True , version : str = "0.0.1" ) -> bool :
1317
1364
"""
@@ -1599,12 +1646,15 @@ def ls_shell_complete(ctx, param, incomplete) -> List[str]:
1599
1646
1600
1647
@click .command ("ls" , help = "containers | networks | images | emulations | all | environments | prometheus "
1601
1648
"| node_exporter | cadvisor | pgadmin | statsmanager | flask | "
1602
- "simulations | emulation_executions | cluster | nginx | postgresql | docker" )
1649
+ "simulations | emulation_executions | cluster | nginx | postgresql | docker | hostmanagers " )
1603
1650
@click .argument ('entity' , default = 'all' , type = str , shell_complete = ls_shell_complete )
1604
1651
@click .option ('--all' , is_flag = True , help = 'list all' )
1605
1652
@click .option ('--running' , is_flag = True , help = 'list running only (default)' )
1606
1653
@click .option ('--stopped' , is_flag = True , help = 'list stopped only' )
1607
- def ls (entity : str , all : bool , running : bool , stopped : bool ) -> None :
1654
+ @click .option ('--ip' , default = "" , type = str )
1655
+ @click .option ('--id' , default = None , type = int )
1656
+ @click .option ('--name' , default = "" , type = str )
1657
+ def ls (entity : str , all : bool , running : bool , stopped : bool , ip : str , name : str , id : int ) -> None :
1608
1658
"""
1609
1659
Lists the set of containers, networks, images, or emulations, or all
1610
1660
@@ -1661,6 +1711,8 @@ def ls(entity: str, all: bool, running: bool, stopped: bool) -> None:
1661
1711
list_simulations ()
1662
1712
elif entity == "emulation_executions" :
1663
1713
list_emulation_executions ()
1714
+ elif entity == "hostmanagers" :
1715
+ list_host_managers (ip = ip , emulation = name , ip_first_octet = id )
1664
1716
else :
1665
1717
container = get_running_container (name = entity )
1666
1718
if container is not None :
@@ -1694,6 +1746,39 @@ def ls(entity: str, all: bool, running: bool, stopped: bool) -> None:
1694
1746
else :
1695
1747
click .secho (f"entity: { entity } is not recognized" , fg = "red" , bold = True )
1696
1748
1749
+ def list_host_managers (ip : str , emulation : str , ip_first_octet : int ) -> None :
1750
+ """
1751
+ Utility function for listing host managers
1752
+
1753
+ :param ip: the ip of the node to start host manager
1754
+ :param emulation: the emulation of the execution
1755
+ :param ip_first_octet: the ID of the execution
1756
+
1757
+ :return: None
1758
+ """
1759
+ import csle_common .constants .constants as constants
1760
+ from csle_common .metastore .metastore_facade import MetastoreFacade
1761
+ config = MetastoreFacade .get_config (id = 1 )
1762
+ for node in config .cluster_config .cluster_nodes :
1763
+ if node .ip == ip or ip == "" :
1764
+ host_manage_info = ClusterController .get_host_managers_info (ip = ip , port = constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT ,
1765
+ emulation = emulation , ip_first_octet = ip_first_octet )
1766
+ host_managers = host_manage_info .hostManagersStatuses
1767
+
1768
+ click .secho ('+' + '-' * 50 + '+' , fg = 'white' )
1769
+ click .secho (f'|{ "Host IP" :^30} |{ "Running Status" :^19} |' , fg = 'white' )
1770
+ click .secho ('+' + '-' * 50 + '+' , fg = 'white' )
1771
+ for hosts in host_managers :
1772
+ status = "Running" if hosts .monitor_running else "Stopped"
1773
+ status_color = 'green' if hosts .monitor_running else 'red'
1774
+
1775
+ click .secho ('|' , nl = False , fg = 'white' )
1776
+ click .secho (f'{ hosts .ip :<30} ' , nl = False , fg = 'white' )
1777
+ click .secho ('|' , nl = False , fg = 'white' )
1778
+ click .secho (f'{ status :<19} ' , nl = False , fg = status_color )
1779
+ click .secho ('|' , fg = 'white' )
1780
+ click .secho ('+' + '-' * 50 + '+' , fg = 'white' )
1781
+
1697
1782
1698
1783
def print_running_container (container : DockerContainerDTO ) -> None :
1699
1784
"""
0 commit comments