Skip to content

Commit

Permalink
feature: PaaS 容器部署适配 (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhuoZhuoCrayon committed Oct 19, 2021
1 parent da30f53 commit 6e1f36e
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions apps/node_man/periodic_tasks/gse_svr_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
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.
"""
from telnetlib import Telnet
from typing import List, Optional, Tuple

from celery.schedules import crontab
Expand All @@ -20,6 +21,18 @@
from common.log import logger


def check_ip_ports_reachable(host: str, ports: List[str]) -> bool:

for port in ports:
try:
with Telnet(host=host, port=port, timeout=2):
pass
except (ConnectionRefusedError, TimeoutError):
logger.error(f"host -> {host}, port -> {port} not reachable.")
return False
return True


class ZkSafeClient:

zk_client: Optional[KazooClient]
Expand Down Expand Up @@ -56,6 +69,12 @@ def gse_svr_discovery():
"/gse/config/server/taskserver/all": "taskserver",
"/gse/config/server/btfiles/all": "btfileserver",
}
zk_node_path__check_ports_map = {
"/gse/config/server/dataserver/all": [ap.port_config["data_port"]],
"/gse/config/server/taskserver/all": [ap.port_config["io_port"]],
"/gse/config/server/btfiles/all": [ap.port_config["file_svr_port"]]
+ [port for port in range(ap.port_config["bt_port"], ap.port_config["tracker_port"] + 1)],
}

is_change = False
auth_data = None
Expand All @@ -67,6 +86,13 @@ def gse_svr_discovery():
for zk_node_path, ap_field in zk_node_path__ap_field_map.items():
try:
svr_ips = zk_client.get_children(path=zk_node_path)
# 过滤不可达的ip
svr_ips = [
svr_ip
for svr_ip in svr_ips
if check_ip_ports_reachable(svr_ip, zk_node_path__check_ports_map[zk_node_path])
]

except NoNodeError:
logger.error(f"zk_node_path -> {zk_node_path} not exist")
except NoAuthError:
Expand Down

0 comments on commit 6e1f36e

Please sign in to comment.