@Override public long pingNode(String nodeIdOrAlias) throws Exception { Node node = clusterManager.findNodeByIdOrAlias(nodeIdOrAlias); if (node == null) { throw new IllegalArgumentException("Cluster group " + nodeIdOrAlias + " doesn't exist"); } Long start = System.currentTimeMillis(); Ping ping = new Ping(clusterManager.generateId()); ping.setDestination(new HashSet(Arrays.asList(node))); executionContext.execute(ping); Long stop = System.currentTimeMillis(); return (stop - start); }
@Override public long pingNode(String nodeIdOrAlias) throws Exception { Node node = clusterManager.findNodeByIdOrAlias(nodeIdOrAlias); if (node == null) { throw new IllegalArgumentException("Cluster group " + nodeIdOrAlias + " doesn't exist"); } Long start = System.currentTimeMillis(); Ping ping = new Ping(clusterManager.generateId()); ping.setDestination(new HashSet(Arrays.asList(node))); executionContext.execute(ping); Long stop = System.currentTimeMillis(); return (stop - start); }
@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 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 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 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 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 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 quit(String groupName, String nodeIdOrAlias) throws Exception { Group group = groupManager.findGroupByName(groupName); if (group == null) { throw new IllegalArgumentException("Cluster group " + groupName + " doesn't exist"); } Node node = clusterManager.findNodeByIdOrAlias(nodeIdOrAlias); if (node == null) { throw new IllegalArgumentException("Cluster node " + nodeIdOrAlias + " doesn't exist"); } Set<Node> nodes = new HashSet<Node>(); nodes.add(node); ManageGroupCommand command = new ManageGroupCommand(clusterManager.generateId()); command.setAction(ManageGroupAction.QUIT); command.setGroupName(groupName); command.setDestination(nodes); executionContext.execute(command); }
public Object doExecute() throws Exception { if (nodeId != null && clusterManager.findNodeByIdOrAlias(nodeId) == null) { System.err.println("Node " + nodeId + " doesn't exist"); return null; } if (nodeId == null) { nodeId = clusterManager.getNode().getId(); } long timestamp = System.currentTimeMillis(); String id = clusterManager.generateId(); ClusterLogKey key = new ClusterLogKey(); key.setNodeId(nodeId); key.setTimeStamp(timestamp); key.setId(id); ClusterLogRecord record = new ClusterLogRecord(); record.setMessage(message); record.setLevel(level); ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); try { Map<ClusterLogKey, ClusterLogRecord> clusterLog = clusterManager.getMap(LogAppender.LOG_MAP); clusterLog.put(key, record); } finally { Thread.currentThread().setContextClassLoader(originalClassLoader); } return null; }
@Override public Object doExecute() throws Exception { SetLogCommand command = new SetLogCommand(clusterManager.generateId()); command.setTimeout(timeout * 1000); Set<Node> recipientList = new HashSet<Node>(); if (nodes != null && !nodes.isEmpty()) { for (String nodeId : nodes) { Node node = clusterManager.findNodeByIdOrAlias(nodeId); if (node == null) { System.err.println("Node " + nodeId + " doesn't exist"); } else { recipientList.add(node); } } } else { recipientList = clusterManager.listNodes(); } if (recipientList.size() < 1) return null; command.setDestination(recipientList); command.setLogger(logger); command.setLevel(level); Map<Node, SetLogResult> results = executionContext.execute(command); if (results == null || results.isEmpty()) { System.err.println("No result received within given timeout"); } return null; }
@Override public void join(String groupName, String nodeIdOrAlias) throws Exception { Group group = groupManager.findGroupByName(groupName); if (group == null) { throw new IllegalArgumentException("Cluster group " + groupName + " doesn't exist"); } Node node = clusterManager.findNodeByIdOrAlias(nodeIdOrAlias); if (node == null) { throw new IllegalArgumentException("Cluster node " + nodeIdOrAlias + " doesn't exist"); } Set<Node> nodes = new HashSet<Node>(); nodes.add(node); ManageGroupCommand command = new ManageGroupCommand(clusterManager.generateId()); command.setAction(ManageGroupAction.JOIN); command.setGroupName(groupName); command.setDestination(nodes); executionContext.execute(command); }
@Override public void join(String groupName, String nodeIdOrAlias) throws Exception { Group group = groupManager.findGroupByName(groupName); if (group == null) { throw new IllegalArgumentException("Cluster group " + groupName + " doesn't exist"); } Node node = clusterManager.findNodeByIdOrAlias(nodeIdOrAlias); if (node == null) { throw new IllegalArgumentException("Cluster node " + nodeIdOrAlias + " doesn't exist"); } Set<Node> nodes = new HashSet<Node>(); nodes.add(node); ManageGroupCommand command = new ManageGroupCommand(clusterManager.generateId()); command.setAction(ManageGroupAction.JOIN); command.setGroupName(groupName); command.setDestination(nodes); executionContext.execute(command); }
@Override public void quit(String groupName, String nodeIdOrAlias) throws Exception { Group group = groupManager.findGroupByName(groupName); if (group == null) { throw new IllegalArgumentException("Cluster group " + groupName + " doesn't exist"); } Node node = clusterManager.findNodeByIdOrAlias(nodeIdOrAlias); if (node == null) { throw new IllegalArgumentException("Cluster node " + nodeIdOrAlias + " doesn't exist"); } Set<Node> nodes = new HashSet<Node>(); nodes.add(node); ManageGroupCommand command = new ManageGroupCommand(clusterManager.generateId()); command.setAction(ManageGroupAction.QUIT); command.setGroupName(groupName); command.setDestination(nodes); executionContext.execute(command); }