private Set<String> getAllHostsAtSite(String siteId) throws IOException { Set<String> allHosts = config.getHostIds().stream() .filter(hostId -> siteId.equals(config.getAttributesForHost(hostId).get("siteId"))) .collect(Collectors.toSet()); if (allHosts.isEmpty()) { throw new IOException("SiteID " + siteId + " does not exist"); } return allHosts; } }
public static String getAppUri(Config config, String hostId) { InetSocketAddress address = config.getAddressForHost(hostId); Map<String, String> attrs = config.getAttributesForHost(hostId); String appUri = String.format("%s://%s:%s", attrs.get(APP_SCHEME), address.getHostName(), attrs.get(APP_PORT)); if (!attrs.containsKey(APP_PORT) || !attrs.containsKey(APP_SCHEME)) { throw new IllegalStateException( String .format("gondola.hosts[%s] is missing either the %s or %s config values", hostId, APP_PORT, APP_SCHEME)); } return appUri; }
/** * A compatibility checking tool for routing module. * * @param config the config */ public static void configCheck(Config config) { StringBuilder sb = new StringBuilder(); for (String shardId : config.getShardIds()) { if (!config.getAttributesForShard(shardId).containsKey("bucketMap")) { sb.append("Shard bucketMap attribute is missing on Shard - ").append(shardId).append("\n"); } } for (String hostId : config.getHostIds()) { Map<String, String> attributes = config.getAttributesForHost(hostId); if (!attributes.containsKey("appScheme") || !attributes.containsKey("appPort")) { sb.append("Host attributes appScheme and appPort is missing on Host - ").append(hostId).append("\n"); } } if (!sb.toString().isEmpty()) { throw new IllegalStateException("Configuration Error: " + sb.toString()); } }
void createConnection() throws GondolaException { Config cfg = gondola.getConfig(); String user = cfg.get("storage.h2.user"); String password = cfg.get("storage.h2.password"); // If there's a store-specific setting, use it; otherwise use default String url = cfg.get("storage.h2.url"); String storeId = cfg.getAttributesForHost(hostId).get("storeId"); if (storeId != null) { String urlKey = "storage." + storeId + ".h2.url"; if (cfg.has(urlKey)) { url = cfg.get(urlKey); } } url = url.replace("$hostId", hostId); logger.info("Initializing H2DB storage. maxCommandSize={} url={} user={}", maxCommandSize, url, user); try { c = DriverManager.getConnection(url, user, password); c.setAutoCommit(true); } catch (SQLException e) { throw new GondolaException(e); } }
@GET @Path("/gondolaStatus") public Map getGondolaStatus() throws InterruptedException { RoutingFilter routingFilter = GondolaApplication.getRoutingFilter(); Gondola gondola = routingFilter.getGondola(); ChangeLogProcessor changeLogProcessor = GondolaApplication.getRoutingFilter().getChangeLogProcessor(); Map<Object, Object> map = new LinkedHashMap<>(); map.put("hostId", gondola.getHostId()); map.put("gondolaStatus", getGondolaStatus(gondola, changeLogProcessor)); map.put("routingTable", routingFilter.getRoutingTable()); map.put("bucketTable", getBucketMapStatus(routingFilter.getBucketManager())); map.put("lock", getLockManagerStatus(routingFilter.getLockManager())); map.put("shardManager", getShardManagerStatus()); map.put("numActiveRequests", routingFilter.getBucketRequestCounters().values().stream().map(AtomicInteger::get) .reduce((i1, i2) -> i1 + i2).orElse(0)); map.put("config", getConfigInfo(gondola)); map.put("stats", gondola.getStats()); map.put("pid", gondola.getConfig().getAttributesForHost(gondola.getHostId()).get("hostname") + ":" + gondola.getProcessId()); map.put("timers", timerMap()); map.put("meters", GondolaApplication.MyMetricsServletContextListener.METRIC_REGISTRY.getMeters()); return map; }
String storeId = cfg.getAttributesForHost(hostId).get("storeId"); if (storeId != null) { String urlKey = "storage." + storeId + ".mysql.url";