2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.controller.devices.web;
11 import java.util.ArrayList;
12 import java.util.HashMap;
13 import java.util.List;
15 import java.util.Map.Entry;
17 import java.util.TreeMap;
18 import java.util.concurrent.ConcurrentMap;
20 import javax.servlet.http.HttpServletRequest;
21 import javax.servlet.http.HttpServletResponse;
23 import org.codehaus.jackson.map.ObjectMapper;
24 import org.opendaylight.controller.forwarding.staticrouting.IForwardingStaticRouting;
25 import org.opendaylight.controller.forwarding.staticrouting.StaticRouteConfig;
26 import org.opendaylight.controller.sal.authorization.Privilege;
27 import org.opendaylight.controller.sal.authorization.UserLevel;
28 import org.opendaylight.controller.sal.core.Config;
29 import org.opendaylight.controller.sal.core.Name;
30 import org.opendaylight.controller.sal.core.Node;
31 import org.opendaylight.controller.sal.core.NodeConnector;
32 import org.opendaylight.controller.sal.core.Tier;
33 import org.opendaylight.controller.sal.utils.GlobalConstants;
34 import org.opendaylight.controller.sal.utils.HexEncode;
35 import org.opendaylight.controller.sal.utils.ServiceHelper;
36 import org.opendaylight.controller.sal.utils.Status;
37 import org.opendaylight.controller.sal.utils.TierHelper;
38 import org.opendaylight.controller.switchmanager.ISwitchManager;
39 import org.opendaylight.controller.switchmanager.SpanConfig;
40 import org.opendaylight.controller.switchmanager.SubnetConfig;
41 import org.opendaylight.controller.switchmanager.Switch;
42 import org.opendaylight.controller.switchmanager.SwitchConfig;
43 import org.opendaylight.controller.web.DaylightWebUtil;
44 import org.opendaylight.controller.web.IDaylightWeb;
45 import org.springframework.stereotype.Controller;
46 import org.springframework.web.bind.annotation.RequestMapping;
47 import org.springframework.web.bind.annotation.RequestMethod;
48 import org.springframework.web.bind.annotation.RequestParam;
49 import org.springframework.web.bind.annotation.ResponseBody;
51 import com.google.gson.Gson;
55 public class Devices implements IDaylightWeb {
56 private static final UserLevel AUTH_LEVEL = UserLevel.CONTAINERUSER;
57 private final String WEB_NAME = "Devices";
58 private final String WEB_ID = "devices";
59 private final short WEB_ORDER = 1;
62 ServiceHelper.registerGlobalService(IDaylightWeb.class, this, null);
66 public String getWebName() {
71 public String getWebId() {
76 public short getWebOrder() {
81 public boolean isAuthorized(UserLevel userLevel) {
82 return userLevel.ordinal() <= AUTH_LEVEL.ordinal();
85 @RequestMapping(value = "/nodesLearnt", method = RequestMethod.GET)
87 public DevicesJsonBean getNodesLearnt(HttpServletRequest request,
88 @RequestParam(required = false) String container) {
89 Gson gson = new Gson();
90 String containerName = (container == null) ? GlobalConstants.DEFAULT
91 .toString() : container;
93 // Derive the privilege this user has on the current container
94 String userName = request.getUserPrincipal().getName();
95 Privilege privilege = DaylightWebUtil.getContainerPrivilege(userName, containerName, this);
97 ISwitchManager switchManager = (ISwitchManager) ServiceHelper
98 .getInstance(ISwitchManager.class, containerName, this);
99 List<Map<String, String>> nodeData = new ArrayList<Map<String, String>>();
100 if (switchManager != null && privilege != Privilege.NONE) {
101 for (Switch device : switchManager.getNetworkDevices()) {
102 HashMap<String, String> nodeDatum = new HashMap<String, String>();
103 Node node = device.getNode();
104 Tier tier = (Tier) switchManager.getNodeProp(node,
107 nodeDatum.put("containerName", containerName);
108 nodeDatum.put("nodeName",
109 switchManager.getNodeDescription(node));
110 nodeDatum.put("nodeId", node.toString());
111 int tierNumber = (tier == null) ? TierHelper.unknownTierNumber
113 nodeDatum.put("tierName", TierHelper.getTierName(tierNumber)
114 + " (Tier-" + tierNumber + ")");
115 nodeDatum.put("tier", tierNumber + "");
116 SwitchConfig sc = switchManager.getSwitchConfig(device
117 .getNode().toString());
118 String modeStr = (sc != null) ? sc.getMode() : "0";
119 nodeDatum.put("mode", modeStr);
121 nodeDatum.put("json", gson.toJson(nodeDatum));
122 nodeDatum.put("mac", HexEncode.bytesToHexString(device
123 .getDataLayerAddress()));
124 StringBuffer sb1 = new StringBuffer();
125 Set<NodeConnector> nodeConnectorSet = device
126 .getNodeConnectors();
127 if (nodeConnectorSet != null && nodeConnectorSet.size() > 0) {
128 Map<Short, String> portList = new HashMap<Short, String>();
129 List<String> intfList = new ArrayList<String>();
130 for (NodeConnector nodeConnector : nodeConnectorSet) {
131 String nodeConnectorNumberToStr = nodeConnector.getID()
133 Name ncName = ((Name) switchManager
134 .getNodeConnectorProp(nodeConnector,
136 Config portStatus = ((Config) switchManager
137 .getNodeConnectorProp(nodeConnector,
138 Config.ConfigPropName));
140 String nodeConnectorName = (ncName != null) ? ncName
142 nodeConnectorName += " (" + nodeConnector.getID() + ")";
144 if (portStatus != null) {
145 if (portStatus.getValue() == Config.ADMIN_UP) {
146 nodeConnectorName = "<span style='color:green;'>"
147 + nodeConnectorName + "</span>";
148 } else if (portStatus.getValue() == Config.ADMIN_DOWN) {
149 nodeConnectorName = "<span style='color:red;'>"
150 + nodeConnectorName + "</span>";
154 Class<?> idClass = nodeConnector.getID().getClass();
155 if (idClass.equals(Short.class)) {
157 Short.parseShort(nodeConnectorNumberToStr),
160 intfList.add(nodeConnectorName);
164 if (portList.size() > 0) {
165 Map<Short, String> sortedPortList = new TreeMap<Short, String>(
168 for (Entry<Short, String> e : sortedPortList.entrySet()) {
169 sb1.append(e.getValue());
172 } else if (intfList.size() > 0) {
173 for (String intf : intfList) {
179 nodeDatum.put("ports", sb1.toString());
180 nodeData.add(nodeDatum);
184 DevicesJsonBean result = new DevicesJsonBean();
185 result.setNodeData(nodeData);
186 result.setPrivilege(privilege);
187 List<String> columnNames = new ArrayList<String>();
188 columnNames.add("Node ID");
189 columnNames.add("Node Name");
190 columnNames.add("Tier");
191 columnNames.add("Mac Address");
192 columnNames.add("Ports");
193 columnNames.add("Port Status");
195 result.setColumnNames(columnNames);
199 @RequestMapping(value = "/tiers", method = RequestMethod.GET)
201 public List<String> getTiers() {
202 return TierHelper.getTiers();
205 @RequestMapping(value = "/nodesLearnt/update", method = RequestMethod.GET)
207 public StatusJsonBean updateLearntNode(
208 @RequestParam("nodeName") String nodeName,
209 @RequestParam("nodeId") String nodeId,
210 @RequestParam("tier") String tier,
211 @RequestParam("operationMode") String operationMode,
212 HttpServletRequest request,
213 @RequestParam(required = false) String container) {
214 String containerName = (container == null) ? GlobalConstants.DEFAULT
215 .toString() : container;
217 // Authorization check
218 String userName = request.getUserPrincipal().getName();
220 .getContainerPrivilege(userName, containerName, this) != Privilege.WRITE) {
221 return unauthorizedMessage();
224 StatusJsonBean resultBean = new StatusJsonBean();
226 ISwitchManager switchManager = (ISwitchManager) ServiceHelper
227 .getInstance(ISwitchManager.class, containerName, this);
228 SwitchConfig cfg = new SwitchConfig(nodeId, nodeName, tier,
230 switchManager.updateSwitchConfig(cfg);
231 resultBean.setStatus(true);
232 resultBean.setMessage("Updated node information successfully");
233 } catch (Exception e) {
234 resultBean.setStatus(false);
235 resultBean.setMessage("Error updating node information. "
241 @RequestMapping(value = "/staticRoutes", method = RequestMethod.GET)
243 public DevicesJsonBean getStaticRoutes(HttpServletRequest request,
244 @RequestParam(required = false) String container) {
245 Gson gson = new Gson();
246 String containerName = (container == null) ? GlobalConstants.DEFAULT
247 .toString() : container;
249 // Derive the privilege this user has on the current container
250 String userName = request.getUserPrincipal().getName();
251 Privilege privilege = DaylightWebUtil.getContainerPrivilege(userName, containerName, this);
253 IForwardingStaticRouting staticRouting = (IForwardingStaticRouting) ServiceHelper
254 .getInstance(IForwardingStaticRouting.class, containerName,
256 if (staticRouting == null) {
259 List<Map<String, String>> staticRoutes = new ArrayList<Map<String, String>>();
260 ConcurrentMap<String, StaticRouteConfig> routeConfigs = staticRouting
261 .getStaticRouteConfigs();
262 if (routeConfigs == null) {
265 if (privilege != Privilege.NONE) {
266 for (StaticRouteConfig conf : routeConfigs.values()) {
267 Map<String, String> staticRoute = new HashMap<String, String>();
268 staticRoute.put("name", conf.getName());
269 staticRoute.put("staticRoute", conf.getStaticRoute());
270 staticRoute.put("nextHopType", conf.getNextHopType());
271 staticRoute.put("nextHop", conf.getNextHop());
272 staticRoute.put("json", gson.toJson(conf));
273 staticRoutes.add(staticRoute);
276 DevicesJsonBean result = new DevicesJsonBean();
277 result.setPrivilege(privilege);
278 result.setColumnNames(StaticRouteConfig.getGuiFieldsNames());
279 result.setNodeData(staticRoutes);
283 @RequestMapping(value = "/staticRoute/add", method = RequestMethod.GET)
285 public StatusJsonBean addStaticRoute(
286 @RequestParam("routeName") String routeName,
287 @RequestParam("staticRoute") String staticRoute,
288 @RequestParam("nextHop") String nextHop,
289 HttpServletRequest request,
290 @RequestParam(required = false) String container) {
291 String containerName = (container == null) ? GlobalConstants.DEFAULT
292 .toString() : container;
294 // Authorization check
295 String userName = request.getUserPrincipal().getName();
297 .getContainerPrivilege(userName, containerName, this) != Privilege.WRITE) {
298 return unauthorizedMessage();
301 StatusJsonBean result = new StatusJsonBean();
303 IForwardingStaticRouting staticRouting = (IForwardingStaticRouting) ServiceHelper
304 .getInstance(IForwardingStaticRouting.class, containerName,
306 StaticRouteConfig config = new StaticRouteConfig();
307 config.setName(routeName);
308 config.setStaticRoute(staticRoute);
309 config.setNextHop(nextHop);
310 Status addStaticRouteResult = staticRouting.addStaticRoute(config);
311 if (addStaticRouteResult.isSuccess()) {
312 result.setStatus(true);
313 result.setMessage("Static Route saved successfully");
315 result.setStatus(false);
316 result.setMessage(addStaticRouteResult.getDescription());
318 } catch (Exception e) {
319 result.setStatus(false);
320 result.setMessage("Error - " + e.getMessage());
325 @RequestMapping(value = "/staticRoute/delete", method = RequestMethod.GET)
327 public StatusJsonBean deleteStaticRoute(
328 @RequestParam("routesToDelete") String routesToDelete,
329 HttpServletRequest request,
330 @RequestParam(required = false) String container) {
331 String containerName = (container == null) ? GlobalConstants.DEFAULT
332 .toString() : container;
334 // Authorization check
335 String userName = request.getUserPrincipal().getName();
336 if (DaylightWebUtil.getContainerPrivilege(userName, containerName, this) != Privilege.WRITE) {
337 return unauthorizedMessage();
340 StatusJsonBean resultBean = new StatusJsonBean();
342 IForwardingStaticRouting staticRouting = (IForwardingStaticRouting) ServiceHelper
343 .getInstance(IForwardingStaticRouting.class, containerName,
345 String[] routes = routesToDelete.split(",");
347 resultBean.setStatus(true);
349 .setMessage("Successfully deleted selected static routes");
350 for (String route : routes) {
351 result = staticRouting.removeStaticRoute(route);
352 if (!result.isSuccess()) {
353 resultBean.setStatus(false);
354 resultBean.setMessage(result.getDescription());
358 } catch (Exception e) {
359 resultBean.setStatus(false);
361 .setMessage("Error occurred while deleting static routes. "
367 @RequestMapping(value = "/subnets", method = RequestMethod.GET)
369 public DevicesJsonBean getSubnetGateways(HttpServletRequest request,
370 @RequestParam(required = false) String container) {
371 Gson gson = new Gson();
372 List<Map<String, String>> subnets = new ArrayList<Map<String, String>>();
373 String containerName = (container == null) ? GlobalConstants.DEFAULT
374 .toString() : container;
376 // Derive the privilege this user has on the current container
377 String userName = request.getUserPrincipal().getName();
378 Privilege privilege = DaylightWebUtil.getContainerPrivilege(
379 userName, containerName, this);
381 if (privilege != Privilege.NONE) {
382 ISwitchManager switchManager = (ISwitchManager) ServiceHelper
383 .getInstance(ISwitchManager.class, containerName, this);
384 if (switchManager != null) {
385 for (SubnetConfig conf : switchManager.getSubnetsConfigList()) {
386 Map<String, String> subnet = new HashMap<String, String>();
387 subnet.put("name", conf.getName());
388 subnet.put("subnet", conf.getSubnet());
389 subnet.put("json", gson.toJson(conf));
394 DevicesJsonBean result = new DevicesJsonBean();
395 result.setPrivilege(privilege);
396 result.setColumnNames(SubnetConfig.getGuiFieldsNames());
397 result.setNodeData(subnets);
401 @RequestMapping(value = "/subnetGateway/add", method = RequestMethod.GET)
403 public StatusJsonBean addSubnetGateways(
404 @RequestParam("gatewayName") String gatewayName,
405 @RequestParam("gatewayIPAddress") String gatewayIPAddress,
406 HttpServletRequest request,
407 @RequestParam(required = false) String container) {
408 String containerName = (container == null) ? GlobalConstants.DEFAULT
409 .toString() : container;
411 // Authorization check
412 String userName = request.getUserPrincipal().getName();
413 if (DaylightWebUtil.getContainerPrivilege(userName, containerName, this) != Privilege.WRITE) {
414 return unauthorizedMessage();
417 StatusJsonBean resultBean = new StatusJsonBean();
419 ISwitchManager switchManager = (ISwitchManager) ServiceHelper
420 .getInstance(ISwitchManager.class, containerName, this);
421 SubnetConfig cfgObject = new SubnetConfig(gatewayName,
422 gatewayIPAddress, new ArrayList<String>());
423 Status result = switchManager.addSubnet(cfgObject);
424 if (result.isSuccess()) {
425 resultBean.setStatus(true);
426 resultBean.setMessage("Added gateway address successfully");
428 resultBean.setStatus(false);
429 resultBean.setMessage(result.getDescription());
431 } catch (Exception e) {
432 resultBean.setStatus(false);
433 resultBean.setMessage(e.getMessage());
438 @RequestMapping(value = "/subnetGateway/delete", method = RequestMethod.GET)
440 public StatusJsonBean deleteSubnetGateways(
441 @RequestParam("gatewaysToDelete") String gatewaysToDelete,
442 HttpServletRequest request,
443 @RequestParam(required = false) String container) {
444 String containerName = (container == null) ? GlobalConstants.DEFAULT
445 .toString() : container;
447 // Authorization check
448 String userName = request.getUserPrincipal().getName();
449 if (DaylightWebUtil.getContainerPrivilege(userName, container, this) != Privilege.WRITE) {
450 return unauthorizedMessage();
453 StatusJsonBean resultBean = new StatusJsonBean();
455 ISwitchManager switchManager = (ISwitchManager) ServiceHelper
456 .getInstance(ISwitchManager.class, containerName, this);
457 String[] subnets = gatewaysToDelete.split(",");
458 resultBean.setStatus(true);
459 resultBean.setMessage("Added gateway address successfully");
460 for (String subnet : subnets) {
461 Status result = switchManager.removeSubnet(subnet);
462 if (!result.isSuccess()) {
463 resultBean.setStatus(false);
464 resultBean.setMessage(result.getDescription());
468 } catch (Exception e) {
469 resultBean.setStatus(false);
470 resultBean.setMessage(e.getMessage());
475 @RequestMapping(value = "/subnetGateway/ports/add", method = RequestMethod.GET)
477 public StatusJsonBean addSubnetGatewayPort(
478 @RequestParam("portsName") String portsName,
479 @RequestParam("ports") String ports,
480 @RequestParam("nodeId") String nodeId, HttpServletRequest request,
481 @RequestParam(required = false) String container) {
482 String containerName = (container == null) ? GlobalConstants.DEFAULT
483 .toString() : container;
485 // Authorization check
486 String userName = request.getUserPrincipal().getName();
487 if (DaylightWebUtil.getContainerPrivilege(userName, containerName, this) != Privilege.WRITE) {
488 return unauthorizedMessage();
491 StatusJsonBean resultBean = new StatusJsonBean();
493 ISwitchManager switchManager = (ISwitchManager) ServiceHelper
494 .getInstance(ISwitchManager.class, containerName, this);
495 Status result = switchManager.addPortsToSubnet(portsName, nodeId
498 if (result.isSuccess()) {
499 resultBean.setStatus(true);
501 .setMessage("Added ports to subnet gateway address successfully");
503 resultBean.setStatus(false);
504 resultBean.setMessage(result.getDescription());
506 } catch (Exception e) {
507 resultBean.setStatus(false);
508 resultBean.setMessage(e.getMessage());
513 @RequestMapping(value = "/subnetGateway/ports/delete", method = RequestMethod.GET)
515 public StatusJsonBean deleteSubnetGatewayPort(
516 @RequestParam("gatewayName") String gatewayName,
517 @RequestParam("nodePort") String nodePort,
518 HttpServletRequest request,
519 @RequestParam(required = false) String container) {
520 String containerName = (container == null) ? GlobalConstants.DEFAULT
521 .toString() : container;
523 // Authorization check
524 String userName = request.getUserPrincipal().getName();
525 if (DaylightWebUtil.getContainerPrivilege(userName, containerName, this) != Privilege.WRITE) {
526 return unauthorizedMessage();
529 StatusJsonBean resultBean = new StatusJsonBean();
531 ISwitchManager switchManager = (ISwitchManager) ServiceHelper
532 .getInstance(ISwitchManager.class, containerName, this);
533 Status result = switchManager.removePortsFromSubnet(gatewayName,
536 if (result.isSuccess()) {
537 resultBean.setStatus(true);
539 .setMessage("Deleted port from subnet gateway address successfully");
541 resultBean.setStatus(false);
542 resultBean.setMessage(result.getDescription());
544 } catch (Exception e) {
545 resultBean.setStatus(false);
546 resultBean.setMessage(e.getMessage());
551 @RequestMapping(value = "/spanPorts", method = RequestMethod.GET)
553 public DevicesJsonBean getSpanPorts(HttpServletRequest request,
554 @RequestParam(required = false) String container) {
555 Gson gson = new Gson();
556 List<Map<String, String>> spanConfigs = new ArrayList<Map<String, String>>();
557 String containerName = (container == null) ? GlobalConstants.DEFAULT
558 .toString() : container;
560 // Derive the privilege this user has on the current container
561 String userName = request.getUserPrincipal().getName();
562 Privilege privilege = DaylightWebUtil.getContainerPrivilege(
563 userName, containerName, this);
565 if (privilege != Privilege.NONE) {
566 List<String> spanConfigs_json = new ArrayList<String>();
567 ISwitchManager switchManager = (ISwitchManager) ServiceHelper
568 .getInstance(ISwitchManager.class, containerName, this);
569 if (switchManager != null) {
570 for (SpanConfig conf : switchManager.getSpanConfigList()) {
571 spanConfigs_json.add(gson.toJson(conf));
574 ObjectMapper mapper = new ObjectMapper();
576 for (String config_json : spanConfigs_json) {
578 @SuppressWarnings("unchecked")
579 Map<String, String> config_data = mapper.readValue(config_json,
581 Map<String, String> config = new HashMap<String, String>();
582 for (String name : config_data.keySet()) {
583 config.put(name, config_data.get(name));
584 // Add switch name value (non-configuration field)
585 config.put("nodeName",
586 getNodeDesc(config_data.get("nodeId"), containerName));
588 config.put("json", config_json);
589 spanConfigs.add(config);
590 } catch (Exception e) {
591 // TODO: Handle the exception.
596 DevicesJsonBean result = new DevicesJsonBean();
597 result.setPrivilege(privilege);
598 result.setColumnNames(SpanConfig.getGuiFieldsNames());
599 result.setNodeData(spanConfigs);
603 @RequestMapping(value = "/nodeports")
605 public Map<String, Object> getNodePorts(HttpServletRequest request,
606 @RequestParam(required = false) String container) {
607 String containerName = (container == null) ? GlobalConstants.DEFAULT
608 .toString() : container;
610 // Derive the privilege this user has on the current container
611 String userName = request.getUserPrincipal().getName();
612 if (DaylightWebUtil.getContainerPrivilege(userName, containerName, this) == Privilege.NONE) {
617 ISwitchManager switchManager = (ISwitchManager) ServiceHelper
618 .getInstance(ISwitchManager.class, containerName, this);
619 if (switchManager == null) {
623 Map<String, Object> nodes = new HashMap<String, Object>();
624 Map<Short, String> port;
626 for (Switch node : switchManager.getNetworkDevices()) {
627 port = new HashMap<Short, String>(); // new port
628 Set<NodeConnector> nodeConnectorSet = node.getNodeConnectors();
630 if (nodeConnectorSet != null) {
631 for (NodeConnector nodeConnector : nodeConnectorSet) {
632 String nodeConnectorName = ((Name) switchManager
633 .getNodeConnectorProp(nodeConnector,
634 Name.NamePropName)).getValue();
635 port.put((Short) nodeConnector.getID(), nodeConnectorName
636 + "(" + nodeConnector.getID() + ")");
640 nodes.put(node.getNode().toString(), port);
646 @RequestMapping(value = "/spanPorts/add", method = RequestMethod.GET)
648 public StatusJsonBean addSpanPort(
649 @RequestParam("jsonData") String jsonData,
650 HttpServletRequest request,
651 @RequestParam(required = false) String container) {
652 String containerName = (container == null) ? GlobalConstants.DEFAULT
653 .toString() : container;
655 // Authorization check
656 String userName = request.getUserPrincipal().getName();
657 if (DaylightWebUtil.getContainerPrivilege(userName, containerName, this) != Privilege.WRITE) {
658 return unauthorizedMessage();
661 StatusJsonBean resultBean = new StatusJsonBean();
663 Gson gson = new Gson();
664 ISwitchManager switchManager = (ISwitchManager) ServiceHelper
665 .getInstance(ISwitchManager.class, containerName, this);
666 SpanConfig cfgObject = gson.fromJson(jsonData, SpanConfig.class);
667 Status result = switchManager.addSpanConfig(cfgObject);
668 if (result.isSuccess()) {
669 resultBean.setStatus(true);
670 resultBean.setMessage("SPAN Port added successfully");
672 resultBean.setStatus(false);
673 resultBean.setMessage(result.getDescription());
675 } catch (Exception e) {
676 resultBean.setStatus(false);
677 resultBean.setMessage("Error occurred while adding span port. "
683 @RequestMapping(value = "/spanPorts/delete", method = RequestMethod.GET)
685 public StatusJsonBean deleteSpanPorts(
686 @RequestParam("spanPortsToDelete") String spanPortsToDelete,
687 HttpServletRequest request,
688 @RequestParam(required = false) String container) {
689 String containerName = (container == null) ? GlobalConstants.DEFAULT
690 .toString() : container;
692 // Authorization check
693 String userName = request.getUserPrincipal().getName();
694 if (DaylightWebUtil.getContainerPrivilege(userName, containerName, this) != Privilege.WRITE) {
695 return unauthorizedMessage();
698 StatusJsonBean resultBean = new StatusJsonBean();
700 Gson gson = new Gson();
701 ISwitchManager switchManager = (ISwitchManager) ServiceHelper
702 .getInstance(ISwitchManager.class, containerName, this);
703 String[] spans = spanPortsToDelete.split("###");
704 resultBean.setStatus(true);
705 resultBean.setMessage("SPAN Port(s) deleted successfully");
706 for (String span : spans) {
707 if (!span.isEmpty()) {
708 SpanConfig cfgObject = gson
709 .fromJson(span, SpanConfig.class);
710 Status result = switchManager.removeSpanConfig(cfgObject);
711 if (!result.isSuccess()) {
712 resultBean.setStatus(false);
713 resultBean.setMessage(result.getDescription());
718 } catch (Exception e) {
719 resultBean.setStatus(false);
720 resultBean.setMessage("Error occurred while deleting span port. "
726 private String getNodeDesc(String nodeId, String containerName) {
727 ISwitchManager switchManager = (ISwitchManager) ServiceHelper
728 .getInstance(ISwitchManager.class, containerName, this);
729 String description = "";
730 if (switchManager != null) {
731 description = switchManager.getNodeDescription(Node
732 .fromString(nodeId));
734 return (description.isEmpty() || description.equalsIgnoreCase("none")) ? nodeId
738 private StatusJsonBean unauthorizedMessage() {
739 StatusJsonBean message = new StatusJsonBean();
740 message.setStatus(false);
741 message.setMessage("Operation not authorized");
745 @RequestMapping(value = "login")
746 public String login(final HttpServletRequest request,
747 final HttpServletResponse response) {
748 // response.setHeader("X-Page-Location", "/login");
750 * IUserManager userManager = (IUserManager) ServiceHelper
751 * .getGlobalInstance(IUserManager.class, this); if (userManager ==
752 * null) { return "User Manager is not available"; }
754 * String username = request.getUserPrincipal().getName();
757 * model.addAttribute("username", username); model.addAttribute("role",
758 * userManager.getUserLevel(username).toNumber());
760 return "forward:" + "/";