Search in sources :

Example 1 with Service

use of spark.Service in project spark by perwendel.

the class MultipleServices method igniteSecondService.

private static void igniteSecondService() {
    Service http = ignite().port(1234).staticFileLocation("/public").threadPool(40);
    http.get("/hello", (q, a) -> "Hello World!");
    http.redirect.any("/hi", "/hello");
}
Also used : Service(spark.Service)

Example 2 with Service

use of spark.Service 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 Service

use of spark.Service in project gocd by gocd.

the class TestApplication method destroy.

@Override
public void destroy() {
    // see Service.stop(), (not invoked directly because it spawns a thread)
    try {
        Method getInstance = Spark.class.getDeclaredMethod("getInstance");
        getInstance.setAccessible(true);
        Service service = (Service) getInstance.invoke(null);
        // Dependent on current version of Spark
        // This is likely to fail in case of upgrades
        clear(service, "routes", Routes.class);
        clear(service, "exceptionMapper", ExceptionMapper.class);
        clear(service, "staticFilesConfiguration", StaticFilesConfiguration.class);
        ReflectionTestUtils.setField(service, "initialized", false);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : Service(spark.Service) Method(java.lang.reflect.Method)

Example 4 with Service

use of spark.Service in project spark by perwendel.

the class MultipleServices method igniteFirstService.

private static void igniteFirstService() {
    // I give the variable the name 'http' for the code to make sense when adding routes.
    Service http = ignite();
    http.get("/hello", (q, a) -> "Hello World!");
}
Also used : Service(spark.Service)

Example 5 with Service

use of spark.Service in project grakn by graknlabs.

the class SparkContext method startSparkCopyOnNewPort.

private Service startSparkCopyOnNewPort() {
    Service spark = Service.ignite();
    String hostName = config.getProperty(GraknConfigKey.SERVER_HOST_NAME);
    if (config.getProperty(GraknConfigKey.SERVER_PORT) == 0) {
        GraknTestUtil.allocateSparkPort(config);
    }
    configureSpark(spark, hostName, port(), config.getPath(GraknConfigKey.STATIC_FILES_PATH), 64);
    spark.init();
    RestAssured.baseURI = "http://" + hostName + ":" + port();
    RestAssured.requestSpecification = new RequestSpecBuilder().build();
    return spark;
}
Also used : Service(spark.Service) RequestSpecBuilder(com.jayway.restassured.builder.RequestSpecBuilder)

Aggregations

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