Skip to content

Commit

Permalink
Do not load server configuration by web-UI
Browse files Browse the repository at this point in the history
The web-UI is typically driven by http server, without permissions to
read /etc/resallocserver files or write /var/log/resallocserver.

Fixes: fedora-copr/copr#3202
  • Loading branch information
praiskup committed Apr 24, 2024
1 parent 151bd59 commit 9ad3370
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""
Track Pool max value
"""

from alembic import op
import sqlalchemy as sa

revision = 'b50e3f64fc2d'
down_revision = '78237445aff8'

def upgrade():
with op.batch_alter_table('pools', schema=None) as batch_op:
batch_op.add_column(sa.Column('max', sa.Integer(), nullable=True))

def downgrade():
with op.batch_alter_table('pools', schema=None) as batch_op:
batch_op.drop_column('max')
19 changes: 12 additions & 7 deletions resallocserver/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,13 +651,7 @@ def _too_soon(self):
last_start = 0.0
with session_scope() as session:
dbinfo = session.query(models.Pool).get(self.name)
if not dbinfo:
dbinfo = models.Pool()
dbinfo.name = self.name
dbinfo.last_start = 0.0
session.add(dbinfo)
else:
last_start = dbinfo.last_start
last_start = dbinfo.last_start

is_too_soon = last_start + self.start_delay > time.time()
if is_too_soon:
Expand Down Expand Up @@ -1075,13 +1069,24 @@ def _decide_where_to_start_on_demand_instances(self, config, pools):
app.log.debug("Ticket=%s can not start new resources, "
"quotas reached", ticket_id)

def _init_pool_in_db(self, pool_config, session):
dbinfo = session.query(models.Pool).get(pool_config.name)
if not dbinfo:
dbinfo = models.Pool()
dbinfo.name = pool_config.name
dbinfo.last_start = 0.0
session.add(dbinfo)
dbinfo.max = pool_config.max

def _loop(self):
app.log.info("Manager's loop.")

# Cleanup the old resources.
cross_pool_config, pools = reload_config()

with session_scope() as session:
for _, config in pools.items():
self._init_pool_in_db(config, session)

for _, pool in pools.items():
pool.detect_closed_tickets(self.sync.ticket)
Expand Down
1 change: 1 addition & 0 deletions resallocserver/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class Pool(Base):
name = Column(String, primary_key=True)
last_start = Column(Float, default=0)
cleaning_unknown_resources = Column(DateTime, server_default=func.now())
max = Column(Integer, default=0)


class Ticket(Base, TagMixin):
Expand Down
12 changes: 5 additions & 7 deletions resallocwebui/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from flask import Flask, render_template
from resallocserver.app import session_scope
from resallocserver.logic import QResources
from resallocserver.manager import reload_config
from resallocserver import models
from resalloc.helpers import RState
from resallocwebui import staticdir, templatedir

Expand Down Expand Up @@ -37,13 +37,11 @@ def pools():
# e.g. result["copr_hv_x86_64_01_prod"]["STARTING"]
result = {}

# Read configuration from pools.yaml
_, pools_config = reload_config()

# Prepare the two-dimensional array, and fill it with zeros
for name, pool in pools_config.items():
result[name] = dict.fromkeys(columns, 0)
result[name]["MAX"] = pools_config[name].max
with session_scope() as session:
for pool in session.query(models.Pool).all():
result[pool.name] = dict.fromkeys(columns, 0)
result[pool.name]["MAX"] = pool.max

with session_scope() as session:
# Iterate over running resources and calculate how many is starting,
Expand Down

0 comments on commit 9ad3370

Please sign in to comment.