Search in sources :

Example 16 with HugeClient

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

the class VertexLabelService method list.

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

Example 17 with HugeClient

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

the class VertexLabelService method get.

public VertexLabelEntity get(String name, int connId) {
    HugeClient client = this.client(connId);
    try {
        VertexLabel vertexLabel = client.schema().getVertexLabel(name);
        List<IndexLabel> indexLabels = client.schema().getIndexLabels();
        return join(vertexLabel, indexLabels);
    } catch (ServerException e) {
        if (e.status() == Constant.STATUS_NOT_FOUND) {
            throw new ExternalException("schema.vertexlabel.not-exist", e, name);
        }
        throw new ExternalException("schema.vertexlabel.get.failed", e, name);
    }
}
Also used : HugeClient(com.baidu.hugegraph.driver.HugeClient) ServerException(com.baidu.hugegraph.exception.ServerException) VertexLabel(com.baidu.hugegraph.structure.schema.VertexLabel) IndexLabel(com.baidu.hugegraph.structure.schema.IndexLabel) ExternalException(com.baidu.hugegraph.exception.ExternalException)

Example 18 with HugeClient

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

the class VertexLabelService method add.

public void add(VertexLabelEntity entity, int connId) {
    HugeClient client = this.client(connId);
    VertexLabel vertexLabel = convert(entity, client);
    try {
        client.schema().addVertexLabel(vertexLabel);
    } catch (Exception e) {
        throw new ExternalException("schema.vertexlabel.create.failed", e, entity.getName());
    }
    List<IndexLabel> indexLabels = collectIndexLabels(entity, client);
    this.piService.addBatch(indexLabels, client);
}
Also used : HugeClient(com.baidu.hugegraph.driver.HugeClient) VertexLabel(com.baidu.hugegraph.structure.schema.VertexLabel) IndexLabel(com.baidu.hugegraph.structure.schema.IndexLabel) ExternalException(com.baidu.hugegraph.exception.ExternalException) ServerException(com.baidu.hugegraph.exception.ServerException) ExternalException(com.baidu.hugegraph.exception.ExternalException)

Example 19 with HugeClient

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

the class FileLoadTest method testHttpsClientValueMapping.

@Test
public void testHttpsClientValueMapping() {
    ioUtil.write("vertex_person.csv", "tiny,1,1,1", "mary,2,2,2");
    String[] args = new String[] { "-f", structPath("value_mapping/struct.json"), "-s", configPath("value_mapping/schema.groovy"), "-g", GRAPH, "-h", SERVER, "-p", String.valueOf(HTTPS_PORT), "--protocol", HTTPS_PROTOCOL, "--trust-store-file", TRUST_STORE_FILE, "--trust-store-password", "hugegraph", "--batch-insert-threads", "2", "--test-mode", "true" };
    HugeGraphLoader.main(args);
    HugeClient httpsClient = null;
    try {
        httpsClient = HugeClient.builder(HTTPS_URL, GRAPH).configSSL(TRUST_STORE_FILE, "hugegraph").build();
        List<Vertex> vertices = httpsClient.graph().listVertices();
        Assert.assertEquals(2, vertices.size());
    } finally {
        clearAndClose(httpsClient, GRAPH);
    }
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) HugeClient(com.baidu.hugegraph.driver.HugeClient) Test(org.junit.Test)

Example 20 with HugeClient

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

the class FileLoadTest method testHttpsHolderClientValueMapping.

@Test
public void testHttpsHolderClientValueMapping() {
    ioUtil.write("vertex_person.csv", "marko,1,1,1", "vadas,2,2,2");
    String[] args = new String[] { "-f", structPath("value_mapping/struct.json"), "-s", configPath("value_mapping/schema.groovy"), "-g", GRAPH, "-h", SERVER, "-p", String.valueOf(HTTPS_PORT), "--protocol", HTTPS_PROTOCOL, "--trust-store-file", TRUST_STORE_FILE, "--trust-store-password", "hugegraph", "--batch-insert-threads", "2", "--test-mode", "true" };
    HugeGraphLoader.main(args);
    LoadOptions options = new LoadOptions();
    options.host = SERVER;
    options.port = HTTPS_PORT;
    options.graph = GRAPH;
    options.protocol = HTTPS_PROTOCOL;
    options.trustStoreFile = TRUST_STORE_FILE;
    options.trustStoreToken = "hugegraph";
    HugeClient httpsClient = null;
    try {
        httpsClient = HugeClientHolder.create(options);
        List<Vertex> vertices = httpsClient.graph().listVertices();
        Assert.assertEquals(2, vertices.size());
    } finally {
        clearAndClose(httpsClient, GRAPH);
    }
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) HugeClient(com.baidu.hugegraph.driver.HugeClient) LoadOptions(com.baidu.hugegraph.loader.executor.LoadOptions) Test(org.junit.Test)

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