|
@@ -10,6 +10,7 @@ import longvideoapi_config
|
|
|
|
|
|
from concurrent.futures import ThreadPoolExecutor
|
|
|
|
|
|
+from gateway.gateway_config import server_group_id_list
|
|
|
|
|
|
health_instances = []
|
|
|
ess_instances = []
|
|
@@ -90,12 +91,20 @@ async def ess_instance(ecs_client, alb_client, ess_count, max_workers, version,
|
|
|
|
|
|
add_weight_list = [(10, 5), (20, 5), (40, 5), (60, 5), (80, 5), (100, 5)]
|
|
|
alb_utils.update_server_group_servers_attribute(alb_client,
|
|
|
- longvideoapi_config.server_group_id_list,
|
|
|
- health_instance_ids,
|
|
|
- add_weight_list,
|
|
|
- longvideoapi_config.port)
|
|
|
- logging.info(f"finished instances: {health_instances}, count: {len(health_instances)}")
|
|
|
-
|
|
|
+ server_group_id_list=longvideoapi_config.server_group_id_list,
|
|
|
+ instance_id_list=health_instance_ids,
|
|
|
+ weight_list=add_weight_list,
|
|
|
+ port=port)
|
|
|
+ global ess_instances
|
|
|
+ ess_instances.extend(health_instance_ids)
|
|
|
+ logging.info(f"ess count: {ess_count}, "
|
|
|
+ f"create count: {len(ess_instance_ids)}, "
|
|
|
+ f"finished count: {len(health_instance_ids)}")
|
|
|
+ else:
|
|
|
+ logging.info(f"ess count: {ess_count}, "
|
|
|
+ f"create count: {len(ess_instance_ids)}, "
|
|
|
+ f"health count: {len(health_instances)}")
|
|
|
+ sys.exit()
|
|
|
|
|
|
|
|
|
def remove_container_image(ecs_client, instance_id, container_name_list):
|
|
@@ -217,10 +226,10 @@ async def update_instance(ecs_client, alb_client, instance_ids, max_workers, ver
|
|
|
|
|
|
add_weight_list = [(10, 5), (20, 5), (40, 5), (60, 5), (80, 5), (100, 5)]
|
|
|
alb_utils.update_server_group_servers_attribute(alb_client,
|
|
|
- longvideoapi_config.server_group_id_list,
|
|
|
- health_instance_ids,
|
|
|
- add_weight_list,
|
|
|
- port)
|
|
|
+ server_group_id_list=longvideoapi_config.server_group_id_list,
|
|
|
+ instance_id_list=health_instance_ids,
|
|
|
+ weight_list=add_weight_list,
|
|
|
+ port=port)
|
|
|
logging.info(f"finished instances: {health_instances}, count: {len(health_instances)}")
|
|
|
update_finished_count += len(health_instances)
|
|
|
logging.info(f"update finished: {update_finished_count}/{len(instance_ids)}")
|
|
@@ -242,10 +251,10 @@ def remove_instances(ecs_client, alb_client, instance_ids, port):
|
|
|
weight_list = [(0, 20)] # 设置权重为0,等待20秒
|
|
|
try:
|
|
|
alb_utils.update_server_group_servers_attribute(alb_client,
|
|
|
- longvideoapi_config.server_group_id_list,
|
|
|
- instance_ids,
|
|
|
- weight_list,
|
|
|
- port)
|
|
|
+ server_group_id_list=longvideoapi_config.server_group_id_list,
|
|
|
+ instance_id_list=instance_ids,
|
|
|
+ weight_list=weight_list,
|
|
|
+ port=port)
|
|
|
except Exception as e:
|
|
|
logging.error(f"Failed to set instance weight: {e}")
|
|
|
sys.exit()
|
|
@@ -255,7 +264,7 @@ def remove_instances(ecs_client, alb_client, instance_ids, port):
|
|
|
for server_group_id in longvideoapi_config.server_group_id_list:
|
|
|
try:
|
|
|
alb_utils.remove_servers_from_server_group(alb_client=alb_client, server_group_id=server_group_id,
|
|
|
- instance_id=instance_ids, port=port)
|
|
|
+ instance_ids=instance_ids, port=port)
|
|
|
logging.info(f"Successfully removed instances from server group {server_group_id}.")
|
|
|
except Exception as e:
|
|
|
logging.error(f"Failed to remove instances from server group {server_group_id}: {e}")
|
|
@@ -329,7 +338,7 @@ def main():
|
|
|
|
|
|
# 4. 停止并释放扩容机器
|
|
|
logging.info(f"stop & release instances start ...")
|
|
|
- remove_instances(ecs_client=ecs_client, alb_client=alb_client, instance_ids=ess_instances)
|
|
|
+ remove_instances(ecs_client=ecs_client, alb_client=alb_client, instance_ids=ess_instances, port=longvideoapi_config.port)
|
|
|
logging.info(f"stop & release instances end!")
|
|
|
except Exception as e:
|
|
|
logging.error(e)
|