Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
hidra
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
steinbac
hidra
Commits
bec5b4d2
Commit
bec5b4d2
authored
9 years ago
by
Manuela Kuhn
Browse files
Options
Downloads
Patches
Plain Diff
Tested + Fixed TaskProvider
parent
0de834bf
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/sender/InotifyxDetector.py
+2
-1
2 additions, 1 deletion
src/sender/InotifyxDetector.py
src/sender/SignalHandler.py
+15
-15
15 additions, 15 deletions
src/sender/SignalHandler.py
src/sender/TaskProvider.py
+58
-5
58 additions, 5 deletions
src/sender/TaskProvider.py
with
75 additions
and
21 deletions
src/sender/InotifyxDetector.py
+
2
−
1
View file @
bec5b4d2
...
...
@@ -79,8 +79,9 @@ class InotifyxDetector():
checkPassed
=
True
if
(
not
config
.
has_key
(
"
monDir
"
)
or
not
config
.
has_key
(
"
monEventType
"
)
or
not
config
.
has_key
(
"
mon
Def
Subdirs
"
)
or
not
config
.
has_key
(
"
monSubdirs
"
)
or
not
config
.
has_key
(
"
monSuffixes
"
)
):
print
"
config
"
,
config
self
.
log
.
error
(
"
Configuration of wrong format
"
)
checkPassed
=
False
...
...
This diff is collapsed.
Click to expand it.
src/sender/SignalHandler.py
+
15
−
15
View file @
bec5b4d2
...
...
@@ -53,9 +53,9 @@ class SignalHandler():
self
.
whiteList
.
append
(
host
)
# sockets
self
.
comSocket
=
None
self
.
signal
FwSocket
=
None
self
.
requestSocket
=
None
self
.
comSocket
=
None
self
.
request
FwSocket
=
None
self
.
requestSocket
=
None
self
.
log
=
self
.
getLogger
()
self
.
log
.
debug
(
"
Init
"
)
...
...
@@ -91,13 +91,13 @@ class SignalHandler():
# setting up router for load-balancing worker-processes.
# each worker-process will handle a file event
self
.
signal
FwSocket
=
self
.
context
.
socket
(
zmq
.
REP
)
self
.
request
FwSocket
=
self
.
context
.
socket
(
zmq
.
REP
)
connectionStr
=
"
tcp://{ip}:{port}
"
.
format
(
ip
=
self
.
localhost
,
port
=
self
.
signalFwPort
)
try
:
self
.
signal
FwSocket
.
bind
(
connectionStr
)
self
.
log
.
debug
(
"
signal
FwSocket started (bind) for
'"
+
connectionStr
+
"'"
)
self
.
request
FwSocket
.
bind
(
connectionStr
)
self
.
log
.
debug
(
"
request
FwSocket started (bind) for
'"
+
connectionStr
+
"'"
)
except
Exception
as
e
:
self
.
log
.
error
(
"
Failed to start
signal
FwSocket (bind):
'"
+
connectionStr
+
"'"
)
self
.
log
.
error
(
"
Failed to start
request
FwSocket (bind):
'"
+
connectionStr
+
"'"
)
self
.
log
.
debug
(
"
Error was:
"
+
str
(
e
))
# create socket to receive requests
...
...
@@ -113,7 +113,7 @@ class SignalHandler():
# Poller to distinguish between start/stop signals and queries for the next set of signals
self
.
poller
=
zmq
.
Poller
()
self
.
poller
.
register
(
self
.
comSocket
,
zmq
.
POLLIN
)
self
.
poller
.
register
(
self
.
signal
FwSocket
,
zmq
.
POLLIN
)
self
.
poller
.
register
(
self
.
request
FwSocket
,
zmq
.
POLLIN
)
self
.
poller
.
register
(
self
.
requestSocket
,
zmq
.
POLLIN
)
...
...
@@ -123,12 +123,12 @@ class SignalHandler():
while
True
:
socks
=
dict
(
self
.
poller
.
poll
())
if
self
.
signal
FwSocket
in
socks
and
socks
[
self
.
signal
FwSocket
]
==
zmq
.
POLLIN
:
if
self
.
request
FwSocket
in
socks
and
socks
[
self
.
request
FwSocket
]
==
zmq
.
POLLIN
:
try
:
incomingMessage
=
self
.
signal
FwSocket
.
recv
()
incomingMessage
=
self
.
request
FwSocket
.
recv
()
if
incomingMessage
==
"
STOP
"
:
self
.
signal
FwSocket
.
send
(
incomingMessage
)
self
.
request
FwSocket
.
send
(
incomingMessage
)
time
.
sleep
(
0.1
)
break
self
.
log
.
debug
(
"
New request for signals received.
"
)
...
...
@@ -140,11 +140,11 @@ class SignalHandler():
openRequests
.
append
(
tmp
)
if
openRequests
:
self
.
signal
FwSocket
.
send
(
str
(
openRequests
))
self
.
request
FwSocket
.
send
(
str
(
openRequests
))
self
.
log
.
debug
(
"
Answered to request:
"
+
str
(
openRequests
))
else
:
openRequests
=
[
"
None
"
]
self
.
signal
FwSocket
.
send
(
str
(
openRequests
))
self
.
request
FwSocket
.
send
(
str
(
openRequests
))
self
.
log
.
debug
(
"
Answered to request:
"
+
str
(
openRequests
))
except
Exception
,
e
:
self
.
log
.
error
(
"
Failed to receive/answer new signal requests.
"
)
...
...
@@ -319,7 +319,7 @@ class SignalHandler():
def
stop
(
self
):
self
.
log
.
debug
(
"
Closing sockets
"
)
self
.
comSocket
.
close
(
0
)
self
.
signal
FwSocket
.
close
(
0
)
self
.
request
FwSocket
.
close
(
0
)
self
.
requestSocket
.
close
(
0
)
...
...
@@ -358,7 +358,7 @@ if __name__ == '__main__':
def
__exit__
(
self
):
self
.
requestFwSocket
.
close
(
0
)
#
self.context.destroy()
self
.
context
.
destroy
()
# def __del__(self):
# self.requestFwSocket.close(0)
...
...
This diff is collapsed.
Click to expand it.
src/sender/TaskProvider.py
+
58
−
5
View file @
bec5b4d2
...
...
@@ -24,6 +24,9 @@ class TaskProvider():
# monSuffixes : ... ,
#}
print
"
eventDetectorConfig
"
,
eventDetectorConfig
self
.
log
=
self
.
getLogger
()
self
.
log
.
debug
(
"
TaskProvider: __init__()
"
)
...
...
@@ -95,7 +98,7 @@ class TaskProvider():
# socket to disribute the events to the worker
self
.
distrSocket
=
self
.
context
.
socket
(
zmq
.
PUSH
)
connectionStr
=
"
tcp://{ip}:{port}
"
.
format
(
ip
=
self
.
localhost
,
port
=
self
.
requestFw
Port
)
connectionStr
=
"
tcp://{ip}:{port}
"
.
format
(
ip
=
self
.
localhost
,
port
=
self
.
distr
Port
)
try
:
self
.
distrSocket
.
bind
(
connectionStr
)
self
.
log
.
debug
(
"
Connecting to distributing socket (bind):
"
+
str
(
connectionStr
))
...
...
@@ -148,8 +151,9 @@ class TaskProvider():
# send the file to the fileMover
try
:
self
.
log
.
debug
(
"
Sending message...
"
)
self
.
log
.
debug
(
str
(
messageDict
))
self
.
distrSocket
.
send_multipart
([
messageDict
,
requests
])
message
=
[
messageDict
]
+
requests
self
.
log
.
debug
(
str
(
message
))
self
.
distrSocket
.
send_multipart
(
message
)
self
.
log
.
debug
(
"
Sending message...done.
"
)
except
Exception
,
e
:
self
.
log
.
error
(
"
Sending message...failed.
"
)
...
...
@@ -187,13 +191,40 @@ if __name__ == '__main__':
sys
.
path
.
append
(
SRC_PATH
)
import
shared.helperScript
as
helperScript
import
time
class
requestResponder
():
def
__init__
(
self
,
requestFwPort
,
context
=
None
):
self
.
context
=
context
or
zmq
.
Context
.
instance
()
self
.
requestFwSocket
=
self
.
context
.
socket
(
zmq
.
REP
)
connectionStr
=
"
tcp://127.0.0.1:
"
+
requestFwPort
self
.
requestFwSocket
.
bind
(
connectionStr
)
logging
.
info
(
"
[requestResponder] requestFwSocket started (bind) for
'"
+
connectionStr
+
"'"
)
self
.
run
()
def
run
(
self
):
logging
.
info
(
"
[requestResponder] Start run
"
)
openRequests
=
[
'
zitpcx19282:6004
'
,
'
zitpcx19282:6005
'
]
while
True
:
request
=
self
.
requestFwSocket
.
recv
()
logging
.
debug
(
"
[requestResponder] Received request:
"
+
str
(
request
)
)
self
.
requestFwSocket
.
send_multipart
(
openRequests
)
logging
.
debug
(
"
[requestResponder] Answer:
"
+
str
(
openRequests
)
)
def
__exit__
(
self
):
self
.
requestFwSocket
.
close
(
0
)
self
.
context
.
destroy
()
#enable logging
helperScript
.
initLogging
(
"
/space/projects/live-viewer/logs/signalHandler.log
"
,
verbose
=
True
,
onScreenLogLevel
=
"
debug
"
)
eventDetectorConfig
=
{
"
configType
"
:
"
inotifyx
"
,
"
monDir
"
:
"
/space/projects/live-viewer/data/src
"
,
"
monDir
"
:
"
/space/projects/live-viewer/data/s
ou
rc
e
"
,
"
monEventType
"
:
"
IN_CLOSE_WRITE
"
,
"
monSubdirs
"
:
[
"
commissioning
"
,
"
current
"
,
"
local
"
],
"
monSuffixes
"
:
[
"
.tif
"
,
"
.cbf
"
]
...
...
@@ -205,4 +236,26 @@ if __name__ == '__main__':
taskProviderPr
=
Process
(
target
=
TaskProvider
,
args
=
(
eventDetectorConfig
,
requestFwPort
,
distrPort
)
)
taskProviderPr
.
start
()
taskProviderPr
.
join
()
requestResponderPr
=
Process
(
target
=
requestResponder
,
args
=
(
requestFwPort
,
)
)
requestResponderPr
.
start
()
context
=
zmq
.
Context
.
instance
()
distrSocket
=
context
.
socket
(
zmq
.
PULL
)
connectionStr
=
"
tcp://localhost:
"
+
distrPort
distrSocket
.
connect
(
connectionStr
)
logging
.
info
(
"
=== distrSocket connected to
"
+
connectionStr
)
try
:
while
True
:
workload
=
distrSocket
.
recv_multipart
()
logging
.
info
(
"
=== next workload
"
+
str
(
workload
))
except
KeyboardInterrupt
:
pass
finally
:
requestResponderPr
.
terminate
()
taskProviderPr
.
terminate
()
distrSocket
.
close
(
0
)
context
.
destroy
()
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