Commit 1aabfe3f authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_jio: Improve/speed up display of monitoring for services and instances

parent a506499c
...@@ -276,7 +276,7 @@ ...@@ -276,7 +276,7 @@
"url": "gadget_slapos_hosting_subscription_status.html", "url": "gadget_slapos_hosting_subscription_status.html",
"sandbox": "", "sandbox": "",
"key": "monitoring_status", "key": "monitoring_status",
"hidden": gadget.state.doc.root_slave === 1, "hidden": 0,
"type": "GadgetField" "type": "GadgetField"
}, },
"my_monitor_scope": { "my_monitor_scope": {
......
...@@ -230,7 +230,7 @@ ...@@ -230,7 +230,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>974.49068.53964.3174</string> </value> <value> <string>974.50466.65103.30515</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -248,7 +248,7 @@ ...@@ -248,7 +248,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1554168123.09</float> <float>1554257716.79</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -18,24 +18,23 @@ ...@@ -18,24 +18,23 @@
"root_slave"]; "root_slave"];
return gadget.jio_allDocs(param_list[0]) return gadget.jio_allDocs(param_list[0])
.push(function (result) { .push(function (result) {
var i, value, len = result.data.total_rows; var i, value, news, len = result.data.total_rows;
for (i = 0; i < len; i += 1) { for (i = 0; i < len; i += 1) {
if (1 || (result.data.rows[i].value.hasOwnProperty("root_slave"))) { if (1 || (result.data.rows[i].value.hasOwnProperty("HostingSubscription_getNewsDict"))) {
if (result.data.rows[i].value.root_slave !== 1) {
value = result.data.rows[i].id; value = result.data.rows[i].id;
result.data.rows[i].value.monitoring_status = { news = result.data.rows[i].value.HostingSubscription_getNewsDict;
result.data.rows[i].value.HostingSubscription_getNewsDict = {
field_gadget_param : { field_gadget_param : {
css_class: "", css_class: "",
description: "The Status", description: "The Status",
hidden: 0, hidden: 0,
"default": {jio_key: value}, "default": {jio_key: value, result: news},
key: "status", key: "status",
url: "gadget_slapos_hosting_subscription_status.html", url: "gadget_slapos_hosting_subscription_status.html",
title: "Status", title: "Status",
type: "GadgetField" type: "GadgetField"
} }
}; };
}
result.data.rows[i].value["listbox_uid:list"] = { result.data.rows[i].value["listbox_uid:list"] = {
key: "listbox_uid:list", key: "listbox_uid:list",
value: 2713 value: 2713
...@@ -72,7 +71,7 @@ ...@@ -72,7 +71,7 @@
var column_list = [ var column_list = [
['title', 'Title'], ['title', 'Title'],
['short_title', 'Short Title'], ['short_title', 'Short Title'],
['monitoring_status', 'Status'] ['HostingSubscription_getNewsDict', 'Status']
]; ];
return form_list.render({ return form_list.render({
erp5_document: { erp5_document: {
......
...@@ -230,7 +230,7 @@ ...@@ -230,7 +230,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>972.32024.53732.34406</string> </value> <value> <string>974.29121.45777.11366</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -248,7 +248,7 @@ ...@@ -248,7 +248,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1552957541.9</float> <float>1554257753.72</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -17,6 +17,10 @@ ...@@ -17,6 +17,10 @@
<a class="ui-btn ui-btn-icon-left ui-icon-desktop" href="{{monitor_url}}" target=_blank> {{status_title}} </a></div></div> <a class="ui-btn ui-btn-icon-left ui-icon-desktop" href="{{monitor_url}}" target=_blank> {{status_title}} </a></div></div>
</script> </script>
<script id="inline-status-no-link-template" type="text/x-handlebars-template">
<div class="ui-block-a" style="width:50%"><div class="ui-bar ui-corner-all first-child {{status_class}}" style="{{status_style}}" >{{status_title}}</div></div>
</script>
<script id="loading-template" type="text/x-handlebars-template"> <script id="loading-template" type="text/x-handlebars-template">
<button data-i18n="loading" type="submit" class="responsive ui-btn ui-icon-spinner ui-icon-spin ui-btn-icon-center ui-disabled" style="border:none;">loading</button> <button data-i18n="loading" type="submit" class="responsive ui-btn ui-icon-spinner ui-icon-spin ui-btn-icon-center ui-disabled" style="border:none;">loading</button>
</script> </script>
......
...@@ -272,7 +272,7 @@ ...@@ -272,7 +272,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>968.33074.267.61440</string> </value> <value> <string>972.32024.53732.34406</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -290,7 +290,7 @@ ...@@ -290,7 +290,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1530120259.86</float> <float>1554257675.61</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -7,7 +7,13 @@ ...@@ -7,7 +7,13 @@
inline_status_source = gadget_klass.__template_element inline_status_source = gadget_klass.__template_element
.getElementById("inline-status-template") .getElementById("inline-status-template")
.innerHTML, .innerHTML,
inline_status_template = Handlebars.compile(inline_status_source); inline_status_template = Handlebars.compile(inline_status_source),
inline_status_no_link_source = gadget_klass.__template_element
.getElementById("inline-status-no-link-template")
.innerHTML,
inline_status_no_link_template = Handlebars
.compile(inline_status_no_link_source);
function checkHostingSubscriptionStatus(options) { function checkHostingSubscriptionStatus(options) {
var message, var message,
...@@ -16,12 +22,22 @@ ...@@ -16,12 +22,22 @@
error_amount = 0, error_amount = 0,
total_amount = 0; total_amount = 0;
if ((!options) || (options && !options.news)) { if ((!options) || (options && !options.instance)) {
return 'ui-btn-no-data'; return 'ui-btn-no-data';
} }
for (instance in options.news) { if (options.is_slave) {
message = options.news[instance].text; return 'ui-btn-is-slave';
}
else if (options.is_stopped) {
return 'ui-btn-is-stopped';
}
else if (options.is_destroyed) {
return 'ui-btn-is-destroyed';
}
for (instance in options.instance) {
message = options.instance[instance].text;
if (message.startsWith("#error")) { if (message.startsWith("#error")) {
partition_class = 'ui-btn-warning'; partition_class = 'ui-btn-warning';
error_amount++; error_amount++;
...@@ -33,9 +49,6 @@ ...@@ -33,9 +49,6 @@
return partition_class; return partition_class;
} }
} }
if (options.computer_partition === {}) {
return 'ui-btn-no-data';
}
if (error_amount === total_amount) { if (error_amount === total_amount) {
// No need to continue the result will be a warnning // No need to continue the result will be a warnning
...@@ -51,65 +64,75 @@ ...@@ -51,65 +64,75 @@
return gadget.jio_get(gadget.options.value.jio_key); return gadget.jio_get(gadget.options.value.jio_key);
} }
function getMonitorParameterDict(gadget, doc) { function getStatus(gadget, result) {
if (doc.portal_type === "Hosting Subscription") {
return gadget.jio_getAttachment(gadget.options.value.jio_key,
gadget.props.hateoas_url + gadget.options.value.jio_key +
"/HostingSubscription_getMonitorParameterDict");
}
}
function getStatus(gadget) {
var result;
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
return getDoc(gadget); return getDoc(gadget);
}) })
.push(function (jio_doc) { .push(function (jio_doc) {
result = jio_doc;
if (gadget.state.monitor_dict === undefined ||
!gadget.state.has_monitor_info) {
return getMonitorParameterDict(gadget, jio_doc)
.push(function (param_dict) {
return gadget.changeState({
monitor_dict: param_dict,
has_monitor_info: true
});
});
}
})
.push(function () {
var monitor_url, var monitor_url,
connection_key,
status_class = 'ui-btn-no-data', status_class = 'ui-btn-no-data',
status_title = 'Instances', status_title = 'Instances',
status_style = ""; status_style = "";
status_class = checkHostingSubscriptionStatus(result); result = jio_doc;
if (gadget.state.monitor_dict.url && status_class = checkHostingSubscriptionStatus(result.news);
gadget.state.monitor_dict.username && // it should verify if the monitor-base-url is ready.
gadget.state.monitor_dict.password) { for (connection_key in result.connection_parameter_list) {
monitor_url = "https://monitor.app.officejs.com/#page=settings_configurator&url=" + if (result.connection_parameter_list[connection_key].connection_key === "monitor-setup-url") {
gadget.state.monitor_dict.url + "&username=" + monitor_url = result.connection_parameter_list[connection_key].connection_value;
gadget.state.monitor_dict.username + "&password=" + }
gadget.state.monitor_dict.password; }
} else { if (monitor_url === "") {
monitor_url = 'https://monitor.app.officejs.com/#/?page=ojsm_dispatch&query=portal_type%3A%22Hosting%20Subscription%22%20AND%20title%3A' + result.title; monitor_url = 'https://monitor.app.officejs.com/#/?page=ojsm_dispatch&query=portal_type%3A%22Hosting%20Subscription%22%20AND%20title%3A' + result.title;
} }
if (status_class === 'ui-btn-no-data') { if (status_class === 'ui-btn-is-slave') {
status_style = "color: transparent !important;"; status_class = 'ui-btn-no-data';
status_style = "color: white !important;";
status_title = 'Slave Only';
}
else if (status_class === 'ui-btn-is-stopped') {
status_class = 'ui-btn-no-data';
status_style = "color: white !important;";
status_title = 'Stopped';
}
else if (status_class === 'ui-btn-is-destroyed') {
status_class = 'ui-btn-no-data';
status_style = "color: white !important;";
status_title = 'Destroyed';
} }
if (status_class === 'ui-btn-no-data') {
gadget.element.innerHTML = inline_status_no_link_template({
status_class: status_class,
status_title: status_title,
status_style: status_style
});
} else {
gadget.element.innerHTML = inline_status_template({ gadget.element.innerHTML = inline_status_template({
monitor_url: monitor_url, monitor_url: monitor_url,
status_class: status_class, status_class: status_class,
status_title: status_title, status_title: status_title,
status_style: status_style status_style: status_style
}); });
}
return gadget; return gadget;
} }
); );
} }
function getStatusLoop(gadget) {
return new RSVP.Queue()
.push(function () {
return gadget.jio_get(gadget.options.value.jio_key);
})
.push(function (result) {
return getStatus(gadget, result);
});
}
gadget_klass gadget_klass
.setState({ .setState({
has_monitor_info: false has_monitor_info: false
...@@ -122,26 +145,27 @@ ...@@ -122,26 +145,27 @@
}); });
}) })
.declareAcquiredMethod("jio_get", "jio_get") .declareAcquiredMethod("jio_get", "jio_get")
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("jio_getAttachment", "jio_getAttachment") .declareAcquiredMethod("jio_getAttachment", "jio_getAttachment")
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("translateHtml", "translateHtml") .declareAcquiredMethod("translateHtml", "translateHtml")
.declareMethod("getContent", function () { .declareMethod("getContent", function () {
return {}; return {};
}) })
.declareJob("getStatus", function () { .declareJob("getStatus", function (result) {
var gadget = this; var gadget = this;
return getStatus(gadget); return getStatus(gadget, {news: result});
}) })
.onLoop(function () { .onLoop(function () {
var gadget = this; var gadget = this;
return getStatus(gadget); return getStatusLoop(gadget);
}, 300000) }, 300000)
.declareMethod("render", function (options) { .declareMethod("render", function (options) {
var gadget = this; var gadget = this;
gadget.options = options; gadget.options = options;
gadget.flag = options.value.jio_key; gadget.flag = options.value.jio_key;
return gadget.getStatus(); return gadget.getStatus(options.value.result);
}); });
}(window, rJS, RSVP, Handlebars)); }(window, rJS, RSVP, Handlebars));
\ No newline at end of file
...@@ -257,7 +257,7 @@ ...@@ -257,7 +257,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>971.49164.31619.41506</string> </value> <value> <string>972.32024.53732.34406</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -275,7 +275,7 @@ ...@@ -275,7 +275,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1542713467.3</float> <float>1554257864.46</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
return [instance.Base_getNewsDict(instance) for instance in context.getSpecialiseRelatedValueList(portal_type="Software Instance")] news_dict = {"instance" : []}
if context.getSlapState() == 'stop_requested':
news_dict["is_stopped"] = 1
elif context.getSlapState() == 'destroy_requested':
news_dict["is_destroyed"] = 1
elif context.getRootSlave():
news_dict["is_slave"] = 1
else:
news_dict["instance"] = [instance.SoftwareInstance_getNewsDict() for instance in context.getSpecialiseRelatedValueList(portal_type="Software Instance")]
return news_dict
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment