Search in sources :

Example 11 with HugeException

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

the class LicenseVerifier method install.

public synchronized void install(HugeConfig config, GraphManager graphManager, String md5) {
    this.manager.config(config);
    this.manager.graphManager(graphManager);
    LicenseManager licenseManager = this.manager.licenseManager();
    try {
        licenseManager.uninstallLicense();
        this.verifyPublicCert(md5);
        LicenseParams params = licenseManager.installLicense();
        LOG.info("The license '{}' is successfully installed for '{}', " + "the term of validity is from {} to {}", params.subject(), params.consumerType(), params.notBefore(), params.notAfter());
    } catch (Exception e) {
        LOG.error("Failed to install license", e);
        throw new HugeException("Failed to install license", e);
    }
}
Also used : HugeException(com.baidu.hugegraph.HugeException) HugeException(com.baidu.hugegraph.HugeException) IOException(java.io.IOException)

Example 12 with HugeException

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

the class BaseApiTest method getVertexId.

protected static String getVertexId(String label, String key, String value) throws IOException {
    String props = MAPPER.writeValueAsString(ImmutableMap.of(key, value));
    Map<String, Object> params = ImmutableMap.of("label", label, "properties", URLEncoder.encode(props, "UTF-8"));
    Response r = client.get(URL_PREFIX + GRAPH_VERTEX, params);
    String content = assertResponseStatus(200, r);
    @SuppressWarnings("rawtypes") List<Map> list = readList(content, "vertices", Map.class);
    if (list.size() != 1) {
        throw new HugeException("Failed to get vertex id: %s", content);
    }
    return (String) list.get(0).get("id");
}
Also used : Response(jakarta.ws.rs.core.Response) HashMap(java.util.HashMap) MultivaluedMap(jakarta.ws.rs.core.MultivaluedMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HugeException(com.baidu.hugegraph.HugeException)

Example 13 with HugeException

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

the class RaftSharedContext method nodeOptions.

public NodeOptions nodeOptions() throws IOException {
    HugeConfig config = this.config();
    PeerId selfId = new PeerId();
    selfId.parse(config.get(CoreOptions.RAFT_ENDPOINT));
    NodeOptions nodeOptions = new NodeOptions();
    nodeOptions.setEnableMetrics(false);
    nodeOptions.setRpcProcessorThreadPoolSize(config.get(CoreOptions.RAFT_RPC_THREADS));
    nodeOptions.setRpcConnectTimeoutMs(config.get(CoreOptions.RAFT_RPC_CONNECT_TIMEOUT));
    nodeOptions.setRpcDefaultTimeout(config.get(CoreOptions.RAFT_RPC_TIMEOUT));
    int electionTimeout = config.get(CoreOptions.RAFT_ELECTION_TIMEOUT);
    nodeOptions.setElectionTimeoutMs(electionTimeout);
    nodeOptions.setDisableCli(false);
    int snapshotInterval = config.get(CoreOptions.RAFT_SNAPSHOT_INTERVAL);
    nodeOptions.setSnapshotIntervalSecs(snapshotInterval);
    Configuration groupPeers = new Configuration();
    String groupPeersStr = config.get(CoreOptions.RAFT_GROUP_PEERS);
    if (!groupPeers.parse(groupPeersStr)) {
        throw new HugeException("Failed to parse group peers %s", groupPeersStr);
    }
    nodeOptions.setInitialConf(groupPeers);
    String raftPath = config.get(CoreOptions.RAFT_PATH);
    String logUri = Paths.get(raftPath, "log").toString();
    FileUtils.forceMkdir(new File(logUri));
    nodeOptions.setLogUri(logUri);
    String metaUri = Paths.get(raftPath, "meta").toString();
    FileUtils.forceMkdir(new File(metaUri));
    nodeOptions.setRaftMetaUri(metaUri);
    if (config.get(CoreOptions.RAFT_USE_SNAPSHOT)) {
        String snapshotUri = Paths.get(raftPath, "snapshot").toString();
        FileUtils.forceMkdir(new File(snapshotUri));
        nodeOptions.setSnapshotUri(snapshotUri);
    }
    RaftOptions raftOptions = nodeOptions.getRaftOptions();
    /*
         * NOTE: if buffer size is too small(<=1024), will throw exception
         * "LogManager is busy, disk queue overload"
         */
    raftOptions.setApplyBatch(config.get(CoreOptions.RAFT_APPLY_BATCH));
    raftOptions.setDisruptorBufferSize(config.get(CoreOptions.RAFT_QUEUE_SIZE));
    raftOptions.setDisruptorPublishEventWaitTimeoutSecs(config.get(CoreOptions.RAFT_QUEUE_PUBLISH_TIMEOUT));
    raftOptions.setReplicatorPipeline(config.get(CoreOptions.RAFT_REPLICATOR_PIPELINE));
    raftOptions.setOpenStatistics(false);
    raftOptions.setReadOnlyOptions(ReadOnlyOption.valueOf(config.get(CoreOptions.RAFT_READ_STRATEGY)));
    return nodeOptions;
}
Also used : RaftOptions(com.alipay.sofa.jraft.option.RaftOptions) Configuration(com.alipay.sofa.jraft.conf.Configuration) NodeOptions(com.alipay.sofa.jraft.option.NodeOptions) HugeConfig(com.baidu.hugegraph.config.HugeConfig) HugeException(com.baidu.hugegraph.HugeException) File(java.io.File) PeerId(com.alipay.sofa.jraft.entity.PeerId)

Example 14 with HugeException

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

the class TraversalUtil method parsePredicate.

public static P<Object> parsePredicate(String predicate) {
    /*
         * Extract P from json string like {"properties": {"age": "P.gt(18)"}}
         * the `predicate` may actually be like "P.gt(18)"
         */
    Pattern pattern = Pattern.compile("^P\\.([a-z]+)\\(([\\S ]*)\\)$");
    Matcher matcher = pattern.matcher(predicate);
    if (!matcher.find()) {
        throw new HugeException("Invalid predicate: %s", predicate);
    }
    String method = matcher.group(1);
    String value = matcher.group(2);
    switch(method) {
        case "eq":
            return P.eq(predicateNumber(value));
        case "neq":
            return P.neq(predicateNumber(value));
        case "lt":
            return P.lt(predicateNumber(value));
        case "lte":
            return P.lte(predicateNumber(value));
        case "gt":
            return P.gt(predicateNumber(value));
        case "gte":
            return P.gte(predicateNumber(value));
        case "between":
            Number[] params = predicateNumbers(value, 2);
            return P.between(params[0], params[1]);
        case "inside":
            params = predicateNumbers(value, 2);
            return P.inside(params[0], params[1]);
        case "outside":
            params = predicateNumbers(value, 2);
            return P.outside(params[0], params[1]);
        case "within":
            return P.within(predicateArgs(value));
        case "textcontains":
            return ConditionP.textContains(predicateArg(value));
        case "contains":
            // Just for inner use case like auth filter
            return ConditionP.contains(predicateArg(value));
        default:
            throw new NotSupportException("predicate '%s'", method);
    }
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) NotSupportException(com.baidu.hugegraph.exception.NotSupportException) HugeException(com.baidu.hugegraph.HugeException)

Example 15 with HugeException

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

the class TraversalUtil method parsePredicate.

public static Condition parsePredicate(PropertyKey pk, String predicate) {
    Pattern pattern = Pattern.compile("^P\\.([a-z]+)\\(([\\S ]*)\\)$");
    Matcher matcher = pattern.matcher(predicate);
    if (!matcher.find()) {
        throw new HugeException("Invalid predicate: %s", predicate);
    }
    String method = matcher.group(1);
    String value = matcher.group(2);
    Object validValue;
    switch(method) {
        case "eq":
            validValue = validPropertyValue(predicateNumber(value), pk);
            return Condition.eq(pk.id(), validValue);
        case "neq":
            validValue = validPropertyValue(predicateNumber(value), pk);
            return Condition.neq(pk.id(), validValue);
        case "lt":
            validValue = validPropertyValue(predicateNumber(value), pk);
            return Condition.lt(pk.id(), validValue);
        case "lte":
            validValue = validPropertyValue(predicateNumber(value), pk);
            return Condition.lte(pk.id(), validValue);
        case "gt":
            validValue = validPropertyValue(predicateNumber(value), pk);
            return Condition.gt(pk.id(), validValue);
        case "gte":
            validValue = validPropertyValue(predicateNumber(value), pk);
            return Condition.gte(pk.id(), validValue);
        case "between":
            Number[] params = predicateNumbers(value, 2);
            Object v1 = validPropertyValue(params[0], pk);
            Object v2 = validPropertyValue(params[1], pk);
            return Condition.and(Condition.gte(pk.id(), v1), Condition.lt(pk.id(), v2));
        case "inside":
            params = predicateNumbers(value, 2);
            v1 = validPropertyValue(params[0], pk);
            v2 = validPropertyValue(params[1], pk);
            return Condition.and(Condition.gt(pk.id(), v1), Condition.lt(pk.id(), v2));
        case "outside":
            params = predicateNumbers(value, 2);
            v1 = validPropertyValue(params[0], pk);
            v2 = validPropertyValue(params[1], pk);
            return Condition.and(Condition.lt(pk.id(), v1), Condition.gt(pk.id(), v2));
        case "within":
            List<T> values = predicateArgs(value);
            List<T> validValues = new ArrayList<>(values.size());
            for (T v : values) {
                validValues.add(validPropertyValue(v, pk));
            }
            return Condition.in(pk.id(), validValues);
        case "textcontains":
            validValue = validPropertyValue(value, pk);
            return Condition.textContains(pk.id(), (String) validValue);
        case "contains":
            validValue = validPropertyValue(value, pk);
            return Condition.contains(pk.id(), validValue);
        default:
            throw new NotSupportException("predicate '%s'", method);
    }
}
Also used : Pattern(java.util.regex.Pattern) T(org.apache.tinkerpop.gremlin.structure.T) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) NotSupportException(com.baidu.hugegraph.exception.NotSupportException) HugeException(com.baidu.hugegraph.HugeException)

