Search in sources :

Example 26 with HugeConfig

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

the class HbaseSessions method open.

@Override
public synchronized void open() throws IOException {
    HugeConfig config = this.config();
    String hosts = config.get(HbaseOptions.HBASE_HOSTS);
    int port = config.get(HbaseOptions.HBASE_PORT);
    String znodeParent = config.get(HbaseOptions.HBASE_ZNODE_PARENT);
    boolean isEnableKerberos = config.get(HbaseOptions.HBASE_KERBEROS_ENABLE);
    Configuration hConfig = HBaseConfiguration.create();
    hConfig.set(HConstants.ZOOKEEPER_QUORUM, hosts);
    hConfig.set(HConstants.ZOOKEEPER_CLIENT_PORT, String.valueOf(port));
    hConfig.set(HConstants.ZOOKEEPER_ZNODE_PARENT, znodeParent);
    hConfig.setInt("zookeeper.recovery.retry", config.get(HbaseOptions.HBASE_ZK_RETRY));
    // Set hbase.hconnection.threads.max 64 to avoid OOM(default value: 256)
    hConfig.setInt("hbase.hconnection.threads.max", config.get(HbaseOptions.HBASE_THREADS_MAX));
    String hbaseSite = config.get(HbaseOptions.HBASE_HBASE_SITE);
    hConfig.addResource(new Path(hbaseSite));
    if (isEnableKerberos) {
        String krb5Conf = config.get(HbaseOptions.HBASE_KRB5_CONF);
        System.setProperty("java.security.krb5.conf", krb5Conf);
        String principal = config.get(HbaseOptions.HBASE_KERBEROS_PRINCIPAL);
        String keyTab = config.get(HbaseOptions.HBASE_KERBEROS_KEYTAB);
        hConfig.set("hadoop.security.authentication", "kerberos");
        hConfig.set("hbase.security.authentication", "kerberos");
        // login/authenticate using keytab
        UserGroupInformation.setConfiguration(hConfig);
        UserGroupInformation.loginUserFromKeytab(principal, keyTab);
    }
    this.hbase = ConnectionFactory.createConnection(hConfig);
}
Also used : Path(org.apache.hadoop.fs.Path) Configuration(org.apache.hadoop.conf.Configuration) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) HugeConfig(com.baidu.hugegraph.config.HugeConfig)

Example 27 with HugeConfig

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

the class RegisterUtil method registerBackends.

public static void registerBackends() {
    String confFile = "/backend.properties";
    URL input = RegisterUtil.class.getResource(confFile);
    E.checkState(input != null, "Can't read file '%s' as stream", confFile);
    PropertiesConfiguration props = null;
    try {
        props = new Configurations().properties(input);
    } catch (ConfigurationException e) {
        throw new HugeException("Can't load config file: %s", e, confFile);
    }
    HugeConfig config = new HugeConfig(props);
    List<String> backends = config.get(DistOptions.BACKENDS);
    for (String backend : backends) {
        registerBackend(backend);
    }
}
Also used : ConfigurationException(org.apache.commons.configuration2.ex.ConfigurationException) Configurations(org.apache.commons.configuration2.builder.fluent.Configurations) HugeConfig(com.baidu.hugegraph.config.HugeConfig) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration) HugeException(com.baidu.hugegraph.HugeException) URL(java.net.URL)

Example 28 with HugeConfig

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

the class BinaryScatterSerializerTest method testVertex.

@Test
public void testVertex() {
    HugeConfig config = FakeObjects.newConfig();
    BinaryScatterSerializer ser = new BinaryScatterSerializer(config);
    HugeEdge edge = new FakeObjects().newEdge(123, 456);
    BackendEntry entry1 = ser.writeVertex(edge.sourceVertex());
    HugeVertex vertex1 = ser.readVertex(edge.graph(), entry1);
    Assert.assertEquals(edge.sourceVertex(), vertex1);
    assertCollectionEquals(edge.sourceVertex().getProperties(), vertex1.getProperties());
    BackendEntry entry2 = ser.writeVertex(edge.targetVertex());
    HugeVertex vertex2 = ser.readVertex(edge.graph(), entry2);
    Assert.assertEquals(edge.targetVertex(), vertex2);
    assertCollectionEquals(edge.targetVertex().getProperties(), vertex2.getProperties());
    Whitebox.setInternalState(vertex2, "removed", true);
    Assert.assertTrue(vertex2.removed());
    BackendEntry entry3 = ser.writeVertex(vertex2);
    Assert.assertEquals(0, entry3.columnsSize());
    Assert.assertNull(ser.readVertex(edge.graph(), null));
}
Also used : BackendEntry(com.baidu.hugegraph.backend.store.BackendEntry) BinaryBackendEntry(com.baidu.hugegraph.backend.serializer.BinaryBackendEntry) BinaryScatterSerializer(com.baidu.hugegraph.backend.serializer.BinaryScatterSerializer) FakeObjects(com.baidu.hugegraph.unit.FakeObjects) HugeEdge(com.baidu.hugegraph.structure.HugeEdge) HugeConfig(com.baidu.hugegraph.config.HugeConfig) HugeVertex(com.baidu.hugegraph.structure.HugeVertex) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Example 29 with HugeConfig

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

the class SerializerFactoryTest method testSerializer.

@Test
public void testSerializer() {
    HugeConfig config = FakeObjects.newConfig();
    AbstractSerializer serializer = SerializerFactory.serializer(config, "text");
    Assert.assertEquals(TextSerializer.class, serializer.getClass());
    serializer = SerializerFactory.serializer(config, "binary");
    Assert.assertEquals(BinarySerializer.class, serializer.getClass());
    serializer = SerializerFactory.serializer(config, "binaryscatter");
    Assert.assertEquals(BinaryScatterSerializer.class, serializer.getClass());
    Assert.assertThrows(BackendException.class, () -> {
        SerializerFactory.serializer(config, "invalid");
    }, e -> {
        Assert.assertContains("Not exists serializer:", e.getMessage());
    });
}
Also used : AbstractSerializer(com.baidu.hugegraph.backend.serializer.AbstractSerializer) HugeConfig(com.baidu.hugegraph.config.HugeConfig) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Example 30 with HugeConfig

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

the class ComputerOptionsTest method testOptions.

@Test
public void testOptions() {
    MapConfiguration mapConfig = new MapConfiguration(options);
    HugeConfig config = new HugeConfig(mapConfig);
    Map<String, TypedOption<?, ?>> allOptions = ComputerOptions.instance().options();
    Collection<TypedOption<?, ?>> typedOptions = allOptions.values();
    for (TypedOption<?, ?> typedOption : typedOptions) {
        Object value = config.get(typedOption);
        String key = typedOption.name();
        if (options.containsKey(key)) {
            Assert.assertEquals(String.valueOf(value), options.get(key));
        } else {
            Assert.assertNull(value);
        }
    }
}
Also used : MapConfiguration(org.apache.commons.configuration.MapConfiguration) TypedOption(com.baidu.hugegraph.config.TypedOption) HugeConfig(com.baidu.hugegraph.config.HugeConfig) 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