Commit 98f677e6 authored by Romain Courteaud's avatar Romain Courteaud 🐙

slapos_jio: status

parent aad1fd71
/*globals window, rJS, Handlebars*/ /*globals window, rJS, domsugar*/
/*jslint indent: 2, nomen: true, maxlen: 80*/ /*jslint indent: 2, nomen: true, maxlen: 80*/
(function (window, rJS, Handlebars) { (function (window, rJS, domsugar) {
"use strict"; "use strict";
var gadget_klass = rJS(window), var STATUS_ERROR = 'ui-btn-error',
inline_status_source = gadget_klass.__template_element STATUS_WARNING = 'ui-btn-warning',
.getElementById("inline-status-template") STATUS_NODATA = 'ui-btn-no-data',
.innerHTML, STATUS_UNHANDLED = 'XXX',
inline_status_template = Handlebars.compile(inline_status_source); STATUS_OK = 'ui-btn-ok';
function checkComputeNodeStatus(options) { function checkComputeNodeStatus(compute_node_news_dict) {
if (!options || !options.news || !options.news.text) { if (compute_node_news_dict.no_data) {
return 'ui-btn-no-data'; return STATUS_NODATA;
} }
if (options.news.text.startsWith("#access")) { if (compute_node_news_dict.text.startsWith("#access")) {
if (options.news.no_data_since_15_minutes) { if (compute_node_news_dict.no_data_since_15_minutes) {
return 'ui-btn-error'; return STATUS_ERROR;
} }
if (options.news.no_data_since_5_minutes) { if (compute_node_news_dict.no_data_since_5_minutes) {
return 'ui-btn-warning'; return STATUS_WARNING;
} }
return 'ui-btn-ok'; return STATUS_OK;
} }
if (options.news.no_data) { return STATUS_UNHANDLED;
return 'ui-btn-no-data';
}
return 'ui-btn-error';
} }
function checkComputePartitionStatus(options) { function checkComputePartitionStatus(partition_news_dict_dict) {
var message, var key,
compute_partition,
partition_class = 'ui-btn-ok',
error_amount = 0, error_amount = 0,
total_amount = 0; partition_amount = 0;
if (!options || !options.compute_partition_news) {
return 'ui-btn-no-data';
}
for (compute_partition in options.compute_partition_news) { for (key in partition_news_dict_dict) {
if (options.compute_partition_news.hasOwnProperty(compute_partition) && if (partition_news_dict_dict.hasOwnProperty(key)) {
options.compute_partition_news[compute_partition].text) { partition_amount += 1;
message = options.compute_partition_news[compute_partition].text; if (partition_news_dict_dict.text &&
if (message.startsWith("#error")) { partition_news_dict_dict.text.startWith('#error')) {
partition_class = 'ui-btn-warning';
error_amount += 1; error_amount += 1;
} }
total_amount += 1;
if ((error_amount > 0) && (error_amount < total_amount)) {
// No need to continue the result will be a warnning
return partition_class;
} }
} }
if (partition_amount === 0) {
return STATUS_NODATA;
} }
if (total_amount === 0) { if (0 < error_amount) {
return 'ui-btn-no-data'; if (error_amount < partition_amount) {
return STATUS_WARNING;
} }
return STATUS_ERROR;
if (error_amount === total_amount) {
// No need to continue the result will be a warnning
return 'ui-btn-error';
} }
return partition_class; return STATUS_OK;
} }
function renderStatusxxx(result) { function renderStatus(status_dict) {
var monitor_url, console.log(status_dict);
status_class = 'ui-btn-no-data', var compute_node_status,
status_title = 'Compute Node', partition_status;
right_title = 'Partitions',
right_class = 'ui-btn-no-data',
status_style = '',
right_style = '';
if (result && result.news && result.news.compute_node) { if (status_dict.compute_node_news_dict) {
status_class = checkComputeNodeStatus({news: result.news.compute_node}); compute_node_status = checkComputeNodeStatus(
} status_dict.compute_node_news_dict
if ((status_class === 'ui-btn-error') ||
(status_class === 'ui-btn-no-data')) {
right_class = status_class;
} else {
if (result && result.news && result.news.partition) {
right_class = checkComputePartitionStatus(
{compute_partition_news: result.news.partition}
); );
if ((compute_node_status === STATUS_OK) ||
(compute_node_status === STATUS_WARNING)) {
partition_status = STATUS_NODATA;
if (status_dict.partition_news_dict_dict) {
// Check if we have info related to the partition
partition_status = checkComputePartitionStatus(
status_dict.partition_news_dict_dict
);
}
return [
domsugar('div', {
'class': 'ui-block-a ui-bar ui-corner-all first-child ' +
'ui-btn ui-btn-icon-left ui-icon-desktop ' +
compute_node_status,
style: 'width:50%',
text: 'Compute Node'
}),
domsugar('div', {
'class': 'ui-block-c ui-bar ui-corner-all last-child ' +
'ui-btn ui-btn-icon-left ui-icon-desktop ' +
compute_node_status,
style: 'width:50%',
text: 'Partitions'
})
];
} }
if (compute_node_status !== STATUS_UNHANDLED) {
return [
domsugar('div', {
'class': 'ui-block-a ui-bar ui-corner-all first-child ' +
'ui-btn ui-btn-icon-left ui-icon-desktop ' +
partition_status,
text: 'Compute Node'
})
];
} }
monitor_url = 'https://monitor.app.officejs.com/#/' +
'?page=ojsm_dispatch&query=portal_type%3A%22Software%20Instance%22%20' +
'AND%20aggregate_reference%3A%22' + result.reference + '%22';
return {html: inline_status_template({
monitor_url: monitor_url,
status_class: status_class,
status_title: status_title,
status_style: status_style,
right_class: right_class,
right_title: right_title,
right_style: right_style
})};
} }
function renderStatus(status_dict) {
console.log(status_dict);
/*
if (status_dict.compute_node) {
status_class = checkComputeNodeStatus({news: status_dict.compute_node});
// Check if we have info related to the partition
}
*/
// By default, display the full parameters, // By default, display the full parameters,
// as it means the gadget does not support the configuration // as it means the gadget does not support the configuration
// but the parameters may contain usefull stuff for the user // but the parameters may contain usefull stuff for the user
...@@ -121,7 +109,7 @@ ...@@ -121,7 +109,7 @@
]; ];
} }
gadget_klass rJS(window)
.declareAcquiredMethod("jio_get", "jio_get") .declareAcquiredMethod("jio_get", "jio_get")
.declareMethod("getContent", function () { .declareMethod("getContent", function () {
...@@ -130,13 +118,14 @@ ...@@ -130,13 +118,14 @@
.onLoop(function () { .onLoop(function () {
var gadget = this; var gadget = this;
console.log('STATUS.onLoop1', gadget.state);
if (gadget.state.jio_key) { if (gadget.state.jio_key) {
return gadget.jio_get(gadget.state.jio_key) return gadget.jio_get(gadget.state.jio_key)
.push(function (result) { .push(function (result) {
console.log('STATUS.onLoop', result); console.log('STATUS.onLoop2', result);
return gadget.changeState({ return gadget.changeState({
compute_node: JSON.stringify(result.news.compute_node), compute_node_news_dict: JSON.stringify(result.news.compute_node),
partition: JSON.stringify(result.news.partition) partition_news_dict_dict: JSON.stringify(result.news.partition)
}); });
}); });
} }
...@@ -145,8 +134,10 @@ ...@@ -145,8 +134,10 @@
.declareMethod("render", function (options) { .declareMethod("render", function (options) {
console.log('STATUS.render', options); console.log('STATUS.render', options);
return this.changeState({ return this.changeState({
compute_node: JSON.stringify(options.compute_node), compute_node_news_dict: JSON.stringify(options.compute_node),
partition: JSON.stringify(options.partition), partition_news_dict_dict: JSON.stringify(
options.partition
),
jio_key: options.value, jio_key: options.value,
reference: options.reference reference: options.reference
}); });
...@@ -155,8 +146,9 @@ ...@@ -155,8 +146,9 @@
.onStateChange(function (modification_dict) { .onStateChange(function (modification_dict) {
console.log('STATUS.onStateChange', modification_dict); console.log('STATUS.onStateChange', modification_dict);
domsugar(this.element, renderStatus({ domsugar(this.element, renderStatus({
compute_node: JSON.parse(this.state.compute_node), compute_node_news_dict: JSON.parse(this.state.compute_node_news_dict),
partition: JSON.parse(this.state.partition), partition_news_dict_dict:
JSON.parse(this.state.partition_news_dict_dict)
})); }));
}); });
}(window, rJS, Handlebars)); }(window, rJS, domsugar));
\ No newline at end of file \ No newline at end of file
...@@ -273,7 +273,7 @@ ...@@ -273,7 +273,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>995.21748.56330.51234</string> </value> <value> <string>995.25882.22519.23739</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -291,7 +291,7 @@ ...@@ -291,7 +291,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1633708139.98</float> <float>1633956166.82</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
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