@Override protected Object doExecute() throws Exception { // check if the group exists Group group = groupManager.findGroupByName(groupName); if (group == null) { System.err.println("Cluster group " + groupName + " doesn't exist"); return null; } // check if the group doesn't contain nodes if (group.getNodes() != null && !group.getNodes().isEmpty()) { System.err.println("Cluster group " + groupName + " is not empty"); return null; } groupManager.deleteGroup(groupName); return null; }
@Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { boolean success = false; final String action = req.getParameter("action"); final String node = req.getParameter("node"); final String group = req.getParameter("group"); final String id = req.getParameter("id"); if (action == null) { success = true; } else if (action.equals("createGroup")) { groupManager.createGroup(group); success = true; } else if (action.equals("deleteGroup")) { groupManager.deleteGroup(group); success = true; } if (success) { // let's wait a little bit to give the framework time // to process our request try { Thread.sleep(800); } catch (InterruptedException e) { // ignore } this.renderJSON(resp, null); } else { super.doPost(req, resp); } }
@Override public void delete(String name) throws Exception { ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); Group g = groupManager.findGroupByName(name); List<String> nodes = new LinkedList<String>(); if (g.getNodes() != null && !g.getNodes().isEmpty()) { for (Node n : g.getNodes()) { nodes.add(n.getId()); } ManageGroupCommand command = new ManageGroupCommand(clusterManager.generateId()); command.setAction(ManageGroupAction.QUIT); command.setGroupName(name); Set<Node> recipientList = clusterManager.listNodes(nodes); command.setDestination(recipientList); executionContext.execute(command); } groupManager.deleteGroup(name); } finally { Thread.currentThread().setContextClassLoader(originalClassLoader); } }
@Override public void delete(String name) throws Exception { ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); Group g = groupManager.findGroupByName(name); List<String> nodes = new LinkedList<String>(); if (g.getNodes() != null && !g.getNodes().isEmpty()) { for (Node n : g.getNodes()) { nodes.add(n.getId()); } ManageGroupCommand command = new ManageGroupCommand(clusterManager.generateId()); command.setAction(ManageGroupAction.QUIT); command.setGroupName(name); Set<Node> recipientList = clusterManager.listNodes(nodes); command.setDestination(recipientList); executionContext.execute(command); } groupManager.deleteGroup(name); } finally { Thread.currentThread().setContextClassLoader(originalClassLoader); } }