Commit 4af007fa authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_jio: Let the API provide the monitor_url

  This makes monitor url, JS agnostic and part of API.
  This also places the real url (bookmarkable) on the gadget link, not requiring to rely on master to redirect.
parent f84f7b57
......@@ -206,11 +206,11 @@
class: "ui-btn ui-btn-icon-left ui-icon-desktop"
};
if (result && result.portal_type && result.portal_type === "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';
if (result && 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 = 'Compute Node';
......@@ -250,13 +250,7 @@
result.portal_type === "Software Instance" ||
result.portal_type === "Slave Instance"
)) {
monitor_url = 'https://monitor.app.officejs.com/#/' +
'?page=ojsm_dispatch&query=' +
'portal_type%3A%22Software%20Instance%22%20AND%20reference%3A%22' +
result.reference + '%22';
if (result && result.news) {
status_class = getInstanceStatus(result.news);
}
status_class = getInstanceStatus(result);
right_class = "ui-btn-hide";
if (status_class === 'ui-btn-is-slave') {
status_class = 'ui-btn-no-data ui-btn-color-white';
......@@ -278,19 +272,6 @@
status_class = getInstanceTreeStatus(result.news);
}
// it should verify if the monitor-base-url is ready.
for (i in result.connection_parameter_list) {
if (result.connection_parameter_list.hasOwnProperty(i)) {
if (result.connection_parameter_list[i].connection_key ===
"monitor-setup-url") {
monitor_url = result.connection_parameter_list[i].connection_value;
}
}
}
if (monitor_url === "") {
monitor_url = 'https://monitor.app.officejs.com/#/' +
'?page=ojsm_dispatch&query=portal_type' +
'%3A%22Instance%20Tree%22%20AND%20title%3A' + result.title;
}
right_class = "ui-btn-hide";
if (status_class === 'ui-btn-is-slave') {
status_class = 'ui-btn-no-data ui-btn-color-white';
......@@ -307,8 +288,6 @@
main_link_configuration_dict.text = 'Instance';
}
} else {
monitor_url = gadget.state.jio_key + '/Base_redirectToMonitor';
main_link_configuration_dict.href = monitor_url;
main_link_configuration_dict.target = "_target";
main_link_configuration_dict.text = 'Compute Node';
......@@ -351,7 +330,9 @@
if (gadget.state.jio_key) {
return gadget.jio_get(gadget.state.jio_key)
.push(function (result) {
return gadget.changeState(result);
var state_dict = result.news || {};
state_dict.jio_key = gadget.state.jio_key;
return gadget.changeState(state_dict);
});
}
}, 300000)
......
......@@ -274,7 +274,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1001.20643.53333.20275</string> </value>
<value> <string>1001.50668.64434.580</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -292,7 +292,7 @@
</tuple>
<state>
<tuple>
<float>1656964043.27</float>
<float>1658520198.62</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -10,4 +10,7 @@ for compute_node in compute_node_list:
compute_partition_dict[compute_node.getReference()] = news_dict["partition"]
return {"compute_node": compute_node_dict,
"partition": compute_partition_dict}
"partition": compute_partition_dict,
"reference": context.getReference(),
"portal_type": context.getPortalType(),
"monitor_url": context.Base_getStatusMonitorUrl()}
base_url = 'https://monitor.app.officejs.com/#/?page=ojsm_dispatch&query=portal_type:"Software Instance" AND '
if context.getPortalType() == "Organisation":
compute_node_reference = ",".join([ '"' + i.getReference() + '"' for i in context.Organisation_getComputeNodeTrackingList()])
return base_url + "aggregate_reference:(%s)" % compute_node_reference
if context.getPortalType() == "Project":
compute_node_reference = ",".join([ '"' + i.getReference() + '"' for i in context.Project_getComputeNodeTrackingList()])
return base_url + "aggregate_reference:(%s)" % compute_node_reference
if context.getPortalType() == "Computer Network":
compute_node_reference = ",".join([ '"' + i.getReference() + '"' for i in context.getSubordinationRelatedValueList(portal_type="Compute Node")])
return base_url + "aggregate_reference:(%s)" % compute_node_reference
if context.getPortalType() == "Instance Tree":
for connection_parameter in context.InstanceTree_getConnectionParameterList():
if connection_parameter['connection_key'] == "monitor-setup-url":
return context.REQUEST.RESPONSE.redirect(connection_parameter['connection_key'])
base_url = 'https://monitor.app.officejs.com/#/?page=ojsm_dispatch&query=portal_type:"Instance Tree" AND '
return base_url + "title:(%s)" % context.getTitle()
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()
......@@ -54,7 +54,7 @@
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_redirectToMonitor</string> </value>
<value> <string>Base_getStatusMonitorUrl</string> </value>
</item>
</dictionary>
</pickle>
......
base_url = 'https://monitor.app.officejs.com/#/?page=ojsm_dispatch&query=portal_type:"Software Instance" AND '
if context.getPortalType() == "Organisation":
compute_node_reference = ",".join([ '"' + i.getReference() + '"' for i in context.Organisation_getComputeNodeTrackingList()])
return context.REQUEST.RESPONSE.redirect(base_url + "aggregate_reference:(%s)" % compute_node_reference)
if context.getPortalType() == "Project":
compute_node_reference = ",".join([ '"' + i.getReference() + '"' for i in context.Project_getComputeNodeTrackingList()])
return context.REQUEST.RESPONSE.redirect(base_url + "aggregate_reference:(%s)" % compute_node_reference)
......@@ -13,7 +13,8 @@ def get_compute_partition_dict(reference):
return {"compute_node": compute_node_dict,
"partition": compute_partition_dict,
"portal_type": compute_node_dict['portal_type'],
"reference": compute_node_dict['reference']}
"reference": compute_node_dict['reference'],
"monitor_url": context.Base_getStatusMonitorUrl()}
# Use Cache here, at least transactional one.
return get_compute_partition_dict(context.getReference())
......@@ -3,6 +3,7 @@ news_dict = {
"portal_type": context.getPortalType(),
"reference": context.getReference(),
"title": context.getTitle(),
"monitor_url": context.Base_getStatusMonitorUrl(),
"instance" : []}
if context.getSlapState() == 'stop_requested':
......
......@@ -7,6 +7,7 @@ if portal_type == "Slave Instance":
return {
"user": "SlapOS Master",
"text": "#nodata is a slave %s" % context.getReference(),
"monitor_url": context.Base_getStatusMonitorUrl(),
"is_slave": 1
}
......@@ -15,6 +16,7 @@ if portal_type == "Software Instance" and slap_state == "stop_requested":
return {
"user": "SlapOS Master",
"text": "#nodata is an stopped instance %s" % context.getReference(),
"monitor_url": context.Base_getStatusMonitorUrl(),
"is_stopped": 1
}
......@@ -22,7 +24,10 @@ if portal_type == "Software Instance" and slap_state == "destroy_requested":
return {
"user": "SlapOS Master",
"text": "#nodata is an destroyed instance %s" % context.getReference(),
"monitor_url": context.Base_getStatusMonitorUrl(),
"is_destroyed": 1
}
return context.getAccessStatus()
news_dict = context.getAccessStatus()
news_dict["monitor_url"] = context.Base_getStatusMonitorUrl()
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