Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Justinas Rumsevicius committed Jul 31, 2018
2 parents 2aacde9 + 284c869 commit c811943
Show file tree
Hide file tree
Showing 7 changed files with 390 additions and 388 deletions.
4 changes: 2 additions & 2 deletions mcm/HTML/navbar_template.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
</li>
<li class="divider-vertical"></li>
<li ng-class='{ "active": dbName=="batches"}'>
<a ng-href='batches' target="_self">Batch <i class="icon-tags"></i></a>
<a ng-href='batches?status=new' target="_self">Batch <i class="icon-tags"></i></a>
</li>
<li class="divider-vertical" ng-hide="role(3);"></li>
<li ng-class='{ "active": dbName=="invalidations"}' ng-hide="role(3);">
<a ng-href='invalidations' target="_self">Invalidations <i class="icon-exclamation-sign"></i></a>
<a ng-href='invalidations?status=new' target="_self">Invalidations <i class="icon-exclamation-sign"></i></a>
</li>
<li class="divider-vertical" ng-hide="role(1);"></li>
<li ng-class='{ "active": dbName=="mccms"}' ng-hide="role(1);">
Expand Down
27 changes: 13 additions & 14 deletions mcm/json_layer/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@
from tools.logger import InjectionLogAdapter


class AFSPermissionError(Exception):
def __init__(self, message=None):
self.message = message

def __str__(self):
return 'AFS permission error: %s' % (self.message)


class request(json_base):
class DuplicateApprovalStep(Exception):
def __init__(self, approval=None):
Expand Down Expand Up @@ -1461,6 +1469,7 @@ def test_failure(self, message, what='Submission', rewind=False, with_notificati
if rewind:
self.set_status(0)
self.approve(0)

self.update_history({'action': 'failed'})
if with_notification:
subject = '%s failed for request %s' % (what, self.get_attribute('prepid'))
Expand All @@ -1474,6 +1483,7 @@ def test_failure(self, message, what='Submission', rewind=False, with_notificati
base_object=self
)
self.notify(subject, message)

self.reload()

def get_stats(self, keys_to_import=None, override_id=None, limit_to_set=0.05,
Expand Down Expand Up @@ -2654,7 +2664,6 @@ def reset(self, hard=True):
self.set_attribute('approval', self._json_base__approvalsteps[__approval_index - 1])
self.set_status(step=__status_index, with_notification=True)


def prepare_upload_command(self, cfgs, test_string):
directory = installer.build_location(self.get_attribute('prepid'))
cmd = 'cd %s \n' % directory
Expand Down Expand Up @@ -2717,6 +2726,9 @@ def prepare_and_upload_config(self, execute=True):
if error and not output: # money on the table that it will break
self.logger.error('Error in wmupload: {0}'.format(error))
self.test_failure('Error in wmupload: {0}'.format(error), what='Configuration upload')
if '.bashrc: Permission denied' in error:
raise AFSPermissionError(error)

return False
cfgs_uploaded = [l for l in output.split("\n") if 'DocID:' in l]

Expand Down Expand Up @@ -2759,19 +2771,6 @@ def prepare_and_upload_config(self, execute=True):
for i in to_release:
locker.release(i)

def prepare_submit_command(self):
l_type = locator()
command = 'cd %s \n' % (l_type.workLocation())
command += self.make_release()
command += 'export X509_USER_PROXY=/afs/cern.ch/user/p/pdmvserv/private/$HOSTNAME/voms_proxy.cert\n'
test_params = ''
if l_type.isDev():
test_params = '--wmtest --wmtesturl cmsweb-testbed.cern.ch'
command += 'export PATH=/afs/cern.ch/cms/PPD/PdmV/tools/wmcontrol:${PATH}\n'
command += 'source /afs/cern.ch/cms/PPD/PdmV/tools/wmclient/current/etc/wmclient.sh\n'
command += 'wmcontrol.py --dont_approve --url-dict %spublic/restapi/requests/get_dict/%s %s \n' % (l_type.baseurl(), self.get_attribute('prepid'), test_params)
return command

def get_events_per_lumi(self, num_cores):
cdb = database('campaigns')
camp = campaign(cdb.get(self.get_attribute("member_of_campaign")))
Expand Down
73 changes: 44 additions & 29 deletions mcm/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import logging.handlers
import shelve
import datetime
import sys


RESTResource.counter = shelve.open('.mcm_rest_counter')
Expand Down Expand Up @@ -214,6 +215,7 @@ def send_HTML(path):
api.add_resource(GetCmsDriverForRequest, '/restapi/requests/get_cmsDrivers/<string:request_id>')
api.add_resource(
ApproveRequest,
'/restapi/requests/approve',
'/restapi/requests/approve/<string:request_id>',
'/restapi/requests/approve/<string:request_id>/<int:step>')
api.add_resource(
Expand Down Expand Up @@ -411,41 +413,54 @@ def send_HTML(path):
api.add_resource(SearchNotifications, '/restapi/notifications/search')
api.add_resource(MarkAsSeen, '/restapi/notifications/mark_as_seen')
# Define loggers
# ERROR log file
error_logger = app.logger
maxBytes = getattr(error_logger, "rot_maxBytes", 10000000)
backupCount = getattr(error_logger, "rot_backupCount", 1000)
fname = getattr(error_logger, "rot_error_file", "logs/error.log")
max_bytes = getattr(error_logger, "rot_maxBytes", 10000000)
backup_count = getattr(error_logger, "rot_backupCount", 1000)
logger = logging.getLogger()
logger.setLevel(0)
ha = logging.handlers.RotatingFileHandler(fname, 'a', maxBytes, backupCount)
error_formatter = logging.Formatter(fmt='[%(asctime)s][%(user)s][%(levelname)s] %(message)s',
datefmt='%d/%b/%Y:%H:%M:%S')
usr_filt = UserFilter()
ha.setFormatter(error_formatter)
ha.addFilter(usr_filt)
error_logger.addHandler(ha)
# set up injection logger
user_filter = UserFilter()
memory_filter = MemoryFilter()
logging.getLogger('werkzeug').disabled = True
console_logging = False
console_handler = logging.StreamHandler(sys.stdout)
# Error logger
if console_logging:
error_handler = console_handler
else:
error_log_filename = getattr(error_logger, "rot_error_file", "logs/error.log")
error_handler = logging.handlers.RotatingFileHandler(error_log_filename, 'a', max_bytes, backup_count)

error_formatter = logging.Formatter(fmt='[%(asctime)s][%(user)s][%(levelname)s] %(message)s', datefmt='%d/%b/%Y:%H:%M:%S')
error_handler.setFormatter(error_formatter)
error_handler.addFilter(user_filter)
error_logger.addHandler(error_handler)

# Injection logger
# due to LogAdapter empty space for message will be added inside of it
inject_formatter = logging.Formatter(fmt='[%(asctime)s][%(levelname)s]%(message)s',
datefmt='%d/%b/%Y:%H:%M:%S')
inject_logger = logging.getLogger("mcm_inject")
hi = logging.FileHandler('logs/inject.log', 'a')
hi.setFormatter(inject_formatter)
inject_logger.addHandler(hi)
injection_logger = logging.getLogger("mcm_inject")
if console_logging:
injection_handler = console_handler
else:
injection_handler = logging.FileHandler('logs/inject.log', 'a')

injection_formatter = logging.Formatter(fmt='[%(asctime)s][%(levelname)s]%(message)s', datefmt='%d/%b/%Y:%H:%M:%S')
injection_handler.setFormatter(injection_formatter)
injection_logger.addHandler(injection_handler)

# Access log file
access_logger = logging.getLogger("access_log")
fname = getattr(access_logger, "rot_access_file", "logs/access.log")
h = logging.handlers.RotatingFileHandler(fname, 'a', maxBytes, backupCount)
rest_formatter = logging.Formatter(fmt='{%(mem)s} [%(asctime)s][%(user)s][%(levelname)s] %(message)s',
datefmt='%d/%b/%Y:%H:%M:%S')
mem_filt = MemoryFilter()
h.setLevel(logging.DEBUG)
h.setFormatter(rest_formatter)
h.addFilter(usr_filt)
h.addFilter(mem_filt)
access_logger.addHandler(h)
logging.getLogger('werkzeug').disabled = True
access_log_filename = getattr(access_logger, "rot_access_file", "logs/access.log")
if console_logging:
access_handler = console_handler
else:
access_handler = logging.handlers.RotatingFileHandler(access_log_filename, 'a', max_bytes, backup_count)

access_formatter = logging.Formatter(fmt='{%(mem)s} [%(asctime)s][%(user)s][%(levelname)s] %(message)s', datefmt='%d/%b/%Y:%H:%M:%S')
access_handler.setLevel(logging.DEBUG)
access_handler.setFormatter(access_formatter)
access_handler.addFilter(user_filter)
access_handler.addFilter(memory_filter)
access_logger.addHandler(access_handler)

# Log accesses
def after_this_request(f):
Expand Down
13 changes: 11 additions & 2 deletions mcm/rest_api/RequestActions.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,12 +572,21 @@ def __init__(self):
self.before_request()
self.count_call()

def get(self, request_id, step=-1):
def get(self, request_id=None, step=-1):
"""
Approve to the next step, or specified index the given request or coma separated list of requests
"""
if request_id is None:
return {'results': False, 'message': 'No prepid was given'}

return self.multiple_approve(request_id, step)

def post(self, request_id=None, step=-1):
"""
Approve to next step. Ignore GET parameter, use list of prepids from POST data
"""
return self.multiple_approve(flask.request.data)

def multiple_approve(self, rid, val=-1, hard=True):
if ',' in rid:
rlist = rid.rsplit(',')
Expand Down Expand Up @@ -1671,7 +1680,7 @@ def get(self, request_id):
self.logger.error('GetInjectCommand: request with id {0} does not exist'.format(request_id))
return {"results": False, 'message': 'Error: request with id {0} does not exist'.format(request_id)}
req = request(db.get(request_id))
return req.prepare_submit_command()
return RequestInjector(prepid=request_id).make_injection_command(req)


class GetUniqueValues(RESTResource):
Expand Down
2 changes: 1 addition & 1 deletion mcm/scripts/mccms_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ angular.module('testApp').controller('resultsCtrl',
}

$scope.approve_gen_request = function(prepids){
$http({method:'GET', url:'restapi/requests/approve/' + prepids}).success(function(data,status){
$http({method:'POST', url:'restapi/requests/approve', data: prepids}).success(function(data,status){
if (!$scope.isArray(data)){
data = [data];
}
Expand Down
Loading

0 comments on commit c811943

Please # to comment.