Search in sources :

Example 6 with ExternalException

use of com.baidu.hugegraph.exception.ExternalException in project incubator-hugegraph-toolchain by apache.

the class VertexLabelService method update.

public void update(VertexLabelUpdateEntity entity, int connId) {
    HugeClient client = this.client(connId);
    VertexLabel vertexLabel = convert(entity, client);
    // All existed indexlabels
    List<IndexLabel> existedIndexLabels = client.schema().getIndexLabels();
    List<String> existedIndexLabelNames = collectNames(existedIndexLabels);
    List<String> addedIndexLabelNames = entity.getAppendPropertyIndexNames();
    List<IndexLabel> addedIndexLabels = convertIndexLabels(entity.getAppendPropertyIndexes(), client, true, entity.getName());
    List<String> removedIndexLabelNames = entity.getRemovePropertyIndexes();
    if (addedIndexLabelNames != null) {
        for (String name : addedIndexLabelNames) {
            if (existedIndexLabelNames.contains(name)) {
                throw new ExternalException("schema.vertexlabel.update.append-index-existed", entity.getName(), name);
            }
        }
    }
    if (removedIndexLabelNames != null) {
        for (String name : removedIndexLabelNames) {
            if (!existedIndexLabelNames.contains(name)) {
                throw new ExternalException("schema.vertexlabel.update.remove-index-unexisted", entity.getName(), name);
            }
        }
    }
    try {
        // NOTE: property can append but doesn't support eliminate now
        client.schema().appendVertexLabel(vertexLabel);
    } catch (Exception e) {
        throw new ExternalException("schema.vertexlabel.update.failed", e, entity.getName());
    }
    this.piService.addBatch(addedIndexLabels, client);
    this.piService.removeBatch(removedIndexLabelNames, 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 7 with ExternalException

use of com.baidu.hugegraph.exception.ExternalException 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 8 with ExternalException

use of com.baidu.hugegraph.exception.ExternalException 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 9 with ExternalException

use of com.baidu.hugegraph.exception.ExternalException in project incubator-hugegraph-toolchain by apache.

the class TomcatServletConfig method customize.

@Override
public void customize(TomcatServletWebServerFactory factory) {
    // Use customized server port
    String host = this.config.get(HubbleOptions.SERVER_HOST);
    try {
        factory.setAddress(InetAddress.getByName(host));
    } catch (UnknownHostException e) {
        throw new ExternalException("service.unknown-host", e, host);
    }
    factory.setPort(this.config.get(HubbleOptions.SERVER_PORT));
    factory.addContextCustomizers(context -> {
        context.setCookieProcessor(new LegacyCookieProcessor());
    });
}
Also used : UnknownHostException(java.net.UnknownHostException) ExternalException(com.baidu.hugegraph.exception.ExternalException) LegacyCookieProcessor(org.apache.tomcat.util.http.LegacyCookieProcessor)

Example 10 with ExternalException

use of com.baidu.hugegraph.exception.ExternalException in project incubator-hugegraph-toolchain by apache.

the class GraphConnectionController method get.

@GetMapping("{id}")
public GraphConnection get(@PathVariable("id") int id) {
    GraphConnection entity = this.connService.get(id);
    if (entity == null) {
        throw new ExternalException("graph-connection.not-exist.id", id);
    }
    if (!this.poolService.containsKey(id)) {
        this.sslService.configSSL(this.config, entity);
        HugeClient client = HugeClientUtil.tryConnect(entity);
        this.poolService.put(entity, client);
    }
    return entity;
}
Also used : HugeClient(com.baidu.hugegraph.driver.HugeClient) GraphConnection(com.baidu.hugegraph.entity.GraphConnection) ExternalException(com.baidu.hugegraph.exception.ExternalException) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

ExternalException (com.baidu.hugegraph.exception.ExternalException)42 HugeClient (com.baidu.hugegraph.driver.HugeClient)14 FileMapping (com.baidu.hugegraph.entity.load.FileMapping)11 ServerException (com.baidu.hugegraph.exception.ServerException)11 GraphConnection (com.baidu.hugegraph.entity.GraphConnection)9 JobManager (com.baidu.hugegraph.entity.load.JobManager)9 DeleteMapping (org.springframework.web.bind.annotation.DeleteMapping)9 IndexLabel (com.baidu.hugegraph.structure.schema.IndexLabel)8 PostMapping (org.springframework.web.bind.annotation.PostMapping)8 LoadTask (com.baidu.hugegraph.entity.load.LoadTask)5 VertexLabel (com.baidu.hugegraph.structure.schema.VertexLabel)5 PutMapping (org.springframework.web.bind.annotation.PutMapping)5 EdgeLabel (com.baidu.hugegraph.structure.schema.EdgeLabel)4 PropertyKey (com.baidu.hugegraph.structure.schema.PropertyKey)4 InternalException (com.baidu.hugegraph.exception.InternalException)3 GetMapping (org.springframework.web.bind.annotation.GetMapping)3 EdgeMapping (com.baidu.hugegraph.entity.load.EdgeMapping)2 VertexMapping (com.baidu.hugegraph.entity.load.VertexMapping)2 GremlinCollection (com.baidu.hugegraph.entity.query.GremlinCollection)2 ClientException (com.baidu.hugegraph.rest.ClientException)2