@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); }
protected Object doExecute(List<String> nodeIdsOrAliases, SwitchStatus status) throws Exception { ProducerSwitchCommand command = new ProducerSwitchCommand(clusterManager.generateId()); command.setTimeout(timeout * 1000); command.setDestination(recipientList); command.setStatus(status);
@Override public TabularData producerStatus() throws Exception { ProducerSwitchCommand command = new ProducerSwitchCommand(clusterManager.generateId()); command.setStatus(null); Map<Node, ProducerSwitchResult> results = executionContext.execute(command); CompositeType compositeType = new CompositeType("Event Producer", "Karaf Cellar cluster event producer", new String[]{"node", "status", "local"}, new String[]{"Node hosting event producer", "Current status of the event producer", "True if the node is local"}, new OpenType[]{SimpleType.STRING, SimpleType.BOOLEAN, SimpleType.BOOLEAN}); TabularType tableType = new TabularType("Event Producers", "Table of Karaf Cellar cluster event producers", compositeType, new String[]{"node"}); TabularDataSupport table = new TabularDataSupport(tableType); for (Node node : results.keySet()) { boolean local = (node.equals(clusterManager.getNode())); ProducerSwitchResult producerSwitchResult = results.get(node); String nodeName = node.getAlias(); if (nodeName == null) { nodeName = node.getId(); } CompositeDataSupport data = new CompositeDataSupport(compositeType, new String[]{"node", "status", "local"}, new Object[]{nodeName, producerSwitchResult.getStatus(), local}); table.put(data); } return table; }
/** * Execute a producer switch command. * * @param command the producer switch command to execute. * @return the result of the command execution. */ @Override public ProducerSwitchResult execute(ProducerSwitchCommand command) { // query if (command.getStatus() == null) { return new ProducerSwitchResult(command.getId(), Boolean.TRUE, producer.getSwitch().getStatus().getValue()); } else if (command.getStatus().equals(SwitchStatus.ON)) { // turn on the switch producer.getSwitch().turnOn(); // persist the change persist(command.getStatus()); return new ProducerSwitchResult(command.getId(), Boolean.TRUE, Boolean.TRUE); } else if (command.getStatus().equals(SwitchStatus.OFF)) { // turn off the switch producer.getSwitch().turnOff(); // persist the change persist(command.getStatus()); return new ProducerSwitchResult(command.getId(), Boolean.TRUE, Boolean.FALSE); } else { return new ProducerSwitchResult(command.getId(), Boolean.FALSE, producer.getSwitch().getStatus().getValue()); } }
@Override public TabularData producerStatus() throws Exception { ProducerSwitchCommand command = new ProducerSwitchCommand(clusterManager.generateId()); command.setStatus(null); Map<Node, ProducerSwitchResult> results = executionContext.execute(command); CompositeType compositeType = new CompositeType("Event Producer", "Karaf Cellar cluster event producer", new String[]{"node", "status", "local"}, new String[]{"Node hosting event producer", "Current status of the event producer", "True if the node is local"}, new OpenType[]{SimpleType.STRING, SimpleType.BOOLEAN, SimpleType.BOOLEAN}); TabularType tableType = new TabularType("Event Producers", "Table of Karaf Cellar cluster event producers", compositeType, new String[]{"node"}); TabularDataSupport table = new TabularDataSupport(tableType); for (Node node : results.keySet()) { boolean local = (node.equals(clusterManager.getNode())); ProducerSwitchResult producerSwitchResult = results.get(node); String nodeName = node.getAlias(); if (nodeName == null) { nodeName = node.getId(); } CompositeDataSupport data = new CompositeDataSupport(compositeType, new String[]{"node", "status", "local"}, new Object[]{nodeName, producerSwitchResult.getStatus(), local}); table.put(data); } return table; }
/** * Execute a producer switch command. * * @param command the producer switch command to execute. * @return the result of the command execution. */ @Override public ProducerSwitchResult execute(ProducerSwitchCommand command) { // query if (command.getStatus() == null) { return new ProducerSwitchResult(command.getId(), Boolean.TRUE, producer.getSwitch().getStatus().getValue()); } else if (command.getStatus().equals(SwitchStatus.ON)) { // turn on the switch producer.getSwitch().turnOn(); // persist the change persist(command.getStatus()); return new ProducerSwitchResult(command.getId(), Boolean.TRUE, Boolean.TRUE); } else if (command.getStatus().equals(SwitchStatus.OFF)) { // turn off the switch producer.getSwitch().turnOff(); // persist the change persist(command.getStatus()); return new ProducerSwitchResult(command.getId(), Boolean.TRUE, Boolean.FALSE); } else { return new ProducerSwitchResult(command.getId(), Boolean.FALSE, producer.getSwitch().getStatus().getValue()); } }
@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 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 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); }