Search in sources :

Example 1 with ProcessorLoader

use of com.alibaba.maxgraph.server.ProcessorLoader 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);
}
Also used : ZKStatementStore(com.alibaba.maxgraph.frontendservice.query.ZKStatementStore) JsonFileSchemaFetcher(com.alibaba.maxgraph.compiler.schema.JsonFileSchemaFetcher) SchemaFetcher(com.alibaba.maxgraph.compiler.api.schema.SchemaFetcher) JsonFileSchemaFetcher(com.alibaba.maxgraph.compiler.schema.JsonFileSchemaFetcher) TinkerMaxGraph(com.alibaba.maxgraph.structure.graph.TinkerMaxGraph) MixedProcessorLoader(com.alibaba.maxgraph.server.processor.MixedProcessorLoader) GremlinProcessorLoader(com.alibaba.maxgraph.server.GremlinProcessorLoader) ProcessorLoader(com.alibaba.maxgraph.server.ProcessorLoader) MaxGraphRecordProcessorManager(com.alibaba.maxgraph.frontendservice.server.manager.MaxGraphRecordProcessorManager) ExecutorAddressFetcher(com.alibaba.maxgraph.frontendservice.server.ExecutorAddressFetcher) MaxGraphServer(com.alibaba.maxgraph.server.MaxGraphServer) Endpoint(com.alibaba.maxgraph.sdkcommon.client.Endpoint) DefaultGraphDfs(com.alibaba.maxgraph.compiler.dfs.DefaultGraphDfs)

Example 2 with ProcessorLoader

use of com.alibaba.maxgraph.server.ProcessorLoader in project GraphScope by alibaba.

the class ReadOnlyGraphServer method start.

