Search in sources :

Example 1 with SimpleURI

use of ai.grakn.util.SimpleURI in project grakn by graknlabs.

the class EngineContext method before.

@Override
protected final void before() throws Throwable {
    RestAssured.baseURI = uri().toURI().toString();
    if (!config.getProperty(GraknConfigKey.TEST_START_EMBEDDED_COMPONENTS)) {
        return;
    }
    SimpleURI redisURI = new SimpleURI(Iterables.getOnlyElement(config.getProperty(GraknConfigKey.REDIS_HOST)));
    jedisPool = new JedisPool(redisURI.getHost(), redisURI.getPort());
    // To ensure consistency b/w test profiles and configuration files, when not using Janus
    // for a unit tests in an IDE, add the following option:
    // -Dgrakn.conf=../conf/test/tinker/grakn.properties
    // 
    // When using janus, add -Dgrakn.test-profile=janus
    // 
    // The reason is that the default configuration of Grakn uses the Janus Factory while the default
    // test profile is tinker: so when running a unit test within an IDE without any extra parameters,
    // we end up wanting to use the JanusFactory but without starting Cassandra first.
    LOG.info("starting engine...");
    // start engine
    setRestAssuredUri(config);
    spark = Service.ignite();
    config.setConfigProperty(GraknConfigKey.REDIS_HOST, Collections.singletonList("localhost:" + redis.port()));
    RedisWrapper redis = RedisWrapper.create(config);
    server = startGraknEngineServer(redis);
    LOG.info("engine started on " + uri());
}
Also used : RedisWrapper(ai.grakn.engine.data.RedisWrapper) SimpleURI(ai.grakn.util.SimpleURI) JedisPool(redis.clients.jedis.JedisPool)

Example 2 with SimpleURI

use of ai.grakn.util.SimpleURI in project grakn by graknlabs.

the class EngineContext method create.

public static EngineContext create(GraknConfig config) {
    SimpleURI redisURI = new SimpleURI(Iterables.getOnlyElement(config.getProperty(GraknConfigKey.REDIS_HOST)));
    int redisPort = redisURI.getPort();
    InMemoryRedisContext redis = InMemoryRedisContext.create(redisPort);
    return new EngineContext(config, redis);
}
Also used : SimpleURI(ai.grakn.util.SimpleURI)

Example 3 with SimpleURI

use of ai.grakn.util.SimpleURI in project grakn by graknlabs.

the class GraqlConsole method start.

public static boolean start(GraqlShellOptions options, SessionProvider sessionProvider, String historyFile, PrintStream sout, PrintStream serr) throws InterruptedException, IOException {
    List<String> queries = null;
    // ------- Check option  ------------------------
    String query = options.getQuery();
    // This is a best-effort guess as to whether the user has made a mistake, without parsing the query
    if (query != null) {
        queries = ImmutableList.of(query);
        if (!query.contains("$") && query.trim().startsWith("match")) {
            serr.println(ErrorMessage.NO_VARIABLE_IN_QUERY.getMessage());
        }
    }
    // Print usage message if requested or if invalid arguments provided
    if (options.displayHelp()) {
        options.printUsage(sout);
        return true;
    }
    if (options.displayVersion()) {
        sout.println(GraknVersion.VERSION);
        return true;
    }
    // ------- Check option  ------------------------
    Path path = options.getBatchLoadPath();
    if (path != null) {
        Keyspace keyspace = options.getKeyspace();
        SimpleURI location = options.getUri();
        SimpleURI httpUri = location != null ? location : Grakn.DEFAULT_URI;
        try {
            BatchLoader.sendBatchRequest(httpUri, keyspace, path, sout, serr);
        } catch (Exception e) {
            sout.println("Batch failed \n" + CommonUtil.simplifyExceptionMessage(e));
            return false;
        }
        return true;
    }
    // --------   If no option set we start GraqlShell   ----------
    OutputFormat outputFormat = options.getOutputFormat();
    boolean infer = options.shouldInfer();
    ConsoleReader console = new ConsoleReader(System.in, sout);
    GraknSession session = sessionProvider.getSession(options, console);
    try (GraqlShell shell = new GraqlShell(historyFile, session, console, serr, outputFormat, infer)) {
        List<Path> filePaths = options.getFiles();
        if (filePaths != null) {
            queries = loadQueries(filePaths);
        }
        // Start shell
        shell.start(queries);
        return !shell.errorOccurred();
    } catch (StatusRuntimeException e) {
        if (e.getStatus().getCode().equals(Status.Code.UNAVAILABLE)) {
            serr.println(ErrorMessage.COULD_NOT_CONNECT.getMessage());
            return false;
        } else {
            throw e;
        }
    }
}
Also used : Path(java.nio.file.Path) ConsoleReader(jline.console.ConsoleReader) SimpleURI(ai.grakn.util.SimpleURI) GraknSession(ai.grakn.GraknSession) IOException(java.io.IOException) StatusRuntimeException(io.grpc.StatusRuntimeException) Keyspace(ai.grakn.Keyspace) StatusRuntimeException(io.grpc.StatusRuntimeException)

