Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
slapos
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Douglas
slapos
Commits
c1148f73
Commit
c1148f73
authored
Sep 02, 2015
by
Tristan Cavelier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
monitor: use hal+json
parent
6b911e36
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
71 additions
and
44 deletions
+71
-44
stack/monitor/buildout.cfg
stack/monitor/buildout.cfg
+1
-1
stack/monitor/monitor.js
stack/monitor/monitor.js
+55
-32
stack/monitor/monitor.py.in
stack/monitor/monitor.py.in
+15
-11
No files found.
stack/monitor/buildout.cfg
View file @
c1148f73
...
...
@@ -98,7 +98,7 @@ strip-top-level-dir = true
recipe = hexagonit.recipe.download
url = ${:_profile_base_location_}/${:filename}
download-only = true
md5sum =
f64caed50df8add6a38ce1eac7a61585
md5sum =
8a5af1a03086788006345e27647c2a1d
filename = monitor.py.in
mode = 0644
...
...
stack/monitor/monitor.js
View file @
c1148f73
...
...
@@ -26,6 +26,38 @@
});
}
///////////////////
// tools for HAL //
function
getProperty
(
object
,
path
)
{
if
(
Array
.
isArray
(
path
))
{
while
(
path
.
length
)
{
object
=
object
[
path
.
shift
()];
}
}
else
{
return
object
[
path
];
}
return
object
;
}
function
softGetProperty
(
object
,
path
)
{
try
{
return
getProperty
(
object
,
path
);
}
catch
(
ignored
)
{
return
undefined
;
}
}
function
forceList
(
value
)
{
if
(
Array
.
isArray
(
value
))
{
return
value
;
}
return
[
value
];
}
///////////////////
var
monitor_json_list
=
[];
function
htmlToElementList
(
html
)
{
...
...
@@ -35,24 +67,12 @@
return
div
.
querySelectorAll
(
"
*
"
);
}
function
absoluteUrl
(
url
)
{
/*global URL, location */
try
{
return
new
URL
(
url
,
location
.
href
).
href
;
}
catch
(
e
)
{
return
url
;
}
}
function
resolveUrl
(
firstUrl
)
{
/*global URL */
var
l
=
arguments
.
length
,
i
=
1
,
url
=
""
;
url
=
absoluteUrl
(
firstUrl
);
while
(
i
<
l
)
{
url
=
new
URL
(
arguments
[
i
],
url
).
href
;
i
+=
1
;
}
return
url
;
/*jslint plusplus: true */
/*global URL, location */
var
l
=
arguments
.
length
,
i
=
1
,
url
=
new
URL
(
firstUrl
,
location
.
href
);
while
(
i
<
l
)
{
url
=
new
URL
(
arguments
[
i
++
],
url
);
}
return
url
.
href
;
}
function
escapeHtml
(
html
)
{
...
...
@@ -60,22 +80,25 @@
}
function
loadAndRenderMonitorSection
(
root
,
monitor_dict
,
monitor_url
)
{
if
(
!
monitor_dict
.
service_list
)
{
var
table
,
service_list
=
forceList
(
softGetProperty
(
monitor_dict
,
[
"
_embedded
"
,
"
service
"
]));
if
(
!
service_list
)
{
root
.
textContent
=
""
;
return
;
}
var
table
=
document
.
createElement
(
"
table
"
);
table
=
document
.
createElement
(
"
table
"
);
root
.
appendChild
(
table
);
return
Promise
.
all
(
monitor_dict
.
service_list
.
map
(
function
(
service_dict
)
{
var
href_html_part
=
(
service_dict
.
interface_url
?
"
href=
\"
"
+
escapeHtml
(
service_dict
.
interface_url
)
+
"
\"
"
:
""
),
return
Promise
.
all
(
service_list
.
map
(
function
(
service_dict
)
{
var
interface_url
=
softGetProperty
(
service_dict
,
[
"
_links
"
,
"
interface
"
,
"
href
"
]),
status_url
=
softGetProperty
(
service_dict
,
[
"
_links
"
,
"
status
"
,
"
href
"
]),
href_html_part
=
(
interface_url
?
"
href=
\"
"
+
escapeHtml
(
interface_url
)
+
"
\"
"
:
""
),
title_html_part
=
(
service_dict
.
title
?
escapeHtml
(
service_dict
.
title
)
:
"
Untitled
"
),
row
=
htmlToElementList
(
"
<table><tbody><tr><td><a
"
+
href_html_part
+
"
>
"
+
title_html_part
+
"
</a></td><td>Loading status...</td><td><a
"
+
href_html_part
+
"
><div style=
\"
height: 10mm; width: 10mm; background-color: gray;
\"
></div></a></td></tr></tbody></table>
"
);
table
.
appendChild
(
row
[
2
]);
if
(
!
s
ervice_dict
.
s
tatus_url
)
{
if
(
!
status_url
)
{
row
[
5
].
textContent
=
"
No status
"
;
return
;
}
return
loadJson
(
resolveUrl
(
monitor_url
,
s
ervice_dict
.
s
tatus_url
)).
then
(
function
(
status_dict
)
{
return
loadJson
(
resolveUrl
(
monitor_url
,
status_url
)).
then
(
function
(
status_dict
)
{
if
(
status_dict
.
description
)
{
row
[
2
].
title
=
status_dict
.
description
;
}
...
...
@@ -92,24 +115,24 @@
function
loadAndRenderMonitorJson
(
root
)
{
root
.
textContent
=
"
Loading monitor section...
"
;
return
loadJson
(
"
monitor.json
"
).
then
(
function
(
monitor_dict
)
{
return
loadJson
(
"
monitor.
hal
json
"
).
then
(
function
(
monitor_dict
)
{
monitor_json_list
.
push
(
monitor_dict
);
root
.
innerHTML
=
""
;
var
loading
=
loadAndRenderMonitorSection
(
root
,
monitor_dict
);
if
(
!
monitor_dict
.
monitor_url
_list
)
{
return
loading
;
}
return
Promise
.
all
([
loading
,
Promise
.
all
(
monitor_dict
.
monitor_url_list
.
map
(
function
(
url
)
{
var
loading
=
loadAndRenderMonitorSection
(
root
,
monitor_dict
)
,
related_monitor_list
=
forceList
(
softGetProperty
(
monitor_dict
,
[
"
_links
"
,
"
related_monitor
"
]))
;
if
(
!
related_monitor
_list
)
{
return
loading
;
}
return
Promise
.
all
([
loading
,
Promise
.
all
(
related_monitor_list
.
map
(
function
(
link
)
{
var
div
=
htmlToElementList
(
"
<div>Loading monitor section...</div>
"
)[
0
];
root
.
appendChild
(
div
);
if
(
url
[
url
.
length
-
1
]
!==
"
/
"
)
{
url
+=
"
/
"
;
if
(
link
.
href
[
link
.
href
.
length
-
1
]
!==
"
/
"
)
{
link
.
href
+=
"
/
"
;
}
url
=
resolveUrl
(
url
,
"
monitor.
json
"
);
return
loadJson
(
url
).
catch
(
function
(
reason
)
{
link
.
href
=
resolveUrl
(
link
.
href
,
"
monitor.hal
json
"
);
return
loadJson
(
link
.
href
).
catch
(
function
(
reason
)
{
div
.
textContent
=
(
reason
&&
(
reason
.
name
+
"
:
"
+
reason
.
message
));
}).
then
(
function
(
monitor_dict
)
{
monitor_json_list
.
push
(
monitor_dict
);
div
.
remove
();
return
loadAndRenderMonitorSection
(
root
,
monitor_dict
,
url
);
return
loadAndRenderMonitorSection
(
root
,
monitor_dict
,
link
.
href
);
});
}))]);
});
...
...
stack/monitor/monitor.py.in
View file @
c1148f73
...
...
@@ -26,17 +26,26 @@ def main():
# XXX see old monitor.py.in
# generate monitor.json
monitor_dict = {}
tmp = softConfigGet(config, "monitor", "title")
if tmp:
monitor_dict["title"] = tmp
tmp = softConfigGet(config, "monitor", "monitor-url-list")
if tmp:
monitor_dict["
monitor_url_list"] = tmp.split()
monitor_dict["
_links"] = {"related_monitor": [{"href": url} for url in tmp.split()]}
if service_config_list:
monitor_dict["service_list"] = []
service_list = []
monitor_dict["_embedded"] = {"service": service_list}
for service_config in service_config_list:
service_dict = {}
monitor_dict["service_list"].append(service_dict)
setConfigIfNotEmptyToDict(service_config, "service", "title", service_dict, "title")
service_name = service_dict["service_name"] = service_config.get("service", "name")
service_dict["status_url"] = "/public/%s/status.json" % service_name
service_list.append(service_dict)
service_name = service_dict["id"] = service_config.get("service", "name")
service_dict["_links"] = {"status": {"href": "/public/%s/status.json" % service_name}}
tmp = softConfigGet(service_config, "service", "title")
if tmp:
service_dict["title"] = tmp
tmp = softConfigGet(service_config, "service", "interface-url")
if tmp:
service_dict["_links"]["interface"] = {"href": tmp}
with open(config.get("monitor", "monitor-json"), "w") as fp:
json.dump(monitor_dict, fp)
# create symlinks from service configurations
...
...
@@ -59,11 +68,6 @@ def softConfigGet(config, *args, **kwargs):
except (ConfigParser.NoOptionError, ConfigParser.NoSectionError):
return None
def setConfigIfNotEmptyToDict(config, section, option, dyct, key):
tmp = softConfigGet(config, section, option)
if tmp:
dyct[key] = tmp
def createSymlinksFromConfig(destination_folder_config_tuple, source_list_config_tuple):
destination_folder = softConfigGet(*destination_folder_config_tuple)
if destination_folder:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment