Search in sources :

Example 31 with HugeConfig

use of com.baidu.hugegraph.config.HugeConfig in project hugegraph-computer by hugegraph.

the class AbstractK8sTest method initConfig.

protected void initConfig() {
    HashMap<String, String> options = new HashMap<>();
    options.put(ComputerOptions.JOB_ID.name(), KubeUtil.genJobId("PageRank"));
    options.put(ComputerOptions.JOB_WORKERS_COUNT.name(), "1");
    options.put(ComputerOptions.ALGORITHM_RESULT_CLASS.name(), LongValue.class.getName());
    options.put(ComputerOptions.ALGORITHM_PARAMS_CLASS.name(), "com.baidu.hugegraph.computer.core.config.Null");
    options.put(ComputerOptions.JOB_PARTITIONS_COUNT.name(), "1000");
    options.put(ComputerOptions.BSP_ETCD_ENDPOINTS.name(), "http://abc:8098");
    options.put(ComputerOptions.HUGEGRAPH_URL.name(), "http://127.0.0.1:8080");
    options.put(KubeDriverOptions.NAMESPACE.name(), this.namespace);
    options.put(KubeDriverOptions.LOG4J_XML_PATH.name(), "conf/log4j2-test.xml");
    options.put(KubeDriverOptions.ENABLE_INTERNAL_ALGORITHM.name(), "false");
    options.put(KubeDriverOptions.IMAGE_REPOSITORY_URL.name(), IMAGE_REPOSITORY_URL);
    options.put(KubeDriverOptions.IMAGE_REPOSITORY_USERNAME.name(), "hugegraph");
    options.put(KubeDriverOptions.IMAGE_REPOSITORY_PASSWORD.name(), "hugegraph");
    options.put(KubeDriverOptions.INTERNAL_ALGORITHM_IMAGE_URL.name(), IMAGE_REPOSITORY_URL + ":PageRank-latest");
    options.put(KubeSpecOptions.PULL_POLICY.name(), "IfNotPresent");
    options.put(KubeSpecOptions.JVM_OPTIONS.name(), "-Dlog4j2.debug=true");
    options.put(KubeSpecOptions.MASTER_COMMAND.name(), "[/bin/sh, -c]");
    options.put(KubeSpecOptions.WORKER_COMMAND.name(), "[/bin/sh, -c]");
    options.put(KubeSpecOptions.MASTER_ARGS.name(), "[echo master]");
    options.put(KubeSpecOptions.WORKER_ARGS.name(), "[echo worker]");
    MapConfiguration mapConfig = new MapConfiguration(options);
    this.config = new HugeConfig(mapConfig);
}
Also used : HashMap(java.util.HashMap) MapConfiguration(org.apache.commons.configuration.MapConfiguration) LongValue(com.baidu.hugegraph.computer.core.graph.value.LongValue) HugeConfig(com.baidu.hugegraph.config.HugeConfig)

Example 32 with HugeConfig

use of com.baidu.hugegraph.config.HugeConfig in project hugegraph-computer by hugegraph.

the class KubernetesDriver method createKubeClient.

private static NamespacedKubernetesClient createKubeClient(HugeConfig conf) {
    String kubeConfig = conf.get(KubeDriverOptions.KUBE_CONFIG);
    Config config;
    try {
        File file = new File(kubeConfig);
        @SuppressWarnings("deprecation") String kubeConfigContents = FileUtils.readFileToString(file);
        config = Config.fromKubeconfig(kubeConfigContents);
    } catch (IOException e) {
        throw new ComputerDriverException("Failed to read KubeConfig: %s", e, kubeConfig);
    }
    return new DefaultKubernetesClient(config);
}
Also used : Config(io.fabric8.kubernetes.client.Config) HugeConfig(com.baidu.hugegraph.config.HugeConfig) ComputerDriverException(com.baidu.hugegraph.computer.driver.ComputerDriverException) IOException(java.io.IOException) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) File(java.io.File)

Example 33 with HugeConfig

use of com.baidu.hugegraph.config.HugeConfig in project hugegraph-computer by hugegraph.

the class OperatorEntrypoint method configFromSysPropsOrEnvVars.

private HugeConfig configFromSysPropsOrEnvVars() {
    Map<String, String> confMap = new HashMap<>();
    Set<String> keys = OperatorOptions.instance().options().keySet();
    for (String key : keys) {
        String envKey = key.substring(Constants.K8S_SPEC_PREFIX.length()).toUpperCase(Locale.ROOT);
        String value = Utils.getSystemPropertyOrEnvVar(envKey);
        if (StringUtils.isNotBlank(value)) {
            confMap.put(key, value);
        }
    }
    MapConfiguration configuration = new MapConfiguration(confMap);
    return new HugeConfig(configuration);
}
Also used : HashMap(java.util.HashMap) MapConfiguration(org.apache.commons.configuration.MapConfiguration) HugeConfig(com.baidu.hugegraph.config.HugeConfig)

Example 34 with HugeConfig

use of com.baidu.hugegraph.config.HugeConfig in project hugegraph-computer by hugegraph.

the class KubernetesDriverTest method testConstruct.

@Test
public void testConstruct() {
    String namespace = Whitebox.getInternalState(this.driver, "namespace");
    HugeConfig conf = Whitebox.getInternalState(this.driver, "conf");
    Object operation = Whitebox.getInternalState(this.driver, "operation");
    MutableBoolean watchActive = Whitebox.getInternalState(this.driver, "watchActive");
    Assert.assertTrue(watchActive.booleanValue());
    Assert.assertEquals(namespace, "test");
    Assert.assertNotNull(conf);
    Assert.assertNotNull(operation);
    final int workerInstances = 2;
    this.updateOptions(KubeSpecOptions.WORKER_INSTANCES.name(), workerInstances);
    Map<String, Object> defaultSpec = Whitebox.invoke(KubernetesDriver.class, "defaultSpec", this.driver);
    String workerInstancesKey = KubeUtil.covertSpecKey(KubeSpecOptions.WORKER_INSTANCES.name());
    Assert.assertEquals(defaultSpec.get(workerInstancesKey), workerInstances);
}
Also used : MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) HugeConfig(com.baidu.hugegraph.config.HugeConfig) Test(org.junit.Test)

Example 35 with HugeConfig

use of com.baidu.hugegraph.config.HugeConfig in project hugegraph-common by hugegraph.

the class ServerClientTest method testLoadBalancer.

@Test
public void testLoadBalancer() {
    // Init 3 servers
    HugeConfig server3 = config("server3");
    RpcServer rpcServer3 = new RpcServer(server3);
    HugeConfig server4 = config("server4");
    RpcServer rpcServer4 = new RpcServer(server4);
    HugeConfig server5 = config("server5");
    RpcServer rpcServer5 = new RpcServer(server5);
    GraphHelloServiceImpl s3g1 = new GraphHelloServiceImpl("g1");
    GraphHelloServiceImpl s4g1 = new GraphHelloServiceImpl("g1");
    GraphHelloServiceImpl s5g1 = new GraphHelloServiceImpl("g1");
    rpcServer3.config().addService(HelloService.class, s3g1);
    rpcServer4.config().addService(HelloService.class, s4g1);
    rpcServer5.config().addService(HelloService.class, s5g1);
    startServer(rpcServer3);
    startServer(rpcServer4);
    startServer(rpcServer5);
    // Test LB "consistentHash"
    HugeConfig clientLB = config("client-lb");
    RpcClientProvider rpcClientCHash = new RpcClientProvider(clientLB);
    HelloService cHash = rpcClientCHash.config().serviceProxy(HelloService.class);
    Assert.assertEquals("g1: load", cHash.echo("load"));
    Assert.assertEquals(16.8, cHash.sum(10, 6.8), 0.00000001d);
    Assert.assertEquals(16.8, s3g1.result() + s4g1.result() + s5g1.result(), 0.00000001d);
    Assert.assertEquals("g1: load", cHash.echo("load"));
    Assert.assertEquals(16.8, cHash.sum(10, 6.8), 0.00000001d);
    Assert.assertEquals(16.8, s3g1.result() + s4g1.result() + s5g1.result(), 0.00000001d);
    Assert.assertEquals("g1: load", cHash.echo("load"));
    Assert.assertEquals(16.8, cHash.sum(10, 6.8), 0.00000001d);
    Assert.assertEquals(16.8, s3g1.result() + s4g1.result() + s5g1.result(), 0.00000001d);
    s3g1.resetResult();
    s4g1.resetResult();
    s5g1.resetResult();
    // Test LB "roundRobin"
    String lbKey = com.baidu.hugegraph.config.RpcOptions.RPC_CLIENT_LOAD_BALANCER.name();
    clientLB.setProperty(lbKey, "roundRobin");
    RpcClientProvider rpcClientRound = new RpcClientProvider(clientLB);
    HelloService round = rpcClientRound.config().serviceProxy(HelloService.class);
    Assert.assertEquals("g1: load", round.echo("load"));
    Assert.assertEquals(1.1, round.sum(1, 0.1), 0.00000001d);
    Assert.assertEquals(1.1, s3g1.result() + s4g1.result() + s5g1.result(), 0.00000001d);
    Assert.assertEquals("g1: load", round.echo("load"));
    Assert.assertEquals(1.1, round.sum(1, 0.1), 0.00000001d);
    Assert.assertEquals(2.2, s3g1.result() + s4g1.result() + s5g1.result(), 0.00000001d);
    Assert.assertEquals("g1: load", round.echo("load"));
    Assert.assertEquals(1.1, round.sum(1, 0.1), 0.00000001d);
    Assert.assertEquals(3.3, s3g1.result() + s4g1.result() + s5g1.result(), 0.00000001d);
    s3g1.resetResult();
    s4g1.resetResult();
    s5g1.resetResult();
    // Test LB "random"
    clientLB.setProperty(lbKey, "random");
    RpcClientProvider rpcClientRandom = new RpcClientProvider(clientLB);
    HelloService random = rpcClientRandom.config().serviceProxy(HelloService.class);
    Assert.assertEquals("g1: load", random.echo("load"));
    Assert.assertEquals(1.1, random.sum(1, 0.1), 0.00000001d);
    Assert.assertEquals(1.1, s3g1.result() + s4g1.result() + s5g1.result(), 0.00000001d);
    Assert.assertEquals("g1: load", random.echo("load"));
    Assert.assertEquals(1.1, random.sum(1, 0.1), 0.00000001d);
    double sum = s3g1.result() + s4g1.result() + s5g1.result();
    Assert.assertTrue(2.2 == sum || 1.1 == sum);
    Assert.assertEquals("g1: load", random.echo("load"));
    Assert.assertEquals(1.1, random.sum(1, 0.1), 0.00000001d);
    double sum2 = s3g1.result() + s4g1.result() + s5g1.result();
    Assert.assertTrue(sum == sum2 || sum + 1.1 == sum2);
    for (int i = 0; i < 9; i++) {
        Assert.assertEquals(1.1, random.sum(1, 0.1), 0.00000001d);
    }
    Assert.assertEquals(3.3, s3g1.result() + s4g1.result() + s5g1.result(), 0.00000001d);
    s3g1.resetResult();
    s4g1.resetResult();
    s5g1.resetResult();
    // Destroy all
    rpcClientCHash.destroy();
    rpcClientRound.destroy();
    rpcClientRandom.destroy();
    stopServer(rpcServer3);
    stopServer(rpcServer4);
    stopServer(rpcServer5);
}
Also used : RpcServer(com.baidu.hugegraph.rpc.RpcServer) HugeConfig(com.baidu.hugegraph.config.HugeConfig) RpcClientProvider(com.baidu.hugegraph.rpc.RpcClientProvider) Test(org.junit.Test)

Aggregations

HugeConfig (com.baidu.hugegraph.config.HugeConfig)63 Test (org.junit.Test)33 PropertiesConfiguration (org.apache.commons.configuration2.PropertiesConfiguration)15 BaseUnitTest (com.baidu.hugegraph.unit.BaseUnitTest)12 Configuration (org.apache.commons.configuration2.Configuration)11 RpcClientProvider (com.baidu.hugegraph.rpc.RpcClientProvider)7 RpcServer (com.baidu.hugegraph.rpc.RpcServer)7 HugeGraph (com.baidu.hugegraph.HugeGraph)5 File (java.io.File)5 BackendEntry (com.baidu.hugegraph.backend.store.BackendEntry)4 HashMap (java.util.HashMap)4 RocksDBSessions (com.baidu.hugegraph.backend.store.rocksdb.RocksDBSessions)3 HugeEdge (com.baidu.hugegraph.structure.HugeEdge)3 HugeVertex (com.baidu.hugegraph.structure.HugeVertex)3 FakeObjects (com.baidu.hugegraph.unit.FakeObjects)3 MapConfiguration (org.apache.commons.configuration.MapConfiguration)3 HugeException (com.baidu.hugegraph.HugeException)2 BackendException (com.baidu.hugegraph.backend.BackendException)2 BinaryBackendEntry (com.baidu.hugegraph.backend.serializer.BinaryBackendEntry)2 BinaryScatterSerializer (com.baidu.hugegraph.backend.serializer.BinaryScatterSerializer)2