コード例 #1
0
ファイル: manager.py プロジェクト: thrix/resalloc
    def _assign_tickets(self):
        with session_scope() as session:
            qticket = QTickets(session)
            tickets = [
                x.id
                for x in qticket.waiting().order_by(models.Ticket.id).all()
            ]

        for ticket_id in tickets:
            notify_ticket = False
            with session_scope() as session:
                ticket = session.query(models.Ticket).get(ticket_id)
                qres = QResources(session)
                resources = qres.ready().all()
                ticket_tags = ticket.tag_set
                for resource in resources:
                    res_tags = resource.tag_set
                    if ticket_tags.issubset(res_tags):
                        # We have found appropriate resource!
                        ticket.resource_id = resource.id
                        if ticket.tid:
                            notify_ticket = ticket.tid
                        session.add_all([ticket])
                        break
            if notify_ticket:
                self._notify_waiting(notify_ticket)
コード例 #2
0
    def _assign_tickets(self):
        with session_scope() as session:
            qticket = QTickets(session)
            tickets = [x.id for x in qticket.waiting().order_by(models.Ticket.id).all()]

        for ticket_id in tickets:
            notify_ticket = False
            with session_scope() as session:
                ticket = session.query(models.Ticket).get(ticket_id)
                qres = QResources(session)
                resources = qres.ready().all()
                ticket_tags = ticket.tag_set
                for resource in resources:
                    res_tags = resource.tag_set
                    if resource.sandbox and resource.sandbox != ticket.sandbox:
                        continue
                    if not ticket_tags.issubset(res_tags):
                        continue

                    # We have found appropriate resource!
                    log.debug("Assigning %s to %s", resource.name, ticket.id)
                    assign_ticket(resource, ticket)
                    if ticket.tid:
                        notify_ticket = ticket.tid
                    break

            if notify_ticket:
                self._notify_waiting(notify_ticket)
コード例 #3
0
    def _assign_tickets(self):
        with session_scope() as session:
            qticket = QTickets(session)
            tickets = [x.id for x in qticket.waiting().order_by(models.Ticket.id).all()]

        for ticket_id in tickets:
            notify_ticket = False
            with session_scope() as session:
                ticket = session.query(models.Ticket).get(ticket_id)
                qres = QResources(session)
                resources = qres.ready().all()

                if not resources:
                    app.log.debug("No available resource, skipping %s", ticket)
                    continue

                queue = PriorityQueue()
                ticket_tags = ticket.tag_set
                for resource in resources:
                    res_tags = resource.tag_set
                    if resource.sandbox and resource.sandbox != ticket.sandbox:
                        continue
                    if not ticket_tags.issubset(res_tags):
                        continue

                    priority = 0
                    for tag in resource.tags:
                        if tag.priority is not None and tag.id in ticket_tags:
                            priority += tag.priority

                    if resource.sandbox:
                        # Re-used resources should be preferred to avoid
                        # allocating new and new resources for the same
                        # sandboxes.  TODO, make this configurable once needed.
                        priority += REUSED_RESOURCE_PRIORITY

                    queue.add_task(resource, priority)

                try:
                    resource = queue.pop_task()
                except KeyError:
                    app.log.debug("%d resources UP but unusable for %s",
                                  len(resources), ticket)
                    continue

                # we found an appropriate resource
                app.log.debug("Assigning %s to %s", resource.name, ticket.id)
                assign_ticket(resource, ticket)
                if ticket.tid:
                    notify_ticket = ticket.tid

            # notify ticket when the session is closed (to have short sessions)
            if notify_ticket:
                self._notify_waiting(notify_ticket)
コード例 #4
0
ファイル: maint.py プロジェクト: praiskup/resalloc
    def resource_delete(self, args):
        resources = args.resource

        with session_scope() as session:
            qresources = QResources(session=session)
            if args.all:
                resources = [res.id for res in qresources.up()]
            elif args.unused:
                resources = [res.id for res in qresources.ready()]

        if not resources or type(resources) != list:
            log.error("no resources specified")
            return

        for res_id in resources:
            with session_scope() as session:
                qresources = QResources(session=session)
                qresources.kill(res_id)