@Override protected Object doExecute() throws Exception { Group group = groupManager.findGroupByName(groupName); if (group == null) { System.err.println("Cluster group " + groupName + " doesn't exist"); return null; } return doExecute(ManageGroupAction.JOIN, groupName, null, nodes,false); }
public void init(BundleContext bundleContext) { // wait the end of Karaf boot process ServiceTracker tracker = new ServiceTracker(bundleContext, BootFinished.class, null); try { tracker.waitForService(120000); } catch (Exception e) { LOGGER.warn("Can't start BootFinished service tracker", e); } if (groupManager == null) return; Set<Group> groups = groupManager.listLocalGroups(); if (groups != null && !groups.isEmpty()) { for (Group group : groups) { sync(group); } } }
@Override public void create(String name) throws Exception { // check if the group exists Group group = groupManager.findGroupByName(name); if (group != null) { throw new IllegalArgumentException("Cluster group " + name + " already exists"); } groupManager.createGroup(name); }
@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; }
/** * Add {@link Node} to the target {@link Group}. * * @param targetGroupName the target group name where to add the node. */ public void joinGroup(String targetGroupName) { Node node = clusterManager.getNode(); Map<String, Group> groups = groupManager.listGroups(); if (groups != null && !groups.isEmpty()) { Group targetGroup = groups.get(targetGroupName); if (targetGroup == null) { groupManager.registerGroup(targetGroupName); } else if (!targetGroup.getNodes().contains(node)) { targetGroup.getNodes().add(node); groupManager.listGroups().put(targetGroupName, targetGroup); groupManager.registerGroup(targetGroup); } } }
if (!groupManager.isLocalGroup(event.getSourceGroup().getName())) { LOGGER.debug("CELLAR HTTP BALANCER: node is not part of the event cluster group {}", event.getSourceGroup().getName()); return;
groups = groupManager.listLocalGroups(); } else { groups = new HashSet<Group>(); if (groupManager.findGroupByName(groupName) == null) { System.err.println("Cluster group " + groupName + " doesn't exist"); return null; groups.add(groupManager.findGroupByName(groupName));
@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); } }
/** * Add the {@link Group} list to the result. * * @param result the result where to add the group list. */ public void addGroupListToResult(ManageGroupResult result) { Set<Group> groups = groupManager.listAllGroups(); for (Group g : groups) { if (g.getName() != null && !g.getName().isEmpty()) { result.getGroups().add(g); } } }
/** * Remove a {@link Node} from the target {@link Group}. * * @param targetGroupName the target group name where to remove the node. */ public void quitGroup(String targetGroupName) { Node node = clusterManager.getNode(); Map<String, Group> groups = groupManager.listGroups(); if (groups != null && !groups.isEmpty()) { Group targetGroup = groups.get(targetGroupName); if (targetGroup.getNodes().contains(node)) { targetGroup.getNodes().remove(node); groupManager.unRegisterGroup(targetGroup); } } }
@Override public int complete(Session session, CommandLine commandLine, List<String> candidates) { StringsCompleter delegate = new StringsCompleter(); try { Map<String, Group> groups = groupManager.listGroups(); if (groups != null && !groups.isEmpty()) { for (String groupName : groups.keySet()) { Map<String, Properties> clusterConfigurations = clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + groupName); if (clusterConfigurations != null && !clusterConfigurations.isEmpty()) { for (String pid : clusterConfigurations.keySet()) { if (delegate.getStrings() != null && !delegate.getStrings().contains(pid)) { delegate.getStrings().add(pid); } } } } } } catch (Exception e) { // nothing to do } return delegate.complete(session, commandLine, candidates); }
if (!groupManager.isLocalGroup(event.getSourceGroup().getName())) { LOGGER.debug("CELLAR FEATURE: node is not part of the event cluster group"); return;
@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); } }
/** * Add the {@link Group} list to the result. * * @param result the result where to add the group list. */ public void addGroupListToResult(ManageGroupResult result) { Set<Group> groups = groupManager.listAllGroups(); for (Group g : groups) { if (g.getName() != null && !g.getName().isEmpty()) { result.getGroups().add(g); } } }
/** * Remove a {@link Node} from the target {@link Group}. * * @param targetGroupName the target group name where to remove the node. */ public void quitGroup(String targetGroupName) { Node node = clusterManager.getNode(); Map<String, Group> groups = groupManager.listGroups(); if (groups != null && !groups.isEmpty()) { Group targetGroup = groups.get(targetGroupName); if (targetGroup.getNodes().contains(node)) { targetGroup.getNodes().remove(node); groupManager.unRegisterGroup(targetGroup); } } }
/** * Add {@link Node} to the target {@link Group}. * * @param targetGroupName the target group name where to add the node. */ public void joinGroup(String targetGroupName) { Node node = clusterManager.getNode(); Map<String, Group> groups = groupManager.listGroups(); if (groups != null && !groups.isEmpty()) { Group targetGroup = groups.get(targetGroupName); if (targetGroup == null) { groupManager.registerGroup(targetGroupName); } else if (!targetGroup.getNodes().contains(node)) { targetGroup.getNodes().add(node); groupManager.listGroups().put(targetGroupName, targetGroup); groupManager.registerGroup(targetGroup); } } }
@Override public int complete(Session session, CommandLine commandLine, List<String> candidates) { StringsCompleter delegate = new StringsCompleter(); try { Map<String, Group> groups = groupManager.listGroups(); if (groups != null && !groups.isEmpty()) { for (String groupName : groups.keySet()) { Map<String, Properties> clusterConfigurations = clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + groupName); if (clusterConfigurations != null && !clusterConfigurations.isEmpty()) { for (String pid : clusterConfigurations.keySet()) { if (delegate.getStrings() != null && !delegate.getStrings().contains(pid)) { delegate.getStrings().add(pid); } } } } } } catch (Exception e) { // nothing to do } return delegate.complete(session, commandLine, candidates); }
@Override protected Object doExecute() throws Exception { Group group = groupManager.findGroupByName(groupName); if (group == null) { System.err.println("Cluster group " + groupName + " doesn't exist"); return null; } return doExecute(ManageGroupAction.QUIT, groupName, null, nodes, false); }
public void init(BundleContext bundleContext) { // wait the end of Karaf boot process ServiceTracker tracker = new ServiceTracker(bundleContext, BootFinished.class, null); try { tracker.waitForService(120000); } catch (Exception e) { LOGGER.warn("Can't start BootFinished service tracker", e); } if (groupManager == null) return; Set<Group> groups = groupManager.listLocalGroups(); if (groups != null && !groups.isEmpty()) { for (Group group : groups) { sync(group); } } }
@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 + " already exists"); return null; } groupManager.createGroup(groupName); return null; }