Search in sources :

Example 11 with HugeConfig

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

the class GremlinQueryService method edgesOfVertex.

private Map<String, Edge> edgesOfVertex(TypedResult result, Map<Object, Vertex> vertices, HugeClient client) {
    final HugeConfig config = this.config;
    int batchSize = config.get(HubbleOptions.GREMLIN_BATCH_QUERY_IDS);
    int edgeLimit = config.get(HubbleOptions.GREMLIN_EDGES_TOTAL_LIMIT);
    int degreeLimit = config.get(HubbleOptions.GREMLIN_VERTEX_DEGREE_LIMIT);
    Set<Object> vertexIds = vertices.keySet();
    Map<String, Edge> edges = new HashMap<>(vertexIds.size());
    Iterables.partition(vertexIds, batchSize).forEach(batch -> {
        List<String> escapedIds = batch.stream().map(GremlinUtil::escapeId).collect(Collectors.toList());
        String ids = StringUtils.join(escapedIds, ",");
        // Any better way to find two vertices has linked?
        String gremlin;
        if (result.getType().isPath()) {
            // If result type is path, the vertices count not too much in theory
            gremlin = String.format("g.V(%s).bothE().local(limit(%s)).dedup()", ids, degreeLimit);
        } else {
            gremlin = String.format("g.V(%s).bothE().dedup().limit(%s)", ids, edgeLimit);
        }
        ResultSet resultSet = client.gremlin().gremlin(gremlin).execute();
        // The edges count for per vertex
        Map<Object, Integer> degrees = new HashMap<>(resultSet.size());
        for (Iterator<Result> iter = resultSet.iterator(); iter.hasNext(); ) {
            Edge edge = iter.next().getEdge();
            Object source = edge.sourceId();
            Object target = edge.targetId();
            // only add the interconnected edges of the found vertices
            if (!vertexIds.contains(source) || !vertexIds.contains(target)) {
                continue;
            }
            edges.put(edge.id(), edge);
            if (edges.size() >= edgeLimit) {
                break;
            }
            int deg = degrees.compute(source, (k, v) -> v == null ? 1 : v + 1);
            if (deg >= degreeLimit) {
                break;
            }
            deg = degrees.compute(target, (k, v) -> v == null ? 1 : v + 1);
            if (deg >= degreeLimit) {
                break;
            }
        }
    });
    return edges;
}
Also used : Direction(com.baidu.hugegraph.structure.constant.Direction) Iterables(com.google.common.collect.Iterables) Type(com.baidu.hugegraph.entity.query.GremlinResult.Type) ServerException(com.baidu.hugegraph.exception.ServerException) ExternalException(com.baidu.hugegraph.exception.ExternalException) AdjacentQuery(com.baidu.hugegraph.entity.query.AdjacentQuery) IdStrategy(com.baidu.hugegraph.structure.constant.IdStrategy) VertexLabelEntity(com.baidu.hugegraph.entity.schema.VertexLabelEntity) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) Ex(com.baidu.hugegraph.util.Ex) StringUtils(org.apache.commons.lang3.StringUtils) ResultSet(com.baidu.hugegraph.structure.gremlin.ResultSet) ArrayList(java.util.ArrayList) JsonView(com.baidu.hugegraph.entity.query.JsonView) HashSet(java.util.HashSet) GremlinUtil(com.baidu.hugegraph.util.GremlinUtil) TableView(com.baidu.hugegraph.entity.query.TableView) Service(org.springframework.stereotype.Service) Map(java.util.Map) ClientException(com.baidu.hugegraph.rest.ClientException) Path(com.baidu.hugegraph.structure.graph.Path) HugeClient(com.baidu.hugegraph.driver.HugeClient) GremlinRequest(com.baidu.hugegraph.api.gremlin.GremlinRequest) ImmutableSet(com.google.common.collect.ImmutableSet) Iterator(java.util.Iterator) ImmutableMap(com.google.common.collect.ImmutableMap) GraphView(com.baidu.hugegraph.entity.query.GraphView) Set(java.util.Set) Result(com.baidu.hugegraph.structure.gremlin.Result) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) TypedResult(com.baidu.hugegraph.entity.query.TypedResult) Edge(com.baidu.hugegraph.structure.graph.Edge) IllegalGremlinException(com.baidu.hugegraph.exception.IllegalGremlinException) Vertex(com.baidu.hugegraph.structure.graph.Vertex) HubbleOptions(com.baidu.hugegraph.options.HubbleOptions) VertexLabelService(com.baidu.hugegraph.service.schema.VertexLabelService) List(java.util.List) CollectionUtils(org.springframework.util.CollectionUtils) HugeClientPoolService(com.baidu.hugegraph.service.HugeClientPoolService) Log4j2(lombok.extern.log4j.Log4j2) HugeConfig(com.baidu.hugegraph.config.HugeConfig) Comparator(java.util.Comparator) InternalException(com.baidu.hugegraph.exception.InternalException) Collections(java.util.Collections) GremlinQuery(com.baidu.hugegraph.entity.query.GremlinQuery) GremlinResult(com.baidu.hugegraph.entity.query.GremlinResult) HashMap(java.util.HashMap) HugeConfig(com.baidu.hugegraph.config.HugeConfig) Result(com.baidu.hugegraph.structure.gremlin.Result) TypedResult(com.baidu.hugegraph.entity.query.TypedResult) GremlinResult(com.baidu.hugegraph.entity.query.GremlinResult) ResultSet(com.baidu.hugegraph.structure.gremlin.ResultSet) Edge(com.baidu.hugegraph.structure.graph.Edge)

Example 12 with HugeConfig

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

the class StandardHugeGraph method drop.

@Override
public void drop() {
    this.clearBackend();
    HugeConfig config = this.configuration();
    this.storeProvider.onDeleteConfig(config);
    ConfigUtil.deleteFile(config.file());
    try {
        /*
             * It's hard to ensure all threads close the tx.
             * TODO:
             *  - schedule a tx-close to each thread,
             *   or
             *  - add forceClose() method to backend store.
             */
        this.close();
    } catch (Throwable e) {
        LOG.warn("Failed to close graph {} {}", this, e);
    }
}
Also used : HugeConfig(com.baidu.hugegraph.config.HugeConfig)

Example 13 with HugeConfig

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

the class HugeAuthenticator method setup.

@Override
public default void setup(final Map<String, Object> config) {
    E.checkState(config != null, "Must provide a 'config' in the 'authentication'");
    String path = (String) config.get("tokens");
    E.checkState(path != null, "Credentials configuration missing key 'tokens'");
    OptionSpace.register("tokens", ServerOptions.instance());
    this.setup(new HugeConfig(path));
}
Also used : HugeConfig(com.baidu.hugegraph.config.HugeConfig)

Example 14 with HugeConfig

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

the class StandardAuthenticator method initAdminUserIfNeeded.

public static void initAdminUserIfNeeded(String confFile) throws Exception {
    StandardAuthenticator auth = new StandardAuthenticator();
    HugeConfig config = new HugeConfig(confFile);
    String authClass = config.get(ServerOptions.AUTHENTICATOR);
    if (authClass.isEmpty()) {
        return;
    }
    config.addProperty(INITING_STORE, true);
    auth.setup(config);
    if (auth.graph().backendStoreFeatures().supportsPersistence()) {
        auth.initAdminUser();
    }
}
Also used : HugeConfig(com.baidu.hugegraph.config.HugeConfig)

Example 15 with HugeConfig

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

the class GraphManager method cloneGraph.

public HugeGraph cloneGraph(String name, String newName, String configText) {
    /*
         * 0. check and modify params
         * 1. create graph instance
         * 2. init backend store
         * 3. inject graph and traversal source into gremlin server context
         * 4. inject graph into rest server context
         */
    HugeGraph cloneGraph = this.graph(name);
    E.checkArgumentNotNull(cloneGraph, "The clone graph '%s' doesn't exist", name);
    E.checkArgument(StringUtils.isNotEmpty(newName), "The graph name can't be null or empty");
    E.checkArgument(!this.graphs().contains(newName), "The graph '%s' has existed", newName);
    HugeConfig cloneConfig = cloneGraph.cloneConfig(newName);
    if (StringUtils.isNotEmpty(configText)) {
        PropertiesConfiguration propConfig = ConfigUtil.buildConfig(configText);
        // Use the passed config to overwrite the old one
        propConfig.getKeys().forEachRemaining(key -> {
            cloneConfig.setProperty(key, propConfig.getProperty(key));
        });
        this.checkOptions(cloneConfig);
    }
    return this.createGraph(cloneConfig, newName);
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) HugeConfig(com.baidu.hugegraph.config.HugeConfig) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration)

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