|
|
|
@ -51,22 +51,23 @@ class DBPortManager(object):
|
|
|
|
|
|
|
|
|
|
def pop(self, db: Application): |
|
|
|
|
mapper = self.get_mapper() |
|
|
|
|
to_delete_port = self.get_port_by_db(db) |
|
|
|
|
to_delete_port = self.get_port_by_db(db, raise_exception=False) |
|
|
|
|
mapper.pop(to_delete_port, None) |
|
|
|
|
self.set_mapper(mapper) |
|
|
|
|
|
|
|
|
|
def get_port_by_db(self, db): |
|
|
|
|
def get_port_by_db(self, db, raise_exception=True): |
|
|
|
|
mapper = self.get_mapper() |
|
|
|
|
for port, db_id in mapper.items(): |
|
|
|
|
if db_id == str(db.id): |
|
|
|
|
return port |
|
|
|
|
error = _( |
|
|
|
|
'No available port is matched. ' |
|
|
|
|
'The number of databases may have exceeded the number of ports ' |
|
|
|
|
'open to the database agent service, ' |
|
|
|
|
'Contact the administrator to open more ports.' |
|
|
|
|
) |
|
|
|
|
raise JMSException(error) |
|
|
|
|
if raise_exception: |
|
|
|
|
error = _( |
|
|
|
|
'No available port is matched. ' |
|
|
|
|
'The number of databases may have exceeded the number of ports ' |
|
|
|
|
'open to the database agent service, ' |
|
|
|
|
'Contact the administrator to open more ports.' |
|
|
|
|
) |
|
|
|
|
raise JMSException(error) |
|
|
|
|
|
|
|
|
|
def get_db_by_port(self, port): |
|
|
|
|
try: |
|
|
|
|