diff --git a/synergy_scheduler_manager/client/command.py b/synergy_scheduler_manager/client/command.py index d199e0d..cc4ef9b 100644 --- a/synergy_scheduler_manager/client/command.py +++ b/synergy_scheduler_manager/client/command.py @@ -96,7 +96,7 @@ class ProjectCommand(ExecuteCommand): if args.s_quota: headers.append("shared quota") if args.queue: - headers.append("queue") + headers.append("queue usage") if args.share: headers.append("share") if args.ttl: @@ -160,8 +160,8 @@ class ProjectCommand(ExecuteCommand): share = project.getShare() share_value = share.getValue() share_norm = share.getNormalizedValue() - row.append("{:.2f}% | {:.2f}%".format(share_value, - share_norm * 100)) + row.append("{:.2f}% | {:.2%}".format(share_value, + share_norm)) if attribute == "TTL": row.append(project.getTTL()) @@ -195,22 +195,21 @@ class ProjectCommand(ExecuteCommand): if attribute == "usage": data = project.getData() - usage = "vcpus: {:.2f}% | ram: {:.2f}%".format( - data["effective_vcpus"] * 100, - data["effective_memory"] * 100) + usage = "vcpus: {:.2%} | ram: {:.2%}".format( + data["effective_vcpus"], data["effective_memory"]) row.append(usage) - if attribute == "queue": + if attribute == "queue usage": data = project.getData() q_usage = data.get("queue_usage", 0) q_size = data.get("queue_size", 0) if q_size: - usage = float(q_usage) / float(q_size) * 100 - row.append("{:.2f}%".format(usage)) + usage = float(q_usage) / float(q_size) + row.append("{:d} ({:.2%})".format(q_usage, usage)) else: - row.append("0%") + row.append("0 (0%)") table.append(row) @@ -300,19 +299,18 @@ class UserCommand(ExecuteCommand): if attribute == "share": share = user.getShare() - share_value = share.getValue() share_norm = share.getNormalizedValue() - row.append("{:.2f}% | {:.2f}%".format(share_value, - share_norm * 100)) + + row.append("{:.2%}".format(share_norm)) + if attribute == "priority": row.append(user.getPriority().getValue()) if attribute == "usage": data = user.getData() - usage = "vcpus: {:.2f}% | ram: {:.2f}%".format( - data["actual_vcpus"] * 100, - data["actual_memory"] * 100) + usage = "vcpus: {:.2%} | ram: {:.2%}".format( + data["actual_vcpus"], data["actual_memory"]) row.append(usage) diff --git a/synergy_scheduler_manager/project_manager.py b/synergy_scheduler_manager/project_manager.py index 47665b4..84d8b1f 100644 --- a/synergy_scheduler_manager/project_manager.py +++ b/synergy_scheduler_manager/project_manager.py @@ -140,8 +140,9 @@ class ProjectManager(Manager): project = self.getProject(id=prj_id) if project: - project.removeUser(usr_id) - self.notify(event_type="USER_REMOVED", user=user) + user = project.removeUser(usr_id) + if user: + self.notify(event_type="USER_REMOVED", user=user) elif event_type == "identity.user.deleted": user_id = kwargs.get("resource_info", None) @@ -156,6 +157,14 @@ class ProjectManager(Manager): except SynergyError as ex: LOG.info(ex) + elif event_type == "identity.project.deleted": + LOG.info(kwargs) + prj_id = kwargs.get("resource_info", None) + project = self.getProject(id=prj_id, name=prj_id) + + if project: + self._removeProject(project) + def _parseNumber(self, value, default=None): if not value: return default @@ -168,8 +177,13 @@ class ProjectManager(Manager): raise SynergyError("%r is not a number!" % str(value)) def _addProject(self, prj_id, prj_name, TTL, share): + project = None + if prj_id: - project = self.keystone_manager.getProject(prj_id) + try: + project = self.keystone_manager.getProject(prj_id) + except SynergyError: + raise SynergyError("project not found in Keystone!") elif prj_name: projects = self.keystone_manager.getProjects(name=prj_name) @@ -182,7 +196,7 @@ class ProjectManager(Manager): raise SynergyError("missing project attributes") if not project: - raise SynergyError("project not found!") + raise SynergyError("project not found in Keystone!") prj_TTL = self._parseNumber(TTL, default=self.default_TTL) prj_share = self._parseNumber(share, 0) @@ -213,9 +227,14 @@ class ProjectManager(Manager): finally: connection.close() + users = self.keystone_manager.getUsers(prj_id=project.getId()) + + for user in users: + project.addUser(user) + self.projects[project.getId()] = project - LOG.info("added project %s" % project.getName()) + LOG.info("added project %r" % project.getName()) self.notify(event_type="PROJECT_ADDED", project=project) return project @@ -255,13 +274,14 @@ class ProjectManager(Manager): finally: connection.close() + LOG.info("updated project %r" % project.getName()) self.notify(event_type="PROJECT_UPDATED", project=project) - def _removeProject(self, project): - if project.getId() not in self.projects.keys(): - raise SynergyError("project %s not found!" % project.getId()) - - self.projects.pop(project.getId()) + def _removeProject(self, project, force=False): + if not force: + if project.getId() not in self.projects.keys(): + raise SynergyError("project %s not found!" % project.getId()) + self.projects.pop(project.getId()) connection = self.db_engine.connect() trans = connection.begin() @@ -279,7 +299,7 @@ class ProjectManager(Manager): finally: connection.close() - LOG.info("removed project %s" % project.getName()) + LOG.info("removed project %r" % project.getName()) self.notify(event_type="PROJECT_REMOVED", project=project) def getProject(self, id=None, name=None): @@ -336,7 +356,7 @@ NOT NULL PRIMARY KEY, name VARCHAR(64), share INT DEFAULT 0, TTL INT DEFAULT \ k_project = self.keystone_manager.getProject(project_id) if not k_project: - self.removeProject(project) + self._removeProject(project) continue users = self.keystone_manager.getUsers(prj_id=project_id) @@ -350,7 +370,10 @@ NOT NULL PRIMARY KEY, name VARCHAR(64), share INT DEFAULT 0, TTL INT DEFAULT \ except SynergyError as ex: LOG.info("the project %s seems not to exist anymore! " "(reason=%s)" % (project.getName(), ex.message)) - self.removeProject(project) + try: + self._removeProject(project, force=True) + except Exception as ex: + LOG.info(ex) except SQLAlchemyError as ex: raise SynergyError(ex.message) finally: diff --git a/synergy_scheduler_manager/queue_manager.py b/synergy_scheduler_manager/queue_manager.py index d56ffc0..bb9bd50 100644 --- a/synergy_scheduler_manager/queue_manager.py +++ b/synergy_scheduler_manager/queue_manager.py @@ -63,11 +63,7 @@ class QueueManager(Manager): raise SynergyError("command %r not supported!" % command) def task(self): - try: - for queue in self.queues.values(): - queue.updatePriority() - except Exception as ex: - LOG.error(ex) + pass def destroy(self): for queue in self.queues.values():