Skip to content
GitLab
Explore
Sign in
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
dbadfbcd
Commit
dbadfbcd
authored
3 years ago
by
Jorrit Schaap
Browse files
Options
Downloads
Patches
Plain Diff
TMSS-1377
: replaced OTDBBuslistener/OTDBEventHandler by TMSSBuslistener/TMSSEventMessageHandler
parent
a2f6855f
No related branches found
No related tags found
1 merge request
!736
TMSS-1377 & TMSS-1376: TMSS-adapted TBB scripts and gitlab/docker TBB builds
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
CEP/TBB/TBBdatawriter/TBBOTDBBusListener.py
+25
-18
25 additions, 18 deletions
CEP/TBB/TBBdatawriter/TBBOTDBBusListener.py
CEP/TBB/TBBdatawriter/currentobs.py
+17
-12
17 additions, 12 deletions
CEP/TBB/TBBdatawriter/currentobs.py
with
42 additions
and
30 deletions
CEP/TBB/TBBdatawriter/TBBOTDBBusListener.py
+
25
−
18
View file @
dbadfbcd
...
...
@@ -18,33 +18,40 @@ logger = logging.getLogger(__name__)
class
TBBTMSSEventMessageHandler
(
TMSSEventMessageHandler
):
def
onSubTaskStatusChanged
(
self
,
id
:
int
,
status
:
str
):
pass
def
__init__
(
self
):
super
().
__init__
(
log_event_messages
=
False
)
self
.
tmss_client
=
TMSSsession
.
create_from_dbcreds_for_ldap
()
def
start_handling
(
self
):
self
.
tmss_client
.
open
()
super
().
start_handling
()
def
onObservationStarted
(
self
,
treeId
,
modificationTime
):
global
prevobsid
global
proclist
global
subdir
global
TBBtype
logger
.
info
(
"
onObservationStarted(%s, %s)
"
%
(
treeId
,
modificationTime
))
def
stop_handling
(
self
):
super
().
stop_handling
()
self
.
tmss_client
.
close
()
try
:
with
OTDBRPC
.
create
()
as
otdbrpc
:
if
otdbrpc
.
taskGetTreeInfo
(
treeId
)[
'
processType
'
]
==
'
Observation
'
:
obsid
=
treeId
def
onSubTaskStatusChanged
(
self
,
id
:
int
,
status
:
str
):
if
status
==
'
started
'
:
subtask
=
self
.
tmss_client
.
get_subtask
(
id
)
if
subtask
[
'
subtask_type
'
]
==
'
observation
'
:
global
prevobsid
global
proclist
global
subdir
global
TBBtype
logger
.
info
(
"
onSubTaskStatusChanged: observation subtask id=% started
"
,
id
)
try
:
obsid
=
id
if
TBBtype
==
'
datawriter
'
:
obsid
=
switchdatawriter
(
obsid
)
elif
TBBtype
==
'
metadata
'
:
obsid
=
addmetadata
(
obsid
)
elif
TBBtype
==
'
writeparset
'
:
obsid
=
writeparset
(
obsid
)
#result = otdbrpc.taskGetSpecification(otdb_id=treeId)
#spec = result['specification']
#writeJSON(spec)
except
Exception
as
e
:
logger
.
error
(
str
(
e
))
except
Exception
as
e
:
logger
.
error
(
str
(
e
))
def
writeparset
(
obsid
):
parset
=
get_all_parameters_new
(
obsid
)
...
...
@@ -181,7 +188,7 @@ def main():
else
:
print
(
"
No observation running, waiting for next observation
"
)
with
OTDB
BusListener
(
handler_type
=
TBB
OTDB
EventMessageHandler
,
num_threads
=
1
):
with
TMSS
BusListener
(
handler_type
=
TBB
TMSS
EventMessageHandler
,
num_threads
=
1
):
waitForInterrupt
()
if
__name__
==
'
__main__
'
:
...
...
This diff is collapsed.
Click to expand it.
CEP/TBB/TBBdatawriter/currentobs.py
+
17
−
12
View file @
dbadfbcd
...
...
@@ -4,26 +4,27 @@
# import os and bfdata package
#import bfdata as bf
from
lofar.sas.resourceassignment.resourceassignmentservice.rpc
import
RADBRPC
from
lofar.sas.otdb.otdbrpc
import
OTDBRPC
from
datetime
import
datetime
from
datetime
import
timedelta
from
lofar.sas.tmss.client.tmss_http_rest_client
import
TMSSsession
def
currentobs
(
offset
=
0
):
"""
Get
'
s a task list with current tasks.
* offset * offset in seconds. Use a negative value to get an observation in the past
"""
d
=
timedelta
(
0
,
offset
)
with
RADBRPC
.
create
()
as
radb_rpc
:
tasks
=
radb_rpc
.
getTasks
(
lower_bound
=
datetime
.
utcnow
()
+
d
,
upper_bound
=
datetime
.
utcnow
()
+
d
,
task_type
=
'
observation
'
)
"""
d
=
timedelta
(
0
,
offset
)
with
TMSSsession
.
create_from_dbcreds_for_ldap
()
as
tmss_client
:
observation_subtasks
=
tmss_client
.
get_subtasks
(
subtask_type
=
'
observation
'
,
scheduled_stop_time_greater_then
=
datetime
.
utcnow
()
+
d
,
scheduled_start_time_less_then
=
datetime
.
utcnow
()
+
d
)
if
len
(
tasks
)
==
0
:
if
len
(
observation_sub
tasks
)
==
0
:
return
"
None
"
elif
len
(
tasks
)
==
1
:
return
tasks
[
0
][
'
otdb_
id
'
]
elif
len
(
observation_sub
tasks
)
==
1
:
return
observation_sub
tasks
[
0
][
'
id
'
]
elif
len
(
tasks
)
>
1
:
# change this to check for stations involved
return
tasks
[
0
][
'
otdb_
id
'
]
return
observation_sub
tasks
[
0
][
'
id
'
]
def
get_all_parameters_new
(
obsid
,
useFilename
=
False
):
if
useFilename
:
...
...
@@ -31,8 +32,12 @@ def get_all_parameters_new(obsid, useFilename=False):
assert
False
if
type
(
obsid
)
==
type
(
""
):
obsid
=
int
(
obsid
.
strip
(
'
L
'
))
with
OTDBRPC
.
create
()
as
otdbrpc
:
parset
=
otdbrpc
.
taskGetSpecification
(
obsid
)[
'
specification
'
]
with
TMSSsession
.
create_from_dbcreds_for_ldap
()
as
tmss_client
:
parset
=
tmss_client
.
get_subtask_parset
(
obsid
)
# the tmss parset is a plain text string
# tbb scripts expect a dict. convert it.
parset
=
{
parts
[
0
].
strip
():
parts
[
2
].
strip
()
for
parts
in
[
line
.
partition
(
'
=
'
)
for
line
in
parset
.
splitlines
()]}
for
k
in
list
(
parset
.
keys
()):
parset
[
k
.
replace
(
"
ObsSW.
"
,
""
)]
=
parset
[
k
]
return
parset
...
...
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