Restored setQuotaTypeServer()
This commit restores the method setQuotaTypeServer() which set the server type as metadata. Change-Id: I09dfafdbe73d59eb43c09c79a50a5449e63833e4 Sem-Ver: bugfix
This commit is contained in:
parent
1a237bdfde
commit
7a9395ce23
@ -229,7 +229,6 @@ class Queue(SynergyObject):
|
|||||||
heapq.heappush(self._items, (-item.getPriority(),
|
heapq.heappush(self._items, (-item.getPriority(),
|
||||||
item.getCreationTime(), item))
|
item.getCreationTime(), item))
|
||||||
|
|
||||||
self._incSize(1)
|
|
||||||
self.condition.notifyAll()
|
self.condition.notifyAll()
|
||||||
|
|
||||||
def getType(self):
|
def getType(self):
|
||||||
|
@ -24,7 +24,7 @@ See the License for the specific language governing
|
|||||||
permissions and limitations under the License."""
|
permissions and limitations under the License."""
|
||||||
|
|
||||||
|
|
||||||
LOG = logging.getLogger("quota")
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class Quota(SynergyObject):
|
class Quota(SynergyObject):
|
||||||
|
@ -685,6 +685,33 @@ class NovaManager(Manager):
|
|||||||
|
|
||||||
return response_data
|
return response_data
|
||||||
|
|
||||||
|
def setQuotaTypeServer(self, server):
|
||||||
|
if not server:
|
||||||
|
return
|
||||||
|
|
||||||
|
QUERY = "insert into nova.instance_metadata (created_at, `key`, " \
|
||||||
|
"`value`, instance_uuid) values (%s, 'quota', %s, %s)"
|
||||||
|
|
||||||
|
connection = self.db_engine.connect()
|
||||||
|
trans = connection.begin()
|
||||||
|
|
||||||
|
quota_type = "private"
|
||||||
|
|
||||||
|
if server.isEphemeral():
|
||||||
|
quota_type = "shared"
|
||||||
|
|
||||||
|
try:
|
||||||
|
connection.execute(QUERY,
|
||||||
|
[server.getCreatedAt(), quota_type,
|
||||||
|
server.getId()])
|
||||||
|
|
||||||
|
trans.commit()
|
||||||
|
except SQLAlchemyError as ex:
|
||||||
|
trans.rollback()
|
||||||
|
raise SynergyError(ex.message)
|
||||||
|
finally:
|
||||||
|
connection.close()
|
||||||
|
|
||||||
def getHosts(self):
|
def getHosts(self):
|
||||||
data = {}
|
data = {}
|
||||||
url = "os-hosts"
|
url = "os-hosts"
|
||||||
|
@ -378,3 +378,4 @@ NOT NULL PRIMARY KEY, name VARCHAR(64), share INT DEFAULT 0, TTL INT DEFAULT \
|
|||||||
raise SynergyError(ex.message)
|
raise SynergyError(ex.message)
|
||||||
finally:
|
finally:
|
||||||
connection.close()
|
connection.close()
|
||||||
|
self.notify(event_type="PROJECT_DONE")
|
||||||
|
@ -37,8 +37,6 @@ class QuotaManager(Manager):
|
|||||||
super(QuotaManager, self).__init__("QuotaManager")
|
super(QuotaManager, self).__init__("QuotaManager")
|
||||||
|
|
||||||
def setup(self):
|
def setup(self):
|
||||||
self.projects = {}
|
|
||||||
|
|
||||||
if self.getManager("NovaManager") is None:
|
if self.getManager("NovaManager") is None:
|
||||||
raise SynergyError("NovaManager not found!")
|
raise SynergyError("NovaManager not found!")
|
||||||
|
|
||||||
@ -142,8 +140,7 @@ class QuotaManager(Manager):
|
|||||||
project.getName(),
|
project.getName(),
|
||||||
project.getId()))
|
project.getId()))
|
||||||
quota.allocate(server)
|
quota.allocate(server)
|
||||||
|
self.updateSharedQuota()
|
||||||
self.projects[project.getId()] = project
|
|
||||||
except SynergyError as ex:
|
except SynergyError as ex:
|
||||||
LOG.error(ex)
|
LOG.error(ex)
|
||||||
raise ex
|
raise ex
|
||||||
@ -254,34 +251,12 @@ class QuotaManager(Manager):
|
|||||||
kprojects = self.keystone_manager.getProjects(domain_id=dom_id)
|
kprojects = self.keystone_manager.getProjects(domain_id=dom_id)
|
||||||
|
|
||||||
for kproject in kprojects:
|
for kproject in kprojects:
|
||||||
project = self.project_manager.getProject(id=kproject.getId())
|
quota = self.nova_manager.getQuota(kproject.getId())
|
||||||
|
|
||||||
if project:
|
if quota.getSize("vcpus") == -1 and\
|
||||||
quota = self.nova_manager.getQuota(project.getId(),
|
quota.getSize("memory") == -1:
|
||||||
|
quota = self.nova_manager.getQuota(kproject.getId(),
|
||||||
is_class=True)
|
is_class=True)
|
||||||
pquota = project.getQuota()
|
|
||||||
vcpus_size = quota.getSize("vcpus")
|
|
||||||
vcpus_usage = pquota.getUsage("vcpus")
|
|
||||||
mem_size = quota.getSize("memory")
|
|
||||||
mem_usage = pquota.getUsage("memory")
|
|
||||||
|
|
||||||
if vcpus_usage > vcpus_size or mem_usage > mem_size:
|
|
||||||
LOG.info("cannot shrink the private quota for project"
|
|
||||||
" %r (id=%s) because the usage of current "
|
|
||||||
"quota exceeds the new size (vcpus=%s, "
|
|
||||||
"memory=%s)" % (project.getName(),
|
|
||||||
project.getId(),
|
|
||||||
quota.getSize("vcpus"),
|
|
||||||
quota.getSize("memory")))
|
|
||||||
self.nova_manager.updateQuota(pquota, is_class=True)
|
|
||||||
quota = pquota
|
|
||||||
else:
|
|
||||||
pquota.setSize("vcpus", value=quota.getSize("vcpus"))
|
|
||||||
pquota.setSize("memory", value=quota.getSize("memory"))
|
|
||||||
pquota.setSize("instances",
|
|
||||||
value=quota.getSize("instances"))
|
|
||||||
else:
|
|
||||||
quota = self.nova_manager.getQuota(kproject.getId())
|
|
||||||
|
|
||||||
if quota.getSize("vcpus") > 0:
|
if quota.getSize("vcpus") > 0:
|
||||||
static_vcpus += quota.getSize("vcpus")
|
static_vcpus += quota.getSize("vcpus")
|
||||||
|
@ -74,6 +74,10 @@ class Worker(Thread):
|
|||||||
while queue_items:
|
while queue_items:
|
||||||
self.queue.restore(queue_items.pop(0))
|
self.queue.restore(queue_items.pop(0))
|
||||||
|
|
||||||
|
for project in self.project_manager.getProjects():
|
||||||
|
for user in project.getUsers():
|
||||||
|
self.queue.updatePriority(user)
|
||||||
|
|
||||||
if len(queue_items) >= self.backfill_depth:
|
if len(queue_items) >= self.backfill_depth:
|
||||||
SharedQuota.wait()
|
SharedQuota.wait()
|
||||||
continue
|
continue
|
||||||
@ -213,8 +217,6 @@ class SchedulerManager(Manager):
|
|||||||
if self.configured:
|
if self.configured:
|
||||||
return
|
return
|
||||||
|
|
||||||
self.quota_manager.updateSharedQuota()
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.queue = self.queue_manager.createQueue("DYNAMIC", "PRIORITY")
|
self.queue = self.queue_manager.createQueue("DYNAMIC", "PRIORITY")
|
||||||
except SynergyError as ex:
|
except SynergyError as ex:
|
||||||
@ -232,7 +234,6 @@ class SchedulerManager(Manager):
|
|||||||
self.nova_manager,
|
self.nova_manager,
|
||||||
self.keystone_manager,
|
self.keystone_manager,
|
||||||
self.backfill_depth)
|
self.backfill_depth)
|
||||||
worker.start()
|
|
||||||
|
|
||||||
self.workers.append(worker)
|
self.workers.append(worker)
|
||||||
|
|
||||||
@ -268,6 +269,10 @@ class SchedulerManager(Manager):
|
|||||||
if self.queue:
|
if self.queue:
|
||||||
self.queue.updatePriority(kwargs.get("user", None))
|
self.queue.updatePriority(kwargs.get("user", None))
|
||||||
|
|
||||||
|
elif event_type == "PROJECT_DONE":
|
||||||
|
for worker in self.workers:
|
||||||
|
worker.start()
|
||||||
|
|
||||||
def _processServerEvent(self, server, event, state):
|
def _processServerEvent(self, server, event, state):
|
||||||
project = self.project_manager.getProject(id=server.getProjectId())
|
project = self.project_manager.getProject(id=server.getProjectId())
|
||||||
|
|
||||||
@ -298,21 +303,14 @@ class SchedulerManager(Manager):
|
|||||||
LOG.warn("cannot release server %s "
|
LOG.warn("cannot release server %s "
|
||||||
"(reason=%s)" % (server.getId(), ex))
|
"(reason=%s)" % (server.getId(), ex))
|
||||||
elif state == "error":
|
elif state == "error":
|
||||||
LOG.info("error occurred on server %s (host %s)"
|
|
||||||
% (server.getId(), server.getHost()))
|
|
||||||
|
|
||||||
if not server.getTerminatedAt() and not server.getDeletedAt():
|
if not server.getTerminatedAt() and not server.getDeletedAt():
|
||||||
try:
|
try:
|
||||||
self.nova_manager.deleteServer(server)
|
LOG.info("error occurred on server %s (host %s)"
|
||||||
except Exception as ex:
|
% (server.getId(), server.getHost()))
|
||||||
LOG.error("cannot delete server %s: %s"
|
|
||||||
% (server.getId(), ex))
|
|
||||||
|
|
||||||
try:
|
self.nova_manager.deleteServer(server)
|
||||||
quota.release(server)
|
except Exception:
|
||||||
except Exception as ex:
|
pass
|
||||||
LOG.warn("cannot release server %s "
|
|
||||||
"(reason=%s)" % (server.getId(), ex))
|
|
||||||
|
|
||||||
def _processServerCreate(self, request):
|
def _processServerCreate(self, request):
|
||||||
server = request.getServer()
|
server = request.getServer()
|
||||||
@ -339,6 +337,8 @@ class SchedulerManager(Manager):
|
|||||||
request.getProjectId(), num_attempts, reason))
|
request.getProjectId(), num_attempts, reason))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
self.nova_manager.setQuotaTypeServer(server)
|
||||||
|
|
||||||
if server.isPermanent():
|
if server.isPermanent():
|
||||||
if quota.allocate(server, blocking=False):
|
if quota.allocate(server, blocking=False):
|
||||||
LOG.info("new request: id=%s user_id=%s prj_id=%s "
|
LOG.info("new request: id=%s user_id=%s prj_id=%s "
|
||||||
|
Loading…
x
Reference in New Issue
Block a user