Search in sources :

Example 1 with D2Config

use of com.linkedin.d2.discovery.util.D2Config in project rest.li by linkedin.

the class ConfigRunner method main.

public static void main(String[] args) throws Exception {
    //get server configuration
    String path = new File(new File(".").getAbsolutePath()).getCanonicalPath() + "/src/main/d2Config/d2Config.json";
    JSONParser parser = new JSONParser();
    Object object = parser.parse(new FileReader(path));
    JSONObject json = (JSONObject) object;
    System.out.println("Finished parsing d2 topology config");
    String zkConnectString = (String) json.get("zkConnectString");
    int zkSessionTimeout = ((Long) json.get("zkSessionTimeout")).intValue();
    String zkBasePath = (String) json.get("zkBasePath");
    int zkRetryLimit = ((Long) json.get("zkRetryLimit")).intValue();
    Map<String, Object> serviceDefaults = (Map<String, Object>) json.get("defaultServiceProperties");
    //this contains the topology of our system
    Map<String, Object> clusterServiceConfigurations = (Map<String, Object>) json.get("d2Clusters");
    // 'comment' has no special meaning in json...
    clusterServiceConfigurations.remove("comment");
    System.out.println("Populating zookeeper with d2 configuration");
    //d2Config is the utility class for populating zookeeper with our topology
    //some the params are not needed for this simple example so we will just use
    //default value by passing an empty map
    D2Config d2Config = new D2Config(zkConnectString, zkSessionTimeout, zkBasePath, zkSessionTimeout, zkRetryLimit, (Map<String, Object>) Collections.EMPTY_MAP, serviceDefaults, clusterServiceConfigurations, (Map<String, Object>) Collections.EMPTY_MAP, (Map<String, Object>) Collections.EMPTY_MAP);
    //populate zookeeper
    d2Config.configure();
    System.out.println("Finished populating zookeeper with d2 configuration");
}
Also used : JSONObject(org.json.simple.JSONObject) JSONParser(org.json.simple.parser.JSONParser) JSONObject(org.json.simple.JSONObject) FileReader(java.io.FileReader) D2Config(com.linkedin.d2.discovery.util.D2Config) File(java.io.File) Map(java.util.Map)

Example 2 with D2Config

use of com.linkedin.d2.discovery.util.D2Config in project rest.li by linkedin.

the class LoadBalancerClientCli method runDiscovery.

@SuppressWarnings("unchecked")
private static int runDiscovery(String zkserverHostPort, String d2path, Map<String, Object> configMap) throws Exception {
    String zkHosts = zkserverHostPort.replace("zk://", "");
    Map<String, Object> clusterDefaults = (Map<String, Object>) configMap.get("clusterDefaults");
    Map<String, Object> serviceDefaults = (Map<String, Object>) configMap.get("serviceDefaults");
    Map<String, Object> clusterServiceConfigurations = (Map<String, Object>) configMap.get("clusterServiceConfigurations");
    Map<String, Object> extraClusterServiceConfigurations = (Map<String, Object>) configMap.get("extraClusterServiceConfigurations");
    Map<String, Object> serviceVariants = (Map<String, Object>) configMap.get("serviceVariants");
    D2Config d2conf = new D2Config(zkHosts, 10000, d2path, 5000L, 10, clusterDefaults, serviceDefaults, clusterServiceConfigurations, extraClusterServiceConfigurations, serviceVariants);
    return d2conf.configure();
}
Also used : D2Config(com.linkedin.d2.discovery.util.D2Config) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

D2Config (com.linkedin.d2.discovery.util.D2Config)2 Map (java.util.Map)2 File (java.io.File)1 FileReader (java.io.FileReader)1 HashMap (java.util.HashMap)1 JSONObject (org.json.simple.JSONObject)1 JSONParser (org.json.simple.parser.JSONParser)1