Search in sources :

Example 1 with EngineGraknTxFactory

use of ai.grakn.engine.factory.EngineGraknTxFactory in project grakn by graknlabs.

the class EngineContext method clearGraphs.

private static void clearGraphs(EngineGraknTxFactory factory) {
    // Drop all keyspaces
    final Set<String> keyspaceNames = new HashSet<String>();
    try (GraknTx systemGraph = factory.tx(GraknKeyspaceStore.SYSTEM_KB_KEYSPACE, GraknTxType.WRITE)) {
        systemGraph.graql().match(var("x").isa("keyspace-name")).forEach(x -> x.concepts().forEach(y -> {
            keyspaceNames.add(y.asAttribute().getValue().toString());
        }));
    }
    keyspaceNames.forEach(name -> {
        GraknTx graph = factory.tx(Keyspace.of(name), GraknTxType.WRITE);
        graph.admin().delete();
    });
    factory.refreshConnections();
}
Also used : Keyspace(ai.grakn.Keyspace) LoggerFactory(org.slf4j.LoggerFactory) RedisSanityCheck(ai.grakn.engine.data.RedisSanityCheck) EngineGraknTxFactory(ai.grakn.engine.factory.EngineGraknTxFactory) GraknConfig(ai.grakn.engine.GraknConfig) CountStorage(ai.grakn.engine.task.postprocessing.CountStorage) GraknTx(ai.grakn.GraknTx) RedisWrapper(ai.grakn.engine.data.RedisWrapper) JedisLockProvider(ai.grakn.engine.lock.JedisLockProvider) JedisPool(redis.clients.jedis.JedisPool) RedisCountStorage(ai.grakn.engine.task.postprocessing.redisstorage.RedisCountStorage) GraknTxType(ai.grakn.GraknTxType) Graql.var(ai.grakn.graql.Graql.var) GraknKeyspaceStoreImpl(ai.grakn.engine.GraknKeyspaceStoreImpl) GraknKeyspaceStore(ai.grakn.engine.GraknKeyspaceStore) Set(java.util.Set) GrpcOpenRequestExecutorImpl(ai.grakn.engine.rpc.GrpcOpenRequestExecutorImpl) GraknConfigKey(ai.grakn.GraknConfigKey) IndexPostProcessor(ai.grakn.engine.task.postprocessing.IndexPostProcessor) IndexStorage(ai.grakn.engine.task.postprocessing.IndexStorage) List(java.util.List) ExceptionUtils.getFullStackTrace(org.apache.commons.lang.exception.ExceptionUtils.getFullStackTrace) GraknEngineServer(ai.grakn.engine.GraknEngineServer) RedisIndexStorage(ai.grakn.engine.task.postprocessing.redisstorage.RedisIndexStorage) RestAssured(com.jayway.restassured.RestAssured) GraknEngineStatus(ai.grakn.engine.GraknEngineStatus) SimpleURI(ai.grakn.util.SimpleURI) Iterables(com.google.common.collect.Iterables) GraknTestUtil(ai.grakn.util.GraknTestUtil) TestRule(org.junit.rules.TestRule) CountPostProcessor(ai.grakn.engine.task.postprocessing.CountPostProcessor) GrpcOpenRequestExecutor(ai.grakn.grpc.GrpcOpenRequestExecutor) LockProvider(ai.grakn.engine.lock.LockProvider) HashSet(java.util.HashSet) ImmutableList(com.google.common.collect.ImmutableList) ServerBuilder(io.grpc.ServerBuilder) Server(io.grpc.Server) GrpcServer(ai.grakn.engine.rpc.GrpcServer) MetricRegistry(com.codahale.metrics.MetricRegistry) GraknEngineServerFactory(ai.grakn.engine.GraknEngineServerFactory) IOException(java.io.IOException) PostProcessor(ai.grakn.engine.task.postprocessing.PostProcessor) GraknSystemKeyspaceSession(ai.grakn.engine.GraknSystemKeyspaceSession) QueueSanityCheck(ai.grakn.engine.data.QueueSanityCheck) EmbeddedGraknSession(ai.grakn.factory.EmbeddedGraknSession) SampleKBLoader.randomKeyspace(ai.grakn.util.SampleKBLoader.randomKeyspace) GrpcGraknService(ai.grakn.engine.rpc.GrpcGraknService) Service(spark.Service) EngineID(ai.grakn.engine.util.EngineID) JedisPoolConfig(redis.clients.jedis.JedisPoolConfig) Collections(java.util.Collections) GraknTx(ai.grakn.GraknTx) HashSet(java.util.HashSet)

Example 2 with EngineGraknTxFactory

use of ai.grakn.engine.factory.EngineGraknTxFactory in project grakn by graknlabs.

the class GraknEngineServerFactory method createGraknEngineServer.

/**
 * Create a {@link GraknEngineServer} configured for Grakn Core. Grakn Queue (which is needed for post-processing and distributed locks) is implemented with Redis as the backend store
 *
 * @return a {@link GraknEngineServer} instance configured for Grakn Core
 */
