Commit 87c2783b authored by Rafael Monnerat's avatar Rafael Monnerat

Remove massive computer partition status calculation

See merge request nexedi/slapos.core!550
parents cd8cff8f a23b5ca0
......@@ -131,10 +131,6 @@ class SlapOSComputeNodeMixin(object):
# called on site
pass
# Also update cache for News Dict, so it speed up access of this UI.
key = '%s_partition_news' % self.getReference()
self._getCachedComputePartitionNewsDict(key, refresh_etag)
def _calculateRefreshEtag(self):
# check max indexation timestamp
# it is unlikely to get an empty catalog
......@@ -333,62 +329,4 @@ class SlapOSComputeNodeMixin(object):
raise ValueError('Wrong list of software releases on %r: %s' % (
self.getReference(), ', '.join([q.getRelativeUrl() for q \
in software_installation_list])
))
def getComputePartitionNewsDict(self):
key = '%s_partition_news' % self.getReference()
cache_plugin = self._getCachePlugin()
refresh_etag = self._calculateRefreshEtag()
try:
entry = cache_plugin.get(key, DEFAULT_CACHE_SCOPE)
except KeyError:
entry = None
if entry is not None and isinstance(entry.getValue(), dict):
cached_dict = entry.getValue()
cached_etag = cached_dict.get('refresh_etag', None)
if (refresh_etag != cached_etag):
return self._getCachedComputePartitionNewsDict(key, refresh_etag)
else:
return cached_dict.get('data')
return self._getCachedComputePartitionNewsDict(key, refresh_etag)
def _getCachedComputePartitionNewsDict(self, key, refresh_etag):
unrestrictedSearchResults = self.getPortalObject().portal_catalog.unrestrictedSearchResults
compute_partition_uid_list = [x.uid for x in unrestrictedSearchResults(
parent_uid=self.getUid(),
validation_state="validated",
portal_type="Compute Partition")]
software_instance_list = unrestrictedSearchResults(
portal_type="Software Instance",
default_aggregate_uid=compute_partition_uid_list,
validation_state="validated",
group_by_list=['default_aggregate_uid'],
select_list=['default_aggregate_uid', 'default_aggregate_title']
)
compute_partition_dict = { }
for software_instance in software_instance_list:
compute_partition_dict[software_instance.default_aggregate_title] = software_instance.getAccessStatus()
try:
self._getCachePlugin().set(key, DEFAULT_CACHE_SCOPE,
dict (
time=time.time(),
refresh_etag=refresh_etag,
data=compute_partition_dict
),
cache_duration=self.getPortalObject().portal_caches\
.getRamCacheRoot().get('compute_node_information_cache_factory'\
).cache_duration
)
except (Unauthorized, IndexError):
# XXX: Unauthorized hack. Race condition of not ready setup delivery which provides
# security information shall not make this method fail, as it will be
# called later anyway
# Note: IndexError ignored, as it happend in case if full reindex is
# called on site
pass
return compute_partition_dict
\ No newline at end of file
))
\ No newline at end of file
......@@ -16,12 +16,8 @@
clear: left;
}
.ui-block-50 {
width: 50% !important;
}
.ui-btn-hide {
display: none !important;
.ui-block {
width: 100%
}
.ui-bar {
......
......@@ -244,7 +244,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1001.40386.24679.24320</string> </value>
<value> <string>1009.35848.48037.15820</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -264,7 +264,7 @@
</tuple>
<state>
<tuple>
<float>1658172898.38</float>
<float>1688482381.84</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -14,15 +14,10 @@
</head>
<body>
<div class="ui-block-a ui-block-50 main-status">
<div class="ui-block-a ui-block main-status">
<div class="ui-bar ui-corner-all first-child ui-btn-no-data">
<a class="ui-btn ui-btn-icon-left ui-icon-spinner ui-btn-color-white"> Node </a>
</div>
</div>
<div class="ui-block-c ui-block-50 sub-status">
<div class="ui-bar ui-corner-all first-child ui-btn-no-data">
<a class="ui-btn ui-btn-icon-left ui-icon-spinner ui-btn-color-white"> Partitions </a>
</div>
</div>
</body>
</html>
\ No newline at end of file
......@@ -282,7 +282,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1001.26171.19762.42854</string> </value>
<value> <string>1009.35843.10522.38024</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -302,7 +302,7 @@
</tuple>
<state>
<tuple>
<float>1657906237.75</float>
<float>1688481140.05</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -77,42 +77,6 @@
return 'ui-btn-error';
}
function getComputePartitionStatus(options) {
var message,
compute_partition,
partition_class = 'ui-btn-ok',
error_amount = 0,
total_amount = 0;
if (!options) {
return 'ui-btn-no-data';
}
for (compute_partition in options) {
if (options.hasOwnProperty(compute_partition) &&
options[compute_partition].text) {
message = options[compute_partition].text;
if (message.startsWith("#error")) {
partition_class = 'ui-btn-warning';
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 (!total_amount) {
return 'ui-btn-no-data';
}
if (error_amount === total_amount) {
return 'ui-btn-error';
}
return partition_class;
}
function getSoftwareInstallationStatus(options) {
if ((!options) || (options && !options.text)) {
return 'ui-btn-no-data';
......@@ -163,81 +127,26 @@
return status;
}
function getComputePartitionStatusList(options) {
var compute_node_reference,
status = 'ui-btn-no-data',
previous_status = "START";
for (compute_node_reference in options.partition) {
if (options.partition.hasOwnProperty(compute_node_reference)) {
status = getComputePartitionStatus(
options.partition[compute_node_reference]
);
if (previous_status === "START") {
previous_status = status;
}
if (status === 'ui-btn-warning') {
// XXX Drop warning
return status;
}
if (previous_status !== status) {
if ((previous_status === 'ui-btn-error') &&
(status === 'ui-btn-ok')) {
return 'ui-btn-warning';
}
if ((status === 'ui-btn-error') &&
(previous_status === 'ui-btn-ok')) {
return 'ui-btn-warning';
}
if (status === 'ui-btn-no-data') {
status = previous_status;
}
}
}
}
return status;
}
function getStatus(gadget, result) {
var i, status_class = 'ui-btn-no-data',
right_class = 'ui-btn-no-data',
var status_class = 'ui-btn-no-data',
main_status_div = gadget.element.querySelector(".main-status"),
sub_status_div = gadget.element.querySelector(".sub-status"),
monitor_url = '',
main_link_configuration_dict = {
class: "ui-btn ui-btn-icon-left ui-icon-desktop"
},
sub_link_configuration_dict = {
class: "ui-btn ui-btn-icon-left ui-icon-desktop"
};
if (result && result.monitor_url) {
monitor_url = result.monitor_url
monitor_url = result.monitor_url;
}
if (result && result.portal_type && result.portal_type === "Compute Node") {
main_link_configuration_dict.href = monitor_url;
main_link_configuration_dict.target = "_target";
main_link_configuration_dict.text = 'Node';
sub_link_configuration_dict.href = monitor_url;
sub_link_configuration_dict.target = "_target";
sub_link_configuration_dict.text = 'Partitions';
if (result && result.compute_node) {
status_class = getComputeNodeStatus(result.compute_node);
}
if ((status_class === 'ui-btn-error') ||
(status_class === 'ui-btn-no-data')) {
right_class = status_class;
} else {
if (result && result.partition) {
right_class = getComputePartitionStatus(result.partition);
}
}
main_link_configuration_dict.class = "ui-btn ui-btn-icon-left";
status_class = getComputeNodeStatus(result);
} else if (result && result.portal_type &&
result.portal_type === "Software Installation") {
status_class = getSoftwareInstallationStatus(result);
main_link_configuration_dict.text = "Installation";
right_class = "ui-btn-hide";
if (status_class === "ui-btn-is-building") {
main_link_configuration_dict.text = "Building";
status_class = "ui-btn-no-data";
......@@ -252,7 +161,6 @@
result.portal_type === "Slave Instance"
)) {
status_class = getInstanceStatus(result);
right_class = "ui-btn-hide";
if (status_class === 'ui-btn-is-slave') {
status_class = 'ui-btn-color-white';
main_link_configuration_dict.text = 'Slave';
......@@ -274,7 +182,6 @@
result.portal_type === "Instance Tree") {
status_class = getInstanceTreeStatus(result);
// it should verify if the monitor-base-url is ready.
right_class = "ui-btn-hide";
if (status_class === 'ui-btn-is-slave') {
status_class = 'ui-btn-color-white';
main_link_configuration_dict.text = 'Slave Only';
......@@ -293,40 +200,18 @@
main_link_configuration_dict.text = 'Instance';
}
} else {
main_link_configuration_dict.href = monitor_url;
main_link_configuration_dict.target = "_target";
main_link_configuration_dict.text = 'Node';
sub_link_configuration_dict.href = monitor_url;
sub_link_configuration_dict.target = "_target";
sub_link_configuration_dict.text = 'Partitions';
main_link_configuration_dict.class = "ui-btn ui-btn-icon-left";
status_class = getComputeNodeStatusList(result);
if ((status_class === 'ui-btn-error') ||
(status_class === 'ui-btn-no-data')) {
right_class = status_class;
} else {
right_class = getComputePartitionStatusList(result);
}
}
main_link_configuration_dict.text = ' ' + main_link_configuration_dict.text;
sub_link_configuration_dict.text = ' ' + sub_link_configuration_dict.text;
domsugar(main_status_div.querySelector('div'),
{
class: "ui-bar ui-corner-all first-child " + status_class
}, [
domsugar("a", main_link_configuration_dict)
]);
domsugar(sub_status_div.querySelector('div'),
{
class: "ui-bar ui-corner-all last-child " + right_class
}, [
domsugar("a", sub_link_configuration_dict)
]);
if (right_class === 'ui-btn-hide') {
// expand main button to use the space
main_status_div.className = "ui-block-a ui-block main-status";
}
return gadget;
}
......@@ -338,7 +223,8 @@
.onLoop(function () {
var gadget = this;
if (typeof gadget.state.jio_key === 'string' && gadget.state.jio_key !== '') {
if (typeof gadget.state.jio_key === 'string' &&
gadget.state.jio_key !== '') {
return gadget.jio_get(gadget.state.jio_key)
.push(function (result) {
var state_dict = result.news || {};
......
......@@ -278,7 +278,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1006.58340.40727.23620</string> </value>
<value> <string>1009.34688.1170.33860</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -298,7 +298,7 @@
</tuple>
<state>
<tuple>
<float>1680031759.77</float>
<float>1688481138.46</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -3,14 +3,9 @@ if REQUEST is not None:
raise Unauthorized
node_dict = {}
partition_dict = {}
for compute_node in compute_node_list:
reference = compute_node.getReference()
node_dict[reference] = compute_node.getAccessStatus()
partition_dict[reference] = compute_node.getComputePartitionNewsDict()
node_dict[compute_node.getReference()] = compute_node.getAccessStatus()
return {"compute_node": node_dict,
"partition": partition_dict,
"reference": context.getReference(),
"portal_type": context.getPortalType(),
"monitor_url": context.Base_getStatusMonitorUrl(compute_node_list=compute_node_list)}
"portal_type": context.getPortalType()}
base_url = 'https://monitor.app.officejs.com/#/?page=ojsm_dispatch&query=portal_type:"Software Instance" AND '
if context.getPortalType() in ["Organisation", "Computer Network"]:
if compute_node_list is None:
return ""
compute_node_reference = ",".join([ '"' + i.getReference() + '"' for i in compute_node_list])
return base_url + "aggregate_reference:(%s)" % compute_node_reference
if context.getPortalType() == "Instance Tree":
for connection_parameter in context.InstanceTree_getConnectionParameterList(raw=True):
if connection_parameter['connection_key'] == "monitor-setup-url":
......@@ -15,6 +9,3 @@ if context.getPortalType() == "Instance Tree":
if context.getPortalType() in ["Software Instance", "Slave Instance"]:
return base_url + "reference:%s" % context.getReference()
if context.getPortalType() == "Compute Node":
return base_url + "aggregate_reference:%s" % context.getReference()
......@@ -2,14 +2,4 @@ from zExceptions import Unauthorized
if REQUEST is not None:
raise Unauthorized
def get_compute_partition_dict():
compute_node_dict = context.getAccessStatus()
compute_partition_dict = context.getComputePartitionNewsDict()
return {"compute_node": compute_node_dict,
"partition": compute_partition_dict,
"portal_type": compute_node_dict['portal_type'],
"reference": compute_node_dict['reference'],
"monitor_url": context.Base_getStatusMonitorUrl()}
return get_compute_partition_dict()
return context.getAccessStatus()
......@@ -154,12 +154,12 @@
</tr>
<tr>
<td>waitForElementPresent</td>
<td>//div[contains(@class, 'main-status')]//div[contains(@class, 'ui-btn-ok')]//a[contains(@href, 'COMP-') and contains(text(), 'Node')]</td>
<td>//div[contains(@class, 'main-status')]//div[contains(@class, 'ui-btn-ok')]//a[contains(text(), 'Node')]</td>
<td></td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>//div[contains(@class, 'main-status')]//div[contains(@class, 'ui-btn-ok')]//a[contains(@href, 'COMP-') and contains(text(), 'Node')]</td>
<td>//div[contains(@class, 'main-status')]//div[contains(@class, 'ui-btn-ok')]//a[contains(text(), 'Node')]</td>
<td></td>
</tr>
<tr>
......@@ -206,12 +206,12 @@
<tr>
<td>waitForElementPresent</td>
<td>//div[contains(@class, 'main-status')]//div[contains(@class, 'ui-btn-ok')]//a[contains(@href, 'COMP-') and contains(text(), 'Node')]</td>
<td>//div[contains(@class, 'main-status')]//div[contains(@class, 'ui-btn-ok')]//a[contains(text(), 'Node')]</td>
<td></td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>//div[contains(@class, 'main-status')]//div[contains(@class, 'ui-btn-ok')]//a[contains(@href, 'COMP-') and contains(text(), 'Node')]</td>
<td>//div[contains(@class, 'main-status')]//div[contains(@class, 'ui-btn-ok')]//a[contains(text(), 'Node')]</td>
<td></td>
</tr>
......@@ -227,12 +227,12 @@
</tr>
<tr>
<td>waitForElementPresent</td>
<td>//td//div[contains(@class, 'main-status')]//div[contains(@class, 'ui-btn-ok')]//a[contains(@href, 'COMP-') and contains(text(), 'Node')]</td>
<td>//td//div[contains(@class, 'main-status')]//div[contains(@class, 'ui-btn-ok')]//a[contains(text(), 'Node')]</td>
<td></td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>//td//div[contains(@class, 'main-status')]//div[contains(@class, 'ui-btn-ok')]//a[contains(@href, 'COMP-') and contains(text(), 'Node')]</td>
<td>//td//div[contains(@class, 'main-status')]//div[contains(@class, 'ui-btn-ok')]//a[contains(text(), 'Node')]</td>
<td></td>
</tr>
......
......@@ -224,12 +224,12 @@
</tr>
<tr>
<td>waitForElementPresent</td>
<td>//div[contains(@class, 'main-status')]//div[contains(@class, 'ui-btn-ok')]//a[contains(@href, 'COMP-') and contains(text(), 'Node')]</td>
<td>//div[contains(@class, 'main-status')]//div[contains(@class, 'ui-btn-ok')]//a[contains(text(), 'Node')]</td>
<td></td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>//div[contains(@class, 'main-status')]//div[contains(@class, 'ui-btn-ok')]//a[contains(@href, 'COMP-') and contains(text(), 'Node')]</td>
<td>//div[contains(@class, 'main-status')]//div[contains(@class, 'ui-btn-ok')]//a[contains(text(), 'Node')]</td>
<td></td>
</tr>
<tr>
......@@ -245,12 +245,12 @@
<tr>
<td>waitForElementPresent</td>
<td>//div[contains(@class, 'main-status')]//div[contains(@class, 'ui-btn-ok')]//a[contains(@href, 'COMP-') and contains(text(), 'Node')]</td>
<td>//div[contains(@class, 'main-status')]//div[contains(@class, 'ui-btn-ok')]//a[contains(text(), 'Node')]</td>
<td></td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>//div[contains(@class, 'main-status')]//div[contains(@class, 'ui-btn-ok')]//a[contains(@href, 'COMP-') and contains(text(), 'Node')]</td>
<td>//div[contains(@class, 'main-status')]//div[contains(@class, 'ui-btn-ok')]//a[contains(text(), 'Node')]</td>
<td></td>
</tr>
<tr>
......
......@@ -179,23 +179,23 @@
<tr>
<td>waitForElementPresent</td>
<td>//div[contains(@class, 'main-status')]//div[contains(@class, 'ui-btn-ok')]//a[contains(@href, 'COMP-') and contains(text(), 'Node')]</td>
<td>//div[contains(@class, 'main-status')]//div[contains(@class, 'ui-btn-ok')]//a[contains(text(), 'Node')]</td>
<td></td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>//div[contains(@class, 'main-status')]//div[contains(@class, 'ui-btn-ok')]//a[contains(@href, 'COMP-') and contains(text(), 'Node')]</td>
<td>//div[contains(@class, 'main-status')]//div[contains(@class, 'ui-btn-ok')]//a[contains(text(), 'Node')]</td>
<td></td>
</tr>
<tr>
<td>waitForElementPresent</td>
<td>//div[contains(@class, 'leaflet-pane')]//div[contains(@class, 'ui-btn-ok')]//a[contains(@href, 'COMP-') and contains(text(), 'Node')]</td>
<td>//div[contains(@class, 'leaflet-pane')]//div[contains(@class, 'ui-btn-ok')]//a[contains(text(), 'Node')]</td>
<td></td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>//div[contains(@class, 'leaflet-pane')]//div[contains(@class, 'ui-btn-ok')]//a[contains(@href, 'COMP-') and contains(text(), 'Node')]</td>
<td>//div[contains(@class, 'leaflet-pane')]//div[contains(@class, 'ui-btn-ok')]//a[contains(text(), 'Node')]</td>
<td></td>
</tr>
......@@ -212,34 +212,34 @@
<tr>
<td>waitForElementPresent</td>
<td>//div[contains(@class, 'main-status')]//div[contains(@class, 'ui-btn-ok')]//a[contains(@href, 'COMP-') and contains(text(), 'Node')]</td>
<td>//div[contains(@class, 'main-status')]//div[contains(@class, 'ui-btn-ok')]//a[contains(text(), 'Node')]</td>
<td></td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>//div[contains(@class, 'main-status')]//div[contains(@class, 'ui-btn-ok')]//a[contains(@href, 'COMP-') and contains(text(), 'Node')]</td>
<td>//div[contains(@class, 'main-status')]//div[contains(@class, 'ui-btn-ok')]//a[contains(text(), 'Node')]</td>
<td></td>
</tr>
<tr>
<td>waitForElementPresent</td>
<td>//div[contains(@class, 'leaflet-pane')]//div[contains(@class, 'ui-btn-ok')]//a[contains(@href, 'COMP-') and contains(text(), 'Node')]</td>
<td>//div[contains(@class, 'leaflet-pane')]//div[contains(@class, 'ui-btn-ok')]//a[contains(text(), 'Node')]</td>
<td></td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>//div[contains(@class, 'leaflet-pane')]//div[contains(@class, 'ui-btn-ok')]//a[contains(@href, 'COMP-') and contains(text(), 'Node')]</td>
<td>//div[contains(@class, 'leaflet-pane')]//div[contains(@class, 'ui-btn-ok')]//a[contains(text(), 'Node')]</td>
<td></td>
</tr>
<!-- Check on listbox -->
<tr>
<td>waitForElementPresent</td>
<td>//td//div[contains(@class, 'main-status')]//div[contains(@class, 'ui-btn-ok')]//a[contains(@href, 'COMP-') and contains(text(), 'Node')]</td>
<td>//td//div[contains(@class, 'main-status')]//div[contains(@class, 'ui-btn-ok')]//a[contains(text(), 'Node')]</td>
<td></td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>//td//div[contains(@class, 'main-status')]//div[contains(@class, 'ui-btn-ok')]//a[contains(@href, 'COMP-') and contains(text(), 'Node')]</td>
<td>//td//div[contains(@class, 'main-status')]//div[contains(@class, 'ui-btn-ok')]//a[contains(text(), 'Node')]</td>
<td></td>
</tr>
......
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