[vlma-devel] commit: Add some documentation regarding the Web API + a few fixes. ( Adrien Grand )
git version control
git at videolan.org
Mon Dec 21 10:47:54 CET 2009
vlma | branch: master | Adrien Grand <jpountz at videolan.org> | Mon Dec 21 10:43:28 2009 +0100| [f0b8ff760719f16d70e99296ab3d3bbe85df36bd] | committer: Adrien Grand
Add some documentation regarding the Web API + a few fixes.
> http://git.videolan.org/gitweb.cgi/vlma.git/?a=commit;h=f0b8ff760719f16d70e99296ab3d3bbe85df36bd
---
vlma-watchdog/src/README | 14 ++++++++++++++
vlma-watchdog/src/serialization.py | 14 ++++++++------
vlma-watchdog/src/streamer/api.py | 10 +++++-----
vlma-watchdog/src/streamer/dvblast.py | 4 ++--
vlma-watchdog/src/web.py | 16 ++++++++++------
5 files changed, 39 insertions(+), 19 deletions(-)
diff --git a/vlma-watchdog/src/README b/vlma-watchdog/src/README
new file mode 100644
index 0000000..c4e992a
--- /dev/null
+++ b/vlma-watchdog/src/README
@@ -0,0 +1,14 @@
+Web API
+=======
+
+ 1. GET /order Get the list of orders
+ 2. POST /order/add Add an order
+ 3. POST /order/remove Remove an order
+ 4. GET /streamer Get the list of streamers
+ 5. GET /streamer/{streamer_id} Get a description of streamer {streamer_id}
+ 6. GET /streamer/{streamer_id}/log Get the logs of streamer {streamer_id}
+ 7. GET /streamer/{streamer_id}/metric Get the metrics of streamer {streamer_id}
+ 8. GET /streamer/{streamer_id}/order Get the list of orders of streamer {streamer_id}
+ 9. GET /streamer/{streamer_id}/restart Restart streamer {streamer_id}
+10. GET /system/metric Get the system metrics
+
diff --git a/vlma-watchdog/src/serialization.py b/vlma-watchdog/src/serialization.py
index f0bc980..3ab0440 100644
--- a/vlma-watchdog/src/serialization.py
+++ b/vlma-watchdog/src/serialization.py
@@ -85,17 +85,19 @@ def order_from_xml(s):
if dest_content.nodeType == xml.TEXT_NODE:
continue
nodeName = dest_content.nodeName
- if nodeName == "streaming":
+ if nodeName == "ip":
+ dest.ip = dest_content.childNodes[0].nodeValue
+ elif nodeName == "port":
+ dest.port = int(dest_content.childNodes[0].nodeValue)
+ elif nodeName == "streaming":
streaming = streamer.api.Streaming()
for streaming_content in dest_content.childNodes:
if streaming_content.nodeType == xml.TEXT_NODE:
continue
nodeName = streaming_content.nodeName
nodeValue = streaming_content.childNodes[0].nodeValue
- if nodeName in ["type", "protocol", "mux", "ip"]:
+ if nodeName in ["type", "protocol", "mux"]:
setattr(streaming, nodeName, nodeValue)
- elif nodeName == "port":
- streaming.port = int(nodeValue)
elif nodeName == "loop":
streaming.loop = (nodeValue == "true")
else:
@@ -165,12 +167,12 @@ def order_to_xml(order, writer):
writer.write("<src>%s</src>" %str(src))
for dest in dests:
writer.write("<dest>")
+ writer.write("<ip>%s</ip>" %dest.ip)
+ writer.write("<port>%s</port>" %dest.port)
writer.write("<streaming>")
writer.write("<type>%s</type>" %dest.streaming.type)
writer.write("<protocol>%s</protocol>" %dest.streaming.protocol)
writer.write("<mux>%s</mux>" %dest.streaming.mux)
- writer.write("<ip>%s</ip>" %dest.streaming.ip)
- writer.write("<port>%s</port>" %dest.streaming.port)
if isinstance(order, streamer.api.FilesOrder):
writer.write("<loop>%s</loop>" %(dest.streaming.loop and "true" or "false"))
writer.write("</streaming>")
diff --git a/vlma-watchdog/src/streamer/api.py b/vlma-watchdog/src/streamer/api.py
index d32ee9e..2fba4af 100644
--- a/vlma-watchdog/src/streamer/api.py
+++ b/vlma-watchdog/src/streamer/api.py
@@ -316,20 +316,20 @@ class Dest:
"""A destination. Describes what to do with the stream (how and where to
stream, transcoding, etc.)"""
- def __init__(self):
+ def __init__(self, ip="0.0.0.0", port=1234):
+ self.ip = ip
+ self.port = port
self.streaming = Streaming()
self.transcoding = None
class Streaming:
- """Describes where and how to stream."""
+ """Describes how to stream."""
- def __init__(self, type="broadcast", protocol="udp", mux="raw", ip="0.0.0.0", port=1234):
+ def __init__(self, type="broadcast", protocol="udp", mux="raw"):
self.type = type
self.protocol = protocol
self.mux = mux
- self.ip = ip
- self.port = port
self.loop = False # Only used for files
diff --git a/vlma-watchdog/src/streamer/dvblast.py b/vlma-watchdog/src/streamer/dvblast.py
index 77696b8..4cf98f8 100644
--- a/vlma-watchdog/src/streamer/dvblast.py
+++ b/vlma-watchdog/src/streamer/dvblast.py
@@ -44,9 +44,9 @@ class DVBlast(Streamer):
conf_file = []
for src, dests in order.programs.items():
for dest in dests:
- d = dest.streaming.ip + ":" + str(dest.streaming.port)
+ d = dest.ip + ":" + str(dest.port)
if dest.streaming.protocol == "udp":
- d += "/rtp"
+ d += "/udp"
conf_file += [d, " ", "1", " ", str(src), "\n"]
f = open(self.filename, 'w')
f.writelines(conf_file)
diff --git a/vlma-watchdog/src/web.py b/vlma-watchdog/src/web.py
index 92f1bc3..928550c 100644
--- a/vlma-watchdog/src/web.py
+++ b/vlma-watchdog/src/web.py
@@ -186,7 +186,7 @@ class OrderAddResource(AuthenticationRequiredResource):
buf.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>")
try:
order = serialization.order_from_xml(xml)
- except SerializationExceptio, e:
+ except serialization.SerializationException, e:
error = Error(ErrorCode.BAD_REQUEST, "Mal formated request: %s" %str(e))
request.setResponseCode(error.code.http_status)
serialization.error_to_xml(error, buf)
@@ -229,23 +229,27 @@ class OrderRemoveResource(AuthenticationRequiredResource):
def render_POST_authenticated(self, request):
prepare_xml_response(request)
- order_id = request.args["id"]
- if len["id"] == 0:
+ order_ids = request.args["id"]
+ if len(order_ids) == 0:
error = Error(ErrorCode.BAD_REQUEST, "Missing parameter'id'")
request.setResponseCode(error.code.http_status)
serialization.error_to_xml(error, request)
return
+ buf = StringBuffer()
+ buf.write("<orders>")
for streamer in self.streamers:
for order_id in order_ids:
- order = streamer.orders[order_id]
- if not order is None:
+ if streamer.orders.has_key(order_id):
+ order = streamer.orders[order_id]
+ serialization.order_to_xml(order, buf)
del streamer.orders[order_id]
try:
streamer.stop_streaming(order)
except BaseException, e:
# TODO: what to do?
pass
-
+ buf.write("</orders>")
+ return str(buf)
class StreamersResource(AuthenticationRequiredResource):
More information about the vlma-devel
mailing list