Commit b2c2c615 authored by Thomas Jürges's avatar Thomas Jürges

Add API for aborted items, rescheduling depending on status

parent 9bd20b44
# This is the Stager API wrapper module for the Lofar LTA staging service. # This is the Stager API wrapper module for the Lofar LTA staging service.
# #
# It uses an xmlrpc proxy to talk and authenticate to the remote service. Your account credentials will be read from # It uses an xmlrpc proxy to talk and authenticate to the remote service. Your account credentials will be read from
# the awlofar catalog Environment.cfg, if present or can be provided in a .stagingrc file in your home directory. # the awlofar catalog Environment.cfg, if present or can be provided in a .stagingrc file in your home directory.
# #
# !! Please do not talk directly to the xmlrpc interface, but use this module to access the provided functionality. # !! Please do not talk directly to the xmlrpc interface, but use this module to access the provided functionality.
# !! This is to ensure that when we change the remote interface, your scripts don't break and you will only have to # !! This is to ensure that when we change the remote interface, your scripts don't break and you will only have to
# !! upgrade this module. # !! upgrade this module.
__version__ = "1.1" __version__ = "1.2"
import xmlrpclib import xmlrpclib
import datetime import datetime
...@@ -36,14 +36,16 @@ except IOError: ...@@ -36,14 +36,16 @@ except IOError:
passw = line.split('=', 1)[1].strip() passw = line.split('=', 1)[1].strip()
print datetime.datetime.now(), "stager_access: Creating proxy" print datetime.datetime.now(), "stager_access: Creating proxy"
proxy = xmlrpclib.ServerProxy("https://"+user+':'+passw+"@webportal.astron.nl/service-public/xmlrpc") proxy = xmlrpclib.ServerProxy("https://"+user+':'+passw+"@webportal.astron.nl/service-public/xmlrpc")
LtaStager = proxy.LtaStager
# --- # ---
def stage(surls): def stage(surls):
""" Stage list of SURLs """ """ Stage list of SURLs """
if isinstance(surls, str): if isinstance(surls, str):
surls = [surls] surls = [surls]
stageid = proxy.LtaStager.add_getid(surls) stageid = proxy.LtaStager .add_getid(surls)
return stageid return stageid
def get_status(stageid): def get_status(stageid):
...@@ -66,9 +68,35 @@ def reschedule(stageid): ...@@ -66,9 +68,35 @@ def reschedule(stageid):
""" Reschedule a request with a given ID, e.g. after it was put on hold due to maintenance """ """ Reschedule a request with a given ID, e.g. after it was put on hold due to maintenance """
return proxy.LtaStager.reschedule(stageid) return proxy.LtaStager.reschedule(stageid)
def get_progress(): def get_progress(status=None, exclude=False):
""" Get a detailed list of all running requests and their current progress. As a normal user, this only returns your own requests. """ """ Get a detailed list of all running requests and their current progress.
return proxy.LtaStager.getprogress() As a normal user, this only returns your own requests.
:param status: If set to a valid status then only requests with that
status are returned.
:param exclude: If set to True then the requests with status 'status' are
excluded.
"""
all_requests = proxy.LtaStager.getprogress()
if status is not None and isinstance(status, basestring):
if exclude is False:
requests = {key: value for key, value in all_requests.iteritems() if value["Status"] == status}
else:
requests = {key: value for key, value in all_requests.iteritems() if value["Status"] != status}
else:
requests = all_requests
return requests
def reschedule_on_status(status=None):
""" Reschedule requests that have a status "on hold" or "aborted".
:param status: The status that a request has to have in order to be
rescheduled.
"""
if status is not None and isinstance(status, basestring) and (status == "on hold" or status == "aborted"):
requests = get_progress(status)
for key in requests.keys():
reschedule(int(key))
else:
print("The parameter status is either None, not a string neither of \"on hold\" nor \"aborted\".")
def get_storage_info(): def get_storage_info():
""" Get storage information of the different LTA sites, e.g. to check available disk pool space. Requires support role permissions. """ """ Get storage information of the different LTA sites, e.g. to check available disk pool space. Requires support role permissions. """
...@@ -87,39 +115,31 @@ def prettyprint(dictionary, indent=""): ...@@ -87,39 +115,31 @@ def prettyprint(dictionary, indent=""):
else: else:
print "stager_access: This prettyprint takes a dict only!" print "stager_access: This prettyprint takes a dict only!"
def get_progress_on_hold():
""" Get a detailed list of all running requests that have a status 'on hold' and
their current progress. As a normal user, this only returns your own requests.
"""
requests = get_progress()
requests_on_hold = {key: value for key, value in requests.iteritems() if value["Status"] == "on hold"}
return requests_on_hold
def reschedule_on_hold(): def reschedule_on_hold():
""" Get a detailed list of all running requests that have a status other than 'success' and """ Reschedule requests that are on hold.
their current progress. As a normal user, this only returns your own requests.
""" """
requests_on_hold = get_progress_on_hold() reschedule_on_status("on hold")
for key in requests_on_hold.keys():
reschedule(int(key))
def print_on_hold(): def print_on_hold():
"""Print a list of all requests that are on hold. """Print a list of all requests that are on hold.
""" """
requests_on_hold = get_progress_on_hold() requests = get_progress("on hold")
prettyprint(requests_on_hold) prettyprint(requests)
def reschedule_aborted():
""" Reschedule requests that were aborted.
"""
reschedule_on_status("aborted")
def get_running(): def print_aborted():
"""Return a list of requests that are currently executed and do not have a """Print a list of all requests that were aborted.
status of "success".
""" """
requests = get_progress() requests = get_progress("aborted")
requests_running = {key: value for key, value in requests.iteritems() if value["Status"] != "success"} prettyprint(requests)
return requests_running
def print_running(): def print_running():
"""Print a list of requests that are currently executed and do not have a """Print a list of requests that are currently executed and do not have a
status of "success" status of "success"
""" """
requests_running = get_running() requests = get_progress("success", True)
prettyprint(requests_running) prettyprint(requests)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment