#!/usr/bin/env python
# Copyright 2014-2018 CERN for the benefit of the ATLAS collaboration.
#
# 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.
#
# Authors:
# - Thomas Beermann <thomas.beermann@cern.ch>, 2014-2017
# - Vincent Garonne <vgaronne@gmail.com>, 2014
# - Mario Lassnig <mario.lassnig@cern.ch>, 2014-2018
# - Martin Barisits <martin.barisits@cern.ch>, 2014-2015
# - Ralph Vigne <ralph.vigne@cern.ch>, 2015
# - Cedric Serfon <cedric.serfon@cern.ch>, 2015-2018
# - Stefan Prenner <stefan.prenner@cern.ch>, 2018
from io import BytesIO
from json import dumps
from os.path import dirname, join
from tarfile import open, TarError
from gzip import GzipFile
from requests import get, ConnectionError
from web import application, header, input as param_input, seeother, template
from rucio.common.config import config_get
from rucio.common.utils import generate_http_error
from rucio.web.ui.common.utils import check_token, get_token
COMMON_URLS = (
'/account_rse_usage', 'AccountRSEUsage',
'/account', 'Account',
'/auth', 'Auth',
'/bad_replicas', 'BadReplicas',
'/suspicious_replicas', 'SuspiciousReplicas',
'/bad_replicas/summary', 'BadReplicasSummary',
'/did', 'DID',
'/heartbeats', 'Heartbeats',
'/lifetime_exception', 'LifetimeException',
'/list_lifetime_exceptions', 'ListLifetimeExceptions',
'/list_accounts', 'ListAccounts',
'/list_rules', 'ListRulesRedirect',
'/r2d2/approve', 'ApproveRules',
'/r2d2/request', 'RequestRule',
'/r2d2/manage_quota', 'RSEAccountUsage',
'/r2d2', 'ListRules',
'/rse_usage', 'RSEUsage',
'/rse_locks', 'RSELocks',
'/rule', 'Rule',
'/rules', 'Rules',
'/request_rule', 'RequestRuleRedirect',
'/search', 'Search',
'/subscriptions/rules', 'SubscriptionRules',
'/subscription', 'Subscription',
'/subscriptions', 'Subscriptions',
'/subscriptions_editor', 'SubscriptionsEditor',
'/logfiles/load', 'LoadLogfile',
'/logfiles/extract', 'ExtractLogfile'
)
POLICY = config_get('policy', 'permission')
ATLAS_URLS = ()
OTHER_URLS = ()
if POLICY == 'atlas':
ATLAS_URLS = (
'/', 'AtlasIndex',
'/account_usage', 'AccountUsage',
'/dumps', 'Dumps',
'/accounting', 'Accounting',
'/conditions_summary', 'Cond',
'/dbrelease_summary', 'DBRelease',
'/infrastructure', 'Infrastructure',
'/rule_backlog_monitor', 'BacklogMon'
)
else:
OTHER_URLS = (
'/', 'Index'
)
class Account(object):
""" Account info page """
def GET(self): # pylint:disable=no-self-use,invalid-name
""" GET """
render = template.render(join(dirname(__file__), 'templates/'))
return check_token(render.account())
class AccountUsage(object):
""" Group Account Usage overview """
def GET(self): # pylint:disable=no-self-use,invalid-name
""" GET """
render = template.render(join(dirname(__file__), 'templates/'))
return check_token(render.account_usage())
class AccountRSEUsage(object):
""" RSE usage per account """
def GET(self): # pylint:disable=no-self-use,invalid-name
""" GET """
render = template.render(join(dirname(__file__), 'templates/'))
return check_token(render.account_rse_usage())
class ApproveRules(object):
""" R2D2 rule approval overview """
def GET(self): # pylint:disable=no-self-use,invalid-name
""" GET """
render = template.render(join(dirname(__file__), 'templates/'))
return check_token(render.approve_rules())
class AtlasIndex(object):
""" Main page """
def GET(self): # pylint:disable=no-self-use,invalid-name
""" GET """
render = template.render(join(dirname(__file__), 'templates/'))
return check_token(render.atlas_index())
class Auth(object):
""" Local Auth Proxy """
def GET(self): # pylint:disable=no-self-use,invalid-name
""" GET """
token = get_token()
if token:
header('X-Rucio-Auth-Token', token)
return str()
else:
raise generate_http_error(401, 'CannotAuthenticate', 'Cannot get token')
class Accounting(object):
""" Accounting """
def GET(self): # pylint:disable=no-self-use,invalid-name
""" GET """
render = template.render(join(dirname(__file__), 'templates/'))
return check_token(render.accounting())
class BadReplicas(object):
""" Bad replica monitoring """
def GET(self): # pylint:disable=no-self-use,invalid-name
""" GET """
render = template.render(join(dirname(__file__), 'templates/'))
return check_token(render.bad_replicas())
class SuspiciousReplicas(object):
""" AccountUsage """
def GET(self): # pylint:disable=no-self-use,invalid-name
""" GET """
render = template.render(join(dirname(__file__), 'templates/'))
return check_token(render.suspicious_replicas())
class BadReplicasSummary(object):
""" Bad replica overview """
def GET(self): # pylint:disable=no-self-use,invalid-name
""" GET """
render = template.render(join(dirname(__file__), 'templates/'))
return check_token(render.bad_replicas_summary())
class BacklogMon(object):
""" Rule Backlog Monitor """
def GET(self): # pylint:disable=no-self-use,invalid-name
""" GET """
render = template.render(join(dirname(__file__), 'templates/'))
return check_token(render.backlog_mon())
class Cond(object):
""" Condition DB overview """
def GET(self): # pylint:disable=no-self-use,invalid-name
""" GET """
render = template.render(join(dirname(__file__), 'templates/'))
return check_token(render.cond())
class DID(object):
""" DID detail page """
def GET(self): # pylint:disable=no-self-use,invalid-name
""" GET """
render = template.render(join(dirname(__file__), 'templates/'))
return check_token(render.did())
class DBRelease(object):
""" DB release overview """
def GET(self): # pylint:disable=no-self-use,invalid-name
""" GET """
render = template.render(join(dirname(__file__), 'templates/'))
return check_token(render.dbrelease())
class Dumps(object):
""" Description page for dumps """
def GET(self): # pylint:disable=no-self-use,invalid-name
""" GET """
render = template.render(join(dirname(__file__), 'templates/'))
return check_token(render.dumps())
class Heartbeats(object):
""" Heartbeat monitoring """
def GET(self): # pylint:disable=no-self-use,invalid-name
""" GET """
render = template.render(join(dirname(__file__), 'templates/'))
return check_token(render.heartbeats())
class LifetimeException():
""" For to request lifetime exception """
def GET(self): # pylint:disable=no-self-use,invalid-name
""" GET """
render = template.render(join(dirname(__file__), 'templates/'))
return check_token(render.lifetime_exception())
class ListLifetimeExceptions():
""" List lifetime exceptions requests """
def GET(self): # pylint:disable=no-self-use,invalid-name
""" GET """
render = template.render(join(dirname(__file__), 'templates/'))
return check_token(render.list_lifetime_exceptions())
class ListAccounts(object):
""" Account list """
def GET(self): # pylint:disable=no-self-use,invalid-name
""" GET """