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