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()));
}
}
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());
}
}
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);
}
}
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);
}
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;
}
Aggregations