blob: 6a56b2fdd01c02ce946eb53c62819f73c78f8991 [file] [log] [blame]
Pavlin Radoslavovda7ef612013-10-30 16:12:14 -07001package net.onrc.onos.datagrid.web;
2
3import java.util.Collection;
4
5import net.onrc.onos.datagrid.IDatagridService;
6import net.onrc.onos.ofcontroller.topology.TopologyElement;
7import net.onrc.onos.ofcontroller.util.FlowEntry;
8import net.onrc.onos.ofcontroller.util.FlowPath;
9
10import org.restlet.resource.Get;
11import org.restlet.resource.ServerResource;
12import org.slf4j.Logger;
13import org.slf4j.LoggerFactory;
14
15/**
16 * Datagrid REST API implementation: Get the state of a map.
17 *
18 * Valid map names:
19 * - "all" : Get all maps
20 * - "flow" : Get the Flows
21 * - "flow-entry" : Get the Flow Entries
22 * - "topology" : Get the Topology
23 *
Pavlin Radoslavov598635c2013-12-18 19:43:12 -080024 * GET /wm/onos/datagrid/get/map/{map-name}/json
Pavlin Radoslavovda7ef612013-10-30 16:12:14 -070025 */
26public class GetMapResource extends ServerResource {
27 protected final static Logger log = LoggerFactory.getLogger(GetMapResource.class);
28
29 /**
30 * Implement the API.
31 *
32 * @return a string with the state of the map(s).
33 */
34 @Get("json")
35 public String retrieve() {
36 String result = "";
37
38 IDatagridService datagridService =
39 (IDatagridService)getContext().getAttributes().
40 get(IDatagridService.class.getCanonicalName());
41
42 if (datagridService == null) {
43 log.debug("ONOS Datagrid Service not found");
44 return result;
45 }
46
47 // Extract the arguments
48 String mapNameStr = (String)getRequestAttributes().get("map-name");
49
Yuta HIGUCHI5302ddf2014-01-06 12:53:35 -080050 log.debug("Get Datagrid Map: {}", mapNameStr);
Pavlin Radoslavovda7ef612013-10-30 16:12:14 -070051
52 //
53 // Get the Flows
54 //
55 if (mapNameStr.equals("flow") || mapNameStr.equals("all")) {
56 Collection<FlowPath> flowPaths = datagridService.getAllFlows();
57 result += "Flows:\n";
58 for (FlowPath flowPath : flowPaths) {
59 result += flowPath.toString() + "\n";
60 }
61 }
62
63 //
64 // Get the Flow Entries
65 //
66 if (mapNameStr.equals("flow-entry") || mapNameStr.equals("all")) {
67 Collection<FlowEntry> flowEntries = datagridService.getAllFlowEntries();
68 result += "Flow Entries:\n";
69 for (FlowEntry flowEntry : flowEntries) {
70 result += flowEntry.toString() + "\n";
71 }
72 }
73
74 if (mapNameStr.equals("topology") || mapNameStr.equals("all")) {
75 Collection<TopologyElement> topologyElements = datagridService.getAllTopologyElements();
76 result += "Topology:\n";
77 for (TopologyElement topologyElement : topologyElements) {
Pavlin Radoslavovc599a8c2013-10-31 15:46:32 -070078 result += topologyElement.toString() + "\n";
Pavlin Radoslavovda7ef612013-10-30 16:12:14 -070079 }
80 }
81
82 return result;
83 }
84}