- private String getNodeDesc(String nodeId, String containerName) {
- ISwitchManager switchManager = (ISwitchManager) ServiceHelper
- .getInstance(ISwitchManager.class, containerName, this);
- String description = "";
- if (switchManager != null) {
- description = switchManager.getNodeDescription(Node
- .fromString(nodeId));
+ @RequestMapping(value = "/connect/nodes", method = RequestMethod.GET)
+ @ResponseBody
+ public List<NodeJsonBean> getNodes(HttpServletRequest request) {
+ IConnectionManager connectionManager = (IConnectionManager) ServiceHelper.getGlobalInstance(
+ IConnectionManager.class, this);
+ if (connectionManager == null) {
+ return null;
+ }
+ ISwitchManager switchManager = (ISwitchManager) ServiceHelper.getInstance(ISwitchManager.class,
+ GlobalConstants.DEFAULT.toString(), this);
+ if (switchManager == null) {
+ return null;
+ }
+
+ Set<Node> nodes = connectionManager.getLocalNodes();
+ List<NodeJsonBean> result = new LinkedList<NodeJsonBean>();
+ if (nodes == null) {
+ return result;
+ }
+ for (Node node : nodes) {
+ Description descriptionProperty = (Description) switchManager.getNodeProp(node, "description");
+ String description = node.toString();
+ if (descriptionProperty != null) {
+ description = descriptionProperty.getValue();
+ }
+ NodeJsonBean nodeBean = new NodeJsonBean();
+ nodeBean.setNodeId(node.getNodeIDString());
+ nodeBean.setNodeType(node.getType());
+ if (description.equals("None")) {
+ nodeBean.setNodeName(node.toString());
+ } else {
+ nodeBean.setNodeName(description);
+ }
+ result.add(nodeBean);
+ }
+
+ return result;
+ }
+
+ @RequestMapping(value = "/connect/{nodeId}", method = RequestMethod.POST)
+ @ResponseBody
+ public Status addNode(HttpServletRequest request, @PathVariable("nodeId") String nodeId,
+ @RequestParam(required = true) String ipAddress, @RequestParam(required = true) String port,
+ @RequestParam(required = false) String nodeType) {
+ IConnectionManager connectionManager = (IConnectionManager) ServiceHelper.getGlobalInstance(
+ IConnectionManager.class, this);
+ if (connectionManager == null) {
+ return new Status(StatusCode.NOTFOUND, "Service not found");
+ }
+
+ if (!NetUtils.isIPv4AddressValid(ipAddress)) {
+ return new Status(StatusCode.NOTACCEPTABLE, "Invalid IP Address: " + ipAddress);
+ }
+
+ try {
+ Integer.parseInt(port);
+ } catch (Exception e) {
+ return new Status(StatusCode.NOTACCEPTABLE, "Invalid Layer 4 Port: " + port);