Umesh Krishnaswamy | e7a682b | 2013-03-21 14:16:28 -0700 | [diff] [blame] | 1 | package net.floodlightcontroller.flowcache.web; |
| 2 | |
| 3 | import java.util.ArrayList; |
| 4 | |
| 5 | import net.floodlightcontroller.flowcache.IFlowService; |
| 6 | import net.floodlightcontroller.util.FlowPath; |
| 7 | import net.floodlightcontroller.util.FlowId; |
| 8 | |
| 9 | import org.restlet.resource.Get; |
| 10 | import org.restlet.resource.ServerResource; |
| 11 | import org.slf4j.Logger; |
| 12 | import org.slf4j.LoggerFactory; |
| 13 | |
| 14 | public class GetSummaryFlowsResource extends ServerResource { |
Umesh Krishnaswamy | 57a32a9 | 2013-03-21 14:21:15 -0700 | [diff] [blame] | 15 | protected static Logger log = LoggerFactory.getLogger(GetSummaryFlowsResource.class); |
Umesh Krishnaswamy | e7a682b | 2013-03-21 14:16:28 -0700 | [diff] [blame] | 16 | |
| 17 | @Get("json") |
| 18 | public ArrayList<FlowPath> retrieve() { |
| 19 | ArrayList<FlowPath> result = null; |
| 20 | |
Umesh Krishnaswamy | 57a32a9 | 2013-03-21 14:21:15 -0700 | [diff] [blame] | 21 | FlowId flowId; |
| 22 | int maxFlows = 0; |
| 23 | |
Umesh Krishnaswamy | e7a682b | 2013-03-21 14:16:28 -0700 | [diff] [blame] | 24 | IFlowService flowService = (IFlowService)getContext().getAttributes().get(IFlowService.class.getCanonicalName()); |
| 25 | |
| 26 | if (flowService == null) { |
| 27 | log.debug("ONOS Flow Service not found"); |
| 28 | return result; |
| 29 | } |
| 30 | |
| 31 | // Extract the arguments |
Umesh Krishnaswamy | 57a32a9 | 2013-03-21 14:21:15 -0700 | [diff] [blame] | 32 | String flowIdStr = (String) getRequestAttributes().get("flow-id"); |
| 33 | String maxFlowStr = (String) getRequestAttributes().get("max-flows"); |
| 34 | log.debug("Get Summary Flows starting flow-id: " + flowIdStr + " max-flows: " + maxFlowStr); |
| 35 | |
| 36 | flowId = new FlowId(flowIdStr); |
| 37 | maxFlows = Integer.parseInt(maxFlowStr); |
| 38 | if (maxFlows < 0) maxFlows = 0; |
Umesh Krishnaswamy | e7a682b | 2013-03-21 14:16:28 -0700 | [diff] [blame] | 39 | |
Umesh Krishnaswamy | 57a32a9 | 2013-03-21 14:21:15 -0700 | [diff] [blame] | 40 | result = flowService.getAllFlowsSummary(flowId, maxFlows); |
Umesh Krishnaswamy | e7a682b | 2013-03-21 14:16:28 -0700 | [diff] [blame] | 41 | |
| 42 | return result; |
| 43 | } |
| 44 | } |