@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); }
public void init() { node = clusterManager.getNode(); remoteEndpoints = clusterManager.getMap(Constants.REMOTE_ENDPOINTS); bundleContext.addServiceListener(this); // lookup for already exported services ServiceReference[] references = null; try { String filter = "(" + Constants.EXPORTED_INTERFACES + "=" + Constants.ALL_INTERFACES + ")"; references = bundleContext.getServiceReferences((String) null, filter); if (references != null) { for (ServiceReference reference : references) { exportService(reference); } } } catch (InvalidSyntaxException e) { LOGGER.error("CELLAR DOSGI: error exporting existing remote services", e); } }
@Override protected Object doExecute() throws Exception { org.apache.karaf.cellar.core.control.ShutdownCommand command = new org.apache.karaf.cellar.core.control.ShutdownCommand(clusterManager.generateId()); Set<Node> recipientList = clusterManager.listNodes(); command.setDestination(recipientList); command.setHalt(halt); System.out.println("!! Cluster shutdown !!"); executionContext.execute(command); return null; }
@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); }
protected Object doExecute(List<String> nodeIdsOrAliases, SwitchStatus status) throws Exception { ConsumerSwitchCommand command = new ConsumerSwitchCommand(clusterManager.generateId()); command.setTimeout(timeout * 1000); if (nodeIdsOrAliases != null && !nodeIdsOrAliases.isEmpty()) { for (String nodeIdOrAlias : nodeIdsOrAliases) { Node node = clusterManager.findNodeByIdOrAlias(nodeIdOrAlias); if (node == null) { System.err.println("Cluster node " + nodeIdOrAlias + " doesn't exist"); if (status == null) { recipientList = clusterManager.listNodes(); } else { recipientList.add(clusterManager.getNode()); for (Node node : results.keySet()) { String local = ""; if (node.equals(clusterManager.getNode())) { local = "x";
/** * 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); } } }
Map<String, ClusterNode> clusterNodes = new LinkedHashMap<String, ClusterNode>(); Set<org.apache.karaf.cellar.core.Node> karafCellarNodes = karafCellarClusterManager.listNodes(); org.apache.karaf.cellar.core.Node thisKarafNode = karafCellarClusterManager.getNode(); Map<String, Properties> clusterConfigurations = karafCellarClusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + karafCellarGroupName); Properties karafCellarClusterNodeConfiguration = clusterConfigurations.get(KARAF_CELLAR_CLUSTER_NODE_CONFIGURATION); Map<String, String> publicNodeEndpoints = new TreeMap<>();
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 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 consumerStatus() throws Exception { ConsumerSwitchCommand command = new ConsumerSwitchCommand(clusterManager.generateId()); command.setStatus(null); Map<Node, ConsumerSwitchResult> results = executionContext.execute(command); CompositeType compositeType = new CompositeType("Event Consumer", "Karaf Cellar cluster event consumer", new String[]{"node", "status", "local"}, new String[]{"Node hosting event consumer", "Current status of the event consumer", "True if the node is local"}, new OpenType[]{SimpleType.STRING, SimpleType.BOOLEAN, SimpleType.BOOLEAN}); TabularType tableType = new TabularType("Event Consumers", "Table of Karaf Cellar cluster event consumers", compositeType, new String[]{"node"}); TabularDataSupport table = new TabularDataSupport(tableType); for (Node node : results.keySet()) { boolean local = (node.equals(clusterManager.getNode())); ConsumerSwitchResult consumerSwitchResult = 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, consumerSwitchResult.getStatus(), local}); table.put(data); } return table; }
@Override public TabularData handlerStatus() throws Exception { ManageHandlersCommand command = new ManageHandlersCommand(clusterManager.generateId()); command.setDestination(clusterManager.listNodes()); command.setHandlerName(null); command.setStatus(null); nodeName = node.getId(); boolean local = (node.equals(clusterManager.getNode())); CompositeDataSupport data = new CompositeDataSupport(compositeType, new String[]{"node", "handler", "status", "local"},
public void init() { remoteEndpoints = clusterManager.getMap(Constants.REMOTE_ENDPOINTS); service.scheduleAtFixedRate(this, 0, 5, TimeUnit.SECONDS); }
@Override public void doAppend(PaxLoggingEvent event) { Map<ClusterLogKey, ClusterLogRecord> clusterLog = clusterManager.getMap(LOG_MAP); ClusterLogRecord record = new ClusterLogRecord(); ClusterLogKey key = new ClusterLogKey(); Node node = clusterManager.getNode(); key.setNodeId(node.getId()); key.setNodeAlias(node.getAlias()); key.setTimeStamp(event.getTimeStamp()); key.setId(clusterManager.generateId()); record.setFQNOfLoggerClass(event.getFQNOfLoggerClass()); record.setLevel(event.getLevel().toString()); record.setLoggerName(event.getLoggerName()); record.setMessage(event.getMessage()); record.setRenderedMessage(event.getRenderedMessage()); record.setThreadName(event.getThreadName()); record.setThrowableStringRep(event.getThrowableStrRep()); clusterLog.put(key, record); }
LOGGER.debug("CELLAR CONFIG: pulling configurations from cluster group {}", groupName); Map<String, Properties> clusterConfigurations = clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + groupName); if (clusterManager.listNodesByGroup(group).size() > 1) { try { for (Configuration configuration : configurationAdmin.listConfigurations(null)) {
@Override public void setLevel(String level, String logger, String nodeId) throws Exception { SetLogCommand command = new SetLogCommand(clusterManager.generateId()); command.setTimeout(30 * 1000); Set<Node> recipientList = new HashSet<Node>(); if (nodeId != null && clusterManager.findNodeByIdOrAlias(nodeId) == null) { throw new IllegalArgumentException("Node " + nodeId + " doesn't exist"); } if (nodeId == null) { recipientList = clusterManager.listNodes(); } else { recipientList.add(clusterManager.findNodeByIdOrAlias(nodeId)); } if (recipientList.size() < 1) throw new IllegalArgumentException("No recipient list"); command.setDestination(recipientList); command.setLogger(logger); command.setLevel(level); Map<Node, SetLogResult> results = executionContext.execute(command); if (results == null || results.isEmpty()) { throw new IllegalStateException("No result received within given timeout"); } }
@Override public Object doExecute() throws Exception { ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); try { Map<ClusterLogKey, ClusterLogRecord> clusterLog = clusterManager.getMap(LogAppender.LOG_MAP); if (nodeIdOrAlias == null) { clusterLog.clear(); } else { Node node = clusterManager.findNodeByIdOrAlias(nodeIdOrAlias); if (node == null) { System.err.println("Node " + nodeIdOrAlias + " doesn't exist"); return null; } for (ClusterLogKey key : clusterLog.keySet()) { if (key.getNodeId().equals(node.getId())) { clusterLog.remove(key); } } } } finally { Thread.currentThread().setContextClassLoader(originalClassLoader); } return null; }
level = "INFO"; if (nodeId != null && clusterManager.findNodeByIdOrAlias(nodeId) == null) { throw new IllegalArgumentException("Node " + nodeId + " doesn't exist"); String id = clusterManager.generateId(); Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); try { Map<ClusterLogKey, ClusterLogRecord> clusterLog = clusterManager.getMap(LogAppender.LOG_MAP); clusterLog.put(key, record); } finally {
LOGGER.trace("CELLAR DOSGI: found {} remote endpoints", remoteEndpoints.size()); Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); final Set<Node> activeNodes = clusterManager.listNodes();
protected Object doExecute(List<String> nodeIdsOrAliases, SwitchStatus status) throws Exception { ProducerSwitchCommand command = new ProducerSwitchCommand(clusterManager.generateId()); command.setTimeout(timeout * 1000); if (nodeIdsOrAliases != null && !nodeIdsOrAliases.isEmpty()) { for (String nodeIdOrAlias : nodeIdsOrAliases) { Node node = clusterManager.findNodeByIdOrAlias(nodeIdOrAlias); if (node == null) { System.err.println("Cluster node " + nodeIdOrAlias + " doesn't exist"); if (status == null) { recipientList = clusterManager.listNodes(); } else { recipientList.add(clusterManager.getNode()); for (Node node : results.keySet()) { String local = ""; if (node.equals(clusterManager.getNode())) { local = "x";
/** * 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); } } }