Search in sources :

Example 6 with SimpleURI

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

the class EngineProcess method graknCheckIfReady.

private boolean graknCheckIfReady(String host, int port, String path) {
    try {
        URL siteURL = UriBuilder.fromUri(new SimpleURI(host, port).toURI()).path(path).build().toURL();
        HttpURLConnection connection = (HttpURLConnection) siteURL.openConnection();
        connection.setRequestMethod("GET");
        connection.connect();
        int code = connection.getResponseCode();
        return code == 200;
    } catch (IOException e) {
        return false;
    }
}
Also used : HttpURLConnection(java.net.HttpURLConnection) SimpleURI(ai.grakn.util.SimpleURI) IOException(java.io.IOException) URL(java.net.URL)

Example 7 with SimpleURI

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

the class GraqlShellIT method addKeyspaceAndUriParams.

// TODO: Remove this when we can clear graphs properly (TP #13745)
private String[] addKeyspaceAndUriParams(String[] args) {
    List<String> argList = Lists.newArrayList(args);
    int keyspaceIndex = argList.indexOf("-k") + 1;
    if (keyspaceIndex == 0) {
        argList.add("-k");
        argList.add(GraqlShellOptions.DEFAULT_KEYSPACE.getValue());
        keyspaceIndex = argList.size() - 1;
    }
    argList.set(keyspaceIndex, argList.get(keyspaceIndex) + keyspaceSuffix);
    boolean uriSpecified = argList.contains("-r");
    if (!uriSpecified) {
        argList.add("-r");
        boolean isBatchLoading = argList.contains("-b");
        SimpleURI uri = isBatchLoading ? engine.uri() : engine.grpcUri();
        argList.add(uri.toString());
    }
    return argList.toArray(new String[argList.size()]);
}
Also used : SimpleURI(ai.grakn.util.SimpleURI) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString)

Example 8 with SimpleURI

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

the class DistributionContext method newEngineProcess.

private Process newEngineProcess(Integer port, Integer redisPort) throws IOException {
    // Set correct port & task manager
    GraknConfig config = GraknConfig.create();
    config.setConfigProperty(GraknConfigKey.SERVER_PORT, port);
    config.setConfigProperty(GraknConfigKey.REDIS_HOST, ImmutableList.of(new SimpleURI("localhost", redisPort).toString()));
    // To speed up tests of failure cases
    config.setConfigProperty(GraknConfigKey.TASKS_RETRY_DELAY, 60);
    // Write new properties to disk
    File propertiesFile = new File("grakn-engine-" + port + ".properties");
    propertiesFile.deleteOnExit();
    config.write(propertiesFile);
    // Java commands to start Engine process
    String[] commands = { "java", "-cp", getClassPath(), "-Dgrakn.dir=" + EXTRACTED_DISTRIBUTION_DIRECTORY, "-Dgrakn.conf=" + propertiesFile.getAbsolutePath(), "-Dgrakn.pidfile=/tmp/grakn.pid", Grakn.class.getName(), "&" };
    // Start process
    ProcessBuilder processBuilder = new ProcessBuilder(commands);
    if (inheritIO)
        processBuilder.inheritIO();
    return processBuilder.start();
}
Also used : GraknConfig(ai.grakn.engine.GraknConfig) Grakn(ai.grakn.bootup.graknengine.Grakn) SimpleURI(ai.grakn.util.SimpleURI) ZipFile(net.lingala.zip4j.core.ZipFile) File(java.io.File)

Example 9 with SimpleURI

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

the class RedisWrapperTest method whenBuildingSentinelNoMaster_Fails.

@Test(expected = IllegalStateException.class)
public void whenBuildingSentinelNoMaster_Fails() {
    RedisServer server = inMemoryRedisContext.server();
    RedisWrapper.builder().setUseSentinel(true).addURI(new SimpleURI(server.getHost(), server.getBindPort()).toString()).build();
}
Also used : SimpleURI(ai.grakn.util.SimpleURI) RedisServer(ai.grakn.redismock.RedisServer) Test(org.junit.Test)

Example 10 with SimpleURI

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

the class GraknSessionProvider method getSession.

@Override
public GraknSession getSession(GraqlShellOptions options, ConsoleReader console) {
    int defaultGrpcPort = config.getProperty(GraknConfigKey.GRPC_PORT);
    SimpleURI defaultGrpcUri = new SimpleURI(Grakn.DEFAULT_URI.getHost(), defaultGrpcPort);
    SimpleURI location = options.getUri();
    SimpleURI uri = location != null ? location : defaultGrpcUri;
    Keyspace keyspace = options.getKeyspace();
    return RemoteGrakn.session(uri, keyspace);
}
Also used : Keyspace(ai.grakn.Keyspace) SimpleURI(ai.grakn.util.SimpleURI)

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