/** * List the nodes in a given cluster group. * * @param group the cluster group. * @return a Set with the nodes. */ @Override public Set<Node> listNodesByGroup(Group group) { return group.getNodes(); }
/** * List the nodes in a given cluster group. * * @param group the cluster group. * @return a Set with the nodes. */ @Override public Set<Node> listNodesByGroup(Group group) { return group.getNodes(); }
/** * Add cluster groups where the local node is belonging. * * @param group the cluster group candidate for completion. * @return true if the cluster group has been accepted, false else. */ @Override protected boolean acceptsGroup(Group group) { Node node = groupManager.getNode(); if (group.getNodes().contains(node)) return true; else return false; }
/** * Accept the cluster groups which don't include the local node. * * @param group the cluster group to check. * @return true if the cluster group doesn't include the local node, false else. */ @Override protected boolean acceptsGroup(Group group) { Node node = groupManager.getNode(); if (group.getNodes().contains(node)) return false; else return true; }
/** * Accept the cluster groups which don't include the local node. * * @param group the cluster group to check. * @return true if the cluster group doesn't include the local node, false else. */ @Override protected boolean acceptsGroup(Group group) { Node node = groupManager.getNode(); if (group.getNodes().contains(node)) return false; else return true; }
/** * Add cluster groups where the local node is belonging. * * @param group the cluster group candidate for completion. * @return true if the cluster group has been accepted, false else. */ @Override protected boolean acceptsGroup(Group group) { Node node = groupManager.getNode(); if (group.getNodes().contains(node)) return true; else return false; }
@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; }
/** * 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 Set<String> listGroupNames(Node node) { Set<String> names = new HashSet<String>(); ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(combinedClassLoader); Map<String, Group> groups = listGroups(); if (groups != null && !groups.isEmpty()) { for (Group group : groups.values()) { if (group.getNodes().contains(node)) { names.add(group.getName()); } } } } finally { Thread.currentThread().setContextClassLoader(originalClassLoader); } return names; }
@Override public Set<String> listGroupNames(Node node) { Set<String> names = new HashSet<String>(); ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(combinedClassLoader); Map<String, Group> groups = listGroups(); if (groups != null && !groups.isEmpty()) { for (Group group : groups.values()) { if (group.getNodes().contains(node)) { names.add(group.getName()); } } } } finally { Thread.currentThread().setContextClassLoader(originalClassLoader); } return names; }
/** * 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 Map<String, Group> listGroups() { ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader(); try { Map<String, Group> res = new HashMap<String, Group>(); Thread.currentThread().setContextClassLoader(combinedClassLoader); Map<Node, Set<String>> nodes = getClusterGroups(); Set<String> groups = convertStringToSet((String) localConfig.get(Configurations.GROUPS_KEY)); groups.add(Configurations.DEFAULT_GROUP_NAME); for (String groupName : groups) { Group group = new Group(groupName); res.put(groupName, group); for (Map.Entry<Node, Set<String>> entry : nodes.entrySet()) { if (entry.getValue().contains(groupName)) { group.getNodes().add(entry.getKey()); } } } return res; } finally { Thread.currentThread().setContextClassLoader(originalClassLoader); } }
@Override public Map<String, Group> listGroups() { ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader(); try { Map<String, Group> res = new HashMap<String, Group>(); Thread.currentThread().setContextClassLoader(combinedClassLoader); Map<Node, Set<String>> nodes = getClusterGroups(); Set<String> groups = convertStringToSet((String) localConfig.get(Configurations.GROUPS_KEY)); groups.add(Configurations.DEFAULT_GROUP_NAME); for (String groupName : groups) { Group group = new Group(groupName); res.put(groupName, group); for (Map.Entry<Node, Set<String>> entry : nodes.entrySet()) { if (entry.getValue().contains(groupName)) { group.getNodes().add(entry.getKey()); } } } return res; } finally { Thread.currentThread().setContextClassLoader(originalClassLoader); } }
/** * 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); } } }
/** * 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 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); } }
@Override protected Object doExecute() throws Exception { Group sourceGroup = groupManager.findGroupByName(sourceGroupName); if (sourceGroup == null) { System.err.println("Source cluster group " + sourceGroupName + " doesn't exist"); return null; } Group targetGroup = groupManager.findGroupByName(targetGroupName); if (targetGroup == null) { System.err.println("Target cluster group " + targetGroupName + " doesn't exist"); return null; } Set<Node> groupMembers = sourceGroup.getNodes(); if (count > groupMembers.size()) count = groupMembers.size(); int i = 0; for (Node node : groupMembers) { if (i >= count) break; List<String> recipients = new LinkedList<String>(); recipients.add(node.getId()); doExecute(ManageGroupAction.SET, targetGroupName, sourceGroup, recipients); i++; } return doExecute(ManageGroupAction.LIST, null, null, new ArrayList(), false); }
@Override public TabularData getGroups() throws Exception { Set<Group> allGroups = groupManager.listAllGroups(); CompositeType groupType = new CompositeType("Group", "Karaf Cellar cluster group", new String[]{ "name", "members"}, new String[]{ "Name of the cluster group", "Members of the cluster group" }, new OpenType[]{ SimpleType.STRING, SimpleType.STRING }); TabularType tableType = new TabularType("Groups", "Table of all Karaf Cellar groups", groupType, new String[]{ "name" }); TabularData table = new TabularDataSupport(tableType); for (Group group : allGroups) { StringBuffer members = new StringBuffer(); for (Node node : group.getNodes()) { // display only up and running nodes in the cluster if (clusterManager.findNodeById(node.getId()) != null) { if (node.getAlias() != null) { members.append(node.getAlias()); } else { members.append(node.getId()); } members.append(" "); } } CompositeData data = new CompositeDataSupport(groupType, new String[]{ "name", "members" }, new Object[]{ group.getName(), members.toString() }); table.put(data); } return table; }
@Override public TabularData getGroups() throws Exception { Set<Group> allGroups = groupManager.listAllGroups(); CompositeType groupType = new CompositeType("Group", "Karaf Cellar cluster group", new String[]{ "name", "members"}, new String[]{ "Name of the cluster group", "Members of the cluster group" }, new OpenType[]{ SimpleType.STRING, SimpleType.STRING }); TabularType tableType = new TabularType("Groups", "Table of all Karaf Cellar groups", groupType, new String[]{ "name" }); TabularData table = new TabularDataSupport(tableType); for (Group group : allGroups) { StringBuffer members = new StringBuffer(); for (Node node : group.getNodes()) { // display only up and running nodes in the cluster if (clusterManager.findNodeById(node.getId()) != null) { if (node.getAlias() != null) { members.append(node.getAlias()); } else { members.append(node.getId()); } members.append(" "); } } CompositeData data = new CompositeDataSupport(groupType, new String[]{ "name", "members" }, new Object[]{ group.getName(), members.toString() }); table.put(data); } return table; }