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
5a118f19
Commit
5a118f19
authored
5 years ago
by
Jan David Mol
Browse files
Options
Downloads
Patches
Plain Diff
SW-610
: Upgrade ObservationControl2 to use Fabric v2+
parent
0a24689d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
MAC/Services/src/ObservationControl2.py
+12
-21
12 additions, 21 deletions
MAC/Services/src/ObservationControl2.py
with
12 additions
and
21 deletions
MAC/Services/src/ObservationControl2.py
+
12
−
21
View file @
5a118f19
...
...
@@ -21,16 +21,8 @@ import os
import
logging
from
optparse
import
OptionParser
from
fabric.exceptions
import
NetworkError
try
:
# WARNING: This code only works with Fabric Version 1
from
fabric
import
tasks
from
fabric.api
import
env
,
run
,
settings
except
ImportError
as
e
:
print
(
str
(
e
))
print
(
'
Please install python3 package fabric: sudo apt-get install fabric
'
)
exit
(
1
)
# WARNING: This code only works with Fabric Version 2
from
fabric.connection
import
Connection
from
lofar.messaging
import
Service
from
lofar.messaging
import
setQpidLogLevel
...
...
@@ -48,15 +40,18 @@ class ObservationControlHandler(MessageHandlerInterface):
'
AbortObservation
'
:
self
.
abort_observation
}
env
.
host
s
=
[
"
localhost
"
]
host
=
"
localhost
"
if
"
LOFARENV
"
in
os
.
environ
:
lofar_environment
=
os
.
environ
[
'
LOFARENV
'
]
if
lofar_environment
==
"
PRODUCTION
"
:
env
.
host
s
=
[
config
.
PRODUCTION_OBSERVATION_CONTROL_HOST
]
host
=
config
.
PRODUCTION_OBSERVATION_CONTROL_HOST
elif
lofar_environment
==
"
TEST
"
:
env
.
hosts
=
[
config
.
TEST_OBSERVATION_CONTROL_HOST
]
host
=
config
.
TEST_OBSERVATION_CONTROL_HOST
self
.
connection
=
Connection
(
host
)
def
_abort_observation_task
(
self
,
sas_id
):
logger
.
info
(
"
trying to abort ObservationControl for SAS ID: %s
"
,
sas_id
)
...
...
@@ -64,25 +59,21 @@ class ObservationControlHandler(MessageHandlerInterface):
killed
=
False
with
settings
(
warn_only
=
True
):
pid_line
=
run
(
'
pidof ObservationControl
'
)
pid_line
=
self
.
connection
.
run
(
'
pidof ObservationControl
'
)
.
stdout
pids
=
pid_line
.
split
(
'
'
)
for
pid
in
pids
:
pid_sas_id
=
run
(
"
ps -p %s --no-heading -o command | awk -F[{}]
'
{ printf $2; }
'"
%
pid
)
pid_sas_id
=
self
.
connection
.
run
(
"
ps -p %s --no-heading -o command | awk -F[{}]
'
{ printf $2; }
'"
%
pid
)
.
stdout
if
str
(
pid_sas_id
)
==
str
(
sas_id
):
logger
.
info
(
"
Killing ObservationControl with PID: %s for SAS ID: %s
"
,
pid
,
sas_id
)
run
(
'
kill -SIGINT %s
'
%
pid
)
self
.
connection
.
run
(
'
kill -SIGINT %s
'
%
pid
)
killed
=
True
return
killed
def
abort_observation
(
self
,
sas_id
):
"""
aborts an observation for a single sas_id
"""
try
:
result
=
tasks
.
execute
(
self
.
_abort_observation_task
,
sas_id
)
aborted
=
True
in
list
(
result
.
values
())
except
NetworkError
:
aborted
=
False
aborted
=
self
.
_abort_observation_task
(
sas_id
)
return
{
'
aborted
'
:
aborted
}
...
...
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