public void init() { remoteEndpoints = clusterManager.getMap(Constants.REMOTE_ENDPOINTS); service.scheduleAtFixedRate(this, 0, 5, TimeUnit.SECONDS); }
public void init() { remoteEndpoints = clusterManager.getMap(Constants.REMOTE_ENDPOINTS); scheduler.scheduleWithFixedDelay(this, 10, 10, TimeUnit.SECONDS); }
@Override public Map<String, String> listProperties(String groupName, String pid) throws Exception { Map<String, String> properties = new HashMap<String, String>(); Map<String, Properties> clusterConfigurations = clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + groupName); Properties clusterProperties = clusterConfigurations.get(pid); if (clusterProperties != null) { Enumeration propertyNames = clusterProperties.propertyNames(); while (propertyNames.hasMoreElements()) { String key = (String) propertyNames.nextElement(); String value = (String) clusterProperties.get(key); properties.put(key, value); } } return properties; }
@Override public Map<String, String> listProperties(String groupName, String pid) throws Exception { Map<String, String> properties = new HashMap<String, String>(); Map<String, Properties> clusterConfigurations = clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + groupName); Properties clusterProperties = clusterConfigurations.get(pid); if (clusterProperties != null) { Enumeration propertyNames = clusterProperties.propertyNames(); while (propertyNames.hasMoreElements()) { String key = (String) propertyNames.nextElement(); String value = (String) clusterProperties.get(key); properties.put(key, value); } } return properties; }
@Override public List<String> getConfigs(String groupName) throws Exception { // check if the group exists Group group = groupManager.findGroupByName(groupName); if (group == null) { throw new IllegalArgumentException("Cluster group " + groupName + " doesn't exist"); } List<String> result = new ArrayList<String>(); Map<String, Properties> clusterConfigurations = clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + groupName); for (String pid : clusterConfigurations.keySet()) { result.add(pid); } return result; }
@Override public List<String> getConfigs(String groupName) throws Exception { // check if the group exists Group group = groupManager.findGroupByName(groupName); if (group == null) { throw new IllegalArgumentException("Cluster group " + groupName + " doesn't exist"); } List<String> result = new ArrayList<String>(); Map<String, Properties> clusterConfigurations = clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + groupName); for (String pid : clusterConfigurations.keySet()) { result.add(pid); } return result; }
@Override public List<String> getRepositories(String groupName) throws Exception { // check if the group exists Group group = groupManager.findGroupByName(groupName); if (group == null) { throw new IllegalArgumentException("Cluster group " + groupName + " doesn't exist"); } // get the features repositories in the cluster group Map<String, String> clusterRepositories = clusterManager.getMap(Constants.REPOSITORIES_MAP + Configurations.SEPARATOR + groupName); List<String> result = new ArrayList<String>(); for (String clusterRepository : clusterRepositories.keySet()) { result.add(clusterRepository); } return result; }
@Override public List<String> getRepositories(String groupName) throws Exception { // check if the group exists Group group = groupManager.findGroupByName(groupName); if (group == null) { throw new IllegalArgumentException("Cluster group " + groupName + " doesn't exist"); } // get the features repositories in the cluster group Map<String, String> clusterRepositories = clusterManager.getMap(Constants.REPOSITORIES_MAP + Configurations.SEPARATOR + groupName); List<String> result = new ArrayList<String>(); for (String clusterRepository : clusterRepositories.keySet()) { result.add(clusterRepository); } return result; }
@Override public Map<String, String> listHttp(String groupName) throws Exception { Map<String, String> result = new HashMap<String, String>(); Group group = groupManager.findGroupByName(groupName); if (group == null) { throw new IllegalArgumentException("Cluster group " + groupName + " doesn't exist"); } Map<String, List<String>> clusterServlets = clusterManager.getMap(Constants.BALANCER_MAP + Configurations.SEPARATOR + groupName); for (String alias : clusterServlets.keySet()) { List<String> locations = clusterServlets.get(alias); StringBuilder builder = new StringBuilder(); for (String location : locations) { builder.append(location).append(" "); } result.put(alias, builder.toString()); } return result; } }
@Override protected Object doExecute() throws Exception { // check if the group exist Group group = groupManager.findGroupByName(groupName); if (group == null) { System.err.println("Cluster group " + groupName + " doesn't exist"); return null; } Map<String, Properties> clusterConfigurations = clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + groupName); if (clusterConfigurations != null && !clusterConfigurations.isEmpty()) { Properties properties = clusterConfigurations.get(pid); if (properties == null || properties.isEmpty()) { System.err.println("Configuration PID " + pid + " not found in cluster group " + groupName); } else { System.out.println(String.format("Property list for configuration PID " + pid + " for cluster group " + groupName)); for (Object key : properties.keySet()) { String value = properties.getProperty((String) key); System.out.println(" " + key + " = " + value); } } } else System.err.println("No configuration found in cluster group " + groupName); return null; }
@Override protected Object doExecute() throws Exception { // check if the group exist Group group = groupManager.findGroupByName(groupName); if (group == null) { System.err.println("Cluster group " + groupName + " doesn't exist"); return null; } Map<String, Properties> clusterConfigurations = clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + groupName); if (clusterConfigurations != null && !clusterConfigurations.isEmpty()) { Properties properties = clusterConfigurations.get(pid); if (properties == null || properties.isEmpty()) { System.err.println("Configuration PID " + pid + " not found in cluster group " + groupName); } else { System.out.println(String.format("Property list for configuration PID " + pid + " for cluster group " + groupName)); for (Object key : properties.keySet()) { String value = properties.getProperty((String) key); System.out.println(" " + key + " = " + value); } } } else System.err.println("No configuration found in cluster group " + groupName); return null; }
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); } }
public Map<String, List<String>> getServices() { Map<String, List<String>> services = new HashMap<String, List<String>>(); ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); Map<String, EndpointDescription> remoteEndpoints = clusterManager.getMap(Constants.REMOTE_ENDPOINTS); if (remoteEndpoints != null && !remoteEndpoints.isEmpty()) { for (Map.Entry<String, EndpointDescription> entry : remoteEndpoints.entrySet()) { EndpointDescription endpointDescription = entry.getValue(); String serviceClass = endpointDescription.getServiceClass(); Set<Node> nodes = endpointDescription.getNodes(); LinkedList<String> providers = new LinkedList<String>(); for (Node node : nodes) { providers.add(node.getId()); } services.put(serviceClass, providers); } } } finally { Thread.currentThread().setContextClassLoader(originalClassLoader); } return services; }
@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; }
@Override public void pull(Group group) { Map<String, List<String>> clusterServlets = clusterManager.getMap(Constants.BALANCER_MAP + Configurations.SEPARATOR + group.getName()); for (String alias : clusterServlets.keySet()) { try { // add a proxy servlet only if the alias is not present locally Collection<ServiceReference<Servlet>> references = bundleContext.getServiceReferences(Servlet.class, "(alias=" + alias + ")"); if (references.isEmpty()) { LOGGER.debug("CELLAR HTTP BALANCER: create proxy servlet for {}", alias); CellarBalancerProxyServlet proxyServlet = new CellarBalancerProxyServlet(); proxyServlet.setLocations(clusterServlets.get(alias)); proxyServlet.init(); Hashtable<String, String> properties = new Hashtable<String, String>(); properties.put("alias", alias); properties.put("cellar.http.balancer.proxy", "true"); ServiceRegistration registration = bundleContext.registerService(Servlet.class, proxyServlet, properties); proxyRegistry.register(alias, registration); } } catch (Exception e) { LOGGER.warn("CELLAR HTTP BALANCER: can't create proxy servlet for {}", alias, e); } } }
@Override public int complete(Session session, CommandLine commandLine, List<String> candidates) { StringsCompleter delegate = new StringsCompleter(); try { Map<String, Group> groups = groupManager.listGroups(); if (groups != null && !groups.isEmpty()) { for (String groupName : groups.keySet()) { Map<String, Properties> clusterConfigurations = clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + groupName); if (clusterConfigurations != null && !clusterConfigurations.isEmpty()) { for (String pid : clusterConfigurations.keySet()) { if (delegate.getStrings() != null && !delegate.getStrings().contains(pid)) { delegate.getStrings().add(pid); } } } } } } catch (Exception e) { // nothing to do } return delegate.complete(session, commandLine, candidates); }
@Override public int complete(Session session, CommandLine commandLine, List<String> candidates) { StringsCompleter delegate = new StringsCompleter(); try { Map<String, Group> groups = groupManager.listGroups(); if (groups != null && !groups.isEmpty()) { for (String groupName : groups.keySet()) { Map<String, Properties> clusterConfigurations = clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + groupName); if (clusterConfigurations != null && !clusterConfigurations.isEmpty()) { for (String pid : clusterConfigurations.keySet()) { if (delegate.getStrings() != null && !delegate.getStrings().contains(pid)) { delegate.getStrings().add(pid); } } } } } } catch (Exception e) { // nothing to do } return delegate.complete(session, commandLine, candidates); }
@Override public Object doExecute() throws Exception { Group group = groupManager.findGroupByName(groupName); if (group == null) { System.err.println("Cluster group " + groupName + " doesn't exist"); return null; } Map<String, List<String>> clusterServlets = clusterManager.getMap(Constants.BALANCER_MAP + Configurations.SEPARATOR + groupName); ShellTable table = new ShellTable(); table.column("Alias"); table.column("Locations"); for (String alias : clusterServlets.keySet()) { List<String> locations = clusterServlets.get(alias); StringBuilder builder = new StringBuilder(); for (String location : locations) { builder.append(location).append(" "); } table.addRow().addContent(alias, builder.toString()); } table.print(System.out); return null; }
private Map<String, ConfigurationState> gatherConfigurations() throws Exception { Map<String, ConfigurationState> configurations = new HashMap<String, ConfigurationState>(); // retrieve cluster configurations Map<String, Properties> clusterConfigurations = clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + groupName); for (String key : clusterConfigurations.keySet()) { Properties properties = clusterConfigurations.get(key); ConfigurationState state = new ConfigurationState(); state.setProperties(properties); state.setCluster(true); state.setLocal(false); configurations.put(key, state); } // retrieve local configurations for (Configuration configuration : configurationAdmin.listConfigurations(null)) { String key = configuration.getPid(); if (configurations.containsKey(key)) { ConfigurationState state = configurations.get(key); state.setLocal(true); } else { ConfigurationState state = new ConfigurationState(); state.setLocal(true); state.setCluster(false); ConfigurationSupport support = new ConfigurationSupport(); state.setProperties(support.dictionaryToProperties(configuration.getProperties())); configurations.put(key, state); } } return configurations; }
@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); }