Search in sources :

Example 31 with HugeClient

use of com.baidu.hugegraph.driver.HugeClient in project incubator-hugegraph-toolchain by apache.

the class PropertyIndexService method checkConflict.

public ConflictStatus checkConflict(PropertyIndex entity, int connId) {
    HugeClient client = this.client(connId);
    String name = entity.getName();
    IndexLabel newIndexLabel = convert(entity, client);
    IndexLabel oldIndexLabel = convert(this.get(name, connId), client);
    if (oldIndexLabel == null) {
        return ConflictStatus.PASSED;
    } else if (isEqual(newIndexLabel, oldIndexLabel)) {
        return ConflictStatus.EXISTED;
    } else {
        return ConflictStatus.DUPNAME;
    }
}
Also used : HugeClient(com.baidu.hugegraph.driver.HugeClient) IndexLabel(com.baidu.hugegraph.structure.schema.IndexLabel)

Example 32 with HugeClient

use of com.baidu.hugegraph.driver.HugeClient in project incubator-hugegraph-toolchain by apache.

the class PropertyIndexService method list.

public List<PropertyIndex> list(Collection<String> names, int connId, boolean emptyAsAll) {
    HugeClient client = this.client(connId);
    List<IndexLabel> indexLabels;
    if (CollectionUtils.isEmpty(names)) {
        if (emptyAsAll) {
            indexLabels = client.schema().getIndexLabels();
        } else {
            indexLabels = new ArrayList<>();
        }
    } else {
        indexLabels = client.schema().getIndexLabels(new ArrayList<>(names));
    }
    List<PropertyIndex> results = new ArrayList<>(indexLabels.size());
    indexLabels.forEach(indexLabel -> {
        results.add(convert(indexLabel));
    });
    return results;
}
Also used : HugeClient(com.baidu.hugegraph.driver.HugeClient) IndexLabel(com.baidu.hugegraph.structure.schema.IndexLabel) ArrayList(java.util.ArrayList) PropertyIndex(com.baidu.hugegraph.entity.schema.PropertyIndex)

Example 33 with HugeClient

use of com.baidu.hugegraph.driver.HugeClient in project incubator-hugegraph-toolchain by apache.

the class HugeClientPoolService method getOrCreate.

public synchronized HugeClient getOrCreate(Integer id) {
    HugeClient client = super.get(id);
    if (client != null) {
        return client;
    }
    GraphConnection connection = this.connService.get(id);
    if (connection == null) {
        throw new ExternalException("graph-connection.get.failed", id);
    }
    if (connection.getTimeout() == null) {
        int timeout = this.config.get(HubbleOptions.CLIENT_REQUEST_TIMEOUT);
        connection.setTimeout(timeout);
    }
    this.sslService.configSSL(this.config, connection);
    client = HugeClientUtil.tryConnect(connection);
    this.put(id, client);
    return client;
}
Also used : HugeClient(com.baidu.hugegraph.driver.HugeClient) GraphConnection(com.baidu.hugegraph.entity.GraphConnection) ExternalException(com.baidu.hugegraph.exception.ExternalException)

Example 34 with HugeClient

use of com.baidu.hugegraph.driver.HugeClient in project incubator-hugegraph-toolchain by apache.

the class LicenseService method updateGraphStatus.

private void updateGraphStatus(GraphConnection conn) {
    HugeClient client;
    try {
        client = this.poolService.getOrCreate(conn.getId());
    } catch (Exception e) {
        String msg = this.getMessage("graph-connection.client.unavailable", conn.getName());
        conn.setEnabled(false);
        conn.setDisableReason(msg);
        this.connService.update(conn);
        return;
    }
    conn.setEnabled(true);
    conn.setDisableReason("");
    this.connService.update(conn);
}
Also used : HugeClient(com.baidu.hugegraph.driver.HugeClient)

Example 35 with HugeClient

use of com.baidu.hugegraph.driver.HugeClient in project hugegraph-computer by hugegraph.

the class RingsDetectionWithFilterTest method setup.

@BeforeClass
public static void setup() {
    clearAll();
    HugeClient client = client();
    SchemaManager schema = client.schema();
    schema.propertyKey("weight").asInt().ifNotExist().create();
    schema.vertexLabel("user").properties("weight").useCustomizeStringId().ifNotExist().create();
    schema.edgeLabel("know").sourceLabel("user").targetLabel("user").properties("weight").ifNotExist().create();
    GraphManager graph = client.graph();
    Vertex vA = graph.addVertex(T.label, "user", T.id, "A", "weight", 1);
    Vertex vB = graph.addVertex(T.label, "user", T.id, "B", "weight", 1);
    Vertex vC = graph.addVertex(T.label, "user", T.id, "C", "weight", 1);
    Vertex vD = graph.addVertex(T.label, "user", T.id, "D", "weight", 1);
    Vertex vE = graph.addVertex(T.label, "user", T.id, "E", "weight", 3);
    vA.addEdge("know", vB, "weight", 1);
    vA.addEdge("know", vC, "weight", 1);
    vA.addEdge("know", vD, "weight", 1);
    vB.addEdge("know", vA, "weight", 2);
    vB.addEdge("know", vC, "weight", 1);
    vB.addEdge("know", vE, "weight", 1);
    vC.addEdge("know", vA, "weight", 1);
    vC.addEdge("know", vB, "weight", 1);
    vC.addEdge("know", vD, "weight", 1);
    vD.addEdge("know", vC, "weight", 1);
    vD.addEdge("know", vE, "weight", 1);
    vE.addEdge("know", vC, "weight", 1);
    RingsDetectionTestOutput.EXPECT_RINGS = EXPECT_RINGS;
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) HugeClient(com.baidu.hugegraph.driver.HugeClient) GraphManager(com.baidu.hugegraph.driver.GraphManager) SchemaManager(com.baidu.hugegraph.driver.SchemaManager) BeforeClass(org.junit.BeforeClass)

Aggregations

HugeClient (com.baidu.hugegraph.driver.HugeClient)66 Vertex (com.baidu.hugegraph.structure.graph.Vertex)21 ArrayList (java.util.ArrayList)16 ExternalException (com.baidu.hugegraph.exception.ExternalException)15 IndexLabel (com.baidu.hugegraph.structure.schema.IndexLabel)14 ServerException (com.baidu.hugegraph.exception.ServerException)12 GraphManager (com.baidu.hugegraph.driver.GraphManager)11 Edge (com.baidu.hugegraph.structure.graph.Edge)10 SchemaManager (com.baidu.hugegraph.driver.SchemaManager)9 ResultSet (com.baidu.hugegraph.structure.gremlin.ResultSet)8 EdgeLabel (com.baidu.hugegraph.structure.schema.EdgeLabel)8 Test (org.junit.Test)8 VertexLabel (com.baidu.hugegraph.structure.schema.VertexLabel)7 PropertyKey (com.baidu.hugegraph.structure.schema.PropertyKey)6 ExecuteHistory (com.baidu.hugegraph.entity.query.ExecuteHistory)4 GraphView (com.baidu.hugegraph.entity.query.GraphView)4 LoadOptions (com.baidu.hugegraph.loader.executor.LoadOptions)4 ClientException (com.baidu.hugegraph.rest.ClientException)4 BeforeClass (org.junit.BeforeClass)4 GraphConnection (com.baidu.hugegraph.entity.GraphConnection)3