X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fweb%2Fdevices%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fdevices%2Fweb%2FDevices.java;h=4e08f99bfd411aab360999092045cfa48da0c663;hb=25186c4271c02a6774e1a16f1e16a71ca06c693f;hp=15ad9e9887d8eb2aba1250bc278a48f7441db00a;hpb=0d8516471e3ee70a8bc9f02d046c5c0a20db01b1;p=controller.git diff --git a/opendaylight/web/devices/src/main/java/org/opendaylight/controller/devices/web/Devices.java b/opendaylight/web/devices/src/main/java/org/opendaylight/controller/devices/web/Devices.java index 15ad9e9887..4e08f99bfd 100644 --- a/opendaylight/web/devices/src/main/java/org/opendaylight/controller/devices/web/Devices.java +++ b/opendaylight/web/devices/src/main/java/org/opendaylight/controller/devices/web/Devices.java @@ -10,7 +10,7 @@ package org.opendaylight.controller.devices.web; import java.util.ArrayList; import java.util.HashMap; -import java.util.HashSet; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -59,9 +59,9 @@ import com.google.gson.Gson; @RequestMapping("/") public class Devices implements IDaylightWeb { private static final UserLevel AUTH_LEVEL = UserLevel.CONTAINERUSER; - private final String WEB_NAME = "Devices"; - private final String WEB_ID = "devices"; - private final short WEB_ORDER = 1; + private static final String WEB_NAME = "Devices"; + private static final String WEB_ID = "devices"; + private static final short WEB_ORDER = 1; public Devices() { ServiceHelper.registerGlobalService(IDaylightWeb.class, this, null); @@ -145,7 +145,6 @@ public class Devices implements IDaylightWeb { State portState = ((State) switchManager .getNodeConnectorProp(nodeConnector, State.StatePropName)); - String nodeConnectorName = (ncName != null) ? ncName .getValue() : ""; nodeConnectorName += " (" + nodeConnector.getID() + ")"; @@ -400,23 +399,35 @@ public class Devices implements IDaylightWeb { @RequestParam(required = false) String container) { Gson gson = new Gson(); List> subnets = new ArrayList>(); - String containerName = (container == null) ? GlobalConstants.DEFAULT - .toString() : 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); + Privilege privilege = DaylightWebUtil.getContainerPrivilege(userName, containerName, this); if (privilege != Privilege.NONE) { - ISwitchManager switchManager = (ISwitchManager) ServiceHelper - .getInstance(ISwitchManager.class, containerName, this); + ISwitchManager switchManager = (ISwitchManager) ServiceHelper.getInstance(ISwitchManager.class, + containerName, this); if (switchManager != null) { for (SubnetConfig conf : switchManager.getSubnetsConfigList()) { Map subnet = new HashMap(); subnet.put("name", conf.getName()); subnet.put("subnet", conf.getSubnet()); - subnet.put("json", gson.toJson(conf)); + List portsList = new ArrayList(); + Iterator itor = conf.getNodeConnectors().iterator(); + while(itor.hasNext()) { + SubnetGatewayPortBean bean = new SubnetGatewayPortBean(); + NodeConnector nodeConnector = itor.next(); + String nodeName = getNodeDesc(nodeConnector.getNode().toString(), containerName); + Name ncName = ((Name) switchManager.getNodeConnectorProp(nodeConnector, Name.NamePropName)); + String nodeConnectorName = (ncName != null) ? ncName.getValue() : ""; + bean.setNodeName(nodeName); + bean.setNodePortName(nodeConnectorName); + bean.setNodeId(nodeConnector.getNode().toString()); + bean.setNodePortId(nodeConnector.toString()); + portsList.add(bean); + } + subnet.put("nodePorts", gson.toJson(portsList)); subnets.add(subnet); } } @@ -449,7 +460,7 @@ public class Devices implements IDaylightWeb { ISwitchManager switchManager = (ISwitchManager) ServiceHelper .getInstance(ISwitchManager.class, containerName, this); SubnetConfig cfgObject = new SubnetConfig(gatewayName, - gatewayIPAddress, new HashSet()); + gatewayIPAddress, new ArrayList()); Status result = switchManager.addSubnet(cfgObject); if (result.isSuccess()) { resultBean.setStatus(true); @@ -524,14 +535,17 @@ public class Devices implements IDaylightWeb { try { ISwitchManager switchManager = (ISwitchManager) ServiceHelper .getInstance(ISwitchManager.class, containerName, this); - Status result = switchManager.addPortsToSubnet(portsName, nodeId - + "/" + ports); + List toAdd = new ArrayList(); + for (String port : ports.split(",")) { + toAdd.add(port); + } + Status result = switchManager.addPortsToSubnet(portsName, toAdd); if (result.isSuccess()) { resultBean.setStatus(true); resultBean .setMessage("Added ports to subnet gateway address successfully"); - DaylightWebUtil.auditlog("Ports to Subnet Gateway", userName, "added",nodeId+"/"+ ports, containerName); + DaylightWebUtil.auditlog("Ports to Subnet Gateway", userName, "added", ports, containerName); } else { resultBean.setStatus(false); resultBean.setMessage(result.getDescription()); @@ -563,13 +577,15 @@ public class Devices implements IDaylightWeb { try { ISwitchManager switchManager = (ISwitchManager) ServiceHelper .getInstance(ISwitchManager.class, containerName, this); - Status result = switchManager.removePortsFromSubnet(gatewayName, - nodePort); + List toRemove = new ArrayList(); + for (String port : nodePort.split(",")) { + toRemove.add(port); + } + Status result = switchManager.removePortsFromSubnet(gatewayName, toRemove); if (result.isSuccess()) { resultBean.setStatus(true); - resultBean - .setMessage("Deleted port from subnet gateway address successfully"); + resultBean.setMessage("Deleted port from subnet gateway address successfully"); DaylightWebUtil.auditlog("Ports from Subnet Gateway", userName, "removed", nodePort, containerName); } else { resultBean.setStatus(false); @@ -615,7 +631,7 @@ public class Devices implements IDaylightWeb { Map config = new HashMap(); for (String name : config_data.keySet()) { config.put(name, config_data.get(name)); - // Add switch name value (non-configuration field) + // Add switch portName value (non-configuration field) config.put("nodeName", getNodeDesc(config_data.get("nodeId"), containerName)); } @@ -636,10 +652,8 @@ public class Devices implements IDaylightWeb { @RequestMapping(value = "/nodeports") @ResponseBody - public Map getNodePorts(HttpServletRequest request, - @RequestParam(required = false) String container) { - String containerName = (container == null) ? GlobalConstants.DEFAULT - .toString() : container; + public String 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(); @@ -647,34 +661,31 @@ public class Devices implements IDaylightWeb { return null; } - ISwitchManager switchManager = (ISwitchManager) ServiceHelper .getInstance(ISwitchManager.class, containerName, this); if (switchManager == null) { return null; } - - Map nodes = new HashMap(); - Map port; + List nodeJsonBeans = new ArrayList(); for (Switch node : switchManager.getNetworkDevices()) { - port = new HashMap(); // new port + NodeJsonBean nodeJsonBean = new NodeJsonBean(); + List port = new ArrayList(); Set nodeConnectorSet = node.getNodeConnectors(); - if (nodeConnectorSet != null) { for (NodeConnector nodeConnector : nodeConnectorSet) { String nodeConnectorName = ((Name) switchManager - .getNodeConnectorProp(nodeConnector, - Name.NamePropName)).getValue(); - port.put((Short) nodeConnector.getID(), nodeConnectorName - + "(" + nodeConnector.getID() + ")"); + .getNodeConnectorProp(nodeConnector, Name.NamePropName)).getValue(); + port.add(new PortJsonBean(nodeConnector.getID().toString(), nodeConnectorName, nodeConnector.toString())); } } - - nodes.put(node.getNode().toString(), port); + nodeJsonBean.setNodeId(node.getNode().toString()); + nodeJsonBean.setNodeName(getNodeDesc(node.getNode().toString(), containerName)); + nodeJsonBean.setNodePorts(port); + nodeJsonBeans.add(nodeJsonBean); } - return nodes; + return new Gson().toJson(nodeJsonBeans); } @RequestMapping(value = "/spanPorts/add", method = RequestMethod.GET)