Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
tmljob committed Dec 10, 2020
2 parents 6701022 + f6f44bb commit 45cf281
Show file tree
Hide file tree
Showing 103 changed files with 6,988 additions and 2,377 deletions.
51 changes: 51 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
FROM ubuntu:xenial

LABEL maintainer="HugeGraph Docker Maintainers <[email protected]>"

ENV PKG_URL https://github.com/hugegraph

# 1. Install needed dependencies of GraphServer & RocksDB
RUN set -x \
&& apt-get -q update \
&& apt-get -q install -y --no-install-recommends --no-install-suggests \
curl \
lsof \
g++ \
gcc \
openjdk-8-jdk \
&& apt-get clean
# && rm -rf /var/lib/apt/lists/*

# 2. Init HugeGraph Sever
# (Optional) You can set the ip of github to speed up the local build
# && echo "192.30.253.112 github.com\n151.101.44.249 github.global.ssl.fastly.net" >> /etc/hosts \
ENV SERVER_VERSION 0.10.4
RUN set -e \
&& mkdir -p /root/hugegraph-server \
&& curl -L -S ${PKG_URL}/hugegraph/releases/download/v${SERVER_VERSION}/hugegraph-${SERVER_VERSION}.tar.gz -o /root/server.tar.gz \
&& tar xzf /root/server.tar.gz --strip-components 1 -C /root/hugegraph-server \
&& rm /root/server.tar.gz \
&& cd /root/hugegraph-server/ \
&& sed -i "s/^restserver.url.*$/restserver.url=http:\/\/0.0.0.0:8080/g" ./conf/rest-server.properties \
&& sed -n '63p' ./bin/start-hugegraph.sh | grep "&" > /dev/null && sed -i 63{s/\&$/#/g} ./bin/start-hugegraph.sh \
&& sed -n '74p' ./bin/start-hugegraph.sh | grep "exit" > /dev/null && sed -i 74{s/^/#/g} ./bin/start-hugegraph.sh \
&& ./bin/init-store.sh

# 3. Prepare for HugeGraph Studio
ENV STUDIO_VERSION 0.10.0
# (Optional) You can set the ip of github to speed up the local build
# && echo "192.30.253.112 github.com\n151.101.44.249 github.global.ssl.fastly.net" >> /etc/hosts \
RUN set -e \
&& mkdir -p /root/hugegraph-studio \
&& curl -L -S ${PKG_URL}/hugegraph-studio/releases/download/v${STUDIO_VERSION}/hugegraph-studio-${STUDIO_VERSION}.tar.gz -o /root/studio.tar.gz \
&& tar xzf /root/studio.tar.gz --strip-components 1 -C /root/hugegraph-studio \
&& rm /root/studio.tar.gz \
&& cd /root/hugegraph-studio/ \
&& sed -i "s/^studio.server.host.*$/studio.server.host=0.0.0.0/g" ./conf/hugegraph-studio.properties \
&& sed -i "s/^graph.server.host.*$/graph.server.host=0.0.0.0/g" ./conf/hugegraph-studio.properties

EXPOSE 8080 8088
WORKDIR /root
VOLUME /root

ENTRYPOINT ["./hugegraph-server/bin/start-hugegraph.sh"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ HugeGraph is licensed under Apache 2.0 License.
## Thanks

HugeGraph relies on the [TinkerPop](http://tinkerpop.apache.org) framework, we refer to the storage structure of Titan and the schema definition of DataStax.
Thanks to Tinkerpop, thanks to Titan, thanks to DataStax. Thanks to all other organizations or authors who contributed to the project.
Thanks to TinkerPop, thanks to Titan, thanks to DataStax. Thanks to all other organizations or authors who contributed to the project.

You are welcome to contribute to HugeGraph, and we are looking forward to working with you to build an excellent open source community.
195 changes: 195 additions & 0 deletions hugegraph-api/src/main/java/com/baidu/hugegraph/api/raft/RaftAPI.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
/*
* Copyright 2017 HugeGraph Authors
*
* 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.
*/

package com.baidu.hugegraph.api.raft;

import java.util.List;
import java.util.Map;

import javax.annotation.security.RolesAllowed;
import javax.inject.Singleton;
import javax.ws.rs.Consumes;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;

import org.slf4j.Logger;

import com.baidu.hugegraph.HugeException;
import com.baidu.hugegraph.HugeGraph;
import com.baidu.hugegraph.api.API;
import com.baidu.hugegraph.api.filter.StatusFilter.Status;
import com.baidu.hugegraph.backend.store.raft.RaftGroupManager;
import com.baidu.hugegraph.core.GraphManager;
import com.baidu.hugegraph.util.Log;
import com.codahale.metrics.annotation.Timed;
import com.google.common.collect.ImmutableMap;

@Path("graphs/{graph}/raft")
@Singleton
public class RaftAPI extends API {

private static final Logger LOG = Log.logger(RaftAPI.class);

@GET
@Timed
@Path("list-peers")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON_WITH_CHARSET)
@RolesAllowed({"admin"})
public Map<String, List<String>> listPeers(@Context GraphManager manager,
@PathParam("graph") String graph,
@QueryParam("group")
@DefaultValue("default")
String group) {
LOG.debug("Graph [{}] prepare to get leader", graph);

HugeGraph g = graph(manager, graph);
RaftGroupManager raftManager = raftGroupManager(g, group, "list-peers");
List<String> peers = raftManager.listPeers();
return ImmutableMap.of(raftManager.group(), peers);
}

@GET
@Timed
@Path("get-leader")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON_WITH_CHARSET)
@RolesAllowed({"admin"})
public Map<String, String> getLeader(@Context GraphManager manager,
@PathParam("graph") String graph,
@QueryParam("group")
@DefaultValue("default")
String group) {
LOG.debug("Graph [{}] prepare to get leader", graph);

HugeGraph g = graph(manager, graph);
RaftGroupManager raftManager = raftGroupManager(g, group, "get-leader");
String leaderId = raftManager.getLeader();
return ImmutableMap.of(raftManager.group(), leaderId);
}

@POST
@Timed
@Status(Status.OK)
@Path("transfer-leader")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON_WITH_CHARSET)
@RolesAllowed({"admin"})
public Map<String, String> transferLeader(@Context GraphManager manager,
@PathParam("graph") String graph,
@QueryParam("group")
@DefaultValue("default")
String group,
@QueryParam("endpoint")
String endpoint) {
LOG.debug("Graph [{}] prepare to transfer leader to: {}",
graph, endpoint);

HugeGraph g = graph(manager, graph);
RaftGroupManager raftManager = raftGroupManager(g, group,
"transfer-leader");
String leaderId = raftManager.transferLeaderTo(endpoint);
return ImmutableMap.of(raftManager.group(), leaderId);
}

@POST
@Timed
@Status(Status.OK)
@Path("set-leader")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON_WITH_CHARSET)
@RolesAllowed({"admin"})
public Map<String, String> setLeader(@Context GraphManager manager,
@PathParam("graph") String graph,
@QueryParam("group")
@DefaultValue("default")
String group,
@QueryParam("endpoint")
String endpoint) {
LOG.debug("Graph [{}] prepare to set leader to: {}",
graph, endpoint);

HugeGraph g = graph(manager, graph);
RaftGroupManager raftManager = raftGroupManager(g, group, "set-leader");
String leaderId = raftManager.setLeader(endpoint);
return ImmutableMap.of(raftManager.group(), leaderId);
}

@POST
@Timed
@Status(Status.OK)
@Path("add-peer")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON_WITH_CHARSET)
@RolesAllowed({"admin"})
public Map<String, String> addPeer(@Context GraphManager manager,
@PathParam("graph") String graph,
@QueryParam("group")
@DefaultValue("default")
String group,
@QueryParam("endpoint")
String endpoint) {
LOG.debug("Graph [{}] prepare to add peer: {}", graph, endpoint);

HugeGraph g = graph(manager, graph);
RaftGroupManager raftManager = raftGroupManager(g, group, "add-peer");
String peerId = raftManager.addPeer(endpoint);
return ImmutableMap.of(raftManager.group(), peerId);
}

@POST
@Timed
@Status(Status.OK)
@Path("remove-peer")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON_WITH_CHARSET)
@RolesAllowed({"admin"})
public Map<String, String> removePeer(@Context GraphManager manager,
@PathParam("graph") String graph,
@QueryParam("group")
@DefaultValue("default")
String group,
@QueryParam("endpoint")
String endpoint) {
LOG.debug("Graph [{}] prepare to remove peer: {}", graph, endpoint);

HugeGraph g = graph(manager, graph);
RaftGroupManager raftManager = raftGroupManager(g, group,
"remove-peer");
String peerId = raftManager.removePeer(endpoint);
return ImmutableMap.of(raftManager.group(), peerId);
}

private static RaftGroupManager raftGroupManager(HugeGraph graph,
String group,
String operation) {
RaftGroupManager raftManager = graph.raftGroupManager(group);
if (raftManager == null) {
throw new HugeException("Allowed %s operation only when " +
"working on raft mode", operation);
}
return raftManager;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import com.baidu.hugegraph.server.RestServer;
import com.baidu.hugegraph.structure.HugeVertex;
import com.baidu.hugegraph.traversal.algorithm.CountTraverser;
import com.baidu.hugegraph.traversal.algorithm.steps.EdgeStep;
import com.baidu.hugegraph.type.define.Directions;
import com.baidu.hugegraph.util.E;
import com.baidu.hugegraph.util.Log;
Expand Down Expand Up @@ -77,18 +78,17 @@ public String post(@Context GraphManager manager,
request.dedupSize);

HugeGraph g = graph(manager, graph);
List<CountTraverser.Step> steps = step(g, request);
List<EdgeStep> steps = steps(g, request);
CountTraverser traverser = new CountTraverser(g);
long count = traverser.count(sourceId, steps, request.containsTraversed,
request.dedupSize);

return manager.serializer(g).writeMap(ImmutableMap.of("count", count));
}