Aggregations

HugeException (com.baidu.hugegraph.HugeException)59 Id (com.baidu.hugegraph.backend.id.Id)11 TimeoutException (java.util.concurrent.TimeoutException)6 HugeVertex (com.baidu.hugegraph.structure.HugeVertex)5 ConfigurationException (org.apache.commons.configuration2.ex.ConfigurationException)5 NotSupportException (com.baidu.hugegraph.exception.NotSupportException)4 File (java.io.File)4 Map (java.util.Map)4 HugeGraph (com.baidu.hugegraph.HugeGraph)3 Condition (com.baidu.hugegraph.backend.query.Condition)3 ConditionQuery (com.baidu.hugegraph.backend.query.ConditionQuery)3 ConfigException (com.baidu.hugegraph.config.ConfigException)3 NotFoundException (com.baidu.hugegraph.exception.NotFoundException)3 SchemaElement (com.baidu.hugegraph.schema.SchemaElement)3 StringReader (java.io.StringReader)3 PeerId (com.alipay.sofa.jraft.entity.PeerId)2 BackendException (com.baidu.hugegraph.backend.BackendException)2 EdgeId (com.baidu.hugegraph.backend.id.EdgeId)2 IdQuery (com.baidu.hugegraph.backend.query.IdQuery)2 GraphTransaction (com.baidu.hugegraph.backend.tx.GraphTransaction)2