From 82b09faede20db506c1af0bb35c00e7f71c72946 Mon Sep 17 00:00:00 2001 From: dandelion Date: Tue, 11 Jul 2023 23:35:07 +0800 Subject: [PATCH 01/10] feat: pre-load some data in container(#840) --- hugegraph-dist/README.md | 35 +++++ .../assembly/static/bin/start-hugegraph.sh | 11 +- .../static/conf/gremlin-server-preload.yaml | 126 ++++++++++++++++++ .../static/scripts/example-preload.groovy | 65 +++++++++ 4 files changed, 235 insertions(+), 2 deletions(-) create mode 100644 hugegraph-dist/README.md create mode 100644 hugegraph-dist/src/assembly/static/conf/gremlin-server-preload.yaml create mode 100644 hugegraph-dist/src/assembly/static/scripts/example-preload.groovy diff --git a/hugegraph-dist/README.md b/hugegraph-dist/README.md new file mode 100644 index 0000000000..aa082373a7 --- /dev/null +++ b/hugegraph-dist/README.md @@ -0,0 +1,35 @@ +# Deploy Hugegraph server with docker compose(WIP) + +## 1. Deploy + +We can use `docker-compose up -d` to quickly start an inner HugeGraph server with RocksDB in background. + +The docker-compose.yaml is below: + +```yaml +version: '3' +services: + graph: + image: hugegraph/hugegraph + ports: + - 18080:8080 +``` + +## 2. Create Sample Graph on Server Startup + +If you want to pre-load some data or graphs in container, you can set the env `PRELOAD=ture` + +If you want to customize the pre-loaded data, please mount the the groovy scripts + +```yaml +version: '3' +services: + graph: + image: hugegraph/hugegraph + environment: + - PRELOAD=true + volumes: + - /path/to/yourscript:/hugegraph/scripts/example-preload.groovy + ports: + - 18080:8080 +``` \ No newline at end of file diff --git a/hugegraph-dist/src/assembly/static/bin/start-hugegraph.sh b/hugegraph-dist/src/assembly/static/bin/start-hugegraph.sh index 85d259d3cd..056323b9b6 100644 --- a/hugegraph-dist/src/assembly/static/bin/start-hugegraph.sh +++ b/hugegraph-dist/src/assembly/static/bin/start-hugegraph.sh @@ -79,13 +79,20 @@ if [ ! -d "$LOGS" ]; then mkdir -p "$LOGS" fi +GERMLIN_SERVER_YAML="gremlin-server.yaml" + +if [ $PRELOAD ]; then + GERMLIN_SERVER_YAML="gremlin-server-preload.yaml" +fi + + if [[ $DAEMON == "true" ]]; then echo "Starting HugeGraphServer in daemon mode..." - "${BIN}"/hugegraph-server.sh "${CONF}"/gremlin-server.yaml "${CONF}"/rest-server.properties \ + "${BIN}"/hugegraph-server.sh "${CONF}"/"${GERMLIN_SERVER_YAML}" "${CONF}"/rest-server.properties \ "${OPEN_SECURITY_CHECK}" "${USER_OPTION}" "${GC_OPTION}" >>"${LOGS}"/hugegraph-server.log 2>&1 & else echo "Starting HugeGraphServer in foreground mode..." - "${BIN}"/hugegraph-server.sh "${CONF}"/gremlin-server.yaml "${CONF}"/rest-server.properties \ + "${BIN}"/hugegraph-server.sh "${CONF}"/"${GERMLIN_SERVER_YAML}" "${CONF}"/rest-server.properties \ "${OPEN_SECURITY_CHECK}" "${USER_OPTION}" "${GC_OPTION}" >>"${LOGS}"/hugegraph-server.log 2>&1 fi diff --git a/hugegraph-dist/src/assembly/static/conf/gremlin-server-preload.yaml b/hugegraph-dist/src/assembly/static/conf/gremlin-server-preload.yaml new file mode 100644 index 0000000000..58a9d1e804 --- /dev/null +++ b/hugegraph-dist/src/assembly/static/conf/gremlin-server-preload.yaml @@ -0,0 +1,126 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# host and port of gremlin server, need to be consistent with host and port in rest-server.properties +#host: 127.0.0.1 +#port: 8182 + +# timeout in ms of gremlin query +evaluationTimeout: 30000 + +channelizer: org.apache.tinkerpop.gremlin.server.channel.WsAndHttpChannelizer +# don't set graph at here, this happens after support for dynamically adding graph +graphs: { +} +scriptEngines: { + gremlin-groovy: { + staticImports: [ + org.opencypher.gremlin.process.traversal.CustomPredicates.*', + org.opencypher.gremlin.traversal.CustomFunctions.* + ], + plugins: { + org.apache.hugegraph.plugin.HugeGraphGremlinPlugin: {}, + org.apache.tinkerpop.gremlin.server.jsr223.GremlinServerGremlinPlugin: {}, + org.apache.tinkerpop.gremlin.jsr223.ImportGremlinPlugin: { + classImports: [ + java.lang.Math, + org.apache.hugegraph.backend.id.IdGenerator, + org.apache.hugegraph.type.define.Directions, + org.apache.hugegraph.type.define.NodeRole, + org.apache.hugegraph.traversal.algorithm.CollectionPathsTraverser, + org.apache.hugegraph.traversal.algorithm.CountTraverser, + org.apache.hugegraph.traversal.algorithm.CustomizedCrosspointsTraverser, + org.apache.hugegraph.traversal.algorithm.CustomizePathsTraverser, + org.apache.hugegraph.traversal.algorithm.FusiformSimilarityTraverser, + org.apache.hugegraph.traversal.algorithm.HugeTraverser, + org.apache.hugegraph.traversal.algorithm.JaccardSimilarTraverser, + org.apache.hugegraph.traversal.algorithm.KneighborTraverser, + org.apache.hugegraph.traversal.algorithm.KoutTraverser, + org.apache.hugegraph.traversal.algorithm.MultiNodeShortestPathTraverser, + org.apache.hugegraph.traversal.algorithm.NeighborRankTraverser, + org.apache.hugegraph.traversal.algorithm.PathsTraverser, + org.apache.hugegraph.traversal.algorithm.PersonalRankTraverser, + org.apache.hugegraph.traversal.algorithm.SameNeighborTraverser, + org.apache.hugegraph.traversal.algorithm.ShortestPathTraverser, + org.apache.hugegraph.traversal.algorithm.SingleSourceShortestPathTraverser, + org.apache.hugegraph.traversal.algorithm.SubGraphTraverser, + org.apache.hugegraph.traversal.algorithm.TemplatePathsTraverser, + org.apache.hugegraph.traversal.algorithm.steps.EdgeStep, + org.apache.hugegraph.traversal.algorithm.steps.RepeatEdgeStep, + org.apache.hugegraph.traversal.algorithm.steps.WeightedEdgeStep, + org.apache.hugegraph.traversal.optimize.ConditionP, + org.apache.hugegraph.traversal.optimize.Text, + org.apache.hugegraph.traversal.optimize.TraversalUtil, + org.apache.hugegraph.util.DateUtil, + org.opencypher.gremlin.traversal.CustomFunctions, + org.opencypher.gremlin.traversal.CustomPredicate + ], + methodImports: [ + java.lang.Math#*, + org.opencypher.gremlin.traversal.CustomPredicate#*, + org.opencypher.gremlin.traversal.CustomFunctions#* + ] + }, + org.apache.tinkerpop.gremlin.jsr223.ScriptFileGremlinPlugin: { + files: [scripts/example-preload.groovy] + } + } + } +} +serializers: + - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphBinaryMessageSerializerV1, + config: { + serializeResultToString: false, + ioRegistries: [org.apache.hugegraph.io.HugeGraphIoRegistry] + } + } + - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV1d0, + config: { + serializeResultToString: false, + ioRegistries: [org.apache.hugegraph.io.HugeGraphIoRegistry] + } + } + - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV2d0, + config: { + serializeResultToString: false, + ioRegistries: [org.apache.hugegraph.io.HugeGraphIoRegistry] + } + } + - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV3d0, + config: { + serializeResultToString: false, + ioRegistries: [org.apache.hugegraph.io.HugeGraphIoRegistry] + } + } +metrics: { + consoleReporter: {enabled: false, interval: 180000}, + csvReporter: {enabled: false, interval: 180000, fileName: ./metrics/gremlin-server-metrics.csv}, + jmxReporter: {enabled: false}, + slf4jReporter: {enabled: false, interval: 180000}, + gangliaReporter: {enabled: false, interval: 180000, addressingMode: MULTICAST}, + graphiteReporter: {enabled: false, interval: 180000} +} +maxInitialLineLength: 4096 +maxHeaderSize: 8192 +maxChunkSize: 8192 +maxContentLength: 65536 +maxAccumulationBufferComponents: 1024 +resultIterationBatchSize: 64 +writeBufferLowWaterMark: 32768 +writeBufferHighWaterMark: 65536 +ssl: { + enabled: false +} diff --git a/hugegraph-dist/src/assembly/static/scripts/example-preload.groovy b/hugegraph-dist/src/assembly/static/scripts/example-preload.groovy new file mode 100644 index 0000000000..5ed072b2e2 --- /dev/null +++ b/hugegraph-dist/src/assembly/static/scripts/example-preload.groovy @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ +import org.apache.hugegraph.HugeFactory +import org.apache.hugegraph.backend.id.IdGenerator +import org.apache.hugegraph.dist.RegisterUtil +import org.apache.hugegraph.type.define.NodeRole +import org.apache.tinkerpop.gremlin.structure.T + +conf = "conf/graphs/hugegraph.properties" +graph = HugeFactory.open(conf) +schema = graph.schema() + +schema.propertyKey("name").asText().ifNotExist().create() +schema.propertyKey("age").asInt().ifNotExist().create() +schema.propertyKey("city").asText().ifNotExist().create() +schema.propertyKey("weight").asDouble().ifNotExist().create() +schema.propertyKey("lang").asText().ifNotExist().create() +schema.propertyKey("date").asText().ifNotExist().create() +schema.propertyKey("price").asInt().ifNotExist().create() + +schema.vertexLabel("person").properties("name", "age", "city").primaryKeys("name").ifNotExist().create() +schema.vertexLabel("software").properties("name", "lang", "price").primaryKeys("name").ifNotExist().create() +schema.indexLabel("personByCity").onV("person").by("city").secondary().ifNotExist().create() +schema.indexLabel("personByAgeAndCity").onV("person").by("age", "city").secondary().ifNotExist().create() +schema.indexLabel("softwareByPrice").onV("software").by("price").range().ifNotExist().create() +schema.edgeLabel("knows").sourceLabel("person").targetLabel("person").properties("date", "weight").ifNotExist().create() +schema.edgeLabel("created").sourceLabel("person").targetLabel("software").properties("date", "weight").ifNotExist().create() +schema.indexLabel("createdByDate").onE("created").by("date").secondary().ifNotExist().create() +schema.indexLabel("createdByWeight").onE("created").by("weight").range().ifNotExist().create() +schema.indexLabel("knowsByWeight").onE("knows").by("weight").range().ifNotExist().create() + +marko = graph.addVertex(T.label, "person", "name", "marko", "age", 29, "city", "Beijing") +vadas = graph.addVertex(T.label, "person", "name", "vadas", "age", 27, "city", "Hongkong") +lop = graph.addVertex(T.label, "software", "name", "lop", "lang", "java", "price", 328) +josh = graph.addVertex(T.label, "person", "name", "josh", "age", 32, "city", "Beijing") +ripple = graph.addVertex(T.label, "software", "name", "ripple", "lang", "java", "price", 199) +peter = graph.addVertex(T.label, "person", "name", "peter", "age", 35, "city", "Shanghai") + +marko.addEdge("knows", vadas, "date", "20160110", "weight", 0.5) +marko.addEdge("knows", josh, "date", "20130220", "weight", 1.0) +marko.addEdge("created", lop, "date", "20171210", "weight", 0.4) +josh.addEdge("created", lop, "date", "20091111", "weight", 0.4) +josh.addEdge("created", ripple, "date", "20171210", "weight", 1.0) +peter.addEdge("created", lop, "date", "20170324", "weight", 0.2) + +graph.tx().commit() + +g = graph.traversal() + +System.out.println(">>>> query all vertices: size=" + g.V().toList().size()) +System.out.println(">>>> query all edges: size=" + g.E().toList().size()) \ No newline at end of file From 947d5302a76b29d66f2aee3c9c68c4485deb40c2 Mon Sep 17 00:00:00 2001 From: dandelion Date: Wed, 26 Jul 2023 15:02:05 +0800 Subject: [PATCH 02/10] feat: pre-load some data in container(#840) --- .../assembly/static/bin/start-hugegraph.sh | 12 +- .../static/conf/gremlin-server-preload.yaml | 126 ------------------ .../static/scripts/example-preload.groovy | 65 --------- 3 files changed, 6 insertions(+), 197 deletions(-) delete mode 100644 hugegraph-dist/src/assembly/static/conf/gremlin-server-preload.yaml delete mode 100644 hugegraph-dist/src/assembly/static/scripts/example-preload.groovy diff --git a/hugegraph-dist/src/assembly/static/bin/start-hugegraph.sh b/hugegraph-dist/src/assembly/static/bin/start-hugegraph.sh index 056323b9b6..bad24dcf46 100644 --- a/hugegraph-dist/src/assembly/static/bin/start-hugegraph.sh +++ b/hugegraph-dist/src/assembly/static/bin/start-hugegraph.sh @@ -62,6 +62,7 @@ BIN=$(abs_path) TOP="$(cd "$BIN"/../ && pwd)" CONF="$TOP/conf" LOGS="$TOP/logs" +SCRIPTS="$TOP/scripts" PID_FILE="$BIN/pid" . "$BIN"/util.sh @@ -79,20 +80,19 @@ if [ ! -d "$LOGS" ]; then mkdir -p "$LOGS" fi -GERMLIN_SERVER_YAML="gremlin-server.yaml" - -if [ $PRELOAD ]; then - GERMLIN_SERVER_YAML="gremlin-server-preload.yaml" +if [[ $PRELOAD == "true" ]]; then + sed -i -e 's/empty-sample.groovy/example.groovy/g' "${CONF}"/gremlin-server.yaml + sed -i -e '/registerRocksDB/d; /serverStarted/d' "${SCRIPTS}"/example.groovy fi if [[ $DAEMON == "true" ]]; then echo "Starting HugeGraphServer in daemon mode..." - "${BIN}"/hugegraph-server.sh "${CONF}"/"${GERMLIN_SERVER_YAML}" "${CONF}"/rest-server.properties \ + "${BIN}"/hugegraph-server.sh "${CONF}"/gremlin-server.yaml "${CONF}"/rest-server.properties \ "${OPEN_SECURITY_CHECK}" "${USER_OPTION}" "${GC_OPTION}" >>"${LOGS}"/hugegraph-server.log 2>&1 & else echo "Starting HugeGraphServer in foreground mode..." - "${BIN}"/hugegraph-server.sh "${CONF}"/"${GERMLIN_SERVER_YAML}" "${CONF}"/rest-server.properties \ + "${BIN}"/hugegraph-server.sh "${CONF}"/gremlin-server.yaml "${CONF}"/rest-server.properties \ "${OPEN_SECURITY_CHECK}" "${USER_OPTION}" "${GC_OPTION}" >>"${LOGS}"/hugegraph-server.log 2>&1 fi diff --git a/hugegraph-dist/src/assembly/static/conf/gremlin-server-preload.yaml b/hugegraph-dist/src/assembly/static/conf/gremlin-server-preload.yaml deleted file mode 100644 index 58a9d1e804..0000000000 --- a/hugegraph-dist/src/assembly/static/conf/gremlin-server-preload.yaml +++ /dev/null @@ -1,126 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# host and port of gremlin server, need to be consistent with host and port in rest-server.properties -#host: 127.0.0.1 -#port: 8182 - -# timeout in ms of gremlin query -evaluationTimeout: 30000 - -channelizer: org.apache.tinkerpop.gremlin.server.channel.WsAndHttpChannelizer -# don't set graph at here, this happens after support for dynamically adding graph -graphs: { -} -scriptEngines: { - gremlin-groovy: { - staticImports: [ - org.opencypher.gremlin.process.traversal.CustomPredicates.*', - org.opencypher.gremlin.traversal.CustomFunctions.* - ], - plugins: { - org.apache.hugegraph.plugin.HugeGraphGremlinPlugin: {}, - org.apache.tinkerpop.gremlin.server.jsr223.GremlinServerGremlinPlugin: {}, - org.apache.tinkerpop.gremlin.jsr223.ImportGremlinPlugin: { - classImports: [ - java.lang.Math, - org.apache.hugegraph.backend.id.IdGenerator, - org.apache.hugegraph.type.define.Directions, - org.apache.hugegraph.type.define.NodeRole, - org.apache.hugegraph.traversal.algorithm.CollectionPathsTraverser, - org.apache.hugegraph.traversal.algorithm.CountTraverser, - org.apache.hugegraph.traversal.algorithm.CustomizedCrosspointsTraverser, - org.apache.hugegraph.traversal.algorithm.CustomizePathsTraverser, - org.apache.hugegraph.traversal.algorithm.FusiformSimilarityTraverser, - org.apache.hugegraph.traversal.algorithm.HugeTraverser, - org.apache.hugegraph.traversal.algorithm.JaccardSimilarTraverser, - org.apache.hugegraph.traversal.algorithm.KneighborTraverser, - org.apache.hugegraph.traversal.algorithm.KoutTraverser, - org.apache.hugegraph.traversal.algorithm.MultiNodeShortestPathTraverser, - org.apache.hugegraph.traversal.algorithm.NeighborRankTraverser, - org.apache.hugegraph.traversal.algorithm.PathsTraverser, - org.apache.hugegraph.traversal.algorithm.PersonalRankTraverser, - org.apache.hugegraph.traversal.algorithm.SameNeighborTraverser, - org.apache.hugegraph.traversal.algorithm.ShortestPathTraverser, - org.apache.hugegraph.traversal.algorithm.SingleSourceShortestPathTraverser, - org.apache.hugegraph.traversal.algorithm.SubGraphTraverser, - org.apache.hugegraph.traversal.algorithm.TemplatePathsTraverser, - org.apache.hugegraph.traversal.algorithm.steps.EdgeStep, - org.apache.hugegraph.traversal.algorithm.steps.RepeatEdgeStep, - org.apache.hugegraph.traversal.algorithm.steps.WeightedEdgeStep, - org.apache.hugegraph.traversal.optimize.ConditionP, - org.apache.hugegraph.traversal.optimize.Text, - org.apache.hugegraph.traversal.optimize.TraversalUtil, - org.apache.hugegraph.util.DateUtil, - org.opencypher.gremlin.traversal.CustomFunctions, - org.opencypher.gremlin.traversal.CustomPredicate - ], - methodImports: [ - java.lang.Math#*, - org.opencypher.gremlin.traversal.CustomPredicate#*, - org.opencypher.gremlin.traversal.CustomFunctions#* - ] - }, - org.apache.tinkerpop.gremlin.jsr223.ScriptFileGremlinPlugin: { - files: [scripts/example-preload.groovy] - } - } - } -} -serializers: - - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphBinaryMessageSerializerV1, - config: { - serializeResultToString: false, - ioRegistries: [org.apache.hugegraph.io.HugeGraphIoRegistry] - } - } - - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV1d0, - config: { - serializeResultToString: false, - ioRegistries: [org.apache.hugegraph.io.HugeGraphIoRegistry] - } - } - - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV2d0, - config: { - serializeResultToString: false, - ioRegistries: [org.apache.hugegraph.io.HugeGraphIoRegistry] - } - } - - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV3d0, - config: { - serializeResultToString: false, - ioRegistries: [org.apache.hugegraph.io.HugeGraphIoRegistry] - } - } -metrics: { - consoleReporter: {enabled: false, interval: 180000}, - csvReporter: {enabled: false, interval: 180000, fileName: ./metrics/gremlin-server-metrics.csv}, - jmxReporter: {enabled: false}, - slf4jReporter: {enabled: false, interval: 180000}, - gangliaReporter: {enabled: false, interval: 180000, addressingMode: MULTICAST}, - graphiteReporter: {enabled: false, interval: 180000} -} -maxInitialLineLength: 4096 -maxHeaderSize: 8192 -maxChunkSize: 8192 -maxContentLength: 65536 -maxAccumulationBufferComponents: 1024 -resultIterationBatchSize: 64 -writeBufferLowWaterMark: 32768 -writeBufferHighWaterMark: 65536 -ssl: { - enabled: false -} diff --git a/hugegraph-dist/src/assembly/static/scripts/example-preload.groovy b/hugegraph-dist/src/assembly/static/scripts/example-preload.groovy deleted file mode 100644 index 5ed072b2e2..0000000000 --- a/hugegraph-dist/src/assembly/static/scripts/example-preload.groovy +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with this - * work for additional information regarding copyright ownership. The ASF - * licenses this file to You under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -import org.apache.hugegraph.HugeFactory -import org.apache.hugegraph.backend.id.IdGenerator -import org.apache.hugegraph.dist.RegisterUtil -import org.apache.hugegraph.type.define.NodeRole -import org.apache.tinkerpop.gremlin.structure.T - -conf = "conf/graphs/hugegraph.properties" -graph = HugeFactory.open(conf) -schema = graph.schema() - -schema.propertyKey("name").asText().ifNotExist().create() -schema.propertyKey("age").asInt().ifNotExist().create() -schema.propertyKey("city").asText().ifNotExist().create() -schema.propertyKey("weight").asDouble().ifNotExist().create() -schema.propertyKey("lang").asText().ifNotExist().create() -schema.propertyKey("date").asText().ifNotExist().create() -schema.propertyKey("price").asInt().ifNotExist().create() - -schema.vertexLabel("person").properties("name", "age", "city").primaryKeys("name").ifNotExist().create() -schema.vertexLabel("software").properties("name", "lang", "price").primaryKeys("name").ifNotExist().create() -schema.indexLabel("personByCity").onV("person").by("city").secondary().ifNotExist().create() -schema.indexLabel("personByAgeAndCity").onV("person").by("age", "city").secondary().ifNotExist().create() -schema.indexLabel("softwareByPrice").onV("software").by("price").range().ifNotExist().create() -schema.edgeLabel("knows").sourceLabel("person").targetLabel("person").properties("date", "weight").ifNotExist().create() -schema.edgeLabel("created").sourceLabel("person").targetLabel("software").properties("date", "weight").ifNotExist().create() -schema.indexLabel("createdByDate").onE("created").by("date").secondary().ifNotExist().create() -schema.indexLabel("createdByWeight").onE("created").by("weight").range().ifNotExist().create() -schema.indexLabel("knowsByWeight").onE("knows").by("weight").range().ifNotExist().create() - -marko = graph.addVertex(T.label, "person", "name", "marko", "age", 29, "city", "Beijing") -vadas = graph.addVertex(T.label, "person", "name", "vadas", "age", 27, "city", "Hongkong") -lop = graph.addVertex(T.label, "software", "name", "lop", "lang", "java", "price", 328) -josh = graph.addVertex(T.label, "person", "name", "josh", "age", 32, "city", "Beijing") -ripple = graph.addVertex(T.label, "software", "name", "ripple", "lang", "java", "price", 199) -peter = graph.addVertex(T.label, "person", "name", "peter", "age", 35, "city", "Shanghai") - -marko.addEdge("knows", vadas, "date", "20160110", "weight", 0.5) -marko.addEdge("knows", josh, "date", "20130220", "weight", 1.0) -marko.addEdge("created", lop, "date", "20171210", "weight", 0.4) -josh.addEdge("created", lop, "date", "20091111", "weight", 0.4) -josh.addEdge("created", ripple, "date", "20171210", "weight", 1.0) -peter.addEdge("created", lop, "date", "20170324", "weight", 0.2) - -graph.tx().commit() - -g = graph.traversal() - -System.out.println(">>>> query all vertices: size=" + g.V().toList().size()) -System.out.println(">>>> query all edges: size=" + g.E().toList().size()) \ No newline at end of file From a33ea5c72ba40c37a67b1fbe38df120792bdca8a Mon Sep 17 00:00:00 2001 From: dandelion Date: Wed, 2 Aug 2023 14:31:27 +0800 Subject: [PATCH 03/10] feat: pre-load some data in container(apache#840) --- .../src/assembly/static/bin/start-hugegraph.sh | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/hugegraph-dist/src/assembly/static/bin/start-hugegraph.sh b/hugegraph-dist/src/assembly/static/bin/start-hugegraph.sh index bad24dcf46..1c0110a8b3 100644 --- a/hugegraph-dist/src/assembly/static/bin/start-hugegraph.sh +++ b/hugegraph-dist/src/assembly/static/bin/start-hugegraph.sh @@ -80,19 +80,23 @@ if [ ! -d "$LOGS" ]; then mkdir -p "$LOGS" fi +GREMLIN_SERVER_CONF="gremlin-server.yaml" if [[ $PRELOAD == "true" ]]; then - sed -i -e 's/empty-sample.groovy/example.groovy/g' "${CONF}"/gremlin-server.yaml - sed -i -e '/registerRocksDB/d; /serverStarted/d' "${SCRIPTS}"/example.groovy + GREMLIN_SERVER_CONF="gremlin-server-preload.yaml" + EXAMPLE_SCRPIT="example-preload.groovy" + cp "${CONF}"/gremlin-server.yaml "${CONF}/${GREMLIN_SERVER_CONF}" + cp "${SCRIPTS}"/example.groovy "${SCRIPTS}/${EXAMPLE_SCRPIT}" + sed -i -e "s/empty-sample.groovy/$EXAMPLE_SCRPIT/g" "${CONF}/${GREMLIN_SERVER_CONF}" + sed -i -e '/registerRocksDB/d; /serverStarted/d' "${SCRIPTS}/${EXAMPLE_SCRPIT}" fi - if [[ $DAEMON == "true" ]]; then echo "Starting HugeGraphServer in daemon mode..." - "${BIN}"/hugegraph-server.sh "${CONF}"/gremlin-server.yaml "${CONF}"/rest-server.properties \ + "${BIN}"/hugegraph-server.sh "${CONF}/${GREMLIN_SERVER_CONF}" "${CONF}"/rest-server.properties \ "${OPEN_SECURITY_CHECK}" "${USER_OPTION}" "${GC_OPTION}" >>"${LOGS}"/hugegraph-server.log 2>&1 & else echo "Starting HugeGraphServer in foreground mode..." - "${BIN}"/hugegraph-server.sh "${CONF}"/gremlin-server.yaml "${CONF}"/rest-server.properties \ + "${BIN}"/hugegraph-server.sh "${CONF}/${GREMLIN_SERVER_CONF}" "${CONF}"/rest-server.properties \ "${OPEN_SECURITY_CHECK}" "${USER_OPTION}" "${GC_OPTION}" >>"${LOGS}"/hugegraph-server.log 2>&1 fi From f69b6e456092918ad00235e03db38bad8eb555aa Mon Sep 17 00:00:00 2001 From: dandelion Date: Fri, 4 Aug 2023 10:49:21 +0800 Subject: [PATCH 04/10] feat: pre-load some data in container(apache#840) --- hugegraph-dist/README.md | 64 ++++++++++++++++++++++++---------------- 1 file changed, 39 insertions(+), 25 deletions(-) diff --git a/hugegraph-dist/README.md b/hugegraph-dist/README.md index aa082373a7..068bd67590 100644 --- a/hugegraph-dist/README.md +++ b/hugegraph-dist/README.md @@ -1,35 +1,49 @@ -# Deploy Hugegraph server with docker compose(WIP) +# Deploy Hugegraph server with docker ## 1. Deploy -We can use `docker-compose up -d` to quickly start an inner HugeGraph server with RocksDB in background. +We can use docker to quickly start an inner HugeGraph server with RocksDB in background. -The docker-compose.yaml is below: +1. Using docker run -```yaml -version: '3' -services: - graph: - image: hugegraph/hugegraph - ports: - - 18080:8080 -``` + Use `docker run -itd --name=graph -p 18080:8080 hugegraph/hugegraph` to start hugegraph server. + +2. Using docker compose + + We can also use `docker-compose up -d`. The docker-compose.yaml is below: + + ```yaml + version: '3' + services: + graph: + image: hugegraph/hugegraph + ports: + - 18080:8080 + ``` ## 2. Create Sample Graph on Server Startup If you want to pre-load some data or graphs in container, you can set the env `PRELOAD=ture` -If you want to customize the pre-loaded data, please mount the the groovy scripts - -```yaml -version: '3' -services: - graph: - image: hugegraph/hugegraph - environment: - - PRELOAD=true - volumes: - - /path/to/yourscript:/hugegraph/scripts/example-preload.groovy - ports: - - 18080:8080 -``` \ No newline at end of file +If you want to customize the pre-loaded data, please mount the the groovy scripts (not necessary). + +1. Using docker run + + Use `docker run -itd --name=graph -p 18080:8080 -e PRELOAD=true -v /yourscript:/hugegraph/scripts/example.groovy hugegraph/hugegraph` to start hugegraph server. + +2. Using docker compose + + We can also use `docker-compose up -d` to quickly start. The docker-compose.yaml is below: + + ```yaml + version: '3' + services: + graph: + image: hugegraph/hugegraph + environment: + - PRELOAD=true + volumes: + - /path/to/yourscript:/hugegraph/scripts/example.groovy + ports: + - 18080:8080 + ``` \ No newline at end of file From c1ca266b50148133d7ce2385493d3aa3e1a50de8 Mon Sep 17 00:00:00 2001 From: imbajin Date: Fri, 4 Aug 2023 16:06:47 +0800 Subject: [PATCH 05/10] Update README.md --- hugegraph-dist/README.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/hugegraph-dist/README.md b/hugegraph-dist/README.md index 068bd67590..9587c1a1d7 100644 --- a/hugegraph-dist/README.md +++ b/hugegraph-dist/README.md @@ -10,7 +10,7 @@ We can use docker to quickly start an inner HugeGraph server with RocksDB in bac 2. Using docker compose - We can also use `docker-compose up -d`. The docker-compose.yaml is below: + We can also use `docker-compose up -d`. The `docker-compose.yaml` is below: ```yaml version: '3' @@ -23,17 +23,18 @@ We can use docker to quickly start an inner HugeGraph server with RocksDB in bac ## 2. Create Sample Graph on Server Startup -If you want to pre-load some data or graphs in container, you can set the env `PRELOAD=ture` +If you want to **pre-load** some (test) data or graphs in container(by default), you can set the env `PRELOAD=ture` If you want to customize the pre-loaded data, please mount the the groovy scripts (not necessary). 1. Using docker run - Use `docker run -itd --name=graph -p 18080:8080 -e PRELOAD=true -v /yourscript:/hugegraph/scripts/example.groovy hugegraph/hugegraph` to start hugegraph server. + Use `docker run -itd --name=graph -p 18080:8080 -e PRELOAD=true -v /path/to/yourScript:/hugegraph/scripts/example.groovy hugegraph/hugegraph` + to start hugegraph server. -2. Using docker compose +3. Using docker compose - We can also use `docker-compose up -d` to quickly start. The docker-compose.yaml is below: + We can also use `docker-compose up -d` to quickly start. The `docker-compose.yaml` is below: ```yaml version: '3' @@ -46,4 +47,4 @@ If you want to customize the pre-loaded data, please mount the the groovy script - /path/to/yourscript:/hugegraph/scripts/example.groovy ports: - 18080:8080 - ``` \ No newline at end of file + ``` From 4fe1fa06e2f96eba7c53e90598474f4dce96e269 Mon Sep 17 00:00:00 2001 From: dandelion Date: Thu, 10 Aug 2023 15:16:20 +0800 Subject: [PATCH 06/10] feat: pre-load some data in container(apache#840) --- hugegraph-dist/README.md | 8 +++++++- hugegraph-dist/src/assembly/static/bin/start-hugegraph.sh | 3 ++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/hugegraph-dist/README.md b/hugegraph-dist/README.md index 068bd67590..94493aa928 100644 --- a/hugegraph-dist/README.md +++ b/hugegraph-dist/README.md @@ -27,6 +27,8 @@ If you want to pre-load some data or graphs in container, you can set the env `P If you want to customize the pre-loaded data, please mount the the groovy scripts (not necessary). + + 1. Using docker run Use `docker run -itd --name=graph -p 18080:8080 -e PRELOAD=true -v /yourscript:/hugegraph/scripts/example.groovy hugegraph/hugegraph` to start hugegraph server. @@ -46,4 +48,8 @@ If you want to customize the pre-loaded data, please mount the the groovy script - /path/to/yourscript:/hugegraph/scripts/example.groovy ports: - 18080:8080 - ``` \ No newline at end of file + ``` + +3. Using start-hugegraph.sh + + If you deploy HugeGraph server without docker, you can also pass arguments using `-p`, like this: `bin/start-hugegraph.sh -p true`. \ No newline at end of file diff --git a/hugegraph-dist/src/assembly/static/bin/start-hugegraph.sh b/hugegraph-dist/src/assembly/static/bin/start-hugegraph.sh index 1c0110a8b3..d02066141a 100644 --- a/hugegraph-dist/src/assembly/static/bin/start-hugegraph.sh +++ b/hugegraph-dist/src/assembly/static/bin/start-hugegraph.sh @@ -23,11 +23,12 @@ GC_OPTION="" USER_OPTION="" SERVER_STARTUP_TIMEOUT_S=30 -while getopts "d:g:m:s:j:t:v" arg; do +while getopts "d:g:m:p:s:j:t:v" arg; do case ${arg} in d) DAEMON="$OPTARG" ;; g) GC_OPTION="$OPTARG" ;; m) OPEN_MONITOR="$OPTARG" ;; + p) PRELOAD="$OPTARG" ;; s) OPEN_SECURITY_CHECK="$OPTARG" ;; j) USER_OPTION="$OPTARG" ;; t) SERVER_STARTUP_TIMEOUT_S="$OPTARG" ;; From 6e60ebb291b9e5a6b744e9e8d4d945103ed91e38 Mon Sep 17 00:00:00 2001 From: imbajin Date: Fri, 4 Aug 2023 16:06:47 +0800 Subject: [PATCH 07/10] Update README.md --- hugegraph-dist/README.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/hugegraph-dist/README.md b/hugegraph-dist/README.md index 94493aa928..4d16d654fd 100644 --- a/hugegraph-dist/README.md +++ b/hugegraph-dist/README.md @@ -10,7 +10,7 @@ We can use docker to quickly start an inner HugeGraph server with RocksDB in bac 2. Using docker compose - We can also use `docker-compose up -d`. The docker-compose.yaml is below: + We can also use `docker-compose up -d`. The `docker-compose.yaml` is below: ```yaml version: '3' @@ -23,7 +23,7 @@ We can use docker to quickly start an inner HugeGraph server with RocksDB in bac ## 2. Create Sample Graph on Server Startup -If you want to pre-load some data or graphs in container, you can set the env `PRELOAD=ture` +If you want to **pre-load** some (test) data or graphs in container(by default), you can set the env `PRELOAD=ture` If you want to customize the pre-loaded data, please mount the the groovy scripts (not necessary). @@ -31,11 +31,12 @@ If you want to customize the pre-loaded data, please mount the the groovy script 1. Using docker run - Use `docker run -itd --name=graph -p 18080:8080 -e PRELOAD=true -v /yourscript:/hugegraph/scripts/example.groovy hugegraph/hugegraph` to start hugegraph server. + Use `docker run -itd --name=graph -p 18080:8080 -e PRELOAD=true -v /path/to/yourScript:/hugegraph/scripts/example.groovy hugegraph/hugegraph` + to start hugegraph server. -2. Using docker compose +3. Using docker compose - We can also use `docker-compose up -d` to quickly start. The docker-compose.yaml is below: + We can also use `docker-compose up -d` to quickly start. The `docker-compose.yaml` is below: ```yaml version: '3' From d74cce7c58b5fbae67244ae57aff3bf99a0659f8 Mon Sep 17 00:00:00 2001 From: dandelion Date: Wed, 23 Aug 2023 15:38:53 +0800 Subject: [PATCH 08/10] feat: pre-load some data in container(apache#840) --- hugegraph-dist/src/assembly/static/bin/start-hugegraph.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hugegraph-dist/src/assembly/static/bin/start-hugegraph.sh b/hugegraph-dist/src/assembly/static/bin/start-hugegraph.sh index d02066141a..361590777f 100644 --- a/hugegraph-dist/src/assembly/static/bin/start-hugegraph.sh +++ b/hugegraph-dist/src/assembly/static/bin/start-hugegraph.sh @@ -34,18 +34,18 @@ while getopts "d:g:m:p:s:j:t:v" arg; do t) SERVER_STARTUP_TIMEOUT_S="$OPTARG" ;; # TODO: should remove it in future (check the usage carefully) v) VERBOSE="verbose" ;; - ?) echo "USAGE: $0 [-d true|false] [-g g1] [-m true|false] [-s true|false] [-j java_options] + ?) echo "USAGE: $0 [-d true|false] [-g g1] [-m true|false] [-p true|false] [-s true|false] [-j java_options] [-t timeout]" && exit 1 ;; esac done if [[ "$OPEN_MONITOR" != "true" && "$OPEN_MONITOR" != "false" ]]; then - echo "USAGE: $0 [-d true|false] [-g g1] [-m true|false] [-s true|false] [-j java_options]" + echo "USAGE: $0 [-d true|false] [-g g1] [-m true|false] [-p true|false] [-s true|false] [-j java_options]" exit 1 fi if [[ "$OPEN_SECURITY_CHECK" != "true" && "$OPEN_SECURITY_CHECK" != "false" ]]; then - echo "USAGE: $0 [-d true|false] [-g g1] [-m true|false] [-s true|false] [-j java_options]" + echo "USAGE: $0 [-d true|false] [-g g1] [-m true|false] [-p true|false] [-s true|false] [-j java_options]" exit 1 fi From e355660fec46456a0c1d80ba9c1ab9eb8cc74741 Mon Sep 17 00:00:00 2001 From: dandelion Date: Wed, 23 Aug 2023 15:45:22 +0800 Subject: [PATCH 09/10] feat: pre-load some data in container(#840) --- hugegraph-dist/src/assembly/static/bin/start-hugegraph.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hugegraph-dist/src/assembly/static/bin/start-hugegraph.sh b/hugegraph-dist/src/assembly/static/bin/start-hugegraph.sh index 361590777f..5a251ea8c2 100644 --- a/hugegraph-dist/src/assembly/static/bin/start-hugegraph.sh +++ b/hugegraph-dist/src/assembly/static/bin/start-hugegraph.sh @@ -49,6 +49,11 @@ if [[ "$OPEN_SECURITY_CHECK" != "true" && "$OPEN_SECURITY_CHECK" != "false" ]]; exit 1 fi +if [[ "$PRELOAD" != "true" && "$PRELOAD" != "false" ]]; then + echo "USAGE: $0 [-d true|false] [-g g1] [-m true|false] [-p true|false] [-s true|false] [-j java_options]" + exit 1 +fi + function abs_path() { SOURCE="${BASH_SOURCE[0]}" while [[ -h "$SOURCE" ]]; do From e948ea28b9c85f70971b5416a3c4252982685602 Mon Sep 17 00:00:00 2001 From: dandelion Date: Wed, 23 Aug 2023 16:18:35 +0800 Subject: [PATCH 10/10] feat: pre-load some data in container(#840) --- hugegraph-dist/src/assembly/static/bin/start-hugegraph.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/hugegraph-dist/src/assembly/static/bin/start-hugegraph.sh b/hugegraph-dist/src/assembly/static/bin/start-hugegraph.sh index 5a251ea8c2..c53df91b9b 100644 --- a/hugegraph-dist/src/assembly/static/bin/start-hugegraph.sh +++ b/hugegraph-dist/src/assembly/static/bin/start-hugegraph.sh @@ -18,6 +18,7 @@ OPEN_MONITOR="false" OPEN_SECURITY_CHECK="true" DAEMON="true" +PRELOAD="false" #VERBOSE="" GC_OPTION="" USER_OPTION=""