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 @@
"url": "gadget_slapos_hosting_subscription_status.html",
"sandbox": "",
"key": "monitoring_status",
"hidden": gadget.state.doc.root_slave === 1,
"hidden": 0,
"type": "GadgetField"
},
"my_monitor_scope": {
......
......@@ -230,7 +230,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>974.49068.53964.3174</string> </value>
<value> <string>974.50466.65103.30515</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -248,7 +248,7 @@
</tuple>
<state>
<tuple>
<float>1554168123.09</float>
<float>1554257716.79</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -18,24 +18,23 @@
"root_slave"];
return gadget.jio_allDocs(param_list[0])
.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) {
if (1 || (result.data.rows[i].value.hasOwnProperty("root_slave"))) {
if (result.data.rows[i].value.root_slave !== 1) {
if (1 || (result.data.rows[i].value.hasOwnProperty("HostingSubscription_getNewsDict"))) {
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 : {
css_class: "",
description: "The Status",
hidden: 0,
"default": {jio_key: value},
"default": {jio_key: value, result: news},
key: "status",
url: "gadget_slapos_hosting_subscription_status.html",
title: "Status",
type: "GadgetField"
}
};
}
result.data.rows[i].value["listbox_uid:list"] = {
key: "listbox_uid:list",
value: 2713
......@@ -72,7 +71,7 @@
var column_list = [
['title', 'Title'],
['short_title', 'Short Title'],
['monitoring_status', 'Status']
['HostingSubscription_getNewsDict', 'Status']
];
return form_list.render({
erp5_document: {
......
......@@ -230,7 +230,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>972.32024.53732.34406</string> </value>
<value> <string>974.29121.45777.11366</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -248,7 +248,7 @@
</tuple>
<state>
<tuple>
<float>1552957541.9</float>
<float>1554257753.72</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -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>
</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">
<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>
......
......@@ -272,7 +272,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>968.33074.267.61440</string> </value>
<value> <string>972.32024.53732.34406</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -290,7 +290,7 @@
</tuple>
<state>
<tuple>
<float>1530120259.86</float>
<float>1554257675.61</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -7,7 +7,13 @@
inline_status_source = gadget_klass.__template_element
.getElementById("inline-status-template")
.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) {
var message,
......@@ -16,12 +22,22 @@
error_amount = 0,
total_amount = 0;
if ((!options) || (options && !options.news)) {
if ((!options) || (options && !options.instance)) {
return 'ui-btn-no-data';
}
for (instance in options.news) {
message = options.news[instance].text;
if (options.is_slave) {
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")) {
partition_class = 'ui-btn-warning';
error_amount++;
......@@ -33,9 +49,6 @@
return partition_class;
}
}
if (options.computer_partition === {}) {
return 'ui-btn-no-data';
}
if (error_amount === total_amount) {
// No need to continue the result will be a warnning
......@@ -51,65 +64,75 @@
return gadget.jio_get(gadget.options.value.jio_key);
}
function getMonitorParameterDict(gadget, doc) {
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;
function getStatus(gadget, result) {
return new RSVP.Queue()
.push(function () {
return getDoc(gadget);
})
.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,
connection_key,
status_class = 'ui-btn-no-data',
status_title = 'Instances',
status_style = "";
status_class = checkHostingSubscriptionStatus(result);
if (gadget.state.monitor_dict.url &&
gadget.state.monitor_dict.username &&
gadget.state.monitor_dict.password) {
monitor_url = "https://monitor.app.officejs.com/#page=settings_configurator&url=" +
gadget.state.monitor_dict.url + "&username=" +
gadget.state.monitor_dict.username + "&password=" +
gadget.state.monitor_dict.password;
} else {
result = jio_doc;
status_class = checkHostingSubscriptionStatus(result.news);
// it should verify if the monitor-base-url is ready.
for (connection_key in result.connection_parameter_list) {
if (result.connection_parameter_list[connection_key].connection_key === "monitor-setup-url") {
monitor_url = result.connection_parameter_list[connection_key].connection_value;
}
}
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;
}
if (status_class === 'ui-btn-no-data') {
status_style = "color: transparent !important;";
if (status_class === 'ui-btn-is-slave') {
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({
monitor_url: monitor_url,
status_class: status_class,
status_title: status_title,
status_style: status_style
});
}
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
.setState({
has_monitor_info: false
......@@ -122,26 +145,27 @@
});
})
.declareAcquiredMethod("jio_get", "jio_get")
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("jio_getAttachment", "jio_getAttachment")
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("translateHtml", "translateHtml")
.declareMethod("getContent", function () {
return {};
})
.declareJob("getStatus", function () {
.declareJob("getStatus", function (result) {
var gadget = this;
return getStatus(gadget);
return getStatus(gadget, {news: result});
})
.onLoop(function () {
var gadget = this;
return getStatus(gadget);
return getStatusLoop(gadget);
}, 300000)
.declareMethod("render", function (options) {
var gadget = this;
gadget.options = options;
gadget.flag = options.value.jio_key;
return gadget.getStatus();
return gadget.getStatus(options.value.result);
});
}(window, rJS, RSVP, Handlebars));
\ No newline at end of file
......@@ -257,7 +257,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>971.49164.31619.41506</string> </value>
<value> <string>972.32024.53732.34406</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -275,7 +275,7 @@
</tuple>
<state>
<tuple>
<float>1542713467.3</float>
<float>1554257864.46</float>
<string>UTC</string>
</tuple>
</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