/** * Remove {@link Node} from all {@link Group}s. */ public void purgeGroups() { Node node = clusterManager.getNode(); Set<String> groupNames = groupManager.listGroupNames(node); if (groupNames != null && !groupNames.isEmpty()) { for (String targetGroupName : groupNames) { quitGroup(targetGroupName); } } }
/** * Remove {@link Node} from all {@link Group}s. */ public void purgeGroups() { Node node = clusterManager.getNode(); Set<String> groupNames = groupManager.listGroupNames(node); if (groupNames != null && !groupNames.isEmpty()) { for (String targetGroupName : groupNames) { quitGroup(targetGroupName); } } }
/** * 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); } } }
/** * 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 void doStart() throws Exception { ClusterManager clusterManager = getTrackedService(ClusterManager.class); if (clusterManager == null) return; String nodeId = clusterManager.getNode().getId(); GreeterImpl greeter = new GreeterImpl(nodeId); Hashtable props = new Hashtable(); props.put("service.exported.interfaces", "*"); register(Greeter.class, greeter, props); }
@Override public void handlerStart(String handlerId, String nodeIdOrAlias) throws Exception { ManageHandlersCommand command = new ManageHandlersCommand(clusterManager.generateId()); Set<Node> nodes = new HashSet<Node>(); if (nodeIdOrAlias == null || nodeIdOrAlias.isEmpty()) { nodes.add(clusterManager.getNode()); } else { Node node = clusterManager.findNodeByIdOrAlias(nodeIdOrAlias); if (node == null) { throw new IllegalArgumentException("Cluster node " + nodeIdOrAlias + " doesn't exist"); } nodes.add(node); } command.setHandlerName(handlerId); command.setDestination(nodes); command.setStatus(Boolean.TRUE); }
@Override public void sendEvent(Serializable eventObject) { Event event = (Event) eventObject; event.setSourceGroup(group); event.setSourceNode(karafCellarClusterManager.getNode()); karafCellarEventProducer.produce(event); }
@Override public void producerStart(String nodeIdOrAlias) throws Exception { ProducerSwitchCommand command = new ProducerSwitchCommand(clusterManager.generateId()); Set<Node> nodes = new HashSet<Node>(); if (nodeIdOrAlias == null || nodeIdOrAlias.isEmpty()) { nodes.add(clusterManager.getNode()); } else { Node node = clusterManager.findNodeByIdOrAlias(nodeIdOrAlias); if (node == null) { throw new IllegalArgumentException("Cluster node " + nodeIdOrAlias + " doesn't exist)"); } nodes.add(node); } command.setDestination(nodes); command.setStatus(SwitchStatus.ON); executionContext.execute(command); }
@Override public void consumerStop(String nodeIdOrAlias) throws Exception { ConsumerSwitchCommand command = new ConsumerSwitchCommand(clusterManager.generateId()); Set<Node> nodes = new HashSet<Node>(); if (nodeIdOrAlias == null || nodeIdOrAlias.isEmpty()) { nodes.add(clusterManager.getNode()); } else { Node node = clusterManager.findNodeByIdOrAlias(nodeIdOrAlias); if (node == null) { throw new IllegalArgumentException("Cluster node " + nodeIdOrAlias + " doesn't exist"); } nodes.add(node); } command.setDestination(nodes); command.setStatus(SwitchStatus.OFF); executionContext.execute(command); }
@Override public void sendEvent(Serializable eventObject) { Event event = (Event) eventObject; event.setSourceGroup(group); event.setSourceNode(karafCellarClusterManager.getNode()); karafCellarEventProducer.produce(event); }
@Override public void consumerStart(String nodeIdOrAlias) throws Exception { ConsumerSwitchCommand command = new ConsumerSwitchCommand(clusterManager.generateId()); Set<Node> nodes = new HashSet<Node>(); if (nodeIdOrAlias == null || nodeIdOrAlias.isEmpty()) { nodes.add(clusterManager.getNode()); } else { Node node = clusterManager.findNodeByIdOrAlias(nodeIdOrAlias); if (node == null) { throw new IllegalArgumentException("Cluster node " + nodeIdOrAlias + " doesn't exist"); } nodes.add(node); } command.setDestination(nodes); command.setStatus(SwitchStatus.ON); executionContext.execute(command); }
@Override public void producerStart(String nodeIdOrAlias) throws Exception { ProducerSwitchCommand command = new ProducerSwitchCommand(clusterManager.generateId()); Set<Node> nodes = new HashSet<Node>(); if (nodeIdOrAlias == null || nodeIdOrAlias.isEmpty()) { nodes.add(clusterManager.getNode()); } else { Node node = clusterManager.findNodeByIdOrAlias(nodeIdOrAlias); if (node == null) { throw new IllegalArgumentException("Cluster node " + nodeIdOrAlias + " doesn't exist)"); } nodes.add(node); } command.setDestination(nodes); command.setStatus(SwitchStatus.ON); executionContext.execute(command); }
@Override public void handlerStart(String handlerId, String nodeIdOrAlias) throws Exception { ManageHandlersCommand command = new ManageHandlersCommand(clusterManager.generateId()); Set<Node> nodes = new HashSet<Node>(); if (nodeIdOrAlias == null || nodeIdOrAlias.isEmpty()) { nodes.add(clusterManager.getNode()); } else { Node node = clusterManager.findNodeByIdOrAlias(nodeIdOrAlias); if (node == null) { throw new IllegalArgumentException("Cluster node " + nodeIdOrAlias + " doesn't exist"); } nodes.add(node); } command.setHandlerName(handlerId); command.setDestination(nodes); command.setStatus(Boolean.TRUE); }
@Override public void producerStop(String nodeIdOrAlias) throws Exception { ProducerSwitchCommand command = new ProducerSwitchCommand(clusterManager.generateId()); Set<Node> nodes = new HashSet<Node>(); if (nodeIdOrAlias == null || nodeIdOrAlias.isEmpty()) { nodes.add(clusterManager.getNode()); } else { Node node = clusterManager.findNodeByIdOrAlias(nodeIdOrAlias); if (node == null) { throw new IllegalArgumentException("Cluster node " + nodeIdOrAlias + " doesn't exist"); } nodes.add(node); } command.setDestination(nodes); command.setStatus(SwitchStatus.OFF); executionContext.execute(command); }
@Override public void handlerStop(String handlerId, String nodeIdOrAlias) throws Exception { ManageHandlersCommand command = new ManageHandlersCommand(clusterManager.generateId()); Set<Node> nodes = new HashSet<Node>(); if (nodeIdOrAlias == null || nodeIdOrAlias.isEmpty()) { nodes.add(clusterManager.getNode()); } else { Node node = clusterManager.findNodeByIdOrAlias(nodeIdOrAlias); if (node == null) { throw new IllegalArgumentException("Cluster node " + nodeIdOrAlias + " doesn't exist"); } nodes.add(node); } command.setHandlerName(handlerId); command.setDestination(nodes); command.setStatus(Boolean.FALSE); }
@Override public void consumerStart(String nodeIdOrAlias) throws Exception { ConsumerSwitchCommand command = new ConsumerSwitchCommand(clusterManager.generateId()); Set<Node> nodes = new HashSet<Node>(); if (nodeIdOrAlias == null || nodeIdOrAlias.isEmpty()) { nodes.add(clusterManager.getNode()); } else { Node node = clusterManager.findNodeByIdOrAlias(nodeIdOrAlias); if (node == null) { throw new IllegalArgumentException("Cluster node " + nodeIdOrAlias + " doesn't exist"); } nodes.add(node); } command.setDestination(nodes); command.setStatus(SwitchStatus.ON); executionContext.execute(command); }
@Override public void consumerStop(String nodeIdOrAlias) throws Exception { ConsumerSwitchCommand command = new ConsumerSwitchCommand(clusterManager.generateId()); Set<Node> nodes = new HashSet<Node>(); if (nodeIdOrAlias == null || nodeIdOrAlias.isEmpty()) { nodes.add(clusterManager.getNode()); } else { Node node = clusterManager.findNodeByIdOrAlias(nodeIdOrAlias); if (node == null) { throw new IllegalArgumentException("Cluster node " + nodeIdOrAlias + " doesn't exist"); } nodes.add(node); } command.setDestination(nodes); command.setStatus(SwitchStatus.OFF); executionContext.execute(command); }
@Override public void producerStop(String nodeIdOrAlias) throws Exception { ProducerSwitchCommand command = new ProducerSwitchCommand(clusterManager.generateId()); Set<Node> nodes = new HashSet<Node>(); if (nodeIdOrAlias == null || nodeIdOrAlias.isEmpty()) { nodes.add(clusterManager.getNode()); } else { Node node = clusterManager.findNodeByIdOrAlias(nodeIdOrAlias); if (node == null) { throw new IllegalArgumentException("Cluster node " + nodeIdOrAlias + " doesn't exist"); } nodes.add(node); } command.setDestination(nodes); command.setStatus(SwitchStatus.OFF); executionContext.execute(command); }
@Override public TabularData getNodes() throws Exception { CompositeType nodeType = new CompositeType("Node", "Karaf Cellar cluster node", new String[]{ "id", "alias", "hostname", "port", "local" }, new String[]{ "ID of the node", "Alias of the node", "Hostname of the node", "Port number of the node", "Flag defining if the node is local" }, new OpenType[]{ SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.INTEGER, SimpleType.BOOLEAN }); TabularType tableType = new TabularType("Nodes", "Table of all Karaf Cellar nodes", nodeType, new String[]{ "id" }); TabularData table = new TabularDataSupport(tableType); Set<Node> nodes = clusterManager.listNodes(); for (Node node : nodes) { boolean local = (node.equals(clusterManager.getNode())); CompositeData data = new CompositeDataSupport(nodeType, new String[]{ "id", "alias", "hostname", "port", "local" }, new Object[]{ node.getId(), node.getAlias(), node.getHost(), node.getPort(), local }); table.put(data); } return table; }
@Override public TabularData getNodes() throws Exception { CompositeType nodeType = new CompositeType("Node", "Karaf Cellar cluster node", new String[]{ "id", "alias", "hostname", "port", "local" }, new String[]{ "ID of the node", "Alias of the node", "Hostname of the node", "Port number of the node", "Flag defining if the node is local" }, new OpenType[]{ SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.INTEGER, SimpleType.BOOLEAN }); TabularType tableType = new TabularType("Nodes", "Table of all Karaf Cellar nodes", nodeType, new String[]{ "id" }); TabularData table = new TabularDataSupport(tableType); Set<Node> nodes = clusterManager.listNodes(); for (Node node : nodes) { boolean local = (node.equals(clusterManager.getNode())); CompositeData data = new CompositeDataSupport(nodeType, new String[]{ "id", "alias", "hostname", "port", "local" }, new Object[]{ node.getId(), node.getAlias(), node.getHost(), node.getPort(), local }); table.put(data); } return table; }