Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
LOFAR
Manage
Activity
Members
Labels
Plan
Issues
Wiki
Jira issues
Open Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
RadioObservatory
LOFAR
Commits
1d0bef5e
Commit
1d0bef5e
authored
7 years ago
by
Jorrit Schaap
Browse files
Options
Downloads
Patches
Plain Diff
Task #10898: properly handle updated start/endtimes via otdb and radb
parent
bb14dee2
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
SAS/ResourceAssignment/ResourceAssignmentEditor/lib/webservice.py
+41
-26
41 additions, 26 deletions
...urceAssignment/ResourceAssignmentEditor/lib/webservice.py
with
41 additions
and
26 deletions
SAS/ResourceAssignment/ResourceAssignmentEditor/lib/webservice.py
+
41
−
26
View file @
1d0bef5e
...
@@ -406,49 +406,60 @@ def putTask(task_id):
...
@@ -406,49 +406,60 @@ def putTask(task_id):
request
.
headers
[
'
Content-Type
'
].
startswith
(
'
application/json
'
):
request
.
headers
[
'
Content-Type
'
].
startswith
(
'
application/json
'
):
try
:
try
:
updatedTask
=
json_loads
(
request
.
data
)
updatedTask
=
json_loads
(
request
.
data
)
logger
.
info
(
'
putTask: updatedTask: %s
'
,
updatedTask
)
if
task_id
!=
int
(
updatedTask
[
'
id
'
]):
if
task_id
!=
int
(
updatedTask
[
'
id
'
]):
abort
(
404
,
'
task_id in url is not equal to id in request.data
'
)
abort
(
404
,
'
task_id in url is not equal to id in request.data
'
)
org_task
=
radb
().
getTask
(
task_id
)
#check if task is known
task
=
radb
().
getTask
(
task_id
)
if
not
org_task
:
if
not
task
:
abort
(
404
,
"
unknown task %s
"
%
updatedTask
)
abort
(
404
,
"
unknown task %s
"
%
str
(
updatedTask
))
for
timeprop
in
[
'
starttime
'
,
'
endtime
'
]:
if
timeprop
in
updatedTask
:
try
:
updatedTask
[
timeprop
]
=
asDatetime
(
updatedTask
[
timeprop
])
except
ValueError
:
abort
(
400
,
'
timestamp not in iso format:
'
+
updatedTask
[
timeprop
])
# first handle start- endtimes...
if
'
starttime
'
in
updatedTask
or
'
endtime
'
in
updatedTask
:
if
'
starttime
'
in
updatedTask
or
'
endtime
'
in
updatedTask
:
# block time edits in productin for now until we've replaced the old scheduler.
logger
.
info
(
'
starttime or endtime in updatedTask: %s
'
,
updatedTask
)
if
isProductionEnvironment
():
if
isProductionEnvironment
():
abort
(
403
,
'
Editing of startime/endtime of tasks by users is not yet approved
'
)
abort
(
403
,
'
Editing of %s of tasks by users is not yet approved
'
%
(
time
,))
#update dict for otdb spec
spec_update
=
{}
for
timeprop
in
[
'
starttime
'
,
'
endtime
'
]:
if
timeprop
in
updatedTask
:
try
:
updatedTask
[
timeprop
]
=
asDatetime
(
updatedTask
[
timeprop
])
except
ValueError
:
abort
(
400
,
'
timestamp not in iso format:
'
+
updatedTask
[
timeprop
])
otdb_key
=
'
LOFAR.ObsSW.Observation.
'
+
(
'
startTime
'
if
timeprop
==
'
starttime
'
else
'
stopTime
'
)
spec_update
[
otdb_key
]
=
updatedTask
[
timeprop
].
strftime
(
'
%Y-%m-%d %H:%M:%S
'
)
#update timestamps in both otdb and radb
otdbrpc
.
taskSetSpecification
(
task
[
'
otdb_id
'
],
spec_update
)
# update the task's (and its claims) start/endtime
# update the task's (and its claims) start/endtime
# do not update the tasks status directly via the radb. See few lines below. task status is routed via otdb (and then ends up in radb automatically)
# do not update the tasks status directly via the radb. See few lines below. task status is routed via otdb (and then ends up in radb automatically)
# it might be that editing the start/end time results in a (rabd)task status update (for example to 'conflict' due to conflicting claims)
# it might be that editing the start/end time results in a (rabd)task status update (for example to 'conflict' due to conflicting claims)
# that's ok, since we'll update the status to the requested status later via otdb (see few lines below)
# that's ok, since we'll update the status to the requested status later via otdb (see few lines below)
radb
().
updateTaskAndResourceClaims
(
task_id
,
starttime
=
updatedTask
.
get
(
'
starttime
'
),
endtime
=
updatedTask
.
get
(
'
endtime
'
))
radb
().
updateTaskAndResourceClaims
(
task_id
,
starttime
=
updatedTask
.
get
(
'
starttime
'
),
endtime
=
updatedTask
.
get
(
'
endtime
'
))
# ...then, handle status update which might trigger resource assignment,
# for which the above updated times are needed
if
'
status
'
in
updatedTask
:
if
'
status
'
in
updatedTask
:
if
isProductionEnvironment
()
and
org_task
[
'
type
'
]
==
'
observation
'
:
abort
(
403
,
'
Editing of observation status by users is not yet approved
'
)
try
:
try
:
otdbrpc
.
taskSetStatus
(
org_task
[
'
otdb_id
'
],
updatedTask
[
'
status
'
])
#update status in otdb only
#the status change will propagate automatically into radb via other services (by design)
otdbrpc
.
taskSetStatus
(
task
[
'
otdb_id
'
],
updatedTask
[
'
status
'
])
#block until radb and mom task status are equal to otdb task status (with timeout)
#block until radb and mom task status are equal to otdb task status (with timeout)
start_wait
=
datetime
.
utcnow
()
start_wait
=
datetime
.
utcnow
()
while
True
:
while
True
:
org_
task
=
radb
().
getTask
(
task_id
)
task
=
radb
().
getTask
(
task_id
)
details
=
momqueryrpc
.
get
Ob
jectDetails
(
org_
task
[
'
mom_id
'
]).
get
(
org_
task
[
'
mom_id
'
])
details
=
momqueryrpc
.
get
Pro
jectDetails
(
task
[
'
mom_id
'
]).
get
(
task
[
'
mom_id
'
])
if
org_
task
[
'
status
'
]
==
updatedTask
[
'
status
'
]
and
details
[
'
object_status
'
]
==
updatedTask
[
'
status
'
]:
if
task
[
'
status
'
]
==
updatedTask
[
'
status
'
]
and
details
[
'
object_status
'
]
==
updatedTask
[
'
status
'
]:
break
break
if
datetime
.
utcnow
()
-
start_wait
>
timedelta
(
seconds
=
10
):
if
datetime
.
utcnow
()
-
start_wait
>
timedelta
(
seconds
=
10
):
...
@@ -459,12 +470,16 @@ def putTask(task_id):
...
@@ -459,12 +470,16 @@ def putTask(task_id):
if
'
does not exist
'
in
e
.
message
:
if
'
does not exist
'
in
e
.
message
:
# task does not exist (anymore) in otdb
# task does not exist (anymore) in otdb
#so remove it from radb as well (with cascading deletes on specification)
#so remove it from radb as well (with cascading deletes on specification)
logger
.
warn
(
'
task with otdb_id %s does not exist anymore in OTDB. removing task radb_id %s from radb
'
,
org_
task
[
'
otdb_id
'
],
org_
task
[
'
id
'
])
logger
.
warn
(
'
task with otdb_id %s does not exist anymore in OTDB. removing task radb_id %s from radb
'
,
task
[
'
otdb_id
'
],
task
[
'
id
'
])
radb
().
deleteSpecification
(
org_
task
[
'
specification_id
'
])
radb
().
deleteSpecification
(
task
[
'
specification_id
'
])
if
'
data_pinned
'
in
updatedTask
:
if
'
data_pinned
'
in
updatedTask
:
if
not
curpc
.
setTaskDataPinned
(
org_task
[
'
otdb_id
'
],
updatedTask
[
'
data_pinned
'
]):
task
=
radb
().
getTask
(
task_id
)
abort
(
500
,
'
Could not (un)pin task
'
)
if
not
task
:
abort
(
404
,
"
unknown task %s
"
%
str
(
updatedTask
))
curpc
.
setTaskDataPinned
(
task
[
'
otdb_id
'
],
updatedTask
[
'
data_pinned
'
])
return
""
,
204
return
""
,
204
except
Exception
as
e
:
except
Exception
as
e
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment