Skip to content

Commit

Permalink
Sync script util.sh with hugegraph-tools
Browse files Browse the repository at this point in the history
1. Rename UserData to Username uniformly
2. Fix EdgeLabelBuilder check nullablekeys twice

Change-Id: I174faf8e2b87d2f5673a298ce09f478570b98978
  • Loading branch information
Linary authored and zhoney committed Nov 27, 2018
1 parent 3cf3bec commit ce6e576
Show file tree
Hide file tree
Showing 12 changed files with 87 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ protected void parseProperties(HugeElement element,
}

@Override
protected void writeUserData(SchemaElement schema,
protected void writeUserdata(SchemaElement schema,
TableBackendEntry entry) {
assert entry instanceof CassandraBackendEntry;
for (Map.Entry<String, Object> e : schema.userdata().entrySet()) {
Expand All @@ -138,7 +138,7 @@ protected void writeUserData(SchemaElement schema,
}

@Override
protected void readUserData(SchemaElement schema,
protected void readUserdata(SchemaElement schema,
TableBackendEntry entry) {
assert entry instanceof CassandraBackendEntry;
// Parse all user data of a schema element
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public class HugeGraph implements GremlinGraph {

private final EventHub schemaEventHub;
private final EventHub indexEventHub;
@SuppressWarnings("UnstableApiUsage")
private final RateLimiter rateLimiter;
private final TaskManager taskManager;

Expand Down Expand Up @@ -183,6 +184,7 @@ public EventHub indexEventHub() {
return this.indexEventHub;
}

@SuppressWarnings("UnstableApiUsage")
public RateLimiter rateLimiter() {
return this.rateLimiter;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ public BackendEntry writeVertexLabel(VertexLabel vertexLabel) {
entry.column(HugeKeys.INDEX_LABELS,
this.toLongSet(vertexLabel.indexLabels()));
this.writeEnableLabelIndex(vertexLabel, entry);
this.writeUserData(vertexLabel, entry);
this.writeUserdata(vertexLabel, entry);
entry.column(HugeKeys.STATUS, vertexLabel.status().code());
return entry;
}
Expand All @@ -403,7 +403,7 @@ public BackendEntry writeEdgeLabel(EdgeLabel edgeLabel) {
entry.column(HugeKeys.INDEX_LABELS,
this.toLongSet(edgeLabel.indexLabels()));
this.writeEnableLabelIndex(edgeLabel, entry);
this.writeUserData(edgeLabel, entry);
this.writeUserdata(edgeLabel, entry);
entry.column(HugeKeys.STATUS, edgeLabel.status().code());
return entry;
}
Expand All @@ -417,7 +417,7 @@ public BackendEntry writePropertyKey(PropertyKey propertyKey) {
entry.column(HugeKeys.CARDINALITY, propertyKey.cardinality().code());
entry.column(HugeKeys.PROPERTIES,
this.toLongSet(propertyKey.properties()));
this.writeUserData(propertyKey, entry);
this.writeUserdata(propertyKey, entry);
entry.column(HugeKeys.STATUS, propertyKey.status().code());
return entry;
}
Expand Down Expand Up @@ -448,7 +448,7 @@ public VertexLabel readVertexLabel(HugeGraph graph,
vertexLabel.nullableKeys(this.toIdArray(nullableKeys));
vertexLabel.indexLabels(this.toIdArray(indexLabels));
this.readEnableLabelIndex(vertexLabel, entry);
this.readUserData(vertexLabel, entry);
this.readUserdata(vertexLabel, entry);
vertexLabel.status(SerialEnum.fromCode(SchemaStatus.class,
status.byteValue()));
return vertexLabel;
Expand Down Expand Up @@ -483,7 +483,7 @@ public EdgeLabel readEdgeLabel(HugeGraph graph, BackendEntry backendEntry) {
edgeLabel.nullableKeys(this.toIdArray(nullableKeys));
edgeLabel.indexLabels(this.toIdArray(indexLabels));
this.readEnableLabelIndex(edgeLabel, entry);
this.readUserData(edgeLabel, entry);
this.readUserdata(edgeLabel, entry);
edgeLabel.status(SerialEnum.fromCode(SchemaStatus.class,
status.byteValue()));
return edgeLabel;
Expand Down Expand Up @@ -512,7 +512,7 @@ public PropertyKey readPropertyKey(HugeGraph graph,
cardinality.byteValue()));
propertyKey.properties(this.toIdArray(properties));

this.readUserData(propertyKey, entry);
this.readUserdata(propertyKey, entry);
propertyKey.status(SerialEnum.fromCode(SchemaStatus.class,
status.byteValue()));
return propertyKey;
Expand Down Expand Up @@ -588,9 +588,9 @@ protected void readEnableLabelIndex(SchemaLabel schema,
schema.enableLabelIndex(enableLabelIndex);
}

protected abstract void writeUserData(SchemaElement schema,
protected abstract void writeUserdata(SchemaElement schema,
TableBackendEntry entry);

protected abstract void readUserData(SchemaElement schema,
protected abstract void readUserdata(SchemaElement schema,
TableBackendEntry entry);
}
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ public BackendEntry writeVertexLabel(VertexLabel vertexLabel) {
writeIds(vertexLabel.indexLabels()));
entry.column(HugeKeys.ENABLE_LABEL_INDEX,
JsonUtil.toJson(vertexLabel.enableLabelIndex()));
writeUserData(vertexLabel, entry);
writeUserdata(vertexLabel, entry);
entry.column(HugeKeys.STATUS,
JsonUtil.toJson(vertexLabel.status()));
return entry;
Expand Down Expand Up @@ -494,7 +494,7 @@ public VertexLabel readVertexLabel(HugeGraph graph,
vertexLabel.indexLabels(readIds(indexLabels));
vertexLabel.enableLabelIndex(JsonUtil.fromJson(enableLabelIndex,
Boolean.class));
readUserData(vertexLabel, entry);
readUserdata(vertexLabel, entry);
vertexLabel.status(JsonUtil.fromJson(status, SchemaStatus.class));
return vertexLabel;
}
Expand All @@ -514,7 +514,7 @@ public BackendEntry writeEdgeLabel(EdgeLabel edgeLabel) {
entry.column(HugeKeys.INDEX_LABELS, writeIds(edgeLabel.indexLabels()));
entry.column(HugeKeys.ENABLE_LABEL_INDEX,
JsonUtil.toJson(edgeLabel.enableLabelIndex()));
writeUserData(edgeLabel, entry);
writeUserdata(edgeLabel, entry);
entry.column(HugeKeys.STATUS,
JsonUtil.toJson(edgeLabel.status()));
return entry;
Expand Down Expand Up @@ -551,7 +551,7 @@ public EdgeLabel readEdgeLabel(HugeGraph graph,
edgeLabel.indexLabels(readIds(indexLabels));
edgeLabel.enableLabelIndex(JsonUtil.fromJson(enableLabelIndex,
Boolean.class));
readUserData(edgeLabel, entry);
readUserdata(edgeLabel, entry);
edgeLabel.status(JsonUtil.fromJson(status, SchemaStatus.class));
return edgeLabel;
}
Expand All @@ -565,7 +565,7 @@ public BackendEntry writePropertyKey(PropertyKey propertyKey) {
entry.column(HugeKeys.CARDINALITY,
JsonUtil.toJson(propertyKey.cardinality()));
entry.column(HugeKeys.PROPERTIES, writeIds(propertyKey.properties()));
writeUserData(propertyKey, entry);
writeUserdata(propertyKey, entry);
entry.column(HugeKeys.STATUS,
JsonUtil.toJson(propertyKey.status()));
return entry;
Expand All @@ -592,7 +592,7 @@ public PropertyKey readPropertyKey(HugeGraph graph,
propertyKey.cardinality(JsonUtil.fromJson(cardinality,
Cardinality.class));
propertyKey.properties(readIds(properties));
readUserData(propertyKey, entry);
readUserdata(propertyKey, entry);
propertyKey.status(JsonUtil.fromJson(status, SchemaStatus.class));
return propertyKey;
}
Expand Down Expand Up @@ -720,12 +720,12 @@ private static Id[] readIds(String str) {
return ids;
}

private static void writeUserData(SchemaElement schema,
private static void writeUserdata(SchemaElement schema,
TextBackendEntry entry) {
entry.column(HugeKeys.USER_DATA, JsonUtil.toJson(schema.userdata()));
}

private static void readUserData(SchemaElement schema,
private static void readUserdata(SchemaElement schema,
TextBackendEntry entry) {
// Parse all user data of a schema element
String userdataStr = entry.column(HugeKeys.USER_DATA);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public EdgeLabel create() {
this.checkProperties(Action.INSERT);
this.checkSortKeys();
this.checkNullableKeys(Action.INSERT);
this.checkNullableKeys(Action.INSERT);
this.checkUserdata(Action.INSERT);

edgeLabel = this.build();
tx.addEdgeLabel(edgeLabel);
Expand All @@ -151,7 +151,7 @@ public EdgeLabel append() {
this.checkStableVars();
this.checkProperties(Action.APPEND);
this.checkNullableKeys(Action.APPEND);
this.checkUserData(Action.APPEND);
this.checkUserdata(Action.APPEND);

for (String key : this.properties) {
PropertyKey propertyKey = this.transaction.getPropertyKey(key);
Expand Down Expand Up @@ -179,7 +179,7 @@ public EdgeLabel eliminate() {
this.checkStableVars();
this.checkProperties(Action.ELIMINATE);
this.checkNullableKeys(Action.ELIMINATE);
this.checkUserData(Action.ELIMINATE);
this.checkUserdata(Action.ELIMINATE);

for (String key : this.userdata.keySet()) {
edgeLabel.removeUserdata(key);
Expand Down Expand Up @@ -450,7 +450,7 @@ private void checkStableVars() {
}
}

private void checkUserData(Action action) {
private void checkUserdata(Action action) {
switch (action) {
case INSERT:
case APPEND:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public PropertyKey create() {
}
tx.checkIdIfRestoringMode(HugeType.PROPERTY_KEY, this.id);

this.checkUserData(Action.INSERT);
this.checkUserdata(Action.INSERT);

propertyKey = this.build();
tx.addPropertyKey(propertyKey);
Expand All @@ -102,7 +102,7 @@ public PropertyKey append() {
"since it doesn't exist", this.name);
}
this.checkStableVars();
this.checkUserData(Action.APPEND);
this.checkUserdata(Action.APPEND);

for (Map.Entry<String, Object> entry : this.userdata.entrySet()) {
propertyKey.userdata(entry.getKey(), entry.getValue());
Expand All @@ -119,7 +119,7 @@ public PropertyKey eliminate() {
"since it doesn't exist", this.name);
}
this.checkStableVars();
this.checkUserData(Action.ELIMINATE);
this.checkUserdata(Action.ELIMINATE);

for (String key : this.userdata.keySet()) {
propertyKey.removeUserdata(key);
Expand Down Expand Up @@ -271,7 +271,7 @@ private void checkStableVars() {
}
}

private void checkUserData(Action action) {
private void checkUserdata(Action action) {
switch (action) {
case INSERT:
case APPEND:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public VertexLabel create() {
this.checkProperties(Action.INSERT);
this.checkIdStrategy();
this.checkNullableKeys(Action.INSERT);
this.checkUserData(Action.INSERT);
this.checkUserdata(Action.INSERT);

vertexLabel = this.build();
tx.addVertexLabel(vertexLabel);
Expand All @@ -139,7 +139,7 @@ public VertexLabel append() {
this.checkStableVars();
this.checkProperties(Action.APPEND);
this.checkNullableKeys(Action.APPEND);
this.checkUserData(Action.APPEND);
this.checkUserdata(Action.APPEND);

for (String key : this.properties) {
PropertyKey propertyKey = this.transaction.getPropertyKey(key);
Expand Down Expand Up @@ -167,7 +167,7 @@ public VertexLabel eliminate() {
this.checkStableVars();
this.checkProperties(Action.ELIMINATE);
this.checkNullableKeys(Action.ELIMINATE);
this.checkUserData(Action.ELIMINATE);
this.checkUserdata(Action.ELIMINATE);

for (String key : this.userdata.keySet()) {
vertexLabel.removeUserdata(key);
Expand Down Expand Up @@ -450,7 +450,7 @@ private void checkStableVars() {
}
}

private void checkUserData(Action action) {
private void checkUserdata(Action action) {
switch (action) {
case INSERT:
case APPEND:
Expand Down
51 changes: 41 additions & 10 deletions hugegraph-dist/src/assembly/static/bin/util.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
#!/bin/bash

function command_available() {
local cmd=$1
if [ `command -v $cmd >/dev/null 2>&1` ]; then
return 1
else
return 0
fi
}

# read a property from .properties file
function read_property() {
# file path
Expand Down Expand Up @@ -57,10 +66,13 @@ function process_id() {
# check the port of rest server is occupied
function check_port() {
local port=`echo $1 | awk -F':' '{print $3}'`
if ! command_available "lsof"; then
echo "Required lsof but it is unavailable"
exit 1
fi
lsof -i :$port >/dev/null

if [ $? -eq 0 ]; then
echo "The port "$port" has already used"
echo "The port $port has already been used"
exit 1
fi
}
Expand Down Expand Up @@ -127,12 +139,10 @@ function free_memory() {
local mem_free=`cat /proc/meminfo | grep -w "MemFree" | awk '{print $2}'`
local mem_buffer=`cat /proc/meminfo | grep -w "Buffers" | awk '{print $2}'`
local mem_cached=`cat /proc/meminfo | grep -w "Cached" | awk '{print $2}'`

if [[ "$mem_free" == "" || "$mem_buffer" == "" || "$mem_cached" == "" ]]; then
echo "Failed to get free memory"
exit 1
fi

free=`expr $mem_free + $mem_buffer + $mem_cached`
free=`expr $free / 1024`
elif [ "$os" == "Darwin" ]; then
Expand Down Expand Up @@ -202,9 +212,29 @@ function get_ip() {
local loopback="127.0.0.1"
local ip=""
case $os in
Linux) ip=`ifconfig | grep 'inet addr:'| grep -v "$loopback" | cut -d: -f2 | awk '{ print $1}'`;;
FreeBSD|OpenBSD|Darwin) ip=`ifconfig | grep -E 'inet.[0-9]' | grep -v "$loopback" | awk '{ print $2}'`;;
SunOS) ip=`ifconfig -a | grep inet | grep -v "$loopback" | awk '{ print $2} '`;;
Linux)
if command_available "ifconfig"; then
ip=`ifconfig | grep 'inet addr:' | grep -v "$loopback" | cut -d: -f2 | awk '{ print $1}'`
elif command_available "ip"; then
ip=`ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | awk -F"/" '{print $1}'`
else
ip=$loopback
fi
;;
FreeBSD|OpenBSD|Darwin)
if command_available "ifconfig"; then
ip=`ifconfig | grep -E 'inet.[0-9]' | grep -v "$loopback" | awk '{ print $2}'`
else
ip=$loopback
fi
;;
SunOS)
if command_available "ifconfig"; then
ip=`ifconfig -a | grep inet | grep -v "$loopback" | awk '{ print $2} '`
else
ip=$loopback
fi
;;
*) ip=$loopback;;
esac
echo $ip
Expand All @@ -214,13 +244,14 @@ function download() {
local path=$1
local link_url=$2

if command -v wget >/dev/null 2>&1; then
if command_available "wget"; then
wget --help | grep -q '\--show-progress' && progress_opt="-q --show-progress" || progress_opt=""
wget ${link_url} -P ${path} $progress_opt
elif command -v curl >/dev/null 2>&1; then
elif command_available "curl"; then
curl ${link_url} -o ${path}/${link_url}
else
echo "Required wget or curl but they are not installed"
echo "Required wget or curl but they are unavailable"
exit 1
fi
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,14 @@ protected void parseProperties(HugeElement element,
}

@Override
protected void writeUserData(SchemaElement schema,
protected void writeUserdata(SchemaElement schema,
TableBackendEntry entry) {
assert entry instanceof MysqlBackendEntry;
entry.column(HugeKeys.USER_DATA, JsonUtil.toJson(schema.userdata()));
}

@Override
protected void readUserData(SchemaElement schema,
protected void readUserdata(SchemaElement schema,
TableBackendEntry entry) {
assert entry instanceof MysqlBackendEntry;
// Parse all user data of a schema element
Expand Down
Loading

0 comments on commit ce6e576

Please sign in to comment.