diff --git a/src/fts3rest/fts3rest/controllers/serverstatus.py b/src/fts3rest/fts3rest/controllers/serverstatus.py index eee9d4f83c33e483eb485b561d9eee0e864bb3c9..ba7641ae59c846e0ed1198eb5eede9bc3bbfe72f 100644 --- a/src/fts3rest/fts3rest/controllers/serverstatus.py +++ b/src/fts3rest/fts3rest/controllers/serverstatus.py @@ -1,5 +1,55 @@ +# Copyright 2015-2020 CERN +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. from werkzeug.exceptions import NotFound +from fts3.model import File +from fts3rest.model.meta import Session +from fts3rest.lib.middleware.fts3auth.authorization import ( + authorize, + require_certificate, +) +from fts3rest.lib.middleware.fts3auth.constants import * +from flask import jsonify + +""" +Server general status +""" def hosts_activity(): - raise NotFound + """ + What are the hosts doing + """ + staging = Session.execute( + "SELECT COUNT(*), agent_dn " + " FROM t_file " + " WHERE file_state = 'STARTED' " + " GROUP BY agent_dn" + ) + response = dict() + + for (count, host) in staging: + response[host] = dict(staging=count) + + active = Session.execute( + "SELECT COUNT(*), transferHost " + " FROM t_file " + " WHERE file_state = 'ACTIVE' " + " GROUP BY transferHost" + ) + for (count, host) in active: + if host not in response: + response[host] = dict() + response[host]["active"] = count + + return jsonify(response)