private static List<CountTraverser.Step> step(HugeGraph graph,
CountRequest request) {
private static List<EdgeStep> steps(HugeGraph graph, CountRequest request) {
int stepSize = request.steps.size();
List<CountTraverser.Step> steps = new ArrayList<>(stepSize);
List<EdgeStep> steps = new ArrayList<>(stepSize);
for (Step step : request.steps) {
steps.add(step.jsonToStep(graph));
}
Expand Down Expand Up @@ -136,10 +136,9 @@ public String toString() {
this.degree, this.skipDegree);
}

private CountTraverser.Step jsonToStep(HugeGraph graph) {
return new CountTraverser.Step(graph, this.direction, this.labels,
this.properties, this.degree,
this.skipDegree);
private EdgeStep jsonToStep(HugeGraph graph) {
return new EdgeStep(graph, this.direction, this.labels,
this.properties, this.degree, this.skipDegree);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import com.baidu.hugegraph.server.RestServer;
import com.baidu.hugegraph.traversal.algorithm.CustomizePathsTraverser;
import com.baidu.hugegraph.traversal.algorithm.HugeTraverser;
import com.baidu.hugegraph.traversal.algorithm.steps.WeightedEdgeStep;
import com.baidu.hugegraph.type.define.Directions;
import com.baidu.hugegraph.util.E;
import com.baidu.hugegraph.util.Log;
Expand Down Expand Up @@ -87,7 +88,7 @@ public String post(@Context GraphManager manager,

HugeGraph g = graph(manager, graph);
Iterator<Vertex> sources = request.sources.vertices(g);
List<CustomizePathsTraverser.Step> steps = step(g, request);
List<WeightedEdgeStep> steps = step(g, request);
boolean sorted = request.sortBy != SortBy.NONE;

CustomizePathsTraverser traverser = new CustomizePathsTraverser(g);
Expand Down Expand Up @@ -116,10 +117,10 @@ public String post(@Context GraphManager manager,
return manager.serializer(g).writePaths("paths", paths, false, iter);
}

private static List<CustomizePathsTraverser.Step> step(HugeGraph graph,
PathRequest req) {
private static List<WeightedEdgeStep> step(HugeGraph graph,
PathRequest req) {
int stepSize = req.steps.size();
List<CustomizePathsTraverser.Step> steps = new ArrayList<>(stepSize);
List<WeightedEdgeStep> steps = new ArrayList<>(stepSize);
for (Step step : req.steps) {
steps.add(step.jsonToStep(graph));
}
Expand Down Expand Up @@ -181,15 +182,11 @@ public String toString() {
this.sample);
}

private CustomizePathsTraverser.Step jsonToStep(HugeGraph g) {
return new CustomizePathsTraverser.Step(g, this.direction,
this.labels,
this.properties,
this.degree,
this.skipDegree,
this.weightBy,
this.defaultWeight,
this.sample);
private WeightedEdgeStep jsonToStep(HugeGraph g) {
return new WeightedEdgeStep(g, this.direction, this.labels,
this.properties, this.degree,
this.skipDegree, this.weightBy,
this.defaultWeight, this.sample);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,11 @@ public String post(@Context GraphManager manager,
Iterator<Vertex> sources = request.sources.vertices(g);
E.checkArgument(sources != null && sources.hasNext(),
"The source vertices can't be empty");
EdgeLabel edgeLabel = request.label == null ?
null : g.edgeLabel(request.label);

FusiformSimilarityTraverser traverser =
new FusiformSimilarityTraverser(g);
SimilarsMap result = traverser.fusiformSimilarity(
sources, request.direction, edgeLabel,
sources, request.direction, request.label,
request.minNeighbors, request.alpha,
request.minSimilars, request.top,
request.groupProperty, request.minGroups,
Expand Down
Loading

0 comments on commit 45cf281

Please sign in to comment.