Merge pull request #9230 from jumpserver/pr@v2.28@v2.28_perf_dbportmapper

fix: 修改db_port_mapper策略; 启动时进行check校验;
pull/9232/head
老广 2022-12-21 18:59:47 +08:00 committed by GitHub
commit 105ef791b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 3 deletions

View File

@ -19,7 +19,7 @@ logger = get_logger(__file__)
def init_db_port_mapper(sender, **kwargs):
logger.info('Init db port mapper')
try:
db_port_manager.init()
db_port_manager.check()
except (ProgrammingError,) as e:
pass

View File

@ -35,9 +35,22 @@ class DBPortManager(object):
def magnus_listen_port_range(self):
return settings.MAGNUS_PORTS
def init(self):
@staticmethod
def fetch_dbs():
with tmp_to_root_org():
db_ids = Application.objects.filter(category=AppCategory.db).values_list('id', flat=True)
dbs = Application.objects.filter(category=AppCategory.db)
return dbs
def check(self):
dbs = self.fetch_dbs()
for db in dbs:
port = self.get_port_by_db(db, raise_exception=False)
if not port:
self.add(db)
def init(self):
dbs = self.fetch_dbs()
db_ids = dbs.values_list('id', flat=True)
db_ids = [str(i) for i in db_ids]
mapper = dict(zip(self.all_available_ports, list(db_ids)))
self.set_mapper(mapper)