Skip to content
Snippets Groups Projects
Commit b780be6a authored by Sybren A. Stüvel's avatar Sybren A. Stüvel
Browse files

Endpoint for manager startup messages.

parent fdda2530
No related branches found
No related tags found
No related merge requests found
...@@ -74,6 +74,22 @@ managers_schema = { ...@@ -74,6 +74,22 @@ managers_schema = {
'field': '_id', 'field': '_id',
}, },
}, },
# Received from the manager itself at startup.
'variables': {
'type': 'dict',
'allow_unknown': True,
},
'stats': {
'type': 'dict',
'schema': {
# TODO: determine which statistics should be stored here.
'nr_of_workers': {
'type': 'integer',
}
}
}
} }
jobs_schema = { jobs_schema = {
......
...@@ -75,8 +75,7 @@ class ManagerManager(object): ...@@ -75,8 +75,7 @@ class ManagerManager(object):
from flamenco import current_flamenco from flamenco import current_flamenco
if not self.user_is_manager(): if not self.user_is_manager():
self._log.debug('user_manages(%s): user is not a Flamenco manager service account', self._log.debug('user_manages(...): user is not a Flamenco manager service account')
mngr_doc_id)
return False return False
if mngr_doc is None: if mngr_doc is None:
...@@ -98,6 +97,7 @@ class ManagerManager(object): ...@@ -98,6 +97,7 @@ class ManagerManager(object):
def setup_app(app): def setup_app(app):
from . import eve_hooks from . import eve_hooks, api
eve_hooks.setup_app(app) eve_hooks.setup_app(app)
api.setup_app(app)
import logging
from flask import Blueprint, request
import flask_login
import werkzeug.exceptions as wz_exceptions
from pillar.api.utils import authorization, authentication
api_blueprint = Blueprint('flamenco.managers', __name__)
log = logging.getLogger(__name__)
@api_blueprint.route('/<manager_id>/startup', methods=['POST'])
@authorization.require_login(require_roles={u'service', u'flamenco_manager'}, require_all=True)
def startup(manager_id):
from flamenco import current_flamenco
from pillar.api.utils import str2id, mongo
manager_id = str2id(manager_id)
manager = mongo.find_one_or_404('flamenco_managers', manager_id)
if not current_flamenco.manager_manager.user_manages(mngr_doc=manager):
user_id = authentication.current_user_id()
log.warning('Service account %s sent startup notification for manager %s of another '
'service account', user_id, manager_id)
raise wz_exceptions.Unauthorized()
notification = request.json
log.info('Received startup notification from manager %s', manager_id)
log.info('Contents:\n%s\n', notification)
mngr_coll = current_flamenco.db('managers')
update_res = mngr_coll.update_one(
{'_id': manager_id},
{'$set': {
'url': notification['manager_url'],
'variables': notification['variables'],
'stats.nr_of_workers': notification['nr_of_workers'],
}}
)
if update_res.matched_count != 1:
log.warning('Updating manager %s matched %i documents.',
manager_id, update_res.matched_count)
raise wz_exceptions.InternalServerError('Unable to update manager in database.')
return '', 204
def setup_app(app):
app.register_api_blueprint(api_blueprint, url_prefix='/flamenco/managers')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment