Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neoppod
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
neoppod
Commits
4fe937d1
Commit
4fe937d1
authored
May 28, 2019
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
admin: simplify code
parent
cf55f66e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
55 deletions
+40
-55
neo/admin/app.py
neo/admin/app.py
+1
-3
neo/admin/handler.py
neo/admin/handler.py
+39
-52
No files found.
neo/admin/app.py
View file @
4fe937d1
...
...
@@ -18,8 +18,7 @@ from neo.lib import logging
from
neo.lib.app
import
BaseApplication
,
buildOptionParser
from
neo.lib.connection
import
ListeningConnection
from
neo.lib.exception
import
PrimaryFailure
from
.handler
import
AdminEventHandler
,
MasterEventHandler
,
\
MasterRequestEventHandler
from
.handler
import
AdminEventHandler
,
MasterEventHandler
from
neo.lib.bootstrap
import
BootstrapManager
from
neo.lib.protocol
import
ClusterStates
,
Errors
,
NodeTypes
,
Packets
from
neo.lib.debug
import
register
as
registerLiveDebugger
...
...
@@ -54,7 +53,6 @@ class Application(BaseApplication):
self
.
pt
=
None
self
.
uuid
=
config
.
get
(
'nid'
)
logging
.
node
(
self
.
name
,
self
.
uuid
)
self
.
request_handler
=
MasterRequestEventHandler
(
self
)
self
.
master_event_handler
=
MasterEventHandler
(
self
)
self
.
cluster_state
=
None
self
.
reset
()
...
...
neo/admin/handler.py
View file @
4fe937d1
...
...
@@ -20,28 +20,46 @@ from neo.lib.protocol import uuid_str, Packets
from
neo.lib.pt
import
PartitionTable
from
neo.lib.exception
import
PrimaryFailure
def
check_primary_master
(
func
):
def
AdminEventHandlerType
(
name
,
bases
,
d
):
def
check_primary_master
(
func
):
def
wrapper
(
self
,
*
args
,
**
kw
):
if
self
.
app
.
master_conn
is
not
None
:
return
func
(
self
,
*
args
,
**
kw
)
raise
protocol
.
NotReadyError
(
'Not connected to a primary master.'
)
return
wrapper
def
forward_ask
(
klass
):
return
check_primary_master
(
lambda
self
,
conn
,
*
args
,
**
kw
:
self
.
app
.
master_conn
.
ask
(
klass
(
*
args
,
**
kw
),
conn
=
conn
,
msg_id
=
conn
.
getPeerId
()))
def
forward_ask
(
klass
):
return
lambda
self
,
conn
,
*
args
:
self
.
app
.
master_conn
.
ask
(
klass
(
*
args
),
conn
=
conn
,
msg_id
=
conn
.
getPeerId
())
del
d
[
'__metaclass__'
]
for
x
in
(
Packets
.
AddPendingNodes
,
Packets
.
AskLastIDs
,
Packets
.
AskLastTransaction
,
Packets
.
AskRecovery
,
Packets
.
CheckReplicas
,
Packets
.
Repair
,
Packets
.
SetClusterState
,
Packets
.
SetNodeState
,
Packets
.
SetNumReplicas
,
Packets
.
Truncate
,
Packets
.
TweakPartitionTable
,
):
d
[
x
.
handler_method_name
]
=
forward_ask
(
x
)
return
type
(
name
,
bases
,
{
k
:
v
if
k
[
0
]
==
'_'
else
check_primary_master
(
v
)
for
k
,
v
in
d
.
iteritems
()})
class
AdminEventHandler
(
EventHandler
):
"""This class deals with events for administrating cluster."""
@
check_primary_master
__metaclass__
=
AdminEventHandlerType
def
askPartitionList
(
self
,
conn
,
min_offset
,
max_offset
,
uuid
):
logging
.
info
(
"ask partition list from %s to %s for %s"
,
min_offset
,
max_offset
,
uuid_str
(
uuid
))
self
.
app
.
sendPartitionTable
(
conn
,
min_offset
,
max_offset
,
uuid
)
@
check_primary_master
def
askNodeList
(
self
,
conn
,
node_type
):
if
node_type
is
None
:
node_type
=
'all'
...
...
@@ -54,37 +72,22 @@ class AdminEventHandler(EventHandler):
p
=
Packets
.
AnswerNodeList
(
node_information_list
)
conn
.
answer
(
p
)
@
check_primary_master
def
askClusterState
(
self
,
conn
):
conn
.
answer
(
Packets
.
AnswerClusterState
(
self
.
app
.
cluster_state
))
@
check_primary_master
def
askPrimary
(
self
,
conn
):
master_node
=
self
.
app
.
master_node
conn
.
answer
(
Packets
.
AnswerPrimary
(
master_node
.
getUUID
()))
@
check_primary_master
def
flushLog
(
self
,
conn
):
self
.
app
.
master_conn
.
send
(
Packets
.
FlushLog
())
super
(
AdminEventHandler
,
self
).
flushLog
(
conn
)
askLastIDs
=
forward_ask
(
Packets
.
AskLastIDs
)
askLastTransaction
=
forward_ask
(
Packets
.
AskLastTransaction
)
addPendingNodes
=
forward_ask
(
Packets
.
AddPendingNodes
)
askRecovery
=
forward_ask
(
Packets
.
AskRecovery
)
tweakPartitionTable
=
forward_ask
(
Packets
.
TweakPartitionTable
)
setClusterState
=
forward_ask
(
Packets
.
SetClusterState
)
setNodeState
=
forward_ask
(
Packets
.
SetNodeState
)
setNumReplicas
=
forward_ask
(
Packets
.
SetNumReplicas
)
checkReplicas
=
forward_ask
(
Packets
.
CheckReplicas
)
truncate
=
forward_ask
(
Packets
.
Truncate
)
repair
=
forward_ask
(
Packets
.
Repair
)
class
MasterEventHandler
(
EventHandler
):
""" This class is just used to dispatch message to right handler"""
def
_connectionLost
(
self
,
conn
):
def
connectionClosed
(
self
,
conn
):
app
=
self
.
app
if
app
.
listening_conn
:
# if running
assert
app
.
master_conn
in
(
conn
,
None
)
...
...
@@ -93,38 +96,22 @@ class MasterEventHandler(EventHandler):
app
.
uuid
=
None
raise
PrimaryFailure
def
connectionFailed
(
self
,
conn
):
self
.
_connectionLost
(
conn
)
def
connectionClosed
(
self
,
conn
):
self
.
_connectionLost
(
conn
)
def
dispatch
(
self
,
conn
,
packet
,
kw
=
{}):
if
'conn'
in
kw
:
# expected answer
if
packet
.
isResponse
():
packet
.
setId
(
kw
[
'msg_id'
])
kw
[
'conn'
].
answer
(
packet
)
else
:
self
.
app
.
request_handler
.
dispatch
(
conn
,
packet
,
kw
)
else
:
# unexpected answers and notifications
forward
=
kw
.
get
(
'conn'
)
if
forward
is
None
:
super
(
MasterEventHandler
,
self
).
dispatch
(
conn
,
packet
,
kw
)
else
:
packet
.
setId
(
kw
[
'msg_id'
])
forward
.
answer
(
packet
)
def
answerClusterState
(
self
,
conn
,
state
):
self
.
app
.
cluster_state
=
state
notifyClusterInformation
=
answerClusterState
def
sendPartitionTable
(
self
,
conn
,
ptid
,
num_replicas
,
row_list
):
pt
=
self
.
app
.
pt
=
object
.
__new__
(
PartitionTable
)
pt
.
load
(
ptid
,
num_replicas
,
row_list
,
self
.
app
.
nm
)
def
notifyPartitionChanges
(
self
,
conn
,
ptid
,
num_replicas
,
cell_list
):
self
.
app
.
pt
.
update
(
ptid
,
num_replicas
,
cell_list
,
self
.
app
.
nm
)
def
notifyClusterInformation
(
self
,
conn
,
cluster_state
):
self
.
app
.
cluster_state
=
cluster_state
class
MasterRequestEventHandler
(
EventHandler
):
""" This class handle all answer from primary master node"""
# XXX: to be deleted ?
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment