HIGUCHI Yuta | 60a1014 | 2013-06-14 15:50:10 -0700 | [diff] [blame] | 1 | package net.onrc.onos.ofcontroller.flowmanager.web; |
Pavlin Radoslavov | 5ab6851 | 2013-02-18 09:59:33 -0800 | [diff] [blame] | 2 | |
HIGUCHI Yuta | 60a1014 | 2013-06-14 15:50:10 -0700 | [diff] [blame] | 3 | import net.onrc.onos.ofcontroller.flowmanager.IFlowService; |
HIGUCHI Yuta | 356086e | 2013-06-12 15:21:19 -0700 | [diff] [blame] | 4 | import net.onrc.onos.ofcontroller.util.FlowId; |
| 5 | import net.onrc.onos.ofcontroller.util.FlowPath; |
Pavlin Radoslavov | 5ab6851 | 2013-02-18 09:59:33 -0800 | [diff] [blame] | 6 | |
Pavlin Radoslavov | 5ab6851 | 2013-02-18 09:59:33 -0800 | [diff] [blame] | 7 | import org.restlet.resource.Get; |
| 8 | import org.restlet.resource.ServerResource; |
| 9 | import org.slf4j.Logger; |
| 10 | import org.slf4j.LoggerFactory; |
| 11 | |
admin | 944ef4f | 2013-10-08 17:48:37 -0700 | [diff] [blame] | 12 | /** |
HIGUCHI Yuta | eb567aa | 2013-10-08 19:27:35 -0700 | [diff] [blame] | 13 | * Flow Manager REST API implementation: Get a single Flow state. |
admin | 944ef4f | 2013-10-08 17:48:37 -0700 | [diff] [blame] | 14 | * |
| 15 | * The "{flow-id}" request attribute value is the Flow ID of the flow to get: |
| 16 | * |
| 17 | * GET /wm/flow/get/{flow-id}/json |
| 18 | */ |
Pavlin Radoslavov | 5ab6851 | 2013-02-18 09:59:33 -0800 | [diff] [blame] | 19 | public class GetFlowByIdResource extends ServerResource { |
Yuta HIGUCHI | 6ac8d18 | 2013-10-22 15:24:56 -0700 | [diff] [blame] | 20 | protected final static Logger log = LoggerFactory.getLogger(GetFlowByIdResource.class); |
Pavlin Radoslavov | 5ab6851 | 2013-02-18 09:59:33 -0800 | [diff] [blame] | 21 | |
admin | 944ef4f | 2013-10-08 17:48:37 -0700 | [diff] [blame] | 22 | /** |
| 23 | * Implement the API. |
| 24 | * |
| 25 | * @return the Flow state if the flow is found, otherwise null. |
| 26 | */ |
Pavlin Radoslavov | 5ab6851 | 2013-02-18 09:59:33 -0800 | [diff] [blame] | 27 | @Get("json") |
| 28 | public FlowPath retrieve() { |
| 29 | FlowPath result = null; |
| 30 | |
| 31 | IFlowService flowService = |
| 32 | (IFlowService)getContext().getAttributes(). |
| 33 | get(IFlowService.class.getCanonicalName()); |
| 34 | |
| 35 | if (flowService == null) { |
| 36 | log.debug("ONOS Flow Service not found"); |
| 37 | return result; |
| 38 | } |
| 39 | |
| 40 | // Extract the arguments |
| 41 | String flowIdStr = (String) getRequestAttributes().get("flow-id"); |
Pavlin Radoslavov | 2013cbb | 2013-02-26 10:15:18 -0800 | [diff] [blame] | 42 | FlowId flowId = new FlowId(flowIdStr); |
Pavlin Radoslavov | a10a9a8 | 2013-02-22 11:47:54 -0800 | [diff] [blame] | 43 | |
Pavlin Radoslavov | 5ab6851 | 2013-02-18 09:59:33 -0800 | [diff] [blame] | 44 | log.debug("Get Flow Id: " + flowIdStr); |
| 45 | |
Pavlin Radoslavov | b6f5354 | 2013-03-01 16:02:14 -0800 | [diff] [blame] | 46 | result = flowService.getFlow(flowId); |
Pavlin Radoslavov | 5ab6851 | 2013-02-18 09:59:33 -0800 | [diff] [blame] | 47 | |
| 48 | return result; |
| 49 | } |
| 50 | } |