From: Sapan Shah Date: Fri, 23 Aug 2013 07:43:04 +0000 (-0700) Subject: Delete Multiple flows in a single click X-Git-Tag: releasepom-0.1.0~182^2 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=e7ffa0d217e8a42fe25a66ae19abb2592de8b005;hp=fb43be7b964997da48f47e5a62a953bc099f315c Delete Multiple flows in a single click Change-Id: I0b61799e66e05aed2b7d89cb885f7b29fa032663 Signed-off-by: Sapan Shah --- diff --git a/opendaylight/web/flows/src/main/java/org/opendaylight/controller/flows/web/Flows.java b/opendaylight/web/flows/src/main/java/org/opendaylight/controller/flows/web/Flows.java index 9444360eec..a96d3efcec 100644 --- a/opendaylight/web/flows/src/main/java/org/opendaylight/controller/flows/web/Flows.java +++ b/opendaylight/web/flows/src/main/java/org/opendaylight/controller/flows/web/Flows.java @@ -8,6 +8,7 @@ package org.opendaylight.controller.flows.web; +import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -77,13 +78,16 @@ public class Flows implements IDaylightWeb { @RequestMapping(value = "/main") @ResponseBody - public Map getFlows(HttpServletRequest request, @RequestParam(required = false) String container) { - String containerName = (container == null) ? GlobalConstants.DEFAULT.toString() : container; + public Map getFlows(HttpServletRequest request, + @RequestParam(required = false) String container) { + String containerName = (container == null) ? GlobalConstants.DEFAULT + .toString() : container; // Derive the privilege this user has on the current container String userName = request.getUserPrincipal().getName(); - Privilege privilege = DaylightWebUtil.getContainerPrivilege(userName, containerName, this); - if (privilege == Privilege.NONE) { + Privilege privilege = DaylightWebUtil.getContainerPrivilege(userName, + containerName, this); + if (privilege == Privilege.NONE) { return null; } @@ -114,7 +118,7 @@ public class Flows implements IDaylightWeb { flowSet.add(entry); } - Map output = new HashMap(2); + Map output = new HashMap(2); output.put("flows", flowSet); output.put("privilege", privilege); return output; @@ -122,12 +126,15 @@ public class Flows implements IDaylightWeb { @RequestMapping(value = "/node-ports") @ResponseBody - public Map getNodePorts(HttpServletRequest request, @RequestParam(required = false) String container) { - String containerName = (container == null) ? GlobalConstants.DEFAULT.toString() : container; + public Map getNodePorts(HttpServletRequest request, + @RequestParam(required = false) String container) { + String containerName = (container == null) ? GlobalConstants.DEFAULT + .toString() : container; // Derive the privilege this user has on the current container String userName = request.getUserPrincipal().getName(); - if (DaylightWebUtil.getContainerPrivilege(userName, containerName, this) == Privilege.NONE) { + if (DaylightWebUtil + .getContainerPrivilege(userName, containerName, this) == Privilege.NONE) { return null; } @@ -171,12 +178,15 @@ public class Flows implements IDaylightWeb { @RequestMapping(value = "/node-flows") @ResponseBody - public Map getNodeFlows(HttpServletRequest request, @RequestParam(required = false) String container) { - String containerName = (container == null) ? GlobalConstants.DEFAULT.toString() : container; + public Map getNodeFlows(HttpServletRequest request, + @RequestParam(required = false) String container) { + String containerName = (container == null) ? GlobalConstants.DEFAULT + .toString() : container; // Derive the privilege this user has on the current container String userName = request.getUserPrincipal().getName(); - if (DaylightWebUtil.getContainerPrivilege(userName, containerName, this) == Privilege.NONE) { + if (DaylightWebUtil + .getContainerPrivilege(userName, containerName, this) == Privilege.NONE) { return null; } @@ -199,10 +209,12 @@ public class Flows implements IDaylightWeb { List flows = frm.getStaticFlows(node); String nodeDesc = node.toString(); - SwitchConfig config = switchManager.getSwitchConfig(node - .toString()); - if ((config != null) && (config.getProperty(Description.propertyName) != null)) { - nodeDesc = ((Description) config.getProperty(Description.propertyName)).getValue(); + SwitchConfig config = switchManager + .getSwitchConfig(node.toString()); + if ((config != null) + && (config.getProperty(Description.propertyName) != null)) { + nodeDesc = ((Description) config + .getProperty(Description.propertyName)).getValue(); } nodes.put(nodeDesc, flows.size()); @@ -216,12 +228,15 @@ public class Flows implements IDaylightWeb { public String actionFlow(@RequestParam(required = true) String action, @RequestParam(required = false) String body, @RequestParam(required = true) String nodeId, - HttpServletRequest request, @RequestParam(required = false) String container) { - String containerName = (container == null) ? GlobalConstants.DEFAULT.toString() : container; + HttpServletRequest request, + @RequestParam(required = false) String container) { + String containerName = (container == null) ? GlobalConstants.DEFAULT + .toString() : container; // Authorization check String userName = request.getUserPrincipal().getName(); - if (DaylightWebUtil.getContainerPrivilege(userName, containerName, this) != Privilege.WRITE) { + if (DaylightWebUtil + .getContainerPrivilege(userName, containerName, this) != Privilege.WRITE) { return "Operation not authorized"; } @@ -238,7 +253,8 @@ public class Flows implements IDaylightWeb { Status result = new Status(StatusCode.BADREQUEST, "Invalid request"); if (action.equals("add")) { result = frm.addStaticFlow(flow); - DaylightWebUtil.auditlog("Flow", userName, "added", flow.getName(), containerName); + DaylightWebUtil.auditlog("Flow", userName, "added", flow.getName(), + containerName); } return (result.isSuccess()) ? StatusCode.SUCCESS.toString() : result @@ -250,12 +266,15 @@ public class Flows implements IDaylightWeb { public String removeFlow(@PathVariable("nodeId") String nodeId, @PathVariable("name") String name, @RequestParam(required = true) String action, - HttpServletRequest request, @RequestParam(required = false) String container) { - String containerName = (container == null) ? GlobalConstants.DEFAULT.toString() : container; + HttpServletRequest request, + @RequestParam(required = false) String container) { + String containerName = (container == null) ? GlobalConstants.DEFAULT + .toString() : container; // Authorization check String userName = request.getUserPrincipal().getName(); - if (DaylightWebUtil.getContainerPrivilege(userName, containerName, this) != Privilege.WRITE) { + if (DaylightWebUtil + .getContainerPrivilege(userName, containerName, this) != Privilege.WRITE) { return "Operation not authorized"; } @@ -272,13 +291,15 @@ public class Flows implements IDaylightWeb { } if (action.equals("remove")) { result = frm.removeStaticFlow(name, node); - if(result.isSuccess()) { - DaylightWebUtil.auditlog("Flow", userName, "removed", name, containerName); + if (result.isSuccess()) { + DaylightWebUtil.auditlog("Flow", userName, "removed", name, + containerName); } } else if (action.equals("toggle")) { result = frm.toggleStaticFlowStatus(name, node); - if(result.isSuccess()) { - DaylightWebUtil.auditlog("Flow", userName, "toggled", name, containerName); + if (result.isSuccess()) { + DaylightWebUtil.auditlog("Flow", userName, "toggled", name, + containerName); } } else { result = new Status(StatusCode.BADREQUEST, "Unknown action"); @@ -288,10 +309,58 @@ public class Flows implements IDaylightWeb { .getDescription(); } + @SuppressWarnings("unchecked") + @RequestMapping(value = "/flow/deleteFlows", method = RequestMethod.POST) + @ResponseBody + public String removeSelectedFlows( + @RequestParam(required = false) String body, + HttpServletRequest request, + @RequestParam(required = false) String container) { + String containerName = (container == null) ? GlobalConstants.DEFAULT + .toString() : container; + + // Authorization check + String userName = request.getUserPrincipal().getName(); + if (DaylightWebUtil + .getContainerPrivilege(userName, containerName, this) != Privilege.WRITE) { + return "Operation not authorized"; + } + + IForwardingRulesManager frm = (IForwardingRulesManager) ServiceHelper + .getInstance(IForwardingRulesManager.class, containerName, this); + if (frm == null) { + return "Forwarding Rules Manager is not available"; + } + + Gson gson = new Gson(); + List> flowList = new ArrayList>(); + flowList = gson.fromJson(body, flowList.getClass()); + Status result = new Status(StatusCode.BADREQUEST, "Invalid request"); + String status = ""; + for (Map flowEntry : flowList) { + Node node = Node.fromString(flowEntry.get("node")); + result = frm.removeStaticFlow(flowEntry.get("name"), node); + if (result.isSuccess()) { + DaylightWebUtil.auditlog("Flow", userName, "removed", + flowEntry.get("name"), containerName); + } else { + status = flowEntry.get("name") + ", " + status; + } + } + if (!status.equals("")) { + return "Could not remove " + + status.substring(0, status.length() - 2) + " Flow(s)"; + } else { + return "Success"; + } + } + private String getNodeDesc(Node node, ISwitchManager switchManager) { - Description desc = (Description) switchManager.getNodeProp(node, Description.propertyName); + Description desc = (Description) switchManager.getNodeProp(node, + Description.propertyName); String description = (desc == null) ? "" : desc.getValue(); - return (description.isEmpty() || description.equalsIgnoreCase("none")) ? node.toString() : description; + return (description.isEmpty() || description.equalsIgnoreCase("none")) ? node + .toString() : description; } } diff --git a/opendaylight/web/flows/src/main/resources/js/page.js b/opendaylight/web/flows/src/main/resources/js/page.js index 0f1eabb859..3dcf9e3006 100644 --- a/opendaylight/web/flows/src/main/resources/js/page.js +++ b/opendaylight/web/flows/src/main/resources/js/page.js @@ -48,7 +48,8 @@ one.f.address = { main : "/main", flows : "/node-flows", nodes : "/node-ports", - flow : "/flow" + flow : "/flow", + deleteFlows:"/flow/deleteFlows" } } @@ -251,9 +252,11 @@ one.f.flows = { id : { dashlet : { add : "one_f_flows_id_dashlet_add", + removeMultiple : "one_f_flows_id_dashlet_removeMultiple", remove : "one_f_flows_id_dashlet_remove", toggle : "one_f_flows_id_dashlet_toggle", - datagrid: "one_f_flows_id_dashlet_datagrid" + datagrid : "one_f_flows_id_dashlet_datagrid", + selectAllFlows : "one_f_flows_id_dashlet_selectAllFlows" }, modal : { install : "one_f_flows_id_modal_install", @@ -327,6 +330,36 @@ one.f.flows = { $modal.modal(); }); $dashlet.append($button); + var button = one.lib.dashlet.button.single("Remove Flow Entry", one.f.flows.id.dashlet.removeMultiple, "btn-primary", "btn-mini"); + var $button = one.lib.dashlet.button.button(button); + + $button.click(function() { + var checkedCheckBoxes = $('.flowEntry[type=checkbox]:checked'); + + var requestData = []; + + var resource = {}; + checkedCheckBoxes.each(function(index, value) { + var flowEntry = {}; + flowEntry['name'] = checkedCheckBoxes[index].name; + flowEntry['node'] = checkedCheckBoxes[index].getAttribute("node"); + requestData.push(flowEntry); + }); + resource['body'] = JSON.stringify(requestData); + + $.post(one.f.address.root+one.f.address.flows.deleteFlows, resource, function(response) { + if(response == "Success") { + one.lib.alert("Flow(s) successfully removed"); + } else { + one.lib.alert(response); + } + one.main.dashlet.right.bottom.empty(); + one.f.detail.dashlet(one.main.dashlet.right.bottom); + one.main.dashlet.left.top.empty(); + one.f.flows.dashlet(one.main.dashlet.left.top); + }); + }); + $dashlet.append($button); } @@ -339,7 +372,12 @@ one.f.flows = { $dashlet.append($gridHTML); var dataSource = one.f.flows.data.flowsDataGrid(data); $("#" + one.f.flows.id.dashlet.datagrid).datagrid({dataSource: dataSource}).on("loaded", function() { - $("#" + one.f.flows.id.dashlet.datagrid).find("tbody tr").each(function(index, tr) { + $("#"+one.f.flows.id.dashlet.datagrid.selectAllFlows).click(function() { + $("#" + one.f.flows.id.dashlet.datagrid).find(':checkbox').prop('checked', + $("#"+one.f.flows.id.dashlet.datagrid.selectAllFlows).is(':checked')); + }); + + $("#" + one.f.flows.id.dashlet.datagrid).find("tbody tr").each(function(index, tr) { $tr = $(tr); $span = $("td span", $tr); var flowstatus = $span.data("flowstatus"); @@ -357,10 +395,22 @@ one.f.flows = { }); // attach click event $tr.click(function() { - var $td = $($(this).find("td")[0]); + var $td = $($(this).find("td")[1]); var id = $td.text(); var node = $td.find("span").data("nodeid"); - one.f.flows.detail(id, node); + one.f.flows.detail(id, node); + }); + $(".flowEntry").click(function(){ + if (!$('.flowEntry[type=checkbox]:not(:checked)').length) { + $("#"+one.f.flows.id.dashlet.datagrid.selectAllFlows) + .prop("checked", + true); + } else { + $("#"+one.f.flows.id.dashlet.datagrid.selectAllFlows) + .prop("checked", + false); + } + event.stopPropagation(); }); }); }); @@ -1193,6 +1243,11 @@ one.f.flows = { flowsDataGrid: function(data) { var source = new StaticDataSource({ columns: [ + { + property: 'selector', + label: "", + sortable: false + }, { property: 'name', label: 'Flow Name', @@ -1207,7 +1262,13 @@ one.f.flows = { data: data.flows, formatter: function(items) { $.each(items, function(index, item) { - item["name"] = '' + item["name"] + ''; }); @@ -1222,6 +1283,8 @@ one.f.flows = { $(data).each(function(index, value) { var tr = {}; var entry = []; + + entry.push(value['name']); entry.push(value['node']); if (value['flow']['installInHw'] == 'true' && value['flow']['status'] == 'Success') @@ -1244,12 +1307,12 @@ one.f.flows = { var $table = one.lib.dashlet.table.table(attributes); var headers = ['Flow Name', 'Node']; + var $thead = one.lib.dashlet.table.header(headers); $table.append($thead); var $tbody = one.lib.dashlet.table.body(body); $table.append($tbody); - return $table; } }