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=188be8aee6f1ee4865b159d1f2225ec6f1534021;hb=1e9531138e44cd757ca27b0d86e98eccb22ccd82;hp=1102a6382e649aa9389528ce5b6d438e5fc2ba8b;hpb=ea1001f9e92eb9ec1ec77eaad8af24a210626c7f;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 1102a6382e..188be8aee6 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 @@ -36,7 +36,6 @@ import org.opendaylight.controller.sal.core.Name; import org.opendaylight.controller.sal.core.Node; import org.opendaylight.controller.sal.core.NodeConnector; import org.opendaylight.controller.sal.core.Tier; -import org.opendaylight.controller.sal.utils.GlobalConstants; import org.opendaylight.controller.sal.utils.HexEncode; import org.opendaylight.controller.sal.utils.ServiceHelper; import org.opendaylight.controller.sal.utils.Status; @@ -89,66 +88,90 @@ public class Devices implements IDaylightWeb { ISwitchManager switchManager = (ISwitchManager) ServiceHelper .getInstance(ISwitchManager.class, containerName, this); List> nodeData = new ArrayList>(); - for (Switch device : switchManager.getNetworkDevices()) { - HashMap nodeDatum = new HashMap(); - Node node = device.getNode(); - Tier tier = (Tier) switchManager.getNodeProp(node, - Tier.TierPropName); - - nodeDatum.put("containerName", containerName); - nodeDatum.put("nodeName", switchManager.getNodeDescription(node)); - nodeDatum.put("nodeId", node.toString()); - int tierNumber = (tier == null) ? TierHelper.unknownTierNumber - : tier.getValue(); - nodeDatum.put("tierName", TierHelper.getTierName(tierNumber) - + " (Tier-" + tierNumber + ")"); - nodeDatum.put("tier", tierNumber + ""); - SwitchConfig sc = switchManager.getSwitchConfig(device.getNode() - .toString()); - String modeStr = (sc != null) ? sc.getMode() : "0"; - nodeDatum.put("mode", modeStr); - - nodeDatum.put("json", gson.toJson(nodeDatum)); - nodeDatum.put("mac", - HexEncode.bytesToHexString(device.getDataLayerAddress())); - StringBuffer sb1 = new StringBuffer(); - Set nodeConnectorSet = device.getNodeConnectors(); - if (nodeConnectorSet != null && nodeConnectorSet.size() > 0) { - Map portList = new HashMap(); - for (NodeConnector nodeConnector : nodeConnectorSet) { - String nodeConnectorNumberToStr = nodeConnector.getID().toString(); - Name ncName = ((Name) switchManager.getNodeConnectorProp( - nodeConnector, Name.NamePropName)); - Config portStatus = ((Config) switchManager - .getNodeConnectorProp(nodeConnector, - Config.ConfigPropName)); - - String nodeConnectorName = (ncName != null) ? ncName.getValue() - : ""; - nodeConnectorName += " ("+nodeConnector.getID()+")"; - - if (portStatus != null) { - if (portStatus.getValue() == Config.ADMIN_UP) { - nodeConnectorName = ""+nodeConnectorName+""; - } else if (portStatus.getValue() == Config.ADMIN_DOWN) { - nodeConnectorName = ""+nodeConnectorName+""; + if (switchManager != null) { + for (Switch device : switchManager.getNetworkDevices()) { + HashMap nodeDatum = new HashMap(); + Node node = device.getNode(); + Tier tier = (Tier) switchManager.getNodeProp(node, + Tier.TierPropName); + + nodeDatum.put("containerName", containerName); + nodeDatum.put("nodeName", + switchManager.getNodeDescription(node)); + nodeDatum.put("nodeId", node.toString()); + int tierNumber = (tier == null) ? TierHelper.unknownTierNumber + : tier.getValue(); + nodeDatum.put("tierName", TierHelper.getTierName(tierNumber) + + " (Tier-" + tierNumber + ")"); + nodeDatum.put("tier", tierNumber + ""); + SwitchConfig sc = switchManager.getSwitchConfig(device + .getNode().toString()); + String modeStr = (sc != null) ? sc.getMode() : "0"; + nodeDatum.put("mode", modeStr); + + nodeDatum.put("json", gson.toJson(nodeDatum)); + nodeDatum.put("mac", HexEncode.bytesToHexString(device + .getDataLayerAddress())); + StringBuffer sb1 = new StringBuffer(); + Set nodeConnectorSet = device + .getNodeConnectors(); + if (nodeConnectorSet != null && nodeConnectorSet.size() > 0) { + Map portList = new HashMap(); + List intfList = new ArrayList(); + for (NodeConnector nodeConnector : nodeConnectorSet) { + String nodeConnectorNumberToStr = nodeConnector.getID() + .toString(); + Name ncName = ((Name) switchManager + .getNodeConnectorProp(nodeConnector, + Name.NamePropName)); + Config portStatus = ((Config) switchManager + .getNodeConnectorProp(nodeConnector, + Config.ConfigPropName)); + + String nodeConnectorName = (ncName != null) ? ncName + .getValue() : ""; + nodeConnectorName += " (" + nodeConnector.getID() + ")"; + + if (portStatus != null) { + if (portStatus.getValue() == Config.ADMIN_UP) { + nodeConnectorName = "" + + nodeConnectorName + ""; + } else if (portStatus.getValue() == Config.ADMIN_DOWN) { + nodeConnectorName = "" + + nodeConnectorName + ""; + } + } + + Class idClass = nodeConnector.getID().getClass(); + if (idClass.equals(Short.class)) { + portList.put( + Short.parseShort(nodeConnectorNumberToStr), + nodeConnectorName); + } else { + intfList.add(nodeConnectorName); } } - - portList.put(Short.parseShort(nodeConnectorNumberToStr), - nodeConnectorName); - } - Map sortedPortList = new TreeMap(portList); + if (portList.size() > 0) { + Map sortedPortList = new TreeMap( + portList); - for (Entry e : sortedPortList.entrySet()) { - sb1.append(e.getValue()); - sb1.append("
"); + for (Entry e : sortedPortList.entrySet()) { + sb1.append(e.getValue()); + sb1.append("
"); + } + } else if (intfList.size() > 0) { + for (String intf : intfList) { + sb1.append(intf); + sb1.append("
"); + } + } } + nodeDatum.put("ports", sb1.toString()); + nodeData.add(nodeDatum); } - nodeDatum.put("ports", sb1.toString()); - nodeData.add(nodeDatum); } + DevicesJsonBean result = new DevicesJsonBean(); result.setNodeData(nodeData); List columnNames = new ArrayList(); @@ -207,6 +230,9 @@ public class Devices implements IDaylightWeb { IForwardingStaticRouting staticRouting = (IForwardingStaticRouting) ServiceHelper .getInstance(IForwardingStaticRouting.class, containerName, this); + if (staticRouting == null) { + return null; + } List> staticRoutes = new ArrayList>(); ConcurrentMap routeConfigs = staticRouting .getStaticRouteConfigs(); @@ -309,12 +335,14 @@ public class Devices implements IDaylightWeb { String containerName = DaylightWebUtil.getAuthorizedContainer(request, container, this); ISwitchManager switchManager = (ISwitchManager) ServiceHelper .getInstance(ISwitchManager.class, containerName, this); - 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)); - subnets.add(subnet); + 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)); + subnets.add(subnet); + } } DevicesJsonBean result = new DevicesJsonBean(); result.setColumnNames(SubnetConfig.getGuiFieldsNames()); @@ -461,8 +489,10 @@ public class Devices implements IDaylightWeb { String containerName = DaylightWebUtil.getAuthorizedContainer(request, container, this); ISwitchManager switchManager = (ISwitchManager) ServiceHelper .getInstance(ISwitchManager.class, containerName, this); - for (SpanConfig conf : switchManager.getSpanConfigList()) { - spanConfigs_json.add(gson.toJson(conf)); + if (switchManager != null) { + for (SpanConfig conf : switchManager.getSpanConfigList()) { + spanConfigs_json.add(gson.toJson(conf)); + } } ObjectMapper mapper = new ObjectMapper(); List> spanConfigs = new ArrayList>(); @@ -496,8 +526,9 @@ public class Devices implements IDaylightWeb { String containerName = DaylightWebUtil.getAuthorizedContainer(request, container, this); ISwitchManager switchManager = (ISwitchManager) ServiceHelper .getInstance(ISwitchManager.class, containerName, this); - if (switchManager == null) + if (switchManager == null) { return null; + } Map nodes = new HashMap(); Map port; @@ -605,7 +636,7 @@ public class Devices implements IDaylightWeb { /** * Is the operation permitted for the given level - * + * * @param level */ private boolean authorize(UserLevel level, HttpServletRequest request) { @@ -638,10 +669,10 @@ public class Devices implements IDaylightWeb { * IUserManager userManager = (IUserManager) ServiceHelper * .getGlobalInstance(IUserManager.class, this); if (userManager == * null) { return "User Manager is not available"; } - * + * * String username = request.getUserPrincipal().getName(); - * - * + * + * * model.addAttribute("username", username); model.addAttribute("role", * userManager.getUserLevel(username).toNumber()); */