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());
}
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);
}
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;
}
}
}
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());
}
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();
}
}
Aggregations