Example 4 with SimpleURI

use of ai.grakn.util.SimpleURI in project grakn by graknlabs.

the class RedisWrapperTest method whenBuildingNoSentinelWellFormed_Succeeds.

@Test
public void whenBuildingNoSentinelWellFormed_Succeeds() {
    RedisServer server = inMemoryRedisContext.server();
    RedisWrapper redisWrapper = RedisWrapper.builder().setUseSentinel(false).addURI(new SimpleURI(server.getHost(), server.getBindPort()).toString()).build();
    assertNotNull(redisWrapper.getJedisPool());
}
Also used : SimpleURI(ai.grakn.util.SimpleURI) RedisServer(ai.grakn.redismock.RedisServer) Test(org.junit.Test)

Example 5 with SimpleURI

use of ai.grakn.util.SimpleURI in project grakn by graknlabs.

the class GraknEngineServerTest method whenEngineServerIsStarted_SystemKeyspaceIsLoaded.

@Test
public void whenEngineServerIsStarted_SystemKeyspaceIsLoaded() throws IOException {
    SimpleURI uri = new SimpleURI(Iterables.getOnlyElement(config.getProperty(GraknConfigKey.REDIS_HOST)));
    RedisServer redisServer = RedisServer.newRedisServer(uri.getPort());
    redisServer.start();
    try {
        try (GraknEngineServer server = createGraknEngineServer(mockRedisWrapper)) {
            server.start();
            assertNotNull(graknKeyspaceStore);
            // init a random keyspace
            String keyspaceName = "thisisarandomwhalekeyspace";
            graknKeyspaceStore.addKeyspace(Keyspace.of(keyspaceName));
            assertTrue(graknKeyspaceStore.containsKeyspace(Keyspace.of(keyspaceName)));
        }
    } finally {
        redisServer.stop();
    }
}
Also used : SimpleURI(ai.grakn.util.SimpleURI) RedisServer(ai.grakn.redismock.RedisServer) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Aggregations

SimpleURI (ai.grakn.util.SimpleURI)12 RedisServer (ai.grakn.redismock.RedisServer)4 Test (org.junit.Test)4 Keyspace (ai.grakn.Keyspace)2 GraknConfig (ai.grakn.engine.GraknConfig)2 IOException (java.io.IOException)2 GraknSession (ai.grakn.GraknSession)1 Grakn (ai.grakn.bootup.graknengine.Grakn)1 RedisWrapper (ai.grakn.engine.data.RedisWrapper)1 StatusRuntimeException (io.grpc.StatusRuntimeException)1 File (java.io.File)1 HttpURLConnection (java.net.HttpURLConnection)1 URI (java.net.URI)1 URL (java.net.URL)1 Path (java.nio.file.Path)1 Properties (java.util.Properties)1 ConsoleReader (jline.console.ConsoleReader)1 ZipFile (net.lingala.zip4j.core.ZipFile)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1