@Override
public void start() {
    this.loadSettings();
    logger.info(GremlinServer.getHeader());
    this.settings.port = GremlinConfig.GREMLIN_PORT.get(this.configs);
    this.settings.host = "0.0.0.0";
    if (settings.gremlinPool == 0) {
        settings.gremlinPool = Runtime.getRuntime().availableProcessors();
    }
    if (StringUtils.equals(settings.channelizer, WsAndHttpChannelizer.class.getName())) {
        settings.channelizer = MaxGraphWsAndHttpSocketChannelizer.class.getName();
    } else {
        throw new IllegalArgumentException("Not support for channelizer=>" + settings.channelizer);
    }
    settings.writeBufferHighWaterMark = GremlinConfig.SERVER_WRITE_BUFFER_HIGH_WATER.get(this.configs);
    settings.writeBufferLowWaterMark = GremlinConfig.SERVER_WRITE_BUFFER_LOW_WATER.get(this.configs);
    this.server = new GremlinServer(settings);
    ServerGremlinExecutor serverGremlinExecutor = Utils.getFieldValue(GremlinServer.class, this.server, "serverGremlinExecutor");
    serverGremlinExecutor.getGraphManager().putGraph("graph", graph);
    serverGremlinExecutor.getGraphManager().putTraversalSource("g", graph.traversal());
    GremlinExecutor gremlinExecutor = Utils.getFieldValue(ServerGremlinExecutor.class, serverGremlinExecutor, "gremlinExecutor");
    Bindings globalBindings = Utils.getFieldValue(GremlinExecutor.class, gremlinExecutor, "globalBindings");
    globalBindings.put("graph", graph);
    globalBindings.put("g", graph.traversal());
    ProcessorLoader processorLoader = new ReadOnlyMaxGraphProcessorLoader(this.configs, this.graph, this.schemaFetcher, this.rpcAddressFetcher);
    try {
        processorLoader.loadProcessor(settings);
    } catch (Exception e) {
        throw new MaxGraphException(e);
    }
    try {
        this.server.start().exceptionally(t -> {
            logger.error("Gremlin Server was unable to start and will now begin" + " shutdown: {}", t.getMessage());
            this.server.stop().join();
            return null;
        }).join();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    logger.info("Gremlin Server started....");
}
Also used : Configs(com.alibaba.maxgraph.common.config.Configs) SocketAddress(java.net.SocketAddress) Bindings(javax.script.Bindings) TinkerMaxGraph(com.alibaba.maxgraph.structure.graph.TinkerMaxGraph) Settings(org.apache.tinkerpop.gremlin.server.Settings) LoggerFactory(org.slf4j.LoggerFactory) WsAndHttpChannelizer(org.apache.tinkerpop.gremlin.server.channel.WsAndHttpChannelizer) StringUtils(org.apache.commons.lang3.StringUtils) GremlinServer(org.apache.tinkerpop.gremlin.server.GremlinServer) Utils(com.alibaba.maxgraph.tinkerpop.Utils) GremlinConfig(com.alibaba.maxgraph.common.config.GremlinConfig) RpcAddressFetcher(com.alibaba.maxgraph.common.rpc.RpcAddressFetcher) MaxGraphException(com.alibaba.maxgraph.compiler.api.exception.MaxGraphException) ServerGremlinExecutor(org.apache.tinkerpop.gremlin.server.util.ServerGremlinExecutor) Logger(org.slf4j.Logger) SchemaFetcher(com.alibaba.maxgraph.compiler.api.schema.SchemaFetcher) Files(java.nio.file.Files) AbstractService(com.alibaba.maxgraph.servers.AbstractService) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) IOException(java.io.IOException) Field(java.lang.reflect.Field) InetSocketAddress(java.net.InetSocketAddress) File(java.io.File) Channel(io.netty.channel.Channel) ProcessorLoader(com.alibaba.maxgraph.server.ProcessorLoader) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) MaxGraphWsAndHttpSocketChannelizer(com.alibaba.maxgraph.server.MaxGraphWsAndHttpSocketChannelizer) Paths(java.nio.file.Paths) GremlinExecutor(org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutor) InputStream(java.io.InputStream) GremlinServer(org.apache.tinkerpop.gremlin.server.GremlinServer) ServerGremlinExecutor(org.apache.tinkerpop.gremlin.server.util.ServerGremlinExecutor) GremlinExecutor(org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutor) Bindings(javax.script.Bindings) MaxGraphException(com.alibaba.maxgraph.compiler.api.exception.MaxGraphException) MaxGraphException(com.alibaba.maxgraph.compiler.api.exception.MaxGraphException) IOException(java.io.IOException) ServerGremlinExecutor(org.apache.tinkerpop.gremlin.server.util.ServerGremlinExecutor) MaxGraphWsAndHttpSocketChannelizer(com.alibaba.maxgraph.server.MaxGraphWsAndHttpSocketChannelizer) ProcessorLoader(com.alibaba.maxgraph.server.ProcessorLoader) WsAndHttpChannelizer(org.apache.tinkerpop.gremlin.server.channel.WsAndHttpChannelizer)

Example 3 with ProcessorLoader

use of com.alibaba.maxgraph.server.ProcessorLoader in project GraphScope by alibaba.

the class GaiaGraphServer method start.

