Search in sources :

Example 21 with HugeConfig

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

the class CassandraTest method testParseReplicaWithSimpleStrategyAndEmptyReplica.

@Test
public void testParseReplicaWithSimpleStrategyAndEmptyReplica() {
    String strategy = CassandraOptions.CASSANDRA_STRATEGY.name();
    String replica = CassandraOptions.CASSANDRA_REPLICATION.name();
    Configuration conf = new PropertiesConfiguration();
    conf.setProperty(strategy, "SimpleStrategy");
    conf.setProperty(replica, ImmutableList.of(""));
    HugeConfig config = new HugeConfig(conf);
    Assert.assertThrows(RuntimeException.class, () -> {
        Whitebox.invokeStatic(CassandraStore.class, "parseReplica", config);
    });
}
Also used : Configuration(org.apache.commons.configuration2.Configuration) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration) HugeConfig(com.baidu.hugegraph.config.HugeConfig) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration) Test(org.junit.Test)

Example 22 with HugeConfig

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

the class SerializerFactory method serializer.

public static AbstractSerializer serializer(HugeConfig config, String name) {
    name = name.toLowerCase();
    switch(name) {
        case "binary":
            return new BinarySerializer(config);
        case "binaryscatter":
            return new BinaryScatterSerializer(config);
        case "text":
            return new TextSerializer(config);
        default:
    }
    Class<? extends AbstractSerializer> clazz = serializers.get(name);
    if (clazz == null) {
        throw new BackendException("Not exists serializer: '%s'", name);
    }
    assert AbstractSerializer.class.isAssignableFrom(clazz);
    try {
        return clazz.getConstructor(HugeConfig.class).newInstance(config);
    } catch (Exception e) {
        throw new BackendException(e);
    }
}
Also used : HugeConfig(com.baidu.hugegraph.config.HugeConfig) BackendException(com.baidu.hugegraph.backend.BackendException) BackendException(com.baidu.hugegraph.backend.BackendException)

Example 23 with HugeConfig

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

the class RaftSharedContext method nodeOptions.

public NodeOptions nodeOptions() throws IOException {
    HugeConfig config = this.config();
    PeerId selfId = new PeerId();
    selfId.parse(config.get(CoreOptions.RAFT_ENDPOINT));
    NodeOptions nodeOptions = new NodeOptions();
    nodeOptions.setEnableMetrics(false);
    nodeOptions.setRpcProcessorThreadPoolSize(config.get(CoreOptions.RAFT_RPC_THREADS));
    nodeOptions.setRpcConnectTimeoutMs(config.get(CoreOptions.RAFT_RPC_CONNECT_TIMEOUT));
    nodeOptions.setRpcDefaultTimeout(config.get(CoreOptions.RAFT_RPC_TIMEOUT));
    int electionTimeout = config.get(CoreOptions.RAFT_ELECTION_TIMEOUT);
    nodeOptions.setElectionTimeoutMs(electionTimeout);
    nodeOptions.setDisableCli(false);
    int snapshotInterval = config.get(CoreOptions.RAFT_SNAPSHOT_INTERVAL);
    nodeOptions.setSnapshotIntervalSecs(snapshotInterval);
    Configuration groupPeers = new Configuration();
    String groupPeersStr = config.get(CoreOptions.RAFT_GROUP_PEERS);
    if (!groupPeers.parse(groupPeersStr)) {
        throw new HugeException("Failed to parse group peers %s", groupPeersStr);
    }
    nodeOptions.setInitialConf(groupPeers);
    String raftPath = config.get(CoreOptions.RAFT_PATH);
    String logUri = Paths.get(raftPath, "log").toString();
    FileUtils.forceMkdir(new File(logUri));
    nodeOptions.setLogUri(logUri);
    String metaUri = Paths.get(raftPath, "meta").toString();
    FileUtils.forceMkdir(new File(metaUri));
    nodeOptions.setRaftMetaUri(metaUri);
    if (config.get(CoreOptions.RAFT_USE_SNAPSHOT)) {
        String snapshotUri = Paths.get(raftPath, "snapshot").toString();
        FileUtils.forceMkdir(new File(snapshotUri));
        nodeOptions.setSnapshotUri(snapshotUri);
    }
    RaftOptions raftOptions = nodeOptions.getRaftOptions();
    /*
         * NOTE: if buffer size is too small(<=1024), will throw exception
         * "LogManager is busy, disk queue overload"
         */
    raftOptions.setApplyBatch(config.get(CoreOptions.RAFT_APPLY_BATCH));
    raftOptions.setDisruptorBufferSize(config.get(CoreOptions.RAFT_QUEUE_SIZE));
    raftOptions.setDisruptorPublishEventWaitTimeoutSecs(config.get(CoreOptions.RAFT_QUEUE_PUBLISH_TIMEOUT));
    raftOptions.setReplicatorPipeline(config.get(CoreOptions.RAFT_REPLICATOR_PIPELINE));
    raftOptions.setOpenStatistics(false);
    raftOptions.setReadOnlyOptions(ReadOnlyOption.valueOf(config.get(CoreOptions.RAFT_READ_STRATEGY)));
    return nodeOptions;
}
Also used : RaftOptions(com.alipay.sofa.jraft.option.RaftOptions) Configuration(com.alipay.sofa.jraft.conf.Configuration) NodeOptions(com.alipay.sofa.jraft.option.NodeOptions) HugeConfig(com.baidu.hugegraph.config.HugeConfig) HugeException(com.baidu.hugegraph.HugeException) File(java.io.File) PeerId(com.alipay.sofa.jraft.entity.PeerId)

Example 24 with HugeConfig

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

the class GremlinQueryAPI method client.

public GremlinClient client() {
    if (this.client != null) {
        return this.client;
    }
    HugeConfig config = this.configProvider.get();
    String url = config.get(ServerOptions.GREMLIN_SERVER_URL);
    int timeout = config.get(ServerOptions.GREMLIN_SERVER_TIMEOUT) * 1000;
    int maxRoutes = config.get(ServerOptions.GREMLIN_SERVER_MAX_ROUTE);
    this.client = new GremlinClient(url, timeout, maxRoutes, maxRoutes);
    return this.client;
}
Also used : HugeConfig(com.baidu.hugegraph.config.HugeConfig)

Example 25 with HugeConfig

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

the class GraphsAPI method getConf.

@GET
@Timed
@Path("{name}/conf")
@Produces(APPLICATION_JSON_WITH_CHARSET)
@RolesAllowed("admin")
public File getConf(@Context GraphManager manager, @PathParam("name") String name) {
    LOG.debug("Get graph configuration by name '{}'", name);
    HugeGraph g = graph4admin(manager, name);
    HugeConfig config = (HugeConfig) g.configuration();
    File file = config.file();
    if (file == null) {
        throw new NotSupportedException("Can't access the api in " + "a node which started with non local file config.");
    }
    return file;
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) HugeConfig(com.baidu.hugegraph.config.HugeConfig) NotSupportedException(jakarta.ws.rs.NotSupportedException) File(java.io.File) Path(jakarta.ws.rs.Path) RolesAllowed(jakarta.annotation.security.RolesAllowed) Produces(jakarta.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(jakarta.ws.rs.GET)

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