public static GraknEngineServer createGraknEngineServer() {
    // grakn engine configuration
    EngineID engineId = EngineID.me();
    GraknConfig config = GraknConfig.create();
    GraknEngineStatus status = new GraknEngineStatus();
    MetricRegistry metricRegistry = new MetricRegistry();
    // redis
    RedisWrapper redisWrapper = RedisWrapper.create(config);
    QueueSanityCheck queueSanityCheck = new RedisSanityCheck(redisWrapper);
    // distributed locks
    LockProvider lockProvider = new JedisLockProvider(redisWrapper.getJedisPool());
    SystemKeyspaceSession systemKeyspaceSession = new GraknSystemKeyspaceSession(config);
    GraknKeyspaceStore graknKeyspaceStore = GraknKeyspaceStoreImpl.create(systemKeyspaceSession);
    // tx-factory
    EngineGraknTxFactory engineGraknTxFactory = EngineGraknTxFactory.create(lockProvider, config, graknKeyspaceStore);
    // post-processing
    IndexStorage indexStorage = RedisIndexStorage.create(redisWrapper.getJedisPool(), metricRegistry);
    CountStorage countStorage = RedisCountStorage.create(redisWrapper.getJedisPool(), metricRegistry);
    IndexPostProcessor indexPostProcessor = IndexPostProcessor.create(lockProvider, indexStorage);
    CountPostProcessor countPostProcessor = CountPostProcessor.create(config, engineGraknTxFactory, lockProvider, metricRegistry, countStorage);
    PostProcessor postProcessor = PostProcessor.create(indexPostProcessor, countPostProcessor);
    // http services: spark, http controller, and gRPC server
    Service sparkHttp = Service.ignite();
    Collection<HttpController> httpControllers = Collections.emptyList();
    GrpcServer grpcServer = configureGrpcServer(config, engineGraknTxFactory, postProcessor);
    return createGraknEngineServer(engineId, config, status, sparkHttp, httpControllers, grpcServer, engineGraknTxFactory, metricRegistry, queueSanityCheck, lockProvider, postProcessor, graknKeyspaceStore);
}
Also used : EngineID(ai.grakn.engine.util.EngineID) RedisWrapper(ai.grakn.engine.data.RedisWrapper) IndexPostProcessor(ai.grakn.engine.task.postprocessing.IndexPostProcessor) MetricRegistry(com.codahale.metrics.MetricRegistry) EngineGraknTxFactory(ai.grakn.engine.factory.EngineGraknTxFactory) GrpcGraknService(ai.grakn.engine.rpc.GrpcGraknService) Service(spark.Service) GrpcServer(ai.grakn.engine.rpc.GrpcServer) SystemKeyspaceSession(ai.grakn.factory.SystemKeyspaceSession) CountPostProcessor(ai.grakn.engine.task.postprocessing.CountPostProcessor) HttpController(ai.grakn.engine.controller.HttpController) LockProvider(ai.grakn.engine.lock.LockProvider) JedisLockProvider(ai.grakn.engine.lock.JedisLockProvider) JedisLockProvider(ai.grakn.engine.lock.JedisLockProvider) QueueSanityCheck(ai.grakn.engine.data.QueueSanityCheck) IndexStorage(ai.grakn.engine.task.postprocessing.IndexStorage) RedisIndexStorage(ai.grakn.engine.task.postprocessing.redisstorage.RedisIndexStorage) RedisSanityCheck(ai.grakn.engine.data.RedisSanityCheck) CountStorage(ai.grakn.engine.task.postprocessing.CountStorage) RedisCountStorage(ai.grakn.engine.task.postprocessing.redisstorage.RedisCountStorage) CountPostProcessor(ai.grakn.engine.task.postprocessing.CountPostProcessor) PostProcessor(ai.grakn.engine.task.postprocessing.PostProcessor) IndexPostProcessor(ai.grakn.engine.task.postprocessing.IndexPostProcessor)

Example 3 with EngineGraknTxFactory

use of ai.grakn.engine.factory.EngineGraknTxFactory in project grakn by graknlabs.

the class GraknEngineServerTest method createGraknEngineServer.

