Module: check_mk
Branch: master
Commit: 46995a940b18296fd3483143e203bfdf70a87c14
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=46995a940b1829…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue Oct 2 14:54:24 2012 +0200
Added progress indicator in single site WATO "Activate Changes"
---
ChangeLog | 1 +
web/htdocs/js/wato.js | 58 +++++++++++++++++++++++++++++++++-
web/htdocs/wato.css | 10 ++++++
web/htdocs/wato.py | 76 +++++++++++++++++++++++++++++++++------------
web/plugins/pages/wato.py | 1 +
5 files changed, 125 insertions(+), 21 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 734e22f..a781264 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -17,6 +17,7 @@
* FIX: Fixed login/login confusions with index page caching
WATO:
+ * Added progress indicator in single site WATO "Activate Changes"
* FIX: Implemented basic non HTTP 200 status code response handling in interactive
progress dialogs (e.g. bulk inventory mode)
diff --git a/web/htdocs/js/wato.js b/web/htdocs/js/wato.js
index e3da0f4..908683b 100644
--- a/web/htdocs/js/wato.js
+++ b/web/htdocs/js/wato.js
@@ -479,6 +479,54 @@ function update_bulk_moveto(val) {
fields = null;
}
+// .----------------------------------------------------------------------.
+// | _ _ _ _ _ |
+// | / \ ___| |_(_)_ ____ _| |_(_) ___ _ __ |
+// | / _ \ / __| __| \ \ / / _` | __| |/ _ \| '_ \ |
+// | / ___ \ (__| |_| |\ V / (_| | |_| | (_) | | | | |
+// | /_/ \_\___|\__|_| \_/ \__,_|\__|_|\___/|_| |_| |
+// | |
+// +----------------------------------------------------------------------+
+
+function wato_do_activation(siteid, est) {
+ // Hide the activate changes button
+ var button = document.getElementById('act_changes_button');
+ if(button) {
+ button.style.display = 'none';
+ button = null;
+ }
+
+ get_url("wato_ajax_activation.py",
+ wato_activation_result, siteid);
+ replication_progress[siteid] = 20; // 10 of 10 10ths
+
setTimeout("replication_step('"+siteid+"',"+est+");",
est/10);
+}
+
+function wato_activation_result(siteid, code) {
+ replication_progress[siteid] = 0;
+ var oState = document.getElementById("repstate_" + siteid);
+ var oMsg = document.getElementById("repmsg_" + siteid);
+ if (code.substr(0, 3) == "OK:") {
+ oState.innerHTML = "<div class='repprogress ok' style='width:
160px;'>OK</div>";
+ oMsg.innerHTML = code.substr(3);
+
+ // Reload page after 2 secs
+ setTimeout(wato_replication_finish, 2000);
+ } else {
+ oState.innerHTML = '';
+ oMsg.innerHTML = code;
+
+ // Show the activate changes button again
+ var button = document.getElementById('act_changes_button');
+ if(button) {
+ button.style.display = '';
+ button = null;
+ }
+ }
+ oState = null;
+ oMsg = null;
+}
+
// +----------------------------------------------------------------------+
// | ____ _ _ _ _ |
// | | _ \ ___ _ __ | (_) ___ __ _| |_(_) ___ _ __ |
@@ -528,8 +576,16 @@ function wato_replication_result(siteid, code) {
function wato_replication_finish() {
if(parent && parent.frames[1])
parent.frames[1].location.reload(); // reload sidebar
- oDiv = document.getElementById("act_changes_button");
+ var oDiv = document.getElementById("act_changes_button");
oDiv.style.display = "none";
+ oDiv = null
+
+ // Hide the pending changes container
+ var oPending = document.getElementById("pending_changes");
+ if(oPending) {
+ oPending.style.display = "none";
+ oPending = null
+ }
}
function wato_randomize_secret(id, len) {
diff --git a/web/htdocs/wato.css b/web/htdocs/wato.css
index 9a8ab58..33c56b6 100644
--- a/web/htdocs/wato.css
+++ b/web/htdocs/wato.css
@@ -804,6 +804,16 @@ div.varname {
width: 300px;
}
+/* activation */
+.wato table.data div.act_success {
+}
+
+.wato table.data div.act_success img {
+ width: 18px;
+ height: 18px;
+ vertical-align: middle;
+}
+
/* Replication */
.wato table.data td.repprogress {
width: 160px;
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index 8541e6a..2a0e216 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -3381,26 +3381,16 @@ def mode_changelog(phase):
elif transaction_already_checked or html.check_transaction():
config.need_permission("wato.activate")
create_snapshot()
- if is_distributed():
- # Do nothing here, but let site status table be shown in a mode
- # were in each site that is not up-to-date an asynchronus AJAX
- # job is being startet that updates that site
- sitestatus_do_async_replication = True
- else:
- try:
- check_mk_local_automation(config.wato_activation_method)
- except Exception, e:
- if config.debug:
- raise
- else:
- raise MKUserError(None, "Error executing hooks: %s" %
str(e))
- log_commit_pending() # flush logfile with pending actions
- log_audit(None, "activate-config", _("Configuration
activated, monitoring server restarted"))
- return None, _("The new configuration has been successfully
activated.")
- else:
- # Distributed WATO: Show replication state of each site
+ # Do nothing here, but let site status table be shown in a mode
+ # were in each site that is not up-to-date an asynchronus AJAX
+ # job is being startet that updates that site
+ sitestatus_do_async_replication = True
+
+ else: # phase: regular page rendering
+
if is_distributed():
+ # Distributed WATO: Show replication state of each site
# During bulk replication we rather create the sync snapshot now. Otherwise
# there is the danger, that it is created multiple times in parallel, thus
@@ -3568,19 +3558,35 @@ def mode_changelog(phase):
html.write("</tr>")
html.write("</table>")
-
# The Javascript world needs to know, how many asynchronous
# replication jobs it should wait to be finished.
- if num_replsites > 0:
+ if sitestatus_do_async_replication and num_replsites > 0:
html.javascript("var num_replsites = %d;\n" % num_replsites)
+ elif sitestatus_do_async_replication:
+ # Single site setup
+
+ # Is rendered on the page after hitting the "activate" button
+ # Renders the html to show the progress and starts the sync via javascript
+ html.write("<table class=data>")
+ html.write("<tr><th
class=left>%s</th><th>%s</th></tr>" %
(_('Progress'), _('Status')))
+ html.write('<tr class="data odd0"><td
class=repprogress><div
id="repstate_local"></div></td>')
+ html.write('<td
id="repmsg_local"><i>%s</i></td></tr></table>'
% _('activating...'))
+
+ srs = load_replication_status().get('local', {})
+ estimated_duration = srs.get("times", {}).get('act', 2.0)
+ html.javascript("wato_do_activation('local', %d);" %
+ (int(estimated_duration * 1000.0)))
+
sitestatus_do_async_replication = None # could survive in global context!
pending = parse_audit_log("pending")
if len(pending) == 0:
html.write("<div class=info>" + _("There are no pending
changes.") + "</div>")
else:
+ html.write('<div id=pending_changes>')
render_audit_log(pending, "pending", hilite_others=True)
+ html.write('</div>')
# Determine if other users have made pending changes
def foreign_changes():
@@ -7170,6 +7176,36 @@ def push_snapshot_to_site(site, do_restart):
raise MKAutomationException(_("Garbled automation response from site %s:
'%s'") %
(site["id"], response_text))
+# AJAX handler for javascript triggered wato activation
+def ajax_activation():
+ try:
+ if is_distributed():
+ raise MKUserError(None, _('Call not supported in distributed
setups.'))
+
+ config.need_permission("wato.activate")
+
+ # Initialise g_root_folder, load all folder information
+ prepare_folder_info()
+
+ # This is the single site activation mode
+ try:
+ start = time.time()
+ check_mk_local_automation(config.wato_activation_method)
+ duration = time.time() - start
+ update_replication_status('local', {}, { 'act': duration })
+ except Exception:
+ import traceback
+ raise MKUserError(None, "Error executing hooks: %s" %
+ traceback.format_exc().replace('\n',
'<br />'))
+
+ log_commit_pending() # flush logfile with pending actions
+ log_audit(None, "activate-config", _("Configuration activated,
monitoring server restarted"))
+
+ # html.message
+ html.write('OK: ')
+ html.write('<div class=act_success><img
src="images/icon_apply.png" /> %s</div>' % _("The new
configuration has been successfully activated."))
+ except Exception, e:
+ html.show_error(str(e))
# AJAX handler for asynchronous site replication
def ajax_replication():
diff --git a/web/plugins/pages/wato.py b/web/plugins/pages/wato.py
index 1fb4a37..19ab792 100644
--- a/web/plugins/pages/wato.py
+++ b/web/plugins/pages/wato.py
@@ -29,6 +29,7 @@ import wato
pagehandlers.update({
"wato" : wato.page_handler,
"wato_ajax_replication" : wato.ajax_replication,
+ "wato_ajax_activation" : wato.ajax_activation,
"automation_login" : wato.page_automation_login,
"automation" : wato.page_automation,
"user_profile" : wato.page_user_profile,