Commit f3ae89df authored by Alejandro Alvarez Ayllon's avatar Alejandro Alvarez Ayllon
Browse files

FTS-690: Allow user to specify time, default=2h

parent 8069b89c
......@@ -443,6 +443,9 @@ Usage: fts-rest-transfer-submit [options] SOURCE DESTINATION [CHECKSUM]
-e/--expire
: Expiration time of the delegation in minutes.
--delegate-when-lifetime-lt
: Delegate the proxy when the remote lifetime is less than this value (in minutes)
-o/--overwrite
: Overwrite files.
......
% FTS-REST-CLI(1) fts-rest-ban
% fts-devel@cern.ch
% August 02, 2016
% August 24, 2016
# NAME
fts-rest-ban
......
% FTS-REST-CLI(1) fts-rest-delegate
% fts-devel@cern.ch
% August 02, 2016
% August 24, 2016
# NAME
fts-rest-delegate
......
% FTS-REST-CLI(1) fts-rest-delete-submit
% fts-devel@cern.ch
% August 02, 2016
% August 24, 2016
# NAME
fts-rest-delete-submit
......
% FTS-REST-CLI(1) fts-rest-server-status
% fts-devel@cern.ch
% August 02, 2016
% August 24, 2016
# NAME
fts-rest-server-status
......
% FTS-REST-CLI(1) fts-rest-snapshot
% fts-devel@cern.ch
% August 02, 2016
% August 24, 2016
# NAME
fts-rest-snapshot
......
% FTS-REST-CLI(1) fts-rest-transfer-cancel
% fts-devel@cern.ch
% August 02, 2016
% August 24, 2016
# NAME
fts-rest-transfer-cancel
......
% FTS-REST-CLI(1) fts-rest-transfer-list
% fts-devel@cern.ch
% August 02, 2016
% August 24, 2016
# NAME
fts-rest-transfer-list
......
% FTS-REST-CLI(1) fts-rest-transfer-status
% fts-devel@cern.ch
% August 02, 2016
% August 24, 2016
# NAME
fts-rest-transfer-status
......
% FTS-REST-CLI(1) fts-rest-transfer-submit
% fts-devel@cern.ch
% August 02, 2016
% August 24, 2016
# NAME
fts-rest-transfer-submit
......@@ -83,6 +83,9 @@ format is as follows:
-e/--expire
: Expiration time of the delegation in minutes.
--delegate-when-lifetime-lt
: Delegate the proxy when the remote lifetime is less than this value (in minutes)
-o/--overwrite
: Overwrite files.
......
% FTS-REST-CLI(1) fts-rest-whoami
% fts-devel@cern.ch
% August 02, 2016
% August 24, 2016
# NAME
fts-rest-whoami
......
......@@ -91,6 +91,8 @@ class JobSubmitter(Base):
help='interval between two poll operations in blocking mode.')
self.opt_parser.add_option('-e', '--expire', dest='proxy_lifetime', type='int', default=420,
help='expiration time of the delegation in minutes.')
self.opt_parser.add_option('--delegate-when-lifetime-lt', type=int, default=120,
help='delegate the proxy when the remote lifetime is less than this value (in minutes)')
self.opt_parser.add_option('-o', '--overwrite', dest='overwrite', default=False, action='store_true',
help='overwrite files.')
self.opt_parser.add_option('-r', '--reuse', dest='reuse', default=False, action='store_true',
......@@ -175,7 +177,10 @@ class JobSubmitter(Base):
verify_checksum = True
delegator = Delegator(context)
delegator.delegate(timedelta(minutes=self.options.proxy_lifetime))
delegator.delegate(
timedelta(minutes=self.options.proxy_lifetime),
delegate_when_lifetime_lt=timedelta(minutes=self.options.delegate_when_lifetime_lt)
)
submitter = Submitter(context)
......
......@@ -217,7 +217,7 @@ class Delegator(object):
delegation_id = self._get_delegation_id()
return json.loads(self.context.get('/delegation/' + delegation_id))
def delegate(self, lifetime=timedelta(hours=7), force=False):
def delegate(self, lifetime=timedelta(hours=7), force=False, delegate_when_lifetime_lt=timedelta(hours=2)):
try:
delegation_id = self._get_delegation_id()
log.debug("Delegation ID: " + delegation_id)
......@@ -228,7 +228,7 @@ class Delegator(object):
log.debug("No previous delegation found")
elif remaining_life <= timedelta(0):
log.debug("The delegated credentials expired")
elif remaining_life >= timedelta(hours=1):
elif remaining_life >= delegate_when_lifetime_lt:
if not force:
log.debug("Not bothering doing the delegation")
return delegation_id
......@@ -248,6 +248,6 @@ class Delegator(object):
self._put_proxy(delegation_id, x509_proxy_pem)
return delegation_id
except Exception, e:
raise ClientError(str(e)), None, sys.exc_info()[2]
......@@ -17,7 +17,7 @@ from datetime import timedelta
from fts3.rest.client import Delegator
def delegate(context, lifetime=timedelta(hours=7), force=False):
def delegate(context, lifetime=timedelta(hours=7), force=False, delegate_when_lifetime_lt=timedelta(hours=2)):
"""
Delegates the credentials
......@@ -26,9 +26,11 @@ def delegate(context, lifetime=timedelta(hours=7), force=False):
lifetime: The delegation life time
force: If true, credentials will be re-delegated regardless
of the remaining life of the previous delegation
delegate_when_lifetime_lt: If the remaining lifetime on the delegated proxy is less than this interval,
do a new delegation
Returns:
The delegation ID
"""
delegator = Delegator(context)
return delegator.delegate(lifetime, force)
return delegator.delegate(lifetime, force, delegate_when_lifetime_lt)
......@@ -124,7 +124,7 @@ def new_job(transfers=None, deletion=None, verify_checksum=True, reuse=False, ov
priority: Job priority
max_time_in_queue: Maximum number
id_generator: Job id generator algorithm
sid: Specific id given by the client
sid: Specific id given by the client
Returns:
An initialized dictionary representing a job
......@@ -163,7 +163,7 @@ def new_staging_job(files, bring_online=None, copy_pin_lifetime=None, source_spa
spacetoken=None, metadata=None, priority=None, id_generator=JobIdGenerator.standard, sid=None):
"""
Creates a new dictionary representing a staging job
Args:
files: Array of surls to stage. Each item can be either a string or a dictionary with keys surl and metadata
bring_online: Bring online timeout
......@@ -174,13 +174,13 @@ def new_staging_job(files, bring_online=None, copy_pin_lifetime=None, source_spa
priority: Job priority
id_generator: Job id generator algorithm
sid: Specific id given by the client
Returns:
An initialized dictionary representing a staging job
"""
if bring_online <= 0 and copy_pin_lifetime <= 0:
raise ClientError('Bad request: bring_online and copy_pin_lifetime are not positive numbers')
transfers = []
for trans in files:
if isinstance(trans, dict):
......@@ -193,7 +193,7 @@ def new_staging_job(files, bring_online=None, copy_pin_lifetime=None, source_spa
raise AttributeError("Unexpected input type %s"%type(files))
transfers.append(new_transfer(source=surl, destination=surl, metadata=meta))
params = dict(
source_spacetoken=source_spacetoken,
spacetoken=spacetoken,
......@@ -238,7 +238,7 @@ def new_delete_job(files, spacetoken=None, metadata=None, priority=None, id_gene
return job
def submit(context, job, delegation_lifetime=timedelta(hours=7), force_delegation=False):
def submit(context, job, delegation_lifetime=timedelta(hours=7), force_delegation=False, delegate_when_lifetime_lt=timedelta(hours=2)):
"""
Submits a job
......@@ -247,11 +247,16 @@ def submit(context, job, delegation_lifetime=timedelta(hours=7), force_delegatio
job: Dictionary representing the job
delegation_lifetime: Delegation lifetime
force_delegation: Force delegation even if there is a valid proxy
delegate_when_lifetime_lt: If the remaining lifetime on the delegated proxy is less than this interval,
do a new delegation
Returns:
The job id
"""
delegate(context, delegation_lifetime, force_delegation)
delegate(context, delegation_lifetime, force_delegation, delegate_when_lifetime_lt)
submitter = Submitter(context)
params = job.get('params', {})
return submitter.submit(transfers=job.get('files', None), delete=job.get('delete', None), staging=job.get('staging', None), **params)
return submitter.submit(
transfers=job.get('files', None), delete=job.get('delete', None), staging=job.get('staging', None),
**params
)
Supports Markdown
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