use of com.alibaba.maxgraph.structure.graph.TinkerMaxGraph in project GraphScope by alibaba.
the class Frontend method initAndStartGremlinServer.
@Override
protected void initAndStartGremlinServer() throws Exception {
SchemaFetcher schemaFetcher;
String vineyardSchemaPath = this.instanceConfig.getVineyardSchemaPath();
logger.info("Read schema from vineyard schema file " + vineyardSchemaPath);
schemaFetcher = new JsonFileSchemaFetcher(vineyardSchemaPath);
this.remoteGraph = new RemoteGraph(this, schemaFetcher);
this.remoteGraph.refresh();
this.graph = new TinkerMaxGraph(instanceConfig, remoteGraph, new DefaultGraphDfs());
// add gaia compiler
AsyncRpcChannelFetcher gaiaRpcFetcher = new AddressChannelFetcher(new ExecutorAddressFetcher(this.clientManager));
GraphStoreService gaiaStoreService = new VineyardGraphStore(schemaFetcher);
AbstractBroadcastProcessor broadcastProcessor = new AsyncRpcBroadcastProcessor(gaiaRpcFetcher);
gaiaGraphServer = new GaiaGraphServer(this.graph, instanceConfig, gaiaStoreService, broadcastProcessor, new VineyardConfig(instanceConfig));
gaiaGraphServer.start(0, null, false);
this.gremlinServerPort = gaiaGraphServer.getGremlinServerPort();
}
use of com.alibaba.maxgraph.structure.graph.TinkerMaxGraph in project GraphScope by alibaba.
the class Frontend method initAndStartGremlinServer.
protected void initAndStartGremlinServer() throws Exception {
SchemaFetcher schemaFetcher;
String vineyardSchemaPath = this.instanceConfig.getVineyardSchemaPath();
LOG.info("Read schema from vineyard schema file " + vineyardSchemaPath);
schemaFetcher = new JsonFileSchemaFetcher(vineyardSchemaPath);
this.remoteGraph = new RemoteGraph(this, schemaFetcher);
this.remoteGraph.refresh();
this.graph = new TinkerMaxGraph(instanceConfig, remoteGraph, new DefaultGraphDfs());
this.graphGremlinServer = new MaxGraphServer(this.graph);
int tmpGremlinServerPort = instanceConfig.getGremlinServerPort() > 0 ? instanceConfig.getGremlinServerPort() : 0;
ProcessorLoader processorLoader;
switch(instanceConfig.getGremlinServerMode()) {
case TIMELY:
case MIXED:
{
processorLoader = MixedProcessorLoader.newProcessorLoader(graph, this.instanceConfig, new ExecutorAddressFetcher(clientManager), schemaFetcher, new ZKStatementStore(instanceConfig), new MaxGraphRecordProcessorManager(this.graph, this), this.getFrontendQueryManager());
break;
}
default:
{
processorLoader = GremlinProcessorLoader.newProcessorLoader();
break;
}
}
this.graphGremlinServer.start(tmpGremlinServerPort, processorLoader, instanceConfig.getInstanceAuthType() == 1);
this.gremlinServerPort = tmpGremlinServerPort > 0 ? tmpGremlinServerPort : this.graphGremlinServer.getGremlinServerPort();
LOG.info("gremlin server port:{}", this.gremlinServerPort);
}
use of com.alibaba.maxgraph.structure.graph.TinkerMaxGraph in project GraphScope by alibaba.
the class MxVertexProperty method remove.
@Override
public void remove() {
TinkerMaxGraph tinkerMaxGraph = (TinkerMaxGraph) vertex.graph();
GraphVertex graphVertex = (GraphVertex) tinkerMaxGraph.schema().getElement(vertex.label());
Set<String> propNameList = graphVertex.getPrimaryKeyList().stream().map(GraphProperty::getName).collect(Collectors.toSet());
if (propNameList.contains(this.key)) {
return;
}
Iterator<VertexProperty<Object>> propItor = vertex.properties();
Map<String, Object> kvs = Maps.newHashMap();
while (propItor.hasNext()) {
VertexProperty<Object> prop = propItor.next();
kvs.put(prop.key(), prop.value());
}
kvs.remove(this.key);
tinkerMaxGraph.getBaseGraph().addVertex(vertex.label(), kvs);
}
use of com.alibaba.maxgraph.structure.graph.TinkerMaxGraph in project GraphScope by alibaba.
the class MaxGraphGryoReader method readGraph.
/**
* Read data into a {@link Graph} from output generated by any of the {@link GryoWriter} {@code writeVertex} or
* {@code writeVertices} methods or by {@link GryoWriter#writeGraph(OutputStream, Graph)}.
*
* @param inputStream a stream containing an entire graph of vertices and edges as defined by the accompanying
* {@link GraphWriter#writeGraph(OutputStream, Graph)}.
* @param graphToWriteTo the graph to write to when reading from the stream.
* @throws IOException
*/
@Override
public void readGraph(final InputStream inputStream, final Graph graphToWriteTo) throws IOException {
if (!(graphToWriteTo instanceof TinkerMaxGraph)) {
throw new IOException("Only support snapshot maxgraph here.");
}
TinkerMaxGraph tinkerMaxGraph = (TinkerMaxGraph) graphToWriteTo;
Transaction tx = tinkerMaxGraph.tx();
tx.open();
Input input = new Input(inputStream);
// insert all vertices
List<StarGraph.StarVertex> starVertexList = Lists.newArrayList();
while (!input.eof()) {
readHeader(input);
final StarGraph starGraph = kryo.readObject(input, StarGraph.class);
// read the terminator
kryo.readClassAndObject(input);
StarGraph.StarVertex starVertex = starGraph.getStarVertex();
Iterator<VertexProperty<Object>> propertyIterator = starVertex.properties();
List<Object> keyValues = Lists.newArrayList();
keyValues.add(T.label);
keyValues.add(starVertex.label());
keyValues.add("id");
keyValues.add(Long.parseLong(starVertex.id().toString()));
while (propertyIterator.hasNext()) {
VertexProperty<Object> vertexProperty = propertyIterator.next();
keyValues.add(vertexProperty.key());
keyValues.add(vertexProperty.value());
}
tinkerMaxGraph.addVertexAsync(keyValues.toArray());
starVertexList.add(starVertex);
}
tx.commit();
// query the inserted vertices
Iterator<Vertex> vertexIterator = graphToWriteTo.vertices();
Map<Integer, Vertex> insertedVertexMap = Maps.newHashMap();
while (vertexIterator.hasNext()) {
Vertex vertex = vertexIterator.next();
insertedVertexMap.put(((Long) vertex.property("id").value()).intValue(), vertex);
}
// insert all the edges
for (StarGraph.StarVertex starVertex : starVertexList) {
Iterator<Edge> edgeIterator = starVertex.edges(Direction.OUT);
while (edgeIterator.hasNext()) {
Edge edge = edgeIterator.next();
Vertex srcVertex = edge.outVertex();
Vertex dstVertex = edge.inVertex();
Vertex insertedSrcVertex = insertedVertexMap.get(srcVertex.id());
Vertex insertedDstVertex = insertedVertexMap.get(dstVertex.id());
checkNotNull(insertedSrcVertex, "src vertex cant be null for edge " + edge);
checkNotNull(insertedDstVertex, "dst vertex cant be null for edge " + edge);
List<Object> keyValues = Lists.newArrayList();
Iterator<Property<Object>> propertyIterator = edge.properties();
keyValues.add("id");
keyValues.add(edge.id());
while (propertyIterator.hasNext()) {
Property<Object> property = propertyIterator.next();
keyValues.add(property.key());
keyValues.add(property.value());
}
tinkerMaxGraph.addEdgeAsync(insertedSrcVertex, insertedDstVertex, edge.label(), keyValues.toArray());
}
}
tx.commit();
}
use of com.alibaba.maxgraph.structure.graph.TinkerMaxGraph in project GraphScope by alibaba.
the class Frontend method initAndStartGremlinServer.
@Override
protected void initAndStartGremlinServer() throws Exception {
SchemaFetcher schemaFetcher;
String vineyardSchemaPath = this.instanceConfig.getVineyardSchemaPath();
logger.info("Read schema from vineyard schema file " + vineyardSchemaPath);
schemaFetcher = new JsonFileSchemaFetcher(vineyardSchemaPath);
this.remoteGraph = new RemoteGraph(this, schemaFetcher);
this.remoteGraph.refresh();
this.graph = new TinkerMaxGraph(instanceConfig, remoteGraph, new DefaultGraphDfs());
// add ir compiler
Configs configs = getConfigs(this.instanceConfig);
IrMetaFetcher irMetaFetcher = getStoreConfigs(this.instanceConfig);
RpcAddressFetcher addressFetcher = new ExecutorAddressFetcher(this.clientManager);
RpcChannelFetcher channelFetcher = new RpcAddressChannelFetcher(addressFetcher);
this.gremlinServer = new IrGremlinServer(this.instanceConfig.getGremlinServerPort());
this.gremlinServer.start(configs, irMetaFetcher, channelFetcher, new IrMetaQueryCallback(irMetaFetcher), TestGraphFactory.VINEYARD);
this.gremlinServerPort = gremlinServer.getGremlinServerPort();
}
Aggregations