private GraknEngineServer createGraknEngineServer(RedisWrapper redisWrapper) {
    // grakn engine configuration
    EngineID engineId = EngineID.me();
    GraknEngineStatus status = new GraknEngineStatus();
    MetricRegistry metricRegistry = new MetricRegistry();
    // distributed locks
    LockProvider lockProvider = new JedisLockProvider(redisWrapper.getJedisPool());
    graknKeyspaceStore = GraknKeyspaceStoreFake.of();
    // tx-factory
    EngineGraknTxFactory engineGraknTxFactory = EngineGraknTxFactory.create(lockProvider, config, graknKeyspaceStore);
    // post-processing
    IndexStorage indexStorage = RedisIndexStorage.create(redisWrapper.getJedisPool(), metricRegistry);
    CountStorage countStorage = RedisCountStorage.create(redisWrapper.getJedisPool(), metricRegistry);
    IndexPostProcessor indexPostProcessor = IndexPostProcessor.create(lockProvider, indexStorage);
    CountPostProcessor countPostProcessor = CountPostProcessor.create(config, engineGraknTxFactory, lockProvider, metricRegistry, countStorage);
    PostProcessor postProcessor = PostProcessor.create(indexPostProcessor, countPostProcessor);
    // http services: spark, http controller, and gRPC server
    Service sparkHttp = Service.ignite();
    Collection<HttpController> httpControllers = Collections.emptyList();
    int grpcPort = config.getProperty(GraknConfigKey.GRPC_PORT);
    GrpcOpenRequestExecutor requestExecutor = new GrpcOpenRequestExecutorImpl(engineGraknTxFactory);
    Server server = ServerBuilder.forPort(grpcPort).addService(new GrpcGraknService(requestExecutor, postProcessor)).build();
    GrpcServer grpcServer = GrpcServer.create(server);
    QueueSanityCheck queueSanityCheck = new RedisSanityCheck(redisWrapper);
    return GraknEngineServerFactory.createGraknEngineServer(engineId, config, status, sparkHttp, httpControllers, grpcServer, engineGraknTxFactory, metricRegistry, queueSanityCheck, lockProvider, postProcessor, graknKeyspaceStore);
}
Also used : EngineID(ai.grakn.engine.util.EngineID) RedisServer(ai.grakn.redismock.RedisServer) Server(io.grpc.Server) GrpcServer(ai.grakn.engine.rpc.GrpcServer) GrpcOpenRequestExecutorImpl(ai.grakn.engine.rpc.GrpcOpenRequestExecutorImpl) IndexPostProcessor(ai.grakn.engine.task.postprocessing.IndexPostProcessor) MetricRegistry(com.codahale.metrics.MetricRegistry) EngineGraknTxFactory(ai.grakn.engine.factory.EngineGraknTxFactory) GrpcOpenRequestExecutor(ai.grakn.grpc.GrpcOpenRequestExecutor) GrpcGraknService(ai.grakn.engine.rpc.GrpcGraknService) Service(spark.Service) GrpcServer(ai.grakn.engine.rpc.GrpcServer) CountPostProcessor(ai.grakn.engine.task.postprocessing.CountPostProcessor) HttpController(ai.grakn.engine.controller.HttpController) JedisLockProvider(ai.grakn.engine.lock.JedisLockProvider) LockProvider(ai.grakn.engine.lock.LockProvider) JedisLockProvider(ai.grakn.engine.lock.JedisLockProvider) IndexStorage(ai.grakn.engine.task.postprocessing.IndexStorage) RedisIndexStorage(ai.grakn.engine.task.postprocessing.redisstorage.RedisIndexStorage) QueueSanityCheck(ai.grakn.engine.data.QueueSanityCheck) CountStorage(ai.grakn.engine.task.postprocessing.CountStorage) RedisCountStorage(ai.grakn.engine.task.postprocessing.redisstorage.RedisCountStorage) RedisSanityCheck(ai.grakn.engine.data.RedisSanityCheck) IndexPostProcessor(ai.grakn.engine.task.postprocessing.IndexPostProcessor) CountPostProcessor(ai.grakn.engine.task.postprocessing.CountPostProcessor) PostProcessor(ai.grakn.engine.task.postprocessing.PostProcessor) GrpcGraknService(ai.grakn.engine.rpc.GrpcGraknService)

Aggregations

QueueSanityCheck (ai.grakn.engine.data.QueueSanityCheck)3 RedisSanityCheck (ai.grakn.engine.data.RedisSanityCheck)3 EngineGraknTxFactory (ai.grakn.engine.factory.EngineGraknTxFactory)3 JedisLockProvider (ai.grakn.engine.lock.JedisLockProvider)3 LockProvider (ai.grakn.engine.lock.LockProvider)3 GrpcGraknService (ai.grakn.engine.rpc.GrpcGraknService)3 GrpcServer (ai.grakn.engine.rpc.GrpcServer)3 CountPostProcessor (ai.grakn.engine.task.postprocessing.CountPostProcessor)3 CountStorage (ai.grakn.engine.task.postprocessing.CountStorage)3 IndexPostProcessor (ai.grakn.engine.task.postprocessing.IndexPostProcessor)3 IndexStorage (ai.grakn.engine.task.postprocessing.IndexStorage)3 PostProcessor (ai.grakn.engine.task.postprocessing.PostProcessor)3 RedisCountStorage (ai.grakn.engine.task.postprocessing.redisstorage.RedisCountStorage)3 RedisIndexStorage (ai.grakn.engine.task.postprocessing.redisstorage.RedisIndexStorage)3 EngineID (ai.grakn.engine.util.EngineID)3 MetricRegistry (com.codahale.metrics.MetricRegistry)3 Service (spark.Service)3 HttpController (ai.grakn.engine.controller.HttpController)2 RedisWrapper (ai.grakn.engine.data.RedisWrapper)2 GrpcOpenRequestExecutorImpl (ai.grakn.engine.rpc.GrpcOpenRequestExecutorImpl)2