public void printUsage() { // Stop is implemented in the shell script System.out.println("Usage: gondola.sh -hostid <host-id> -clusterid <cluster-id> [-port <port>] [-workers <num>] [start|stop]"); if (config != null) { System.out.println(" Available host ids: " + config.getHostIds()); } System.exit(1); }
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 Map<String, Object> getServiceStatus() { Map<String, Object> map = new LinkedHashMap<>(); config.getHostIds().stream() .collect(Collectors.toMap( hostId -> hostId, this::getHostStatusAsync)) .forEach((hostId, mapFuture) -> { try { map.put(hostId, mapFuture.get()); } catch (InterruptedException | ExecutionException e) { logger.warn("Cannot get serviceStatus for hostId={}", hostId); map.put(hostId, null); } }); return map; }
private String getAffinityColoShard() { String siteId = getSiteId(); Config config = gondola.getConfig(); return config.getHostIds().stream() .map(config::getSiteIdForHost) .filter(s -> s.equals(siteId)) .findAny().orElseThrow(() -> new IllegalStateException("Cannot find any shard in siteId=" + siteId)); }
private Map getConfigInfo(Gondola gondola) { Map<Object, Object> map = new LinkedHashMap<>(); Config config = gondola.getConfig(); map.put("file", config.getFile()); map.put("members", config.getMembers()); map.put("shards", config.getShardIds().stream() .map(config::getAttributesForShard) .collect(Collectors.toList())); map.put("hosts", config.getHostIds().stream() .map(config::getAttributesForHost) .collect(Collectors.toList())); return map; }
/** * 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()); } }
private Gondola createGondolaInstance() throws GondolaException { Config config = ConfigLoader.getConfigInstance(configUri); String hostId = null; for (String h : config.getHostIds()) { if (Utils.isMyAddress(config.getAddressForHost(h).getAddress())) { hostId = h; break; } } if (System.getenv("hostId") != null) { hostId = System.getenv("hostId"); } if (hostId == null) { throw new IllegalStateException("Cannot find IP address on the host."); } return new Gondola(config, hostId); }
/** * Private methods. */ private void loadRoutingTable() { // The routing entry will be modified on the fly, concurrent map is needed Map<String, List<String>> newRoutingTable = new ConcurrentHashMap<>(); Config config = gondola.getConfig(); for (String hostId : config.getHostIds()) { if (hostId.equals(gondola.getHostId())) { myAppUri = Utils.getAppUri(config, hostId); continue; } String appUri = Utils.getAppUri(config, hostId); serviceUris.put(hostId, appUri); for (String shardId : config.getShardIds(hostId)) { List<String> addresses = newRoutingTable.get(shardId); if (addresses == null) { addresses = new ArrayList<>(); newRoutingTable.put(shardId, addresses); } addresses.add(appUri); } } routingTable = newRoutingTable; }
throw new UnsupportedOperationException("Enable/disable a shard is not allowed."); case SITE: config.getHostIds().stream().filter(hostId -> config.getSiteIdForHost(hostId).equals(targetId)).forEach( hostId -> { for (String shardId : config.getShardIds(hostId)) {
usage(); adminClient.inspectRequestUri(config.getHostIds().get(0), argsList.get(1)); break; case "setLeader":