Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
itminedu
synnefo
Commits
c1ca947a
Commit
c1ca947a
authored
May 26, 2011
by
Georgios Gousios
Browse files
Lots of backfixes in status reconciliation code
parent
5fbe73dd
Changes
3
Hide whitespace changes
Inline
Side-by-side
logic/dispatcher.py
View file @
c1ca947a
...
...
@@ -173,11 +173,11 @@ def cleanup_queues() :
if
ans
not
in
[
'Y'
,
'y'
]:
return
for
exchange
in
settings
.
EXCHANGES
:
try
:
chan
.
exchange_delete
(
exchange
=
exchange
)
except
amqp
.
exceptions
.
AMQPChannelException
as
e
:
print
e
.
amqp_reply_code
,
" "
,
e
.
amqp_reply_text
#
for exchange in settings.EXCHANGES:
#
try:
#
chan.exchange_delete(exchange=exchange)
#
except amqp.exceptions.AMQPChannelException as e:
#
print e.amqp_reply_code, " ", e.amqp_reply_text
for
queue
in
settings
.
QUEUES
:
try
:
...
...
logic/dispatcher_callbacks.py
View file @
c1ca947a
...
...
@@ -50,6 +50,9 @@ def update_db(message):
_logger
.
error
(
"Message is of unknown type %s."
,
msg
[
"type"
])
return
if
msg
[
"operation"
]
==
"OP_INSTANCE_QUERY_DATA"
:
return
status_job_finished
(
message
)
vmid
=
utils
.
id_from_instance_name
(
msg
[
"instance"
])
vm
=
VirtualMachine
.
objects
.
get
(
id
=
vmid
)
...
...
@@ -113,63 +116,62 @@ def update_credits(message):
message
.
channel
.
basic_ack
(
message
.
delivery_tag
)
def
trigger_status_update
(
message
):
_logger
.
debug
(
"Request to trigger status update:"
,
message
.
body
)
_logger
.
debug
(
"Request to trigger status update:
%s
"
,
message
.
body
)
try
:
msg
=
json
.
loads
(
message
.
body
)
if
msg
[
"type"
]
!=
"reconcil
iat
e"
:
if
msg
[
"type"
]
!=
"reconcile"
:
_logger
.
error
(
"Message is of unknown type %s"
,
msg
[
"type"
])
return
if
msg
[
"vm
-
id"
]
==
""
:
_logger
.
error
(
"
M
essage does not specify a VM id"
)
if
msg
[
"vmid"
]
==
""
:
_logger
.
error
(
"
Reconciliate m
essage does not specify a VM id"
)
return
vm
=
VirtualMachine
.
objects
.
get
(
id
=
msg
[
"vm
-
id"
])
vm
=
VirtualMachine
.
objects
.
get
(
id
=
msg
[
"vmid"
])
backend
.
request_status_update
(
vm
)
message
.
channel
.
basic_ack
(
message
.
delivery_tag
)
except
KeyError
:
_logger
.
error
(
"Malformed incoming JSON, missing attributes: %s"
,
message
.
body
)
except
KeyError
as
k
:
_logger
.
error
(
"Malformed incoming JSON, missing attributes: %s"
,
k
)
except
Exception
as
e
:
_logger
.
error
(
"Unexpected error:
\n
%s"
%
""
.
join
(
traceback
.
format_exception
(
*
sys
.
exc_info
())))
_logger
.
error
(
"Unexpected error:%s"
,
e
)
def
status_job_finished
(
message
)
:
_logger
.
debug
(
"Job status message received:"
,
message
.
body
)
try
:
msg
=
json
.
loads
(
message
.
body
)
msg
=
message
.
body
;
if
msg
[
'operation'
]
!=
u
'OP_INSTANCE_QUERY_DATA'
:
if
msg
[
"operation"
]
!=
'OP_INSTANCE_QUERY_DATA'
:
_logger
.
error
(
"Message is of unknown type %s"
,
msg
[
"operation"
])
return
if
msg
[
"status"
]
!=
"success"
:
_logger
.
error
(
"Status job %d for %s did not finish properly
"
,
_logger
.
warn
(
"Ignoring non-success status update from job %d on VM %s
"
,
msg
[
'jobId'
],
msg
[
'instance'
])
return
status
=
backend
.
get_job_status
(
msg
[
'job
i
d'
])
status
=
backend
.
get_job_status
(
msg
[
'job
I
d'
])
if
status
[
"summary"
]
!=
"INSTANCE_QUERY_DATA"
or
type
(
status
[
"opresult"
])
is
not
list
:
_logger
.
error
(
"Status is of unknown type %s"
,
msg
[
"summary"
])
_logger
.
debug
(
"Node status job result: %s"
%
status
)
stat
=
json
.
loads
(
status
)
if
stat
[
"summary"
]
!=
"INSTANCE_QUERY_DATA"
or
\
type
(
stat
[
"opresult"
])
is
not
list
:
_logger
.
error
(
"Status is of unknown type %s"
,
stat
[
"summary"
])
return
req_state
=
stat
us
[
'opresult'
][
msg
[
'instance'
]][
'config_state'
]
run_state
=
stat
us
[
'opresult'
][
msg
[
'instance'
]][
'run_state'
]
req_state
=
stat
[
'opresult'
][
msg
[
'instance'
]][
'config_state'
]
run_state
=
stat
[
'opresult'
][
msg
[
'instance'
]][
'run_state'
]
vm
=
VirtualMachine
.
objects
.
get
(
name
=
msg
[
'instance'
])
backend
.
update_status
(
vm
,
run_state
)
message
.
channel
.
basic_ack
(
message
.
delivery_tag
)
except
KeyError
:
_logger
.
error
(
"Malformed incoming JSON, missing attributes: %s"
,
message
.
body
)
except
KeyError
as
k
:
_logger
.
error
(
"Malformed incoming JSON, missing attributes: %s"
,
k
)
except
Exception
as
e
:
_logger
.
error
(
"Unexpected error:
\n
%s"
%
""
.
join
(
traceback
.
format_exception
(
*
sys
.
exc_info
())))
_logger
.
error
(
"Unexpected error:%s"
%
e
)
def
dummy_proc
(
message
):
try
:
...
...
logic/management/commands/reconcile.py
View file @
c1ca947a
...
...
@@ -67,14 +67,15 @@ class Command(NoArgsCommand):
to_update
=
all
.
count
()
/
settings
.
RECONCILIATION_MIN
vm_ids
=
map
(
lambda
x
:
x
.
name
,
VirtualMachine
.
objects
.
all
()[:
to_update
])
vm_ids
=
map
(
lambda
x
:
x
.
id
,
VirtualMachine
.
objects
.
all
()[:
to_update
])
sent
=
False
self
.
open_channel
()
for
vmid
in
vm_ids
:
while
sent
is
False
:
try
:
msg
=
dict
(
type
=
"reconciliate"
,
vmid
=
vmid
)
self
.
chan
.
basic_publish
(
json
.
dumps
(
msg
),
msg
=
dict
(
type
=
"reconcile"
,
vmid
=
vmid
)
amqp_msg
=
amqp
.
Message
(
json
.
dumps
(
msg
))
self
.
chan
.
basic_publish
(
amqp_msg
,
exchange
=
settings
.
EXCHANGE_CRON
,
routing_key
=
"reconciliation.%s"
%
vmid
)
sent
=
True
...
...
@@ -83,5 +84,4 @@ class Command(NoArgsCommand):
except
Exception
:
raise
print
"All: %d, To update: %d, Triggered update for: %s"
%
(
all
.
count
(),
not_updated
.
count
(),
vm_ids
)
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