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);
}
}
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");
}
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;
}
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);
}
}
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);
}
}
Aggregations