@Override
public void start(int port, ProcessorLoader processorLoader, boolean hasAuth) {
    logger.info(GremlinServer.getHeader());
    this.settings.port = instanceConfig.getGremlinServerPort();
    this.settings.host = "0.0.0.0";
    if (settings.gremlinPool == 0) {
        settings.gremlinPool = Runtime.getRuntime().availableProcessors();
    }
    this.server = new GremlinServer(settings);
    loadProcessor(gaiaConfig, broadcastProcessor, storeService);
    // bind g to traversal source
    Graph traversalGraph = TraversalSourceGraph.open(new BaseConfiguration());
    ServerGremlinExecutor serverGremlinExecutor = PlanUtils.getServerGremlinExecutor(this.server);
    serverGremlinExecutor.getGraphManager().putGraph("graph", traversalGraph);
    serverGremlinExecutor.getGraphManager().putTraversalSource("g", traversalGraph.traversal());
    Bindings globalBindings = PlanUtils.getGlobalBindings(server.getServerGremlinExecutor().getGremlinExecutor());
    globalBindings.put("graph", traversalGraph);
    globalBindings.put("g", traversalGraph.traversal());
    // start gremlin server
    try {
        server.start().exceptionally(t -> {
            logger.error("Gremlin Server was unable to start and will now begin" + " shutdown {}", t);
            server.stop().join();
            return null;
        }).join();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    logger.info("Gremlin Server started....");
}
Also used : ServerGremlinExecutor(org.apache.tinkerpop.gremlin.server.util.ServerGremlinExecutor) OpProcessor(org.apache.tinkerpop.gremlin.server.OpProcessor) AbstractBroadcastProcessor(com.alibaba.graphscope.gaia.broadcast.AbstractBroadcastProcessor) SocketAddress(java.net.SocketAddress) Bindings(javax.script.Bindings) Settings(org.apache.tinkerpop.gremlin.server.Settings) Graph(org.apache.tinkerpop.gremlin.structure.Graph) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) TraversalOpProcessor(com.alibaba.graphscope.gaia.processor.TraversalOpProcessor) GremlinServer(org.apache.tinkerpop.gremlin.server.GremlinServer) Map(java.util.Map) GraphStoreService(com.alibaba.graphscope.gaia.store.GraphStoreService) BaseConfiguration(org.apache.commons.configuration.BaseConfiguration) GaiaGraphOpProcessor(com.alibaba.graphscope.gaia.processor.GaiaGraphOpProcessor) ServerGremlinExecutor(org.apache.tinkerpop.gremlin.server.util.ServerGremlinExecutor) Logger(org.slf4j.Logger) GaiaConfig(com.alibaba.graphscope.gaia.config.GaiaConfig) PlanUtils(com.alibaba.graphscope.gaia.plan.PlanUtils) InstanceConfig(com.alibaba.maxgraph.common.cluster.InstanceConfig) Field(java.lang.reflect.Field) InetSocketAddress(java.net.InetSocketAddress) Channel(io.netty.channel.Channel) ProcessorLoader(com.alibaba.maxgraph.server.ProcessorLoader) OpLoader(org.apache.tinkerpop.gremlin.server.op.OpLoader) LogicPlanProcessor(com.alibaba.graphscope.gaia.processor.LogicPlanProcessor) MaxGraphServer(com.alibaba.maxgraph.server.MaxGraphServer) GremlinExecutor(org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutor) TraversalSourceGraph(com.alibaba.graphscope.gaia.TraversalSourceGraph) InputStream(java.io.InputStream) GremlinServer(org.apache.tinkerpop.gremlin.server.GremlinServer) BaseConfiguration(org.apache.commons.configuration.BaseConfiguration) Graph(org.apache.tinkerpop.gremlin.structure.Graph) TraversalSourceGraph(com.alibaba.graphscope.gaia.TraversalSourceGraph) Bindings(javax.script.Bindings)

Aggregations

ProcessorLoader (com.alibaba.maxgraph.server.ProcessorLoader)3 SchemaFetcher (com.alibaba.maxgraph.compiler.api.schema.SchemaFetcher)2 MaxGraphServer (com.alibaba.maxgraph.server.MaxGraphServer)2 TinkerMaxGraph (com.alibaba.maxgraph.structure.graph.TinkerMaxGraph)2 Channel (io.netty.channel.Channel)2 InputStream (java.io.InputStream)2 Field (java.lang.reflect.Field)2 InetSocketAddress (java.net.InetSocketAddress)2 SocketAddress (java.net.SocketAddress)2 Bindings (javax.script.Bindings)2 GremlinExecutor (org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutor)2 GremlinServer (org.apache.tinkerpop.gremlin.server.GremlinServer)2 Settings (org.apache.tinkerpop.gremlin.server.Settings)2 ServerGremlinExecutor (org.apache.tinkerpop.gremlin.server.util.ServerGremlinExecutor)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 TraversalSourceGraph (com.alibaba.graphscope.gaia.TraversalSourceGraph)1 AbstractBroadcastProcessor (com.alibaba.graphscope.gaia.broadcast.AbstractBroadcastProcessor)1 GaiaConfig (com.alibaba.graphscope.gaia.config.GaiaConfig)1 PlanUtils (com.alibaba.graphscope.gaia.plan.PlanUtils)1