Search in sources :

Example 41 with HugeConfig

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

the class LoadDetectFilter method filter.

@Override
public void filter(ContainerRequestContext context) {
    if (LoadDetectFilter.isWhiteAPI(context)) {
        return;
    }
    HugeConfig config = this.configProvider.get();
    int maxWorkerThreads = config.get(ServerOptions.MAX_WORKER_THREADS);
    WorkLoad load = this.loadProvider.get();
    // There will be a thread doesn't work, dedicated to statistics
    if (load.incrementAndGet() >= maxWorkerThreads) {
        throw new ServiceUnavailableException(String.format("The server is too busy to process the request, " + "you can config %s to adjust it or try again later", ServerOptions.MAX_WORKER_THREADS.name()));
    }
    long minFreeMemory = config.get(ServerOptions.MIN_FREE_MEMORY);
    long allocatedMem = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
    long presumableFreeMem = (Runtime.getRuntime().maxMemory() - allocatedMem) / Bytes.MB;
    if (presumableFreeMem < minFreeMemory) {
        gcIfNeeded();
        throw new ServiceUnavailableException(String.format("The server available memory %s(MB) is below than " + "threshold %s(MB) and can't process the request, " + "you can config %s to adjust it or try again later", presumableFreeMem, minFreeMemory, ServerOptions.MIN_FREE_MEMORY.name()));
    }
}
Also used : ServiceUnavailableException(jakarta.ws.rs.ServiceUnavailableException) HugeConfig(com.baidu.hugegraph.config.HugeConfig) WorkLoad(com.baidu.hugegraph.define.WorkLoad)

Example 42 with HugeConfig

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

the class StandardAuthenticator method setup.

@Override
public void setup(HugeConfig config) {
    String graphName = config.get(ServerOptions.AUTH_GRAPH_STORE);
    Map<String, String> graphConfs = ConfigUtil.scanGraphsDir(config.get(ServerOptions.GRAPHS));
    String graphPath = graphConfs.get(graphName);
    E.checkArgument(graphPath != null, "Can't find graph name '%s' in config '%s' at " + "'rest-server.properties' to store auth information, " + "please ensure the value of '%s' matches it correctly", graphName, ServerOptions.GRAPHS, ServerOptions.AUTH_GRAPH_STORE.name());
    HugeConfig graphConfig = new HugeConfig(graphPath);
    if (config.getProperty(INITING_STORE) != null && config.getBoolean(INITING_STORE)) {
        // Forced set RAFT_MODE to false when initializing backend
        graphConfig.setProperty(CoreOptions.RAFT_MODE.name(), "false");
    }
    this.graph = (HugeGraph) GraphFactory.open(graphConfig);
    String remoteUrl = config.get(ServerOptions.AUTH_REMOTE_URL);
    if (StringUtils.isNotEmpty(remoteUrl)) {
        RpcClientProviderWithAuth clientProvider = new RpcClientProviderWithAuth(config);
        this.graph.switchAuthManager(clientProvider.authManager());
    }
}
Also used : RpcClientProviderWithAuth(com.baidu.hugegraph.rpc.RpcClientProviderWithAuth) HugeConfig(com.baidu.hugegraph.config.HugeConfig)

Example 43 with HugeConfig

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

the class GraphManager method loadGraph.

private void loadGraph(String name, String path) {
    final Graph graph = GraphFactory.open(path);
    this.graphs.put(name, graph);
    HugeConfig config = (HugeConfig) graph.configuration();
    config.file(path);
    LOG.info("Graph '{}' was successfully configured via '{}'", name, path);
    if (this.requireAuthentication() && !(graph instanceof HugeGraphAuthProxy)) {
        LOG.warn("You may need to support access control for '{}' with {}", path, HugeFactoryAuthProxy.GRAPH_FACTORY);
    }
}
Also used : Graph(org.apache.tinkerpop.gremlin.structure.Graph) HugeGraph(com.baidu.hugegraph.HugeGraph) HugeConfig(com.baidu.hugegraph.config.HugeConfig) HugeGraphAuthProxy(com.baidu.hugegraph.auth.HugeGraphAuthProxy)

Example 44 with HugeConfig

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

the class GraphManager method createGraph.

public HugeGraph createGraph(String name, String configText) {
    E.checkArgument(this.conf.get(ServerOptions.ENABLE_DYNAMIC_CREATE_DROP), "Not allowed to create graph '%s' dynamically, " + "please set `enable_dynamic_create_drop` to true.", name);
    E.checkArgument(StringUtils.isNotEmpty(name), "The graph name can't be null or empty");
    E.checkArgument(!this.graphs().contains(name), "The graph name '%s' has existed", name);
    PropertiesConfiguration propConfig = ConfigUtil.buildConfig(configText);
    HugeConfig config = new HugeConfig(propConfig);
    this.checkOptions(config);
    return this.createGraph(config, name);
}
Also used : HugeConfig(com.baidu.hugegraph.config.HugeConfig) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration)

Example 45 with HugeConfig

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

the class RestServer method start.

public static RestServer start(String conf, EventHub hub) throws Exception {
    LOG.info("RestServer starting...");
    ApiVersion.check();
    HugeConfig config = new HugeConfig(conf);
    RestServer server = new RestServer(config, hub);
    server.start();
    LOG.info("RestServer started");
    return server;
}
Also used : HugeConfig(com.baidu.hugegraph.config.HugeConfig)

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